Conditions | 26 |
Paths | 12103 |
Total Lines | 99 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
25 | function protector_precheck() |
||
26 | { |
||
27 | // check the access is from install/index.php |
||
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 | // Protector class |
||
33 | require_once dirname(__DIR__) . '/class/protector.php'; |
||
34 | |||
35 | // Protector object |
||
36 | $protector = Protector::getInstance(); |
||
37 | $conf = $protector->getConf(); |
||
38 | |||
39 | // bandwidth limitation |
||
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 | // bad_ips |
||
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 | // global enabled or disabled |
||
56 | if (!empty($conf['global_disabled'])) { |
||
57 | return true; |
||
58 | } |
||
59 | |||
60 | // reliable ips |
||
61 | $reliable_ips = @unserialize(@$conf['reliable_ips']); |
||
62 | if (!is_array($reliable_ips)) { |
||
63 | // for the environment of (buggy core version && magic_quotes_gpc) |
||
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 | // "Big Umbrella" subset version |
||
77 | if (!empty($conf['enable_bigumbrella'])) { |
||
78 | @define('PROTECTOR_ENABLED_ANTI_XSS', 1); |
||
79 | $protector->bigumbrella_init(); |
||
80 | } |
||
81 | |||
82 | // force intval variables whose name is *id |
||
83 | if (!empty($conf['id_forceintval'])) { |
||
84 | $protector->intval_allrequestsendid(); |
||
85 | } |
||
86 | |||
87 | // eliminate '..' from requests looks like file specifications |
||
88 | if (!$is_reliable && !empty($conf['file_dotdot'])) { |
||
89 | $protector->eliminate_dotdot(); |
||
90 | } |
||
91 | |||
92 | // Check uploaded files |
||
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 | // Variables contamination |
||
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 | // prepare for DoS |
||
116 | //if( ! $protector->check_dos_attack_prepare() ) { |
||
117 | // $protector->output_log( $protector->last_error_type , 0 , true ) ; |
||
118 | //} |
||
119 | |||
120 | if (!empty($conf['disable_features'])) { |
||
121 | $protector->disable_features(); |
||
122 | } |
||
123 | return true; |
||
124 | } |
||
125 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.