PluginProbe ʕ •ᴥ•ʔ
Anti-Malware Security and Brute-Force Firewall / 4.19.68
Anti-Malware Security and Brute-Force Firewall v4.19.68
4.23.90 trunk 1.2.03.23 1.3.02.15 3.07.06 4.14.47 4.15.16 4.16.17 4.17.28 4.17.29 4.17.44 4.17.57 4.17.58 4.17.68 4.17.69 4.18.52 4.18.62 4.18.63 4.18.69 4.18.71 4.18.74 4.18.76 4.19.44 4.19.50 4.19.68 4.19.69 4.20.59 4.20.72 4.20.92 4.20.93 4.20.94 4.20.95 4.20.96 4.21.74 4.21.83 4.21.84 4.21.85 4.21.86 4.21.87 4.21.88 4.21.89 4.21.90 4.21.91 4.21.92 4.21.93 4.21.94 4.21.95 4.21.96 4.23.56 4.23.57 4.23.67 4.23.68 4.23.69 4.23.71 4.23.73 4.23.77 4.23.81 4.23.83 4.23.85 4.23.87 4.23.88 4.23.89
gotmls / images / index.php
gotmls / images Last commit date
.htaccess 11 years ago ELI-16x16.gif 14 years ago GOTMLS-16x16.gif 12 years ago blocked.gif 14 years ago btn_donateCC_WIDE.gif 13 years ago checked.gif 14 years ago index.php 6 years ago question.gif 13 years ago threat.gif 13 years ago wait.gif 14 years ago
index.php
1786 lines
1 <?php
2 /**
3 * GOTMLS Plugin Global Variables and Functions
4 * @package GOTMLS
5 */
6
7 if (!function_exists("GOTMLS_define")) {
8 function GOTMLS_define($DEF, $val) {
9 if (!defined($DEF))
10 define($DEF, $val);
11 }}
12
13 $file = basename(__FILE__);
14 GOTMLS_define("GOTMLS_local_images_path", substr(__FILE__, 0, strlen(__FILE__) - strlen($file)));
15 GOTMLS_define("GOTMLS_plugin_path", substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen(basename(dirname(__FILE__)))));
16 if (is_file(GOTMLS_plugin_path.$file) && ($contents = @file_get_contents(GOTMLS_plugin_path.$file)) && preg_match('/\nversion:\s*([0-9\.]+)/i', $contents, $match))
17 GOTMLS_define("GOTMLS_Version", $match[1]);
18 else
19 GOTMLS_define("GOTMLS_Version", "Unknown");
20 GOTMLS_define("GOTMLS_require_version", "3.3");
21 if (isset($wp_version) && ($wp_version))
22 GOTMLS_define("GOTMLS_wp_version", $wp_version);
23 if (!function_exists("__")) {
24 function __($text, $domain = "gotmls") {
25 return $text;
26 }}
27
28 function GOTMLS_htmlentities($TXT, $flags = ENT_COMPAT, $encoding = "UTF-8") {
29 $prelen = strlen($TXT);
30 if ($prelen == 0)
31 return "";
32 $encoded = htmlentities($TXT, $flags, $encoding);
33 if (strlen($encoded) == 0) {
34 $encoding = "ISO-8859-1";
35 $encoded = htmlentities($TXT, $flags, $encoding);
36 }
37 if (strlen($encoded) == 0)
38 $encoded = __("Failed to encode HTML entities!",'gotmls');
39 $GLOBALS["GOTMLS"]["tmp"]["encoding"] = $encoding;
40 return $encoded;
41 }
42
43 function GOTMLS_htmlspecialchars($TXT, $flags = ENT_COMPAT, $encoding = "UTF-8") {
44 $prelen = strlen($TXT);
45 if ($prelen == 0)
46 return "";
47 $encoded = htmlspecialchars($TXT, $flags, $encoding);
48 if (strlen($encoded) == 0) {
49 $encoding = "ISO-8859-1";
50 $encoded = htmlspecialchars($TXT, $flags, $encoding);
51 }
52 if (strlen($encoded) == 0)
53 $encoded = __("Failed to encode HTML characters!",'gotmls');
54 $GLOBALS["GOTMLS"]["tmp"]["encoding"] = $encoding;
55 return $encoded;
56 }
57
58 $bad = array("eval", "preg_replace", "auth_pass");
59 $GLOBALS["GOTMLS"] = array(
60 "MT" => microtime(true),
61 "tmp"=>array("HeadersError"=>"", "onLoad"=>"", "file_contents"=>"", "new_contents"=>"", "threats_found"=>array(),
62 "skip_dirs" => array(".", ".."), "scanfiles" => array(), "nonce"=>array(),
63 "mt" => ((isset($_REQUEST["mt"])&&is_numeric($_REQUEST["mt"]))?$_REQUEST["mt"]:microtime(true)),
64 "threat_files" => array("htaccess"=>".htaccess","timthumb"=>"thumb.php"),
65 "threat_levels" => array(__("Database Injections",'gotmls')=>"db_scan",__("htaccess Threats",'gotmls')=>"htaccess",__("TimThumb Exploits",'gotmls')=>"timthumb",__("Known Threats",'gotmls')=>"known",__("Core File Changes",'gotmls')=>"wp_core",__("Potential Threats",'gotmls')=>"potential"),
66 "apache" => array(),
67 "skip_ext"=>array("png", "jpg", "jpeg", "gif", "bmp", "tif", "tiff", "psd", "svg", "doc", "docx", "ttf", "fla", "flv", "mov", "mp3", "pdf", "css", "pot", "po", "mo", "so", "exe", "zip", "7z", "gz", "rar"),
68 "execution_time" => 60,
69 "default" => array("msg_position" => array("80px", "40px", "400px", "600px")),
70 "Definition" => array("Default" => "CCIGG"),
71 "definitions_array" => array(
72 "potential"=>array(
73 $bad[0]=>array("CCIGG", "/[^a-z_\\/'\"]".$bad[0]."\\(.+\\)+\\s*;/i"),
74 $bad[1]." /e"=>array("CCIGG", "/".$bad[1]."[\\s*\\(]+(['\"])([\\!\\/\\#\\|\\@\\%\\^\\*\\~]).+?\\2[imsx]*e[imsx]*\\1\\s*,[^,]+,[^\\)]+[\\);\\s]+/i"),
75 $bad[2]=>array("CCIGG", "/\\\$".$bad[2]."\\s*=.+;/i"),
76 "function add_action wp_enqueue_script json2"=>array("CCIGG", "/json2\\.min\\.js/i"),
77 "Tagged Code"=>array("CCIGG", "/\\#(\\w+)\\#.+?\\#\\/\\1\\#/is"),
78 "protected by copyright"=>array("CCIGG", "/\\/\\* This file is protected by copyright law and provided under license. Reverse engineering of this file is strictly prohibited. \\*\\//i")),
79 )
80 )
81 );
82 if (isset($_SERVER["HTTP_HOST"]))
83 $SERVER_HTTP = 'HOST://'.$_SERVER["HTTP_HOST"];
84 elseif (isset($_SERVER["SERVER_NAME"]))
85 $SERVER_HTTP = 'NAME://'.$_SERVER["SERVER_NAME"];
86 elseif (isset($_SERVER["SERVER_ADDR"]))
87 $SERVER_HTTP = 'ADDR://'.$_SERVER["SERVER_ADDR"];
88 else
89 $SERVER_HTTP = "NULL://not.anything.com";
90 if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"])
91 $SERVER_HTTP .= ":".$_SERVER["SERVER_PORT"];
92 $SERVER_parts = explode(":", $SERVER_HTTP.":");
93 if ((isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] == 1)) || (count($SERVER_parts) > 2 && $SERVER_parts[2] == "443"))
94 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "https:";
95 else
96 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "http:";
97 GOTMLS_define("GOTMLS_script_URI", preg_replace('/\&(last_)?mt=[0-9\.]+/i', '', str_replace('&amp;', '&', GOTMLS_htmlspecialchars($_SERVER["REQUEST_URI"], ENT_QUOTES))).'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"]);
98 GOTMLS_define("GOTMLS_plugin_home", "https://gotmls.net/");
99
100 if (!function_exists("GOTMLS_encode")) {
101 function GOTMLS_encode($unencoded_string) {
102 if (function_exists("base64_encode"))
103 $encoded_string = base64_encode($unencoded_string);
104 elseif (function_exists("mb_convert_encoding"))
105 $encoded_string = mb_convert_encoding($unencoded_string, "BASE64", "UTF-8");
106 else
107 $encoded_string = "Cannot encode: $unencoded_string function_exists: ";
108 $encoded_array = explode("=", $encoded_string."=");
109 return strtr($encoded_array[0], "+/0", "-_=").(count($encoded_array)-1);
110 }}
111
112 if (!function_exists("GOTMLS_decode")) {
113 function GOTMLS_decode($encoded_string) {
114 $tail = 0;
115 if (strlen($encoded_string) > 1 && is_numeric(substr($encoded_string, -1)) && substr($encoded_string, -1) > 0)
116 $tail = substr($encoded_string, -1) - 1;
117 else
118 $encoded_string .= "$tail";
119 $encoded_string = strtr(substr($encoded_string, 0, -1), "-_=", "+/0").str_repeat("=", $tail);
120 if (function_exists("base64_decode"))
121 return base64_decode($encoded_string);
122 elseif (function_exists("mb_convert_encoding"))
123 return mb_convert_encoding($encoded_string, "UTF-8", "BASE64");
124 else
125 return "Cannot decode: $encoded_string";
126 }}
127
128 GOTMLS_define("GOTMLS_Failed_to_list_LANGUAGE", __("Failed to list files in directory!",'gotmls'));
129 GOTMLS_define("GOTMLS_Run_Quick_Scan_LANGUAGE", __("Quick Scan",'gotmls'));
130 GOTMLS_define("GOTMLS_View_Quarantine_LANGUAGE", __("View Quarantine",'gotmls'));
131 GOTMLS_define("GOTMLS_View_Scan_Log_LANGUAGE", __("View Scan History",'gotmls'));
132 GOTMLS_define("GOTMLS_require_version_LANGUAGE", sprintf(__("This Plugin requires WordPress version %s or higher",'gotmls'), GOTMLS_require_version));
133 GOTMLS_define("GOTMLS_Scan_Settings_LANGUAGE", __("Scan Settings",'gotmls'));
134 GOTMLS_define("GOTMLS_Loading_LANGUAGE", __("Loading, Please Wait ...",'gotmls'));
135 GOTMLS_define("GOTMLS_Automatically_Fix_LANGUAGE", __("Automatically Fix SELECTED Files Now",'gotmls'));
136
137 if (function_exists("plugins_url"))
138 GOTMLS_define("GOTMLS_images_path", plugins_url('/', __FILE__));
139 elseif (function_exists("plugin_dir_url"))
140 GOTMLS_define("GOTMLS_images_path", plugin_dir_url(__FILE__));
141 elseif (isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"]) && strlen($_SERVER["DOCUMENT_ROOT"]) < __FILE__ && substr(__FILE__, 0, strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
142 GOTMLS_define("GOTMLS_images_path", substr(dirname(__FILE__), strlen($_SERVER["DOCUMENT_ROOT"])));
143 elseif (isset($_SERVER["SCRIPT_FILENAME"]) && isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"]) && strlen($_SERVER["DOCUMENT_ROOT"]) < strlen($_SERVER["SCRIPT_FILENAME"]) && substr($_SERVER["SCRIPT_FILENAME"], 0, strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
144 GOTMLS_define("GOTMLS_images_path", substr(dirname($_SERVER["SCRIPT_FILENAME"]), strlen($_SERVER["DOCUMENT_ROOT"])));
145 else
146 GOTMLS_define("GOTMLS_images_path", "/wp-content/plugins/update/images/");
147
148 function GOTMLS_user_can() {
149 if (is_multisite())
150 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] = "manage_network";
151 elseif (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"]) || $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] == "manage_network")
152 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] = "activate_plugins";
153 if (current_user_can($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"]))
154 return true;
155 else
156 return false;
157 }
158
159 if (!defined("ABSPATH")) {
160 define("ABSPATH", dirname(dirname(__FILE__)).'/safe-load/');
161 $root_path = dirname(ABSPATH);
162 while (strlen($root_path) > 1 && !is_file($root_path."/wp-config.php"))
163 $root_path = dirname($root_path);
164 if (is_file($root_path."/wp-config.php"))
165 include_once($root_path."/wp-config.php");
166 else
167 die("No wp-config!");
168 }
169
170 function GOTMLS_update_option($index, $value = array()) {
171 return update_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($value)));
172 }
173
174 function GOTMLS_get_option($index, $value = array()) {
175 if (is_array($tmp = get_option('GOTMLS_'.$index.'_array', array())) && count($tmp)) {
176 GOTMLS_update_option($index, $tmp);
177 delete_option('GOTMLS_'.$index.'_array');
178 } else
179 $tmp = $value;
180 return unserialize(GOTMLS_decode(get_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($tmp)))));
181 }
182
183 $GOTMLS_chmod_file = (0644);
184 $GOTMLS_chmod_dir = (0755);
185 $GLOBALS["GOTMLS"]["tmp"]["nonce"] = GOTMLS_get_option('nonce', array());
186 $GLOBALS["GOTMLS"]["tmp"]["settings_array"] = get_option('GOTMLS_settings_array', array());
187 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"] = GOTMLS_get_option('definitions', $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]);
188 GOTMLS_define("GOTMLS_siteurl", get_option("siteurl", $GLOBALS["GOTMLS"]["tmp"]["protocol"].$SERVER_parts[1].((count($SERVER_parts) > 2 && ($SERVER_parts[2] == '80' || $SERVER_parts[2] == '443'))?"":":".$SERVER_parts[2])."/"));
189 $GLOBALS["GOTMLS"]["log"] = get_option('GOTMLS_scan_log/'.(isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:"0.0.0.0").'/'.$GLOBALS["GOTMLS"]["tmp"]["mt"], array());
190 if (!(isset($GLOBALS["GOTMLS"]["log"]["settings"]) && is_array($GLOBALS["GOTMLS"]["log"]["settings"])))
191 $GLOBALS["GOTMLS"]["log"]["settings"] = $GLOBALS["GOTMLS"]["tmp"]["settings_array"];
192 GOTMLS_define("GOTMLS_installation_key", md5(GOTMLS_siteurl));
193 GOTMLS_define("GOTMLS_update_home", "//updates.gotmls.net/".GOTMLS_installation_key."/");
194
195 if (!function_exists("GOTMLS_Invalid_Nonce")) {
196 function GOTMLS_Invalid_Nonce($pre = "//Error: ") {
197 return $pre.__("Invalid or expired Nonce Token!",'gotmls').(isset($_REQUEST["GOTMLS_mt"])?(" (".GOTMLS_htmlspecialchars($_REQUEST["GOTMLS_mt"]).((strlen($_REQUEST["GOTMLS_mt"]) == 32)?(isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]])?$GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]:" !found)"):" !len[".strlen($_REQUEST["GOTMLS_mt"])."])")):" (GOTMLS_mt !set)").__("Refresh and try again?",'gotmls');
198 }}
199
200 if (!function_exists("GOTMLS_set_nonce")) {
201 function GOTMLS_set_nonce($context = "NULL") {
202 $hour = round(($GLOBALS["GOTMLS"]["tmp"]["mt"]/60)/60);
203 $transient_name = md5(substr(number_format(microtime(true), 9, '-', '/'), 6).GOTMLS_installation_key.GOTMLS_plugin_path);
204 if (isset($GLOBALS["GOTMLS"]["tmp"]["nonce"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["nonce"])) {
205 foreach ($GLOBALS["GOTMLS"]["tmp"]["nonce"] as $nonce_key => $nonce_value) {
206 if (($nonce_value > $hour) || (($nonce_value + 24) < $hour))
207 unset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$nonce_key]);
208 elseif ($nonce_value == $hour)
209 $transient_name = $nonce_key;
210 }
211 }
212 if (!isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name])) {
213 $GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name] = $hour;
214 if (!GOTMLS_update_option('nonce', $GLOBALS["GOTMLS"]["tmp"]["nonce"]))
215 return ("$context=DB-err:".preg_replace('/[\r\n]+/', " ", GOTMLS_htmlspecialchars(print_r($GLOBALS["GOTMLS"]["tmp"]["nonce"],1).$wpdb->last_error)));
216 }
217 return 'GOTMLS_mt='.$transient_name;
218 }}
219
220 if (!function_exists("GOTMLS_get_nonce")) {
221 function GOTMLS_get_nonce() {
222 if (isset($_REQUEST["GOTMLS_mt"])) {
223 if (is_array($_REQUEST["GOTMLS_mt"])) {
224 foreach ($_REQUEST["GOTMLS_mt"] as $_REQUEST_GOTMLS_mt)
225 if (strlen($_REQUEST_GOTMLS_mt) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST_GOTMLS_mt]))
226 return $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST_GOTMLS_mt];
227 return 0;
228 } elseif (strlen($_REQUEST["GOTMLS_mt"]) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]))
229 return $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]];
230 else
231 return "";
232 } else
233 return false;
234 }}
235
236 function GOTMLS_fileperms($file) {
237 if ($prm = @fileperms($file)) {
238 if (($prm & 0xC000) == 0xC000)
239 $ret = "s";
240 elseif (($prm & 0xA000) == 0xA000)
241 $ret = "l";
242 elseif (($prm & 0x8000) == 0x8000)
243 $ret = "-";
244 elseif (($prm & 0x6000) == 0x6000)
245 $ret = "b";
246 elseif (($prm & 0x4000) == 0x4000)
247 $ret = "d";
248 elseif (($prm & 0x2000) == 0x2000)
249 $ret = "c";
250 elseif (($prm & 0x1000) == 0x1000)
251 $ret = "p";
252 else
253 $ret = "u";
254 $ret .= (($prm & 0x0100)?"r":"-").(($prm & 0x0080)?"w":"-");
255 $ret .= (($prm & 0x0040)?(($prm & 0x0800)?"s":"x" ):(($prm & 0x0800)?"S":"-"));
256 $ret .= (($prm & 0x0020)?"r":"-").(($prm & 0x0010)?"w":"-");
257 $ret .= (($prm & 0x0008)?(($prm & 0x0400)?"s":"x" ):(($prm & 0x0400)?"S":"-"));
258 $ret .= (($prm & 0x0004)?"r":"-").(($prm & 0x0002)?"w":"-");
259 $ret .= (($prm & 0x0001)?(($prm & 0x0200)?"t":"x" ):(($prm & 0x0200)?"T":"-"));
260 return $ret;
261 } else
262 return "stat failed!";
263 }
264
265 function GOTMLS_file_details($file) {
266 return '<div id="file_details_'.md5($file).'" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"><b>File Details: '.GOTMLS_htmlspecialchars(basename($file)).'</b><br />in: '.dirname(realpath($file)).'<br />size: '.filesize(realpath($file)).' ( '.ceil(strlen(GOTMLS_htmlspecialchars($GLOBALS["GOTMLS"]["tmp"]["file_contents"]))/1024).' KB )<br />encoding: '.(isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])?$GLOBALS["GOTMLS"]["tmp"]["encoding"]:(function_exists("mb_detect_encoding")?mb_detect_encoding($GLOBALS["GOTMLS"]["tmp"]["file_contents"]):"Unknown")).'<br />permissions: '.GOTMLS_fileperms(realpath($file)).'<br />Owner/Group: '.fileowner(realpath($file)).'/'.filegroup(realpath($file)).' (you are: '.getmyuid().'/'.getmygid().')<br />modified:'.date(" Y-m-d H:i:s ", filemtime(realpath($file))).'<br />changed:'.date(" Y-m-d H:i:s ", filectime(realpath($file))).'</div>';
267 }
268
269 function GOTMLS_admin_url($url = '') {
270 if (function_exists("admin_url"))
271 return admin_url($url);
272 else {
273 return "../../../../wp-admin/$url";
274 }
275 }
276
277 function GOTMLS_close_button($box_id, $margin = '6px') {
278 return '<a href="javascript:void(0);" style="float: right; color: #F00; overflow: hidden; width: 20px; height: 20px; text-decoration: none; margin: '.$margin.'" onclick="showhide(\''.$box_id.'\');"><span class="dashicons dashicons-dismiss"></span>X</a>';
279 }
280
281 function GOTMLS_get_styles($pre_style = '<style>') {
282 $head_nonce = GOTMLS_set_nonce(__FUNCTION__."272");
283 return $pre_style.'
284 span.GOTMLS_date {float: right; width: 130px; white-space: nowrap;}
285 .GOTMLS_page {float: left; border-radius: 10px; padding: 0 5px;}
286 .GOTMLS_quarantine_item {margin: 4px 12px;}
287 .rounded-corners {margin: 10px; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #000;}
288 .shadowed-box {box-shadow: -3px 3px 3px #666; -moz-box-shadow: -3px 3px 3px #666; -webkit-box-shadow: -3px 3px 3px #666;}
289 .sidebar-box {background-color: #CCC;}
290 iframe {border: 0;}
291 .GOTMLS-scanlog li a {display: none;}
292 .GOTMLS-scanlog li:hover a {display: block;}
293 .GOTMLS-sidebar-links {list-style: none;}
294 .GOTMLS-sidebar-links li img {margin: 3px; height: 16px; vertical-align: middle;}
295 .GOTMLS-sidebar-links li {margin-bottom: 0 !important;}
296 .popup-box {background-color: #FFC; display: none; position: absolute; left: 0px; z-index: 10;}
297 .shadowed-text {text-shadow: #00F -1px 1px 1px;}
298 .sub-option {float: left; margin: 3px 5px;}
299 .inside {margin: 10px; position: relative;}
300 .GOTMLS_li, .GOTMLS_plugin li {list-style: none;}
301 .GOTMLS_plugin {margin: 5px; background: #cfc; border: 1px solid #0C0; padding: 0 5px; border-radius: 3px;}
302 .GOTMLS_plugin.known, .GOTMLS_plugin.db_scan, .GOTMLS_plugin.htaccess, .GOTMLS_plugin.timthumb, .GOTMLS_plugin.errors {background: #f99; border: 1px solid #f00;}
303 .GOTMLS_plugin.potential, .GOTMLS_plugin.wp_core, .GOTMLS_plugin.skipdirs, .GOTMLS_plugin.skipped {background: #ffc; border: 1px solid #fc6;}
304 .GOTMLS ul li {margin-left: 12px;}
305 .GOTMLS h2 {margin: 0 0 10px;}
306 .postbox {margin-right: 10px; line-height: 1.4; font-size: 13px;}
307 #pastDonations li {list-style: none;}
308 #quarantine_buttons {position: absolute; right: 0px; top: -54px; margin: 0px; padding: 0px;}
309 #quarantine_buttons input.button-primary {margin-right: 20px;}
310 #reclean_buttons {
311 color: #a00;
312 min-height: 32px;
313 border-top: solid 2px black;
314 padding-top: 10px;
315 }
316 #reclean_buttons input.button-primary {float: right;}
317 #delete_button {
318 background-color: #C33;
319 color: #FFF;
320 background-image: linear-gradient(to bottom, #C22, #933);
321 border-color: #933 #933 #900;
322 box-shadow: 0 1px 0 rgba(230, 120, 120, 0.5) inset;
323 text-decoration: none; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
324 margin-top: 10px;
325 }
326 #main-page-title {
327 background: url("https://secure.gravatar.com/avatar/5feb789dd3a292d563fea3b885f786d6?s=64") no-repeat scroll 0 0 transparent;
328 height: 64px;
329 line-height: 58px;
330 margin: 10px 0 0 0;
331 max-width: 600px;
332 padding: 0 110px 0 84px;
333 }
334 #main-page-title h1 {
335 background: url("https://secure.gravatar.com/avatar/8151cac22b3fc543d099241fd573d176?s=64") no-repeat scroll top right transparent;
336 height: 64px;
337 line-height: 32px;
338 margin: 0;
339 padding: 0 84px 0 0;
340 display: table-cell;
341 text-align: center;
342 vertical-align: middle;
343 }
344 </style>
345 <div id="div_file" class="shadowed-box rounded-corners sidebar-box" style="padding: 0; display: none; position: fixed; top: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][1].'; left: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][0].'; width: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][3].'; height: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][2].'; border: solid #c00; z-index: 112358;"><table style="width: 100%; height: 100%;" cellspacing="0" cellpadding="0"><tr><td style="border-bottom: 1px solid #EEE; height: 32px;" colspan="2">'.GOTMLS_close_button("div_file").'<h3 onmousedown="grabDiv();" onmouseup="releaseDiv();" id="windowTitle" style="cursor: move; border-bottom: 0px none; z-index: 2345677; position: absolute; left: 0px; top: 0px; margin: 0px; padding: 6px; width: 90%; height: 20px;">'.GOTMLS_Loading_LANGUAGE.'</h3></td></tr><tr><td colspan="2" style="height: 100%"><div style="width: 100%; height: 100%; position: relative; padding: 0; margin: 0;" class="inside"><br /><br /><center><img src="'.GOTMLS_images_path.'wait.gif" height=16 width=16 alt="..."> '.GOTMLS_Loading_LANGUAGE.'<br /><br /><input type="button" onclick="showhide(\'GOTMLS_iFrame\', true);" value="'.__("If this is taking too long, click here.",'gotmls').'" class="button-primary" /></center><iframe id="GOTMLS_iFrame" name="GOTMLS_iFrame" style="top: 0px; left: 0px; position: absolute; width: 100%; height: 100%; background-color: #CCC;"></iframe></td></tr><tr><td style="height: 20px;"><iframe id="GOTMLS_statusFrame" name="GOTMLS_statusFrame" style="width: 100%; height: 20px; background-color: #CCC;"></iframe></div></td><td style="height: 20px; width: 20px;"><h3 id="cornerGrab" onmousedown="grabCorner();" onmouseup="releaseCorner();" style="cursor: move; height: 24px; width: 24px; margin: 0; padding: 0; z-index: 2345678; overflow: hidden; position: absolute; right: 0px; bottom: 0px;"><span class="dashicons dashicons-editor-expand"></span>&#8690;</h3></td></tr></table></div>
346 <script type="text/javascript">
347 function showhide(id) {
348 divx = document.getElementById(id);
349 if (divx) {
350 if (divx.style.display == "none" || arguments[1]) {
351 divx.style.display = "block";
352 divx.parentNode.className = (divx.parentNode.className+"close").replace(/close/gi,"");
353 return true;
354 } else {
355 divx.style.display = "none";
356 return false;
357 }
358 }
359 }
360 function checkAllFiles(check) {
361 var checkboxes = new Array();
362 checkboxes = document["GOTMLS_Form_clean"].getElementsByTagName("input");
363 for (var i=0; i<checkboxes.length; i++)
364 if (checkboxes[i].type == "checkbox" && (checkboxes[i].id.substring(0, 6) == "check_" || checkboxes[i].id.substring(0, 24) == "GOTMLS_quarantine_check_"))
365 checkboxes[i].checked = check;
366 }
367 function setvalAllFiles(val) {
368 var checkboxes = document.getElementById("GOTMLS_fixing");
369 if (checkboxes)
370 checkboxes.value = val;
371 }
372 function getWindowWidth(min) {
373 if (typeof window.innerWidth != "undefined" && window.innerWidth > min)
374 min = window.innerWidth;
375 else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth > min)
376 min = document.documentElement.clientWidth;
377 else if (typeof document.getElementsByTagName("body")[0].clientWidth != "undefined" && document.getElementsByTagName("body")[0].clientWidth > min)
378 min = document.getElementsByTagName("body")[0].clientWidth;
379 return min;
380 }
381 function getWindowHeight(min) {
382 if (typeof window.innerHeight != "undefined" && window.innerHeight > min)
383 min = window.innerHeight;
384 else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientHeight != "undefined" && document.documentElement.clientHeight > min)
385 min = document.documentElement.clientHeight;
386 else if (typeof document.getElementsByTagName("body")[0].clientHeight != "undefined" && document.getElementsByTagName("body")[0].clientHeight > min)
387 min = document.getElementsByTagName("body")[0].clientHeight;
388 return min;
389 }
390 function loadIframe(title) {
391 showhide("GOTMLS_iFrame", true);
392 showhide("GOTMLS_iFrame");
393 document.getElementById("windowTitle").innerHTML = title;
394 if (curDiv) {
395 windowW = getWindowWidth(200);
396 windowH = getWindowHeight(200);
397 if (windowW > 200)
398 windowW -= 30;
399 if (windowH > 200)
400 windowH -= 20;
401 if (px2num(curDiv.style.width) > windowW) {
402 curDiv.style.width = windowW + "px";
403 curDiv.style.left = "0px";
404 } else if ((px2num(curDiv.style.left) + px2num(curDiv.style.width)) > windowW) {
405 curDiv.style.left = (windowW - px2num(curDiv.style.width)) + "px";
406 }
407 if (px2num(curDiv.style.height) > windowH) {
408 curDiv.style.height = windowH + "px";
409 curDiv.style.top = "0px";
410 } else if ((px2num(curDiv.style.top) + px2num(curDiv.style.height)) > windowH) {
411 curDiv.style.top = (windowH - px2num(curDiv.style.height)) + "px";
412 }
413 if (px2num(curDiv.style.left) < 0)
414 curDiv.style.left = "0px";
415 if (px2num(curDiv.style.top)< 0)
416 curDiv.style.top = "0px";
417 }
418 showhide("div_file", true);
419 if (IE)
420 curDiv.scrollIntoView(true);
421 }
422 function cancelserver(divid) {
423 document.getElementById(divid).innerHTML = "<div class=\'error\'>'. __("No response from server!",'gotmls').'</div>";
424 }
425 function checkupdateserver(server, divid) {
426 var updatescript = document.createElement("script");
427 updatescript.setAttribute("src", server);
428 divx = document.getElementById(divid);
429 if (divx) {
430 divx.appendChild(updatescript);
431 if (arguments[2])
432 return setTimeout("stopCheckingDefinitions = checkupdateserver(\'"+arguments[2]+"\',\'"+divid+"\')",15000);
433 else
434 return setTimeout("cancelserver(\'"+divid+"\')",'.($GLOBALS["GOTMLS"]["tmp"]['execution_time']+1).'000+3000);
435 }
436 }
437 var IE = document.all?true:false;
438 //if (!IE) document.addEventListener("mousemove", getMouseXY);
439 document.onmousemove = getMouseXY;
440 var offsetX = 0;
441 var offsetY = 0;
442 var offsetW = 0;
443 var offsetH = 0;
444 var curX = 0;
445 var curY = 0;
446 var curDiv;
447 function getMouseXY(e) {
448 if (IE) { // grab the mouse pos if browser is IE
449 curX = event.clientX + document.body.scrollLeft;
450 curY = event.clientY + document.body.scrollTop;
451 } else { // grab the mouse pos if browser is Not IE
452 curX = e.pageX - document.body.scrollLeft;
453 curY = e.pageY - document.body.scrollTop;
454 }
455 if (curX < 0) {curX = 0;}
456 if (curY < 0) {curY = 0;}
457 if (offsetX && curX > 10) {curDiv.style.left = (curX - offsetX)+"px";}
458 if (offsetY && (curY - offsetY) > 0) {curDiv.style.top = (curY - offsetY)+"px";}
459 if (offsetW && (curX - offsetW) > 360) {curDiv.style.width = (curX - offsetW)+"px";}
460 if (offsetH && (curY - offsetH) > 200) {curDiv.style.height = (curY - offsetH)+"px";}
461 return true;
462 }
463 function px2num(px) {
464 return parseInt(px.substring(0, px.length - 2), 10);
465 }
466 function setDiv(DivID) {
467 if (curDiv = document.getElementById(DivID)) {
468 if (IE)
469 curDiv.style.position = "absolute";
470 curDiv.style.left = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][0].'";
471 curDiv.style.top = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][1].'";
472 curDiv.style.height = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][2].'";
473 curDiv.style.width = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][3].'";
474 }
475 }
476 function grabDiv() {
477 corner = document.getElementById("windowTitle");
478 if (corner) {
479 corner.style.width="100%";
480 corner.style.height="100%";
481 }
482 offsetX=curX-px2num(curDiv.style.left);
483 offsetY=curY-px2num(curDiv.style.top);
484 }
485 function releaseDiv() {
486 corner = document.getElementById("windowTitle");
487 if (corner) {
488 corner.style.width="90%";
489 corner.style.height="20px";
490 }
491 document.getElementById("GOTMLS_statusFrame").src = "'.GOTMLS_admin_url('admin-ajax.php?action=GOTMLS_position&'.$head_nonce.'&GOTMLS_x=').'"+curDiv.style.left+"&GOTMLS_y="+curDiv.style.top;
492 offsetX=0;
493 offsetY=0;
494 }
495 function grabCorner() {
496 corner = document.getElementById("cornerGrab");
497 if (corner) {
498 corner.style.width="100%";
499 corner.style.height="100%";
500 }
501 offsetW=curX-px2num(curDiv.style.width);
502 offsetH=curY-px2num(curDiv.style.height);
503 }
504 function releaseCorner() {
505 corner = document.getElementById("cornerGrab");
506 if (corner) {
507 corner.style.width="20px";
508 corner.style.height="20px";
509 }
510 document.getElementById("GOTMLS_statusFrame").src = "'.GOTMLS_admin_url('admin-ajax.php?action=GOTMLS_position&'.$head_nonce.'&GOTMLS_w=').'"+curDiv.style.width+"&GOTMLS_h="+curDiv.style.height;
511 offsetW=0;
512 offsetH=0;
513 }
514 function check_for_donation(chk) {
515 if ((audl = document.getElementById("autoUpdateDownload")) && audl.src.replace(/^.+\?/,"")=="0")
516 if (chk.substr(0, 8) != "Changed " || chk.substr(8, 1) != "0")
517 chk += "\\n\\n'.__("Please make a donation for the use of this wonderful feature!",'gotmls').'";
518 alert(chk);
519 }
520 setDiv("div_file");
521 </script>';
522 }
523
524 function GOTMLS_get_header($optional_box = "") {
525 if (isset($_GET["check_site"]) && $_GET["check_site"])
526 $pre_style = '<div id="check_site" style="z-index: 1234567;"><img src="'.GOTMLS_images_path.'checked.gif" onload="showhide(\'inside_ddd6dbd641b9a5909fe4d44da2017cc7\');" height=16 width=16 alt="&#x2714;"> '.__("Tested your site. It appears we didn't break anything",'gotmls').' ;-)</div><script type="text/javascript">if (csw = window.parent.document.getElementById("check_site_warning")) csw.style.backgroundColor=\'#0C0\';</script><li>Please <a target="_blank" href="https://wordpress.org/support/plugin/gotmls/reviews/#wporg-footer">write a "Five-Star" Review</a> on WordPress.org if you like this plugin.</li><style>#footer, #GOTMLS-metabox-container, #GOTMLS-right-sidebar, #admin-page-container, #wpadminbar, #adminmenuback, #adminmenuwrap, #adminmenu, .error, .updated, .notice, .update-nag {display: none !important;} #wpbody-content {padding-bottom: 0;} #wpbody, html.wp-toolbar {padding-top: 0 !important;} #wpcontent, #footer {margin-left: 5px !important;}';
527 else
528 $pre_style = '<style>#GOTMLS-right-sidebar {float: right; margin-right: 0px;}';
529 return GOTMLS_get_styles($pre_style).'<div id="main-page-title"><h1 style="vertical-align: middle;">Anti-Malware from&nbsp;GOTMLS.NET</h1></div>';
530 }
531
532 function GOTMLS_get_quarantine($only = false) {
533 global $wpdb, $post;
534 if (is_numeric($only))
535 return get_post($only, ARRAY_A);
536 elseif ($only)
537 return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private'");
538 else
539 $args = array('posts_per_page' => (isset($_GET['posts_per_page'])&&is_numeric($_GET['posts_per_page'])&&$_GET['posts_per_page']>0?$_GET['posts_per_page']:200), 'orderby' => 'date', 'post_type' => 'GOTMLS_quarantine', "post_status" => "private");
540 if (isset($_POST["paged"]))
541 $args["paged"] = $_POST["paged"];
542 $my_query = new WP_Query($args);
543 $Q_Paged = '<form method="POST" name="GOTMLS_Form_page"><input type="hidden" id="GOTMLS_paged" name="paged" value="1"><div style="float: left;">Page:</div>';
544 $Q_Page = '
545 <form method="POST" action="'.admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."645")).(isset($_SERVER["QUERY_STRING"])&&strlen($_SERVER["QUERY_STRING"])?"&".$_SERVER["QUERY_STRING"]:"").'" target="GOTMLS_iFrame" name="GOTMLS_Form_clean"><input type="hidden" id="GOTMLS_fixing" name="GOTMLS_fixing" value="1"><input type="hidden" name="action" value="GOTMLS_fix">';
546 if ($my_query->have_posts()) {
547 $Q_Page .= '<p id="quarantine_buttons" style="display: none;"><input id="repair_button" type="submit" value="'.__("Restore selected files",'gotmls').'" class="button-primary" onclick="if (confirm(\''.__("Are you sure you want to overwrite the previously cleaned files with the selected files in the Quarantine?",'gotmls').'\')) { setvalAllFiles(1); loadIframe(\'File Restoration Results\'); } else return false;" /><input id="delete_button" type="submit" class="button-primary" value="'.__("Delete selected files",'gotmls').'" onclick="if (confirm(\''.__("Are you sure you want to permanently delete the selected files in the Quarantine?",'gotmls').'\')) { setvalAllFiles(2); loadIframe(\'File Deletion Results\'); } else return false;" /></p><p><b>'.__("The following items highlighted in yellow had been found to contain malicious code, they have been cleaned and the malicious contents have been removed. A record of the infection has been saved here in the Quarantine for your review and could help with any future investigations. The code is safe here and you do not need to do anything further with these files.",'gotmls').'</b></p>
548 <p id="reclean_buttons" style="display: none;"><input id="reclean_button" type="submit" value="'.__("Re-clean re-infected files",'gotmls').'" class="button-primary" onclick="checkAllFiles(false); setvalAllFiles(1); loadIframe(\'Reinfected File Recleaning Results\');" /><b>'.__("The items highlighted in red have been found to be re-infected. The malicious code has returned and needs to be cleaned again.",'gotmls').'</b></p>
549 <ul name="found_Quarantine" id="found_Quarantine" class="GOTMLS_plugin known" style="background-color: #ccc; padding: 0;"><h3 style="margin: 8px 12px;">'.($my_query->post_count>1?'<input type="checkbox" onchange="checkAllFiles(this.checked); document.getElementById(\'quarantine_buttons\').style.display = \'block\';"> '.sprintf(__("Check all %d",'gotmls'),$my_query->post_count):"").__(" Items in Quarantine",'gotmls').'<span class="GOTMLS_date">'.__("Quarantined",'gotmls').'</span><span class="GOTMLS_date">'.__("Date Infected",'gotmls').'</span></h3>';
550 $root_path = implode(GOTMLS_slash(), array_slice(GOTMLS_explode_dir(__FILE__), 0, (2 + intval($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_level"])) * -1));
551 while ($my_query->have_posts()) {
552 $my_query->the_post();
553 $gif = 'blocked.gif';
554 $threat = 'potential';
555 $action = $post->ID.'" id="check_'.$post->ID.'" onchange="document.getElementById(\'quarantine_buttons\').style.display = \'block\';';
556 $link = GOTMLS_error_link(__("The current/live file is missing or deleted",'gotmls'), $post->ID, $threat);
557 if (is_file($post->post_title)) {
558 GOTMLS_scanfile($post->post_title);
559 if (count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
560 $gif = 'threat.gif" onload="document.getElementById(\'reclean_buttons\').style.display = \'block\';';
561 $threat = 'known';
562 $action = GOTMLS_encode(realpath($post->post_title)).'" id="ilist_'.$post->ID.'" checked="true';
563 }
564 $link = GOTMLS_error_link(__("View current/live version",'gotmls'), $post->post_title, $threat);
565 } elseif (is_array($postdb = explode(":", $post->post_title.":")) && count($postdb) > 3 && is_numeric($postdb[1])) {
566 if ("options" == substr($postdb[0], -7)) {
567 if ($opt_row = $wpdb->get_row("SELECT * FROM `$wpdb->options` WHERE `option_id` = ".$postdb[1], ARRAY_A))
568 $link = GOTMLS_error_link(__("View Option Record: ",'gotmls').$postdb[1], $postdb[1].'.1', $threat);
569 elseif ($opt_row = $wpdb->get_row($SQL = $wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_name` LIKE %s", trim($postdb[2], '"')), ARRAY_A))
570 $link = GOTMLS_error_link(__("View Option Record: ",'gotmls').htmlspecialchars($postdb[2]), $opt_row["option_id"].'.1', $threat);
571 else
572 $link = GOTMLS_error_link(__("View Quarantine Record",'gotmls'), $post->ID, $threat);
573 } else {
574 $link = '<a target="_blank" href="';
575 if ("revision" == $postdb[0])
576 $link .= admin_url('revision.php?revision='.$postdb[1])."\" title=\"View this revision";
577 else
578 $link .= admin_url('post.php?action=edit&post='.$postdb[1])."\" title=\"View current ".$postdb[0];
579 $link .= "\" id=\"list_edit_$postdb[1]\" class=\"GOTMLS_plugin $threat\">";
580 }
581 }
582 $Q_Page .= '
583 <li id="GOTMLS_quarantine_'.$post->ID.'" class="GOTMLS_quarantine_item" onmouseover="this.style.fontWeight=\'bold\';" onmouseout="this.style.fontWeight=\'normal\';"><span class="GOTMLS_date">'.GOTMLS_error_link(__("View Quarantine Record",'gotmls'), $post->ID, $threat).$post->post_date_gmt.'</a></span><span class="GOTMLS_date">'.$post->post_modified_gmt.'</span><input type="checkbox" name="GOTMLS_fix[]" value="'.$action.'" /><img src="'.GOTMLS_images_path.$gif.'" height=16 width=16 alt="Q">'.$link.str_replace($root_path, "...", $post->post_title)."</a></li>\n";
584 }
585 $Q_Page .= "\n</ul>";
586 for ($p = 1; $p <= $my_query->max_num_pages; $p++) {
587 $Q_Paged .= '<input class="GOTMLS_page" type="submit" value="'.$p.'"'.((isset($_POST["paged"]) && $_POST["paged"] == $p) || (!isset($_POST["paged"]) && 1 == $p)?" DISABLED":"").' onclick="document.getElementById(\'GOTMLS_paged\').value = \''.$p.'\';">';
588 }
589 } else
590 $Q_Page .= '<h3>'.__("No Items in Quarantine",'gotmls').'</h3>';
591 wp_reset_query();
592 $return = "$Q_Paged\n</form><br style=\"clear: left;\" />\n$Q_Page\n</form>\n$Q_Paged\n</form><br style=\"clear: left;\" />\n";
593 if (($trashed = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` != 'private'")) > 1)
594 $return = '<a href="'.admin_url('admin-ajax.php?action=GOTMLS_empty_trash&'.GOTMLS_set_nonce(__FUNCTION__."720")).'" id="empty_trash_link" style="float: right;" target="GOTMLS_statusFrame">['.sprintf(__("Clear %s Deleted Files from the Trash",'gotmls'), $trashed)."]</a>$return";
595 return $return;
596 }
597
598 function GOTMLS_box($bTitle, $bContents, $bType = "postbox") {
599 $md5 = md5($bTitle);
600 if (isset($GLOBALS["GOTMLS"]["tmp"]["$bType"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["$bType"]))
601 $GLOBALS["GOTMLS"]["tmp"]["$bType"]["$md5"] = "$bTitle";
602 else
603 $GLOBALS["GOTMLS"]["tmp"]["$bType"] = array("$md5"=>"$bTitle");
604 return '
605 <div id="box_'.$md5.'" class="'.$bType.'"><h3 title="Click to toggle" onclick="if (typeof '.$bType.'_showhide == \'function\'){'.$bType.'_showhide(\'inside_'.$md5.'\');}else{showhide(\'inside_'.$md5.'\');}" style="cursor: pointer;" class="hndle"><span id="title_'.$md5.'">'.$bTitle.'</span></h3>
606 <div id="inside_'.$md5.'" class="inside">
607 '.$bContents.'
608 </div>
609 </div>';
610 }
611
612 if (isset($_GET["SESSION"]) && is_numeric($_GET["SESSION"]) && preg_match('|(.*?/gotmls\.js\?SESSION=)|', GOTMLS_script_URI, $match)) {
613 header("Content-type: text/javascript");
614 if (is_file(GOTMLS_plugin_path."safe-load/session.php"))
615 require_once(GOTMLS_plugin_path."safe-load/session.php");
616 if (isset($_SESSION["GOTMLS_SESSION_TEST"]))
617 die("/* GOTMLS SESSION PASS */\nif('undefined' != typeof stopCheckingSession && stopCheckingSession)\n\tclearTimeout(stopCheckingSession);\nshowhide('GOTMLS_patch_searching', true);\nif (autoUpdateDownloadGIF = document.getElementById('autoUpdateDownload'))\n\tdonationAmount = autoUpdateDownloadGIF.src.replace(/^.+\?/,'');\nif ((autoUpdateDownloadGIF.src == donationAmount) || donationAmount=='0') {\n\tif (patch_searching_div = document.getElementById('GOTMLS_patch_searching')) {\n\t\tif (autoUpdateDownloadGIF.src == donationAmount)\n\t\t\tpatch_searching_div.innerHTML = '<span style=\"color: #F00;\">".__("You must register and donate to use this feature!",'gotmls')."</span>';\n\t\telse\n\t\t\tpatch_searching_div.innerHTML = '<span style=\"color: #F00;\">".__("This feature is available to those who have donated!",'gotmls')."</span>';\n\t}\n} else {\n\tshowhide('GOTMLS_patch_searching');\n\tshowhide('GOTMLS_patch_button', true);\n}\n");
618 else {
619 $_SESSION["GOTMLS_SESSION_TEST"] = $_GET["SESSION"] + 1;
620 if ($_GET["SESSION"] > 0)
621 die("/* GOTMLS SESSION FAIL */\nif('undefined' != typeof stopCheckingSession && stopCheckingSession)\n\tclearTimeout(stopCheckingSession);\ndocument.getElementById('GOTMLS_patch_searching').innerHTML = '<div class=\"error\">".__("Your Server could not start a Session!",'gotmls')."</div>';");
622 else
623 die("/* GOTMLS SESSION TEST */\nif('undefined' != typeof stopCheckingSession && stopCheckingSession)\n\tclearTimeout(stopCheckingSession);\nstopCheckingSession = checkupdateserver('".$match[0].$_SESSION["GOTMLS_SESSION_TEST"]."', 'GOTMLS_patch_searching');");
624 }
625 } elseif ((isset($_SERVER["DOCUMENT_ROOT"]) && ($SCRIPT_FILE = str_replace($_SERVER["DOCUMENT_ROOT"], "", (isset($_SERVER["SCRIPT_FILENAME"])?$_SERVER["SCRIPT_FILENAME"]:(isset($_SERVER["SCRIPT_NAME"])?$_SERVER["SCRIPT_NAME"]:"")))) && strlen($SCRIPT_FILE) > strlen("/".basename(__FILE__)) && substr(__FILE__, -1 * strlen($SCRIPT_FILE)) == substr($SCRIPT_FILE, -1 * strlen(__FILE__)))) {
626 if (isset($_GET["page"]) && str_replace('-', '_', $_GET["page"]) == "GOTMLS_View_Quarantine" && isset($_REQUEST["GOTMLS_mt"]) && strlen($_REQUEST["GOTMLS_mt"]) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]])) {
627 $return = (print_r( array("nonce"=>$GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]],"mt"=>($_REQUEST["GOTMLS_mt"])),1));
628 try {
629 $Q_Paged = '<form method="POST" name="GOTMLS_Form_page"><input type="hidden" id="GOTMLS_paged" name="paged" value="1">';//<div style="float: left;">Page:</div>';
630 $Q_Page = '<form method="POST" action="?'.(isset($_SERVER["QUERY_STRING"])&&strlen($_SERVER["QUERY_STRING"])?$_SERVER["QUERY_STRING"]:"page=GOTMLS_View_Quarantine&".GOTMLS_set_nonce(__FUNCTION__."592")).'" name="GOTMLS_Form_clean">';
631 if (isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) {
632 $my_query = $wpdb->get_results("SELECT * FROM `{$table_prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private' AND `ID` = ".$_REQUEST["id"], ARRAY_A);
633 if (is_array($my_query) && count($my_query) && ($Q_post = $my_query[0]) && isset($Q_post["post_type"]) && $Q_post["post_type"] == "GOTMLS_quarantine" && isset($Q_post["post_status"]) && $Q_post["post_status"] == "private") {
634 $clean_file = $Q_post["post_title"];
635 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = GOTMLS_decode($Q_post["post_content"]);
636 $fa = "";
637 if (isset($Q_post["post_excerpt"]) && strlen($Q_post["post_excerpt"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"] = @unserialize(GOTMLS_decode($Q_post["post_excerpt"])))) {
638 $f = 1;
639 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
640 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
641 if (strlen($end) > 0 && is_numeric($start) && is_numeric($end)) {
642 if ($start < $end)
643 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
644 else
645 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$end.', '.$start.');">['.$f++.']</a>';
646 } else {
647 if (is_numeric($threats_found)) {
648 $threats_found = $threats_name;
649 $threats_name = $f;
650 }
651 $fpos = 0;
652 $flen = 0;
653 $potential_threat = str_replace("\r", "", $threats_found);
654 while (($fpos = strpos(str_replace("\r", "", $GLOBALS["GOTMLS"]["tmp"]["file_contents"]), ($potential_threat), $flen + $fpos)) !== false) {
655 $flen = strlen($potential_threat);
656 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.($fpos).', '.($fpos + $flen).');">['.$f++.']</a>';
657 }
658 }
659 }
660 }
661 die("\n".'<script type="text/javascript">
662 function select_text_range(ta_id, start, end) {
663 var textBox = document.getElementById(ta_id);
664 var scrolledText = "";
665 scrolledText = textBox.value.substring(0, end);
666 textBox.focus();
667 if (textBox.setSelectionRange) {
668 scrolledText = textBox.value.substring(end);
669 textBox.value = textBox.value.substring(0, end);
670 textBox.scrollTop = textBox.scrollHeight;
671 textBox.value = textBox.value + scrolledText;
672 textBox.setSelectionRange(start, end);
673 } else if (textBox.createTextRange) {
674 var range = textBox.createTextRange();
675 range.collapse(true);
676 range.moveStart("character", start);
677 range.moveEnd("character", end);
678 range.select();
679 } else
680 alert("The highlighting function does not work in your browser");
681 }
682 </script><table style="top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;"><tr><td style="width: 100%"><form style="margin: 0;" method="post" action="?'.GOTMLS_set_nonce(__FUNCTION__."643").'&page=GOTMLS_View_Quarantine" onsubmit="return confirm(\''.__("Are you sure you want to restore this file from the quarantine?",'gotmls').'\');"><input type="hidden" name="id[]" value="'.$Q_post["ID"].'"><input type="submit" value="RESTORE from Quarantine" style="display: none; background-color: #0C0; float: right;"></form><div id="fileperms" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"><b>File Details</b><br />encoding: '.(function_exists("mb_detect_encoding")?mb_detect_encoding($GLOBALS["GOTMLS"]["tmp"]["file_contents"]):"Unknown").'<br />size: '.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).' bytes<br />infected:'.$Q_post["post_modified_gmt"].'<br />quarantined:'.$Q_post["post_date_gmt"].'</div><div style="overflow: auto;"><span onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';">'.__("File Details:",'gotmls').'</span> ('.$fa.' )</div></td></tr><tr><td style="height: 100%"><textarea id="ta_file" style="width: 100%; height: 100%">'.GOTMLS_htmlentities(str_replace("\r", "", $GLOBALS["GOTMLS"]["tmp"]["file_contents"])).'</textarea></td></tr></table>');
683 } else
684 die('<h3>Item NOT Found in Quarantine</h3>');
685 } else {
686 $my_query = $wpdb->get_results("SELECT * FROM `{$table_prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private' ORDER BY `post_date_gmt` DESC", ARRAY_A);
687 if (is_array($my_query) && count($my_query)) {
688 $Q_Page .= '<p id="quarantine_buttons" style="display: none;"><input id="repair_button" type="submit" value="Restore selected files" class="button-primary" style="background-color: #0C0;" onclick="return confirm(\'Are you sure you want to overwrite the previously cleaned files with the selected files in the Quarantine?\');" /></p><p><b>The following items have been found to contain malicious code, they have been cleaned, and the original infected file contents have been saved here in the Quarantine. The code is safe here and you do not need to do anything further with these files.</b></p>
689 <ul name="found_Quarantine" id="found_Quarantine" class="GOTMLS_plugin known" style="background-color: #ccc; padding: 0;"><h3 style="margin: 8px 12px;">'.(count($my_query)>1?'<input type="checkbox" onchange="checkAllFiles(this.checked); document.getElementById(\'quarantine_buttons\').style.display = \'block\';"> '.sprintf(__("Check all %d",'gotmls'),count($my_query)):"").__(" Items in Quarantine",'gotmls').'<span class="GOTMLS_date">'.__("Quarantined",'gotmls').'</span><span class="GOTMLS_date">'.__("Date Infected",'gotmls').'</span></h3>';
690 $root_path = implode(GOTMLS_slash(), array_slice(GOTMLS_explode_dir(__FILE__), 0, (2 + intval($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_level"])) * -1));
691 foreach ($my_query as $post_a) {
692 $restored = "";
693 $image = "blocked";
694 if (isset($_REQUEST["id"]) && is_array($_REQUEST["id"]) && in_array($post_a["ID"], $_REQUEST["id"])) {
695 $restored = " read-only disabled";
696 if (GOTMLS_file_put_contents($post_a["post_title"], GOTMLS_decode($post_a["post_content"]))) {
697 $post_a["post_modified_gmt"] = date("Y-m-d H:i:s");
698 $image = "checked";
699 $wpdb->query("UPDATE `{$table_prefix}posts` SET `post_status` = 'pending' WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private' AND `ID` = ".$post_a["ID"]);
700 }
701 }
702 $Q_Page .= '
703 <li id="GOTMLS_quarantine_'.$post_a["ID"].'" class="GOTMLS_quarantine_item"><span class="GOTMLS_date">'.$post_a["post_date_gmt"].'</span><span class="GOTMLS_date">'.$post_a["post_modified_gmt"].'</span><input'.$restored.' type="checkbox" name="id[]" value="'.$post_a["ID"].'" id="GOTMLS_quarantine_check_'.$post_a["ID"].'" onchange="document.getElementById(\'quarantine_buttons\').style.display = \'block\';" /><img src="'.$image.'.gif" height=16 width=16 alt="Q"><a class="GOTMLS_plugin '.$restored.$post_a["ping_status"].'" target="_blank" href="?page=GOTMLS_View_Quarantine&id='.$post_a["ID"].'&'.GOTMLS_set_nonce(__FUNCTION__."191").'" title="View Quarantined File">'.str_replace($root_path, "...", $post_a["post_title"])."</a></li>\n";
704 }
705 $Q_Page .= "\n</ul>";
706 for ($p = 1; $p <= 0; $p++) {
707 $Q_Paged .= '<input class="GOTMLS_page" type="submit" value="'.$p.'"'.((isset($_POST["paged"]) && $_POST["paged"] == $p) || (!isset($_POST["paged"]) && 1 == $p)?" DISABLED":"").' onclick="document.getElementById(\'GOTMLS_paged\').value = \''.$p.'\';">';
708 }
709 } else
710 $Q_Page .= '<h3>'.__("No Items in Quarantine",'gotmls').'</h3>';
711 $return = "$Q_Paged\n</form><br style=\"clear: left;\" />\n$Q_Page\n</form>\n$Q_Paged\n</form><br style=\"clear: left;\" />\n";
712 die(GOTMLS_html_tags(array("html" => array("body" => GOTMLS_get_header().GOTMLS_box(__("View Quarantine",'gotmls'), "$return")))));
713 }
714 } catch (Exception $e) {
715 die('Caught exception: '. $e->getMessage(). "\n");
716 }
717 } else {
718 header("Content-type: image/gif");
719 $img_src = GOTMLS_local_images_path.'GOTMLS-16x16.gif';
720 if (!(file_exists($img_src) && $img_bin = @file_get_contents($img_src)))
721 $img_bin = GOTMLS_decode('R=lGODlhEAAQAIABAAAAAP___yH5BAEAAAEALAAAAAAQABAAAAIshB=Qm-eo2HuJNWdrjlFm3S2hKB7kViKaxZmr98YgSo_jzH6tiU=974MADwUAOw2');
722 die($img_bin);
723 }
724 } elseif (isset($_GET["no_error_reporting"]))
725 @error_reporting(0);
726
727 $GOTMLS_image_alt = array("wait"=>"...", "checked"=>"&#x2714;", "blocked"=>"X", "question"=>"?", "threat"=>"!");
728 $GOTMLS_dir_at_depth = array();
729 $GOTMLS_dirs_at_depth = array();
730 $GLOBAL_STRING = array("REQUEST" => "&","SERVER" => "&","FILES" => "&");
731 if (isset($_REQUEST) && is_array($_REQUEST))
732 foreach ($_REQUEST as $req => $val)
733 $GLOBAL_STRING["REQUEST"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
734 if (isset($_SERVER) && is_array($_SERVER))
735 foreach ($_SERVER as $req => $val)
736 $GLOBAL_STRING["SERVER"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
737 if (isset($_FILES) && is_array($_FILES))
738 foreach ($_FILES as $req => $fila)
739 foreach (array("tmp_name","name") as $val)
740 if (isset($fila["$val"]))
741 $GLOBAL_STRING["FILES"] .= "$req.$val=".(is_array($fila["$val"])?print_r($fila["$val"],1):$fila["$val"])."&";
742 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]) && array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"])))
743 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] = array(
744 "RevSlider"=>array("CCIGG", "Revolution Slider Exploit Protection", "This protection is automatically activated because of the widespread attacks on WordPress that have affected so many sites. It is still recommended that you make sure to upgrade any older versions of the Revolution Slider plugin, especially those included in themes that will not update automatically. Even if you don't think you have Revolution Slider on your site it doen't hurt to have this protection enabled.", "SERVER", '/\/admin-ajax\.php/i', "REQUEST", '/\&img=[^\&]*(?<!\.'.implode(')(?<!\.', array_slice($GLOBALS["GOTMLS"]["tmp"]["skip_ext"], 0, 10)).')\&/i'),
745 "Traversal"=>array("CCIGG", "Directory Traversal Protection", "This protection is automatically activated because this type of attack is quite common. This protection can prevent hackers from accessing secure files in parent directories (or user's folders outside the site_root).", "REQUEST", '/=[\s\/]*\.\.\//'),
746 "UploadPHP"=>array("CCIGG", "Upload PHP File Protection", "This protection is automatically activated because this type of attack is extremely dangerous. This protection can prevent hackers from uploading malicious code via web scripts.", "FILES", '/name=[^\&]*\.php\&/'));
747 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] as $TP => $VA) {
748 $V = 3;
749 if (is_array($VA) && count($VA) > $V && is_array($VA[$V])) {
750 foreach ($VA[$V] as $reg => $arr) {
751 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $arr;
752 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $reg;
753 }
754 }
755 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"]) && $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"])) {
756 $GLOBALS["GOTMLS"]["detected_attacks"] = "&attack[]=FW_$TP";
757 for ($V = 4; isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V]); $V+=2)
758 if (!isset($GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]]))
759 die($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]." [$V] not in <pre>".GOTMLS_htmlspecialchars(print_r($GLOBAL_STRING,1))."</pre>");
760 elseif (!preg_match($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V], $GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]], $matches))
761 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
762 if ($GLOBALS["GOTMLS"]["detected_attacks"])
763 include(dirname(dirname(__FILE__))."/safe-load/index.php");
764 }
765 }
766 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
767 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"]) && count($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"]) == 4))
768 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"] = $GLOBALS["GOTMLS"]["tmp"]["default"]["msg_position"];
769 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"]))
770 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"] = 2;
771 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]))
772 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"] = -1;
773 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"])))
774 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"] = $GLOBALS["GOTMLS"]["tmp"]["skip_ext"];
775 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"]))
776 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"] = "";
777 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"])))
778 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"] = array();
779 $GOTMLS_total_percent = 0;
780
781 function GOTMLS_admin_notices() {
782 if (!is_admin())
783 return;
784 elseif (is_file(dirname(dirname(dirname(__FILE__)))."/yuzo-related-post/yuzo_related_post.php"))
785 echo '<div class="error">It looks like you have <b>"Related Post" plugin By <i>Lenin Zapata</i></b> installed on your site.<br />This plugin was removed from the WordPress Plugin Repository because it contained a major vulnerability that was responsible for a fairly widespread breach to many WordPress sites that had it installed.<br />It is recommended that it be deactivated and deleted until a fix is released that solves this problem.</div>';
786 elseif ($GLOBALS["GOTMLS"]["tmp"]["HeadersError"])
787 echo $GLOBALS["GOTMLS"]["tmp"]["HeadersError"];
788 }
789 add_action("admin_notices", "GOTMLS_admin_notices");
790
791 function GOTMLS_array_recurse($array1, $array2) {
792 foreach ($array2 as $key => $value) {
793 if (!isset($array1[$key]) || (isset($array1[$key]) && !is_array($array1[$key])))
794 $array1[$key] = array();
795 if (is_array($value))
796 $value = GOTMLS_array_recurse($array1[$key], $value);
797 $array1[$key] = $value;
798 }
799 return $array1;
800 }
801
802 function GOTMLS_array_replace($array1, $array2) {
803 foreach ($array2 as $key => $value)
804 $array1[$key] = $value;
805 return $array1;
806 }
807
808 function GOTMLS_array_replace_recursive($array1 = array()) {
809 $args = func_get_args();
810 $array1 = $args[0];
811 if (!is_array($array1))
812 $array1 = array();
813 for ($i = 1; $i < count($args); $i++)
814 if (is_array($args[$i]))
815 $array1 = GOTMLS_array_recurse($array1, $args[$i]);
816 return $array1;
817 }
818
819 function GOTMLS_update_scan_log($scan_log) {
820 if (is_array($scan_log)) {
821 $GLOBALS["GOTMLS"]["log"] = GOTMLS_array_replace_recursive($GLOBALS["GOTMLS"]["log"], $scan_log);
822 if (isset($GLOBALS["GOTMLS"]["log"]["scan"]["percent"]) && is_numeric($GLOBALS["GOTMLS"]["log"]["scan"]["percent"]) && ($GLOBALS["GOTMLS"]["log"]["scan"]["percent"] >= 100))
823 $GLOBALS["GOTMLS"]["log"]["scan"]["finish"] = time();
824 if (isset($GLOBALS["GOTMLS"]["log"]["scan"]))
825 update_option("GOTMLS_scan_log/".(isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:"0.0.0.0")."/".$GLOBALS["GOTMLS"]["tmp"]["mt"], $GLOBALS["GOTMLS"]["log"]);
826 }
827 }
828
829 function GOTMLS_loaded() {
830 if (headers_sent($filename, $linenum)) {
831 if (!$filename)
832 $filename = __("an unknown file",'gotmls');
833 if (!is_numeric($linenum))
834 $linenum = __("unknown",'gotmls');
835 $GLOBALS["GOTMLS"]["tmp"]["HeadersError"] = '<div class="error">'.sprintf(__('<b>Headers already sent</b> in %1$s on line %2$s.<br />This is not a good sign, it may just be a poorly written plugin but Headers should not have been sent at this point.<br />Check the code in the above mentioned file to fix this problem.','gotmls'), $filename, $linenum).'</div>';
836 } elseif (isset($_GET["SESSION"]) && !session_id()) {
837 @session_start();
838 if (session_id() && $_GET["SESSION"] == "GOTMLS_debug" && !isset($_SESSION["GOTMLS_debug"]))
839 $_SESSION["GOTMLS_debug"]=array();
840 }
841 }
842 add_action("plugins_loaded", "GOTMLS_loaded");
843
844 if (!function_exists("add_action")) {
845 GOTMLS_loaded();
846 // GOTMLS_admin_notices();
847 }
848
849 function GOTMLS_get_ext($filename) {
850 $nameparts = explode(".", ".$filename");
851 return strtolower($nameparts[(count($nameparts)-1)]);
852 }
853
854 function GOTMLS_preg_match_all($threat_definition, $threat_name) {
855 if (@preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["file_contents"], $threats_found)) {
856 $start = -1;
857 if (!@preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["new_contents"], $threat_found)) {
858 $new_contents = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
859 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
860 } else
861 $new_contents = false;
862 foreach ($threats_found[0] as $find) {
863 $potential_threat = str_replace("\r", "", $find);
864 $flen = strlen($potential_threat);
865 while (($start = strpos(str_replace("\r", "", $GLOBALS["GOTMLS"]["tmp"]["file_contents"]), $potential_threat, $start+1)) !== false)
866 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".($flen+$start)] = "$threat_name";
867 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = str_replace($find, "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]);
868 }
869 if ($new_contents && strlen($new_contents) < strlen($GLOBALS["GOTMLS"]["tmp"]["new_contents"]))
870 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $new_contents;
871 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
872 } else
873 return false;
874 }
875
876 function GOTMLS_check_threat($check_threats, $file='UNKNOWN') {
877 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
878 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
879 if (is_array($check_threats)) {
880 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
881 if (substr($file, 0, strlen(ABSPATH)) == ABSPATH && isset($check_threats[GOTMLS_wp_version]["$path"])) {
882 if (($check_threats[GOTMLS_wp_version]["$path"] != md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"])."O".strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])) && ($source = GOTMLS_get_URL("http://core.svn.wordpress.org/tags/".GOTMLS_wp_version."$path")) && ($check_threats[GOTMLS_wp_version]["$path"] == md5($source)."O".strlen($source))) {
883 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
884 $len = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
885 if (strlen($source) < $len)
886 $len = strlen($source);
887 for ($start = 0, $end = 0; ($start == 0 || $end == 0) && $len > 0; $len--){
888 if ($start == 0 && substr($source, 0, $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], 0, $len))
889 $start = $len;
890 if ($end == 0 && substr($source, -1 * $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], -1 * $len))
891 $end = $len;
892 }
893 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".(strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])-$end)] = "Core File Modified";
894 }
895 } else {
896 foreach ($check_threats as $threat_name=>$threat_definitions) {
897 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
898 if (is_array($threat_definitions) && count($threat_definitions) > 1 && strlen(array_shift($threat_definitions)) == 5 && (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["dont_check"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["dont_check"]) && in_array($threat_name, $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["dont_check"]))))
899 while ($threat_definition = array_shift($threat_definitions))
900 GOTMLS_preg_match_all($threat_definition, $threat_name);
901 if (isset($_SESSION["GOTMLS_debug"])) {
902 $_SESSION["GOTMLS_debug"]["threat_name"] = $threat_name;
903 $file_time = round(microtime(true) - $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"], 5);
904 if (isset($_GET["GOTMLS_debug"]) && is_numeric($_GET["GOTMLS_debug"]) && $file_time > $_GET["GOTMLS_debug"])
905 echo "\n//GOTMLS_debug $file_time $threat_name $file\n";
906 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"]))
907 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] += $file_time;
908 else
909 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] = $file_time;
910 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"]))
911 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"] ++;
912 else
913 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"] = 1;
914 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"])
915 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"] = $file_time;
916 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"])
917 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"] = $file_time;
918 }
919 }
920 }
921 } elseif (strlen($check_threats) && isset($_GET['eli']) && substr($check_threats, 0, 1) == '/')
922 GOTMLS_preg_match_all($check_threats, $check_threats);
923 if (isset($_SESSION["GOTMLS_debug"])) {
924 $file_time = round(microtime(true) - $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"], 5);
925 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"]))
926 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] += $file_time;
927 else
928 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] = $file_time;
929 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"]))
930 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"] ++;
931 else
932 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"] = 1;
933 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"])
934 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"] = $file_time;
935 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"])
936 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"] = $file_time;
937 }
938 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
939 }
940
941 function GOTMLS_scanfile($file) {
942 global $wpdb, $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
943 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="Scanning...";
944 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
945 $gt = ">";
946 $lt = "<";
947 $found = false;
948 $threat_link = "";
949 $className = "scanned";
950 $real_file = realpath($file);
951 $clean_file = GOTMLS_encode($real_file);
952 if (is_file($real_file) && ($filesize = filesize($real_file)) && ($GLOBALS["GOTMLS"]["tmp"]["file_contents"] = @file_get_contents($real_file))) {
953 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]))
954 $whitelist = array_flip($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]);
955 else
956 $whitelist = array();
957 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"])) {
958 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"] as $whitelist_file=>$non_threats) {
959 if (is_array($non_threats) && count($non_threats) > 1) {
960 if (isset($non_threats[0]))
961 unset($non_threats[0]);
962 $whitelist = array_merge($whitelist, $non_threats);
963 }
964 }
965 }
966 if (isset($whitelist[md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'O'.$filesize]))
967 return GOTMLS_return_threat($className, "checked.gif?$className", $file, $threat_link);
968 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
969 if (isset($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"]) && strlen($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"]) && isset($_GET['eli']) && substr($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"], 0, 1) == '/' && ($found = GOTMLS_check_threat($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"])))
970 $className = "known";
971 else {
972 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
973 if (isset($_SESSION["GOTMLS_debug"])) {
974 $_SESSION["GOTMLS_debug"]["file"] = $file;
975 $_SESSION["GOTMLS_debug"]["last"]["total"] = microtime(true);
976 }
977 if (isset($GLOBALS["GOTMLS"]["tmp"]["threat_levels"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threat_levels"])) {
978 foreach ($GLOBALS["GOTMLS"]["tmp"]["threat_levels"] as $threat_level) {
979 if ("db_scan" != $threat_level) {
980 if (isset($_SESSION["GOTMLS_debug"])) {
981 $_SESSION["GOTMLS_debug"]["threat_level"] = $threat_level;
982 $_SESSION["GOTMLS_debug"]["last"]["threat_level"] = microtime(true);
983 }
984 if (in_array($threat_level, $GLOBALS["GOTMLS"]["log"]["settings"]["check"]) && !$found && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"][$threat_level]) && ($threat_level != "wp_core" || (substr($file, 0, strlen(ABSPATH)) == ABSPATH && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"]))) && (!array_key_exists($threat_level, $GLOBALS["GOTMLS"]["tmp"]["threat_files"]) || (substr($file."e", (-1 * strlen($GLOBALS["GOTMLS"]["tmp"]["threat_files"][$threat_level]."e"))) == $GLOBALS["GOTMLS"]["tmp"]["threat_files"][$threat_level]."e")) && ($found = GOTMLS_check_threat($GLOBALS["GOTMLS"]["tmp"]["definitions_array"][$threat_level],$file)))
985 $className = $threat_level;
986 }
987 }
988 }
989 if (isset($_SESSION["GOTMLS_debug"])) {
990 $file_time = round(microtime(true) - $_SESSION["GOTMLS_debug"]["last"]["total"], 5);
991 if (isset($_SESSION["GOTMLS_debug"]["total"]["total"]))
992 $_SESSION["GOTMLS_debug"]["total"]["total"] += $file_time;
993 else
994 $_SESSION["GOTMLS_debug"]["total"]["total"] = $file_time;
995 if (isset($_SESSION["GOTMLS_debug"]["total"]["count"]))
996 $_SESSION["GOTMLS_debug"]["total"]["count"] ++;
997 else
998 $_SESSION["GOTMLS_debug"]["total"]["count"] = 1;
999 if (!isset($_SESSION["GOTMLS_debug"]["total"]["least"]) || $file_time < $_SESSION["GOTMLS_debug"]["total"]["least"])
1000 $_SESSION["GOTMLS_debug"]["total"]["least"] = $file_time;
1001 if (!isset($_SESSION["GOTMLS_debug"]["total"]["most"]) || $file_time > $_SESSION["GOTMLS_debug"]["total"]["most"])
1002 $_SESSION["GOTMLS_debug"]["total"]["most"] = $file_time;
1003 }
1004 }
1005 } else {
1006 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = (is_file($real_file)?(is_readable($real_file)?(filesize($real_file)?__("Failed to read file contents!",'gotmls'):__("Empty file!",'gotmls')):(isset($_GET["eli"])?(@chmod($real_file, $GOTMLS_chmod_file)?__("Fixed file permissions! (try again)",'gotmls'):__("File permissions read-only!",'gotmls')):__("File not readable!",'gotmls'))):__("File does not exist!",'gotmls'));
1007 // $threat_link = GOTMLS_error_link($GLOBALS["GOTMLS"]["tmp"]["file_contents"], $real_file);
1008 $className = "errors";
1009 }
1010 if (count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1011 $threat_link = $lt.'a target="GOTMLS_iFrame" href="'.admin_url('admin-ajax.php?action=GOTMLS_scan&'.GOTMLS_set_nonce(__FUNCTION__."687").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$clean_file.preg_replace('/\&(GOTMLS_scan|mt|GOTMLS_mt|action)=/', '&last_\1=', isset($_SERVER["QUERY_STRING"])&&strlen($_SERVER["QUERY_STRING"])?"&".$_SERVER["QUERY_STRING"]:"")).'" id="list_'.$clean_file.'" onclick="loadIframe(\''.str_replace("\"", "&quot;", $lt.'div style="float: left; white-space: nowrap;"'.$gt.__("Examine File",'gotmls').' ... '.$lt.'/div'.$gt.$lt.'div style="overflow: hidden; position: relative; height: 20px;"'.$gt.$lt.'div style="position: absolute; right: 0px; text-align: right; width: 9000px;"'.$gt.GOTMLS_htmlspecialchars(GOTMLS_strip4java($file), ENT_NOQUOTES)).$lt.'/div'.$gt.$lt.'/div'.$gt.'\');" class="GOTMLS_plugin"'.$gt;
1012 if ($className == "errors") {
1013 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="errors";
1014 $threat_link = GOTMLS_error_link($GLOBALS["GOTMLS"]["tmp"]["file_contents"], $file);
1015 $imageFile = "/blocked";
1016 } elseif ($className != "potential") {
1017 if (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1018 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="GOTMLS_fix";
1019 if (GOTMLS_get_nonce()) {
1020 if ($className == "timthumb") {
1021 if (($source = GOTMLS_get_URL("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/timthumb/timthumb.php")) && strlen($source) > 500)
1022 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1023 else
1024 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
1025 } elseif ($className == 'wp_core') {
1026 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
1027 if (substr($file, 0, strlen(ABSPATH)) == ABSPATH && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"]) && ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"] != md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"])."O".strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])) && ($source = GOTMLS_get_URL("http://core.svn.wordpress.org/tags/".GOTMLS_wp_version."$path")) && ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"] == md5($source)."O".strlen($source)))
1028 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1029 else
1030 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
1031 } else {
1032 $GOTMLS_no_contents = trim(preg_replace('/\/\*.*?\*\/\s*/s', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
1033 $GOTMLS_no_contents = trim(preg_replace('/\n\s*\/\/.*/', "", $GOTMLS_no_contents));
1034 $GOTMLS_no_contents = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GOTMLS_no_contents));
1035 if (strlen($GOTMLS_no_contents))
1036 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
1037 else
1038 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = "";
1039 }
1040 if (strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]) > 0 && (($Q_post = GOTMLS_write_quarantine($file, $className)) !== false) && ((strlen($GLOBALS["GOTMLS"]["tmp"]["new_contents"])==0 && isset($_GET["eli"]) && ($_GET["eli"] == "delete") && @unlink($file)) || (($Write_File = GOTMLS_file_put_contents($file, $GLOBALS["GOTMLS"]["tmp"]["new_contents"])) !== false))) {
1041 echo __("Success!",'gotmls');
1042 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
1043 } else {
1044 echo __("Failed:",'gotmls').' '.(strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])?((is_writable(dirname($file)) && is_writable($file))?(($Q_post===false)?__("failed to quarantine!",'gotmls')." (".$wpdb->last_error.")":((isset($Write_File)&&$Write_File)?"Q=$Q_post: ".__("reason unknown!",'gotmls'):"Q=$Q_post: ".__("failed to write!",'gotmls'))):__("file not writable!",'gotmls')):__("no file contents!",'gotmls'));
1045 if (isset($_GET["eli"]))
1046 echo 'uid='.getmyuid().'('.get_current_user().'),gid='.getmygid().($lt.'br'.$gt.$lt.'pre'.$gt.'file_stat'.print_r(stat($file), true));
1047 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
1048 }
1049 } else {
1050 echo GOTMLS_Invalid_Nonce(__("Failed: ",'gotmls'));
1051 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
1052 }
1053 }
1054 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]=isset($_POST["GOTMLS_fix"])?"GOTMLS_fix=".GOTMLS_htmlspecialchars(print_r($_POST["GOTMLS_fix"],1)):"!potential";
1055 $threat_link = $lt.'input type="checkbox" name="GOTMLS_fix[]" value="'.$clean_file.'" id="check_'.$clean_file.(($className != "wp_core||ifitis")?'" checked="'.$className:'').'" /'.$gt.$threat_link;
1056 $imageFile = "threat";
1057 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1058 echo __("Already Fixed!",'gotmls');
1059 return "/*-->*"."/\nfixedFile('$clean_file');\n/*<!--*"."/";
1060 } else
1061 $imageFile = "question";
1062 return GOTMLS_return_threat($className, $imageFile, $file, str_replace("GOTMLS_plugin", "GOTMLS_plugin $className", $threat_link));
1063 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1064 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="Already Fixed";
1065 echo __("Already Fixed!",'gotmls');
1066 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
1067 } else {
1068 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="no threat";
1069 return GOTMLS_return_threat($className, ($className=="scanned"?"checked":"blocked").".gif?$className", $file, $threat_link);
1070 }
1071 }
1072
1073 function GOTMLS_db_scan($id = 0) {
1074 global $wpdb;
1075 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"]) && count($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"])) {
1076 if ($id) {
1077 $encoded_id = GOTMLS_encode($id);
1078 $ids = explode(".", $id.'.');
1079 if (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl1' && is_numeric($ids[0]) && ($Q_post = $wpdb->get_row("SELECT * FROM `$wpdb->options` WHERE `option_id` = ".$ids[0], ARRAY_A))) {
1080 $path = 'Option ID: '.$Q_post["option_id"];
1081 $clean_file = $Q_post["option_name"];
1082 $fa = "";
1083 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = $Q_post["option_value"];
1084 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = ($Q_post["option_value"]);
1085 $found = 0;
1086 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1087 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
1088 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1089 $threat_name = array_shift($scan_regex);
1090 while ($threat_definition = array_shift($scan_regex))
1091 $found += GOTMLS_preg_match_all($threat_definition, $threat_name);
1092 }
1093 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1094 $f = 1;
1095 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
1096 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
1097 if ($start > $end)
1098 $fa .= 'ERROR['.($f++).']: Threat_size{'.$threats_found.'} Content_size{'.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'}';
1099 else
1100 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
1101 }
1102 } else
1103 $fa = " No Threats Found";
1104 if (isset($_REQUEST["GOTMLS_fix"]) && is_array($_REQUEST["GOTMLS_fix"]) && in_array($encoded_id, $_REQUEST["GOTMLS_fix"]) && isset($_REQUEST["GOTMLS_fixing"]) && $_REQUEST["GOTMLS_fixing"] > 0) {
1105 GOTMLS_write_quarantine($Q_post, "db_scan");
1106 if ($_REQUEST["GOTMLS_fixing"] > 1) {
1107 echo "<li>Removing $path ... ";
1108 if ($wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_id` = ".$Q_post["option_id"])) {
1109 echo __("Done!",'gotmls');
1110 $li_js .= "/*-->*"."/\nDeletedFile('$encoded_id');\n/*<!--*"."/";
1111 } else {
1112 echo __("Failed to delete!",'gotmls');
1113 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1114 }
1115 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal of Option")));
1116 } else {
1117 echo "<li>Fixing $path ... ";
1118 if ($wpdb->update($wpdb->options, array("option_value" => $GLOBALS["GOTMLS"]["tmp"]["new_contents"]), array('option_id' => $Q_post["option_id"]))) {
1119 echo __("Success!",'gotmls');
1120 $li_js .= "/*-->*"."/\nfixedFile('$encoded_id');\n/*<!--*"."/";
1121 } else {
1122 echo __("Update Failed!",'gotmls');
1123 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1124 }
1125 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal from Option")));
1126 }
1127 return $li_js;
1128 } else {
1129 return admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."853")).'" onsubmit="return confirm(\''.__("Are you sure you want to delete this option?",'gotmls').'\');"><input type="hidden" name="GOTMLS_fixing" value="2"><input type="hidden" name="action" value="GOTMLS_fix"><input type="submit" value="Delete this Option" style="float: right;"><input type="hidden" name="GOTMLS_fix[]" value="'.$encoded_id.'"></form><div id="fileperms" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"><b>Record Details</b><br />encoding: '.(function_exists("mb_detect_encoding")?mb_detect_encoding($GLOBALS["GOTMLS"]["tmp"]["file_contents"]):"Unknown").'<br />size: '.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).' bytes</div><div style="overflow: auto;"><span onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';">'.__("Record Details:",'gotmls').'</span> ('.$fa.' )</div></td></tr><tr><td style="height: 100%"><textarea id="ta_file" style="width: 100%; height: 100%">'.GOTMLS_htmlentities(str_replace("\r", "", $GLOBALS["GOTMLS"]["tmp"]["file_contents"])).'</textarea></td></tr></table>';
1130 }
1131 } elseif (($Q_post = GOTMLS_get_quarantine($ids[0])) && isset($Q_post["post_content"])) {
1132 $path = $Q_post["post_type"].' ID: '.$Q_post["ID"];
1133 $clean_file = $Q_post["post_title"];
1134 $fa = "";
1135 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = $Q_post["post_content"];
1136 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = ($Q_post["post_content"]);
1137 $found = 0;
1138 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1139 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
1140 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1141 $threat_name = array_shift($scan_regex);
1142 while ($threat_definition = array_shift($scan_regex))
1143 $found += GOTMLS_preg_match_all($threat_definition, $threat_name);
1144 }
1145 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1146 $f = 1;
1147 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
1148 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
1149 if ($start > $end)
1150 $fa .= 'ERROR['.($f++).']: Threat_size{'.$threats_found.'} Content_size{'.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'}';
1151 else
1152 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
1153 }
1154 } else
1155 $fa = " No Threats Found";
1156 if (isset($_REQUEST["GOTMLS_fix"]) && is_array($_REQUEST["GOTMLS_fix"]) && in_array($encoded_id, $_REQUEST["GOTMLS_fix"]) && isset($_REQUEST["GOTMLS_fixing"]) && $_REQUEST["GOTMLS_fixing"] > 0) {
1157 if ($_REQUEST["GOTMLS_fixing"] > 1) {
1158 echo "<li>Removing $path ... ";
1159 $Q_post["post_status"] = "trash";
1160 if (wp_update_post($Q_post)) {
1161 echo __("Done!",'gotmls');
1162 $li_js .= "/*-->*"."/\nDeletedFile('$encoded_id');\n/*<!--*"."/";
1163 } else {
1164 echo __("Failed to delete!",'gotmls');
1165 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1166 }
1167 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal of Revision")));
1168 } else {
1169 echo "<li>Fixing $path ... ";
1170 GOTMLS_write_quarantine($Q_post, "db_scan");
1171 $Q_post["post_content"] = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
1172 if (wp_update_post($Q_post)) {
1173 echo __("Success!",'gotmls');
1174 $li_js .= "/*-->*"."/\nfixedFile('$encoded_id');\n/*<!--*"."/";
1175 } else {
1176 echo __("Update Failed!",'gotmls');
1177 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1178 }
1179 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal from Content")));
1180 }
1181 return $li_js;
1182 } else {
1183 return admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."905")).($Q_post["post_type"]=="revision"?'" onsubmit="return confirm(\''.__("Are you sure you want to delete this revision?",'gotmls').'\');"><input type="hidden" name="GOTMLS_fixing" value="2"><input type="hidden" name="action" value="GOTMLS_fix"><input type="submit" value="Delete this revision" style="float: right;"><input type="hidden" name="GOTMLS_fix[]" value="'.$encoded_id:"").'"></form><div id="fileperms" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"><b>Record Details</b><br />encoding: '.(function_exists("mb_detect_encoding")?mb_detect_encoding($GLOBALS["GOTMLS"]["tmp"]["file_contents"]):"Unknown").'<br />size: '.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).' bytes<br />last_modified:'.$Q_post["post_modified_gmt"].'<br />post_type:'.$Q_post["post_type"].'<br />author:'.$Q_post["post_author"].'<br />status:'.$Q_post["post_status"].'</div><div style="overflow: auto;"><span onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';">'.__("Record Details:",'gotmls').'</span> ('.$fa.' )</div></td></tr><tr><td style="height: 100%"><textarea id="ta_file" style="width: 100%; height: 100%">'.GOTMLS_htmlentities(str_replace("\r", "", $GLOBALS["GOTMLS"]["tmp"]["file_contents"])).'</textarea></td></tr></table>';
1184 }
1185 } else
1186 die(GOTMLS_html_tags(array("html" => array("body" => __("This record no longer exists.",'gotmls')."<br />\n<script type=\"text/javascript\">\nwindow.parent.showhide('GOTMLS_iFrame', true);\n</script>"))));
1187 } else {
1188 $threats_found = array();
1189 $li_js = "";
1190 if (!isset($_REQUEST["eli"]))
1191 $and = " AND `post_status` != 'trash'";
1192 if (isset($_REQUEST["limit"]) && is_numeric($_REQUEST["limit"]))
1193 $and = " LIMIT ".$_REQUEST["limit"];
1194 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"])) {
1195 if (isset($_GET["GOTMLS_scan"]) && strlen($_GET["GOTMLS_scan"]) > 8 && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][substr($_GET["GOTMLS_scan"], 8)])) {
1196 $scan_replace = str_replace("db_scan", "Database for ", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1197 $db_scan_a = array(substr($_GET["GOTMLS_scan"], 8) => $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][substr($_GET["GOTMLS_scan"], 8)]);
1198 } elseif (isset($_GET["GOTMLS_only_file"]) && strlen($_GET["GOTMLS_only_file"]) && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][GOTMLS_decode($_GET["GOTMLS_only_file"])])) {
1199 $scan_replace = str_replace("db_scan", "Database only ".(isset($_GET["limit"]) && is_numeric($_GET["limit"])) ? $_GET["limit"] : ""." for ", GOTMLS_htmlspecialchars("db_scan".GOTMLS_decode($_GET["GOTMLS_only_file"])));
1200 $_GET["GOTMLS_scan"] = "db_scan=".GOTMLS_decode($_GET["GOTMLS_only_file"]);
1201 $db_scan_a = array(GOTMLS_decode($_GET["GOTMLS_only_file"]) => $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][GOTMLS_decode($_GET["GOTMLS_only_file"])]);
1202 } else {
1203 $scan_replace = str_replace("db_scan", "Database", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1204 $db_scan_a = $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"];
1205 }
1206 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), $scan_replace));
1207 GOTMLS_flush();
1208 $li_js .= "/*<!--*"."/".GOTMLS_return_threat("dir", "checked", $_GET["GOTMLS_scan"]).GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), $scan_replace));
1209 } else {
1210 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("No Definitions for DB Injections!",'gotmls')));
1211 GOTMLS_flush();
1212 $li_js .= GOTMLS_return_threat("error", "question", $_GET["GOTMLS_scan"]);
1213 $db_scan_a = $_GET["GOTMLS_scan"];
1214 }
1215 if (isset($db_scan_a) && is_array($db_scan_a)) {
1216 echo "\n//memory_limit=".@ini_get("memory_limit")."\n";
1217 foreach ($db_scan_a as $scan_sql => $scan_regex) {
1218 $SQL = preg_replace('/\{[a-f0-9]{64}\}/', '%', $wpdb->prepare("SELECT * FROM `$wpdb->posts` WHERE `post_content` LIKE %s $and", $scan_sql));
1219 $threat_name = array_shift($scan_regex);
1220 if (($found_row = $wpdb->get_results($SQL, ARRAY_A)) && is_array($found_row) && count($found_row)) {
1221 $val = count($found_row);
1222 if (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1223 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("$val Rows", 0));//debug
1224 foreach ($found_row as $frow) {
1225 $encoded_id = GOTMLS_encode($frow["ID"].'.0');
1226 $found = 0;
1227 if ($frow["post_type"] != "revision" || isset($_REQUEST["eli"])) {
1228 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = $frow["post_content"];
1229 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1230 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1231 foreach ($scan_regex as $threat_definition)
1232 $found += GOTMLS_preg_match_all($threat_definition, $threat_name);
1233 if ($found && !isset($threats_found['row_id_'.$encoded_id])) {
1234 echo str_replace($frow["ID"].'</a>', '</a><a target="_blank" title="Open '.$frow["post_type"].'" href="'.admin_url(($frow["post_type"]=="revision")?'revision.php?revision='.$frow["ID"].'">View Revision: ':'post.php?action=edit&post='.$frow["ID"].'">Edit '.$frow["post_type"].': ').$frow["ID"].'</a>', GOTMLS_return_threat("db_scan", "threat", "$found $threat_name(\"".str_replace('%', '*', trim($scan_sql, "%")).'") in '.$frow["post_type"]."(".(($frow["post_status"]=='inherit')?$frow["post_parent"]:$frow["post_status"]).'):"'.GOTMLS_htmlspecialchars($frow["post_title"]).'":'.$frow["ID"], '<input type="checkbox" name="GOTMLS_fix[]" id="check_'.$encoded_id.'" value="'.$encoded_id.'" checked="true">'.GOTMLS_error_link(__("View DB Injection",'gotmls'), $frow["ID"].'.0', "db_scan")));
1235 $threats_found['row_id_'.$encoded_id] = $threat_name;
1236 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1237 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("post_id"=>$frow["ID"], "scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("No preg_match", 0));//debug
1238 }
1239 }
1240 }
1241 if (($found_row = $wpdb->get_results(preg_replace('/\{[a-f0-9]{64}\}/', '%', $wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_value` LIKE %s", $scan_sql)), ARRAY_A)) && is_array($found_row) && count($found_row)) {
1242 $val = count($found_row);
1243 if (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1244 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("$val Rows", 0));//debug
1245 foreach ($found_row as $frow) {
1246 $encoded_id = GOTMLS_encode($frow["option_id"].'.1');
1247 $found = 0;
1248 $opt_val = maybe_unserialize($frow["option_value"]);
1249 if (is_array($opt_val)) {
1250 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1251 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1252 foreach ($scan_regex as $threat_definition)
1253 foreach ($opt_val as $GLOBALS["GOTMLS"]["tmp"]["file_contents"])
1254 $found += GOTMLS_preg_match_all($threat_definition, $threat_name);
1255 if ($found && !isset($threats_found['row_id_'.$encoded_id])) {
1256 echo GOTMLS_return_threat("db_scan", "threat", "$found $threat_name(\"".str_replace('%', '*', trim($scan_sql, "%")).'") in '."$wpdb->options:".GOTMLS_htmlspecialchars($frow["option_name"]).'":'.$frow["option_id"].'.1', '<input type="checkbox" name="GOTMLS_fix[]" id="check_'.$encoded_id.'" value="'.$encoded_id.'" checked="true">'.GOTMLS_error_link(__("View DB Injection",'gotmls'), $frow["option_id"].'.1', "db_scan"));
1257 $threats_found['row_id_'.$encoded_id] = $threat_name;
1258 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1259 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("post_id"=>$frow["ID"], "scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("No preg_match", 0));//debug
1260 } else {
1261 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = $opt_val;
1262 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1263 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1264 foreach ($scan_regex as $threat_definition)
1265 $found += GOTMLS_preg_match_all($threat_definition, $threat_name);
1266 if ($found && !isset($threats_found['row_id_'.$encoded_id])) {
1267 echo GOTMLS_return_threat("db_scan", "threat", "$found $threat_name(\"".str_replace('%', '*', trim($scan_sql, "%")).'") in '."$wpdb->options:".GOTMLS_htmlspecialchars($frow["option_name"]).'":'.$frow["option_id"].'.1', '<input type="checkbox" name="GOTMLS_fix[]" id="check_'.$encoded_id.'" value="'.$encoded_id.'" checked="true">'.GOTMLS_error_link(__("View DB Injection",'gotmls'), $frow["option_id"].'.1', "db_scan"));
1268 $threats_found['row_id_'.$encoded_id] = $threat_name;
1269 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1270 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("post_id"=>$frow["ID"], "scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("No preg_match", 0));//debug
1271 }
1272 }
1273 }
1274 }
1275 }
1276 return "$li_js/*-->*"."/\nscanNextDir(-1);\n/*<!--*"."/";
1277 }
1278 }
1279 }
1280
1281 function GOTMLS_remove_dots($dir) {
1282 if ($dir != "." && $dir != "..")
1283 return $dir;
1284 }
1285
1286 function GOTMLS_getfiles($dir) {
1287 $files = false;
1288 if (is_dir($dir)) {
1289 if (function_exists("scandir"))
1290 $files = @scandir($dir);
1291 if (is_array($files))
1292 $files = array_filter($files, "GOTMLS_remove_dots");
1293 elseif ($handle = @opendir($dir)) {
1294 $files = array();
1295 while (false !== ($entry = readdir($handle)))
1296 if ($entry != "." && $entry != "..")
1297 $files[] = "$entry";
1298 closedir($handle);
1299 } else
1300 $files = GOTMLS_read_error($dir);
1301 }
1302 return $files;
1303 }
1304
1305 function GOTMLS_decodeBase64($encoded_string) {
1306 if (function_exists("base64_decode"))
1307 $unencoded_string = base64_decode($encoded_string);
1308 elseif (function_exists("mb_convert_encoding"))
1309 $unencoded_string = mb_convert_encoding($encoded_string, "UTF-8", "BASE64");
1310 else
1311 return "Cannot decode: '$encoded_string'";
1312 return "'".str_replace("'", "\\'", str_replace("\\", "\\\\", $unencoded_string))."'";
1313 }
1314
1315 function GOTMLS_decodeHex($encoded_string) {
1316 if (strtolower(substr($encoded_string, 0, 2)) == "\\x")
1317 $dec_string = hexdec($encoded_string);
1318 else
1319 $dec_string = octdec($encoded_string);
1320 return chr($dec_string);
1321 }
1322
1323 function GOTMLS_return_threat($className, $imageFile, $fileName, $link = "") {
1324 global $GOTMLS_image_alt;
1325 $fileNameJS = GOTMLS_strip4java(str_replace("db_scan", "Database", str_replace("db_scan=", "Database Query ", isset($GLOBALS["GOTMLS"]["log"]["scan"]["dir"])?str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $fileName):$fileName)));
1326 $fileName64 = GOTMLS_encode($fileName);
1327 $li_js = "/*-->*"."/";
1328 if ($className != "scanned")
1329 $li_js .= "\n$className++;\ndivx=document.getElementById('found_$className');\nif (divx) {\n\tvar newli = document.createElement('li');\n\tnewli.innerHTML='<img src=\"".GOTMLS_strip4java(GOTMLS_images_path.$imageFile).".gif\" height=16 width=16 alt=\"".$GOTMLS_image_alt[$imageFile]."\" style=\"float: left;\" id=\"$imageFile"."_$fileName64\">".GOTMLS_strip4java($link, true).$fileNameJS.($link?"</a>';\n\tdivx.display='block":"")."';\n\tdivx.appendChild(newli);\n}";
1330 if ($className == "errors")
1331 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx) {\n\tdivx.src='".GOTMLS_images_path."blocked.gif';\n\tdirerrors++;\n}";
1332 elseif (is_file($fileName))
1333 $li_js .= "\nscanned++;\n";
1334 if ($className == "dir")
1335 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx)\n\tdivx.src='".GOTMLS_images_path."checked.gif';";
1336 return $li_js."\n/*<!--*"."/";
1337 }
1338
1339 function GOTMLS_slash($dir = __FILE__) {
1340 if (substr($dir.' ', 1, 1) == ':' || substr($dir.' ', 0, 1) == "\\")
1341 return "\\";
1342 else
1343 return '/';
1344 }
1345
1346 function GOTMLS_trailingslashit($dir = "") {
1347 if (substr(' '.$dir, -1) != GOTMLS_slash($dir))
1348 $dir .= GOTMLS_slash($dir);
1349 return $dir;
1350 }
1351
1352 function GOTMLS_explode_dir($dir, $pre = '') {
1353 if (strlen($pre))
1354 $dir = GOTMLS_slash($dir).$pre.$dir;
1355 return explode(GOTMLS_slash($dir), $dir);
1356 }
1357
1358 function GOTMLS_html_tags($tags, $inner = array()) {
1359 $html = "";
1360 $gt = ">";
1361 if (!is_array($tags))
1362 return $html;
1363 foreach ($tags as $tag => $contents) {
1364 $html .= ($tag=="html"?"<!DOCTYPE html$gt":"")."<$tag".(isset($inner[$tag])?" ".$inner[$tag]:"").$gt;
1365 if (is_array($contents))
1366 $html .= GOTMLS_html_tags($contents, $inner);
1367 else
1368 $html .= $contents;
1369 $html .= "</$tag$gt";
1370 }
1371 return $html;
1372 }
1373
1374 function GOTMLS_write_quarantine($file, $className) {
1375 global $wpdb;
1376 $insert = array("post_author"=>GOTMLS_get_current_user_id(), "post_content"=>GOTMLS_encode($GLOBALS["GOTMLS"]["tmp"]["file_contents"]), "post_mime_type"=>md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"]), "ping_status"=>$className, "post_status"=>"private", "post_type"=>"GOTMLS_quarantine", "post_content_filtered"=>GOTMLS_encode($GLOBALS["GOTMLS"]["tmp"]["new_contents"]), "guid"=>GOTMLS_Version);//! comment_status post_password post_name to_ping post_parent menu_order";
1377 if (isset($file["ID"]) && is_numeric($file["ID"])) {
1378 $insert["post_modified"] = $file["post_modified"];
1379 $insert["post_modified_gmt"] = $file["post_modified_gmt"];
1380 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1381 $file = $file["post_type"].':'.$file["ID"].':"'.$file["post_title"].'"';
1382 } elseif (isset($file["option_id"]) && is_numeric($file["option_id"])) {
1383 $insert["post_modified"] = date("Y-m-d H:i:s");
1384 $insert["post_modified_gmt"] = date("Y-m-d H:i:s");
1385 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1386 $file = $wpdb->options.':'.$file["option_id"].':"'.$file["option_name"].'"';
1387 }
1388 $insert["post_title"] = $file;
1389 $insert["post_date"] = date("Y-m-d H:i:s");
1390 $insert["post_date_gmt"] = $insert["post_date"];
1391 if (is_file($file)) {
1392 if (@filemtime($file))
1393 $insert["post_modified"] = date("Y-m-d H:i:s", @filemtime($file));
1394 else
1395 $insert["post_modified"] = $insert["post_date"];
1396 if (@filectime($file))
1397 $insert["post_modified_gmt"] = date("Y-m-d H:i:s", @filectime($file));
1398 else
1399 $insert["post_modified_gmt"] = $insert["post_date"];
1400 if (!($insert["comment_count"] = @filesize($file)))
1401 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1402 }
1403 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1404 $insert["post_excerpt"] = GOTMLS_encode(@serialize($GLOBALS["GOTMLS"]["tmp"]["threats_found"]));
1405 $pinged = array();
1406 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $loc => $threat_name) {
1407 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][0]) && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1]) && strlen($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][0]) == 5 && strlen($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1]))
1408 $ping = $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1];
1409 else
1410 $ping = $threat_name;
1411 if (isset($pinged[$ping]))
1412 $pinged[$ping]++;
1413 else
1414 $pinged[$ping] = 1;
1415 }
1416 $insert["pinged"] = GOTMLS_encode(@serialize($pinged));
1417 }
1418 if ($return = $wpdb->insert($wpdb->posts, $insert))
1419 return $return;
1420 else
1421 die(print_r(array('return'=>($return===false)?"FALSE":$return, 'last_error'=>$wpdb->last_error, 'insert'=>$insert),1));
1422 }
1423
1424 function GOTMLS_get_current_user_id() {
1425 $return = 1;
1426 if (($current_user = @wp_get_current_user()) && (@$current_user->ID > 1))
1427 $return = $current_user->ID;
1428 return $return;
1429 }
1430
1431 function GOTMLS_update_status($status, $percent = -1) {
1432 if (!(isset($GLOBALS["GOTMLS"]["log"]["scan"]["start"]) && is_numeric($GLOBALS["GOTMLS"]["log"]["scan"]["start"])))
1433 $GLOBALS["GOTMLS"]["log"]["scan"]["start"] = time();
1434 $microtime = ceil(time()-$GLOBALS["GOTMLS"]["log"]["scan"]["start"]);
1435 GOTMLS_update_scan_log(array("scan" => array("microtime" => $microtime, "percent" => $percent)));
1436 return "/*-->*"."/\nupdate_status('".GOTMLS_strip4java($status)."', $microtime, $percent);\n/*<!--*"."/";
1437 }
1438
1439 function GOTMLS_flush($tag = "") {
1440 $output = "";
1441 if (($output = @ob_get_contents()) && strlen(trim($output)) > 18) {
1442 @ob_clean();
1443 if (!(isset($_GET["eli"]) && $_GET["eli"] == "debug"))
1444 $output = preg_replace('/\/\*<\!--\*\/.*?\/\*-->\*\//s', "", "$output/*-->*"."/");
1445 echo "$output\n//flushed(".strlen(trim($output)).")\n";
1446 if ($tag)
1447 echo "\n</$tag>\n";
1448 if (@ob_get_length())
1449 @ob_flush();
1450 if ($tag)
1451 echo "<$tag>\n";
1452 echo "/*<!--*"."/";
1453 }
1454 }
1455
1456 function GOTMLS_readdir($dir, $current_depth = 1) {
1457 global $GOTMLS_dirs_at_depth, $GOTMLS_dir_at_depth, $GOTMLS_total_percent;
1458 if ($current_depth) {
1459 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1460 $entries = GOTMLS_getfiles($dir);
1461 if (is_array($entries)) {
1462 echo GOTMLS_return_threat("dirs", "wait", $dir).GOTMLS_update_status(sprintf(__("Preparing %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1463 $files = array();
1464 $directories = array();
1465 foreach ($entries as $entry) {
1466 if (is_dir(GOTMLS_trailingslashit($dir).$entry))
1467 $directories[] = $entry;
1468 else
1469 $files[] = $entry;
1470 }
1471 if (isset($_GET["eli"]) && $_GET["eli"] == "trace" && count($files)) {
1472 $tracer_code = "(base64_decode('".base64_encode('if(isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] == "'.$_SERVER["REMOTE_ADDR"].'" && is_file("'.GOTMLS_local_images_path.'../safe-load/trace.php")) {include_once("'.GOTMLS_local_images_path.'../safe-load/trace.php");GOTMLS_debug_trace(__FILE__);}')."'));";
1473 foreach ($files as $file)
1474 if (GOTMLS_get_ext($file) == "php" && $filecontents = @file_get_contents(GOTMLS_trailingslashit($dir).$file))
1475 GOTMLS_file_put_contents(GOTMLS_trailingslashit($dir).$file, preg_replace('/^<\?php(?! eval)/is', '<?php eval'.$tracer_code, $filecontents));
1476 }
1477 if ($_REQUEST["scan_type"] == "Quick Scan") {
1478 $GOTMLS_dirs_at_depth[$current_depth] = count($directories);
1479 $GOTMLS_dir_at_depth[$current_depth] = 0;
1480 } else
1481 $GLOBALS["GOTMLS"]["tmp"]["scanfiles"][GOTMLS_encode($dir)] = GOTMLS_strip4java(str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir));
1482 foreach ($directories as $directory) {
1483 $path = GOTMLS_trailingslashit($dir).$directory;
1484 if (isset($_REQUEST["scan_depth"]) && is_numeric($_REQUEST["scan_depth"]) && ($_REQUEST["scan_depth"] != $current_depth) && !in_array($directory, $GLOBALS["GOTMLS"]["tmp"]["skip_dirs"])) {
1485 $current_depth++;
1486 $current_depth = GOTMLS_readdir($path, $current_depth);
1487 } else {
1488 echo GOTMLS_return_threat("skipdirs", "blocked", $path);
1489 $GOTMLS_dir_at_depth[$current_depth] = (isset($GOTMLS_dir_at_depth[$current_depth])?$GOTMLS_dir_at_depth[$current_depth]:0) + 1;
1490 }
1491 }
1492 if ($_REQUEST["scan_type"] == "Quick Scan") {
1493 $echo = "";
1494 echo GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1495 GOTMLS_flush("script");
1496 foreach ($files as $file)
1497 echo GOTMLS_check_file(GOTMLS_trailingslashit($dir).$file);
1498 echo GOTMLS_return_threat("dir", "checked", $dir);
1499 }
1500 } else
1501 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' readdir:'.($entries===false?'('.GOTMLS_fileperms($dir).')':$entries)));
1502 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1503 if ($current_depth-- && $_REQUEST["scan_type"] == "Quick Scan") {
1504 $GOTMLS_dir_at_depth[$current_depth] = (isset($GOTMLS_dir_at_depth[$current_depth])?$GOTMLS_dir_at_depth[$current_depth]:0) + 1;
1505 for ($GOTMLS_total_percent = 0, $depth = $current_depth; $depth >= 0; $depth--) {
1506 if (!isset($GOTMLS_dir_at_depth[$depth]))
1507 $GOTMLS_dir_at_depth[$depth] = 0;
1508 echo "\n//(($GOTMLS_total_percent / $GOTMLS_dirs_at_depth[$depth]) + ($GOTMLS_dir_at_depth[$depth] / $GOTMLS_dirs_at_depth[$depth])) = ";
1509 $GOTMLS_total_percent = (($GOTMLS_dirs_at_depth[$depth]?($GOTMLS_total_percent / $GOTMLS_dirs_at_depth[$depth]):0) + ($GOTMLS_dir_at_depth[$depth] / ($GOTMLS_dirs_at_depth[$depth]+1)));
1510 echo "$GOTMLS_total_percent\n";
1511 }
1512 $GOTMLS_total_percent = floor($GOTMLS_total_percent * 100);
1513 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1514 }
1515 GOTMLS_flush("script");
1516 }
1517 return $current_depth;
1518 }
1519
1520 function GOTMLS_sexagesimal($timestamp = 0) {
1521 if (!is_numeric($timestamp) && strlen($timestamp) == 5) {
1522 $delim = array("=", "-", "-", " ", ":");
1523 foreach (str_split($timestamp) as $bit)
1524 $timestamp .= array_shift($delim).substr("00".(ord($bit)>96?ord($bit)-61:(ord($bit)>64?ord($bit)-55:ord($bit)-48)), -2);
1525 return "20".substr($timestamp, -14);
1526 } else {
1527 $match = '/^(20)?([0-5][0-9])[\-: \/]*(0*[1-9]|1[0-2])[\-: \/]*(0*[1-9]|[12][0-9]|3[01])[\-: \/]*([0-5][0-9])[\-: \/]*([0-5][0-9])$/';
1528 if (preg_match($match, $timestamp))
1529 $date = preg_replace($match, "\\2-\\3-\\4-\\5-\\6", $timestamp);
1530 elseif ($timestamp && strtotime($timestamp))
1531 $date = date("y-m-d-H-i", strtotime($timestamp));
1532 else
1533 $date = date("y-m-d-H-i", time());
1534 foreach (explode("-", $date) as $bit)
1535 $date .= (intval($bit)>35?chr(ord("a")+intval($bit)-36):(intval($bit)>9?chr(ord("A")+intval($bit)-10):substr('0'.$bit, -1)));
1536 return substr($date, -5);
1537 }
1538 }
1539
1540 if (!function_exists('ur1encode')) { function ur1encode($url) {
1541 $return = "";
1542 foreach (str_split($url) as $char)
1543 $return .= '%'.substr('00'.strtoupper(dechex(ord($char))),-2);
1544 return $return;
1545 }}
1546
1547 function GOTMLS_strip4java($item, $htmlentities = false) {
1548 return preg_replace("/\\\\/", "\\\\\\\\", str_replace("'", "'+\"'\"+'", preg_replace('/\\+n|\\+r|\n|\r|\0/', "", ($htmlentities?$item:GOTMLS_htmlentities($item)))));
1549 }
1550
1551 function GOTMLS_error_link($errorTXT, $file = "", $class = "errors") {
1552 global $post, $wpdb;
1553 $encoded_file = GOTMLS_encode($file);
1554 $ids = explode(".", $file.'.');
1555 if (isset($post->post_title))
1556 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($post->post_title, ENT_NOQUOTES));
1557 elseif (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl1' && is_numeric($ids[0]))
1558 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($wpdb->get_var("SELECT CONCAT('option', `option_id`, ': ', `option_name`) FROM `$wpdb->options` WHERE `option_id` = ".$ids[0]), ENT_NOQUOTES));
1559 elseif (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl0' && is_numeric($ids[0]))
1560 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($wpdb->get_var("SELECT CONCAT(`post_type`, `ID`, ': ', `post_title`) FROM `$wpdb->posts` WHERE `ID` = ".$ids[0]), ENT_NOQUOTES));
1561 else
1562 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($file, ENT_NOQUOTES));
1563 if (count($ids) == 2 && is_numeric($ids[0])) {
1564 $encoded_file = $file;
1565 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.__("Examine Quarantined Content",'gotmls').' ... </div><div style="overflow: hidden; position: relative; height: 20px;"><div style="position: absolute; right: 0px; text-align: right; width: 9000px;">'.$js_file).'</div></div>\');" href="'.admin_url('admin-ajax.php?action=GOTMLS_scan&'.GOTMLS_set_nonce(__FUNCTION__."1263").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$file);
1566 } elseif ($file)
1567 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.__("Examine Current Content",'gotmls').' ... </div><div style="overflow: hidden; position: relative; height: 20px;"><div style="position: absolute; right: 0px; text-align: right; width: 9000px;">'.$js_file).'</div></div>\');" href="'.admin_url('admin-ajax.php?action=GOTMLS_scan&'.GOTMLS_set_nonce(__FUNCTION__."1265").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$encoded_file.preg_replace('/\&(GOTMLS_scan|mt|GOTMLS_mt|action)=/', '&last_\1=', isset($_SERVER["QUERY_STRING"])&&strlen($_SERVER["QUERY_STRING"])?"&".$_SERVER["QUERY_STRING"]:""));
1568 else
1569 $onclick = 'return false;';
1570 return "<a id=\"list_$encoded_file\" title=\"$errorTXT\" target=\"GOTMLS_iFrame\" onclick=\"$onclick\" class=\"GOTMLS_plugin $class\">";
1571 }
1572
1573 function GOTMLS_check_file($file) {
1574 $filesize = @filesize($file);
1575 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checking ".GOTMLS_strip4java($file)." ($filesize bytes)';\n/*<!--*"."/";
1576 if ($filesize===false)
1577 echo GOTMLS_return_threat("errors", "blocked", $file, GOTMLS_error_link(__("Failed to determine file size!",'gotmls'), $file));
1578 elseif (($filesize==0) || ($filesize>((isset($_GET["eli"])&&is_numeric($_GET["eli"]))?$_GET["eli"]:1234567)))
1579 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file size!",'gotmls')." ($filesize bytes)", $file, "potential"));
1580 elseif (in_array(GOTMLS_get_ext($file), $GLOBALS["GOTMLS"]["tmp"]["skip_ext"]) && !(preg_match('/(shim|social[0-9]*)\.png$/i', $file)))
1581 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file extention!",'gotmls'), $file, "potential"));
1582 else {
1583 try {
1584 echo @GOTMLS_scanfile($file);
1585 echo "//debug_fix:".$GLOBALS["GOTMLS"]["tmp"]["debug_fix"];
1586 } catch (Exception $e) {
1587 die("//Exception:".GOTMLS_strip4java($e));
1588 }
1589 }
1590 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checked ".GOTMLS_strip4java($file)."';\n/*<!--*"."/";
1591 }
1592
1593 function GOTMLS_read_error($path) {
1594 global $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
1595 $error = error_get_last();
1596 if (!file_exists($path))
1597 return " (Path not found)";
1598 if (!is_readable($path) && isset($_GET["eli"]))
1599 $return = (@chmod($path, (is_dir($path)?$GOTMLS_chmod_dir:$GOTMLS_chmod_file))?"Fixed permissions":"error: ".preg_replace('/[\r\n]/', ' ', print_r($error,1)));
1600 else
1601 $return = (is_array($error) && isset($error["message"])?preg_replace('/[\r\n]/', ' ', print_r($error["message"],1)):"readable?");
1602 return " [".GOTMLS_fileperms($path)."] ( ".filesize($path)." $return)";
1603 }
1604
1605 function GOTMLS_scandir($dir) {
1606 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", GOTMLS_htmlspecialchars($dir))));
1607 GOTMLS_flush();
1608 $li_js = "/*-->*"."/\nscanNextDir(-1);\n/*<!--*"."/";
1609 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]) && $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]))
1610 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link("Directory Scan Depth set to 0, no files will be scanned!"));
1611 elseif (isset($_GET["GOTMLS_skip_dir"]) && $dir == GOTMLS_decode($_GET["GOTMLS_skip_dir"])) {
1612 if (isset($_GET["GOTMLS_only_file"]) && strlen($_GET["GOTMLS_only_file"]))
1613 echo GOTMLS_return_threat("errors", "blocked", GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"]), GOTMLS_error_link("Failed to read this file!".GOTMLS_read_error(GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"])), GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"])));
1614 else
1615 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(__("Failed to read directory!",'gotmls')).GOTMLS_read_error($dir));
1616 } else {
1617 $files = GOTMLS_getfiles($dir);
1618 if (is_array($files)) {
1619 if (isset($_GET["GOTMLS_only_file"])) {
1620 if (strlen($_GET["GOTMLS_only_file"])) {
1621 $path = GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"]);
1622 if (is_file($path)) {
1623 GOTMLS_check_file($path);
1624 echo GOTMLS_return_threat("dir", "checked", $path);
1625 }
1626 } else {
1627 foreach ($files as $file) {
1628 $path = GOTMLS_trailingslashit($dir).$file;
1629 if (is_file($path)) {
1630 $file_ext = GOTMLS_get_ext($file);
1631 $filesize = @filesize($path);
1632 if ((in_array($file_ext, $GLOBALS["GOTMLS"]["tmp"]["skip_ext"]) && !(preg_match('/social[0-9]*\.png$/i', $file))) || ($filesize==0) || ($filesize>((isset($_GET["eli"])&&is_numeric($_GET["eli"]))?$_GET["eli"]:1234567)))
1633 echo GOTMLS_return_threat("skipped", "blocked", $path, GOTMLS_error_link(sprintf(__('Skipped because of file size (%1$s bytes) or file extention (%2$s)!','gotmls'), $filesize, $file_ext), $file, "potential"));
1634 else
1635 echo "/*-->*"."/\nscanfilesArKeys.push('".GOTMLS_encode($dir)."&GOTMLS_only_file=".GOTMLS_encode($file)."');\nscanfilesArNames.push('Re-Checking ".GOTMLS_strip4java($path)."');\n/*<!--*"."/".GOTMLS_return_threat("dirs", "wait", $path);
1636 } elseif (is_dir($path)) {
1637 echo "/*-->*"."/\n//sub-directory $path;\n/*<!--*"."/";
1638 }
1639 }
1640 echo GOTMLS_return_threat("dir", "question", $dir);
1641 }
1642 } else {
1643 foreach ($files as $file) {
1644 $path = GOTMLS_trailingslashit($dir).$file;
1645 if (is_file($path)) {
1646 if (isset($_GET["GOTMLS_skip_file"]) && is_array($_GET["GOTMLS_skip_file"]) && in_array($path, $_GET["GOTMLS_skip_file"])) {
1647 $li_js .= "/*-->*"."/\n//skipped $path;\n/*<!--*"."/";
1648 if ($path == $_GET["GOTMLS_skip_file"][count($_GET["GOTMLS_skip_file"])-1])
1649 echo GOTMLS_return_threat("errors", "blocked", $path, GOTMLS_error_link(__("Failed to read file!",'gotmls'), $path));
1650 } else {
1651 GOTMLS_check_file($path);
1652 }
1653 } elseif (is_dir($path)) {
1654 $li_js .= "/*-->*"."/\n//sub-directory $path;\n/*<!--*"."/";
1655 }
1656 }
1657 echo GOTMLS_return_threat("dir", "checked", $dir);
1658 }
1659 } else
1660 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' scandir:'.($files===false?' (FALSE)':$files)));
1661 }
1662 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)));
1663 GOTMLS_update_scan_log(array("scan" => array("finish" => time())));
1664 return $li_js;
1665 }
1666
1667 function GOTMLS_reset_settings($item, $key) {
1668 $key_parts = explode("_", $key."_");
1669 if (strlen($key_parts[0]) != 4 && $key_parts[0] != "exclude")
1670 unset($GLOBALS["GOTMLS"]["tmp"]["settings_array"][$key]);
1671 }
1672
1673 function GOTMLS_file_put_contents($file, $content) {
1674 global $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
1675 $chmoded_file = false;
1676 $chmoded_dir = false;
1677 if ((is_dir(dirname($file)) || @mkdir(dirname($file), $GOTMLS_chmod_dir, true)) && !is_writable(dirname($file)) && ($GOTMLS_chmod_dir = @fileperms(dirname($file))))
1678 $chmoded_dir = @chmod(dirname($file), 0777);
1679 if (is_file($file) && !is_writable($file) && ($GOTMLS_chmod_file = @fileperms($file)))
1680 $chmoded_file = @chmod($file, 0666);
1681 if (function_exists("file_put_contents"))
1682 $return = @file_put_contents($file, $content);
1683 elseif ($fp = fopen($file, 'w')) {
1684 fwrite($fp, $content);
1685 fclose($fp);
1686 $return = true;
1687 } else
1688 $return = false;
1689 if ($chmoded_file)
1690 @chmod($file, $GOTMLS_chmod_file);
1691 if ($chmoded_dir)
1692 @chmod(dirname($file), $GOTMLS_chmod_dir);
1693 return $return;
1694 }
1695
1696 function GOTMLS_scan_log() {
1697 global $wpdb;
1698 if ($rs = $wpdb->get_row("SELECT substring_index(option_name, '/', -1) AS `mt`, option_name, option_value FROM `$wpdb->options` where option_name like 'GOTMLS_scan_log/%' ORDER BY mt DESC LIMIT 1", ARRAY_A))
1699 $GOTMLS_scan_log = (isset($rs["option_name"])?get_option($rs["option_name"], array()):array());
1700 $units = array("seconds"=>60,"minutes"=>60,"hours"=>24,"days"=>365,"years"=>10);
1701 if (isset($GOTMLS_scan_log["scan"]["start"]) && is_numeric($GOTMLS_scan_log["scan"]["start"])) {
1702 $time = (time() - $GOTMLS_scan_log["scan"]["start"]);
1703 $ukeys = array_keys($units);
1704 for ($unit = $ukeys[0], $key=0; (isset($units[$ukeys[$key]]) && $key < (count($ukeys) - 1) && $time >= $units[$ukeys[$key]]); $unit = $ukeys[++$key])
1705 $time = floor($time/$units[$ukeys[$key]]);
1706 if (1 == $time)
1707 $unit = substr($unit, 0, -1);
1708 $LastScan = "started $time $unit ago";
1709 if (isset($GOTMLS_scan_log["scan"]["finish"]) && is_numeric($GOTMLS_scan_log["scan"]["finish"]) && ($GOTMLS_scan_log["scan"]["finish"] >= $GOTMLS_scan_log["scan"]["start"])) {
1710 $time = ($GOTMLS_scan_log["scan"]["finish"] - $GOTMLS_scan_log["scan"]["start"]);
1711 for ($unit = $ukeys[0], $key=0; (isset($units[$ukeys[$key]]) && $key < (count($ukeys) - 1) && $time >= $units[$ukeys[$key]]); $unit = $ukeys[++$key])
1712 $time = floor($time/$units[$ukeys[$key]]);
1713 if (1 == $time)
1714 $unit = substr($unit, 0, -1);
1715 if ($time)
1716 $LastScan .= " and ran for $time $unit";
1717 else
1718 $LastScan = str_replace("started", "ran", $LastScan);
1719 } else
1720 $LastScan .= " and has not finish";
1721 if (!isset($_GET['Scanlog']))
1722 $LastScan .= '<a style="float: right;" href="'.admin_url('admin.php?page=GOTMLS_View_Quarantine&Scanlog').'">'.GOTMLS_View_Scan_Log_LANGUAGE.'</a><br style="clear: right;">';
1723 } else
1724 $LastScan = "never started ";
1725 return "Last ".(isset($GOTMLS_scan_log["scan"]["type"])?$GOTMLS_scan_log["scan"]["type"]:"Scan")." $LastScan";
1726 }
1727
1728 function GOTMLS_get_URL($URL) {
1729 $response = "";
1730 $GLOBALS["GOTMLS"]["get_URL"] = get_option('GOTMLS_get_URL_array', array());
1731 $min = round($GLOBALS["GOTMLS"]["tmp"]["mt"]/60);
1732 if (is_array($GLOBALS["GOTMLS"]["get_URL"])) {
1733 foreach ($GLOBALS["GOTMLS"]["get_URL"] as $URI => $property)
1734 if (!(isset($property["time"]) && is_numeric($property["time"]) && ($property["time"] + 60) > $min))
1735 unset($GLOBALS["GOTMLS"]["get_URL"]["$URI"]);
1736 } else
1737 $GLOBALS["GOTMLS"]["get_URL"] = array();
1738 $URI = md5(preg_replace('/GOTMLS_mt[\[\]]*=[0-9a-f]*/i', "", $URL));
1739 if (isset($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"]) && strlen($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"])) {
1740 $method = "cached";
1741 $response = $GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"];
1742 } else {
1743 $GLOBALS["GOTMLS"]["get_URL"]["$URI"] = array("time" => $min);
1744 if (function_exists($method = "wp_remote_get")) {
1745 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = wp_remote_get($URL, array("sslverify" => false));
1746 if (200 == wp_remote_retrieve_response_code($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]))
1747 $response = wp_remote_retrieve_body($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]);
1748 }
1749 if (strlen($response) == 0 && function_exists($method = "curl_exec")) {
1750 $curl_hndl = curl_init();
1751 curl_setopt($curl_hndl, CURLOPT_URL, $URL);
1752 curl_setopt($curl_hndl, CURLOPT_TIMEOUT, 30);
1753 if (isset($_SERVER['HTTP_REFERER']))
1754 $SERVER_HTTP_REFERER = $_SERVER['HTTP_REFERER'];
1755 elseif (isset($_SERVER['HTTP_HOST']))
1756 $SERVER_HTTP_REFERER = 'HOST://'.$_SERVER['HTTP_HOST'];
1757 elseif (isset($_SERVER['SERVER_NAME']))
1758 $SERVER_HTTP_REFERER = 'NAME://'.$_SERVER['SERVER_NAME'];
1759 elseif (isset($_SERVER['SERVER_ADDR']))
1760 $SERVER_HTTP_REFERER = 'ADDR://'.$_SERVER['SERVER_ADDR'];
1761 else
1762 $SERVER_HTTP_REFERER = 'NULL://not.anything.com';
1763 curl_setopt($curl_hndl, CURLOPT_REFERER, $SERVER_HTTP_REFERER);
1764 if (isset($_SERVER['HTTP_USER_AGENT']))
1765 curl_setopt($curl_hndl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
1766 curl_setopt($curl_hndl, CURLOPT_HEADER, 0);
1767 curl_setopt($curl_hndl, CURLOPT_RETURNTRANSFER, TRUE);
1768 if (!($response = curl_exec($curl_hndl)))
1769 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = curl_error($curl_hndl);
1770 curl_close($curl_hndl);
1771 }
1772 if (strlen($response) == 0 && function_exists($method = "file_get_contents")) {
1773 try {
1774 $response = @file_get_contents($URL).'';
1775 } catch(Exception $e) {
1776 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = $e->getTrace();
1777 }
1778 }
1779 $GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"] = $response;
1780 update_option('GOTMLS_get_URL_array', $GLOBALS["GOTMLS"]["get_URL"], 'no');
1781 }
1782 if (isset($_GET["GOTMLS_debug"]) && (strlen($response) == 0 || $_GET["GOTMLS_debug"] == "GOTMLS_get_URL"))
1783 print_r(array("$method $URI:".strlen($response)=>htmlspecialchars($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["time"]." ~ $min: ".count($GLOBALS["GOTMLS"]["get_URL"]))));
1784 return $response;
1785 }
1786