function install_uc_server() { global $db, $dbhost, $dbuser, $dbpw, $dbname, $tablepre, $username, $password, $email; $ucsql = file_get_contents(ROOT_PATH . './uc_server/install/uc.sql'); $uctablepre = $tablepre . 'ucenter_'; $ucsql = str_replace(' uc_', ' ' . $uctablepre, $ucsql); $ucsql && runucquery($ucsql, $uctablepre); $appauthkey = _generate_key(); $ucdbhost = $dbhost; $ucdbname = $dbname; $ucdbuser = $dbuser; $ucdbpw = $dbpw; $ucdbcharset = DBCHARSET; $uccharset = CHARSET; $pathinfo = pathinfo($_SERVER['PHP_SELF']); $pathinfo['dirname'] = substr($pathinfo['dirname'], 0, -8); $appurl = 'http://' . preg_replace("/\\:\\d+/", '', $_SERVER['HTTP_HOST']) . ($_SERVER['SERVER_PORT'] && $_SERVER['SERVER_PORT'] != 80 ? ':' . $_SERVER['SERVER_PORT'] : '') . $pathinfo['dirname']; $ucapi = $appurl . '/uc_server'; $ucip = ''; $app_tagtemplates = 'apptagtemplates[template]=' . urlencode('<a href="{url}" target="_blank">{subject}</a>') . '&' . 'apptagtemplates[fields][subject]=' . urlencode($lang['tagtemplates_subject']) . '&' . 'apptagtemplates[fields][uid]=' . urlencode($lang['tagtemplates_uid']) . '&' . 'apptagtemplates[fields][username]=' . urlencode($lang['tagtemplates_username']) . '&' . 'apptagtemplates[fields][dateline]=' . urlencode($lang['tagtemplates_dateline']) . '&' . 'apptagtemplates[fields][url]=' . urlencode($lang['tagtemplates_url']); $db->query("INSERT INTO {$uctablepre}applications SET name='Discuz! Board', url='{$appurl}', ip='{$ucip}', authkey='{$appauthkey}', synlogin='******', charset='{$charset}', dbcharset='{$dbcharset}', type='DISCUZX', recvnote='1', tagtemplates='{$apptagtemplates}'", $link); $appid = $db->insert_id($link); $db->query("ALTER TABLE {$uctablepre}notelist ADD COLUMN app{$appid} tinyint NOT NULL"); $config = array($appauthkey, $appid, $ucdbhost, $ucdbname, $ucdbuser, $ucdbpw, $ucdbcharset, $uctablepre, $uccharset, $ucapi, $ucip); save_uc_config($config, ROOT_PATH . './config/config_ucenter.php'); $salt = substr(uniqid(rand()), -6); $passwordmd5 = md5(md5($password) . $salt); $db->query("INSERT INTO {$uctablepre}members SET {$sqladd} username='******', password='******', email='{$email}', regip='hidden', regdate='" . time() . "', salt='{$salt}'"); $uid = $db->insert_id(); $db->query("INSERT INTO {$uctablepre}memberfields SET uid='{$uid}'"); $db->query("INSERT INTO {$uctablepre}admins SET\r\n\t\tuid='{$uid}',\r\n\t\tusername='******',\r\n\t\tallowadminsetting='1',\r\n\t\tallowadminapp='1',\r\n\t\tallowadminuser='******',\r\n\t\tallowadminbadword='1',\r\n\t\tallowadmincredits='1',\r\n\t\tallowadmintag='1',\r\n\t\tallowadminpm='1',\r\n\t\tallowadmindomain='1',\r\n\t\tallowadmindb='1',\r\n\t\tallowadminnote='1',\r\n\t\tallowadmincache='1',\r\n\t\tallowadminlog='1'"); uc_write_config($config, ROOT_PATH . './uc_server/data/config.inc.php', $password); //vot @unlink(ROOT_PATH.'./uc_server/install/index.php'); @unlink(ROOT_PATH . './uc_server/data/cache/settings.php'); @touch(ROOT_PATH . './uc_server/data/upgrade.lock'); @touch(ROOT_PATH . './uc_server/data/install.lock'); dir_clear(ROOT_PATH . './uc_server/data/cache'); dir_clear(ROOT_PATH . './uc_server/data/view'); }
function uc_write_config($config, $file, $password) { list($appauthkey, $appid, $ucdbhost, $ucdbname, $ucdbuser, $ucdbpw, $ucdbcharset, $uctablepre, $uccharset, $ucapi, $ucip) = explode('|', $config); $ucauthkey = _generate_key(); $ucsiteid = _generate_key(); $ucmykey = _generate_key(); $salt = substr(_generate_key(), 0, 6); $pw = md5(md5($password) . $salt); $config = "<?php \r\ndefine('UC_DBHOST', '{$ucdbhost}');\r\n"; $config .= "define('UC_DBUSER', '{$ucdbuser}');\r\n"; $config .= "define('UC_DBPW', '{$ucdbpw}');\r\n"; $config .= "define('UC_DBNAME', '{$ucdbname}');\r\n"; $config .= "define('UC_DBCHARSET', '{$ucdbcharset}');\r\n"; $config .= "define('UC_DBTABLEPRE', '{$uctablepre}');\r\n"; $config .= "define('UC_COOKIEPATH', '/');\r\n"; $config .= "define('UC_COOKIEDOMAIN', '');\r\n"; $config .= "define('UC_DBCONNECT', 0);\r\n"; $config .= "define('UC_CHARSET', '" . $uccharset . "');\r\n"; $config .= "define('UC_FOUNDERPW', '{$pw}');\r\n"; $config .= "define('UC_FOUNDERSALT', '{$salt}');\r\n"; $config .= "define('UC_KEY', '{$ucauthkey}');\r\n"; $config .= "define('UC_SITEID', '{$ucsiteid}');\r\n"; $config .= "define('UC_MYKEY', '{$ucmykey}');\r\n"; $config .= "define('UC_DEBUG', false);\r\n"; $config .= "define('UC_PPP', 20);\r\n"; $fp = fopen($file, 'w'); fwrite($fp, $config); fclose($fp); }
if (is_writeable(ROOT_PATH . './config.php')) { $configfile = @file_get_contents(ROOT_PATH . './config.php'); $configfile = trim($configfile); $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile; $configfile = preg_replace("/[\$]_SC\\[[\"']founder[\"']\\]\\s*\\=\\s*[\"'].*?[\"'];/is", "\$_SC['founder'] = '{$uid}';", $configfile); @file_put_contents(ROOT_PATH . './config.php', $configfile); } @dir_clear(ROOT_PATH . './data/cache/tpl'); @dir_clear(ROOT_PATH . './data/cache/block'); @dir_clear(ROOT_PATH . './data/cache/model'); @dir_clear(ROOT_PATH . './uc_client/data'); @dir_clear(ROOT_PATH . './uc_client/data/cache'); touch($lockfile); VIEW_OFF && show_msg('initdbresult_succ'); //設置SITEKEY等 $sitekey = substr(_generate_key(), 4, 16); runquery("REPLACE INTO " . ORIG_TABLEPRE . "settings (`variable` ,`value`) VALUES ('sitekey', '{$sitekey}')"); if (!VIEW_OFF) { echo '<script type="text/javascript">document.getElementById("laststep").disabled=false;document.getElementById("laststep").value = \'' . lang('install_founder_contact') . '\';</script><script type="text/javascript">setTimeout(function(){window.location=\'index.php?method=ext_info\'}, 2000);</script><iframe src="../" style="display:none"></iframe>' . "\r\n"; show_footer(); } } if (VIEW_OFF) { show_msg('missing_parameter', '', 0); } else { show_form($form_db_init_items, $error_msg); } } elseif ($method == 'ext_info') { @(include CONFIG); $db = new dbstuff(); $db->connect($dbhost, $dbuser, $dbpw, $dbname, DBCHARSET);
$configfile = preg_replace("/[\$]dbpw\\s*\\=\\s*[\"'].*?[\"'];/is", "\$dbpw = '{$dbpw}';", $configfile); $configfile = preg_replace("/[\$]dbname\\s*\\=\\s*[\"'].*?[\"'];/is", "\$dbname = '{$dbname}';", $configfile); $configfile = preg_replace("/[\$]adminemail\\s*\\=\\s*[\"'].*?[\"'];/is", "\$adminemail = '{$adminemail}';", $configfile); $configfile = preg_replace("/[\$]tablepre\\s*\\=\\s*[\"'].*?[\"'];/is", "\$tablepre = '{$tablepre}';", $configfile); $configfile = preg_replace("/[\$]cookiepre\\s*\\=\\s*[\"'].*?[\"'];/is", "\$cookiepre = '" . random(3) . "_';", $configfile); if (!$error_admin) { $configfile = preg_replace("/[\$]forumfounders\\s*\\=\\s*[\"'].*?[\"'];/is", "\$forumfounders = '{$adminuser['uid']}';", $configfile); } @file_put_contents(DISCUZ_ROOT . './config.inc.php', $configfile); $db = new dbstuff(); $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset); $ucsql = file_get_contents(DISCUZ_ROOT . './uc_server/install/uc.sql'); $uctablepre = $tablepre . 'uc_'; $ucsql = str_replace(' uc_', ' ' . $uctablepre, $ucsql); $ucsql && runquery($ucsql, FALSE); $appauthkey = _generate_key(); $ucdbhost = $dbhost; $ucdbname = $dbname; $ucdbuser = $dbuser; $ucdbpw = $dbpw; $ucdbcharset = $dbcharset; $uccharset = $charset; $pathinfo = pathinfo($_SERVER['PHP_SELF']); $pathinfo['dirname'] = substr($pathinfo['dirname'], 0, -8); $appurl = 'http://' . preg_replace("/\\:\\d+/", '', $_SERVER['HTTP_HOST']) . ($_SERVER['SERVER_PORT'] && $_SERVER['SERVER_PORT'] != 80 ? ':' . $_SERVER['SERVER_PORT'] : '') . $pathinfo['dirname']; $ucapi = $appurl . '/uc_server'; $ucip = '127.0.0.1'; $app_tagtemplates = 'apptagtemplates[template]=' . urlencode('<a href="{url}" target="_blank">{subject}</a>') . '&' . 'apptagtemplates[fields][subject]=' . urlencode($lang['tagtemplates_subject']) . '&' . 'apptagtemplates[fields][uid]=' . urlencode($lang['tagtemplates_uid']) . '&' . 'apptagtemplates[fields][username]=' . urlencode($lang['tagtemplates_username']) . '&' . 'apptagtemplates[fields][dateline]=' . urlencode($lang['tagtemplates_dateline']) . '&' . 'apptagtemplates[fields][url]=' . urlencode($lang['tagtemplates_url']); $db->query("INSERT INTO {$uctablepre}applications SET name='Discuz! Board', url='{$appurl}', ip='{$ucip}', authkey='{$appauthkey}', synlogin='******', charset='{$charset}', dbcharset='{$dbcharset}', type='DISCUZ', recvnote='1', tagtemplates='{$apptagtemplates}'", $link); $appid = $db->insert_id($link); if ($appid < 1) {