PluginProbe ʕ •ᴥ•ʔ
Anti-Malware Security and Brute-Force Firewall / 4.23.81
Anti-Malware Security and Brute-Force Firewall v4.23.81
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 GOTMLS-Loading.gif 1 year ago blocked.gif 14 years ago btn_donateCC_WIDE.gif 13 years ago checked.gif 14 years ago index.php 1 year ago question.gif 13 years ago threat.gif 13 years ago wait.gif 14 years ago
index.php
2005 lines
1 <?php
2 /**
3 * GOTMLS Plugin Global Variables and Functions
4 * @package GOTMLS
5 * @since 4.23.81
6 */
7
8 define("GOTMLS_plugin_path", dirname(dirname(__FILE__))."/");
9
10 if (!function_exists("__")) {
11 function __($text, $domain = "gotmls") {
12 return $text;
13 }}
14
15 require_once(GOTMLS_plugin_path."safe-load/trace.php");
16
17 GOTMLS_define("GOTMLS_local_images_path", substr(__FILE__, 0, GOTMLS_strlen(__FILE__) - GOTMLS_strlen(basename(__FILE__))));
18
19 if (!defined("ABSPATH")) {
20 define("ABSPATH", dirname(dirname(__FILE__)).'/safe-load/');
21 $root_path = dirname(ABSPATH);
22 while (GOTMLS_strlen($root_path) > 1 && !is_file($root_path."/wp-config.php"))
23 $root_path = dirname($root_path);
24 if (is_file($root_path."/wp-config.php"))
25 include_once($root_path."/wp-config.php");
26 else
27 die("No wp-config!");
28 }
29
30 $bad = array("eval", "preg_replace", "auth_pass");
31 $GLOBALS["GOTMLS"] = array(
32 "MT" => microtime(true),
33 "tmp"=>array("debug_fix"=>"", "HeadersError"=>"", "onLoad"=>"", "file_contents"=>"", "new_contents"=>"", "threats_found"=>array(),
34 "base_page" => "GOTMLS-settings",
35 "pluginTitle" => "Anti-Malware",
36 "default_encodings" => array('UTF-8', 'ISO-8859-1', 'windows-1252'),
37 "skip_dirs" => array(".", ".."), "scanfiles" => array(), "nonce"=>array(),
38 "mt" => ((isset($_REQUEST["mt"])&&GOTMLS_strlen($_REQUEST["mt"])==32)?$_REQUEST["mt"]:md5(microtime(true))),
39 "threat_files" => array("htaccess"=>".htaccess","timthumb"=>"thumb.php"),
40 "apache" => array(),
41 "skip_ext"=>array("png", "jpg", "jpeg", "gif", "bmp", "tif", "tiff", "psd", "svg", "webp", "doc", "docx", "otf", "ttf", "fla", "flv", "mov", "mp3", "pdf", "css", "pot", "po", "mo", "so", "exe", "zip", "7z", "gz", "rar"),
42 "execution_time" => 60,
43 "default" => array("msg_position" => array("80px", "40px", "400px", "600px")),
44 "Definition" => array("Default" => "CCIGG"),
45 "definitions_array" => array(
46 "potential" => array(
47 $bad[0] => array("CCIGG", "/[^a-z_\\/'\"]".$bad[0]."\\(.+\\)+\\s*;/i"),
48 $bad[1]." /e" => array("CCIGG", "/".$bad[1]."[\\s*\\(]+(['\"])([\\!\\/\\#\\|\\@\\%\\^\\*\\~]).+?\\2[imsx]*e[imsx]*\\1\\s*,[^,]+,[^\\)]+[\\);\\s]+/i"),
49 $bad[2] => array("CCIGG", "/\\\$".$bad[2]."\\s*=.+;/i"),
50 "function add_action wp_enqueue_script json2" => array("CCIGG", "/json2\\.min\\.js/i"),
51 "Tagged Code" => array("CCIGG", "/\\#(\\w+)\\#.+?\\#\\/\\1\\#/is"),
52 "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")
53 )
54 )
55 )
56 );
57 if (isset($_SERVER["HTTP_HOST"]))
58 $SERVER_HTTP = 'HOST://'.GOTMLS_safe_domain($_SERVER["HTTP_HOST"]);
59 elseif (isset($_SERVER["SERVER_NAME"]))
60 $SERVER_HTTP = 'NAME://'.GOTMLS_safe_domain($_SERVER["SERVER_NAME"]);
61 elseif (isset($_SERVER["SERVER_ADDR"]))
62 $SERVER_HTTP = 'ADDR://'.GOTMLS_safe_ip($_SERVER["SERVER_ADDR"]);
63 else
64 $SERVER_HTTP = "NULL://not.anything.com";
65 if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"])
66 $SERVER_HTTP .= ":".GOTMLS_safe_ip($_SERVER["SERVER_PORT"]);
67 $SERVER_parts = explode(":", $SERVER_HTTP.":");
68 if ((isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] == 1)) || (count($SERVER_parts) > 2 && $SERVER_parts[2] == "443"))
69 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "https:";
70 else
71 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "http:";
72 GOTMLS_define("GOTMLS_script_URI", preg_replace('/\&(last_)?mt=[0-9\.a-f]+/i', '', str_replace('&amp;', '&', GOTMLS_htmlspecialchars($_SERVER["REQUEST_URI"], ENT_QUOTES))).'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"]);
73 GOTMLS_define("GOTMLS_plugin_home", "https://gotmls.net/");
74 if (function_exists("plugins_url"))
75 GOTMLS_define("GOTMLS_images_path", plugins_url('/', __FILE__));
76 elseif (function_exists("plugin_dir_url"))
77 GOTMLS_define("GOTMLS_images_path", plugin_dir_url(__FILE__));
78 elseif (isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"]) && GOTMLS_strlen($_SERVER["DOCUMENT_ROOT"]) < __FILE__ && substr(__FILE__, 0, GOTMLS_strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
79 GOTMLS_define("GOTMLS_images_path", substr(dirname(__FILE__), GOTMLS_strlen($_SERVER["DOCUMENT_ROOT"])).'/');
80 elseif (isset($_SERVER["SCRIPT_FILENAME"]) && isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"]) && GOTMLS_strlen($_SERVER["DOCUMENT_ROOT"]) < GOTMLS_strlen($_SERVER["SCRIPT_FILENAME"]) && substr($_SERVER["SCRIPT_FILENAME"], 0, GOTMLS_strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
81 GOTMLS_define("GOTMLS_images_path", substr(GOTMLS_safe_url(dirname($_SERVER["SCRIPT_FILENAME"])), GOTMLS_strlen($_SERVER["DOCUMENT_ROOT"])).'/');
82 else
83 GOTMLS_define("GOTMLS_images_path", "/wp-content/plugins/gotmls/images/");
84
85 function GOTMLS_user_can() {
86 if (is_multisite())
87 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] = "manage_network";
88 elseif (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"]) || $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] == "manage_network")
89 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] = "activate_plugins";
90 if (current_user_can($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"]))
91 return true;
92 else
93 return false;
94 }
95
96 function GOTMLS_update_option($index, $value = array(), $auto = true) {
97 return update_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($value)), $auto);
98 }
99
100 function GOTMLS_get_option($index, $value = array()) {
101 if (is_array($tmp = get_option('GOTMLS_'.$index.'_array', array())) && count($tmp)) {
102 GOTMLS_update_option($index, $tmp);
103 delete_option('GOTMLS_'.$index.'_array');
104 } else
105 $tmp = $value;
106 return GOTMLS_uckserialize(GOTMLS_decode(get_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($tmp)))));
107 }
108
109 $GLOBALS["GOTMLS"]["tmp"]["nonce"] = GOTMLS_get_option('nonce', array());
110 $GLOBALS["GOTMLS"]["tmp"]["settings_array"] = get_option('GOTMLS_settings_array', array());
111 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"] = GOTMLS_get_option('definitions', $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]);
112 GOTMLS_define("GOTMLS_siteurl", rtrim(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])."/"), '\\/'));
113 GOTMLS_load_scanlog($GLOBALS["GOTMLS"]["tmp"]["mt"]);
114 if (!(isset($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]) && is_array($GLOBALS["GOTMLS"]["scan"]["log"]["settings"])))
115 $GLOBALS["GOTMLS"]["scan"]["log"]["settings"] = $GLOBALS["GOTMLS"]["tmp"]["settings_array"];
116 GOTMLS_define("GOTMLS_installation_key", md5(GOTMLS_siteurl));
117 GOTMLS_define("GOTMLS_update_home", "//updates.gotmls.net/".GOTMLS_installation_key."/");
118
119 function GOTMLS_get_corefile_URL($path, $hash) {
120 if (strpos($URL = GOTMLS_get_version("URL"), '&cp='))
121 //$hash != md5($contents)."O".GOTMLS_strlen($contents)
122 return 'http:'.GOTMLS_update_home.'cp_core.php?'.$URL.'&f='.GOTMLS_encode($path)."&h=$hash&ts=".gmdate("YmdHis").'&d='.rawurlencode(GOTMLS_siteurl);
123 else
124 return "http://core.svn.wordpress.org/tags/".GOTMLS_wp_version."$path";
125 }
126
127 function GOTMLS_Invalid_Nonce($pre = "//Error: ") {
128 return sprintf(__("%s Invalid or expired Nonce Token! %s Refresh and try again?",'gotmls'), $pre, (isset($_REQUEST["GOTMLS_mt"])?(" (".GOTMLS_htmlspecialchars($_REQUEST["GOTMLS_mt"]).((GOTMLS_strlen($_REQUEST["GOTMLS_mt"]) == 32)?(isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]["hour"])&&isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]["user"])?(substr($pre, 0, 7)=="//DEBUG"?GOTMLS_htmlspecialchars(", U:".$GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]["user"].", H:".$GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]["hour"]."!) "):" !UH!) "):" !found!) "):" !len[".GOTMLS_strlen($_REQUEST["GOTMLS_mt"])."]!) ")):" (GOTMLS_mt !set!) "));
129 }
130
131 function GOTMLS_set_nonce($context = "NULL", $uid = 0) {
132 $hour = (int) round(round($GLOBALS["GOTMLS"]["MT"]/60)/60);
133 if (!$uid)
134 $uid = GOTMLS_get_current_user_id(GOTMLS_REMOTEADDR);
135 $transient_name = md5(substr(number_format(microtime(true), 9, '-', '/'), 6).GOTMLS_installation_key.GOTMLS_plugin_path.$context.$uid);
136 if (isset($GLOBALS["GOTMLS"]["tmp"]["nonce"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["nonce"])) {
137 foreach ($GLOBALS["GOTMLS"]["tmp"]["nonce"] as $nonce_key => $token) {
138 if ((!(is_array($token) && isset($token["hour"]) && is_numeric($token["hour"]))) || (($token["hour"] > $hour) || (($token["hour"] + 24) < $hour)))
139 unset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$nonce_key]);
140 elseif (is_array($token) && isset($token["hour"]) && isset($token["user"]) && isset($token["context"]) && ($token["hour"] == $hour) && ($token["user"] == $uid) && ($token["context"] == $context))
141 $transient_name = $nonce_key;
142 }
143 }
144 if (!isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name])) {
145 $GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name] = array("hour" => $hour, "user" => $uid, "context" => $context);
146 if (!GOTMLS_update_option('nonce', $GLOBALS["GOTMLS"]["tmp"]["nonce"], false))
147 return (GOTMLS_sanitize($context)."=DB-err:".rawurlencode(preg_replace('/[\r\n]+/', " ", print_r($GLOBALS["GOTMLS"]["tmp"]["nonce"],1).$wpdb->last_error)));
148 }
149 return 'GOTMLS_mt='.rawurlencode($transient_name);
150 }
151
152 function GOTMLS_get_nonce($context = "", $uid = 0) {
153 $return = false;
154 if (isset($_REQUEST["GOTMLS_mt"])) {
155 if (!$uid)
156 $uid = GOTMLS_get_current_user_id(GOTMLS_REMOTEADDR);
157 if (isset($_POST["GOTMLS_mt"]) && (GOTMLS_strlen($_POST["GOTMLS_mt"]) == 32) && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_POST["GOTMLS_mt"]]))
158 $token = $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_POST["GOTMLS_mt"]];
159 elseif (isset($_GET["GOTMLS_mt"]) && (GOTMLS_strlen($_GET["GOTMLS_mt"]) == 32) && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_GET["GOTMLS_mt"]]))
160 $token = $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_GET["GOTMLS_mt"]];
161 if (isset($token) && is_array($token) && isset($token["hour"]) && isset($token["user"]) && isset($token["context"])) {
162 if (GOTMLS_strlen($context) && ($context != $token["context"]))
163 $return = null;
164 elseif ($uid == $token["user"] || (is_numeric($uid) && !is_numeric(GOTMLS_REMOTEADDR) && (GOTMLS_REMOTEADDR == $token["user"])))
165 $return = (INT) $token["hour"];
166 else
167 $return = 0;
168 } else
169 $return = "";
170 }
171 return $return;
172 }
173
174 function GOTMLS_fileperms($file) {
175 if ($prm = @fileperms($file)) {
176 if (($prm & 0xC000) == 0xC000)
177 $ret = "s";
178 elseif (($prm & 0xA000) == 0xA000)
179 $ret = "l";
180 elseif (($prm & 0x8000) == 0x8000)
181 $ret = "-";
182 elseif (($prm & 0x6000) == 0x6000)
183 $ret = "b";
184 elseif (($prm & 0x4000) == 0x4000)
185 $ret = "d";
186 elseif (($prm & 0x2000) == 0x2000)
187 $ret = "c";
188 elseif (($prm & 0x1000) == 0x1000)
189 $ret = "p";
190 else
191 $ret = "u";
192 $ret .= (($prm & 0x0100)?"r":"-").(($prm & 0x0080)?"w":"-");
193 $ret .= (($prm & 0x0040)?(($prm & 0x0800)?"s":"x" ):(($prm & 0x0800)?"S":"-"));
194 $ret .= (($prm & 0x0020)?"r":"-").(($prm & 0x0010)?"w":"-");
195 $ret .= (($prm & 0x0008)?(($prm & 0x0400)?"s":"x" ):(($prm & 0x0400)?"S":"-"));
196 $ret .= (($prm & 0x0004)?"r":"-").(($prm & 0x0002)?"w":"-");
197 $ret .= (($prm & 0x0001)?(($prm & 0x0200)?"t":"x" ):(($prm & 0x0200)?"T":"-"));
198 return $ret;
199 } else
200 return "stat failed!";
201 }
202
203 function GOTMLS_file_details($file) {
204 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(GOTMLS_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)).(function_exists("getmyuid")&&function_exists("getmygid")?' (you are: '.getmyuid().'/'.getmygid():'(getmyuid does not exist').')<br />modified:'.gmdate(" Y-m-d H:i:s ", filemtime(realpath($file))).'<br />changed:'.gmdate(" Y-m-d H:i:s ", filectime(realpath($file))).'</div>';
205 }
206
207 function GOTMLS_esc_url($url) {
208 if ("" === trim($url))
209 return "";
210 $original_url = $url;
211 $url = str_replace(' ', '%20', ltrim($url));
212 $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url);
213 $url = wp_kses_normalize_entities($url);
214 $url = str_replace('&amp;', '&#038;', $url);
215 $url = str_replace("'", '&#039;', $url);
216 if ((false !== strpos($url, '[')) || (false !== strpos($url, ']'))) {
217 $end_dirty = preg_replace('/^([fhtps]+\:)?\/\/([^\@]+\@)*[^\/]++/i', '', $url);
218 $end_clean = str_replace(array('[', ']'), array('%5B', '%5D'), $end_dirty);
219 $url = str_replace($end_dirty, $end_clean, $url);
220 }
221 return $url;
222 }
223
224 function GOTMLS_admin_url($action, $url = '') {
225 $return = admin_url("admin-ajax.php?action=$action");
226 foreach (array('eli', 'oversize', 'GOTMLS_debug') as $pass_on)
227 if (isset($_GET["$pass_on"]))
228 $return .= "&$pass_on=".GOTMLS_esc_url($_GET["$pass_on"]);
229 return ("$return&$url");
230 }
231
232 function GOTMLS_dashicon_button($title, $dashicon = "editor-help", $style = 'text-decoration: none;', $contents = "", $href = "javascript:void(0);") {
233 $gt = ">"; // This local variable never changes
234 $lt = "<"; // This local variable never changes
235 return $lt.'a href="'.$href.'" title="'.$title.'" style="'.$style.'"'.$gt.$lt."span class='dashicons dashicons-$dashicon'$gt$lt/span$gt $contents$lt/a$gt\n";
236 }
237
238 function GOTMLS_close_button($box_id, $margin = '6px', $title = "Close") {
239 return GOTMLS_dashicon_button($title, 'dismiss', "float: right; color: #F00; overflow: hidden; width: 20px; height: 20px; text-decoration: none; margin: $margin", "X", 'javascript:void(0);" onclick="showhide(\''.$box_id.'\');');
240 }
241
242 function GOTMLS_get_styles($pre_style = "") {
243 $head_nonce = GOTMLS_set_nonce(__FUNCTION__."255");
244 $gt = ">"; // This local variable never changes
245 $lt = "<"; // This local variable never changes
246 if (!GOTMLS_strlen(trim("$pre_style")))
247 $pre_style = $lt."style$gt";
248 return $pre_style.'
249 span.GOTMLS_date {float: right; width: 130px; white-space: nowrap;}
250 .GOTMLS_page {float: left; border-radius: 10px; padding: 0 5px;}
251 .GOTMLS_quarantine_item {margin: 4px 12px;}
252 .rounded-corners {margin: 10px; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #000;}
253 .shadowed-box {box-shadow: -3px 3px 3px #666; -moz-box-shadow: -3px 3px 3px #666; -webkit-box-shadow: -3px 3px 3px #666;}
254 .sidebar-box {background-color: #CCC;}
255 iframe {border: 0;}
256 .GOTMLS-scanlog li a {display: none;}
257 .GOTMLS-scanlog li:hover a {display: block;}
258 .GOTMLS-sidebar-links {list-style: none;}
259 .GOTMLS-sidebar-links li img {margin: 3px; height: 16px; vertical-align: middle;}
260 .GOTMLS-sidebar-links li {margin-bottom: 0 !important;}
261 .popup-box {background-color: #FFC; display: none; position: absolute; left: 0px; z-index: 10;}
262 .shadowed-text {text-shadow: #00F -1px 1px 1px;}
263 .sub-option {float: left; margin: 3px 5px;}
264 .inside {margin: 10px; position: relative;}
265 .GOTMLS_li, .GOTMLS_plugin li {list-style: none;}
266 .GOTMLS_plugin {margin: 5px; background: #cfc; border: 1px solid #0C0; padding: 0 5px; border-radius: 3px;}
267 .GOTMLS_plugin.known, .GOTMLS_plugin.db_scan, .GOTMLS_plugin.htaccess, .GOTMLS_plugin.timthumb, .GOTMLS_plugin.errors {background: #f99; border: 1px solid #f00;}
268 .GOTMLS_plugin.potential, .GOTMLS_plugin.wp_core, .GOTMLS_plugin.skipdirs, .GOTMLS_plugin.skipped {background: #ffc; border: 1px solid #fc6;}
269 .GOTMLS ul li {margin-left: 12px;}
270 .GOTMLS h2 {margin: 0 0 10px;}
271 .postbox {margin-right: 10px; line-height: 1.4; font-size: 13px;}
272 #pastDonations li {list-style: none;}
273 #quarantine_buttons {margin: 0px; padding: 0px;}
274 #quarantine_buttons input.button-primary {margin-right: 20px;}
275 #reclean_buttons {
276 color: #a00;
277 min-height: 32px;
278 border-top: solid 2px black;
279 padding-top: 10px;
280 }
281 #reclean_buttons input.button-primary {float: right;}
282 #delete_button {
283 background-color: #C33;
284 color: #FFF;
285 background-image: linear-gradient(to bottom, #C22, #933);
286 border-color: #933 #933 #900;
287 box-shadow: 0 1px 0 rgba(230, 120, 120, 0.5) inset;
288 text-decoration: none; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
289 margin-top: 10px;
290 }
291 #main-page-title {
292 background: url("https://secure.gravatar.com/avatar/5feb789dd3a292d563fea3b885f786d6?s=64") no-repeat scroll 0 0 transparent;
293 height: 64px;
294 line-height: 58px;
295 margin: 10px 0 0 0;
296 max-width: 600px;
297 padding: 0 110px 0 84px;
298 }
299 #main-page-title h1 {
300 background: url("https://secure.gravatar.com/avatar/8151cac22b3fc543d099241fd573d176?s=64") no-repeat scroll top right transparent;
301 height: 64px;
302 line-height: 32px;
303 margin: 0;
304 padding: 0 84px 0 0;
305 display: table-cell;
306 text-align: center;
307 vertical-align: middle;
308 }
309 '."$lt/style$gt\n$lt".'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;"'.$gt.$lt.'table style="width: 100%; height: 100%;" cellspacing="0" cellpadding="0"'.$gt.$lt.'tr'.$gt.$lt.'td style="border-bottom: 1px solid #EEE; height: 32px;" colspan="2"'.$gt.GOTMLS_close_button("div_file").$lt.'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;"'.$gt.GOTMLS_Loading_LANGUAGE."$lt/h3$gt$lt/td$gt$lt/tr$gt$lt".'tr'.$gt.$lt.'td colspan="2" style="height: 100%"'.$gt.$lt.'div style="width: 100%; height: 100%; position: relative; padding: 0; margin: 0; background-color: #fff;" class="inside"'.$gt.$lt.'center'.$gt.$lt.'img src="'.GOTMLS_images_path.'GOTMLS-Loading.gif" id="got-loading-gif" style="max-height: 280px;" alt="..."'.$gt.$lt.'br /'.$gt.GOTMLS_Loading_LANGUAGE.$lt.'br /'.$gt.$lt.'div id="gotmls_too_long" style="display: none;"'.$gt.__("If this is taking too long:",'gotmls').$lt.'br /'.$gt.$lt.'input type="button" onclick="showhide(\'div_file\');if (formx = document.getElementById(\'GOTMLS_Form_clean\')) formx.method = \'get\';" value="'.__("Go Back and Try Again",'gotmls').'" style="margin: 0 5px;" class="button-primary" /'.$gt.'or'.$lt.'input type="button" onclick="showhide(\'GOTMLS_iFrame\', true);" value="'.__("Show the Unloaded Page",'gotmls').'" style="margin: 0 5px;" class="button-primary" /'."$gt$lt/div$gt$lt/center$gt$lt".'iframe id="GOTMLS_iFrame" name="GOTMLS_iFrame" style="top: 0px; left: 0px; position: absolute; width: 100%; height: 100%; background-color: #CCC;"'."$gt$lt/iframe$gt$lt/td$gt$lt/tr$gt$lt".'tr'.$gt.$lt.'td style="height: 20px;"'.$gt.$lt.'iframe id="GOTMLS_statusFrame" name="GOTMLS_statusFrame" style="width: 100%; height: 20px; background-color: #CCC;"'."$gt$lt/iframe$gt$lt/div$gt$lt/td$gt$lt".'td style="height: 20px; width: 20px;"'.$gt.$lt.'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;"'.$gt.$lt.'span class="dashicons dashicons-editor-expand"'."$gt$lt/span$gt&#8690;$lt/h3$gt$lt/td$gt$lt/tr$gt$lt/table$gt$lt/div$gt\n$lt".'script type="text/javascript"'.$gt.'
310 function showhide(id) {
311 divx = document.getElementById(id);
312 if (divx) {
313 if (divx.style.display == "none" || arguments[1]) {
314 divx.style.display = "block";
315 divx.parentNode.className = (divx.parentNode.className+"close").replace(/close/gi,"");
316 return true;
317 } else {
318 divx.style.display = "none";
319 return false;
320 }
321 }
322 }
323 function checkAllFiles(check) {
324 var checkboxes = new Array();
325 checkboxes = document["GOTMLS_Form_clean"].getElementsByTagName("input");
326 for (var i=0; i<checkboxes.length; i++)
327 if (checkboxes[i].type == "checkbox" && (checkboxes[i].id.substring(0, 6) == "check_" || checkboxes[i].id.substring(0, 24) == "GOTMLS_quarantine_check_"))
328 checkboxes[i].checked = check;
329 }
330 function setvalAllFiles(val) {
331 var checkboxes = document.getElementById("GOTMLS_fixing");
332 if (checkboxes)
333 checkboxes.value = val;
334 }
335 function getWindowWidth(min) {
336 if (typeof window.innerWidth != "undefined" && window.innerWidth > min)
337 min = window.innerWidth;
338 else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth > min)
339 min = document.documentElement.clientWidth;
340 else if (typeof document.getElementsByTagName("body")[0].clientWidth != "undefined" && document.getElementsByTagName("body")[0].clientWidth > min)
341 min = document.getElementsByTagName("body")[0].clientWidth;
342 return min;
343 }
344 function getWindowHeight(min) {
345 if (typeof window.innerHeight != "undefined" && window.innerHeight > min)
346 min = window.innerHeight;
347 else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientHeight != "undefined" && document.documentElement.clientHeight > min)
348 min = document.documentElement.clientHeight;
349 else if (typeof document.getElementsByTagName("body")[0].clientHeight != "undefined" && document.getElementsByTagName("body")[0].clientHeight > min)
350 min = document.getElementsByTagName("body")[0].clientHeight;
351 return min;
352 }
353 function loadIframe(title) {
354 showhide("gotmls_too_long", true);
355 showhide("gotmls_too_long");
356 showhide("GOTMLS_iFrame", true);
357 showhide("GOTMLS_iFrame");
358 document.getElementById("windowTitle").innerHTML = title;
359 if (curDiv) {
360 windowW = getWindowWidth(200);
361 windowH = getWindowHeight(200);
362 if (windowW > 200)
363 windowW -= 30;
364 if (windowH > 200)
365 windowH -= 20;
366 if (px2num(curDiv.style.width) > windowW) {
367 curDiv.style.width = windowW + "px";
368 curDiv.style.left = "0px";
369 } else if ((px2num(curDiv.style.left) + px2num(curDiv.style.width)) > windowW) {
370 curDiv.style.left = (windowW - px2num(curDiv.style.width)) + "px";
371 }
372 if (px2num(curDiv.style.height) > windowH) {
373 curDiv.style.height = windowH + "px";
374 curDiv.style.top = "0px";
375 } else if ((px2num(curDiv.style.top) + px2num(curDiv.style.height)) > windowH) {
376 curDiv.style.top = (windowH - px2num(curDiv.style.height)) + "px";
377 }
378 if (px2num(curDiv.style.left) < 0)
379 curDiv.style.left = "0px";
380 if (px2num(curDiv.style.top)< 0)
381 curDiv.style.top = "0px";
382 }
383 showhide("div_file", true);
384 if (IE)
385 curDiv.scrollIntoView(true);
386 setTimeout(function (){ showhide(\'gotmls_too_long\', true); }, 15000);
387 }
388 function cancelserver(divid) {
389 document.getElementById(divid).innerHTML = "'.$lt."div class='error'$gt".GOTMLS_strip4java(__("No response from server!",'gotmls'))."$lt/div$gt".'";
390 }
391 var stopCheckingDefinitions = 0;
392 function checkPrimaryUpdateServer() {
393 var updatescript = document.createElement("script");
394 if (arguments[0])
395 updatescript.setAttribute("src", pri_addr+arguments[0]);
396 else
397 updatescript.setAttribute("src", pri_addr);
398 if (divx = document.getElementById("Definition_Updates"))
399 divx.appendChild(updatescript);
400 return setTimeout(function() {stopCheckingDefinitions = checkAlternateUpdateServer();}, 15000);
401 }
402 function checkAlternateUpdateServer() {
403 var updatescript = document.createElement("script");
404 if (arguments[0])
405 updatescript.setAttribute("src", alt_addr+arguments[0]);
406 else
407 updatescript.setAttribute("src", alt_addr);
408 if (divx = document.getElementById("Definition_Updates"))
409 divx.appendChild(updatescript);
410 return setTimeout(function() {stopCheckingDefinitions = cancelserver("Definition_Updates");}, 15000);
411 }
412 function checkupdateserver(server) {
413 var updatescript = document.createElement("script");
414 updatescript.setAttribute("src", server);
415 if (divx = document.getElementById("GOTMLS_patch_searching"))
416 divx.appendChild(updatescript);
417 return setTimeout(function() {cancelserver("GOTMLS_patch_searching");}, '.(((INT) $GLOBALS["GOTMLS"]["tmp"]['execution_time'])+1).'000+3000);
418 }
419 var IE = document.all?true:false;
420 //if (!IE) document.addEventListener("mousemove", getMouseXY);
421 document.onmousemove = getMouseXY;
422 var offsetX = 0;
423 var offsetY = 0;
424 var offsetW = 0;
425 var offsetH = 0;
426 var curX = 0;
427 var curY = 0;
428 var curDiv, loadingGif;
429 function getMouseXY(e) {
430 if (IE) { // grab the mouse pos if browser is IE
431 curX = event.clientX + document.body.scrollLeft;
432 curY = event.clientY + document.body.scrollTop;
433 } else { // grab the mouse pos if browser is Not IE
434 curX = e.pageX - document.body.scrollLeft;
435 curY = e.pageY - document.body.scrollTop;
436 }
437 if (curX < 0) {curX = 0;}
438 if (curY < 0) {curY = 0;}
439 if (offsetX && curX > 10) {curDiv.style.left = (curX - offsetX)+"px";}
440 if (offsetY && (curY - offsetY) > 0) {curDiv.style.top = (curY - offsetY)+"px";}
441 if (offsetW && (curX - offsetW) > 360) {curDiv.style.width = (curX - offsetW)+"px";}
442 if (offsetH && (curY - offsetH) > 200) {
443 curDiv.style.height = (curY - offsetH)+"px";
444 loadingGif.style.height = (curY - offsetH - 130)+"px";
445 }
446 return true;
447 }
448 function px2num(px) {
449 return parseInt(px.substring(0, px.length - 2), 10);
450 }
451 function setDiv(DivID) {
452 if (curDiv = document.getElementById(DivID)) {
453 if (IE)
454 curDiv.style.position = "absolute";
455 curDiv.style.left = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][0].'";
456 curDiv.style.top = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][1].'";
457 curDiv.style.height = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][2].'";
458 curDiv.style.width = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][3].'";
459 }
460 if (loadingGif = document.getElementById("got-loading-gif"))
461 loadingGif.style.height = "'.(substr($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][2], 0, -2) - 130).'px";
462 }
463 function grabDiv() {
464 corner = document.getElementById("windowTitle");
465 if (corner) {
466 corner.style.width="100%";
467 corner.style.height="100%";
468 }
469 offsetX=curX-px2num(curDiv.style.left);
470 offsetY=curY-px2num(curDiv.style.top);
471 }
472 function releaseDiv() {
473 corner = document.getElementById("windowTitle");
474 if (corner) {
475 corner.style.width="90%";
476 corner.style.height="20px";
477 }
478 document.getElementById("GOTMLS_statusFrame").src = "'.GOTMLS_admin_url('GOTMLS_position', ($GOTMLS_position_nonce = GOTMLS_set_nonce(GOTMLS_position_msg)).'&GOTMLS_x=').'"+curDiv.style.left+"&GOTMLS_y="+curDiv.style.top;
479 offsetX=0;
480 offsetY=0;
481 }
482 function grabCorner() {
483 corner = document.getElementById("cornerGrab");
484 if (corner) {
485 corner.style.width="100%";
486 corner.style.height="100%";
487 }
488 offsetW=curX-px2num(curDiv.style.width);
489 offsetH=curY-px2num(curDiv.style.height);
490 }
491 function releaseCorner() {
492 corner = document.getElementById("cornerGrab");
493 if (corner) {
494 corner.style.width="20px";
495 corner.style.height="20px";
496 }
497 document.getElementById("GOTMLS_statusFrame").src = "'.GOTMLS_admin_url('GOTMLS_position', $GOTMLS_position_nonce.'&GOTMLS_w=').'"+curDiv.style.width+"&GOTMLS_h="+curDiv.style.height;
498 offsetW=0;
499 offsetH=0;
500 }
501 function check_for_donation(chk) {
502 if ((audl = document.getElementById("autoUpdateDownload")) && audl.src.replace(/^.+\?/,"")=="0")
503 if (chk.substr(0, 8) != "Changed " || chk.substr(8, 1) != "0")
504 chk += "\\n\\n'.__("Please make a donation for the use of this wonderful feature!",'gotmls').'";
505 alert(chk);
506 }
507 setDiv("div_file");'."\n$lt/script$gt\n";
508 }
509
510 function GOTMLS_get_header($optional_box = "") {
511 $gt = ">"; // This local variable never changes
512 $lt = "<"; // This local variable never changes
513 if (isset($_GET["check_site"]) && $_GET["check_site"])
514 $pre_style = $lt.'div id="check_site" style="z-index: 1234567;"'.$gt.$lt.'img src="'.GOTMLS_images_path.'checked.gif" height=16 width=16 alt="&#x2714;"'.$gt.__("Tested your site. It appears we didn't break anything",'gotmls')." ;-)$lt/div$gt$lt".'script type="text/javascript"'.$gt.'if (csw = window.parent.document.getElementById("check_site_warning")) csw.style.backgroundColor=\'#0C0\';window.addEventListener(\'load\', (event) => {showhide(\'inside_ddd6dbd641b9a5909fe4d44da2017cc7\');});'."$lt/script$gt{$lt}li$gt Please $lt".'a target="_blank" href="https://wordpress.org/support/plugin/gotmls/reviews/#wporg-footer"'.$gt.'write a "Five-Star" Review'."$lt/a$gt".' on WordPress.org if you like this plugin.'."$lt/li$gt$lt".'style'.$gt.'#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;}';
515 else
516 $pre_style = $lt.'style'.$gt.'#GOTMLS-right-sidebar {float: right; margin-right: 0px;}';
517 return GOTMLS_get_styles($pre_style).$lt.'div id="main-page-title"'.$gt.$lt.'h1 style="vertical-align: middle;"'.$gt.'Anti-Malware from&nbsp;GOTMLS.NET'."$lt/h1$gt$lt/div$gt";
518 }
519
520 function GOTMLS_object_to_array($obj) {
521 if (is_object($obj))
522 $obj = (array) $obj;
523 $new = array();
524 if (is_array($obj)) {
525 foreach ($obj as $key => $val)
526 $new[$key] = GOTMLS_object_to_array($val);
527 } else
528 $new = $obj;
529 return $new;
530 }
531
532 function GOTMLS_get_pagination($count, $wrap = "") {
533 $Q_Paged = "";
534 if (isset($_REQUEST["paged"]) && is_numeric($_REQUEST["paged"])) {
535 if ((INT) $count < (INT) $_REQUEST["paged"])
536 $GLOBALS["GOTMLS"]["Quarantine"]["paged"] = (INT) $count;
537 else
538 $GLOBALS["GOTMLS"]["Quarantine"]["paged"] = (INT) $_REQUEST["paged"];
539 } else
540 $GLOBALS["GOTMLS"]["Quarantine"]["paged"] = 1;
541 for ($p = 1; $p <= $count; $p++) {
542 $Q_Paged .= '<input class="GOTMLS_page" type="submit" value="'.$p.'"'.((isset($GLOBALS["GOTMLS"]["Quarantine"]["paged"]) && $GLOBALS["GOTMLS"]["Quarantine"]["paged"] == $p) || (!isset($GLOBALS["GOTMLS"]["Quarantine"]["paged"]) && 1 == $p)?" DISABLED":"").' name="paged">';
543 }
544 if ($Q_Paged) {
545 foreach ($_GET as $name => $value) {
546 if (substr($name, 0, 10) != 'paged') {
547 if (is_array($value)) {
548 foreach ($value as $val)
549 $Q_Paged .= '<input type="hidden" name="'.GOTMLS_htmlspecialchars($name).'[]" value="'.GOTMLS_htmlspecialchars($val).'">';
550 } else
551 $Q_Paged .= '<input type="hidden" name="'.GOTMLS_htmlspecialchars($name).'" value="'.GOTMLS_htmlspecialchars($value).'">';
552 }
553 }
554 $Q_Paged = '<form method="GET" name="GOTMLS_Form_page"><div style="float: left;">Page:</div>'."$Q_Paged\n</form><br style=\"clear: left;\" />\n";
555 }
556 if ($wrap)
557 return "$Q_Paged<!-- p = $p , count = $count -->$wrap$Q_Paged";
558 else
559 return $Q_Paged;
560 }
561
562 function GOTMLS_get_quarantine($only = false) {
563 global $wpdb, $post;
564 if (is_numeric($only))
565 return get_post($only, ARRAY_A);
566 elseif ($only === true)
567 return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private'");
568 else
569 $args = array("orderby" => 'date', "post_type" => 'GOTMLS_quarantine', "post_status" => array('private'));
570 if (isset($_REQUEST["post_status"]))
571 $args["post_status"] = $_REQUEST["post_status"];
572 if (isset($_REQUEST["paged"]) && is_numeric($_REQUEST["paged"]))
573 $args["paged"] = (INT) $_REQUEST["paged"];
574 if (isset($_REQUEST["posts_per_page"]) && is_numeric($_REQUEST["posts_per_page"]) && ($_REQUEST["posts_per_page"]))
575 $args["posts_per_page"] = (INT) $_REQUEST["posts_per_page"];
576 else
577 $args["posts_per_page"] = 200;
578 $my_query = new WP_Query($args);
579 if ($my_query->have_posts()) {
580 $Q_Page = '<form method="POST" action="'.admin_url('admin-ajax.php').'" target="GOTMLS_iFrame" id="GOTMLS_Form_clean" name="GOTMLS_Form_clean"><input type="hidden" id="GOTMLS_fixing" name="GOTMLS_fixing" value="1"><input type="hidden" name="'.str_replace('=', '" value="', GOTMLS_set_nonce(__FUNCTION__."581")).'"><input type="hidden" name="action" value="GOTMLS_fix"><p id="quarantine_buttons" style="display: none;"><input id="repair_button" type="submit" value="'.__("Restore selected files from quarantine records",'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 quarantine records",'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>
581 <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>
582 <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').((isset($_REQUEST["GOTMLS_debug"]))?'</span><span class="GOTMLS_date">'.__("Date Modified",'gotmls').'</span><span class="GOTMLS_date">'.__("Date Changed",'gotmls').'</span><span class="GOTMLS_date">'.__("File Size",'gotmls').'</span><span class="GOTMLS_date">'.__("Threat Found",'gotmls'):"").'</span></h3>';
583 $root_path = implode(GOTMLS_slash(), array_slice(GOTMLS_explode_dir(__FILE__), 0, (2 + intval($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_level"])) * -1));
584 while ($my_query->have_posts()) {
585 $my_query->the_post();
586 $gif = 'blocked.gif';
587 $threat = 'potential';
588 $action = $post->ID.'" id="check_'.$post->ID.'" onchange="document.getElementById(\'quarantine_buttons\').style.display = \'block\';';
589 $link = GOTMLS_error_link(__("The current/live file is missing or deleted",'gotmls'), $post->ID, $threat);
590 $fa = GOTMLS_threats_found_meta(GOTMLS_object_to_array($post));
591 if (is_file($post->post_title)) {
592 GOTMLS_scanfile($post->post_title);
593 if (count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
594 $gif = 'threat.gif" onload="document.getElementById(\'reclean_buttons\').style.display = \'block\';';
595 $threat = 'known';
596 $action = GOTMLS_encode(realpath($post->post_title)).'" id="ilist_'.$post->ID.'" checked="true';
597 }
598 $link = GOTMLS_error_link(__("View current/live version",'gotmls'), $post->post_title, $threat);
599 } elseif (is_array($postdb = explode(":", $post->post_title.":")) && count($postdb) > 3 && is_numeric($postdb[1])) {
600 if ("options" == substr($postdb[0], -7)) {
601 if ($opt_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_id` = %s",(INT) $postdb[1]), ARRAY_A))
602 $link = GOTMLS_error_link(__("View Option Record: ",'gotmls').((INT) $postdb[1]), ((INT) $postdb[1]).'.1', $threat);
603 elseif ($opt_row = $wpdb->get_row($SQL = $wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_name` LIKE %s", trim($postdb[2], '"')), ARRAY_A))
604 $link = GOTMLS_error_link(__("View Option Record: ",'gotmls').htmlspecialchars($postdb[2]), $opt_row["option_id"].'.1', $threat);
605 else
606 $link = GOTMLS_error_link(__("View Quarantine Record",'gotmls'), $post->ID, $threat);
607 } else {
608 $link = '<a target="_blank" href="';
609 if ("revision" == $postdb[0])
610 $link .= admin_url('revision.php?revision='.rawurlencode($postdb[1]))."\" title=\"View this revision";
611 else
612 $link .= admin_url('post.php?action=edit&post='.rawurlencode((INT) $postdb[1]))."\" title=\"View current ".GOTMLS_htmlspecialchars($postdb[0]);
613 $link .= "\" id=\"list_edit_".((INT) $postdb[1])."\" class=\"GOTMLS_plugin $threat\">";
614 }
615 }
616 $Q_Page .= '
617 <li id="GOTMLS_quarantine_'.((INT) $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.'</a></span><span title="modified: '.GOTMLS_htmlspecialchars($post->post_modified).'" class="GOTMLS_date">'.GOTMLS_htmlspecialchars($post->post_modified_gmt).((isset($_REQUEST["GOTMLS_debug"]) && is_file($post->post_title))?'</span><span class="GOTMLS_date">'.gmdate("Y-m-d H:i:s", filemtime($post->post_title)).'</span><span class="GOTMLS_date">'.gmdate("Y-m-d H:i:s", filectime($post->post_title)).'</span><span class="GOTMLS_date">('.filesize($post->post_title).' bytes)</span><span class="GOTMLS_date">( '.$fa.')':"").'</span><input type="checkbox" name="GOTMLS_fix[]" value="'.$action.'" /><img src="'.GOTMLS_images_path.$gif.'" height=16 width=16 alt="Q">'.$link.GOTMLS_htmlspecialchars(str_replace($root_path, "...", $post->post_title))."</a></li>\n";
618 }
619 $Q_Page = GOTMLS_get_pagination($my_query->max_num_pages, "$Q_Page\n</ul>\n</form>");
620 } else
621 $Q_Page = '<h3>'.__("No Items in Quarantine",'gotmls').'</h3>';
622 wp_reset_query();
623 return $Q_Page;
624 }
625
626 function GOTMLS_box($bTitle, $bContents, $bType = "postbox") {
627 $md5 = md5($bTitle);
628 if (isset($GLOBALS["GOTMLS"]["tmp"]["$bType"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["$bType"]))
629 $GLOBALS["GOTMLS"]["tmp"]["$bType"]["$md5"] = "$bTitle";
630 else
631 $GLOBALS["GOTMLS"]["tmp"]["$bType"] = array("$md5"=>"$bTitle");
632 return '
633 <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>
634 <div id="inside_'.$md5.'" class="inside">
635 '.$bContents.'
636 </div>
637 </div>';
638 }
639
640 function GOTMLS_threats_ver($threats_name) {
641 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"] as $threat_level => $Threats)
642 if (is_array($Threats) && isset($Threats["$threats_name"][0]) && GOTMLS_strlen($Threats["$threats_name"][0]) == 5)
643 return $Threats["$threats_name"][0];
644 return $threats_name;
645 }
646
647 function GOTMLS_threats_found_meta($Q_post = array()) {
648 global $wpdb, $table_prefix;
649 $gt = ">"; // This local variable never changes
650 $lt = "<"; // This local variable never changes
651 $SQL = "SELECT `meta_value` AS `Threat`, COUNT(*) AS `Found` FROM `{$wpdb->prefix}postmeta` WHERE `meta_key` = 'GOTMLS_threats_found'";
652 if (isset($Q_post["ID"]) && is_numeric($pID = $Q_post["ID"]) && ($pID > 0))
653 $SQL = $wpdb->prepare("$SQL AND post_id = %s", (INT) $pID);
654 else
655 $pID = 0;
656 $my_query = $wpdb->get_results("$SQL GROUP BY `meta_value`", ARRAY_A);
657 $fa = "";
658 if (is_array($my_query) && count($my_query)) {
659 $f = 1;
660 foreach ($my_query as $rec) {
661 if (isset($rec["Threat"]) && is_string($rec["Threat"]) && is_array($Threat = @GOTMLS_uckserialize($rec["Threat"])) && isset($Threat["DefVer"]) && isset($Threat["SubPos"])) {
662 $ends = explode("-", $Threat["SubPos"]."--", 3);
663 if (GOTMLS_strlen($ends[0]) > 0 && GOTMLS_strlen($ends[1]) > 0 && is_numeric($ends[1]) && is_numeric($ends[0])) {
664 if ($ends[1] < $ends[0])
665 $ends = array_reverse($ends);
666 $fa .= $lt.'a title="'.GOTMLS_htmlspecialchars($Threat["DefVer"]).'" href="javascript:select_text_range(\'ta_file\', '.$ends[0].', '.$ends[1].');"'.$gt.'['.$f++."]$lt/a$gt ";
667 }
668 }
669 }
670 } else {
671 if (isset($Q_post["post_excerpt"]) && GOTMLS_strlen($Q_post["post_excerpt"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"] = @GOTMLS_uckserialize(GOTMLS_decode($Q_post["post_excerpt"])))) {
672 $f = 1;
673 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
674 $ends = explode("-", "$threats_found--", 3);
675 if (GOTMLS_strlen($ends[0]) > 0 && GOTMLS_strlen($ends[1]) > 0 && is_numeric($ends[1]) && is_numeric($ends[0])) {
676 if ($ends[1] < $ends[0])
677 $ends = array_reverse($ends);
678 $fa .= $lt.'a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$ends[0].', '.$ends[1].');"'.$gt.'['.$f++."]$lt/a$gt ";
679 if (function_exists("add_post_meta"))
680 add_post_meta($pID, 'GOTMLS_threats_found', array("SubPos" => $ends[0]."-".$ends[1], "DefVer" => GOTMLS_threats_ver($threats_name)));
681 } else {
682 if (is_numeric($threats_found)) {
683 $threats_found = $threats_name;
684 $threats_name = $f;
685 }
686 $fpos = 0;
687 $flen = 0;
688 $potential_threat = GOTMLS_convert_r($threats_found);
689 while (($fpos = strpos($GLOBALS["GOTMLS"]["tmp"]["file_contents"], ($potential_threat), $flen + $fpos)) !== false) {
690 $flen = GOTMLS_strlen($potential_threat);
691 $fa .= $lt.'a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.($fpos).', '.($fpos + $flen).');"'.$gt.'['.$f++."]$lt/a$gt ";
692 if (function_exists("add_post_meta"))
693 add_post_meta($pID, 'GOTMLS_threats_found', serialize(array("SubPos" => $fpos."-".($fpos + $flen), "DefVer" => GOTMLS_threats_ver($threats_name))));
694 }
695 }
696 }
697 } else
698 $fa = GOTMLS_strlen($Q_post["post_excerpt"])."No Threats Found ";
699 }
700 return $fa;
701 }
702
703 function GOTMLS_view_details($Q_post, $pretext = "") {
704 $title = __("View Details:",'gotmls');
705 $clean_file = GOTMLS_htmlentities($Q_post["post_title"]);
706 $encoded_file_contents = GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
707 if (isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])) {
708 $en = $GLOBALS["GOTMLS"]["tmp"]["encoding"];
709 @header("Content-type: text/html; charset=$en");
710 } else
711 $en = "Unknown";
712 $fa = GOTMLS_threats_found_meta($Q_post);
713 die(GOTMLS_html_tags(array(
714 "html" => array(
715 "head" => array(
716 "title" => "$title $clean_file",
717 "script" => GOTMLS_js_text_range()
718 ),
719 "body" => array(
720 "table" => array(
721 "tr" => array(
722 "td" => "$pretext".
723 GOTMLS_html_tags(array(
724 "div" => array(
725 "b" => "$title",
726 "br id='encoding' /" => "encoding: $en",
727 "br id='size' /" => "size: ".GOTMLS_strlen("$encoded_file_contents")." Bytes",
728 "br id='modified' /" => 'modified:'.$Q_post["post_modified"],
729 "br id='changed' /" => 'changed:'.$Q_post["post_modified_gmt"],
730 "br id='quarantined' /" => 'quarantined:'.$Q_post["post_date"]
731 )
732 ), array(
733 '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;"'
734 )
735 ).
736 GOTMLS_html_tags(array(
737 "div" => GOTMLS_html_tags(array('span' => $title), array('span' => 'onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';"'))."( $fa)"
738 ), array(
739 'div' => 'style="overflow: auto;"'
740 )
741 )
742 ),
743 GOTMLS_html_tags(array(
744 "tr" => array(
745 "td" => array(
746 "textarea" => GOTMLS_htmlentities("$encoded_file_contents")
747 )
748 )
749 ), array(
750 'td' => 'style="height: 100%; padding: 5px 5px 0 0;"',
751 'textarea' => 'id="ta_file" style="width: 100%; height: 100%"'
752 )
753 )
754 )
755 )
756 )
757 ), array(
758 'script' => 'type="text/javascript"',
759 'table' => 'style="top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;"',
760 'td' => 'style="width: 100%"'
761 )
762 ));
763 }
764
765 function GOTMLS_js_text_range($posttext = "") {
766 return '
767 function select_text_range(ta_id, start, end) {
768 var textBox = document.getElementById(ta_id);
769 var scrolledText = "";
770 scrolledText = textBox.value.substring(0, end);
771 textBox.focus();
772 if (textBox.setSelectionRange) {
773 scrolledText = textBox.value.substring(end);
774 textBox.value = textBox.value.substring(0, end);
775 textBox.scrollTop = textBox.scrollHeight;
776 textBox.value = textBox.value + scrolledText;
777 textBox.setSelectionRange(start, end);
778 } else if (textBox.createTextRange) {
779 var range = textBox.createTextRange();
780 range.collapse(true);
781 range.moveStart("character", start);
782 range.moveEnd("character", end);
783 range.select();
784 } else
785 alert("The highlighting function does not work in your browser");
786 }
787 if (typeof window.parent.showhide === "function")
788 window.parent.showhide("GOTMLS_iFrame", true);
789 '.$posttext;
790 }
791
792 if ((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"]:"")))) && GOTMLS_strlen($SCRIPT_FILE) > GOTMLS_strlen("/".basename(__FILE__)) && substr(__FILE__, -1 * GOTMLS_strlen($SCRIPT_FILE)) == substr($SCRIPT_FILE, -1 * GOTMLS_strlen(__FILE__)))) {
793 if (isset($_REQUEST["page"]) && str_replace('-', '_', $_REQUEST["page"]) == "GOTMLS_View_Quarantine" && isset($_REQUEST["GOTMLS_mt"]) && GOTMLS_strlen($GOTMLS_nonce = $_REQUEST["GOTMLS_mt"]) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]["context"]) && ($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]["context"] == GOTMLS_update_home)) {
794 try {
795 $wpdb->prefix = $table_prefix;
796 GOTMLS_define("GOTMLS_Loading_LANGUAGE", __("Loading, Please Wait ...",'gotmls'));
797 GOTMLS_define("GOTMLS_position_msg", __("Default position",'gotmls'));
798 if (isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) {
799 $my_query = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `ID` = %s", (INT) $_REQUEST["id"]), ARRAY_A);
800 if (is_array($my_query) && isset($my_query[0]["post_type"]) && strtolower($my_query[0]["post_type"]) == "gotmls_quarantine") {
801 GOTMLS_load_contents(GOTMLS_decode($my_query[0]["post_content"]));
802 GOTMLS_view_details($my_query[0], '<form style="margin: 0;" method="post" action="?GOTMLS_mt='.$GOTMLS_nonce.'&page=GOTMLS_View_Quarantine" onsubmit="return confirm(\''.GOTMLS_strip4java(__("Are you sure you want to restore this record from the quarantine?",'gotmls')).'\');"><input type="hidden" name="id[]" value="'.$my_query[0]["ID"].'"><input type="submit" value="Restore from Quarantine" style="display: none; background-color: #0C0; float: right;"></form>');
803 } else
804 die('<h3>Item NOT Found in Quarantine</h3>');
805 } else {
806 if (!isset($_REQUEST["not_in"]))
807 $_REQUEST["not_in"] = "trash";
808 $GLOBALS["GOTMLS"]["Quarantine"]["SQL"] = $wpdb->prepare("FROM `{$wpdb->prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` != %s ORDER BY `post_date_gmt` DESC", $_REQUEST["not_in"]);
809 $GLOBALS["GOTMLS"]["Quarantine"]["Count"] = $wpdb->get_var("SELECT COUNT(*) ".$GLOBALS["GOTMLS"]["Quarantine"]["SQL"]);
810 if (isset($_REQUEST["posts_per_page"]) && is_numeric($_REQUEST["posts_per_page"]) && ($_REQUEST["posts_per_page"]))
811 $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"] = (INT) $_REQUEST["posts_per_page"];
812 else
813 $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"] = 200;
814 $paged = GOTMLS_get_pagination(ceil($GLOBALS["GOTMLS"]["Quarantine"]["Count"] / $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"]));
815 $GLOBALS["GOTMLS"]["Quarantine"]["SQL"] .= $wpdb->prepare(" LIMIT %d,%d", (INT) (($GLOBALS["GOTMLS"]["Quarantine"]["paged"] - 1) * $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"]), (INT) $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"]);
816 $my_query = $wpdb->get_results("SELECT * ".$GLOBALS["GOTMLS"]["Quarantine"]["SQL"], ARRAY_A);
817 if (is_array($my_query) && count($my_query)) {
818 $Q_Page = $paged.'<form method="POST" action="?page=GOTMLS_View_Quarantine" id="GOTMLS_Form_clean" name="GOTMLS_Form_clean"><input type="hidden" name="GOTMLS_mt" value="'.$GOTMLS_nonce.'"><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>
819 <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>';
820 $root_path = implode(GOTMLS_slash(), array_slice(GOTMLS_explode_dir(__FILE__), 0, (2 + intval($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_level"])) * -1));
821 foreach ($my_query as $post_a) {
822 $restored = "";
823 $image = "threat";
824 $extra = "";
825 if (isset($_REQUEST["id"]) && is_array($_REQUEST["id"]) && in_array($post_a["ID"], $_REQUEST["id"])) {
826 if (GOTMLS_save_contents($post_a["post_title"], $apost_content = GOTMLS_decode($post_a["post_content"]))) {
827 $post_a["post_date_gmt"] = gmdate("Y-m-d H:i:s");
828 if ($wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}posts` SET `post_status` = 'pending', `post_name` = 'whitelist', `post_date_gmt` = '".$post_a["post_date_gmt"]."' WHERE `post_type` = 'GOTMLS_quarantine' AND `ID` = %s", (INT) $post_a["ID"])))
829 $post_a["post_status"] = 'pending';
830 }
831 }
832 if ($post_a["post_status"] == 'pending') {
833 $restored = " read-only disabled";
834 $image = "checked";
835 $extra = " Whitelisted ".$post_a["post_date_gmt"];
836 }
837 if ($post_a["post_status"] == 'trash') {
838 $restored = " read-only disabled";
839 $image = "blocked";
840 $extra = " Deleted ".$post_a["post_date_gmt"];
841 }
842 $Q_Page .= '
843 <li id="GOTMLS_quarantine_'.$post_a["ID"].'" class="GOTMLS_quarantine_item"><span class="GOTMLS_date">'.$post_a["post_date"].'</span><span class="GOTMLS_date" title="modified: '.$post_a["post_modified"].'">'.$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["post_status"]=='pending'?'" title="View Whitelisted File':($post_a["post_status"]=='trash'?' potential" title="View Deleted File':' known" title="View Quarantined File')).'" target="_blank" href="?page=GOTMLS_View_Quarantine&id='.$post_a["ID"].'&GOTMLS_mt='.$GOTMLS_nonce.'">'.str_replace($root_path, "...", $post_a["post_title"])."$extra</a></li>\n";
844 }
845 $Q_Page .= "\n</ul>\n</form>$paged";
846 } else
847 $Q_Page = '<h3>'.__("No Items in Quarantine",'gotmls').'</h3>';
848 die(GOTMLS_html_tags(array("html" => array("body" => GOTMLS_get_header().GOTMLS_box(__("View Quarantine",'gotmls'), $Q_Page)))));
849 }
850 } catch (Exception $e) {
851 die('Caught exception: '.GOTMLS_htmlspecialchars($e->getMessage())."\n");
852 }
853 } else {
854 header("Content-type: image/gif");
855 die(GOTMLS_decode('R=lGODlhEAAQAIQYAAAAAAIAAAMAAAgAAAkAAAsAAAwAAHcAAHgAAKYAAK4AAK8AALUAALYAAMcAAMgAAM=AANkAANoAANwAAN=AAP4AAP8AANTU1P_______________________________yH5BAEKAB8ALAAAAAAQABAAAAWB4HddwGia5SWSAVBZMAwIKQkg7xtXCJAKCEukURgRIJbKQWCrSGw-QAJWiS4sjFHUAYNUFD7LpKilvC6DiaVUqZxipuQIFpfXSWLC5UWpFdQ-V=gWD1EjDBYLUToJUT4XEVUlAQddAyMGDRIWS1o3SW=6PI9aNKJJMykrNSckIx8hADs2'));
856
857 }
858 }
859 $GOTMLS_image_alt = array("wait"=>"...", "checked"=>"&#x2714;", "blocked"=>"X", "question"=>"?", "threat"=>"!");
860 $GOTMLS_dir_at_depth = array();
861 $GOTMLS_dirs_at_depth = array();
862 $GLOBAL_STRING = array("REQUEST" => "&","SERVER" => "&","FILES" => "&");
863 if (isset($_GET) && is_array($_GET))
864 foreach ($_GET as $req => $val)
865 $GLOBAL_STRING["REQUEST"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
866 if (isset($_POST) && is_array($_POST))
867 foreach ($_POST as $req => $val)
868 $GLOBAL_STRING["REQUEST"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
869 if (isset($_SERVER) && is_array($_SERVER))
870 foreach ($_SERVER as $req => $val)
871 $GLOBAL_STRING["SERVER"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
872 if (isset($_FILES) && is_array($_FILES))
873 foreach ($_FILES as $req => $fila)
874 foreach (array("tmp_name","name") as $val)
875 if (isset($fila["$val"]))
876 $GLOBAL_STRING["FILES"] .= "$req.$val=".(is_array($fila["$val"])?print_r($fila["$val"],1):$fila["$val"])."&";
877 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]) && array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"])))
878 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] = array(
879 "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'),
880 "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", '/[\=\/](\.\.|etc)\//'),
881 "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\&/'));
882 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] as $TP => $VA) {
883 $V = 3;
884 if (is_array($VA) && count($VA) > $V && is_array($VA[$V])) {
885 foreach ($VA[$V] as $reg => $arr) {
886 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $arr;
887 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $reg;
888 }
889 }
890 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"]) && $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"])) {
891 $GLOBALS["GOTMLS"]["detected_attacks"] = "&attack[]=FW_$TP";
892 for ($V = 4; isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V]); $V+=2)
893 if (!isset($GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]]))
894 die($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]." [$V] not in ".GOTMLS_html_tags(array('pre' => GOTMLS_htmlspecialchars(print_r($GLOBAL_STRING,1)))));
895 elseif (!preg_match($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V], $GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]], $matches))
896 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
897 if ($GLOBALS["GOTMLS"]["detected_attacks"])
898 include(dirname(dirname(__FILE__))."/safe-load/index.php");
899 }
900 }
901 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
902 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))
903 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"] = $GLOBALS["GOTMLS"]["tmp"]["default"]["msg_position"];
904 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"]))
905 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"] = 2;
906 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]))
907 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"] = -1;
908 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"])))
909 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"] = $GLOBALS["GOTMLS"]["tmp"]["skip_ext"];
910 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"]))
911 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"] = "";
912 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"])))
913 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"] = array();
914 $GOTMLS_total_percent = 0;
915
916 function GOTMLS_admin_notices() {
917 if (!is_admin())
918 return;
919 if (is_file(dirname(dirname(dirname(__FILE__)))."/yuzo-related-post/yuzo_related_post.php"))
920 echo GOTMLS_error_div('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.');
921 if (!function_exists("mb_detect_encoding"))
922 echo GOTMLS_error_div('It looks like you don\'t have <b>"mbstring" functions</b> enabled on your server.<br />This Anti-Malware plugin requires Multibyte String compatibility for best results. Please make sure that php-mbstring is installed and configured for the version of PHP running on your server.');
923 if ($GLOBALS["GOTMLS"]["tmp"]["HeadersError"])
924 echo $GLOBALS["GOTMLS"]["tmp"]["HeadersError"];
925 }
926 add_action("admin_notices", "GOTMLS_admin_notices");
927
928 function GOTMLS_array_recurse($array1, $array2) {
929 foreach ($array2 as $key => $value) {
930 if (!isset($array1[$key]) || (isset($array1[$key]) && !is_array($array1[$key])))
931 $array1[$key] = array();
932 if (is_array($value))
933 $value = GOTMLS_array_recurse($array1[$key], $value);
934 $array1[$key] = $value;
935 }
936 return $array1;
937 }
938
939 function GOTMLS_array_replace($array1, $array2) {
940 foreach ($array2 as $key => $value)
941 $array1[$key] = $value;
942 return $array1;
943 }
944
945 function GOTMLS_array_replace_recursive($array1 = array()) {
946 $args = func_get_args();
947 $array1 = $args[0];
948 if (!is_array($array1))
949 $array1 = array();
950 for ($i = 1; $i < count($args); $i++)
951 if (is_array($args[$i]))
952 $array1 = GOTMLS_array_recurse($array1, $args[$i]);
953 return $array1;
954 }
955
956 function GOTMLS_scanlog_title() {
957 $units = array("seconds"=>60,"minutes"=>60,"hours"=>24,"days"=>365,"years"=>10);
958 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["type"]) && GOTMLS_strlen($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["type"]))
959 $GLOBALS["GOTMLS"]["scan"]["title"] = GOTMLS_sanitize($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["type"]);
960 else
961 $GLOBALS["GOTMLS"]["scan"]["title"] = "Unknown scan type";
962 $scan_only = "";
963 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["scan_only"])) {
964 if (is_array($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["scan_only"])) {
965 if (count($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["scan_only"]) == 1 && isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["scan_only"][0]))
966 $scan_only = "/".$GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["scan_only"][0];
967 } else
968 $scan_only = "/".$GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["scan_only"];
969 }
970 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["dir"]) && @is_dir($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["dir"]))
971 $GLOBALS["GOTMLS"]["scan"]["title"] .= " of ".basename($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["dir"].$scan_only);
972 elseif ($scan_only)
973 $GLOBALS["GOTMLS"]["scan"]["title"] .= " of ".basename($scan_only);
974 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]) && is_numeric($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"])) {
975 $ukeys = array_keys($units);
976 $GLOBALS["GOTMLS"]["scan"]["title"] .= " on ".date("Y-m-d", $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]);
977 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"]) && is_numeric($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"]) && ($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"] >= $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"])) {
978 $time = ($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"] - $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]);
979 for ($unit = $ukeys[0], $key=0; (isset($units[$ukeys[$key]]) && $key < (count($ukeys) - 1) && $time >= $units[$ukeys[$key]]); $unit = $ukeys[++$key])
980 $time = floor($time/$units[$ukeys[$key]]);
981 if (1 == $time)
982 $unit = substr($unit, 0, -1);
983 if ($time)
984 $GLOBALS["GOTMLS"]["scan"]["title"] .= " ran for $time $unit";
985 } else
986 $GLOBALS["GOTMLS"]["scan"]["title"] .= " was not finished!";
987 } else
988 $GLOBALS["GOTMLS"]["scan"]["title"] .= " failed to started!";
989 return $GLOBALS["GOTMLS"]["scan"]["title"];
990 }
991
992 function GOTMLS_load_scanlog($scanlog_key) {
993 global $wpdb;
994 if (GOTMLS_strlen($scanlog_key = preg_replace('/[^0-9a-f]++]i/', "", $scanlog_key)) != 32)
995 $scanlog_key = preg_replace('/[^0-9a-f]++]i/', "", $GLOBALS["GOTMLS"]["tmp"]["mt"]);
996 if ((GOTMLS_strlen($scanlog_key) == 32) && ($prs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}posts` WHERE post_type = %s AND post_name = %s", 'gotmls_results', $scanlog_key), ARRAY_A))) {
997 $GLOBALS["GOTMLS"]["scan"]["key"] = $scanlog_key;
998 if (!(isset($prs[0]["post_content"]) && (GOTMLS_strlen($prs[0]["post_content"])) && is_array($GLOBALS["GOTMLS"]["scan"]["log"] = json_decode($prs[0]["post_content"], true))))
999 $GLOBALS["GOTMLS"]["scan"]["log"] = array();
1000 if (!isset($GLOBALS["GOTMLS"]["scan"]["title"]) && !(isset($prs[0]["post_title"]) && (GOTMLS_strlen($GLOBALS["GOTMLS"]["scan"]["title"] = $prs[0]["post_title"])))) {
1001 GOTMLS_scanlog_title();
1002 }
1003 return $scanlog_key;
1004 }
1005 return false;
1006 }
1007
1008 function GOTMLS_update_scanlog($scan_log, $status = "") {
1009 global $wpdb;
1010 if (is_array($scan_log)) {
1011 if (isset($GLOBALS["GOTMLS"]["scan"]["key"]) && GOTMLS_strlen($scanlog_key = preg_replace('/[^0-9a-f]++]i/', "", $GLOBALS["GOTMLS"]["scan"]["key"])) == 32) {
1012 $GLOBALS["GOTMLS"]["scan"]["log"] = GOTMLS_array_replace_recursive($GLOBALS["GOTMLS"]["scan"]["log"], $scan_log);
1013 $values = array("post_modified" => date("Y-m-d H:i:s", (int) $GLOBALS["GOTMLS"]["MT"]));
1014 $where = array("post_type" => 'gotmls_results', "post_name" => $scanlog_key);
1015 } else {
1016 $where = false;
1017 $values = array("post_modified" => date("Y-m-d H:i:s", (int) $GLOBALS["GOTMLS"]["MT"]), "post_date_gmt" => date("Y-m-d H:i:s", (int) $GLOBALS["GOTMLS"]["MT"]), "post_type" => 'gotmls_results', "post_parent" => 0);
1018 if (($prs = $wpdb->get_results($wpdb->prepare("SELECT ID FROM `{$wpdb->prefix}posts` WHERE post_type = %s ORDER BY post_date DESC LIMIT 1", 'gotmls_results'), ARRAY_A)) && isset($prs[0]["ID"]))
1019 $values["post_parent"] = $prs[0]["ID"];
1020 $GLOBALS["GOTMLS"]["scan"]["log"] = $scan_log;
1021 }
1022 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["percent"]) && is_numeric($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["percent"]) && ($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["percent"] >= 100))
1023 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"] = time();
1024 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"]) && is_numeric($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"])) {
1025 $values["post_modified_gmt"] = date("Y-m-d H:i:s", (int) $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"]);
1026 if (!isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]))
1027 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"] = $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"];
1028 }
1029 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["type"]) && !isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]))
1030 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"] = (int) $GLOBALS["GOTMLS"]["MT"];
1031 $values["post_content"] = json_encode($GLOBALS["GOTMLS"]["scan"]["log"]);
1032 $values["post_author"] = GOTMLS_get_current_user_id(0);
1033 $values["post_modified"] = date("Y-m-d H:i:s", (int) microtime(true));
1034 if (!(isset($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]) && is_array($GLOBALS["GOTMLS"]["scan"]["log"]["settings"])) && isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]))
1035 $GLOBALS["GOTMLS"]["scan"]["log"]["settings"] = $GLOBALS["GOTMLS"]["tmp"]["settings_array"];
1036 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]) && is_numeric($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]) && ($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"] > 0)) {
1037 $values["post_date"] = date("Y-m-d H:i:s", (int) $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]);
1038 $values["post_title"] = GOTMLS_scanlog_title();
1039 if ($where)
1040 $scan_log["updated" . $wpdb->update($wpdb->posts, $values, $where)] = $where;
1041 else {
1042 if (GOTMLS_strlen($GLOBALS["GOTMLS"]["scan"]["key"] = preg_replace('/[^0-9a-f]++]i/', "", $GLOBALS["GOTMLS"]["tmp"]["mt"])) != 32)
1043 $GLOBALS["GOTMLS"]["scan"]["key"] = md5($GLOBALS["GOTMLS"]["MT"]);
1044 $values["post_name"] = $GLOBALS["GOTMLS"]["scan"]["key"];
1045 $scan_log["inserted"] = $wpdb->insert($wpdb->posts, $values);
1046 }
1047 }
1048 }
1049 }
1050
1051 function GOTMLS_loaded() {
1052 if (headers_sent($filename, $linenum)) {
1053 if (!$filename)
1054 $filename = __("an unknown file",'gotmls');
1055 if (!is_numeric($linenum))
1056 $linenum = __("unknown",'gotmls');
1057 $GLOBALS["GOTMLS"]["tmp"]["HeadersError"] = GOTMLS_error_div(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));
1058 } elseif (isset($_GET["SESSION"]) && !session_id()) {
1059 @session_start();
1060 }
1061 if (session_id() && isset($_GET["SESSION"]) && $_GET["SESSION"] == "GOTMLS_debug" && ((isset($_GET["GOTMLS_debug"]) && "SESSION" == $_GET["GOTMLS_debug"]) || !isset($_SESSION["GOTMLS_debug"])))
1062 $_SESSION["GOTMLS_debug"] = array("GOTMLS_loaded" => microtime(true));
1063 }
1064 add_action("plugins_loaded", "GOTMLS_loaded");
1065
1066 if (!function_exists("add_action")) {
1067 GOTMLS_loaded();
1068 // GOTMLS_admin_notices();
1069 }
1070
1071 function GOTMLS_get_ext($filename) {
1072 $nameparts = explode(".", ".$filename");
1073 return strtolower($nameparts[(count($nameparts)-1)]);
1074 }
1075
1076 function GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized = true) {
1077 if ($match = @preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["file_contents"], $threats_found)) {
1078 $start = -1;
1079 if (!@preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["new_contents"], $threat_found)) {
1080 $new_contents = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
1081 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
1082 } else
1083 $new_contents = false;
1084 foreach ($threats_found[0] as $find) {
1085 $potential_threat = GOTMLS_convert_r($find);
1086 $flen = GOTMLS_strlen($potential_threat);
1087 while (($start = strpos(GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"]), $potential_threat, $start+1)) !== false) {
1088 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".($flen+$start)] = "$threat_name";
1089 if ($not_serialized)
1090 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = str_replace($find, "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]);
1091 else
1092 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = substr($GLOBALS["GOTMLS"]["tmp"]["new_contents"], 0, $start).str_repeat(" ", $flen).substr($GLOBALS["GOTMLS"]["tmp"]["new_contents"], $start + $flen);
1093 }
1094 }
1095 if ($not_serialized && ($new_contents !== false) && GOTMLS_strlen($new_contents) < GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["new_contents"]))
1096 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $new_contents;
1097 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
1098 } else
1099 return $match;
1100 }
1101
1102 function GOTMLS_preg_last_pcre_error() {
1103 $DC = array('PREG_NO_ERROR', 'PREG_INTERNAL_ERROR', 'PREG_BACKTRACK_LIMIT_ERROR', 'PREG_RECURSION_LIMIT_ERROR', 'PREG_BAD_UTF8_ERROR', 'PREG_BAD_UTF8_OFFSET_ERROR');
1104 if (function_exists("preg_last_error") && ($key = (INT) preg_last_error()) && isset($DC[$key]))
1105 return $DC[$key];
1106 else
1107 return "";
1108 }
1109
1110 function GOTMLS_check_threat($check_threats, $file='UNKNOWN') {
1111 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1112 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"] = microtime(true);
1113 $filekey = md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"])."O".GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1114 if (is_array($check_threats)) {
1115 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, GOTMLS_strlen(ABSPATH))));
1116 if (substr($file, 0, GOTMLS_strlen(ABSPATH)) == ABSPATH && isset($check_threats[GOTMLS_wp_version]["$path"])) {
1117 if (($check_threats[GOTMLS_wp_version]["$path"] != $filekey) && ($source = GOTMLS_get_URL(GOTMLS_get_corefile_URL("$path", $check_threats[GOTMLS_wp_version]["$path"]))) && ($check_threats[GOTMLS_wp_version]["$path"] == md5($source)."O".GOTMLS_strlen($source))) {
1118 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1119 $len = GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1120 if (GOTMLS_strlen($source) < $len)
1121 $len = GOTMLS_strlen($source);
1122 for ($start = 0, $end = 0; ($start == 0 || $end == 0) && $len > 0; $len--){
1123 if ($start == 0 && substr($source, 0, $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], 0, $len))
1124 $start = $len;
1125 if ($end == 0 && substr($source, -1 * $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], -1 * $len))
1126 $end = $len;
1127 }
1128 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".(GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])-$end)] = "Core File Modified";
1129 }
1130 } else {
1131 foreach ($check_threats as $threat_name=>$threat_definitions) {
1132 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"] = microtime(true);
1133 if (is_array($threat_definitions) && count($threat_definitions) > 1 && GOTMLS_strlen($def_ver = 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"])))) {
1134 while ($threat_definition = array_shift($threat_definitions)) {
1135 $found = GOTMLS_preg_match_all($threat_definition, $threat_name);
1136 if ($found===false && ($err = GOTMLS_preg_last_pcre_error())) {
1137 $GLOBALS["GOTMLS"]["tmp"]["file_scan"]["errors"]["$threat_definition"] = $err;
1138 $GLOBALS["GOTMLS"]["tmp"]["errors"]["$def_ver"]["$filekey"] = $err;
1139 }
1140 }
1141 if (isset($_SESSION["GOTMLS_debug"])) {
1142 $_SESSION["GOTMLS_debug"]["threat_name"] = "$threat_name";// ($def_ver)";
1143 $file_time = sprintf('%f', (microtime(true) - $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"]));
1144 if (isset($_GET["GOTMLS_debug"]) && is_numeric($_GET["GOTMLS_debug"]) && $file_time > $_GET["GOTMLS_debug"])
1145 echo GOTMLS_htmlspecialchars("\n//GOTMLS_debug $file_time $threat_name $file\n");
1146 if (isset($GLOBALS["GOTMLS"]["tmp"]["errors"]["$def_ver"]["$filekey"]))
1147 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["errors"]["$filekey"] = $GLOBALS["GOTMLS"]["tmp"]["errors"]["$def_ver"]["$filekey"];
1148 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"]))
1149 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] = sprintf('%f', $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] + $file_time);
1150 else
1151 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] = $file_time;
1152 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"]))
1153 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"]++;
1154 else
1155 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"] = 1;
1156 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"])
1157 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"] = $file_time;
1158 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"])
1159 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"] = $file_time;
1160 }
1161 }
1162 }
1163 }
1164 } elseif (GOTMLS_strlen($check_threats) && isset($_GET['eli']) && GOTMLS_verify_regex($check_threats)) {
1165 $found = GOTMLS_preg_match_all($check_threats, $check_threats);
1166 if ($found===false && ($err = GOTMLS_preg_last_pcre_error()))
1167 $GLOBALS["GOTMLS"]["tmp"]["errors"]["$check_threats"]["$filekey"] = $err;
1168 }
1169 if (isset($_SESSION["GOTMLS_debug"])) {
1170 $file_time = sprintf('%f', (microtime(true) - $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"]));
1171 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"]))
1172 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] = sprintf('%f', $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] + $file_time);
1173 else
1174 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] = $file_time;
1175 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"]))
1176 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"]++;
1177 else
1178 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"] = 1;
1179 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"])
1180 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"] = $file_time;
1181 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"])
1182 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"] = $file_time;
1183 }
1184 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
1185 }
1186
1187 function GOTMLS_verify_regex($RegExp) {
1188 if (preg_match('/^(\/|\#|\|).+\1[is]*$/', $RegExp))
1189 return $RegExp;
1190 else
1191 return "";
1192 }
1193
1194 function GOTMLS_is_whitelisted($MD5Ofile, $file = "") {
1195 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["whitelist"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["whitelist"]))) {
1196 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]))
1197 $GLOBALS["GOTMLS"]["tmp"]["whitelist"] = array_flip($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]);
1198 else
1199 $GLOBALS["GOTMLS"]["tmp"]["whitelist"] = array();
1200 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"])) {
1201 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"] as $whitelist_file=>$non_threats) {
1202 if (is_array($non_threats) && count($non_threats) > 1) {
1203 if (isset($non_threats[0]))
1204 unset($non_threats[0]);
1205 $GLOBALS["GOTMLS"]["tmp"]["whitelist"] = array_merge($GLOBALS["GOTMLS"]["tmp"]["whitelist"], $non_threats);
1206 }
1207 }
1208 }
1209 }
1210 if (isset($GLOBALS["GOTMLS"]["tmp"]["whitelist"][$MD5Ofile]))
1211 return true;
1212 else
1213 return false;
1214 }
1215
1216 function GOTMLS_scanfile($file) {
1217 global $wpdb;
1218 $gt = ">"; // This local variable never changes
1219 $lt = "<"; // This local variable never changes
1220 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"] = "Scanning...";
1221 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1222 $found = false;
1223 $threat_link = "";
1224 $MD5O = "O";
1225 $className = "scanned";
1226 $real_file = realpath($file);
1227 $clean_file = GOTMLS_encode($real_file);
1228 $GLOBALS["GOTMLS"]["tmp"]["file_scan"] = array("start" => microtime(true), "name" => $real_file, "size" => 0, "errors" => array());
1229 if (is_file($real_file) && ($filesize = filesize($real_file)) && GOTMLS_load_contents(@file_get_contents($real_file))) {
1230 $MD5O = md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'O';
1231 $GLOBALS["GOTMLS"]["tmp"]["file_scan"]["size"] = $filesize;
1232 if (GOTMLS_is_whitelisted($MD5O.$filesize))
1233 return GOTMLS_return_threat($className, "checked.gif?$className", $file, $threat_link);
1234 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
1235 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check_custom"]) && GOTMLS_strlen($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check_custom"]) && isset($_GET['eli']) && GOTMLS_verify_regex($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check_custom"]) && ($found = GOTMLS_check_threat($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check_custom"])))
1236 $className = "known";
1237 else {
1238 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, GOTMLS_strlen(ABSPATH))));
1239 if (isset($_SESSION["GOTMLS_debug"])) {
1240 $_SESSION["GOTMLS_debug"]["file"] = $file;
1241 $_SESSION["GOTMLS_debug"]["last"]["total"] = microtime(true);
1242 }
1243 if (isset($GLOBALS["GOTMLS"]["tmp"]["threat_levels"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threat_levels"])) {
1244 foreach ($GLOBALS["GOTMLS"]["tmp"]["threat_levels"] as $threat_level) {
1245 if ("db_scan" != $threat_level) {
1246 if (isset($_SESSION["GOTMLS_debug"])) {
1247 $_SESSION["GOTMLS_debug"]["threat_level"] = $threat_level;
1248 $_SESSION["GOTMLS_debug"]["last"]["threat_level"] = microtime(true);
1249 }
1250 if (in_array($threat_level, $GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check"]) && !$found && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"][$threat_level]) && ($threat_level != "wp_core" || (substr($file, 0, GOTMLS_strlen(ABSPATH)) == ABSPATH && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"]))) && (!isset($GLOBALS["GOTMLS"]["tmp"]["threat_files"]["$threat_level"]) || (substr($file."e", (-1 * GOTMLS_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)))
1251 $className = $threat_level;
1252 }
1253 }
1254 }
1255 if (isset($_SESSION["GOTMLS_debug"])) {
1256 $file_time = round(microtime(true) - $_SESSION["GOTMLS_debug"]["last"]["total"], 5);
1257 if (isset($_SESSION["GOTMLS_debug"]["total"]["total"]))
1258 $_SESSION["GOTMLS_debug"]["total"]["total"] += $file_time;
1259 else
1260 $_SESSION["GOTMLS_debug"]["total"]["total"] = $file_time;
1261 if (isset($_SESSION["GOTMLS_debug"]["total"]["count"]))
1262 $_SESSION["GOTMLS_debug"]["total"]["count"] ++;
1263 else
1264 $_SESSION["GOTMLS_debug"]["total"]["count"] = 1;
1265 if (!isset($_SESSION["GOTMLS_debug"]["total"]["least"]) || $file_time < $_SESSION["GOTMLS_debug"]["total"]["least"])
1266 $_SESSION["GOTMLS_debug"]["total"]["least"] = $file_time;
1267 if (!isset($_SESSION["GOTMLS_debug"]["total"]["most"]) || $file_time > $_SESSION["GOTMLS_debug"]["total"]["most"])
1268 $_SESSION["GOTMLS_debug"]["total"]["most"] = $file_time;
1269 }
1270 }
1271 } else {
1272 GOTMLS_load_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')));
1273 $className = "errors";
1274 }
1275 if (count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1276 $threat_link = $lt.'a target="GOTMLS_iFrame" href="'.GOTMLS_admin_url('GOTMLS_scan', GOTMLS_set_nonce(__FUNCTION__."1275").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$clean_file).'" id="list_'.$clean_file.'" onclick="loadIframe(\''.str_replace("\"", "&quot;", $lt.'div style="float: left; white-space: nowrap;"'.$gt.GOTMLS_strip4java(__("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";
1277 if ($className == "errors") {
1278 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="errors";
1279 $threat_link = GOTMLS_error_link($GLOBALS["GOTMLS"]["tmp"]["file_contents"], $file);
1280 $imageFile = "/blocked";
1281 } elseif ($className != "potential") {
1282 if (isset($_REQUEST["GOTMLS_fix"]) && is_array($_REQUEST["GOTMLS_fix"]) && in_array($clean_file, $_REQUEST["GOTMLS_fix"])) {
1283 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="GOTMLS_fix";
1284 if (GOTMLS_get_nonce()) {
1285 if ($className == "timthumb") {
1286 if (($source = GOTMLS_get_URL("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/timthumb/timthumb.php")) && GOTMLS_strlen($source) > 500)
1287 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1288 else
1289 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
1290 } elseif ($className == 'wp_core') {
1291 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, GOTMLS_strlen(ABSPATH))));
1292 if (substr($file, 0, GOTMLS_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"] != $MD5O.GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])) && ($source = GOTMLS_get_URL(GOTMLS_get_corefile_URL("$path", $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"]))) && ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"] == md5($source)."O".GOTMLS_strlen($source)))
1293 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1294 else
1295 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
1296 } else {
1297 $GOTMLS_no_contents = trim(preg_replace('/\/\*.*?\*\/\s*/s', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
1298 $GOTMLS_no_contents = trim(preg_replace('/\n\s*\/\/.*/', "", $GOTMLS_no_contents));
1299 $GOTMLS_no_contents = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GOTMLS_no_contents));
1300 if (GOTMLS_strlen($GOTMLS_no_contents))
1301 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
1302 else
1303 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = "";
1304 }
1305 if (GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]) > 0 && (($Q_post = GOTMLS_write_quarantine($file, $className)) !== false) && ((GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["new_contents"])==0 && isset($_GET["eli"]) && ($_GET["eli"] == "delete") && @unlink($file)) || (($Write_File = GOTMLS_save_contents($file, $GLOBALS["GOTMLS"]["tmp"]["new_contents"])) !== false))) {
1306 echo __("Success!",'gotmls');
1307 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
1308 } else {
1309 echo __("Failed:",'gotmls').' '.(GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])?((is_writable(dirname($file)) && is_writable($file))?(($Q_post===false)?__("failed to quarantine!",'gotmls')." (".GOTMLS_htmlspecialchars($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'));
1310 if (isset($_GET["eli"]))
1311 echo get_current_user().$lt."br$gt{$lt}pre$gt file_stat".print_r(stat($file), true);
1312 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
1313 }
1314 } else {
1315 echo GOTMLS_Invalid_Nonce(__("Failed: ",'gotmls'));
1316 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
1317 }
1318 }
1319 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]=isset($_POST["GOTMLS_fix"])?"GOTMLS_fix=".GOTMLS_htmlspecialchars(preg_replace('/[\r\n]+/', ' ', print_r($_POST["GOTMLS_fix"],1))):"!potential";
1320 $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;
1321 $imageFile = "threat";
1322 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1323 echo __("Already Fixed!",'gotmls');
1324 return "/*-->*"."/\nfixedFile('$clean_file');\n/*<!--*"."/";
1325 } else
1326 $imageFile = "question";
1327 return GOTMLS_return_threat($className, $imageFile, $file, str_replace("GOTMLS_plugin", "GOTMLS_plugin $className", $threat_link));
1328 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1329 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="Already Fixed";
1330 echo __("Already Fixed!",'gotmls');
1331 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
1332 } else {
1333 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="no threat";
1334 return GOTMLS_return_threat($className, ($className=="scanned"?"checked":"blocked").".gif?$className", $file, $threat_link);
1335 }
1336 }
1337
1338 function GOTMLS_db_scan($id = 0) {
1339 global $wpdb;
1340 $li_js = "";
1341 if (isset($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check"]) && is_array($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check"]) && in_array("db_scan", $GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["check"]) && 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"])) {
1342 if ($id) {
1343 $encoded_id = GOTMLS_encode($id);
1344 $ids = explode(".", $id.'.');
1345 if (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl1' && is_numeric($ids[0]) && ($Q_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_id` = %s", (INT) $ids[0]), ARRAY_A))) {
1346 $path = 'Option ID: '.$Q_post["option_id"];
1347 $clean_file = $Q_post["option_name"];
1348 $fa = "";
1349 GOTMLS_load_contents($Q_post["option_value"]);
1350 $not_serialized = !(is_array(GOTMLS_uckserialize($GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $Q_post["option_value"])));
1351 $found = 0;
1352 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1353 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
1354 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"] = microtime(true);
1355 $threat_name = array_shift($scan_regex);
1356 while ($threat_definition = array_shift($scan_regex))
1357 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1358 }
1359 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1360 $f = 1;
1361 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
1362 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
1363 if ($start > $end)
1364 $fa .= 'ERROR['.($f++).']: Threat_size{'.$threats_found.'} Content_size{'.GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'}';
1365 else
1366 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
1367 }
1368 } else
1369 $fa = " No Threats Found";
1370 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) {
1371 GOTMLS_write_quarantine($Q_post, "db_scan");
1372 if ($_REQUEST["GOTMLS_fixing"] > 1) {
1373 echo "<li>Removing $path ... ";
1374 if ($wpdb->query($wpdb->prepare("DELETE FROM `$wpdb->options` WHERE `option_id` = %s", (INT) $Q_post["option_id"]))) {
1375 echo __("Done!",'gotmls');
1376 $li_js .= "/*-->*"."/\nDeletedFile('$encoded_id');\n/*<!--*"."/";
1377 } else {
1378 echo __("Failed to delete!",'gotmls');
1379 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1380 }
1381 GOTMLS_update_scanlog(array("scan" => array("finish" => time(), "type" => "Removal of Option")));
1382 } else {
1383 echo "<li>Fixing $path ... ";
1384 if ($wpdb->update($wpdb->options, array("option_value" => $GLOBALS["GOTMLS"]["tmp"]["new_contents"]), array('option_id' => $Q_post["option_id"]))) {
1385 echo __("Success!",'gotmls');
1386 $li_js .= "/*-->*"."/\nfixedFile('$encoded_id');\n/*<!--*"."/";
1387 } else {
1388 echo __("Update Failed!",'gotmls');
1389 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1390 }
1391 GOTMLS_update_scanlog(array("scan" => array("finish" => time(), "type" => "Removal from Option")));
1392 }
1393 return $li_js;
1394 } else {
1395 return '<form style="margin: 0;" method="post" action="'.admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."1394")).'" 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: '.(isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])?$GLOBALS["GOTMLS"]["tmp"]["encoding"]:"Unknown").'<br />size: '.GOTMLS_strlen(GOTMLS_convert_r($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(GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"])).'</textarea></td></tr></table>';
1396 }
1397 } elseif (($Q_post = GOTMLS_get_quarantine($ids[0])) && isset($Q_post["post_content"])) {
1398 $path = $Q_post["post_type"].' ID: '.$Q_post["ID"];
1399 $clean_file = $Q_post["post_title"];
1400 $fa = "";
1401 GOTMLS_load_contents($Q_post["post_content"]);
1402 $not_serialized = !(is_array(GOTMLS_uckserialize($GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $Q_post["post_content"])));
1403 $found = 0;
1404 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1405 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
1406 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"] = microtime(true);
1407 $threat_name = array_shift($scan_regex);
1408 while ($threat_definition = array_shift($scan_regex))
1409 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1410 }
1411 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1412 $f = 1;
1413 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
1414 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
1415 if ($start > $end)
1416 $fa .= 'ERROR['.($f++).']: Threat_size{'.$threats_found.'} Content_size{'.GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'}';
1417 else
1418 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
1419 }
1420 } else
1421 $fa = " No Threats Found";
1422 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) {
1423 if ($_REQUEST["GOTMLS_fixing"] > 1) {
1424 echo "<li>Removing $path ... ";
1425 $Q_post["post_status"] = "trash";
1426 if (wp_update_post($Q_post)) {
1427 echo __("Done!",'gotmls');
1428 $li_js .= "/*-->*"."/\nDeletedFile('$encoded_id');\n/*<!--*"."/";
1429 } else {
1430 echo __("Failed to delete!",'gotmls');
1431 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1432 }
1433 GOTMLS_update_scanlog(array("scan" => array("finish" => time(), "type" => "Removal of Revision")));
1434 } else {
1435 echo "<li>Fixing $path ... ";
1436 GOTMLS_write_quarantine($Q_post, "db_scan");
1437 $Q_post["post_content"] = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
1438 if (wp_update_post($Q_post)) {
1439 echo __("Success!",'gotmls');
1440 $li_js .= "/*-->*"."/\nfixedFile('$encoded_id');\n/*<!--*"."/";
1441 } else {
1442 echo __("Update Failed!",'gotmls');
1443 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1444 }
1445 GOTMLS_update_scanlog(array("scan" => array("finish" => time(), "type" => "Removal from Content")));
1446 }
1447 return $li_js;
1448 } else {
1449 return '<form style="margin: 0;" method="post" action="'.admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."1448")).($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: '.(isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])?$GLOBALS["GOTMLS"]["tmp"]["encoding"]:"Unknown").'<br />size: '.GOTMLS_strlen(GOTMLS_convert_r($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(GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"])).'</textarea></td></tr></table>';
1450 }
1451 } else
1452 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>"))));
1453 } else {
1454 $threats_found = array();
1455 $and = "";
1456 if (!isset($_REQUEST["eli"]))
1457 $and .= " AND `post_status` != 'trash'";
1458 if (isset($_REQUEST["limit"]) && is_numeric($_REQUEST["limit"]))
1459 $and .= " LIMIT ".((INT) $_REQUEST["limit"]);
1460 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"])) {
1461 if (isset($_GET["GOTMLS_scan"]) && GOTMLS_strlen($_GET["GOTMLS_scan"]) > 8 && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][substr($_GET["GOTMLS_scan"], 8)])) {
1462 $scan_replace = str_replace("db_scan", "Database for ", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1463 $db_scan_a = array(GOTMLS_sanitize(substr($_GET["GOTMLS_scan"], 8)) => $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][substr($_GET["GOTMLS_scan"], 8)]);
1464 } elseif (isset($_GET["GOTMLS_only_file"]) && GOTMLS_strlen($_GET["GOTMLS_only_file"]) && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][GOTMLS_decode($_GET["GOTMLS_only_file"])])) {
1465 $scan_replace = str_replace("db_scan", ("Database only $and for "), GOTMLS_htmlspecialchars("db_scan=".htmlspecialchars_decode(GOTMLS_decode($_GET["GOTMLS_only_file"]))));
1466 $_GET["GOTMLS_scan"] = "db_scan=".GOTMLS_decode($_GET["GOTMLS_only_file"]);
1467 $db_scan_a = array(GOTMLS_decode($_GET["GOTMLS_only_file"]) => $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][GOTMLS_decode($_GET["GOTMLS_only_file"])]);
1468 } else {
1469 $scan_replace = str_replace("db_scan", "Database", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1470 $db_scan_a = $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"];
1471 }
1472 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), $scan_replace));
1473 GOTMLS_flush();
1474 $li_js .= "/*<!--*"."/".GOTMLS_return_threat("dir", "checked", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"])).GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), $scan_replace));
1475 } else {
1476 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("No Definitions for DB Injections!",'gotmls')));
1477 GOTMLS_flush();
1478 $li_js .= GOTMLS_return_threat("error", "question", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1479 $db_scan_a = GOTMLS_sanitize($_GET["GOTMLS_scan"]);
1480 }
1481 if (isset($db_scan_a) && is_array($db_scan_a)) {
1482 echo "\n//memory_limit=".@ini_get("memory_limit")."\n";
1483 foreach ($db_scan_a as $scan_sql => $scan_regex) {
1484 if (!in_array(GOTMLS_sanitize($scan_sql), $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["dont_check"])) {
1485 $SQL = preg_replace('/\{[a-f0-9]{64}\}/', '%', $wpdb->prepare("SELECT * FROM `$wpdb->posts` WHERE `post_content` LIKE %s $and", $scan_sql));
1486 $threat_name = array_shift($scan_regex);
1487 if (($found_row = $wpdb->get_results($SQL, ARRAY_A)) && is_array($found_row) && count($found_row)) {
1488 $val = count($found_row);
1489 if (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1490 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("$val Rows", 0));//debug
1491 foreach ($found_row as $frow) {
1492 $encoded_id = GOTMLS_encode($frow["ID"].'.0');
1493 $found = 0;
1494 if ($frow["post_type"] != "revision" || isset($_REQUEST["eli"])) {
1495 GOTMLS_load_contents($frow["post_content"]);
1496 $not_serialized = !(is_array(GOTMLS_uckserialize($frow["post_content"])));
1497 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1498 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"] = microtime(true);
1499 foreach ($scan_regex as $threat_definition)
1500 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1501 if ($found && !isset($threats_found['row_id_'.$encoded_id])) {
1502 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")));
1503 $threats_found['row_id_'.$encoded_id] = $threat_name;
1504 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1505 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
1506 }
1507 }
1508 }
1509 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)) {
1510 $val = count($found_row);
1511 if (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1512 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("$val Rows", 0));//debug
1513 foreach ($found_row as $frow) {
1514 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["last_threat"] = microtime(true);
1515 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1516 $encoded_id = GOTMLS_encode($frow["option_id"].'.1');
1517 $found = 0;
1518 GOTMLS_load_contents($frow["option_value"]);
1519 $not_serialized = !(is_array(GOTMLS_uckserialize($frow["option_value"])));
1520 foreach ($scan_regex as $threat_definition)
1521 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1522 if ($found && !isset($threats_found['row_id_'.$encoded_id])) {
1523 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"));
1524 $threats_found['row_id_'.$encoded_id] = $threat_name;
1525 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1526 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
1527 }
1528 }
1529 }
1530 }
1531 }
1532 //
1533 }
1534 } else {
1535 $li_js .= "/*<!--*"."/".GOTMLS_return_threat("skipdirs", "blocked", "db_scan").GOTMLS_update_status(__("Skipped DB Scan",'gotmls'));
1536 }
1537 GOTMLS_update_scanlog(array("scan" => array("finish" => time())));
1538 return "$li_js/*-->*"."/\nscanNextDir(-1);\n/*<!--*"."/";
1539 }
1540
1541 function GOTMLS_remove_dots($dir) {
1542 if ($dir != "." && $dir != "..")
1543 return $dir;
1544 }
1545
1546 function GOTMLS_getfiles($dir) {
1547 $files = false;
1548 if (is_dir($dir)) {
1549 if (function_exists("scandir"))
1550 $files = @scandir($dir);
1551 if (is_array($files))
1552 $files = array_filter($files, "GOTMLS_remove_dots");
1553 elseif ($handle = @opendir($dir)) {
1554 $files = array();
1555 while (false !== ($entry = readdir($handle)))
1556 if ($entry != "." && $entry != "..")
1557 $files[] = "$entry";
1558 closedir($handle);
1559 } else
1560 $files = GOTMLS_read_error($dir);
1561 }
1562 return $files;
1563 }
1564
1565 function GOTMLS_return_threat($className, $imageFile, $fileName, $link = "") {
1566 global $GOTMLS_image_alt;
1567 $fileNameJS = GOTMLS_strip4java(str_replace("db_scan", "Database", str_replace("db_scan=", "Database Query ", GOTMLS_replace_dirname(htmlspecialchars_decode($fileName)))));
1568 $fileName64 = GOTMLS_encode(htmlspecialchars_decode($fileName));
1569 $li_js = "/*-->*"."/";
1570 $imageF = explode(".", $imageFile.".");
1571 if ($className != "scanned")
1572 $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[$imageF[0]].'" style="float: left;" id="'.$imageFile."_$fileName64\">".GOTMLS_strip4java($link, true).$fileNameJS.($link?"</a>';\n\tdivx.display='block":"")."';\n\tdivx.appendChild(newli);\n}";
1573 elseif ($GLOBALS["GOTMLS"]["scan"]["log"]["settings"]["scan_depth"] == 1) {
1574 if (isset($GLOBALS["GOTMLS"]["tmp"]["file_scan"]["errors"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["file_scan"]["errors"]) && count($GLOBALS["GOTMLS"]["tmp"]["file_scan"]["errors"]))
1575 $text = preg_replace('/[\r\n]/', " ", print_r($GLOBALS["GOTMLS"]["tmp"]["file_scan"]["errors"],1));
1576 else
1577 $text = (isset($GLOBALS["GOTMLS"]["tmp"]["file_scan"]["size"]) ? $GLOBALS["GOTMLS"]["tmp"]["file_scan"]["size"]." bytes" : "Size Errors");
1578 $link = GOTMLS_error_link(htmlspecialchars($text), $fileName, substr($text, -1)=="s"?$className:"potential");
1579 $li_js .= "\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[$imageF[0]].'" style="float: left;" id="'.$imageFile."_$fileName64\">".round(microtime(true)-$GLOBALS["GOTMLS"]["tmp"]["file_scan"]["start"], 4).GOTMLS_strip4java($link, true).$fileNameJS.($link?"</a>';\n\tdivx.display='block":"")."';\n\tdivx.appendChild(newli);\n}";
1580 }
1581 if ($className == "errors")
1582 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx) {\n\tdivx.src='".GOTMLS_images_path."blocked.gif';\n\tdirerrors++;\n}";
1583 elseif (is_file($fileName))
1584 $li_js .= "\nscanned++;\n";
1585 if ($className == "dir")
1586 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx)\n\tdivx.src='".GOTMLS_images_path."checked.gif';";
1587 return $li_js."\n/*<!--*"."/";
1588 }
1589
1590 function GOTMLS_slash($dir = __FILE__) {
1591 if (substr($dir.' ', 1, 1) == ':' || substr($dir.' ', 0, 1) == "\\")
1592 return "\\";
1593 else
1594 return '/';
1595 }
1596
1597 function GOTMLS_trailingslashit($dir = "") {
1598 if (substr(' '.$dir, -1) != GOTMLS_slash($dir))
1599 $dir .= GOTMLS_slash($dir);
1600 return $dir;
1601 }
1602
1603 function GOTMLS_explode_dir($dir, $pre = '') {
1604 if (GOTMLS_strlen($pre))
1605 $dir = GOTMLS_slash($dir).$pre.$dir;
1606 return explode(GOTMLS_slash($dir), $dir);
1607 }
1608
1609 function GOTMLS_html_tags($tags, $inner = array()) {
1610 $html = "";
1611 $gt = ">"; // This local variable never changes
1612 if (!is_array($tags))
1613 $tags = array($tags => (is_array($inner)?(isset($inner["contents"])?$inner["contents"]:""):$inner));
1614 foreach ($tags as $tag => $contents) {
1615 if (!is_numeric($tag))
1616 $html .= ($tag=="html"?"<!DOCTYPE html$gt":"")."<$tag".(isset($inner[$tag])?" ".$inner[$tag]:"").$gt;
1617 if (is_array($contents))
1618 $html .= GOTMLS_html_tags($contents, $inner);
1619 else
1620 $html .= $contents;
1621 if ((!is_numeric($tag)) && substr($tag, -1) != '/')
1622 $html .= "</$tag$gt";
1623 }
1624 return $html;
1625 }
1626
1627 function GOTMLS_write_quarantine($file, $className, $post_status = "private") {
1628 global $wpdb;
1629 $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"]), "post_name"=>$className, "post_status"=>$post_status, "post_type"=>"GOTMLS_quarantine", "post_content_filtered"=>GOTMLS_encode($GLOBALS["GOTMLS"]["tmp"]["new_contents"]), "guid"=>GOTMLS_Version);
1630 if (isset($file["ID"]) && is_numeric($file["ID"])) {
1631 $insert["post_modified"] = $file["post_modified"];
1632 $insert["post_modified_gmt"] = $file["post_modified_gmt"];
1633 $file = $file["post_type"].':'.$file["ID"].':"'.$file["post_title"].'"';
1634 } elseif (isset($file["option_id"]) && is_numeric($file["option_id"])) {
1635 $insert["post_modified"] = gmdate("Y-m-d H:i:s");
1636 $insert["post_modified_gmt"] = gmdate("Y-m-d H:i:s");
1637 $file = $wpdb->options.':'.$file["option_id"].':"'.$file["option_name"].'"';
1638 }
1639 $insert["comment_count"] = GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1640 $insert["post_title"] = $file;
1641 $insert["post_date"] = gmdate("Y-m-d H:i:s");
1642 $insert["post_date_gmt"] = $insert["post_date"];
1643 if (is_file($file)) {
1644 if (@filemtime($file))
1645 $insert["post_modified"] = gmdate("Y-m-d H:i:s", filemtime($file));
1646 else
1647 $insert["post_modified"] = $insert["post_date"];
1648 if (@filectime($file))
1649 $insert["post_modified_gmt"] = gmdate("Y-m-d H:i:s", filectime($file));
1650 else
1651 $insert["post_modified_gmt"] = $insert["post_date"];
1652 if (!($insert["comment_count"] = @filesize($file)))
1653 $insert["comment_count"] = GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1654 }
1655 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1656 $insert["post_excerpt"] = GOTMLS_encode(@serialize($GLOBALS["GOTMLS"]["tmp"]["threats_found"]));
1657 $pinged = array();
1658 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $loc => $threat_name) {
1659 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][0]) && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1]) && GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][0]) == 5 && GOTMLS_strlen($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1]))
1660 $ping = $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1];
1661 else
1662 $ping = $threat_name;
1663 if (isset($pinged[$ping]))
1664 $pinged[$ping]++;
1665 else
1666 $pinged[$ping] = 1;
1667 }
1668 $insert["pinged"] = GOTMLS_encode(@serialize($pinged));
1669 }
1670 if ($return = $wpdb->insert($wpdb->posts, $insert))
1671 return $return;
1672 else
1673 die(print_r(array('return'=>($return===false)?"FALSE":$return, 'last_error'=>$wpdb->last_error, 'insert'=>$insert),1));
1674 }
1675
1676 function GOTMLS_update_status($status, $percent = -1) {
1677 if (!(isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]) && is_numeric($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"])))
1678 $GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"] = time();
1679 $microtime = ceil(time()-$GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["start"]);
1680 if (($percent > 0) || isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["finish"]))
1681 GOTMLS_update_scanlog(array("scan" => array("microtime" => $microtime, "percent" => $percent)), $status);
1682 return "/*-->*"."/\nupdate_status('".GOTMLS_strip4java($status)."', $microtime, $percent);\n/*<!--*"."/";
1683 }
1684
1685 function GOTMLS_flush($tag = "") {
1686 $output = "";
1687 if (($output = @ob_get_contents()) && GOTMLS_strlen(trim($output)) > 18) {
1688 @ob_clean();
1689 if (!(isset($_GET["eli"]) && $_GET["eli"] == "debug"))
1690 $output = preg_replace('/\/\*<\!--\*\/.*?\/\*-->\*\//s', "", "$output/*-->*"."/");
1691 echo "$output\n//flushed(".GOTMLS_strlen(trim($output)).")\n";
1692 if ($tag)
1693 echo "\n</$tag>\n";
1694 if (@ob_get_length())
1695 @ob_flush();
1696 if ($tag)
1697 echo "<$tag>\n";
1698 echo "/*<!--*"."/";
1699 }
1700 }
1701
1702 function GOTMLS_replace_dirname($dir, $replace_with = "...") {
1703 return (isset($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["dir"]) ? str_replace(dirname($GLOBALS["GOTMLS"]["scan"]["log"]["scan"]["dir"]), $replace_with, $dir) : $dir);
1704 }
1705
1706 function GOTMLS_readdir($dir, $current_depth = 1) {
1707 global $GOTMLS_dirs_at_depth, $GOTMLS_dir_at_depth, $GOTMLS_total_percent;
1708 if ($current_depth) {
1709 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1710 $entries = GOTMLS_getfiles($dir);
1711 if (is_array($entries)) {
1712 echo GOTMLS_return_threat("dirs", "wait", $dir).GOTMLS_update_status(sprintf(__("Preparing %s",'gotmls'), GOTMLS_replace_dirname($dir)), $GOTMLS_total_percent);
1713 $files = array();
1714 $directories = array();
1715 foreach ($entries as $entry) {
1716 if (is_dir(GOTMLS_trailingslashit($dir).$entry))
1717 $directories[] = $entry;
1718 else
1719 $files[] = $entry;
1720 }
1721 if ($_REQUEST["scan_type"] == "Quick Scan") {
1722 $GOTMLS_dirs_at_depth[$current_depth] = count($directories);
1723 $GOTMLS_dir_at_depth[$current_depth] = 0;
1724 } else
1725 $GLOBALS["GOTMLS"]["tmp"]["scanfiles"][GOTMLS_encode($dir)] = GOTMLS_strip4java(GOTMLS_replace_dirname($dir));
1726 foreach ($directories as $directory) {
1727 $path = GOTMLS_trailingslashit($dir).$directory;
1728 if (isset($_REQUEST["scan_depth"]) && is_numeric($_REQUEST["scan_depth"]) && ($_REQUEST["scan_depth"] != $current_depth) && (!((($Recusive = strpos(GOTMLS_trailingslashit($dir), '/'.$directory.'/')) !== FALSE) && is_dir($dir.substr($dir, $Recusive).substr($dir, $Recusive).substr($dir, $Recusive)))) && !in_array($directory, $GLOBALS["GOTMLS"]["tmp"]["skip_dirs"]) && !in_array($path, $GLOBALS["GOTMLS"]["tmp"]["skip_dirs"])) {
1729 $current_depth++;
1730 $current_depth = GOTMLS_readdir($path, $current_depth);
1731 } else {
1732 if (!(isset($_REQUEST["scan_only"]) && is_array($_REQUEST["scan_only"])&& in_array($directory, $_REQUEST["scan_only"])))
1733 echo GOTMLS_return_threat("skipdirs", "blocked", $path, '<a title="'.(in_array($directory, $GLOBALS["GOTMLS"]["tmp"]["skip_dirs"])||in_array($path, $GLOBALS["GOTMLS"]["tmp"]["skip_dirs"])?"Directory is on Skip List":"Directory is below Scan Depth").'">');
1734 $GOTMLS_dir_at_depth[$current_depth] = (isset($GOTMLS_dir_at_depth[$current_depth])?$GOTMLS_dir_at_depth[$current_depth]:0) + 1;
1735 }
1736 }
1737 if ($_REQUEST["scan_type"] == "Quick Scan") {
1738 $echo = "";
1739 echo GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), GOTMLS_replace_dirname($dir)), $GOTMLS_total_percent);
1740 GOTMLS_flush("script");
1741 foreach ($files as $file)
1742 echo GOTMLS_check_file(GOTMLS_trailingslashit($dir).$file);
1743 echo GOTMLS_return_threat("dir", "checked", $dir);
1744 }
1745 } else
1746 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' readdir:'.($entries===false?'('.GOTMLS_fileperms($dir).')':$entries)));
1747 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1748 if ($current_depth-- && $_REQUEST["scan_type"] == "Quick Scan") {
1749 $GOTMLS_dir_at_depth[$current_depth] = (isset($GOTMLS_dir_at_depth[$current_depth])?$GOTMLS_dir_at_depth[$current_depth]:0) + 1;
1750 for ($GOTMLS_total_percent = 0, $depth = $current_depth; $depth >= 0; $depth--) {
1751 if (!isset($GOTMLS_dir_at_depth[$depth]))
1752 $GOTMLS_dir_at_depth[$depth] = 0;
1753 echo "\n//(($GOTMLS_total_percent / $GOTMLS_dirs_at_depth[$depth]) + ($GOTMLS_dir_at_depth[$depth] / $GOTMLS_dirs_at_depth[$depth])) = ";
1754 $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)));
1755 echo "$GOTMLS_total_percent\n";
1756 }
1757 $GOTMLS_total_percent = floor($GOTMLS_total_percent * 100);
1758 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), GOTMLS_replace_dirname($dir)), $GOTMLS_total_percent);
1759 }
1760 GOTMLS_flush("script");
1761 }
1762 return $current_depth;
1763 }
1764
1765 function GOTMLS_sexagesimal($timestamp = 0) {
1766 if (!is_numeric($timestamp) && GOTMLS_strlen($timestamp) == 5) {
1767 $delim = array("=", "-", "-", " ", ":");
1768 foreach (str_split($timestamp) as $bit)
1769 $timestamp .= array_shift($delim).substr("00".(ord($bit)>96?ord($bit)-61:(ord($bit)>64?ord($bit)-55:ord($bit)-48)), -2);
1770 return "20".substr($timestamp, -14);
1771 } else {
1772 $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])$/';
1773 if (preg_match($match, $timestamp))
1774 $date = preg_replace($match, "\\2-\\3-\\4-\\5-\\6", $timestamp);
1775 elseif ($timestamp && strtotime($timestamp))
1776 $date = date("y-m-d-H-i", strtotime($timestamp));
1777 else
1778 $date = gmdate("y-m-d-H-i", time());
1779 foreach (explode("-", $date) as $bit)
1780 $date .= (intval($bit)>35?chr(ord("a")+intval($bit)-36):(intval($bit)>9?chr(ord("A")+intval($bit)-10):substr('0'.$bit, -1)));
1781 return substr($date, -5);
1782 }
1783 }
1784
1785 if (!function_exists('ur1encode')) { function ur1encode($url) {
1786 $return = "";
1787 foreach (str_split($url) as $char)
1788 $return .= '%'.substr('00'.strtoupper(dechex(ord($char))),-2);
1789 return $return;
1790 }}
1791
1792 function GOTMLS_strip4java($item, $htmlentities = false) {
1793 return preg_replace("/\\\\/", "\\\\\\\\", str_replace("'", "'+\"'\"+'", preg_replace('/\\+n|\\+r|\n|\r|\0/', "", ($htmlentities?$item:GOTMLS_htmlentities($item)))));
1794 }
1795
1796 function GOTMLS_error_link($errorTXT, $file = "", $class = "errors") {
1797 global $post, $wpdb;
1798 $encoded_file = GOTMLS_encode($file);
1799 $ids = explode(".", $file.'.');
1800 if (isset($post->post_title))
1801 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($post->post_title, ENT_NOQUOTES));
1802 elseif (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl1' && is_numeric($ids[0]))
1803 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($wpdb->get_var($wpdb->prepare("SELECT CONCAT('option', `option_id`, ': ', `option_name`) FROM `$wpdb->options` WHERE `option_id` = %s", (INT) $ids[0])), ENT_NOQUOTES));
1804 elseif (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl0' && is_numeric($ids[0]))
1805 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($wpdb->get_var($wpdb->prepare("SELECT CONCAT(`post_type`, `ID`, ': ', `post_title`) FROM `$wpdb->posts` WHERE `ID` = %s", (INT) $ids[0])), ENT_NOQUOTES));
1806 else
1807 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($file, ENT_NOQUOTES));
1808 $nonce_url = GOTMLS_set_nonce(__FUNCTION__."1823");
1809 if (count($ids) == 2 && is_numeric($ids[0])) {
1810 $encoded_file = (INT) $file;
1811 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.GOTMLS_strip4java(__("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="'.GOTMLS_admin_url('GOTMLS_scan', $nonce_url.'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$encoded_file);
1812 } elseif ($file)
1813 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.GOTMLS_strip4java(__("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="'.GOTMLS_admin_url('GOTMLS_scan', $nonce_url.'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$encoded_file);
1814 else
1815 $onclick = 'return false;';
1816 return "<a id=\"list_$encoded_file\" title=\"$errorTXT\" target=\"GOTMLS_iFrame\" onclick=\"$onclick\" class=\"GOTMLS_plugin $class\">";
1817 }
1818
1819 function GOTMLS_check_file($file) {
1820 $filesize = @filesize($file);
1821 $MD5O = @md5_file($file)."O";
1822 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checking ".GOTMLS_strip4java($file)." ($filesize bytes)';\n/*<!--*"."/";
1823 if ($filesize===false)
1824 echo GOTMLS_return_threat("errors", "blocked", $file, GOTMLS_error_link(__("Failed to determine file size!",'gotmls'), $file));
1825 elseif (GOTMLS_is_whitelisted($MD5O.$filesize, $file))
1826 echo GOTMLS_return_threat("scanned", "checked", $file, GOTMLS_error_link(__("CORE file was not modified!",'gotmls'), $file, ""));
1827 elseif (($filesize==0) || ($filesize>((isset($_REQUEST["oversize"])&&is_numeric($_REQUEST["oversize"]))?$_REQUEST["oversize"]:2934567)))
1828 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file size!",'gotmls')." ($filesize bytes)", $file, "potential"));
1829 elseif (in_array(GOTMLS_get_ext($file), $GLOBALS["GOTMLS"]["tmp"]["skip_ext"]) && !(preg_match('/(?:(?:shim|social\d*+)\.png|\/\.[^\/]++)$/i', $file)))
1830 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file extention!",'gotmls'), $file, "potential"));
1831 elseif (isset($GLOBALS["GOTMLS"]["tmp"]["custom_whitelist"]) && isset($GLOBALS["GOTMLS"]["tmp"]["custom_whitelist"]["$MD5O$filesize"]))
1832 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because file was Whitelisted!",'gotmls'), $file, "potential"));
1833 else {
1834 try {
1835 echo @GOTMLS_scanfile($file);
1836 echo "/*-->*"."/\n//debug_fix:".$GLOBALS["GOTMLS"]["tmp"]["debug_fix"]."\n/*<!--*"."/";
1837 } catch (Exception $e) {
1838 die("//Exception:".GOTMLS_strip4java($e));
1839 }
1840 }
1841 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checked ".GOTMLS_strip4java($file)."';\n/*<!--*"."/";
1842 }
1843
1844 function GOTMLS_read_error($path) {
1845 $error = error_get_last();
1846 if (!file_exists($path))
1847 return " (Path not found)";
1848 if (!is_readable($path) && isset($_GET["eli"]))
1849 $return = (@chmod($path, (is_dir($path)?GOTMLS_CHMOD_DIR:GOTMLS_CHMOD_FILE))?"Fixed permissions":"error: ".preg_replace('/[\r\n]/', ' ', print_r($error,1)));
1850 else
1851 $return = (is_array($error) && isset($error["message"])?preg_replace('/[\r\n]/', ' ', print_r($error["message"],1)):"readable?");
1852 return " [".GOTMLS_fileperms($path)."] ( ".filesize($path)." $return)";
1853 }
1854
1855 function GOTMLS_scandir($dir) {
1856 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), GOTMLS_replace_dirname(GOTMLS_htmlspecialchars($dir))));
1857 GOTMLS_flush();
1858 $li_js = "/*-->*"."/\nscanNextDir(-1);\n/*<!--*"."/";
1859 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]) && $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]))
1860 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link("Directory Scan Depth set to 0, no files will be scanned!"));
1861 elseif (isset($_GET["GOTMLS_skip_dir"]) && $dir == GOTMLS_decode($_GET["GOTMLS_skip_dir"])) {
1862 if (isset($_GET["GOTMLS_only_file"]) && GOTMLS_strlen($_GET["GOTMLS_only_file"]))
1863 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"])));
1864 else
1865 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(__("Failed to read directory!",'gotmls')).GOTMLS_read_error($dir));
1866 } else {
1867 if (is_dir($dir) && is_array($files = GOTMLS_getfiles($dir))) {
1868 if (isset($_GET["GOTMLS_only_file"])) {
1869 if (GOTMLS_strlen($_GET["GOTMLS_only_file"])) {
1870 $path = GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"]);
1871 if (is_file($path)) {
1872 GOTMLS_check_file($path);
1873 echo GOTMLS_return_threat("dir", "checked", $path);
1874 }
1875 } else {
1876 foreach ($files as $file) {
1877 $path = GOTMLS_trailingslashit($dir).$file;
1878 if (is_file($path)) {
1879 $file_ext = GOTMLS_get_ext($file);
1880 $filesize = @filesize($path);
1881 if ((in_array($file_ext, $GLOBALS["GOTMLS"]["tmp"]["skip_ext"]) && !(preg_match('/(?:(?:shim|social\d*+)\.png|\/\.[^\/]++)$/i', $file))) || ($filesize==0) || ($filesize>((isset($_REQUEST["oversize"])&&is_numeric($_REQUEST["oversize"]))?$_REQUEST["oversize"]:2934567)))
1882 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"));
1883 else
1884 echo "/*-->*"."/\nscanfilesArKeys.push('".GOTMLS_encode($dir)."&GOTMLS_only_file=".GOTMLS_encode($file, "D")."');\nscanfilesArNames.push('Re-Checking ".GOTMLS_strip4java($path)."');\n/*<!--*"."/".GOTMLS_return_threat("dirs", "wait", $path);
1885 } elseif (is_dir($path)) {
1886 echo "/*-->*"."/\n//sub-directory $path;\n/*<!--*"."/";
1887 }
1888 }
1889 echo GOTMLS_return_threat("dir", "question", $dir);
1890 }
1891 } else {
1892 foreach ($files as $file) {
1893 $path = GOTMLS_trailingslashit($dir).$file;
1894 if (is_file($path)) {
1895 if (isset($_GET["GOTMLS_skip_file"]) && is_array($_GET["GOTMLS_skip_file"]) && in_array($path, $_GET["GOTMLS_skip_file"])) {
1896 $li_js .= "/*-->*"."/\n//skipped $path;\n/*<!--*"."/";
1897 if ($_GET["GOTMLS_skip_file"][count($_GET["GOTMLS_skip_file"])-1] == $path)
1898 echo GOTMLS_return_threat("errors", "blocked", $path, GOTMLS_error_link(__("Failed to read file!",'gotmls'), $path));
1899 } else {
1900 GOTMLS_check_file($path);
1901 }
1902 } elseif (is_dir($path)) {
1903 $li_js .= "/*-->*"."/\n//sub-directory $path;\n/*<!--*"."/";
1904 }
1905 }
1906 echo GOTMLS_return_threat("dir", "checked", $dir);
1907 }
1908 } else
1909 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' scandir:'.($files===false?' (FALSE)':$files)));
1910 }
1911 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), GOTMLS_replace_dirname($dir)));
1912 return $li_js;
1913 }
1914
1915 function GOTMLS_safe_domain($domain) {
1916 return preg_replace('/[^a-z_0-9\-\~\+\.\?\#\/\:\@]/i', "", $domain);
1917 }
1918
1919 function GOTMLS_safe_url($url, $allow = array(' ', '%20')) {
1920 $all = implode("", array_keys($allow));
1921 $url = preg_replace('/[^a-z_0-9\-\~\+\.\?\#\/\:\@\%\$\|\*\(\)\[\]\=\!\&\;'.$all.']/i', "", $url);
1922 foreach ($allow as $al => $low)
1923 $url = str_replace($al, $low, ltrim($url));
1924 return $url;
1925 }
1926
1927 function GOTMLS_reset_settings($item, $key) {
1928 $key_parts = explode("_", $key."_");
1929 if (GOTMLS_strlen($key_parts[0]) != 4 && $key_parts[0] != "exclude")
1930 unset($GLOBALS["GOTMLS"]["tmp"]["settings_array"][$key]);
1931 }
1932
1933 function GOTMLS_sanitize($unsanitized, $allow = 'a-zA-Z0-9\|\[\]\{\}<>\s\?\*\%\#\&\/=_\~\:;\.,\+-') {
1934 if (is_array($unsanitized)) {
1935 $sanitized = array();
1936 foreach ($unsanitized as $key => $val)
1937 $sanitized[preg_replace('/[^'.$allow.']/', '', $key)] = preg_replace('/[^'.$allow.']/', '', $val);
1938 } else
1939 $sanitized = preg_replace('/[^'.$allow.']/', '', $unsanitized);
1940 return $sanitized;
1941 }
1942
1943 function GOTMLS_get_URL($URL) {
1944 $response = "";
1945 $GLOBALS["GOTMLS"]["get_URL"] = GOTMLS_get_option('get_URL', array());
1946 $min = round($GLOBALS["GOTMLS"]["MT"]/60);
1947 if (is_array($GLOBALS["GOTMLS"]["get_URL"]) && !preg_match('/\&dt=\d++/', $URL)) {
1948 foreach ($GLOBALS["GOTMLS"]["get_URL"] as $URI => $property)
1949 if (!(isset($property["time"]) && is_numeric($property["time"]) && ($property["time"] + 30) > $min))
1950 unset($GLOBALS["GOTMLS"]["get_URL"]["$URI"]);
1951 } else
1952 $GLOBALS["GOTMLS"]["get_URL"] = array();
1953 $URI = md5(preg_replace('/GOTMLS_mt[\[\]]*+=[a-f\d]*+/i', "", $URL));
1954 if (isset($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"]) && GOTMLS_strlen($response = ($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"])))
1955 $method = "cached";
1956 else {
1957 $GLOBALS["GOTMLS"]["get_URL"]["$URI"] = array("time" => $min);
1958 if (function_exists($method = "wp_remote_get")) {
1959 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = wp_remote_get($URL, array("sslverify" => false));
1960 if (200 == wp_remote_retrieve_response_code($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method])) {
1961 $response = wp_remote_retrieve_body($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]);
1962 if (isset($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]["http_response"]))
1963 unset($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]["http_response"]);
1964 if (isset($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]["body"]))
1965 unset($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]["body"]);
1966 }
1967 }
1968 if (GOTMLS_strlen($response) == 0 && function_exists($method = "curl_exec")) {
1969 $curl_hndl = curl_init();
1970 curl_setopt($curl_hndl, CURLOPT_URL, $URL);
1971 curl_setopt($curl_hndl, CURLOPT_TIMEOUT, 30);
1972 if (isset($_SERVER['HTTP_REFERER']))
1973 $SERVER_HTTP_REFERER = GOTMLS_safe_url($_SERVER['HTTP_REFERER']);
1974 elseif (isset($_SERVER['HTTP_HOST']))
1975 $SERVER_HTTP_REFERER = 'HOST://'.GOTMLS_safe_domain($_SERVER['HTTP_HOST']);
1976 elseif (isset($_SERVER['SERVER_NAME']))
1977 $SERVER_HTTP_REFERER = 'NAME://'.GOTMLS_safe_domain($_SERVER['SERVER_NAME']);
1978 elseif (isset($_SERVER['SERVER_ADDR']))
1979 $SERVER_HTTP_REFERER = 'ADDR://'.GOTMLS_safe_ip($_SERVER['SERVER_ADDR']);
1980 else
1981 $SERVER_HTTP_REFERER = 'NULL://not.anything.com';
1982 curl_setopt($curl_hndl, CURLOPT_REFERER, $SERVER_HTTP_REFERER);
1983 if (isset($_SERVER['HTTP_USER_AGENT']))
1984 curl_setopt($curl_hndl, CURLOPT_USERAGENT, GOTMLS_safe_url($_SERVER['HTTP_USER_AGENT'], array(' ', ' ')));
1985 curl_setopt($curl_hndl, CURLOPT_HEADER, 0);
1986 curl_setopt($curl_hndl, CURLOPT_RETURNTRANSFER, TRUE);
1987 if (!($response = curl_exec($curl_hndl)))
1988 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = curl_error($curl_hndl);
1989 curl_close($curl_hndl);
1990 }
1991 if (GOTMLS_strlen($response) == 0 && function_exists($method = "file_get_contents")) {
1992 try {
1993 $response = @file_get_contents($URL).'';
1994 } catch(Exception $e) {
1995 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = $e->getTrace();
1996 }
1997 }
1998 $GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"] = ($response);
1999 }
2000 GOTMLS_update_option('get_URL', $GLOBALS["GOTMLS"]["get_URL"], false);
2001 if (isset($_GET["GOTMLS_debug"]) && (GOTMLS_strlen($response) == 0 || $_GET["GOTMLS_debug"] == "GOTMLS_get_URL"))
2002 print_r(array("$method $URI:".GOTMLS_strlen($response)=>htmlspecialchars($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["time"]." ~ $min: ".count($GLOBALS["GOTMLS"]["get_URL"]))));
2003 return $response;
2004 }
2005