PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/source/admincp/admincp_checktools.php

https://github.com/kuaileshike/upload
PHP | 589 lines | 529 code | 54 blank | 6 comment | 133 complexity | e3e3adc9da8b495282e173b6fa9d0c20 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: admincp_checktools.php 28265 2012-02-27 02:46:37Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. cpheader();
  12. if(!isfounder()) cpmsg('noaccess_isfounder', '', 'error');
  13. if($operation == 'filecheck') {
  14. $step = max(1, intval($_GET['step']));
  15. shownav('tools', 'nav_filecheck');
  16. showsubmenusteps('nav_filecheck', array(
  17. array('nav_filecheck_confirm', $step == 1),
  18. array('nav_filecheck_verify', $step == 2),
  19. array('nav_filecheck_completed', $step == 3)
  20. ));
  21. if($step == 1) {
  22. cpmsg(cplang('filecheck_tips_step1'), 'action=checktools&operation=filecheck&step=2', 'button', '', FALSE);
  23. } elseif($step == 2) {
  24. cpmsg(cplang('filecheck_verifying'), "action=checktools&operation=filecheck&step=3", 'loading', '', FALSE);
  25. } elseif($step == 3) {
  26. if(!$discuzfiles = @file('./source/admincp/discuzfiles.md5')) {
  27. cpmsg('filecheck_nofound_md5file', '', 'error');
  28. }
  29. $md5data = array();
  30. $cachelist = checkcachefiles('data/sysdata/');
  31. checkfiles('./', '', 0);
  32. checkfiles('config/', '', 1, 'config_global.php,config_ucenter.php');
  33. checkfiles('data/', '\.xml', 0);
  34. checkfiles('data/', '\.htm', 0);
  35. checkfiles('data/log/', '\.htm', 0);
  36. checkfiles('data/plugindata/', '\.htm', 0);
  37. checkfiles('data/download/', '\.htm', 0);
  38. checkfiles('data/addonmd5/', '\.htm', 0);
  39. checkfiles('data/avatar/', '\.htm', 0);
  40. checkfiles('data/cache/', '\.htm', 0);
  41. checkfiles('data/ipdata/', '\.htm|\.dat', 0);
  42. checkfiles('data/template/', '\.htm', 0);
  43. checkfiles('data/threadcache/', '\.htm', 0);
  44. checkfiles('template/', '');
  45. checkfiles('api/', '');
  46. checkfiles('source/', '', 1, 'discuzfiles.md5,plugin');
  47. checkfiles('static/', '');
  48. checkfiles('archiver/', '');
  49. checkfiles('uc_client/', '\.php|\.htm', 0);
  50. checkfiles('uc_client/data/', '\.htm');
  51. checkfiles('uc_client/control/', '\.php|\.htm');
  52. checkfiles('uc_client/model/', '\.php|\.htm');
  53. checkfiles('uc_client/lib/', '\.php|\.htm');
  54. checkfiles('uc_server/', '\.php|\.htm|\.txt|\.xml', 0);
  55. checkfiles('uc_server/data/', '\.htm');
  56. checkfiles('uc_server/api/', '\.php|\.htm');
  57. checkfiles('uc_server/control/', '\.php|\.htm|\.md5');
  58. checkfiles('uc_server/model/', '\.php|\.htm');
  59. checkfiles('uc_server/lib/', '\.php|\.htm');
  60. checkfiles('uc_server/plugin/', '\.php|\.htm|\.xml');
  61. checkfiles('uc_server/upgrade/', '\.php');
  62. checkfiles('uc_server/images/', '\..+?');
  63. checkfiles('uc_server/js/', '\.js|\.htm');
  64. checkfiles('uc_server/release/', '\.php');
  65. checkfiles('uc_server/view/', '\.php|\.htm');
  66. foreach($discuzfiles as $line) {
  67. $file = trim(substr($line, 34));
  68. $md5datanew[$file] = substr($line, 0, 32);
  69. if($md5datanew[$file] != $md5data[$file]) {
  70. $modifylist[$file] = $md5data[$file];
  71. }
  72. $md5datanew[$file] = $md5data[$file];
  73. }
  74. $weekbefore = TIMESTAMP - 604800;
  75. $addlist = @array_merge(@array_diff_assoc($md5data, $md5datanew), $cachelist[2]);
  76. $dellist = @array_diff_assoc($md5datanew, $md5data);
  77. $modifylist = @array_merge(@array_diff_assoc($modifylist, $dellist), $cachelist[1]);
  78. $showlist = @array_merge($md5data, $md5datanew, $cachelist[0]);
  79. $doubt = 0;
  80. $dirlist = $dirlog = array();
  81. foreach($showlist as $file => $md5) {
  82. $dir = dirname($file);
  83. if(@array_key_exists($file, $modifylist)) {
  84. $fileststus = 'modify';
  85. } elseif(@array_key_exists($file, $dellist)) {
  86. $fileststus = 'del';
  87. } elseif(@array_key_exists($file, $addlist)) {
  88. $fileststus = 'add';
  89. } else {
  90. $filemtime = @filemtime($file);
  91. if($filemtime > $weekbefore) {
  92. $fileststus = 'doubt';
  93. $doubt++;
  94. } else {
  95. $fileststus = '';
  96. }
  97. }
  98. if(file_exists($file)) {
  99. $filemtime = @filemtime($file);
  100. $fileststus && $dirlist[$fileststus][$dir][basename($file)] = array(number_format(filesize($file)).' Bytes', dgmdate($filemtime));
  101. } else {
  102. $fileststus && $dirlist[$fileststus][$dir][basename($file)] = array('', '');
  103. }
  104. }
  105. $result = $resultjs = '';
  106. $dirnum = 0;
  107. foreach($dirlist as $status => $filelist) {
  108. $dirnum++;
  109. $class = $status == 'modify' ? 'edited' : ($status == 'del' ? 'del' : 'unknown');
  110. $result .= '<tbody id="status_'.$status.'" style="display:'.($status != 'modify' ? 'none' : '').'">';
  111. foreach($filelist as $dir => $files) {
  112. $result .= '<tr><td colspan="4"><div class="ofolder">'.$dir.'</div><div class="margintop marginbot">';
  113. foreach($files as $filename => $file) {
  114. $result .= '<tr><td><em class="files bold">'.$filename.'</em></td><td style="text-align: right">'.$file[0].'&nbsp;&nbsp;</td><td>'.$file[1].'</td><td><em class="'.$class.'">&nbsp;</em></td></tr>';
  115. }
  116. }
  117. $result .= '</tbody>';
  118. $resultjs .= '$(\'status_'.$status.'\').style.display=\'none\';';
  119. }
  120. $modifiedfiles = count($modifylist);
  121. $deletedfiles = count($dellist);
  122. $unknownfiles = count($addlist);
  123. $doubt = intval($doubt);
  124. $result .= '<script>function showresult(o) {'.$resultjs.'$(\'status_\' + o).style.display=\'\';}</script>';
  125. showtips('filecheck_tips');
  126. showtableheader('filecheck_completed');
  127. showtablerow('', 'colspan="4"', "<div class=\"margintop marginbot\">".
  128. "<em class=\"edited\">$lang[filecheck_modify]: $modifiedfiles</em> ".($modifiedfiles > 0 ? "<a href=\"###\" onclick=\"showresult('modify')\">[$lang[view]]</a> " : '').
  129. " &nbsp; <em class=\"del\">$lang[filecheck_delete]: $deletedfiles</em> ".($deletedfiles > 0 ? "<a href=\"###\" onclick=\"showresult('del')\">[$lang[view]]</a> " : '').
  130. " &nbsp; <em class=\"unknown\">$lang[filecheck_unknown]: $unknownfiles</em> ".($unknownfiles > 0 ? "<a href=\"###\" onclick=\"showresult('add')\">[$lang[view]]</a> " : '').
  131. ($doubt > 0 ? "&nbsp;&nbsp;&nbsp;&nbsp;<em class=\"unknown\">$lang[filecheck_doubt]: $doubt</em> <a href=\"###\" onclick=\"showresult('doubt')\">[$lang[view]]</a> " : '').
  132. "</div>");
  133. showsubtitle(array('filename', '', 'lastmodified', ''));
  134. echo $result;
  135. showtablefooter();
  136. }
  137. } elseif($operation == 'hookcheck') {
  138. $step = max(1, intval($_GET['step']));
  139. shownav('tools', 'nav_hookcheck');
  140. showsubmenusteps('nav_hookcheck', array(
  141. array('nav_hookcheck_confirm', $step == 1),
  142. array('nav_hookcheck_verify', $step == 2),
  143. array('nav_hookcheck_completed', $step == 3)
  144. ));
  145. showtips('hookcheck_tips');
  146. if($step == 1) {
  147. $styleselect = "<br><br><select name=\"styleid\">";
  148. foreach(C::t('common_style')->fetch_all_data() as $style) {
  149. $styleselect .= "<option value=\"$style[styleid]\" ".
  150. ($style['styleid'] == $_G['setting']['styleid'] ? 'selected="selected"' : NULL).
  151. ">$style[name]</option>\n";
  152. }
  153. $styleselect .= '</select>';
  154. cpmsg(cplang('hookcheck_tips_step1', array('template' => $styleselect)), 'action=checktools&operation=hookcheck&step=2', 'form', '', FALSE);
  155. } elseif($step == 2) {
  156. cpmsg(cplang('hookcheck_verifying'), "action=checktools&operation=hookcheck&step=3&styleid=$_POST[styleid]", 'loading', '', FALSE);
  157. } elseif($step == 3) {
  158. if(!$discuzfiles = @file('./source/admincp/discuzhook.dat')) {
  159. cpmsg('filecheck_nofound_md5file', '', 'error');
  160. }
  161. $discuzhookdata = $hookdata = array();
  162. $discuzhookdata_hook = array();
  163. $styleid = intval($_GET['styleid']);
  164. if(!$styleid) {
  165. $styleid = $_G['setting']['styleid'];
  166. }
  167. $style = C::t('common_style')->fetch_by_styleid($styleid);
  168. checkhook(substr($style['directory'], 2).'/', '\.htm', 1);
  169. foreach($discuzfiles as $line) {
  170. list($file, $hook) = explode(' *', substr($line, 0, -2));
  171. if($hook) {
  172. $discuzhookdata[$file][$hook][] = $hook;
  173. $discuzhookdata_hook[$file][] = $hook;
  174. }
  175. }
  176. $diffhooklist = $difffilelist = array();
  177. $diffnum = 0;
  178. foreach($discuzhookdata as $file => $hook) {
  179. $dir = dirname($file);
  180. if(isset($hookdata[$file])) {
  181. foreach($hook as $k => $hookarr) {
  182. if(($diff = count($hookarr) - count($hookdata[$file][$k])) > 0) {
  183. for($i = 0; $i < $diff; $i++) {
  184. $diffhooklist[$file][] = $k;
  185. }
  186. }
  187. }
  188. if(!empty($diffhooklist[$file])) {
  189. $difffilelist[$dir][] = $file;
  190. $diffnum++;
  191. }
  192. }
  193. }
  194. foreach($difffilelist as $dir => $files) {
  195. $result .= '<tbody><tr><td class="td30"><a href="javascript:;" onclick="toggle_group(\'dir_'.$dir.'\')" id="a_dir_'.$dir.'">[-]</a></td><td colspan="3"><div class="ofolder">'.$dir.'</div></td></tr></tbody>';
  196. $result .= '<tbody id="dir_'.$dir.'">';
  197. foreach($files as $file) {
  198. $result .= '<tr><td></td><td><em class="files bold">'.basename($file).'</em></td><td>';
  199. foreach($discuzhookdata_hook[$file] as $hook) {
  200. $result .= '<p>'.dhtmlspecialchars($hook).'</p>';
  201. }
  202. $result .= '</td><td>';
  203. foreach($diffhooklist[$file] as $hook) {
  204. $result .= '<p>'.dhtmlspecialchars($hook).'</p>';
  205. }
  206. $result .= '</td></tr>';
  207. }
  208. $result .= '</tbody>';
  209. }
  210. if($diffnum > 20) {
  211. $result .= '<script type="text/javascript">hide_all_hook(\'dir_\', \'tbody\');</script>';
  212. }
  213. if($diffnum) {
  214. showformheader('forums');
  215. showtableheader('hookcheck_completed');
  216. showtablerow('', 'colspan="4"', "<div class=\"margintop marginbot\">".
  217. '<a href="javascript:;" onclick="show_all_hook(\'dir_\', \'tbody\')">'.$lang[show_all].'</a> | <a href="javascript:;" onclick="hide_all_hook(\'dir_\', \'tbody\')">'.$lang[hide_all].'</a>'.
  218. " &nbsp; <em class=\"del\">$lang[hookcheck_delete]: $diffnum</em> ".
  219. "</div>");
  220. showsubtitle(array('', 'filename', 'hookcheck_discuzhook', 'hookcheck_delhook'));
  221. echo $result;
  222. showtablefooter();
  223. showformfooter();
  224. } else {
  225. cpmsg('hookcheck_nodelhook', '', 'succeed', '', FALSE);
  226. }
  227. }
  228. } elseif($operation == 'ftpcheck') {
  229. $alertmsg = '';
  230. $testcontent = md5('Discuz!' + $_G['config']['security']['authkey']);
  231. $testfile = 'test/discuztest.txt';
  232. $attach_dir = $_G['setting']['attachdir'];
  233. @mkdir($attach_dir.'test', 0777);
  234. if($fp = @fopen($attach_dir.'/'.$testfile, 'w')) {
  235. fwrite($fp, $testcontent);
  236. fclose($fp);
  237. }
  238. if(!$alertmsg) {
  239. $settingnew = $_GET['settingnew'];
  240. $settings['ftp'] = C::t('common_setting')->fetch('ftp', true);
  241. $settings['ftp']['password'] = authcode($settings['ftp']['password'], 'DECODE', md5($_G['config']['security']['authkey']));
  242. $pwlen = strlen($settingnew['ftp']['password']);
  243. if($settingnew['ftp']['password']{0} == $settings['ftp']['password']{0} && $settingnew['ftp']['password']{$pwlen - 1} == $settings['ftp']['password']{strlen($settings['ftp']['password']) - 1} && substr($settingnew['ftp']['password'], 1, $pwlen - 2) == '********') {
  244. $settingnew['ftp']['password'] = $settings['ftp']['password'];
  245. }
  246. $settingnew['ftp']['password'] = authcode($settingnew['ftp']['password'], 'ENCODE', md5($_G['config']['security']['authkey']));
  247. $settingnew['ftp']['attachurl'] .= substr($settingnew['ftp']['attachurl'], -1, 1) != '/' ? '/' : '';
  248. $_G['setting']['ftp'] = $settingnew['ftp'];
  249. ftpcmd('upload', $testfile);
  250. $ftp = ftpcmd('object');
  251. if(ftpcmd('error')) {
  252. $alertmsg = cplang('setting_attach_remote_'.ftpcmd('error'));
  253. }
  254. if(!$alertmsg) {
  255. $str = getremotefile($_G['setting']['ftp']['attachurl'].$testfile);
  256. if($str !== $testcontent) {
  257. $alertmsg = cplang('setting_attach_remote_geterr');
  258. }
  259. }
  260. if(!$alertmsg) {
  261. ftpcmd('delete', $testfile);
  262. ftpcmd('delete', 'test/index.htm');
  263. $ftp->ftp_rmdir('test');
  264. $str = getremotefile($_G['setting']['ftp']['attachurl'].$testfile);
  265. if($str === $testcontent) {
  266. $alertmsg = cplang('setting_attach_remote_delerr');
  267. }
  268. @unlink($attach_dir.'/'.$testfile);
  269. @rmdir($attach_dir.'test');
  270. }
  271. }
  272. if(!$alertmsg) {
  273. $alertmsg = cplang('setting_attach_remote_ok');
  274. }
  275. echo '<script language="javascript">alert(\''.str_replace('\'', '\\\'', $alertmsg).'\');parent.$(\'cpform\').action=\''.ADMINSCRIPT.'?action=setting&edit=yes\';parent.$(\'cpform\').target=\'_self\'</script>';
  276. } elseif($operation == 'mailcheck') {
  277. $oldmail = dunserialize($_G['setting']['mail']);
  278. $settingnew = $_GET['settingnew'];
  279. $oldsmtp = $settingnew['mail']['mailsend'] == 3 ? $settingnew['mail']['smtp'] : $settingnew['mail']['esmtp'];
  280. $deletesmtp = $settingnew['mail']['mailsend'] != 1 ? ($settingnew['mail']['mailsend'] == 3 ? $settingnew['mail']['smtp']['delete'] : $settingnew['mail']['esmtp']['delete']) : array();
  281. $settingnew['mail']['smtp'] = array();
  282. foreach($oldsmtp as $id => $value) {
  283. if((empty($deletesmtp) || !in_array($id, $deletesmtp)) && !empty($value['server']) && !empty($value['port'])) {
  284. $passwordmask = $oldmail['smtp'][$id]['auth_password'] ? $oldmail['smtp'][$id]['auth_password']{0}.'********'.substr($oldmail['smtp'][$id]['auth_password'], -2) : '';
  285. $value['auth_password'] = $value['auth_password'] == $passwordmask ? $oldmail['smtp'][$id]['auth_password'] : $value['auth_password'];
  286. $settingnew['mail']['smtp'][] = $value;
  287. }
  288. }
  289. if(!empty($_GET['newsmtp'])) {
  290. foreach($_GET['newsmtp']['server'] as $id => $smtp) {
  291. if(!empty($smtp) && !empty($_GET['newsmtp']['port'][$id])) {
  292. $settingnew['mail']['smtp'][] = array(
  293. 'server' => $smtp,
  294. 'port' => $_GET['newsmtp']['port'][$id] ? intval($_GET['newsmtp']['port'][$id]) : 25,
  295. 'auth' => $_GET['newsmtp']['auth'][$id] ? 1 : 0,
  296. 'from' => $_GET['newsmtp']['from'][$id],
  297. 'auth_username' => $_GET['newsmtp']['auth_username'][$id],
  298. 'auth_password' => $_GET['newsmtp']['auth_password'][$id]
  299. );
  300. }
  301. }
  302. }
  303. $_G['setting']['mail'] = serialize($settingnew['mail']);
  304. $test_to = $_GET['test_to'];
  305. $test_from = $_GET['test_from'];
  306. $date = date('Y-m-d H:i:s');
  307. $alertmsg = '';
  308. $title = $lang['setting_mailcheck_title_'.$settingnew['mail']['mailsend']];
  309. $message = $lang['setting_mailcheck_message_'.$settingnew['mail']['mailsend']].' '.$test_from.$lang['setting_mailcheck_date'].' '.$date;
  310. $_G['setting']['bbname'] = $lang['setting_mail_check_method_1'];
  311. include libfile('function/mail');
  312. $succeed = sendmail($test_to, $title.' @ '.$date, $_G['setting']['bbname']."\n\n\n$message", $test_from);
  313. $_G['setting']['bbname'] = $lang['setting_mail_check_method_2'];
  314. $succeed = sendmail($test_to, $title.' @ '.$date, $_G['setting']['bbname']."\n\n\n$message", $test_from);
  315. if($succeed) {
  316. $alertmsg = $lang['setting_mail_check_success_1']."$title @ $date".$lang['setting_mail_check_success_2'];
  317. } else {
  318. $alertmsg = $lang['setting_mail_check_error'].$alertmsg;
  319. }
  320. echo '<script language="javascript">alert(\''.str_replace(array('\'', "\n", "\r"), array('\\\'', '\n', ''), $alertmsg).'\');parent.$(\'cpform\').action=\''.ADMINSCRIPT.'?action=setting&edit=yes\';parent.$(\'cpform\').target=\'_self\';parent.$(\'cpform\').operation.value=\'mail\';</script>';
  321. } elseif($operation == 'imagepreview') {
  322. $settingnew = $_GET['settingnew'];
  323. if(!empty($_GET['previewthumb'])) {
  324. $_G['setting']['imagelib'] = $settingnew['imagelib'];
  325. $_G['setting']['imageimpath'] = $settingnew['imageimpath'];
  326. $_G['setting']['thumbwidth'] = $settingnew['thumbwidth'];
  327. $_G['setting']['thumbheight'] = $settingnew['thumbheight'];
  328. $_G['setting']['thumbquality'] = $settingnew['thumbquality'];
  329. require_once libfile('class/image');
  330. @unlink(DISCUZ_ROOT.'./data/attachment/temp/watermark_temp1.jpg');
  331. @unlink(DISCUZ_ROOT.'./data/attachment/temp/watermark_temp2.jpg');
  332. $image = new image;
  333. $r = 0;
  334. if(!($r = $image->Thumb(DISCUZ_ROOT.'./static/image/admincp/watermarkpreview.jpg', 'temp/watermark_temp1.jpg', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], 1))) {
  335. $r = $image->error();
  336. }
  337. $sizetarget1 = $image->imginfo['size'];
  338. $image->Thumb(DISCUZ_ROOT.'./static/image/admincp/watermarkpreview.jpg', 'temp/watermark_temp2.jpg', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], 2);
  339. $sizetarget2 = $image->imginfo['size'];
  340. if($r > 0) {
  341. showsubmenu('imagepreview_thumb');
  342. $sizesource = filesize(DISCUZ_ROOT.'./static/image/admincp/watermarkpreview.jpg');
  343. echo '<img src="data/attachment/temp/watermark_temp1.jpg?'.random(5).'"><br /><br />'.
  344. $lang['imagepreview_imagesize_source'].' '.number_format($sizesource).' Bytes &nbsp;&nbsp;'.
  345. $lang['imagepreview_imagesize_target'].' '.number_format($sizetarget1).' Bytes ('.
  346. (sprintf("%2.1f", $sizetarget1 / $sizesource * 100)).'%)<br /><br />';
  347. echo '<img src="data/attachment/temp/watermark_temp2.jpg?'.random(5).'"><br /><br />'.
  348. $lang['imagepreview_imagesize_source'].' '.number_format($sizesource).' Bytes &nbsp;&nbsp;'.
  349. $lang['imagepreview_imagesize_target'].' '.number_format($sizetarget2).' Bytes ('.
  350. (sprintf("%2.1f", $sizetarget2 / $sizesource * 100)).'%)';
  351. } else {
  352. cpmsg('imagepreview_errorcode_'.$r, '', 'error');
  353. }
  354. } else {
  355. $type = $_GET['type'];
  356. if(!$_G['setting']['watermarkstatus'][$type]) {
  357. cpmsg('watermarkpreview_error', '', 'error');
  358. }
  359. require_once libfile('class/image');
  360. @unlink(DISCUZ_ROOT.'./data/attachment/temp/watermark_temp3.jpg');
  361. $image = new image;
  362. if(!($r = $image->Watermark(DISCUZ_ROOT.'./static/image/admincp/watermarkpreview.jpg', 'temp/watermark_temp3.jpg', $type))) {
  363. $r = $image->error();
  364. }
  365. if($r > 0) {
  366. showsubmenu('imagepreview_watermark');
  367. $sizesource = filesize('static/image/admincp/watermarkpreview.jpg');
  368. $sizetarget = $image->imginfo['size'];
  369. echo '<img src="data/attachment/temp/watermark_temp3.jpg?'.random(5).'"><br /><br />'.
  370. $lang['imagepreview_imagesize_source'].' '.number_format($sizesource).' Bytes &nbsp;&nbsp;'.
  371. $lang['imagepreview_imagesize_target'].' '.number_format($sizetarget).' Bytes ('.
  372. (sprintf("%2.1f", $sizetarget / $sizesource * 100)).'%)';
  373. } else {
  374. cpmsg('imagepreview_errorcode_'.$r, '', 'error');
  375. }
  376. }
  377. } elseif($operation == 'rewrite') {
  378. $rule = array();
  379. $rewritedata = rewritedata();
  380. $rule['{apache1}'] = $rule['{apache2}'] = $rule['{iis}'] = $rule['{iis7}'] = $rule['{zeus}'] = $rule['{nginx}'] = '';
  381. foreach($rewritedata['rulesearch'] as $k => $v) {
  382. if(!in_array($k, $_G['setting']['rewritestatus'])) {
  383. continue;
  384. }
  385. $v = !$_G['setting']['rewriterule'][$k] ? $v : $_G['setting']['rewriterule'][$k];
  386. $pvmaxv = count($rewritedata['rulevars'][$k]) + 2;
  387. $vkeys = array_keys($rewritedata['rulevars'][$k]);
  388. $rewritedata['rulereplace'][$k] = pvsort($vkeys, $v, $rewritedata['rulereplace'][$k]);
  389. $v = str_replace($vkeys, $rewritedata['rulevars'][$k], addcslashes($v, '?*+^$.[]()|'));
  390. $rule['{apache1}'] .= "\t".'RewriteCond %{QUERY_STRING} ^(.*)$'."\n\t".'RewriteRule ^(.*)/'.$v.'$ $1/'.pvadd($rewritedata['rulereplace'][$k])."&%1\n";
  391. if($k != 'forum_archiver') {
  392. $rule['{apache2}'] .= 'RewriteCond %{QUERY_STRING} ^(.*)$'."\n".'RewriteRule ^'.$v.'$ '.$rewritedata['rulereplace'][$k]."&%1\n";
  393. } else {
  394. $rule['{apache2}'] .= 'RewriteCond %{QUERY_STRING} ^(.*)$'."\n".'RewriteRule ^archiver/'.$v.'$ archiver/'.$rewritedata['rulereplace'][$k]."&%1\n";
  395. }
  396. $rule['{iis}'] .= 'RewriteRule ^(.*)/'.$v.'(\?(.*))*$ $1/'.addcslashes(pvadd($rewritedata['rulereplace'][$k]).'&$'.($pvmaxv + 1), '.?')."\n";
  397. $rule['{iis7}'] .= "\t\t".'&lt;rule name="'.$k.'"&gt;'."\n\t\t\t".'&lt;match url="^(.*/)*'.str_replace('\.', '.', $v).'\?*(.*)$" /&gt;'."\n\t\t\t".'&lt;action type="Rewrite" url="{R:1}/'.str_replace(array('&', 'page\%3D'), array('&amp;amp;', 'page%3D'), addcslashes(pvadd($rewritedata['rulereplace'][$k], 1).'&{R:'.$pvmaxv.'}', '?')).'" /&gt;'."\n\t\t".'&lt;/rule&gt;'."\n";
  398. $rule['{zeus}'] .= 'match URL into $ with ^(.*)/'.$v.'\?*(.*)$'."\n".'if matched then'."\n\t".'set URL = $1/'.pvadd($rewritedata['rulereplace'][$k]).'&$'.$pvmaxv."\nendif\n";
  399. $rule['{nginx}'] .= 'rewrite ^([^\.]*)/'.$v.'$ $1/'.stripslashes(pvadd($rewritedata['rulereplace'][$k]))." last;\n";
  400. }
  401. $rule['{nginx}'] .= "if (!-e \$request_filename) {\n\treturn 404;\n}";
  402. echo str_replace(array_keys($rule), $rule, cplang('rewrite_message'));
  403. } elseif($operation == 'robots') {
  404. if($do == 'output') {
  405. $robots = implode('', file(DISCUZ_ROOT.'./source/admincp/robots.txt'));
  406. $robots = str_replace('{path}', $_G['siteroot'], $robots);
  407. $robots = str_replace('{ver}', $_G['setting']['version'], $robots);
  408. ob_end_clean();
  409. dheader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  410. dheader('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  411. dheader('Cache-Control: no-cache, must-revalidate');
  412. dheader('Pragma: no-cache');
  413. dheader('Content-Encoding: none');
  414. dheader('Content-Length: '.strlen($robots));
  415. dheader('Content-Disposition: attachment; filename=robots.txt');
  416. dheader('Content-Type: text/plain');
  417. echo $robots;
  418. define('FOOTERDISABLED' , 1);
  419. exit();
  420. }
  421. cpmsg('robots_output', 'action=checktools&operation=robots&do=output&frame=no', 'download', array('siteurl' => $_G['siteurl']));
  422. }
  423. function pvsort($key, $v, $s) {
  424. $r = '/';
  425. $p = '';
  426. foreach($key as $k) {
  427. $r .= $p.preg_quote($k);
  428. $p = '|';
  429. }
  430. $r .= '/';
  431. preg_match_all($r, $v, $a);
  432. $a = $a[0];
  433. $a = array_flip($a);
  434. foreach($a as $key => $value) {
  435. $s = str_replace($key, '$'.($value + 1), $s);
  436. }
  437. return $s;
  438. }
  439. function pvadd($s, $t = 0) {
  440. $s = str_replace(array('$3', '$2', '$1'), array('~4', '~3', '~2'), $s);
  441. if(!$t) {
  442. return str_replace(array('~4', '~3', '~2'), array('$4', '$3', '$2'), $s);
  443. } else {
  444. return str_replace(array('~4', '~3', '~2'), array('{R:4}', '{R:3}', '{R:2}'), $s);
  445. }
  446. }
  447. function checkfiles($currentdir, $ext = '', $sub = 1, $skip = '') {
  448. global $md5data;
  449. $dir = @opendir(DISCUZ_ROOT.$currentdir);
  450. $exts = '/('.$ext.')$/i';
  451. $skips = explode(',', $skip);
  452. while($entry = @readdir($dir)) {
  453. $file = $currentdir.$entry;
  454. if($entry != '.' && $entry != '..' && (($ext && preg_match($exts, $entry) || !$ext) || $sub && is_dir($file)) && !in_array($entry, $skips)) {
  455. if($sub && is_dir($file)) {
  456. checkfiles($file.'/', $ext, $sub, $skip);
  457. } else {
  458. if(is_dir($file)) {
  459. $md5data[$file] = md5($file);
  460. } else {
  461. $md5data[$file] = md5_file($file);
  462. }
  463. }
  464. }
  465. }
  466. }
  467. function checkcachefiles($currentdir) {
  468. global $_G;
  469. $dir = opendir($currentdir);
  470. $exts = '/\.php$/i';
  471. $showlist = $modifylist = $addlist = array();
  472. while($entry = readdir($dir)) {
  473. $file = $currentdir.$entry;
  474. if($entry != '.' && $entry != '..' && preg_match($exts, $entry)) {
  475. $fp = fopen($file, "rb");
  476. $cachedata = fread($fp, filesize($file));
  477. fclose($fp);
  478. if(preg_match("/^<\?php\n\/\/Discuz! cache file, DO NOT modify me!\n\/\/Identify: (\w+)\n\n(.+?)\?>$/s", $cachedata, $match)) {
  479. $showlist[$file] = $md5 = $match[1];
  480. $cachedata = $match[2];
  481. if(md5($entry.$cachedata.$_G['config']['security']['authkey']) != $md5) {
  482. $modifylist[$file] = $md5;
  483. }
  484. } else {
  485. $showlist[$file] = '';
  486. }
  487. }
  488. }
  489. return array($showlist, $modifylist, $addlist);
  490. }
  491. function checkmailerror($type, $error) {
  492. global $alertmsg;
  493. $alertmsg .= !$alertmsg ? $error : '';
  494. }
  495. function getremotefile($file) {
  496. global $_G;
  497. @set_time_limit(0);
  498. $file = $file.'?'.TIMESTAMP.rand(1000, 9999);
  499. $str = @implode('', @file($file));
  500. if(!$str) {
  501. $str = dfsockopen($file);
  502. }
  503. return $str;
  504. }
  505. function checkhook($currentdir, $ext = '', $sub = 1, $skip = '') {
  506. global $hooks, $hookdata;
  507. $dir = opendir($currentdir);
  508. $exts = '/('.$ext.')$/i';
  509. $skips = explode(',', $skip);
  510. while($entry = readdir($dir)) {
  511. $file = $currentdir.$entry;
  512. if($entry != '.' && $entry != '..' && (preg_match($exts, $entry) || $sub && is_dir($file)) && !in_array($entry, $skips)) {
  513. if($sub && is_dir($file)) {
  514. checkhook($file.'/', $ext, $sub, $skip);
  515. } else {
  516. $data = file_get_contents($file);
  517. $hooks = array();
  518. preg_replace("/\{hook\/(\w+?)(\s+(.+?))?\}/ie", "findhook('\\1', '\\3')", $data);
  519. if($hooks) {
  520. foreach($hooks as $v) {
  521. $hookdata[$file][$v][] = $v;
  522. }
  523. }
  524. }
  525. }
  526. }
  527. }
  528. function findhook($hookid, $key) {
  529. global $hooks;
  530. if($key) {
  531. $key = ' '.$key;
  532. }
  533. $hooks[] = '<!--{hook/'.$hookid.$key.'}-->';
  534. }
  535. ?>