PageRenderTime 43ms CodeModel.GetById 20ms app.highlight 7ms RepoModel.GetById 14ms app.codeStats 0ms

/source/plugin/security/upgrade.php

https://github.com/jinbo51/DiscuzX
PHP | 119 lines | 99 code | 14 blank | 6 comment | 21 complexity | baab3c6401ffb3e760447c11e7af20b1 MD5 | raw file
  1<?php
  2
  3/**
  4 *      [Discuz!] (C)2001-2099 Comsenz Inc.
  5 *      This is NOT a freeware, use is subject to license terms
  6 *
  7 *      $Id: install.php 27070 2012-01-04 05:55:20Z songlixin $
  8 */
  9
 10if(!defined('IN_DISCUZ')) {
 11	exit('Access Denied');
 12}
 13
 14$field = C::t('#security#security_failedlog')->fetch_all_field();
 15$table = DB::table('security_failedlog');
 16$sql = '';
 17if (!$field['scheduletime']) {
 18	$sql .= "ALTER TABLE $table ADD `scheduletime` INT(10) NOT NULL DEFAULT '0';\n";
 19}
 20
 21if (!$field['lastfailtime']) {
 22	$sql .= "ALTER TABLE $table ADD `lastfailtime` INT(10) NOT NULL DEFAULT '0';\n";
 23}
 24
 25if (!$field['posttime']) {
 26	$sql .= "ALTER TABLE $table ADD `posttime` INT(10) unsigned NOT NULL DEFAULT '0';\n";
 27}
 28
 29if (!$field['delreason']) {
 30	$sql .= "ALTER TABLE $table ADD `delreason` char(255) NOT NULL;\n";
 31}
 32
 33if (!$field['extra1']) {
 34	$sql .= "ALTER TABLE $table ADD `extra1` INT(10) unsigned NOT NULL DEFAULT '0';\n";
 35}
 36
 37if (!$field['extra2']) {
 38	$sql .= "ALTER TABLE $table ADD `extra2` char(255) NOT NULL;\n";
 39}
 40if ($sql) {
 41	runquery($sql);
 42}
 43
 44$field = C::t('#security#security_evilpost')->fetch_all_field();
 45$table = DB::table('security_evilpost');
 46$sql = '';
 47if (!$field['censorword']) {
 48	$sql .= "ALTER TABLE $table ADD `censorword` char(50) NOT NULL;\n";
 49}
 50
 51if ($sql) {
 52	runquery($sql);
 53}
 54
 55$table = DB::table('common_plugin');
 56include DISCUZ_ROOT . 'source/language/lang_admincp_cloud.php';
 57$format = "UPDATE $table SET name = '%s' WHERE identifier = 'security'";
 58$name = $extend_lang['menu_cloud_security'];
 59$sql = sprintf($format, $name);
 60
 61runquery($sql);
 62$cronId_security_daily = $cronId_security_lastpost = 0;
 63if(file_exists(DISCUZ_ROOT . './source/include/cron/cron_security_cleanup_lastpost.php') || file_exists(DISCUZ_ROOT . './source/include/cron/cron_security_daily.php')) {
 64	$count = C::t('common_cron')->count();
 65	$oldData = C::t('common_cron')->range(0, $count);
 66	foreach ($oldData as $value) {
 67		if ($value['filename'] == 'cron_security_daily.php') {
 68			$cronId_security_daily = $value['cronid'];
 69		}elseif ($value['filename'] == 'cron_security_cleanup_lastpost.php') {
 70			$cronId_security_lastpost = $value['cronid'];
 71		}
 72	}
 73}
 74if(file_exists(DISCUZ_ROOT . './source/include/cron/cron_security_cleanup_lastpost.php') && empty($cronId_security_lastpost)) {
 75	$data = array(
 76		'available' => 0,
 77		'type' => 'user',
 78		'name' => $extend_lang['security_cron_lastpost'],
 79		'filename' => 'cron_security_cleanup_lastpost.php',
 80		'weekday' => -1,
 81		'day' => -1,
 82		'hour' => -1,
 83		'minute' => 0,
 84	);
 85	C::t('common_cron')->insert($data, true, false, false);
 86}
 87if (file_exists(DISCUZ_ROOT . './source/include/cron/cron_security_daily.php')) {
 88	if (empty($cronId_security_daily)) {
 89		$data = array(
 90			'available' => 1,
 91			'type' => 'user',
 92			'name' => $extend_lang['security_cron_daily'],
 93			'filename' => 'cron_security_daily.php',
 94			'weekday' => -1,
 95			'day' => -1,
 96			'hour' => 2,
 97			'minute' => 0,
 98		);
 99		$cronId_security_daily = C::t('common_cron')->insert($data, true, false, false);
100	} else {
101		C::t('common_cron')->update($cronId_security_daily, array(
102			'name' => $extend_lang['security_cron_daily'],
103			'available' => 1,
104			'weekday' => -1,
105			'day' => -1,
106			'hour' => 2,
107			'minute' => 0,
108		));
109	}
110	updatecache('setting');
111	discuz_cron::run($cronId_security_daily);
112}
113
114if(!C::t('common_setting')->skey_exists('security_safelogin')) {
115	C::t('common_setting')->update('security_safelogin', 1);
116	updatecache('setting');
117}
118
119$finish = true;