Record [f:_dev/util/copyto.php] < dev.sky.1.001
Version 1.001
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | <?php defined('START') and AUTH_OK or die; if (START == 'ajax'): eval(get((bool)$ival)); if ($ival) $step = $ival; switch ($step) { case 1: # filesystem $log = sprintf(span_b, "\n***************** COPY TO ... *****************\n"); set(['u_ct_where' => (int)$p_w, 'u_ct_path' => $PVAL, 'u_ct_exec' => $_ = (int)isset($p_exec), 'u_ct_del' => (int)($_ && $p_exec)], 0, 2); if ($PVAL) { $res = @copy($u_ct_files, $PVAL); $log = $res ? "{$log}copied to `$PVAL` " . sprintf(span_g, '- OK') : "-{$log}Error occured when copy to `$PVAL`"; $res && @unlink($u_ct_files); if ($res && isset($p_exec)) { $log .= sprintf(span_b, "\n\n***************** EXEC FILE *******************\n"); chdir(dirname($PVAL)); $out = ''; exec('php ' . basename($PVAL), $out); $log .= implode("\n", $out); if ($p_exec) { $log .= sprintf(span_b, "\n\n***************** DELETE FILE *****************\n"); $log .= @unlink($PVAL) ? sprintf(span_g, 'deleted - OK') : sprintf(span_r, 'deleting FAILED!'); } } } else $log = "-{$log}File NOT copied"; break; case 2: # remote host break; case 3: # email break; case 4: # CREATE ARCHIVE START $area = @area($syn); # 2do syntax of an area $tfn = '_dev/temp/my.archive'; set(['u_narch' => $u_narch, 'u_ct_files' => $afn = "$tfn.sky"], 0, 2); require '_dev/main/diff.php'; list ($dir_list, $skip, $nused, $files2) = filter_path($area->inc_p, "$area->exc_p $tfn $afn"); $add = array_diff(get_tables2($rows = filter_rows($area->inc_r, $area->exc_r)), $tables = filter_tables($area->inc_t, $area->exc_t)); $log = "1. Saving path structure:\n" . loger($dirs = implode(' ', $dir_list)); set([ 'i_dir=i_file=fcnt=tcnt=rcnt=dcnt' => 0, 'tfn' => $tfn, 'afn' => $afn, 'u_svn_skips' => implode(' ', $u_svn_skips), 'dirs' => $dirs, 'skip' => implode(' ', $skip), 'rows' => implode(' ', $rows), 'tcnt' => count($tables = array_merge($tables, $add)), 'dcnt' => count($dirs = array_diff($dir_list, $files2 + [-1 => '.'])), 'step' => 5, ], []); $log .= "\n2. Saving tables:\n" . loger(implode(' ', $tables)) . "\n3. Saving rows:"; $tables = strtr(implode(";\t", array_map('create_table', $tables)) . ";\t", "\r\n\t", " \n"); $dirs = implode("\n", $dirs); file_put_contents($tfn, "### folders: ###\n$dirs\n### file: database.sql ###\nset names utf8;\n$tables"); # 2do error check of writing break; case 5: $rows = str2ary($rows); $i = 0; if ($i_dir < count($rows)) { list ($table, $cn, $cp, $where) = explode('.', $rows[$i_dir], 4); if ('!' !== $cp) { if ($cn) $cn = "order by $cn limit $i_file, $u_row_portion"; else $where = ''; $q = sql("select * from $table $where $cn"); while ($r = fetch($q, true)) ++$i && file_put_contents($tfn, "insert into $table values(" . make_insert($r, ',') . ");\n", FILE_APPEND); if ($i) $ary += ['rcnt' => $rcnt + $i] and $log = " `$table`: $i rows stored"; elseif (!$cn || $cn && !$i_file) $log = " `$table`: " . sprintf(span_r, 'no rows stored!'); } $i_file = $cn && $i ? $i + $i_file : 0 or ++$i_dir; set($ary + ['i_dir' => $i_dir, 'i_file' => $i_file]); } else { set(['step' => 6, 'i_dir=i_file' => 0]); $rcnt or $log = loger() . "\n"; $log = $log . '4. Saving files:'; } break; case 6: $dirs = str2ary($dirs); if ($i_dir < count($dirs)) { if ($i_file) $files = str2ary($files); else { $files = is_file($dirs[$i_dir]) ? [$dirs[$i_dir]] : Area::lst($dirs[$i_dir], 'is_file', false, $skip); $ary = ['files' => implode(' ', $files)] + $ary; } if ($i_file < count($files)) { if (!in_array(basename($fn = $files[$i_file++]), $u_svn_skips)) { $file = file_get_contents($fn); file_put_contents($tfn, "### file: $fn: " . filesize($fn) . " ###\n$file\n", FILE_APPEND); $ary += ['fcnt' => ++$fcnt] and $log = " $fn"; } else $log = " $fn " . sprintf(span_r, '- skipped by $u_svn_skips'); } else ++$i_dir and $i_file = 0; set($ary + ['i_dir' => $i_dir, 'i_file' => $i_file]); } else { $bz = bzopen($afn, 'w'); $fh = fopen($tfn, 'r'); while (!feof($fh)) { $dat = fread($fh, 8192); bzwrite($bz, $dat); } fclose($fh); bzwrite($bz, '### end package: ###'); bzclose($bz); $log = $fcnt ? '+' : '+' . loger() . "\n"; $fs = filesize($afn); $log .= "5. Archive done, saved to file: $afn - $fs bytes\n FTRD: A^<u>$fcnt/$tcnt/$rcnt/$dcnt</u>"; } break; } echo_json($log); else: # HTML PAGE ?><form id="f1" style="width:90%"> <fieldset style="background:#ffe;width:97%"><legend>1. Source:</legend> <label><input type="radio" name="st1" onclick="s1(0)" /> Select files</label> <?=pad()?><label><input type="radio" name="st1" onclick="s1(1)" /> Export Package</label> <?=pad()?><label><input type="radio" name="st1" onclick="s1(2)" checked /> Make Wind of changes</label> <?=pad()?><label><input type="radio" name="st1" onclick="s1(3)" /> Make Archive</label> </fieldset> <div id="what"> <div class="area"><small>define exect path to each file:</small><br><textarea name="files" style="width:100%" rows="3"></textarea></div> <div class="area" style="display:none">Select Package: <select name="pack"><?=option(0, '_dev_packages')?></select></div> <div class="area" style="display:none">Codebase ID enter point: <input size="3" name="ep" value="<?=$u_ct_ep?>" /> <?=pad()?>Description: <input size="55" name="title" value="<?=$u_ct_ep_desc?>" /> </div> <div class="area" style="display:none"><? eval(get()); require '_dev/main/area.php' ?></div> </div> <br> <fieldset id="copyto" style="background:#ffe;width:97%"><legend>2. Copy to:</legend> <label><input type="radio" onclick="s2(0)" name="st2" checked /> filesystem</label> <?=pad()?><label><input type="radio" onclick="s2(1)" name="st2" /> remote host</label> <?=pad()?><label><input type="radio" onclick="s2(2)" name="st2" /> send by e-mail</label> </fieldset> <div id="to"> <div class="area"><small>destination path:</small><br><textarea name="path" style="width:100%" rows="1"><?=$u_ct_path?></textarea></div> <div class="area" style="display:none"><small>host:</small><br><textarea name="host" style="width:100%" rows="1"><?=''?></textarea></div> <div class="area" style="display:none"><small>e-mail to:</small><br><textarea name="email" style="width:100%" rows="1"><?=''?></textarea></div> </div> <br> <fieldset id="last" style="background:#ffe;width:97%"><legend>3. and ...</legend> <label><input type="checkbox" name="st3"<?=$u_ct_exec?' checked':''?> /> execute .php files</label> <?=pad()?>and... <label><input type="checkbox" name="st4"<?=$u_ct_del?' checked':''?> /> delete copied files after</label> </fieldset> <br><br> <input type="button" value="Copy to.. - F9 " onclick="key_F9()" /> </form> <pre id="log"></pre> <script type="text/javascript"> var f1 = $('f1'); var ptitle = 'This utility can archive files and DB tables (+rows) and/or move files (or archive) to remote host or some backup\'s dir and maybe ' + 'run Wind script on remote host or filesystem<br>Read <a href="?help=whatis">here</a> what is `Wind`.'; mtop(ptitle); f1.$$('input', s1(<?=$u_ct_where?>)).checked = true; function s1(n) { if (t$(n)) mtop(n < 2 ? 'Not implemented now, todo...' : ptitle, n < 2 ? red: yellow); $$('div', 'what', 'area', function(div, i) { if (t$(n)) div.$(i === n); else if (div.style.display != 'none') n = i; }); return n; } function s2(n) { if (0 == n) mtop(ptitle); else mtop('Not implemented now, todo...', red); $$('div', 'to', 'area', function(div, i) { div.$(i === n); }); } function key_F9() { var v = f1.st3.checked ? '&exec=' + (f1.st4.checked ? 1 : 0) : '', name = 'Make archive'; this.copy = function(json, err) { if (loger(json, err, name) && !err) ajax('1&path=' + e$(f1.path.value) + v + '&w=' + s1(), function(r, err) { var json = callback(r, err, '(copyto) '); if (t$(json.log)) html('log', 'be', json.log), scrollBy(0, 10000); if (err) scrollUp(); }); } switch (s1()) { case 0: break; // 'Select Files' case 1: break; // 'Export Package' case 2: cycle(f1.ep.value + '&ds=' + e$(f1.title.value), 'Generation of Wind', this.copy, 'wind'); break; case 3: cycle('4&pp=' + qs_area(), name, this.copy); break; } } </script><style type="text/css">.area {margin:5px 0 0 0}</style> <?php endif; |
Codebase entries (89)
SKY. status
Current version: 1.001
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php