<?php
require ('authentication_manager.php');
?>
<?php

/* 网站参数配置 */
/* 162100源码 - 162100.com */

if (!function_exists('get_root_domain')) {
  @ require ('inc/function/get_root_domain.php');
}
@ require ('inc/function/filter.php');
if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆。');
}

$_POST['manager'] = strtolower($_POST['manager']);
$_POST['password'] = strtolower($_POST['password']);

if ($_POST['password'] == '') {
  $psw = $web['password'];
} else {
  if (preg_match('/[\s\r\n]+/', $_POST['password'])) {
    err('基础管理员密码不能有空格。');
  }
  if (strlen($_POST['password']) > 30 || strlen($_POST['password']) < 3) {
    err('基础管理员密码长度是3-30字符。');
  }
  $psw = md162100(filter1(strtolower($_POST['password'])));
}

if (!preg_match('/^[\x80-\xff\w]{3,45}$/', $_POST['manager'])) {
  err('基础管理员名称不能空且请用汉字、数字、英文及下划线组成！长度范围为3-45字符。');
}
if (!empty($_POST['sitelogo']) && !file_exists($_POST['sitelogo'])) {
  err('你所填的信息站LOGO不存在！请先将制作好的logo图片制为gif格式，存到images目录中。');
}
if (isset($_POST['sitemode'])) {
  if(!file_exists('inc/css/'.$_POST['sitemode'].'/index.php')) {
    err('你所选的风格模式'.$_POST['sitemode'].'出错！（首页模板不存在！）。');
  } elseif (!file_exists('inc/css/'.$_POST['sitemode'].'/list.php')) {
    err('你所选的风格模式'.$_POST['sitemode'].'出错！（列表模板不存在！）。');
  } elseif (!file_exists('inc/css/'.$_POST['sitemode'].'/article.php')) {
    err('你所选的风格模式'.$_POST['sitemode'].'出错！（文章模板不存在！）。');
  }
} else {
  if (!(file_exists('inc/css/a/index.php') && file_exists('inc/css/a/list.php') && file_exists('inc/css/a/article.php'))) {
    err('默认风格模板不存在！请检查inc/css/a目录。');
  } else {
    $_POST['sitemode'] = 'a';
  }
}

$_POST['_17_type'] = strtolower(preg_replace('/^\||\|$/', '', preg_replace('/\|{2,}/', '|', $_POST['_17_type'])));
$_POST['_18_type'] = strtolower(preg_replace('/^\||\|$/', '', preg_replace('/\|{2,}/', '|', $_POST['_18_type'])));
if (preg_match('/[^a-zA-Z0-9\|]+/', $_POST['_17_type']))
  err('允许上传的影音文件只应用合理的后缀名及分隔符|填写。');
if (preg_match('/[^a-zA-Z0-9\|]+/', $_POST['_18_type']))
  err('允许上传的其它文件只应用合理的后缀名及分隔符|填写。');
  
