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