\n"; $str .= "\t\n"; $str .= ""; send_mime_type_header(); echo $str; exit; } else { show_header(); global $step; $title = lang($error_no); $comment = lang($error_no.'_comment', false); $errormsg = ''; if($error_msg) { if(!empty($error_msg)) { foreach ((array)$error_msg as $k => $v) { if(is_numeric($k)) { $comment .= "
  • ".lang($v)."
  • "; } } } } if($step > 0) { echo "
    $title"; } else { echo "
    $title"; } if($quit) { echo '
    '.lang('error_quit_msg').'


    '; } echo '


    '; echo '
    '; $quit && show_footer(); } } function check_db($dbhost, $dbuser, $dbpw, $dbname, $tablepre) { if(!function_exists('mysqli_connect')) { show_msg('undefine_func', 'mysqli_connect', 0); } mysqli_report(MYSQLI_REPORT_OFF); $link = @new mysqli($dbhost, $dbuser, $dbpw); if(!$link) { $errno = mysqli_errno($link); $error = mysqli_error($link); if($errno == 1045) { show_msg('database_errno_1045', $error, 0); } elseif($errno == 2003) { show_msg('database_errno_2003', $error, 0); } else { show_msg('database_connect_error', $error, 0); } } else { if($query = ($link->query("SHOW TABLES FROM $dbname"))) { if(!$query) { return false; } while($row = ($query->fetch_row())) { if(preg_match("/^$tablepre/", $row[0])) { return false; } } } } return true; } function dirfile_check(&$dirfile_items) { foreach($dirfile_items as $key => $item) { $item_path = $item['path']; if($item['type'] == 'dir') { if(!dir_writeable(ROOT_PATH.$item_path)) { if(is_dir(ROOT_PATH.$item_path)) { $dirfile_items[$key]['status'] = 0; $dirfile_items[$key]['current'] = '+r'; } else { $dirfile_items[$key]['status'] = -1; $dirfile_items[$key]['current'] = 'nodir'; } } else { $dirfile_items[$key]['status'] = 1; $dirfile_items[$key]['current'] = '+r+w'; } } else { if(file_exists(ROOT_PATH.$item_path)) { if(is_writable(ROOT_PATH.$item_path)) { $dirfile_items[$key]['status'] = 1; $dirfile_items[$key]['current'] = '+r+w'; } else { $dirfile_items[$key]['status'] = 0; $dirfile_items[$key]['current'] = '+r'; } } else { if(dir_writeable(dirname(ROOT_PATH.$item_path))) { $dirfile_items[$key]['status'] = 1; $dirfile_items[$key]['current'] = '+r+w'; } else { $dirfile_items[$key]['status'] = -1; $dirfile_items[$key]['current'] = 'nofile'; } } } } } function env_check(&$env_items) { foreach($env_items as $key => $item) { if($key == 'php') { $env_items[$key]['current'] = PHP_VERSION; } elseif($key == 'attachmentupload') { $env_items[$key]['current'] = @ini_get('file_uploads') ? getmaxupload() : 'unknow'; } elseif($key == 'gdversion') { $tmp = function_exists('gd_info') ? gd_info() : array(); $env_items[$key]['current'] = empty($tmp['GD Version']) ? 'noext' : $tmp['GD Version']; unset($tmp); } elseif($key == 'diskspace') { if(function_exists('disk_free_space')) { $env_items[$key]['current'] = floor(disk_free_space(ROOT_PATH) / (1024*1024)).'M'; } else { $env_items[$key]['current'] = 'unknow'; } } elseif(isset($item['c'])) { $env_items[$key]['current'] = constant($item['c']); } elseif($key == 'opcache') { $opcache_data = function_exists('opcache_get_configuration') ? opcache_get_configuration() : array(); $env_items[$key]['current'] = !empty($opcache_data['directives']['opcache.enable']) ? 'enable' : 'disable'; } elseif($key == 'curl') { if(function_exists('curl_init') && function_exists('curl_version')){ $v = curl_version(); $env_items[$key]['current'] = 'enable'.' '.$v['version']; }else{ $env_items[$key]['current'] = 'disable'; } } elseif(isset($item['f'])) { $env_items[$key]['current'] = function_exists($item['f']) ? 'enable' : 'disable'; } $env_items[$key]['status'] = 1; if($item['r'] != 'notset' && strcmp($env_items[$key]['current'], $item['r']) < 0) { $env_items[$key]['status'] = 0; } } } function function_check(&$func_items) { foreach($func_items as $item) { function_exists($item) or show_msg('undefine_func', $item, 0); } } function show_env_result(&$env_items, &$dirfile_items, &$func_items) { $env_str = $file_str = $dir_str = $func_str = ''; $error_code = 0; foreach($env_items as $key => $item) { if($key == 'php' && strcmp($item['current'], $item['r']) < 0) { show_msg('php_version_too_low', $item['current'], 0); } $status = 1; if($item['r'] != 'notset') { if(intval($item['current']) && intval($item['r'])) { if(intval($item['current']) < intval($item['r'])) { $status = 0; $error_code = ENV_CHECK_ERROR; } } else { if(strcmp($item['current'], $item['r']) < 0) { $status = 0; $error_code = ENV_CHECK_ERROR; } } } if(VIEW_OFF) { $env_str .= "\t\t\n"; } else { $env_str .= "\n"; $env_str .= "".lang($key)."\n"; $env_str .= "".lang($item['r'])."\n"; $env_str .= "".lang($item['b'])."\n"; $env_str .= ($status ? "" : "").$item['current']."\n"; $env_str .= "\n"; } } foreach($dirfile_items as $key => $item) { $tagname = $item['type'] == 'file' ? 'File' : 'Dir'; $variable = $item['type'].'_str'; if(VIEW_OFF) { if($item['status'] == 0) { $error_code = ENV_CHECK_ERROR; } $$variable .= "\t\t\t\n"; } else { $$variable .= "\n"; $$variable .= "{$item['path']}".lang('writeable')."\n"; if($item['status'] == 1) { $$variable .= "".lang('writeable')."\n"; } elseif($item['status'] == -1) { $error_code = ENV_CHECK_ERROR; $$variable .= "".lang('nodir')."\n"; } else { $error_code = ENV_CHECK_ERROR; $$variable .= "".lang('unwriteable')."\n"; } $$variable .= "\n"; } } if(VIEW_OFF) { $str = "\n"; $str .= "\t\n"; $str .= $env_str; $str .= "\t\n"; $str .= "\t\n"; $str .= "\t\t\n"; $str .= $dir_str; $str .= "\t\t\n"; $str .= "\t\t\n"; $str .= $file_str; $str .= "\t\t\n"; $str .= "\t\n"; $str .= "\t\n"; $str .= ""; send_mime_type_header(); echo $str; exit; } else { show_header(); echo "

    ".lang('env_check')."

    \n"; echo "\n"; echo "\n"; echo "\t\n"; echo "\t\n"; echo "\t\n"; echo "\t\n"; echo "\n"; echo $env_str; echo "
    ".lang('project')."".lang('ucenter_required')."".lang('ucenter_best')."".lang('curr_server')."
    \n"; echo "

    ".lang('priv_check')."

    \n"; echo "\n"; echo "\t\n"; echo "\t\n"; echo "\t\n"; echo "\t\n"; echo "\n"; echo $file_str; echo $dir_str; echo "
    ".lang('step1_file')."".lang('step1_need_status')."".lang('step1_status')."
    \n"; foreach($func_items as $item) { $status = function_exists($item); $func_str .= "\n"; $func_str .= "$item()\n"; if($status) { $func_str .= "".lang('supportted')."\n"; $func_str .= "".lang('none')."\n"; } else { $error_code = ENV_CHECK_ERROR; $func_str .= "".lang('unsupportted')."\n"; $func_str .= "".lang('advice_'.$item)."\n"; } } echo "

    ".lang('func_depend')."

    \n"; echo "\n"; echo "\n"; echo "\t\n"; echo "\t\n"; echo "\t\n"; echo "\n"; echo $func_str; echo "
    ".lang('func_name')."".lang('check_result')."".lang('suggestion')."
    \n"; show_next_step(2, $error_code); show_footer(); } } function show_next_step($step, $error_code) { echo "
    \n"; echo ""; if(isset($GLOBALS['hidden'])) { echo $GLOBALS['hidden']; } if($error_code == 0) { $nextstep = "\n"; } else { $nextstep = "\n"; } echo "
    ".$nextstep."
    \n"; echo "
    \n"; } function show_form(&$form_items, $error_msg) { global $step; if(empty($form_items) || !is_array($form_items)) { return; } show_header(); show_setting('start'); show_setting('hidden', 'step', $step); $is_first = 1; foreach($form_items as $key => $items) { global ${'error_'.$key}; if($is_first == 0) { echo ''; } if(!${'error_'.$key}) { show_tips('tips_'.$key); } else { show_error('tips_admin_config', ${'error_'.$key}); } if($is_first == 0) { echo ''; } foreach($items as $k => $v) { global $$k; if(!empty($error_msg)) { $value = isset($_POST[$key][$k]) ? $_POST[$key][$k] : ''; } else { if(isset($v['value']) && is_array($v['value'])) { if($v['value']['type'] == 'constant') { $value = defined($v['value']['var']) ? constant($v['value']['var']) : ''; } elseif($v['value']['type'] == 'var') { $value = $GLOBALS[$v['value']['var']]; } elseif($v['value']['type'] == 'string') { $value = $v['value']['var']; } } else { $value = ''; } } if($v['type'] == 'checkbox') { $value = '1'; } show_setting($k, $key.'['.$k.']', $value, $v['type'], isset($error_msg[$key][$k]) ? $key.'_'.$k.'_invalid' : ''); } if($is_first) { $is_first = 0; } } show_setting('', 'submitname', 'new_step', 'submit'); show_setting('end'); show_footer(); } function show_license() { global $self, $uchidden, $step; $next = $step + 1; if(VIEW_OFF) { show_msg('license_contents', lang('license'), 1); } else { show_header(); $license = str_replace(' ', '  ', lang('license')); $lang_agreement_yes = lang('agreement_yes'); $lang_agreement_no = lang('agreement_no'); echo <<
    $license
    $uchidden  
    EOT; show_footer(); } } function createtable($sql) { $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql)); $type = in_array($type, array('INNODB', 'MYISAM', 'HEAP', 'MEMORY')) ? $type : 'INNODB'; return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql) . " ENGINE=$type DEFAULT CHARSET=" . DBCHARSET . (DBCHARSET === 'utf8mb4' ? " COLLATE=utf8mb4_unicode_ci" : ""); } function dir_writeable($dir) { $writeable = 0; if(!is_dir($dir)) { @mkdir($dir, 0777); } if(is_dir($dir)) { if($fp = @fopen("$dir/test.txt", 'w')) { @fclose($fp); @unlink("$dir/test.txt"); $writeable = 1; } else { $writeable = 0; } } return $writeable; } function dir_clear($dir) { global $lang; showjsmessage($lang['clear_dir'].' '.str_replace(ROOT_PATH, '', $dir)); $directory = dir($dir); while($entry = $directory->read()) { $filename = $dir.'/'.$entry; if(is_file($filename)) { @unlink($filename); } } $directory->close(); @touch($dir.'/index.htm'); } function show_header() { define('SHOW_HEADER', TRUE); global $step; $version = SOFT_VERSION; $release = SOFT_RELEASE; $install_lang = lang(INSTALL_LANG); $title = lang('title_install'); $charset = CHARSET; echo << $title

    $title

    V$version $install_lang $release EOT; $step > 0 && show_step($step); } function show_footer($quit = true) { $copy = lang('copyright'); echo <<$copy
    EOT; $quit && exit(); } function showjsmessage($message) { if(VIEW_OFF) return; echo ''."\r\n"; flush(); ob_flush(); } function random($length, $numeric = 0) { $seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35); $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed)); if($numeric) { $hash = ''; } else { $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64); $length--; } $max = strlen($seed) - 1; for($i = 0; $i < $length; $i++) { $hash .= $seed[mt_rand(0, $max)]; } return $hash; } function secrandom($length, $numeric = 0, $strong = false) { $chars = $numeric ? array('A','B','+','/','=') : array('+','/','='); $num_find = str_split('CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'); $num_repl = str_split('01234567890123456789012345678901234567890123456789'); $isstrong = false; if(function_exists('random_bytes')) { $isstrong = true; $random_bytes = function($length) { return random_bytes($length); }; } elseif(extension_loaded('mcrypt') && function_exists('mcrypt_create_iv')) { $isstrong = true; $random_bytes = function($length) { $rand = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM); if ($rand !== false && strlen($rand) === $length) { return $rand; } else { return false; } }; } elseif(extension_loaded('openssl') && function_exists('openssl_random_pseudo_bytes')) { $isstrong = true; $random_bytes = function($length) { $rand = openssl_random_pseudo_bytes($length, $secure); if($secure === true) { return $rand; } else { return false; } }; } if(!$isstrong) { return $strong ? false : random($length, $numeric); } $retry_times = 0; $return = ''; while($retry_times < 128) { $getlen = $length - strlen($return); // 33% extra bytes $bytes = $random_bytes(max($getlen, 12)); if($bytes === false) { return false; } $bytes = str_replace($chars, '', base64_encode($bytes)); $return .= substr($bytes, 0, $getlen); if(strlen($return) == $length) { return $numeric ? str_replace($num_find, $num_repl, $return) : $return; } $retry_times++; } } function redirect($url) { echo ""; exit(); } function validate_ip($ip) { return filter_var($ip, FILTER_VALIDATE_IP) !== false; } function get_onlineip() { $onlineip = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) { $onlineip = $_SERVER['HTTP_CLIENT_IP']; } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") > 0) { $exp = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']); $onlineip = validate_ip(trim($exp[0])) ? $exp[0] : $onlineip; } else { $onlineip = validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $onlineip; } } return $onlineip; } function config_edit() { extract($GLOBALS, EXTR_SKIP); $ucsalt = ''; $ucfounderpw = password_hash($ucfounderpw, PASSWORD_BCRYPT); $regdate = time(); $ucauthkey = generate_key(); $ucsiteid = generate_key(); $ucmykey = generate_key(); $config = " 'HTTP_X_FORWARDED_FOR')));\r\n"; file_put_contents(CONFIG, $config); } function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; $key = md5($key ? $key : UC_KEY); $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc); $key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; $string_length = strlen($string); $result = ''; $box = range(0, 255); $rndkey = array(); for($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); } if($operation == 'DECODE') { if(((int)substr($result, 0, 10) == 0 || (int)substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) === substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.str_replace('=', '', base64_encode($result)); } } function generate_key($length = 32) { $random = secrandom($length); $info = md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['SERVER_NAME'].(isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '').(isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : '').$_SERVER['HTTP_USER_AGENT'].time()); $return = ''; for($i=0; $i<$length; $i++) { $return .= $random[$i].$info[$i]; } return $return; } function show_install() { if(VIEW_OFF) return; ?>
    query(createtable($query)); } else { $db->query($query); } } } } function charcovert($string) { return str_replace('\'', '\\\'', $string); } function insertconfig($s, $find, $replace) { if(preg_match($find, $s)) { $s = preg_replace($find, $replace, $s); } else { $s .= "\r\n".$replace; } return $s; } function getgpc($k, $t='GP') { $t = strtoupper($t); switch($t) { case 'GP' : isset($_POST[$k]) ? $var = &$_POST : $var = &$_GET; break; case 'G': $var = &$_GET; break; case 'P': $var = &$_POST; break; case 'C': $var = &$_COOKIE; break; case 'R': $var = &$_REQUEST; break; } return isset($var[$k]) ? $var[$k] : ''; } function var_to_hidden($k, $v) { return "\n"; } function fsocketopen($hostname, $port = 80, &$errno = null, &$errstr = null, $timeout = 15) { $fp = ''; if(function_exists('fsockopen')) { $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout); } elseif(function_exists('pfsockopen')) { $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout); } elseif(function_exists('stream_socket_client')) { $fp = @stream_socket_client($hostname.':'.$port, $errno, $errstr, $timeout); } return $fp; } function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); $scheme = strtolower($matches['scheme']); $host = $matches['host']; $path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/'; $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80); if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { $ch = curl_init(); $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host)); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); if(!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP) && !filter_var($host, FILTER_VALIDATE_IP) && version_compare(PHP_VERSION, '5.5.0', 'ge')) { curl_setopt($ch, CURLOPT_RESOLVE, array("$host:$port:$ip")); curl_setopt($ch, CURLOPT_URL, $scheme.'://'.$host.':'.$port.$path); } else { curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if($post) { curl_setopt($ch, CURLOPT_POST, 1); if($encodetype == 'URLENCODE') { curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } else { parse_str($post, $postarray); curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray); } } if($cookie) { curl_setopt($ch, CURLOPT_COOKIE, $cookie); } curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); $status = curl_getinfo($ch); $errno = curl_errno($ch); curl_close($ch); if($errno || $status['http_code'] != 200) { return; } else { return !$limit ? $data : substr($data, 0, $limit); } } if($post) { $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; if($allowcurl) { $encodetype = 'URLENCODE'; } $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2)); $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n"; $header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n"; $header .= "Host: $host:$port\r\n"; $header .= 'Content-Length: '.strlen($post)."\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cache-Control: no-cache\r\n"; $header .= "Cookie: $cookie\r\n\r\n"; $out .= $header.$post; } else { $out = "GET $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; $header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n"; $header .= "Host: $host:$port\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cookie: $cookie\r\n\r\n"; $out .= $header; } $fpflag = 0; $context = array(); if($scheme == 'https') { $context['ssl'] = array( 'verify_peer' => false, 'verify_peer_name' => false, 'peer_name' => $host ); if(version_compare(PHP_VERSION, '5.6.0', '<')) { $context['ssl']['SNI_enabled'] = true; $context['ssl']['SNI_server_name'] = $host; } } if(ini_get('allow_url_fopen')) { $context['http'] = array( 'method' => $post ? 'POST' : 'GET', 'header' => $header, 'timeout' => $timeout ); if($post) { $context['http']['content'] = $post; } $context = stream_context_create($context); $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context); $fpflag = 1; } elseif(function_exists('stream_socket_client')) { $context = stream_context_create($context); $fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); } else { $fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout); } if(!$fp) { return ''; } else { stream_set_blocking($fp, $block); stream_set_timeout($fp, $timeout); if(!$fpflag) { @fwrite($fp, $out); } $status = stream_get_meta_data($fp); if(!$status['timed_out']) { while (!feof($fp) && !$fpflag) { if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) { break; } } $stop = false; while(!feof($fp) && !$stop) { $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit)); $return .= $data; if($limit) { $limit -= strlen($data); $stop = $limit <= 0; } } } @fclose($fp); return $return; } } function check_env() { global $lang, $attachdir; $errors = array('quit' => false); $quit = false; if(!function_exists('mysqli_connect')) { $errors[] = 'mysqli_unsupport'; $quit = true; } if(!file_exists(DISCUZ_ROOT.'./config.inc.php')) { $errors[] = 'config_nonexistence'; $quit = true; } elseif(!is_writeable(DISCUZ_ROOT.'./config.inc.php')) { $errors[] = 'config_unwriteable'; $quit = true; } $checkdirarray = array( 'attach' => $attachdir, 'forumdata' => './forumdata', 'cache' => './forumdata/cache', 'ftemplates' => './forumdata/templates', 'threadcache' => './forumdata/threadcaches', 'log' => './forumdata/logs', 'uccache' => './uc_client/data/cache' ); foreach($checkdirarray as $key => $dir) { if(!dir_writeable(DISCUZ_ROOT.$dir)) { $langkey = $key.'_unwriteable'; $errors[] = $key.'_unwriteable'; if(!in_array($key, array('ftemplate'))) { $quit = TRUE; } } } $errors['quit'] = $quit; return $errors; } function show_error($type, $errors = '', $quit = false) { global $lang, $step; $title = lang($type); $comment = lang($type.'_comment', false); $errormsg = ''; if($errors) { if(!empty($errors)) { foreach ((array)$errors as $k => $v) { if(is_numeric($k)) { $comment .= "
  • ".lang($v)."
  • "; } } } } if($step > 0) { echo "
    $title
      $comment
    "; } else { echo "
    $title
      $comment
    "; } if($quit) { echo '
    '.$lang['error_quit_msg'].'





    '; } echo '
    '; $quit && show_footer(); } function show_tips($tip, $title = '', $comment = '', $style = 1) { global $lang; $title = empty($title) ? lang($tip) : $title; $comment = empty($comment) ? lang($tip.'_comment', FALSE) : $comment; if($style) { echo "
    $title"; } else { echo "
    $title
      "; } $comment && print('
      '.$comment); echo "
    "; } function show_setting($setname, $varname = '', $value = '', $type = 'text|password|checkbox', $error = '') { if($setname == 'start') { echo "
    \n
    \n"; return; } elseif($setname == 'end') { echo "\n
    \n\n"; return; } elseif($setname == 'hidden') { echo "\n"; return; } echo "\n".' '.(empty($setname) ? '' : lang($setname).':')."\n"; if($type == 'text' || $type == 'password') { $value = dhtmlspecialchars($value); echo ""; } elseif($type == 'submit') { $value = empty($value) ? 'next_step' : $value; echo "\n"; } elseif($type == 'checkbox') { if(!is_array($varname) && !is_array($value)) { echo'\n"; } } else { echo $value; } echo "\n "; if($error) { $comment = ''.(is_string($error) ? lang($error) : lang($setname.'_error')).''; } else { $comment = lang($setname.'_comment', false); } echo "$comment\n\n"; return true; } function show_step($step) { global $method; $laststep = 4; $title = lang('step_'.$method.'_title'); $comment = lang('step_'.$method.'_desc'); $stepclass = array(); for($i = 1; $i <= $laststep; $i++) { $stepclass[$i] = $i == $step ? 'current' : ($i < $step ? '' : 'unactivated'); } $stepclass[$laststep] .= ' last'; echo <<

    $title

    $comment

    • 1
    • 2
    • 3
    • 4
    EOT; } function lang($lang_key, $force = true) { return isset($GLOBALS['lang'][$lang_key]) ? $GLOBALS['lang'][$lang_key] : ($force ? $lang_key : ''); } function check_adminuser($username, $password, $email) { @include ROOT_PATH.'./config.inc.php'; include ROOT_PATH.'./uc_client/client.php'; $error = ''; $uid = uc_user_register($username, $password, $email); if($uid == -1 || $uid == -2) { $error = 'admin_username_invalid'; } elseif($uid == -4 || $uid == -5 || $uid == -6) { $error = 'admin_email_invalid'; } elseif($uid == -3) { $ucresult = uc_user_login($username, $password); list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email']) = uc_addslashes($ucresult); $ucresult = $tmp; if($ucresult['uid'] <= 0) { $error = 'admin_exist_password_error'; } else { $uid = $ucresult['uid']; $email = $ucresult['email']; $password = $ucresult['password']; } } if(!$error && $uid > 0) { $password = md5($password); uc_user_addprotected($username, ''); } else { $uid = 0; $error = empty($error) ? 'error_unknow_type' : $error; } return array('uid' => $uid, 'username' => $username, 'password' => $password, 'email' => $email, 'error' => $error); } function dhtmlspecialchars($string, $flags = null) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dhtmlspecialchars($val, $flags); } } else { if($flags === null) { $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string); if(strpos($string, '&#') !== false) { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $string); } } else { if(PHP_VERSION < '5.4.0') { $string = htmlspecialchars($string, $flags); } else { if(strtolower(CHARSET) == 'utf-8') { $charset = 'UTF-8'; } else { $charset = 'ISO-8859-1'; } $string = htmlspecialchars($string, $flags, $charset); } } } return $string; } function send_mime_type_header($type = 'application/xml') { header("Content-Type: ".$type); } function getmaxupload() { $sizeconv = array('B' => 1, 'KB' => 1024, 'MB' => 1048576, 'GB' => 1073741824); $sizes = array(); $sizes[] = ini_get('upload_max_filesize'); $sizes[] = ini_get('post_max_size'); $sizes[] = ini_get('memory_limit'); if(intval($sizes[1]) === 0) { unset($sizes[1]); } if(intval($sizes[2]) === -1) { unset($sizes[2]); } $sizes = preg_replace_callback( '/^(\-?\d+)([KMG]?)$/i', function($arg) use ($sizeconv) { return (intval($arg[1]) * $sizeconv[strtoupper($arg[2]).'B']).'|'.strtoupper($arg[0]); }, $sizes ); natsort($sizes); $output = explode('|', current($sizes)); if(!empty($output[1])) { return $output[1]; } else { return ini_get('upload_max_filesize'); } }