<?php
error_reporting(0);
$k=trim($_GET['k']); include("key.php");
$d=rawurldecode(trim($_GET['d'])); $n=rawurldecode(trim($_GET['n']));
if ($d==NULL) {$d="";} elseif ($d=="/") {$d="";} if ($n==NULL) {$n="";}
$p=trim($_GET['p']); $ed=trim($_GET['ed']);
$kdr=trim($_GET['kdr']); $ikdr=trim($_GET['ikdr']);
$rf=strtolower(preg_replace("~.*\.([^\.]*)~m","\\1",$n));
$rd=rawurlencode($d); $rn=rawurlencode($n);
$d=str_replace(".|htaccess",".htaccess",$d);
$n=str_replace(".|htaccess",".htaccess",$n);
include("utf.php"); include("esc.php"); include("koi.php"); $soft=""; $v=$_GET['ln'];
if (($rf=="wml")||($rf=="htm")||($rf=="html")||($rf=="txt")) {
$soft="<do name=\"show\" type=\"options\" label=\"Просмотр\"><go href=\"$dftp/show.php?k=$k&t=$rf\"/></do>";
} elseif ($rf=="php") {
$soft="<do name=\"chck\" type=\"options\" label=\"Синтаксис\"><go href=\"$dftp/chck.php?k=$k\"/></do>";
}
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: text/vnd.wap.wml; charset=utf-8");
echo ("<?xml version=\"1.0\" encoding=\"Utf-8\"?><!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml_1.2.xml\"><wml>
<card title=\"FTP - $n\">");
if ($ed==1) {@unlink("data/$k.edbk"); @unlink("data/$k.edbkp"); @unlink("data/$k.ed");
if (($ftp=ftp_connect($sr))&&(ftp_login($ftp,$lg,$ps))) {
ftp_pasv($ftp,true); $sz=ftp_size($ftp,"$d/$n");
if (($sz==-1)||($sz>122880)) {
header("Location: $dftp/ftp.php?k=$k&d=$rd"); exit;
}
ftp_get($ftp,"data/$k.ed","$d/$n",FTP_BINARY);
$fl=@file("data/$k.ed");
if ($fl<>NULL) {
$f=fopen("data/$k.ed","w");
for ($i=0;$i<count($fl);$i++) {
if ($i==0) {
if (substr($fl[$i],0,3)==chr(239).chr(187).chr(191)) {$fl[$i]=substr($fl[$i],3);}
}
if ($kdr==5) {fwrite($f,trim($fl[$i])."\r\n");}
else {
if ($ikdr==1) {fwrite($f,trim(k2u($fl[$i]))."\r\n");}
else {fwrite($f,trim(w2u(e2w(u2w($fl[$i]))))."\r\n");}
}
}
fclose($f);
$msz=$_GET['msz'];
if ($msz<>NULL) {
if ($msz>1024) {$msz=1024;}
if ($msz>=32) {
$fl=@file("data/$k.ed");
$f=fopen("data/$k.ed","w");
for ($i=0;$i<count($fl);$i++) {
if (strlen($fl[$i])>$msz) {
$fl[$i]=trim(preg_replace("~.{".$msz."}[\s;}>,]~m","\\0\r\n",trim($fl[$i])))."\r\n";
}
fwrite($f,$fl[$i]);
}
}
fclose($f);
}
}
ftp_close($ftp);
} else {
echo("<p align=\"center\"><small>
Нет соединения с сервером.<br/>
- - -<br/>
<anchor>Назад<prev/></anchor>
</small></p>
</card></wml>"); exit;
}
}
$d=str_replace('$','$$',$d); $n=str_replace('$','$$',$n);
$sv=trim($_GET['sv']); $svs=trim($_GET['svs']); $undo=trim($_GET['undo']);
if (($v==NULL)||($v<1)||($v>15)) {$v=7;}
function rept($kl) {
if (($kl[1]<>NULL)&&($kl[1]!=="0")&&($kl[1]<=50)) {return str_repeat("\r\n",$kl[1]);}
else {return $kl[0];}
}
function lcopy($nmr) {global $k;
$fl=@file("data/$k.ed");
$cnt=count($fl);
if (($nmr[1]>=1)&&($nmr[1]<=$cnt)) {return trim($fl[$nmr[1]-1]);}
else {return $nmr[0];}
}
function chars($ch) {
global $kdr;
if (($ch[1]>=0)&&($ch[1]<=255)) {
if ($kdr==5) {return chr($ch[1]);}
else {return w2u(chr($ch[1]));}
} else {return $ch[0];}
}
function repl($txt) {
$txt=preg_replace_callback("~#_new_line_\[(\d*)\]#~",rept,$txt);
$txt=preg_replace_callback("~#_copy_\[(\d*)\]#~",lcopy,$txt);
$txt=preg_replace("~#_new_line#~","\r\n",$txt);
$txt=preg_replace("~[^\n]*#_del_line#[^\n]*\n?~","",$txt,1);
$txt=str_replace("#_wml_1.1#","<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">",$txt);
$txt=str_replace("#_wml_1.2#","<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml_1.2.xml\">",$txt);
$txt=str_replace("#_wml_1.3#","<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\">",$txt);
$txt=str_replace("#_html_4.0#","<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">",$txt);
$txt=str_replace("#_html_4.01#","<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">",$txt);
$txt=str_replace("#_wml_header#","header(\"Content-type: text/vnd.wap.wml; charset=utf-8\");",$txt);
$txt=str_replace("#_html_header#","header(\"Content-type: text/html; charset=utf-8\");",$txt);
$txt=str_replace("#_txt_header#","header(\"Content-type: text/plain; charset=utf-8\");",$txt);
$txt=str_replace("#_wml_begin#","<wml><card id=\"card1\" title=\"\"><p align=\"left\">",$txt);
$txt=str_replace("#_wml_end#","</p></card></wml>",$txt);
$txt=str_replace("#_html_begin#","<html><head><title></title><meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\"></head><body>",$txt);
$txt=str_replace("#_html_end#","</body></html>",$txt);
$txt=str_replace("#_html_css#","<link rel=\"STYLESHEET\" type=\"text/css\" href=\".css\">",$txt);
$txt=str_replace("#_php_location#","header(\"Location: http://\"); exit;",$txt);
$txt=str_replace("#_php_date#","date(\"d.m.Y, H:i:s\",mktime(date(\"H\")+0));",$txt);
$txt=preg_replace_callback("~#_(\d{1,3})#~",chars,$txt);
return $txt;
}
if ($undo<>NULL) {
@copy("data/$k.edbk","data/$k.ed");
$p=trim(@file_get_contents("data/$k.edbkp"));
@unlink("data/$k.edbk"); @unlink("data/$k.edbkp");
} else {
if ($sv<>NULL) {
@copy("data/$k.ed","data/$k.edbk");
$f=@fopen("data/$k.edbkp","w"); @fwrite($f,$p); @fclose($f);
$e1=trim(stripslashes($_POST['e1'])); $e2=trim(stripslashes($_POST['e2']));
$e3=trim(stripslashes($_POST['e3'])); $e4=trim(stripslashes($_POST['e4']));
$e5=trim(stripslashes($_POST['e5'])); $e6=trim(stripslashes($_POST['e6']));
$e7=trim(stripslashes($_POST['e7'])); $e8=trim(stripslashes($_POST['e8']));
$e9=trim(stripslashes($_POST['e9'])); $e10=trim(stripslashes($_POST['e10']));
$e11=trim(stripslashes($_POST['e11'])); $e12=trim(stripslashes($_POST['e12']));
$e13=trim(stripslashes($_POST['e13'])); $e14=trim(stripslashes($_POST['e14']));
$e15=trim(stripslashes($_POST['e15']));
if (($e1<>NULL)||($e2<>NULL)||($e3<>NULL)||($e4<>NULL)||($e5<>NULL)||($e6<>NULL)||
($e7<>NULL)||($e8<>NULL)||($e9<>NULL)||($e10<>NULL)||($e11<>NULL)||($e12<>NULL)||
($e13<>NULL)||($e14<>NULL)||($e15<>NULL)) {
if ($fl=@file("data/$k.ed")) {$cnt=count($fl);
$begin=$sv*$v-$v; if ($begin>$cnt) {$begin=0;}
$end=$begin+$v; if ($end>$cnt) {$end=$cnt;} $ar=NULL; $nm=1; $str="";
for ($i=$begin;$i<$end;$i++) {$fl[$i]=repl(${"e$nm"}."\r\n"); $nm++;}
for ($i=0;$i<count($fl);$i++) {$str.=$fl[$i];}
if (strpos($str,"#_del_free#")!==false) {
$str=preg_replace("~[\s]*#_del_free#[\s]*~","\r\n",$str);
}
if ((strpos($str,"#_del_begin#")!==false)&&(strpos($str,"#_del_end#")!==false)) {
$str=preg_replace("~#_del_begin#[\s\S]*#_del_end#~","",$str);
}
if (strpos($str,"#_del_free_all#")!==false) {
$str=str_replace("#_del_free_all#","",$str);
$str=str_replace("\n\r","",$str);
$str=preg_replace("~^\r\n~","",$str,1);
}
$f=fopen("data/$k.ed","w"); fwrite($f,$str); fclose($f);
} else {$str="";
for ($i=1;$i<=$v;$i++) {$str.=${"e$i"}; if ($i<>$v) {$str.="\r\n";}}
if (strpos($str,"#_del_free#")!==false) {
$str=preg_replace("~[\s]*#_del_free#[\s]*~","\r\n",$str);
}
if ((strpos($str,"#_del_begin#")!==false)&&(strpos($str,"#_del_end#")!==false)) {
$str=preg_replace("~#_del_begin#[\s\S]*#_del_end#~","",$str);
}
if (strpos($str,"#_del_free_all#")!==false) {
$str=str_replace("#_del_free_all#","",$str);
$str=str_replace("\n\r","",$str);
}
$f=@fopen("data/$k.ed","w"); @fwrite($f,repl(trim($str))); @fclose($f); $str=NULL;
}
}
}
if ($svs<>NULL) {
if ($kdr==1) {copy("data/$k.ed","data/$k.eds");}
else {
$fl=@file("data/$k.ed");
@$f=fopen("data/$k.eds","w");
if ($fl<>NULL) {
for ($i=0;$i<count($fl);$i++) {
if ($kdr==2) {@fwrite($f,trim(u2w($fl[$i]))."\r\n");}
elseif ($kdr==3) {@fwrite($f,trim(w2e(u2w($fl[$i])))."\r\n");}
elseif ($kdr==4) {@fwrite($f,trim(u2k($fl[$i]))."\r\n");}
else {@fwrite($f,trim($fl[$i])."\r\n");}
}
}
@fclose($f);
}
if (($ftp=ftp_connect($sr))&&(ftp_login($ftp,$lg,$ps))) {
@ftp_pasv($ftp,true);
@ftp_put($ftp,str_replace('$$','$',"$d/$n"),"data/$k.eds",FTP_BINARY);
@ftp_close($ftp);
} else {
echo("<p align=\"center\"><small>
Нет соединения с сервером.<br/>
- - -<br/>
<anchor>Назад<prev/></anchor>
</small></p>
</card></wml>"); exit;
}
@unlink("data/$k.eds");
}
} $bl=""; $nav="";
if ($fl=@file("data/$k.ed")) {$cnt=count($fl); $allp=ceil($cnt/$v);
if (($p==NULL)||($p==0)) {$p=1;} elseif ($p>$allp) {$p=$allp;} elseif ($p<1) {$p=1;}
$begin=$p*$v-$v; if ($begin>$cnt) {$begin=0;}
$end=$begin+$v; if ($end>$cnt) {$end=$cnt;} $ar=NULL; $vl=$end-$begin;
function chrpl($str) {
for ($j=0;$j<32;$j++) {
if (($j<>10)&&($j<>13)) {$str=str_replace(chr($j),"#_$j#",$str);}
}
return $str;
}
for ($i=$begin;$i<$end;$i++) {
if (strpos(strtolower(getenv("HTTP_USER_AGENT")),"sonyericssonk")!==false) {
$ar[]=str_replace('$','#_36#',htmlspecialchars(chrpl($fl[$i]),ENT_QUOTES));
} else {
$ar[]=str_replace('$','$$',htmlspecialchars(chrpl($fl[$i]),ENT_QUOTES));
}
}
if ($p>1) {$vp=$p-1;
$bl.="<a href=\"edit.php?k=$k&d=$rd&n=$rn&p=$vp&kdr=$kdr&ln=$v\">Предыдущая</a><br/>\r\n";}
if ($allp>$p) {$vp=$p+1;
$bl.="<a href=\"edit.php?k=$k&d=$rd&n=$rn&p=$vp&kdr=$kdr&ln=$v\">Следующая</a><br/>\r\n";}
if ($bl<>NULL) {$bl="$bl";
$nav="</small><input name=\"pg\" type=\"text\" value=\"$p\" size=\"3\" format=\"*N\"/><small><a href=\"edit.php?k=$k&d=$rd&n=$rn&p=$(pg)&kdr=$kdr&ln=$v\">GO</a><br/>\r\n";}
} else {$p=1; $allp=1; $ar[]=""; $vl=1;}
echo("<onevent type=\"onenterforward\"><refresh>");
for ($i=1;$i<=$vl;$i++) {
echo("<setvar name=\"e".$i."\" value=\"".trim($ar[$i-1])."\"/>");
}
echo("</refresh></onevent>\r\n$soft<do name=\"pr\" type=\"options\" label=\"Код\"><go href=\"$dftp/show.php?k=$k&t=pr\"/></do><do name=\"pr2\" type=\"options\" label=\"Код 2.0\"><go href=\"$dftp/show.php?k=$k&t=pr2\"/></do><do name=\"faq\" type=\"options\" label=\"FAQ\"><go href=\"$dftp/faq.php?p=4\"/></do>\r\n");
echo("<p align=\"left\"><small>
<a href=\"ftp.php?k=$k&d=$rd\">$d/</a><a href=\"file.php?k=$k&d=$rd&n=$rn\">$n</a><br/>
- - -<br/>
</small>");
for ($i=1;$i<=$vl;$i++) {
echo("<input name=\"e".$i."\" type=\"text\" title=\"".$i."(".($begin+$i).")\" format=\"*m\"/><br/>\r\n");
}
echo("<small>- - -<br/>
Строк: $vl/$cnt<br/>
Страница: $p/$allp<br/>
$bl$nav- - -<br/>
<anchor>Сохранить<go href=\"$dftp/edit.php?k=$k&d=$rd&n=$rn&p=$p&kdr=$kdr&sv=$p&svs=1&ln=$v\" method=\"post\">");
for ($i=1;$i<=$vl;$i++) {
echo("<postfield name=\"e".$i."\" value=\"$(e".$i.")\"/>");
}
echo("</go></anchor><br/><a href=\"edit.php?k=$k&d=$rd&n=$rn&p=$p&kdr=$kdr&svs=1&ln=$v\">Сохранить без изменений</a><br/><a href=\"func.php?k=$k&d=$rd&n=$rn&kdr=$kdr&p=$p&ln=$v\">Действия..</a>");
if (@file_exists("data/$k.edbk")) {echo("<br/>- - -<br/><a href=\"edit.php?k=$k&d=$rd&n=$rn&kdr=$kdr&undo=1&ln=$v\">Отмена</a>");}
echo("</small></p>
</card></wml>");
?>