unset($web['sitehttp']);
$web['sitehttp'] = 'http://'.(!empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']).'/';  //站点网址
$web['sitehttp'] = ($web['sitehttp'] == 'http://localhost/' || $web['sitehttp'] == 'http://127.0.0.1/') ? '' : $web['sitehttp'];


  @unlink('./.htaccess');
  @unlink('./web.config');
  @unlink('./httpd.ini');
  $wjt_index = $_POST['url_html_index'] == 1 ? 1 : 0;
  $wjt_list = $_POST['url_html_list'] == 1 ? 1 : 0;
  $wjt_article = $_POST['url_html_article'] == 1 ? 1 : 0;
if ($_POST['p_static'] == 'Apache') {
  @copy('inc/function/Apache/.htaccess', './.htaccess');
} elseif ($_POST['p_static'] == 'IIS7') {
  @copy('inc/function/IIS7/web.config', './web.config');
} elseif ($_POST['p_static'] == 'IIS6') {
  @copy('inc/function/IIS6/httpd.ini', './httpd.ini');
} else {
  $wjt_index = $wjt_list = $wjt_article = 0;
}

$text_web='
$web[\'code_author\'] = \'\'; //base64_decode(\'IC0gUG93ZXJlZCBieSAxNjIxMDAuY29t\');
$web[\'sitehttp\'] = \''.$web['sitehttp'].'\';  //站点网址
$web[\'root\'] = \''.get_root_domain($web['sitehttp']).'\'; //根目录
if ($web[\'sitehttp\'] == \'\') {
  $web[\'sitehttp\'] = \'http://\'.(!empty($_SERVER[\'HTTP_X_FORWARDED_HOST\']) ? $_SERVER[\'HTTP_X_FORWARDED_HOST\'] : $_SERVER[\'HTTP_HOST\']).\'/\';  //站点网址
  $GLOBALS[\'WEATHER_DATA\'] = (isset($GLOBALS[\'WEATHER_DATA\']) && $GLOBALS[\'WEATHER_DATA\']) ? $GLOBALS[\'WEATHER_DATA\'] : \'\';
  if (!function_exists(\'get_root_domain\')) {
    @ require ($GLOBALS[\'WEATHER_DATA\'].\'inc/function/get_root_domain.php\');
  }
  $web[\'root\'] = get_root_domain($web[\'sitehttp\']);
}
$web[\'path\'] = dirname(trim($web[\'sitehttp\'], \'/\').$_SERVER[\'REQUEST_URI\'].\'.abc\').\'/\';  //路径

//管理员设置
$web[\'manager\'] = \''.$_POST['manager'].'\';  //基础管理员名称
$web[\'password\'] = \''.$psw.'\';  //基础管理员密码，注：系统出现一切故障时以基础管理员名称和密码为准

//网站外观
$web[\'sitemode\'] = \''.$_POST['sitemode'].'\';  //网站模式
$web[\'listmode\'] = '.abs($_POST['list_mode']).';  //列表模式：0普通列表 1突出头像 2缩略图列表 3同时
$web[\'siteclose\'] = '.($_POST['siteclose'] == 1 || $_POST['siteclose'] == 2 || $_POST['siteclose'] == 3 ? $_POST['siteclose'] : 0).';  //0正常 1全站公告 2首页公告 3网站关闭
$web[\'sitelogo\'] = \''.filter1($_POST['sitelogo']).'\';  //网站LOGO

//基本设置
$web[\'sitename\'] = \''.(!empty($_POST['sitename']) ? filter1($_POST['sitename'], true) : '我的网站').'\';  //站点名称
$web[\'sitename2\'] = \''.(!empty($_POST['sitename2']) ? filter1($_POST['sitename2'], true) : '我的网站').'\';  //站点简称
$web[\'description\'] = \''.filter1($_POST['description'], true).'\';  //站点描述
$web[\'keywords\'] = \''.filter1($_POST['keywords'], true).'\';  //关键字
$web[\'stop_reg\'] = '.($_POST['stop_reg'] != 1 && $_POST['stop_reg'] != 2 ? 0 : $_POST['stop_reg']).';  //用户注册 1禁止 0不禁止 2注册需审核
$web[\'stop_login\'] = '.abs($_POST['stop_login']).';  //用户登录密码错误限数 0不限
$web[\'re_update\'] = '.($_POST['re_update'] != 1 ? 0 : 1).';  //1回复时将主题文章提前 0自然顺序
$web[\'re_del\'] = '.($_POST['re_del'] != 1 ? 0 : 1).';  //1允许用户删除自己的回复 0不允许

//全局设置
$web[\'chmod\'] = \''.(!preg_match('/^0?([0-7]{3})$/', $_POST['chmod'], $matches_chmod) ? '755' : $matches_chmod[1]).'\';  //权限
$web[\'time_pos\'] = \''.$_POST['time_pos'].'\';  //服务器时区调整
$web[\'mail_send\'] = '.(abs((int)$_POST['mail_send']) != 1 ? 0 : 1).';  //1发送邮件 0不发送
$web[\'time_mode\'] = '.(abs((int)$_POST['time_mode']) != 1 ? 0 : 1).';  //人性化时间模式（如几分钟前、几小时前、昨天、前天……）
$web[\'onlinetimed\'] = '.(abs($_POST['onlinetimed']) > 0 ? abs((int)$_POST['onlinetimed']) : 10).';  //在线统计取？分钟之内活动者
$web[\'pagesize\'] = '.(abs($_POST['pagesize'])>0 ? abs((int)$_POST['pagesize']) : 30).';  //每页显示数量
$web[\'pagesize_reply\'] = '.(abs($_POST['pagesize_reply'])>0 ? abs((int)$_POST['pagesize_reply']) : 20).';  //回复评论页面每页显示数量
$web[\'list_wordcount\'] = '.(abs($_POST['list_wordcount']) > 0 ? abs((int)$_POST['list_wordcount']) : 50000).';  //发表文章最多字符数
$web[\'re_wordcount\'] = '.(abs($_POST['re_wordcount']) > 0 ? abs((int)$_POST['re_wordcount']) : 5000).';  //评论回复最多字符数
$web[\'mess_wordcount\'] = '.(abs($_POST['mess_wordcount']) > 0 ? abs((int)$_POST['mess_wordcount']) : 400).';  //短信发表最多字符数
$web[\'mess_count\'] = '.(abs($_POST['mess_count']) > 0 ? abs((int)$_POST['mess_count']) : 100).';  //站内短信最多保存条数

//伪静态
$web[\'url_html_index\'] = '.$wjt_index.';  //首页伪静态
$web[\'url_html_list\'] = '.$wjt_list.';  //列表页伪静态
$web[\'url_html_article\'] = '.$wjt_article.';  //文章页伪静态

//关于积分
$web[\'class_iron\'] = '.abs((int)$_POST['class_iron']).';  //铁级用户等级分标准
$web[\'class_silver\'] = '.abs((int)$_POST['class_silver']).';  //银级用户等级分标准
$web[\'class_gold\'] = '.abs((int)$_POST['class_gold']).';  //金级用户等级分标准，大于此数量的为砧级用户
$web[\'loginadd\'] = '.abs((int)$_POST['loginadd']).';  //用户登陆加等级分数
$web[\'writeadd\'] = '.abs((int)$_POST['writeadd']).';  //用户发表主题加等级分数
$web[\'replyadd\'] = '.abs((int)$_POST['replyadd']).';  //用户回复加等级分数
$web[\'regadd\'] = '.round((float)$_POST['regadd'], 2).';  //用户注册赠送货币值
$web[\'refreshdel\'] = '.round((float)$_POST['refreshdel'], 2).';  //用户刷新每篇扣除货币值
$web[\'addcolordel\'] = '.round((float)$_POST['addcolordel'], 2).';  //主题着色每篇扣除货币值
$web[\'top_point\'] = '.((float)$_POST['top_point'] > 0 ? round((float)$_POST['top_point'], 2) : 10.00).';  //或购买置顶每篇每天扣货币值
$web[\'top_expires\'] = '.((float)$_POST['top_expires'] > 0 ? (float)$_POST['top_expires'] : 30).';  //全局置顶期限，一般30天
$web[\'top_expires_member\'] = '.((float)$_POST['top_expires_member'] > 0 ? (float)$_POST['top_expires_member'] : 1).';  //用户购买置顶最低期限
$web[\'ess_index_point\'] = '.((float)$_POST['ess_index_point'] > 0 ? round((float)$_POST['ess_index_point'], 2) : 10.00).';  //或购买首页图文展示每篇每天扣货币值
$web[\'ess_index_expires_member\'] = '.((float)$_POST['ess_index_expires_member'] > 0 ? (float)$_POST['ess_index_expires_member'] : 1).';  //用户购买首页图文展示最低期限
$web[\'reward_cash_add_credit\'] = '.round((float)$_POST['reward_cash_add_credit'], 2).';  //兑现悬赏加赠信誉值
$web[\'point_funds\'] = array(\''.abs($_POST['class_point_0']).'\', \''.round((float)$_POST['class_point_1'], 2).'\');  //等级分转换货币值

//关于发表
$web[\'send_face\'] = '.(abs($_POST['send_face']) != 1 ? 0 : 1).';  //1注册成员必须上传了头像才允许发表 0否
$web[\'reg_to_send\'] = '.abs((int)$_POST['reg_to_send']).';  //新注册成员  秒之后才允许发表
$web[\'send_mx\'] = '.(abs((int)$_POST['send_mx']) != 1 ? 0 : 1).';  //1每日发表限量 0不限量
$web[\'send_re\'] = '.($_POST['send_re'] == 1 || $_POST['send_re'] == 2 ? $_POST['send_re'] : 0).';  //1全文禁止重复 2作者禁止重复 0随便
$web[\'send_ms\'] = '.abs((int)$_POST['send_ms']).';  //发表时间间隔 0不间隔
$web[\'write_start\'] = '.abs((int)$_POST['write_start']).';  //发表权限起始分，如：禁止新人发表可设高一点分值
$web[\'up_start\'] = '.abs((int)$_POST['up_start']).';  //上传权限起始分
$web[\'link_start\'] = '.abs((int)$_POST['link_start']).';  //文章允许加链接起始分
$web[\'max_file_size\'][15] = '.abs((int)$_POST['max_face_size_15']).';  //限定上传图片尺寸（单位KB）
$web[\'max_file_size\'][16] = '.abs((int)$_POST['max_face_size_16']).';  //限定上传动画尺寸（单位KB）
$web[\'max_file_size\'][17] = '.abs((int)$_POST['max_face_size_17']).';  //限定上传影音文件尺寸（单位KB）
$web[\'max_file_size\'][18] = '.abs((int)$_POST['max_face_size_18']).';  //限定上传其它文件尺寸（单位KB）
$web[\'_17_type\'] = \''.$_POST['_17_type'].'\';  //设置允许上传的影音文件类型，用|分开写
$web[\'_18_type\'] = \''.$_POST['_18_type'].'\';  //设置允许上传的其它文件类型，用|分开写
$web[\'uploadto\'] = '.(abs($_POST['uploadto']) != 1 ? 0 : 1).';  //1保存到数据库 0保存在目录
$web[\'temp\'] = '.(abs($_POST['uploadto']) == 1 ? (abs($_POST['temp']) != 1 ? 0 : 1) : 1).';  //1保留临时上传文件 0否

//图片处理
$web[\'water\'] = '.(abs($_POST['water']) != 1 ? 0 : 1).';                //1图片加水印 0否
$web[\'spic_w\'] = '.(abs($_POST['spic_w']) > 0 ? abs((int)$_POST['spic_w']) : 60).';  //缩略图宽
$web[\'spic_h\'] = '.(abs($_POST['spic_h']) > 0 ? abs((int)$_POST['spic_h']) : 45).';  //缩略图高
$web[\'pic_markwords\'] = \''.filter1($_POST['pic_markwords'], true).'\';  //水印文字
$web[\'pic_markfont\'] = \''.filter1($_POST['pic_markfont'], true).'\';  //水印字体
$web[\'pic_quality\'] = '.(abs($_POST['pic_quality']) > 60 ? abs((int)$_POST['pic_quality']) : 80).';  //上传图片质量

//登录接口
$web[\'login_key\'] = '.var_export($_POST['login_key'], true).';


';

  $text = '<?php
@ini_set(\'default_charset\', \'utf-8\');
@ini_set(\'display_errors\', \'Off\');
@error_reporting(E_ERROR | E_WARNING | E_PARSE);
if(PHP_VERSION < "4.1.0"){
  $_GET = &$HTTP_GET_VARS;
  $_POST = &$HTTP_POST_VARS;
  $_COOKIE = &$HTTP_COOKIE_VARS;
  $_SERVER = &$HTTP_SERVER_VARS;
  $_ENV = &$HTTP_ENV_VARS;
  $_FILES = &$HTTP_POST_FILES;
}

$_GET = array_map(\'htmlspecialchars\', preg_replace(\'/[\r\n]+/\', \'\', $_GET));

$web = array();

/* ----------【网站设置】能不用尽量不要用特殊符号，如 \ / : ; * ? \' < > | ，必免导致错误--------- */
'.$text_web.'

?>';

//@copy('index.'.$_POST['sitemode'].'.php', 'index.php');

@ require ('inc/function/write_file.php');
if (abs($_POST['siteclose']) > 0) {
  $_POST['siteclose_why'] = filter_this($_POST['siteclose_why']); //filter_this
  $_POST['siteclose_why'] = "<div class=\"siteannounce\">".preg_replace("/\s*\n\s*/", "</div>\n<div class=\"siteannounce\">", $_POST['siteclose_why'])."</div>";
  write_file('inc/require/siteclose_why.txt', $_POST['siteclose_why'].($_POST['siteclose'] == 3 ? '<?php if (POWER != 5) { die(\'</body></html>\'); } ?>' : '').'');
}

if (!empty($_POST['siteannounce'])) {
  $_POST['siteannounce'] = filter_this($_POST['siteannounce']); //filter_this
  $_POST['siteannounce'] = "<div class=\"siteannounce\">".preg_replace("/\s*[\r\n]+\s*/", "</div>\n<div class=\"siteannounce\">", $_POST['siteannounce'])."</div>";
  write_file('inc/require/siteannounce.txt', $_POST['siteannounce']);
} else {
  write_file('inc/require/siteannounce.txt', '');
}


function filter_this($text) {
  $text = trim($text);
  $text = stripslashes($text);
  $text = htmlspecialchars($text);
  $text = preg_replace('/[\r\n]+/', "\n", $text);
  $text = str_replace('\'', '&#039;', $text);
  $text = str_replace('\\', '&#92;', $text);
  return $text;
}


function md162100($str) {
  return substr(sha1(md5($str)), 4, 32);
}


$sqlaccess = '';
if ($_POST['manager'] != $web['manager'] || $psw != $web['password']) {
  if (!isset($sql['db_err'])) {
    db_conn();
  }

  if ($sql['db_err'] == '') {
    if (@mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET username="'.$_POST['manager'].'",password="'.$psw.'" WHERE username="'.$web['manager'].'" LIMIT 1', $db)) {
      $admin_c = 1;
    } else {
      if (@mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET password="'.$psw.'" WHERE username="'.$_POST['manager'].'" LIMIT 1', $db)) {
        $admin_c = 1;
      }
    }
    if (isset($admin_c) && $admin_c == 1) {
    //if (@mysql_affected_rows() > 0) {
      if ($_POST['manager'] != $web['manager']) {
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET author_ip="'.$_POST['manager'].'" WHERE author_ip="'.$web['manager'].'"', $db);
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' SET author_ip="'.$_POST['manager'].'" WHERE author_ip="'.$web['manager'].'"', $db);
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' SET username="'.$_POST['manager'].'" WHERE username="'.$web['manager'].'"', $db);
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' SET username="'.$_POST['manager'].'" WHERE username="'.$web['manager'].'"', $db);
      }
      $sqlaccess = '数据库管理员名称和密码副本同时更新成功。由于管理员信息被改动，建议重新登陆以使新设置生效！
      <script language="javascript" type="text/javascript">
      <!--
      var expiration=new Date((new Date()).getTime()-31622400);
      try{
      document.cookie="usercookie=; expires="+expiration.toGMTString()+"; path=/; domain=.'.$web['root'].';";
	  }catch (e) {
	  }
      document.cookie="usercookie=; expires="+expiration.toGMTString()+"; path=/;";
      -->
      </script>';
    }
  }
  @mysql_close();

  if ($sqlaccess == '') {
    err('由于基础管理员信息(如名称或密码)有变，但数据库连接不成功！拒绝此次修改。请先<a href="?get=sql">连接数据库</a>');
  }
}
/* 写 */
write_file('inc/set/set.php', $text);

/*
if (function_exists('apache_get_version') && apache_get_version() != false) {
  if (!file_exists('.htaccess')) {
    write_file('.htaccess', '<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /

RewriteRule ^index\.html index.php [L]
RewriteRule ^index\.([a-z]+)\.([0-9\-\_]*)\.([0-9]*)\.([0-9]*)\.html(&.*)? index.php?mode=$1&area_id=$2&list_mode=$3&p=$4$5 [L]
RewriteRule  ^list\.([a-z]+)\.([0-9\-\_]*)\.([0-9]*)\.([0-9]*)\.html(&.*)?  list.php?mode=$1&area_id=$2&list_mode=$3&p=$4$5 [L]
RewriteRule ^article\.([a-z]+)\.([0-9]+)\.([0-9]*)\.html(&.*)? article.php?mode=$1&id=$2&p=$3$4 [L]

</IfModule>

<IfModule mod_deflate.c>
#压缩网页
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Make sure proxies don\'t deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

<IfModule mod_expires.c>
ExpiresActive on
#缓存首页及物件新方法
<FilesMatch "obj\.php\?title=.*|\.(gif|jpg|jpeg|png|ico|swf|js|css)$">
ExpiresDefault "access plus 365 days"
Header set Cache-Control "max-age=31536000"
#Header unset Pragma
#Header unset ETag
#FileETag None
</FilesMatch>
</IfModule>');
  }
} else {
  @unlink('.htaccess');

}
*/







alert('执行成功！'.$sqlaccess, 'webmaster_central.php?get=set');




?>