1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20:
21:
22: 23: 24:
25: function protector_precheck()
26: {
27:
28: if (defined('_INSTALL_CHARSET') && !is_writable(\XoopsBaseConfig::get('root-path') . '/mainfile.php')) {
29: die('To use installer, remove protector\'s lines from mainfile.php first.');
30: }
31:
32:
33: require_once dirname(__DIR__) . '/class/protector.php';
34:
35:
36: $protector = Protector::getInstance();
37: $conf = $protector->getConf();
38:
39:
40: if (@$conf['bwlimit_count'] >= 10) {
41: $bwexpire = $protector->get_bwlimit();
42: if ($bwexpire > time()) {
43: header('HTTP/1.0 503 Service unavailable');
44: $protector->call_filter('precommon_bwlimit', 'This site is very crowed now. try later.');
45: }
46: }
47:
48:
49: $bad_ips = $protector->get_bad_ips(true);
50: $bad_ip_match = $protector->ip_match($bad_ips);
51: if ($bad_ip_match) {
52: $protector->call_filter('precommon_badip', 'You are registered as BAD_IP by Protector.');
53: }
54:
55:
56: if (!empty($conf['global_disabled'])) {
57: return true;
58: }
59:
60:
61: $reliable_ips = @unserialize(@$conf['reliable_ips']);
62: if (!is_array($reliable_ips)) {
63:
64: $reliable_ips = @unserialize(stripslashes(@$conf['reliable_ips']));
65: if (!is_array($reliable_ips)) {
66: $reliable_ips = array();
67: }
68: }
69: $is_reliable = false;
70: foreach ($reliable_ips as $reliable_ip) {
71: if (!empty($reliable_ip) && preg_match('/' . $reliable_ip . '/', $_SERVER['REMOTE_ADDR'])) {
72: $is_reliable = true;
73: }
74: }
75:
76:
77: if (!empty($conf['enable_bigumbrella'])) {
78: @define('PROTECTOR_ENABLED_ANTI_XSS', 1);
79: $protector->bigumbrella_init();
80: }
81:
82:
83: if (!empty($conf['id_forceintval'])) {
84: $protector->intval_allrequestsendid();
85: }
86:
87:
88: if (!$is_reliable && !empty($conf['file_dotdot'])) {
89: $protector->eliminate_dotdot();
90: }
91:
92:
93: if (!$is_reliable && !empty($_FILES) && !empty($conf['die_badext']) && !defined('PROTECTOR_SKIP_FILESCHECKER') && !$protector->check_uploaded_files()) {
94: $protector->output_log($protector->last_error_type);
95: $protector->purge();
96: }
97:
98:
99: if (!$protector->check_contami_systemglobals()) {
100: if (@$conf['contami_action'] & 4) {
101: if (@$conf['contami_action'] & 8) {
102: $protector->_should_be_banned = true;
103: } else {
104: $protector->_should_be_banned_time0 = true;
105: }
106: $_GET = $_POST = array();
107: }
108:
109: $protector->output_log($protector->last_error_type);
110: if (@$conf['contami_action'] & 2) {
111: $protector->purge();
112: }
113: }
114:
115:
116:
117:
118:
119:
120: if (!empty($conf['disable_features'])) {
121: $protector->disable_features();
122: }
123: return true;
124: }
125: