PageRenderTime 62ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/miles/GlobalMBA/mba/sns_00/upload/bbs/install/func.inc.php

#
PHP | 1202 lines | 1121 code | 75 blank | 6 comment | 118 complexity | f02e5b0a05d4980619f34d5953274d4a MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /*
  3. [Discuz!] (C)2001-2009 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: func.inc.php 21095 2009-11-12 05:13:39Z liulanbo $
  6. */
  7. if(!defined('IN_COMSENZ')) {
  8. exit('Access Denied');
  9. }
  10. function show_msg($error_no, $error_msg = 'ok', $success = 1, $quit = TRUE) {
  11. if(VIEW_OFF) {
  12. $error_code = $success ? 0 : constant(strtoupper($error_no));
  13. $error_msg = empty($error_msg) ? $error_no : $error_msg;
  14. $error_msg = str_replace('"', '\"', $error_msg);
  15. $str = "<root>\n";
  16. $str .= "\t<error errorCode=\"$error_code\" errorMessage=\"$error_msg\" />\n";
  17. $str .= "</root>";
  18. echo $str;
  19. exit;
  20. } else {
  21. show_header();
  22. global $step;
  23. $title = lang($error_no);
  24. $comment = lang($error_no.'_comment', false);
  25. $errormsg = '';
  26. if($error_msg) {
  27. if(!empty($error_msg)) {
  28. foreach ((array)$error_msg as $k => $v) {
  29. if(is_numeric($k)) {
  30. $comment .= "<li><em class=\"red\">".lang($v)."</em></li>";
  31. }
  32. }
  33. }
  34. }
  35. if($step > 0) {
  36. echo "<div class=\"desc\"><b>$title</b><ul>$comment</ul>";
  37. } else {
  38. echo "</div><div class=\"main\" style=\"margin-top: -123px;\"><b>$title</b><ul style=\"line-height: 200%; margin-left: 30px;\">$comment</ul>";
  39. }
  40. if($quit) {
  41. echo '<br /><span class="red">'.lang('error_quit_msg').'</span><br /><br /><br />';
  42. }
  43. echo '<input type="button" onclick="history.back()" value="'.lang('click_to_back').'" /><br /><br /><br />';
  44. echo '</div>';
  45. $quit && show_footer();
  46. }
  47. }
  48. function check_db($dbhost, $dbuser, $dbpw, $dbname, $tablepre) {
  49. if(!function_exists('mysql_connect')) {
  50. show_msg('undefine_func', 'mysql_connect', 0);
  51. }
  52. if(!@mysql_connect($dbhost, $dbuser, $dbpw)) {
  53. $errno = mysql_errno();
  54. $error = mysql_error();
  55. if($errno == 1045) {
  56. show_msg('database_errno_1045', $error, 0);
  57. } elseif($errno == 2003) {
  58. show_msg('database_errno_2003', $error, 0);
  59. } else {
  60. show_msg('database_connect_error', $error, 0);
  61. }
  62. } else {
  63. if($query = mysql_query("SHOW TABLES FROM $dbname")) {
  64. while($row = mysql_fetch_row($query)) {
  65. if(preg_match("/^$tablepre/", $row[0])) {
  66. return false;
  67. }
  68. }
  69. }
  70. }
  71. return true;
  72. }
  73. function dirfile_check(&$dirfile_items) {
  74. foreach($dirfile_items as $key => $item) {
  75. $item_path = $item['path'];
  76. if($item['type'] == 'dir') {
  77. if(!dir_writeable(ROOT_PATH.$item_path)) {
  78. if(is_dir(ROOT_PATH.$item_path)) {
  79. $dirfile_items[$key]['status'] = 0;
  80. $dirfile_items[$key]['current'] = '+r';
  81. } else {
  82. $dirfile_items[$key]['status'] = -1;
  83. $dirfile_items[$key]['current'] = 'nodir';
  84. }
  85. } else {
  86. $dirfile_items[$key]['status'] = 1;
  87. $dirfile_items[$key]['current'] = '+r+w';
  88. }
  89. } else {
  90. if(file_exists(ROOT_PATH.$item_path)) {
  91. if(is_writable(ROOT_PATH.$item_path)) {
  92. $dirfile_items[$key]['status'] = 1;
  93. $dirfile_items[$key]['current'] = '+r+w';
  94. } else {
  95. $dirfile_items[$key]['status'] = 0;
  96. $dirfile_items[$key]['current'] = '+r';
  97. }
  98. } else {
  99. if(dir_writeable(dirname(ROOT_PATH.$item_path))) {
  100. $dirfile_items[$key]['status'] = 1;
  101. $dirfile_items[$key]['current'] = '+r+w';
  102. } else {
  103. $dirfile_items[$key]['status'] = -1;
  104. $dirfile_items[$key]['current'] = 'nofile';
  105. }
  106. }
  107. }
  108. }
  109. }
  110. function env_check(&$env_items) {
  111. foreach($env_items as $key => $item) {
  112. if($key == 'php') {
  113. $env_items[$key]['current'] = PHP_VERSION;
  114. } elseif($key == 'attachmentupload') {
  115. $env_items[$key]['current'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknow';
  116. } elseif($key == 'gdversion') {
  117. $tmp = function_exists('gd_info') ? gd_info() : array();
  118. $env_items[$key]['current'] = empty($tmp['GD Version']) ? 'noext' : $tmp['GD Version'];
  119. unset($tmp);
  120. } elseif($key == 'diskspace') {
  121. if(function_exists('disk_free_space')) {
  122. $env_items[$key]['current'] = floor(disk_free_space(ROOT_PATH) / (1024*1024)).'M';
  123. } else {
  124. $env_items[$key]['current'] = 'unknow';
  125. }
  126. } elseif(isset($item['c'])) {
  127. $env_items[$key]['current'] = constant($item['c']);
  128. }
  129. $env_items[$key]['status'] = 1;
  130. if($item['r'] != 'notset' && strcmp($env_items[$key]['current'], $item['r']) < 0) {
  131. $env_items[$key]['status'] = 0;
  132. }
  133. }
  134. }
  135. function function_check(&$func_items) {
  136. foreach($func_items as $item) {
  137. function_exists($item) or show_msg('undefine_func', $item, 0);
  138. }
  139. }
  140. function show_env_result(&$env_items, &$dirfile_items, &$func_items) {
  141. $env_str = $file_str = $dir_str = $func_str = '';
  142. $error_code = 0;
  143. foreach($env_items as $key => $item) {
  144. if($key == 'php' && strcmp($item['current'], $item['r']) < 0) {
  145. show_msg('php_version_too_low', $item['current'], 0);
  146. }
  147. $status = 1;
  148. if($item['r'] != 'notset') {
  149. if(intval($item['current']) && intval($item['r'])) {
  150. if(intval($item['current']) < intval($item['r'])) {
  151. $status = 0;
  152. $error_code = ENV_CHECK_ERROR;
  153. }
  154. } else {
  155. if(strcmp($item['current'], $item['r']) < 0) {
  156. $status = 0;
  157. $error_code = ENV_CHECK_ERROR;
  158. }
  159. }
  160. }
  161. if(VIEW_OFF) {
  162. $env_str .= "\t\t<runCondition name=\"$key\" status=\"$status\" Require=\"$item[r]\" Best=\"$item[b]\" Current=\"$item[current]\"/>\n";
  163. } else {
  164. $env_str .= "<tr>\n";
  165. $env_str .= "<td>".lang($key)."</td>\n";
  166. $env_str .= "<td class=\"padleft\">".lang($item['r'])."</td>\n";
  167. $env_str .= "<td class=\"padleft\">".lang($item['b'])."</td>\n";
  168. $env_str .= ($status ? "<td class=\"w pdleft1\">" : "<td class=\"nw pdleft1\">").$item['current']."</td>\n";
  169. $env_str .= "</tr>\n";
  170. }
  171. }
  172. foreach($dirfile_items as $key => $item) {
  173. $tagname = $item['type'] == 'file' ? 'File' : 'Dir';
  174. $variable = $item['type'].'_str';
  175. if(VIEW_OFF) {
  176. if($item['status'] == 0) {
  177. $error_code = ENV_CHECK_ERROR;
  178. }
  179. $$variable .= "\t\t\t<File name=\"$item[path]\" status=\"$item[status]\" requirePermisson=\"+r+w\" currentPermisson=\"$item[current]\" />\n";
  180. } else {
  181. $$variable .= "<tr>\n";
  182. $$variable .= "<td>$item[path]</td><td class=\"w pdleft1\">".lang('writeable')."</td>\n";
  183. if($item['status'] == 1) {
  184. $$variable .= "<td class=\"w pdleft1\">".lang('writeable')."</td>\n";
  185. } elseif($item['status'] == -1) {
  186. $error_code = ENV_CHECK_ERROR;
  187. $$variable .= "<td class=\"nw pdleft1\">".lang('nodir')."</td>\n";
  188. } else {
  189. $error_code = ENV_CHECK_ERROR;
  190. $$variable .= "<td class=\"nw pdleft1\">".lang('unwriteable')."</td>\n";
  191. }
  192. $$variable .= "</tr>\n";
  193. }
  194. }
  195. if(VIEW_OFF) {
  196. $str = "<root>\n";
  197. $str .= "\t<runConditions>\n";
  198. $str .= $env_str;
  199. $str .= "\t</runConditions>\n";
  200. $str .= "\t<FileDirs>\n";
  201. $str .= "\t\t<Dirs>\n";
  202. $str .= $dir_str;
  203. $str .= "\t\t</Dirs>\n";
  204. $str .= "\t\t<Files>\n";
  205. $str .= $file_str;
  206. $str .= "\t\t</Files>\n";
  207. $str .= "\t</FileDirs>\n";
  208. $str .= "\t<error errorCode=\"$error_code\" errorMessage=\"\" />\n";
  209. $str .= "</root>";
  210. echo $str;
  211. exit;
  212. } else {
  213. show_header();
  214. echo "<h2 class=\"title\">".lang('env_check')."</h2>\n";
  215. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;\">\n";
  216. echo "<tr>\n";
  217. echo "\t<th>".lang('project')."</th>\n";
  218. echo "\t<th class=\"padleft\">".lang('ucenter_required')."</th>\n";
  219. echo "\t<th class=\"padleft\">".lang('ucenter_best')."</th>\n";
  220. echo "\t<th class=\"padleft\">".lang('curr_server')."</th>\n";
  221. echo "</tr>\n";
  222. echo $env_str;
  223. echo "</table>\n";
  224. echo "<h2 class=\"title\">".lang('priv_check')."</h2>\n";
  225. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;width:90%;\">\n";
  226. echo "\t<tr>\n";
  227. echo "\t<th>".lang('step1_file')."</th>\n";
  228. echo "\t<th class=\"padleft\">".lang('step1_need_status')."</th>\n";
  229. echo "\t<th class=\"padleft\">".lang('step1_status')."</th>\n";
  230. echo "</tr>\n";
  231. echo $file_str;
  232. echo $dir_str;
  233. echo "</table>\n";
  234. foreach($func_items as $item) {
  235. $status = function_exists($item);
  236. $func_str .= "<tr>\n";
  237. $func_str .= "<td>$item()</td>\n";
  238. if($status) {
  239. $func_str .= "<td class=\"w pdleft1\">".lang('supportted')."</td>\n";
  240. $func_str .= "<td class=\"padleft\">".lang('none')."</td>\n";
  241. } else {
  242. $error_code = ENV_CHECK_ERROR;
  243. $func_str .= "<td class=\"nw pdleft1\">".lang('unsupportted')."</td>\n";
  244. $func_str .= "<td><font color=\"red\">".lang('advice_'.$item)."</font></td>\n";
  245. }
  246. }
  247. echo "<h2 class=\"title\">".lang('func_depend')."</h2>\n";
  248. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;width:90%;\">\n";
  249. echo "<tr>\n";
  250. echo "\t<th>".lang('func_name')."</th>\n";
  251. echo "\t<th class=\"padleft\">".lang('check_result')."</th>\n";
  252. echo "\t<th class=\"padleft\">".lang('suggestion')."</th>\n";
  253. echo "</tr>\n";
  254. echo $func_str;
  255. echo "</table>\n";
  256. show_next_step(2, $error_code);
  257. show_footer();
  258. }
  259. }
  260. function show_next_step($step, $error_code) {
  261. global $uchidden;
  262. echo "<form action=\"index.php\" method=\"post\">\n";
  263. echo "<input type=\"hidden\" name=\"step\" value=\"$step\" />";
  264. if(isset($GLOBALS['hidden'])) {
  265. echo $GLOBALS['hidden'];
  266. }
  267. echo "<input type=\"hidden\" name=\"uchidden\" value=\"$uchidden\" />";
  268. if($error_code == 0) {
  269. $nextstep = "<input type=\"button\" onclick=\"history.back();\" value=\"".lang('old_step')."\"><input type=\"submit\" value=\"".lang('new_step')."\">\n";
  270. } else {
  271. $nextstep = "<input type=\"button\" disabled=\"disabled\" value=\"".lang('not_continue')."\">\n";
  272. }
  273. echo "<div class=\"btnbox marginbot\">".$nextstep."</div>\n";
  274. echo "</form>\n";
  275. }
  276. function show_form(&$form_items, $error_msg) {
  277. global $step, $uchidden;
  278. if(empty($form_items) || !is_array($form_items)) {
  279. return;
  280. }
  281. show_header();
  282. show_setting('start');
  283. show_setting('hidden', 'step', $step);
  284. $is_first = 1;
  285. if(!empty($uchidden)) {
  286. $uc_info_transfer = unserialize(urldecode($uchidden));
  287. }
  288. foreach($form_items as $key => $items) {
  289. global ${'error_'.$key};
  290. if($is_first == 0) {
  291. echo '</table>';
  292. }
  293. if(!${'error_'.$key}) {
  294. show_tips('tips_'.$key);
  295. } else {
  296. show_error('tips_admin_config', ${'error_'.$key});
  297. }
  298. echo '<table class="tb2">';
  299. foreach($items as $k => $v) {
  300. $value = '';
  301. if(!empty($error_msg)) {
  302. $value = isset($_POST[$key][$k]) ? $_POST[$key][$k] : '';
  303. }
  304. if(empty($value)) {
  305. if(isset($v['value']) && is_array($v['value'])) {
  306. if($v['value']['type'] == 'constant') {
  307. $value = defined($v['value']['var']) ? constant($v['value']['var']) : $v['value']['var'];
  308. } else {
  309. $value = $GLOBALS[$v['value']['var']];
  310. }
  311. } else {
  312. $value = '';
  313. }
  314. }
  315. if($k == 'ucurl' && isset($uc_info_transfer['ucapi'])) {
  316. $value = $uc_info_transfer['ucapi'];
  317. } elseif($k == 'ucpw' && isset($uc_info_transfer['ucfounderpw'])) {
  318. $value = $uc_info_transfer['ucfounderpw'];
  319. }
  320. show_setting($k, $key.'['.$k.']', $value, $v['type'], isset($error_msg[$key][$k]) ? $key.'_'.$k.'_invalid' : '');
  321. }
  322. if($is_first) {
  323. $is_first = 0;
  324. }
  325. }
  326. show_setting('', 'submitname', 'new_step', 'submit');
  327. show_setting('end');
  328. show_footer();
  329. }
  330. function show_license() {
  331. global $self, $uchidden, $step;
  332. $next = $step + 1;
  333. if(VIEW_OFF) {
  334. show_msg('license_contents', lang('license'), 1);
  335. } else {
  336. show_header();
  337. $license = str_replace(' ', '&nbsp; ', lang('license'));
  338. $lang_agreement_yes = lang('agreement_yes');
  339. $lang_agreement_no = lang('agreement_no');
  340. echo <<<EOT
  341. </div>
  342. <div class="main" style="margin-top:-123px;">
  343. <div class="licenseblock">$license</div>
  344. <div class="btnbox marginbot">
  345. <form method="get" action="index.php">
  346. <input type="hidden" name="step" value="$next">
  347. <input type="hidden" name="uchidden" value="$uchidden">
  348. <input type="submit" name="submit" value="{$lang_agreement_yes}" style="padding: 2px">&nbsp;
  349. <input type="button" name="exit" value="{$lang_agreement_no}" style="padding: 2px" onclick="javascript: window.close(); return false;">
  350. </form>
  351. </div>
  352. EOT;
  353. show_footer();
  354. }
  355. }
  356. function transfer_ucinfo(&$post) {
  357. global $uchidden;
  358. if(isset($post['ucapi']) && isset($post['ucfounderpw'])) {
  359. $arr = array(
  360. 'ucapi' => $post['ucapi'],
  361. 'ucfounderpw' => $post['ucfounderpw']
  362. );
  363. $uchidden = urlencode(serialize($arr));
  364. } else {
  365. $uchidden = '';
  366. }
  367. }
  368. if(!function_exists('file_put_contents')) {
  369. function file_put_contents($filename, $s) {
  370. $fp = @fopen($filename, 'w');
  371. @fwrite($fp, $s);
  372. @fclose($fp);
  373. return TRUE;
  374. }
  375. }
  376. function createtable($sql) {
  377. $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
  378. $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
  379. return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
  380. (mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=".DBCHARSET : " TYPE=$type");
  381. }
  382. function dir_writeable($dir) {
  383. $writeable = 0;
  384. if(!is_dir($dir)) {
  385. @mkdir($dir, 0777);
  386. }
  387. if(is_dir($dir)) {
  388. if($fp = @fopen("$dir/test.txt", 'w')) {
  389. @fclose($fp);
  390. @unlink("$dir/test.txt");
  391. $writeable = 1;
  392. } else {
  393. $writeable = 0;
  394. }
  395. }
  396. return $writeable;
  397. }
  398. function dir_clear($dir) {
  399. global $lang;
  400. showjsmessage($lang['clear_dir'].' '.str_replace(ROOT_PATH, '', $dir));
  401. $directory = dir($dir);
  402. while($entry = $directory->read()) {
  403. $filename = $dir.'/'.$entry;
  404. if(is_file($filename)) {
  405. @unlink($filename);
  406. }
  407. }
  408. $directory->close();
  409. @touch($dir.'/index.htm');
  410. }
  411. function show_header() {
  412. define('SHOW_HEADER', TRUE);
  413. global $step;
  414. $version = SOFT_VERSION;
  415. $release = SOFT_RELEASE;
  416. $install_lang = lang(INSTALL_LANG);
  417. $title = lang('title_install');
  418. $charset = CHARSET;
  419. echo <<<EOT
  420. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  421. <html xmlns="http://www.w3.org/1999/xhtml">
  422. <head>
  423. <meta http-equiv="Content-Type" content="text/html; charset=$charset" />
  424. <title>$title</title>
  425. <link rel="stylesheet" href="style.css" type="text/css" media="all" />
  426. <script type="text/javascript">
  427. function $(id) {
  428. return document.getElementById(id);
  429. }
  430. function showmessage(message) {
  431. document.getElementById('notice').innerHTML += message + '<br />';
  432. }
  433. </script>
  434. <meta content="Comsenz Inc." name="Copyright" />
  435. </head>
  436. <div class="container">
  437. <div class="header">
  438. <h1>$title</h1>
  439. <span>V$version $install_lang $release</span>
  440. EOT;
  441. $step > 0 && show_step($step);
  442. }
  443. function show_footer($quit = true) {
  444. echo <<<EOT
  445. <div class="footer">&copy;2001 - 2009 <a href="http://www.comsenz.com/">Comsenz</a> Inc.</div>
  446. </div>
  447. </div>
  448. </body>
  449. </html>
  450. EOT;
  451. $quit && exit();
  452. }
  453. function loginit($logfile) {
  454. global $lang;
  455. showjsmessage($lang['init_log'].' '.$logfile);
  456. if($fp = @fopen('./forumdata/logs/'.$logfile.'.php', 'w')) {
  457. fwrite($fp, '<'.'?PHP exit(); ?'.">\n");
  458. fclose($fp);
  459. }
  460. }
  461. function showjsmessage($message) {
  462. if(VIEW_OFF) return;
  463. echo '<script type="text/javascript">showmessage(\''.addslashes($message).' \');</script>'."\r\n";
  464. flush();
  465. ob_flush();
  466. }
  467. function random($length) {
  468. $hash = '';
  469. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  470. $max = strlen($chars) - 1;
  471. PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
  472. for($i = 0; $i < $length; $i++) {
  473. $hash .= $chars[mt_rand(0, $max)];
  474. }
  475. return $hash;
  476. }
  477. function redirect($url) {
  478. echo "<script>".
  479. "function redirect() {window.location.replace('$url');}\n".
  480. "setTimeout('redirect();', 0);\n".
  481. "</script>";
  482. exit();
  483. }
  484. function get_onlineip() {
  485. $onlineip = '';
  486. if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  487. $onlineip = getenv('HTTP_CLIENT_IP');
  488. } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  489. $onlineip = getenv('HTTP_X_FORWARDED_FOR');
  490. } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  491. $onlineip = getenv('REMOTE_ADDR');
  492. } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  493. $onlineip = $_SERVER['REMOTE_ADDR'];
  494. }
  495. return $onlineip;
  496. }
  497. function config_edit() {
  498. extract($GLOBALS, EXTR_SKIP);
  499. $configfile = @file_get_contents(CONFIG);
  500. $configfile = trim($configfile);
  501. $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
  502. $configfile = preg_replace("/[$]dbhost\s*\=\s*[\"'].*?[\"'];/is", "\$dbhost = '$dbhost';", $configfile);
  503. $configfile = preg_replace("/[$]dbuser\s*\=\s*[\"'].*?[\"'];/is", "\$dbuser = '$dbuser';", $configfile);
  504. $configfile = preg_replace("/[$]dbpw\s*\=\s*[\"'].*?[\"'];/is", "\$dbpw = '$dbpw';", $configfile);
  505. $configfile = preg_replace("/[$]dbname\s*\=\s*[\"'].*?[\"'];/is", "\$dbname = '$dbname';", $configfile);
  506. $configfile = preg_replace("/[$]adminemail\s*\=\s*[\"'].*?[\"'];/is", "\$adminemail = '$adminemail';", $configfile);
  507. $configfile = preg_replace("/[$]tablepre\s*\=\s*[\"'].*?[\"'];/is", "\$tablepre = '$tablepre';", $configfile);
  508. $configfile = preg_replace("/[$]cookiepre\s*\=\s*[\"'].*?[\"'];/is", "\$cookiepre = '".random(3)."_';", $configfile);
  509. $configfile = preg_replace("/[$]forumfounders\s*\=\s*[\"'].*?[\"'];/is", "\$forumfounders = '$adminuser[uid]';", $configfile);
  510. @file_put_contents(CONFIG, $configfile);
  511. }
  512. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  513. $ckey_length = 4; // 随机密钥长度 取值 0-32;
  514. // 加入随机密钥,可以令密文无任何规律,即便是原文和密钥完全相同,加密结果也会每次不同,增大破解难度。
  515. // 取值越大,密文变动规律越大,密文变化 = 16 的 $ckey_length 次方
  516. // 当此值为 0 时,则不产生随机密钥
  517. $key = md5($key ? $key : UC_KEY);
  518. $keya = md5(substr($key, 0, 16));
  519. $keyb = md5(substr($key, 16, 16));
  520. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
  521. $cryptkey = $keya.md5($keya.$keyc);
  522. $key_length = strlen($cryptkey);
  523. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  524. $string_length = strlen($string);
  525. $result = '';
  526. $box = range(0, 255);
  527. $rndkey = array();
  528. for($i = 0; $i <= 255; $i++) {
  529. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  530. }
  531. for($j = $i = 0; $i < 256; $i++) {
  532. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  533. $tmp = $box[$i];
  534. $box[$i] = $box[$j];
  535. $box[$j] = $tmp;
  536. }
  537. for($a = $j = $i = 0; $i < $string_length; $i++) {
  538. $a = ($a + 1) % 256;
  539. $j = ($j + $box[$a]) % 256;
  540. $tmp = $box[$a];
  541. $box[$a] = $box[$j];
  542. $box[$j] = $tmp;
  543. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  544. }
  545. if($operation == 'DECODE') {
  546. if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
  547. return substr($result, 26);
  548. } else {
  549. return '';
  550. }
  551. } else {
  552. return $keyc.str_replace('=', '', base64_encode($result));
  553. }
  554. }
  555. function generate_key() {
  556. $random = random(32);
  557. $info = md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['SERVER_NAME'].$_SERVER['SERVER_ADDR'].$_SERVER['SERVER_PORT'].$_SERVER['HTTP_USER_AGENT'].time());
  558. $return = '';
  559. for($i=0; $i<64; $i++) {
  560. $p = intval($i/2);
  561. $return[$i] = $i % 2 ? $random[$p] : $info[$p];
  562. }
  563. return implode('', $return);
  564. }
  565. function show_install() {
  566. if(VIEW_OFF) return;
  567. ?>
  568. <script type="text/javascript">
  569. function showmessage(message) {
  570. document.getElementById('notice').innerHTML += message + '<br />';
  571. document.getElementById('notice').scrollTop = 100000000;
  572. }
  573. function initinput() {
  574. window.location='index.php?method=ext_info';
  575. }
  576. </script>
  577. <div class="main">
  578. <div class="btnbox"><div id="notice"></div></div>
  579. <div class="btnbox marginbot">
  580. <input type="button" name="submit" value="<?=lang('install_in_processed')?>" disabled style="height: 25" id="laststep" onclick="initinput()">
  581. </div>
  582. <?php
  583. }
  584. function runquery($sql) {
  585. global $lang, $tablepre, $db;
  586. if(!isset($sql) || empty($sql)) return;
  587. $sql = str_replace("\r", "\n", str_replace(' '.ORIG_TABLEPRE, ' '.$tablepre, $sql));
  588. $ret = array();
  589. $num = 0;
  590. foreach(explode(";\n", trim($sql)) as $query) {
  591. $ret[$num] = '';
  592. $queries = explode("\n", trim($query));
  593. foreach($queries as $query) {
  594. $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
  595. }
  596. $num++;
  597. }
  598. unset($sql);
  599. foreach($ret as $query) {
  600. $query = trim($query);
  601. if($query) {
  602. if(substr($query, 0, 12) == 'CREATE TABLE') {
  603. $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  604. showjsmessage(lang('create_table').' '.$name.' ... '.lang('succeed'));
  605. $db->query(createtable($query));
  606. } else {
  607. $db->query($query);
  608. }
  609. }
  610. }
  611. }
  612. function runucquery($sql, $tablepre) {
  613. global $lang, $db;
  614. if(!isset($sql) || empty($sql)) return;
  615. $sql = str_replace("\r", "\n", str_replace(' uc_', ' '.$tablepre, $sql));
  616. $ret = array();
  617. $num = 0;
  618. foreach(explode(";\n", trim($sql)) as $query) {
  619. $ret[$num] = '';
  620. $queries = explode("\n", trim($query));
  621. foreach($queries as $query) {
  622. $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
  623. }
  624. $num++;
  625. }
  626. unset($sql);
  627. foreach($ret as $query) {
  628. $query = trim($query);
  629. if($query) {
  630. if(substr($query, 0, 12) == 'CREATE TABLE') {
  631. $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  632. showjsmessage(lang('create_table').' '.$name.' ... '.lang('succeed'));
  633. $db->query(createtable($query));
  634. } else {
  635. $db->query($query);
  636. }
  637. }
  638. }
  639. }
  640. function charcovert($string) {
  641. if(!get_magic_quotes_gpc()) {
  642. $string = str_replace('\'', '\\\'', $string);
  643. } else {
  644. $string = str_replace('\"', '"', $string);
  645. }
  646. return $string;
  647. }
  648. function insertconfig($s, $find, $replace) {
  649. if(preg_match($find, $s)) {
  650. $s = preg_replace($find, $replace, $s);
  651. } else {
  652. // 插入到最后一行
  653. $s .= "\r\n".$replace;
  654. }
  655. return $s;
  656. }
  657. function getgpc($k, $t='GP') {
  658. $t = strtoupper($t);
  659. switch($t) {
  660. case 'GP' : isset($_POST[$k]) ? $var = &$_POST : $var = &$_GET; break;
  661. case 'G': $var = &$_GET; break;
  662. case 'P': $var = &$_POST; break;
  663. case 'C': $var = &$_COOKIE; break;
  664. case 'R': $var = &$_REQUEST; break;
  665. }
  666. return isset($var[$k]) ? $var[$k] : '';
  667. }
  668. function var_to_hidden($k, $v) {
  669. return "<input type=\"hidden\" name=\"$k\" value=\"$v\" />\n";
  670. }
  671. function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
  672. $return = '';
  673. $matches = parse_url($url);
  674. $host = $matches['host'];
  675. $path = $matches['path'] ? $matches['path'].(isset($matches['query']) && $matches['query'] ? '?'.$matches['query'] : '') : '/';
  676. $port = !empty($matches['port']) ? $matches['port'] : 80;
  677. if($post) {
  678. $out = "POST $path HTTP/1.0\r\n";
  679. $out .= "Accept: */*\r\n";
  680. //$out .= "Referer: $boardurl\r\n";
  681. $out .= "Accept-Language: zh-cn\r\n";
  682. $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
  683. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  684. $out .= "Host: $host\r\n";
  685. $out .= 'Content-Length: '.strlen($post)."\r\n";
  686. $out .= "Connection: Close\r\n";
  687. $out .= "Cache-Control: no-cache\r\n";
  688. $out .= "Cookie: $cookie\r\n\r\n";
  689. $out .= $post;
  690. } else {
  691. $out = "GET $path HTTP/1.0\r\n";
  692. $out .= "Accept: */*\r\n";
  693. //$out .= "Referer: $boardurl\r\n";
  694. $out .= "Accept-Language: zh-cn\r\n";
  695. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  696. $out .= "Host: $host\r\n";
  697. $out .= "Connection: Close\r\n";
  698. $out .= "Cookie: $cookie\r\n\r\n";
  699. }
  700. $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
  701. if(!$fp) {
  702. return '';
  703. } else {
  704. stream_set_blocking($fp, $block);
  705. stream_set_timeout($fp, $timeout);
  706. @fwrite($fp, $out);
  707. $status = stream_get_meta_data($fp);
  708. if(!$status['timed_out']) {
  709. while (!feof($fp)) {
  710. if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
  711. break;
  712. }
  713. }
  714. $stop = false;
  715. while(!feof($fp) && !$stop) {
  716. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  717. $return .= $data;
  718. if($limit) {
  719. $limit -= strlen($data);
  720. $stop = $limit <= 0;
  721. }
  722. }
  723. }
  724. @fclose($fp);
  725. return $return;
  726. }
  727. }
  728. function check_env() {
  729. global $lang, $attachdir;
  730. $errors = array('quit' => false);
  731. $quit = false;
  732. if(!function_exists('mysql_connect')) {
  733. $errors[] = 'mysql_unsupport';
  734. $quit = true;
  735. }
  736. if(PHP_VERSION < '4.3') {
  737. $errors[] = 'php_version_430';
  738. $quit = true;
  739. }
  740. if(!file_exists(ROOT_PATH.'./config.inc.php')) {
  741. $errors[] = 'config_nonexistence';
  742. $quit = true;
  743. } elseif(!is_writeable(ROOT_PATH.'./config.inc.php')) {
  744. $errors[] = 'config_unwriteable';
  745. $quit = true;
  746. }
  747. $checkdirarray = array(
  748. 'attach' => $attachdir,
  749. 'forumdata' => './forumdata',
  750. 'cache' => './forumdata/cache',
  751. 'ftemplates' => './forumdata/templates',
  752. 'threadcache' => './forumdata/threadcaches',
  753. 'log' => './forumdata/logs',
  754. 'uccache' => './uc_client/data/cache'
  755. );
  756. foreach($checkdirarray as $key => $dir) {
  757. if(!dir_writeable(ROOT_PATH.$dir)) {
  758. $langkey = $key.'_unwriteable';
  759. $errors[] = $key.'_unwriteable';
  760. if(!in_array($key, array('ftemplate'))) {
  761. $quit = TRUE;
  762. }
  763. }
  764. }
  765. $errors['quit'] = $quit;
  766. return $errors;
  767. }
  768. function show_error($type, $errors = '', $quit = false) {
  769. global $lang, $step;
  770. $title = lang($type);
  771. $comment = lang($type.'_comment', false);
  772. $errormsg = '';
  773. if($errors) {
  774. if(!empty($errors)) {
  775. foreach ((array)$errors as $k => $v) {
  776. if(is_numeric($k)) {
  777. $comment .= "<li><em class=\"red\">".lang($v)."</em></li>";
  778. }
  779. }
  780. }
  781. }
  782. if($step > 0) {
  783. echo "<div class=\"desc\"><b>$title</b><ul>$comment</ul>";
  784. } else {
  785. echo "</div><div class=\"main\" style=\"margin-top: -123px;\"><b>$title</b><ul style=\"line-height: 200%; margin-left: 30px;\">$comment</ul>";
  786. }
  787. if($quit) {
  788. echo '<br /><span class="red">'.$lang['error_quit_msg'].'</span><br /><br /><br /><br /><br /><br />';
  789. }
  790. echo '</div>';
  791. $quit && show_footer();
  792. }
  793. function show_tips($tip, $title = '', $comment = '', $style = 1) {
  794. global $lang;
  795. $title = empty($title) ? lang($tip) : $title;
  796. $comment = empty($comment) ? lang($tip.'_comment', FALSE) : $comment;
  797. if($style) {
  798. echo "<div class=\"desc\"><b>$title</b>";
  799. } else {
  800. echo "</div><div class=\"main\" style=\"margin-top: -123px;\">$title<div class=\"desc1 marginbot\"><ul>";
  801. }
  802. $comment && print('<br>'.$comment);
  803. echo "</div>";
  804. }
  805. function show_setting($setname, $varname = '', $value = '', $type = 'text|password|checkbox', $error = '') {
  806. if($setname == 'start') {
  807. echo "<form method=\"post\" action=\"index.php\">\n";
  808. return;
  809. } elseif($setname == 'end') {
  810. echo "\n</table>\n</form>\n";
  811. return;
  812. } elseif($setname == 'hidden') {
  813. echo "<input type=\"hidden\" name=\"$varname\" value=\"$value\">\n";
  814. return;
  815. }
  816. echo "\n".'<tr><th class="tbopt'.($error ? ' red' : '').'">&nbsp;'.(empty($setname) ? '' : lang($setname).':')."</th>\n<td>";
  817. if($type == 'text' || $type == 'password') {
  818. $value = htmlspecialchars($value);
  819. echo "<input type=\"$type\" name=\"$varname\" value=\"$value\" size=\"35\" class=\"txt\">";
  820. } elseif($type == 'submit') {
  821. $value = empty($value) ? 'next_step' : $value;
  822. echo "<input type=\"submit\" name=\"$varname\" value=\"".lang($value)."\" class=\"btn\">\n";
  823. } elseif($type == 'checkbox') {
  824. if(!is_array($varname) && !is_array($value)) {
  825. echo "<label><input type=\"checkbox\" name=\"$varname\" value=\"1\"".($value ? 'checked="checked"' : '')."style=\"border: 0\">".lang($setname.'_check_label')."</label>\n";
  826. }
  827. } else {
  828. echo $value;
  829. }
  830. echo "</td>\n<td>&nbsp;";
  831. if($error) {
  832. $comment = '<span class="red">'.(is_string($error) ? lang($error) : lang($setname.'_error')).'</span>';
  833. } else {
  834. $comment = lang($setname.'_comment', false);
  835. }
  836. echo "$comment</td>\n</tr>\n";
  837. return true;
  838. }
  839. function show_step($step) {
  840. global $method;
  841. $laststep = 4;
  842. $title = lang('step_'.$method.'_title');
  843. $comment = lang('step_'.$method.'_desc');
  844. $stepclass = array();
  845. for($i = 1; $i <= $laststep; $i++) {
  846. $stepclass[$i] = $i == $step ? 'current' : ($i < $step ? '' : 'unactivated');
  847. }
  848. $stepclass[$laststep] .= ' last';
  849. echo <<<EOT
  850. <div class="setup step{$step}">
  851. <h2>$title</h2>
  852. <p>$comment</p>
  853. </div>
  854. <div class="stepstat">
  855. <ul>
  856. <li class="$stepclass[1]">1</li>
  857. <li class="$stepclass[2]">2</li>
  858. <li class="$stepclass[3]">3</li>
  859. <li class="$stepclass[4]">4</li>
  860. </ul>
  861. <div class="stepstatbg stepstat1"></div>
  862. </div>
  863. </div>
  864. <div class="main">
  865. EOT;
  866. }
  867. function lang($lang_key, $force = true) {
  868. return isset($GLOBALS['lang'][$lang_key]) ? $GLOBALS['lang'][$lang_key] : ($force ? $lang_key : '');
  869. }
  870. function check_adminuser($username, $password, $email) {
  871. @include CONFIG;
  872. include ROOT_PATH.'./uc_client/client.php';
  873. $error = '';
  874. $uid = uc_user_register($username, $password, $email);
  875. /*
  876. -1 : 用户名不合法
  877. -2 : 包含不允许注册的词语
  878. -3 : 用户名已经存在
  879. -4 : email 格式有误
  880. -5 : email 不允许注册
  881. -6 : 该 email 已经被注册
  882. >1 : 表示成功,数值为 UID
  883. */
  884. if($uid == -1 || $uid == -2) {
  885. $error = 'admin_username_invalid';
  886. } elseif($uid == -4 || $uid == -5 || $uid == -6) {
  887. $error = 'admin_email_invalid';
  888. } elseif($uid == -3) {
  889. $ucresult = uc_user_login($username, $password);
  890. list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email']) = uc_addslashes($ucresult);
  891. $ucresult = $tmp;
  892. if($ucresult['uid'] <= 0) {
  893. $error = 'admin_exist_password_error';
  894. } else {
  895. $uid = $ucresult['uid'];
  896. $email = $ucresult['email'];
  897. $password = $ucresult['password'];
  898. }
  899. }
  900. if(!$error && $uid > 0) {
  901. $password = md5($password);
  902. uc_user_addprotected($username, '');
  903. } else {
  904. $uid = 0;
  905. $error = empty($error) ? 'error_unknow_type' : $error;
  906. }
  907. return array('uid' => $uid, 'username' => $username, 'password' => $password, 'email' => $email, 'error' => $error);
  908. }
  909. function save_uc_config($config, $file) {
  910. $success = false;
  911. list($appauthkey, $appid, $ucdbhost, $ucdbname, $ucdbuser, $ucdbpw, $ucdbcharset, $uctablepre, $uccharset, $ucapi, $ucip) = explode('|', $config);
  912. if($content = file_get_contents($file)) {
  913. $content = trim($content);
  914. $content = substr($content, -2) == '?>' ? substr($content, 0, -2) : $content;
  915. $link = mysql_connect($ucdbhost, $ucdbuser, $ucdbpw, 1);
  916. $uc_connnect = $link && mysql_select_db($ucdbname, $link) ? 'mysql' : '';
  917. $content = insertconfig($content, "/define\('UC_CONNECT',\s*'.*?'\);/i", "define('UC_CONNECT', '$uc_connnect');");
  918. $content = insertconfig($content, "/define\('UC_DBHOST',\s*'.*?'\);/i", "define('UC_DBHOST', '$ucdbhost');");
  919. $content = insertconfig($content, "/define\('UC_DBUSER',\s*'.*?'\);/i", "define('UC_DBUSER', '$ucdbuser');");
  920. $content = insertconfig($content, "/define\('UC_DBPW',\s*'.*?'\);/i", "define('UC_DBPW', '$ucdbpw');");
  921. $content = insertconfig($content, "/define\('UC_DBNAME',\s*'.*?'\);/i", "define('UC_DBNAME', '$ucdbname');");
  922. $content = insertconfig($content, "/define\('UC_DBCHARSET',\s*'.*?'\);/i", "define('UC_DBCHARSET', '$ucdbcharset');");
  923. $content = insertconfig($content, "/define\('UC_DBTABLEPRE',\s*'.*?'\);/i", "define('UC_DBTABLEPRE', '`$ucdbname`.$uctablepre');");
  924. $content = insertconfig($content, "/define\('UC_DBCONNECT',\s*'.*?'\);/i", "define('UC_DBCONNECT', '0');");
  925. $content = insertconfig($content, "/define\('UC_KEY',\s*'.*?'\);/i", "define('UC_KEY', '$appauthkey');");
  926. $content = insertconfig($content, "/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '$ucapi');");
  927. $content = insertconfig($content, "/define\('UC_CHARSET',\s*'.*?'\);/i", "define('UC_CHARSET', '$uccharset');");
  928. $content = insertconfig($content, "/define\('UC_IP',\s*'.*?'\);/i", "define('UC_IP', '$ucip');");
  929. $content = insertconfig($content, "/define\('UC_APPID',\s*'?.*?'?\);/i", "define('UC_APPID', '$appid');");
  930. $content = insertconfig($content, "/define\('UC_PPP',\s*'?.*?'?\);/i", "define('UC_PPP', '20');");
  931. if(@file_put_contents($file, $content)) {
  932. $success = true;
  933. }
  934. }
  935. return $success;
  936. }
  937. function _generate_key() {
  938. $random = random(32);
  939. $info = md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['SERVER_NAME'].$_SERVER['SERVER_ADDR'].$_SERVER['SERVER_PORT'].$_SERVER['HTTP_USER_AGENT'].time());
  940. $return = array();
  941. for($i=0; $i<32; $i++) {
  942. $return[$i] = $random[$i].$info[$i];
  943. }
  944. return implode('', $return);
  945. }
  946. function uc_write_config($config, $file, $password) {
  947. list($appauthkey, $appid, $ucdbhost, $ucdbname, $ucdbuser, $ucdbpw, $ucdbcharset, $uctablepre, $uccharset, $ucapi, $ucip) = explode('|', $config);
  948. $ucauthkey = _generate_key();
  949. $ucsiteid = _generate_key();
  950. $ucmykey = _generate_key();
  951. $salt = substr(_generate_key(), 0, 6);
  952. $pw = md5(md5($password).$salt);
  953. $config = "<?php \r\ndefine('UC_DBHOST', '$ucdbhost');\r\n";
  954. $config .= "define('UC_DBUSER', '$ucdbuser');\r\n";
  955. $config .= "define('UC_DBPW', '$ucdbpw');\r\n";
  956. $config .= "define('UC_DBNAME', '$ucdbname');\r\n";
  957. $config .= "define('UC_DBCHARSET', '$ucdbcharset');\r\n";
  958. $config .= "define('UC_DBTABLEPRE', '$uctablepre');\r\n";
  959. $config .= "define('UC_COOKIEPATH', '/');\r\n";
  960. $config .= "define('UC_COOKIEDOMAIN', '');\r\n";
  961. $config .= "define('UC_DBCONNECT', 0);\r\n";
  962. $config .= "define('UC_CHARSET', '".$uccharset."');\r\n";
  963. $config .= "define('UC_FOUNDERPW', '$pw');\r\n";
  964. $config .= "define('UC_FOUNDERSALT', '$salt');\r\n";
  965. $config .= "define('UC_KEY', '$ucauthkey');\r\n";
  966. $config .= "define('UC_SITEID', '$ucsiteid');\r\n";
  967. $config .= "define('UC_MYKEY', '$ucmykey');\r\n";
  968. $config .= "define('UC_DEBUG', false);\r\n";
  969. $config .= "define('UC_PPP', 20);\r\n";
  970. $fp = fopen($file, 'w');
  971. fwrite($fp, $config);
  972. fclose($fp);
  973. }
  974. function install_uc_server() {
  975. global $db, $dbhost, $dbuser, $dbpw, $dbname, $tablepre, $username, $password, $email;
  976. $ucsql = file_get_contents(ROOT_PATH.'./uc_server/install/uc.sql');
  977. $uctablepre = $tablepre.'uc_';
  978. $ucsql = str_replace(' uc_', ' '.$uctablepre, $ucsql);
  979. $ucsql && runucquery($ucsql, $uctablepre);
  980. $appauthkey = _generate_key();
  981. $ucdbhost = $dbhost;
  982. $ucdbname = $dbname;
  983. $ucdbuser = $dbuser;
  984. $ucdbpw = $dbpw;
  985. $ucdbcharset = DBCHARSET;
  986. $uccharset = CHARSET;
  987. $pathinfo = pathinfo($_SERVER['PHP_SELF']);
  988. $pathinfo['dirname'] = substr($pathinfo['dirname'], 0, -8);
  989. $appurl = 'http://'.preg_replace("/\:\d+/", '', $_SERVER['HTTP_HOST']).($_SERVER['SERVER_PORT'] && $_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '').$pathinfo['dirname'];
  990. $ucapi = $appurl.'/uc_server';
  991. $ucip = '127.0.0.1';
  992. $app_tagtemplates = 'apptagtemplates[template]='.urlencode('<a href="{url}" target="_blank">{subject}</a>').'&'.
  993. 'apptagtemplates[fields][subject]='.urlencode($lang['tagtemplates_subject']).'&'.
  994. 'apptagtemplates[fields][uid]='.urlencode($lang['tagtemplates_uid']).'&'.
  995. 'apptagtemplates[fields][username]='.urlencode($lang['tagtemplates_username']).'&'.
  996. 'apptagtemplates[fields][dateline]='.urlencode($lang['tagtemplates_dateline']).'&'.
  997. 'apptagtemplates[fields][url]='.urlencode($lang['tagtemplates_url']);
  998. $db->query("INSERT INTO {$uctablepre}applications SET name='Discuz! Board', url='$appurl', ip='$ucip', authkey='$appauthkey', synlogin='1', charset='$charset', dbcharset='$dbcharset', type='DISCUZ', recvnote='1', tagtemplates='$apptagtemplates'", $link);
  999. $appid = $db->insert_id($link);
  1000. $db->query("ALTER TABLE {$uctablepre}notelist ADD COLUMN app$appid tinyint NOT NULL");
  1001. $config = "$appauthkey|$appid|$ucdbhost|$ucdbname|$ucdbuser|$ucdbpw|$ucdbcharset|$uctablepre|$uccharset|$ucapi|$ucip";
  1002. save_uc_config($config, ROOT_PATH.'./config.inc.php');
  1003. $salt = substr(uniqid(rand()), -6);
  1004. $passwordmd5 = md5(md5($password).$salt);
  1005. $db->query("INSERT INTO {$uctablepre}members SET $sqladd username='$username', password='$passwordmd5', email='$email', regip='hidden', regdate='".time()."', salt='$salt'");
  1006. $uid = $db->insert_id();
  1007. $db->query("INSERT INTO {$uctablepre}memberfields SET uid='$uid'");
  1008. $db->query("INSERT INTO {$uctablepre}admins SET
  1009. uid='$uid',
  1010. username='$username',
  1011. allowadminsetting='1',
  1012. allowadminapp='1',
  1013. allowadminuser='1',
  1014. allowadminbadword='1',
  1015. allowadmincredits='1',
  1016. allowadmintag='1',
  1017. allowadminpm='1',
  1018. allowadmindomain='1',
  1019. allowadmindb='1',
  1020. allowadminnote='1',
  1021. allowadmincache='1',
  1022. allowadminlog='1'");
  1023. uc_write_config($config, ROOT_PATH.'./uc_server/data/config.inc.php', $password);
  1024. @unlink(ROOT_PATH.'./uc_server/install/index.php');
  1025. @unlink(ROOT_PATH.'./uc_server/data/cache/settings.php');
  1026. @touch(ROOT_PATH.'./uc_server/data/upgrade.lock');
  1027. @touch(ROOT_PATH.'./uc_server/data/install.lock');
  1028. dir_clear(ROOT_PATH.'./uc_server/data/cache');
  1029. dir_clear(ROOT_PATH.'./uc_server/data/view');
  1030. }
  1031. function install_testdata($username, $uid) {
  1032. global $db, $tablepre, $testdatacontent;
  1033. if(empty($testdatacontent)) return;
  1034. showjsmessage(lang('install_test_data')." ... ".lang('succeed'));
  1035. $threads = 0;
  1036. foreach($testdatacontent as $val) {
  1037. $db->query("INSERT INTO {$tablepre}threads (fid, subject, author, authorid, dateline, lastpost, lastposter) VALUES (2, '".addslashes($val['subject'])."', '$username', '$uid', ".time().", ".time().", '$username')");
  1038. if($tid = $db->insert_id()) {
  1039. $threads++;
  1040. $db->query("INSERT INTO {$tablepre}posts (fid, tid, first, subject, author, authorid, dateline, message)
  1041. VALUES (2, $tid, 1, '".addslashes($val['subject'])."', '$username', '$uid', ".time().", '".addslashes($val['message'])."')");
  1042. }
  1043. }
  1044. $db->query("UPDATE {$tablepre}forums SET threads=$threads, posts=$threads, lastpost='$tid\t$val[subject]\t".time()."\t$username' WHERE fid=2");
  1045. $db->query("UPDATE {$tablepre}members SET threads=$threads, posts=$threads WHERE uid='$uid'");
  1046. }