📄 cms.php
字号:
<?
/*
#------------------------------------------------------#
# 本程序为SHEYI工作室提供 #
# #
# 本程序版权归Sheyi工作室所有!任何人皆可自由 #
# 使用本程序于非商业用途,商业用途必须付费人 #
# 民币200元! #
# #
# 谢谢您使用本程序 sheyi #
# QQ : 1912070 #
# E-mail: sheyee@163.com #
# URL :http://sheyi.126.com #
# #
# 本程序为免费程序,您可以使用本程序,但必须 #
# 保留Sheyi工作室(http://sheyi.126.com)的链接! #
#------------------------------------------------------#
Name: cms.php
*/
if (strpos(servervar('SERVER_SOFTWARE'), "IIS")) $scriptname =preg_replace('/([^\?]*)\?.*/','\1',servervar('SCRIPT_NAME')); else $scriptname=preg_replace('/([^\?]*)\?.*/','\1',servervar('REQUEST_URI'));
// INIT
$intvars=array('download','function','search','text','selected','login','logout','sitemap','settings','print','file','action','validate','images','edit','normal','stylesheet','passwd');
for ($i = 0; $i<count($intvars); $i++) initvar($intvars[$i]);
if (servervar('QUERY_STRING')!='') {
$requestarray=explode('&',servervar('QUERY_STRING'));
$selected=$requestarray[0];
for ($i = 1; $i<count($requestarray); $i++) { if ($GLOBALS[preg_replace("/=.*/i","",$requestarray[$i])]=='') $GLOBALS[preg_replace("/=.*/i","",$requestarray[$i])]='true';}}
// if (mygetcookie('status')!=''||$login) { header('Cache-Control: no-cache');header('Pragma: no-cache');}
$title=null;$contentout=null;$error=null;$headingjs=null;$onload=null;
if ($stylesheet!='') { include($file_stylesheet); exit; }
if ($download!='') { download($folder_download.$download); }
if ($function!='search'&&$function!='save') $function='';
if ($sitemap) $function='sitemap';
// ADMIN CHECK AND LOGIN
// LOGIN SECURITY HAS TO BE IMPROVED!
$admin=(mygetcookie('status')=='admin' && logincheck());
if ($login && !$admin) {
if (!$usewwwaut) {
if ($passwd==$password) {
setcookie ('status','admin');
setcookie ('passwd',$passwd);
$admin=true; $edit=true;
writelog(date("Y-m-d H:i:s")." from ".servervar('REMOTE_ADDR')." logged in\n");
} else getlost();
} else {
if(servervar('PHP_AUTH_USER')==''||servervar('PHP_AUTH_PW')==''||mygetcookie('status')=='') {
setcookie('status','login');
header('WWW-Authenticate: Basic realm="'.$text_loginwarning.'"');
getlost(); } else {
if (logincheck()) {
setcookie ('status','admin'); $admin=true; $edit=true;
writelog(date("Y-m-d H:i:s")." from ".servervar('REMOTE_ADDR')." logged in\n");
} else { getlost();} }
}} else if ($logout && $admin) {
$file=date("YmdHis").'.htm';
if (@copy($file_content,$folder_cmsimple.'/'.$file)) {
$contentout.='<p>New backup file '.$file.' created.</p>';
$filelist=array();
$fd = @opendir($folder_cmsimple);
while ( ($part = @readdir($fd)) == true ) {
if (preg_match("/\d{3}\.htm/", $part)) {
$filelist[] = $part;
}}
if($fd==true) { closedir($fd); }
sort($filelist);
for ($i = 0; $i < count($filelist)-$no_bckfiles; $i++) {
if (@unlink($folder_cmsimple.'/'.$filelist[$i])) $contentout.='<p>Old backup file '.$filelist[$i].' deleted.</p>'; else $error.='<li>Old backup file '.$filelist[$i].' could not be deleted';
}} else { $error="<li>failed to create backup"; }
$admin=false; $contentout.='<p><font color="red">You have been logged out.</font></p>';
}
// SETTING FUNCTIONS AS PERMITTED
if ($admin) {
if ($validate) $function='validate';
if ($settings) $function='settings';
if ($file) $function='file';
if ($images) $function='images';
if ($edit) setcookie('mode','edit');
if ($normal) setcookie('mode','');
if (mygetcookie('mode')=='edit' && !$normal) $edit=true;
} else {
if (mygetcookie('status')!='') setcookie('status','');
if (mygetcookie('mode')=='edit') setcookie ('mode', '');
// Script for javascript login()
if (!$usewwwaut) $headingjs='<script language="JavaScript"><!--
function login(){var tmp=prompt("'.$text_loginwarning.'","");if (tmp!=null&&tmp!=""){document.getElementById("passwd").value=tmp;document.getElementById("login").submit();}}
//-->
</script>';
}
// READ FILE
read_file_content();
if ($selectednum==-1 && !$function && $contentout=='') {
if ($selected!='') { header('HTTP/1.0 404 Not Found'); $title=$text_title['error404'];$contentout='<h1>'.$title.'</h1>'.$contentout; } else $selectednum=0;
}
// Public functions
if ($function=='search') {
$title=$text_title['search'];
$style='search';
$tmp=null;$result=0;
for ($i = 0; $i < count($contentarray); $i++) {
if (preg_match('/'.$search.'/i',$contentarray[$i])) { $tmp.=trlink($i,$style,true); $result++; }
}
if ($tmp!='') $tmp=$tablestart.$tmp.'</table>';
$resulttext='<p>"'.htmlentities($search).'" ';
if ($result==0) $resulttext.=$text_notfound.'.</p>'; else {
$resulttext.=$text_foundin.' '.$result. ' ';
if ($result>1) $resulttext.=$text_pgplural; else $resulttext.=$text_pgsingular;
$resulttext.=':</p>';
}
$contentout.='<h1>'.$text_searchresult.'</h1>'.$resulttext.$tmp;
}
if ($function=='sitemap') {
$tmp=''; $title=$text_title['sitemap'];
$contentout.='<h1>'.$text_title['sitemap'].'</h1>';
for ($i = 0; $i < count($contentarray); $i++) {
$tmp.=trlink($i,'sitemaplevel'.level($i),false);
} $contentout.=$tablestart.$tmp.'</table>';}
// Protected functions
if ($admin) {
if ($function=='settings') {
$contentout.='<h1>Settings</h1><p>Don\'t mess with this, unless you know, what you are doing!</p><ul><a href="'.$scriptname.'?file=file_settings"><li>Edit settings</a><a href="'.$scriptname.'?file=file_stylesheet"><li>Edit stylesheet</a><a href="'.$scriptname.'?file=file_template"><li>Edit template</a><a href="'.$scriptname.'?file=file_content"><li>Edit content</a><a href="'.$scriptname.'?file=file_execute&action=view"><li>View execute</a><a href="'.$scriptname.'?file=file_log&action=view"><li>View log</a><a href="'.$scriptname.'?file=file_content&action=view"><li>View content</a><a href="'.$scriptname.'?file=file_content&action=download"><li>Download content</a></ul>';
$contentout.='<h1>Backup</h1><p>On logout file_content is backed up in folder_cmsimple, and the oldest backup file(s) will be deleted.</p><p>The number of backup files is set with no_bckfiles in <a href="'.$scriptname.'?file=file_settings">file_settings</a>, currently: '.$no_bckfiles.'</p><p>If you wish to save a backup of the current content on your local harddisk: <a href="'.$scriptname.'?file=file_content&action=download">Download file_content '.$GLOBALS['file_content'].'.</a></p><p>Use copy/paste or ';if ($ftp!='') $contentout.='<a href="'.$ftp.$folder_cmsimple.'" target="_blank">FTP</a>'; else $contentout.='FTP';
$contentout.=' for restoring data.</p><p>The time of backup can be read from the filename: YYYYMMDDHHMMSS.</p><ul>';
$fd = @opendir($folder_cmsimple); while(($part = @readdir($fd)) == true ) {if (preg_match("/\d{3}\.htm/", $part)) {
$contentout.='<a href="'.$scriptname.'?file='.$part.'&action=view"><li>'.$part.'</a> ('.(round((filesize($folder_cmsimple.'/'.$part))/102.4)/10).' KB)';
}}if($fd==true) { closedir($fd); }$contentout.='</ul>';}
if ($function=='images') {
$contentout.='<h1>Images</h1><p>Use ';if ($ftp!='' && is_dir($folder_image)) $contentout.='<a href="'.$ftp.$folder_image.'" target="_blank">FTP</a>'; else $contentout.='FTP';
$contentout.=' to upload or delete images.</p>';
$totalsize=0;if (is_dir($folder_image)) {
$fd = @opendir($folder_image);
while ( ($part = @readdir($fd)) == true ) {
if (preg_match("/\.gif$|\.jpg$|\.png$/i", $part)) {
$totalsize+=filesize($folder_image.'/'.$part);
$contentout.='<p><img src="'.$folder_image.$part.'"><br>'.$part.' ('.(round((filesize($folder_image.'/'.$part))/102.4)/10).' KB)';
for ($i = 0; $i < count($contentarray); $i++) {
$id_count = preg_match_all('/<img src=["]*([^"]*?)'.'\/'.$part.'["]*(.*?)>/i', $contentarray[$i], $matches, PREG_PATTERN_ORDER);
if ($id_count>0) { $contentout.='<br>Used in '.astart($i,'','').$heading[$i].'</a>';
}}$contentout.='</p>';
}}if($fd==true) { closedir($fd); }
$contentout.='<p>Total size of images: '.(round($totalsize/102.4)/10).' KB.</p>';
} else { $iimage.= '<li>could not open folder_image '.$folder_image; }}
if ($function=='file') {
if (preg_match("/\d{3}\.htm/", $file)) $GLOBALS[$file]=$folder_cmsimple.'/'.$file;
if ($GLOBALS[$file]!='') {
if ($action=='view') {
if ($file=='file_log' || $file=='file_execute') header('Content-Type: text/plain');
echo rmnl(myreadfile($GLOBALS[$file]));exit; }
if ($action=='download') {download($GLOBALS[$file]);}
if ($action=='save') {
if (is_writable($GLOBALS[$file])) {
$fp = fopen($GLOBALS[$file], "w");
fwrite($fp,rmnl(stripslashes($text)));
fclose($fp);} else $error.='<li>could not write to '.$file.' '.$GLOBALS[$file];
} $error.=chkfile($file,true);
$contentout.='<h1>Edit '.$GLOBALS[$file].'</h1><form name="file" action="'.$GLOBALS['scriptname'].'" method="post" style="margin:0"><textarea rows="25" cols="50" name="text" class="edit">'.rmnl(myreadfile($GLOBALS[$file])).'</textarea><input type="hidden" name="file" value="'.$file.'"><input type="hidden" name="action" value="save"> <input type="submit" value="Save" class="edit"></form>';}}
if ($function=='validate') {
$contentout.='<h1>Validate links</h1>';
for ($i = 0; $i < count($contentarray); $i++) {
$id_count = preg_match_all('/<a(.*?)href=["]*([^"]*)["]*(.*?)>(.*?)<\/a>/i', $contentarray[$i], $matches, PREG_PATTERN_ORDER);
if ($id_count>0) {
$contentout.='<h4>'.astart($i,'','').heading($i).'</a> - '.$id_count.' link';
if ($id_count>1) $contentout.='s';
$contentout.=':</h4>';
for ($j=0; $j<$id_count; $j++) {
$contentout.='<p>'.$matches[0][$j].'<br>'.$matches[2][$j].'<br>';
if (trim(strip_tags($matches[0][$j]))=='') $contentout.='<font color="red">NO TEXT IN LINK</font> ';
if (preg_match('/^http/i',$matches[2][$j])) {
if($open = @fopen($matches[2][$j], "r")) $contentout.='<font color="green">EXTERNAL LINK OK</font>'; else $contentout.='<font color="red">EXTERNAL LINK FAILED</font>';
} else { if (preg_match('/^mailto/i',$matches[2][$j])) $contentout.='<font color="orange">MAILTO LINK</font>'; else { $match=false; for ($k = 0; $k < count($contentarray); $k++) { if ($matches[2][$j]==$scriptname.'?'.$url[$k]) $match=true;
} if ($match) $contentout.='<font color="green">INTERNAL LINK OK</font>';
else { if (chkdownload($matches[2][$j])) $contentout.='<font color="green">INTERNAL LINK TO FILE OK</font>'; else $contentout.='<font color="red">INTERNAL LINK FAILED</font>';
}}}$contentout.='</p>';}}}}
if ($function=='save') {
$savednum=$selectednum;
$contentarray[$selectednum]=stripslashes($text);
while(!is_writable($file_content) && file_exists($file_content)) { clearstatcache(); sleep( 1 ); }
$fp = fopen($file_content, "w");
fwrite($fp,'<html><head><link rel="stylesheet" href="'.$scriptname.'?&stylesheet" type="text/css" /></head><body>
');foreach ($contentarray as $item) { fwrite($fp, rmnl($item."\n")); }
fwrite($fp,'</body></html>');fclose($fp);read_file_content();}
if ($edit && (!$function||$function=='save') && !$download) {
if ($selectednum<0 && $savednum<count($contentarray)) $selectednum=$savednum;
if ($selectednum>-1) {
$iimage=null;
if (is_dir($folder_image)) {
$fd = @opendir($folder_image);
while ( ($part = @readdir($fd)) == true ) {
if (preg_match("/\.gif$|\.jpg$|\.png$/i", $part)) {
if ($iimage!='') $iimage.=',';
$iimage.='["'.$folder_image.$part.'","'.substr($part,0,30).'"]';
}}
if($fd==true) { closedir($fd); }
} else { $iimage.= '["","Could not open dir '.$folder_image.'"]'; }
if ($iimage=='') $iimage.= '["","No images in '.$folder_image.'"]';
$ilink=null;
for ($i = 0; $i < count($contentarray); $i++) {
if ($ilink!='') $ilink.=',';
$ilink.='["'.$scriptname.'?'.$url[$i].'","'.substr($heading[$i],0,30).'"]';
}
if (is_dir($folder_download)) {
$fd = @opendir($folder_download);
while ( ($part = @readdir($fd)) == true ) {
if (preg_match("/.*\....$/i", $part)) {
if ($ilink!='') $ilink.=',';
$ilink.='["'.$scriptname.'?download='.$part.'","(File '.(round((filesize($folder_download.'/'.$part))/102.4)/10).' KB)'.' '.substr($part,0,25).'"]';
}} if($fd==true) { closedir($fd); }}
$onload.=' onload="init()"';
$headingjs='<script language="JavaScript">
// OEdit Ver. 3.1 - ?2003 Peter Andreas Harteg - http://www.harteg.dk
var copyright="CMSimple - http://www.harteg.dk"'.$editorsettings.'
var iimage=['.$iimage.']; var ilink=['.$ilink.']; var getimage="'.$scriptname.'?image=";
var format="HTML";
var isNav=(navigator.appName == "Netscape");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -