/** * If the given $source is an error type, it will display an instant message * * @param $source WP_Error|TranslationProxy_Api_Error|Exception */ function icl_handle_error($source) { $error = false; if (is_translationproxy_api_error($source)) { $error = array('message' => $source->getMessage(), 'code' => $source->getCode()); } elseif (is_exception($source)) { $error = array('message' => $source->getMessage(), 'code' => $source->getCode()); } elseif (is_wp_error($source)) { $error = array('message' => $source->get_error_message(), 'data' => $source->get_error_data(), 'code' => $source->get_error_code()); } if ($error) { $message = ''; $message .= '<strong>'; if (isset($error['code']) && $error['code']) { $message .= '#' . $error['code'] . ' '; } $message .= $error['message']; $message .= '</strong>'; if (isset($error['data'])) { foreach ($error['data'] as $data_key => $data_item) { if ($data_key == 'details') { $message .= '<br/>Details: ' . $data_item; } elseif ($data_key == 'service_id') { $message .= '<br/>Service ID: ' . $data_item; } else { $message .= '<br/><pre>' . print_r($data_item, true) . '</pre>'; } } } ICL_AdminNotifier::displayInstantMessage($message, 'error'); } return $error; }
function check_trojan($directory) { //定义挂马语句和webshell特征字符串的正则表达式.. $troscript = "/(iframe)|(exec\\()|(system\\()|(shell_exec)|(proc_open) |(wscript.shell)|(eval\\(\$_)/i"; //加模式修正符i表示不区分大小写.. $check_trojan_dir = @opendir($directory); while ($file = @readdir($check_trojan_dir)) { if (is_exception($directory, $file)) { continue; } if (is_dir("{$directory}/{$file}")) { check_trojan("{$directory}/{$file}"); //递归调用 } else { $handle = file(trim($directory . "/" . $file)); $notes_length = count($handle); for ($i = 0; $i < $notes_length; $i++) { $content = $handle[$i]; //搜索$file文件中的字符是否包含正则表达式中的挂马和webshell特征字符串.. if (preg_match($troscript, $content, $arr)) { //print_r ($arr); $i = $i + 1; //校正行数. print_r("warning trojan code " . $arr[0] . " found in " . $directory . "/" . $file . " line {$i} <br>"); } } } } closedir($check_trojan_dir); }
/** * Based on a function and user ID passed, uses the \mfoley\SQL helper class to operate on a given database * * @param string $userID The base64 representation of the user's ID, used as a key in the table. * @param string $task The function requested through the url. * @param string $db_name The path which contains the sqlite3 database to be connected to. * @return array Array with a key indicating success or failure, and a more specific key for function specific returns. */ function run_task($userID, $task, $db_name) { $db = null; $success = array("result" => "success"); $failure = array("result" => "failure"); $error_flag = false; $error = ""; $tasks = array("addUser", "updateCheckIn", "updateConfirmed", "dateCheckedIn", "dateConfirmed", "isWaiting", "getUserIDs", "getWaiting", "getConfirmed"); try { $db = new StudentSQL($db_name); } catch (\Exception $e) { $failure["error"] = $e->getMessage(); return $failure; } if (!is_exception($task) && (!$db->userIDExists($userID) && $task !== $tasks[0])) { $error_flag = true; $error = "User ID does not exist"; } if (!$error_flag) { switch ($task) { case $tasks[0]: $success[$tasks[0]] = $db->addKey($userID); break; case $tasks[1]: $db->updateCheckIn($userID); break; case $tasks[2]: $db->updateConfirmed($userID); break; case $tasks[3]: $success[$tasks[3]] = $db->getDateCheckedIn($userID); break; case $tasks[4]: $success[$tasks[4]] = $db->getDateConfirmed($userID); break; case $tasks[5]: $success[$tasks[5]] = $db->isWaiting($userID); break; case $tasks[6]: $success['userIDs'] = $db->getAll(); break; case $tasks[7]: $success['userIDs'] = $db->getAllWaiting(); break; case $tasks[8]: $success['userIDs'] = $db->getAllConfirmed(); break; default: $error_flag = true; $error = "Bad command"; } } if (!$error_flag) { return $success; } else { $failure["error"] = $error; return $failure; } }
function test_is_exception() { $directory = "./home/cache/front_tmpl"; $file = "03a9f8c100af014be78fe9a9c5f87faf.php"; $ret = is_exception($directory, $file); var_dump($ret); $directory = "./core/admin/controller"; $file = "ctl.template.php"; $ret = is_exception($directory, $file); var_dump($ret); }
/** * @param string $task Task request to be fulfilled. * @param string $db_name Path to a database containing tables required by * @param string $hash * @param string $pubkey * @param string $crypt * @param string $password * @param string $salt * @param string $iv * @return array|string * @throws \ErrorException */ function run_crypt_task($task, $db_name, $hash, $pubkey, $crypt = NULL, $password = NULL, $salt = NULL, $iv = NULL) { $db = null; $success = array("result" => "success"); $failure = array("result" => "failure"); $error = ""; $error_flag = false; $tasks = array("addClient", "studentFunction"); try { $db = new ClientDeviceSQL($db_name); } catch (\Exception $e) { $failure["error"] = $e->getMessage(); return $failure; } if (!$error_flag) { switch ($task) { case $tasks[0]: $success[$tasks[0]] = $db->addKey($pubkey); break; case $tasks[1]: if (!$db->keyAuthorized($hash)) { $failure["error"] = "Key not authorized for action."; return $failure; } $task_string = $db->decryptString($crypt, $hash); $data = parse_query($task_string); if (array_key_exists("function", $data) && (array_key_exists("userID", $data) || is_exception($data["function"]))) { $ret = run_task($data["userID"], $data["function"], $db_name); $success[$tasks[1]] = $db->encrypt_string(json_encode($ret), $hash); } else { $error = "Malformed URL"; $error_flag = true; } break; } } if (!$error_flag) { return $success; } else { $failure["error"] = $error; return $error; } }
function get_repeating_entries($user, $dateYmd) { global $repeated_events; $n = 0; $ret = array(); //echo count($repeated_events)."<BR>"; for ($i = 0; $i < count($repeated_events); $i++) { if (repeated_event_matches_date($repeated_events[$i], $dateYmd)) { // make sure this is not an exception date... $unixtime = date_to_epoch($dateYmd); if (!is_exception($unixtime, $repeated_events[$i]['cal_exceptions'])) { $ret[$n++] = $repeated_events[$i]; } } } return $ret; }
function tokenize_ml($txt, $exceptions, $prefixes) { $coeff = array(); $out = array(); $token = ''; $txt = Normalizer::normalize($txt, Normalizer::FORM_C); $res = sql_query("SELECT * FROM tokenizer_coeff"); while ($r = sql_fetch_array($res)) { $coeff[$r[0]] = $r[1]; } $txt .= ' '; for ($i = 0; $i < mb_strlen($txt, 'UTF-8'); ++$i) { $prevchar = $i > 0 ? mb_substr($txt, $i - 1, 1, 'UTF-8') : ''; $char = mb_substr($txt, $i + 0, 1, 'UTF-8'); $nextchar = mb_substr($txt, $i + 1, 1, 'UTF-8'); $nnextchar = mb_substr($txt, $i + 2, 1, 'UTF-8'); //$chain is the current word which we will perhaps need to check in the dictionary $chain = $chain_left = $chain_right = ''; $odd_symbol = ''; if (is_hyphen($char) || is_hyphen($nextchar)) { $odd_symbol = '-'; } elseif (preg_match('/([\\.\\/\\?\\=\\:&"!\\+\\(\\)])/u', $char, $match) || preg_match('/([\\.\\/\\?\\=\\:&"!\\+\\(\\)])/u', $nextchar, $match)) { $odd_symbol = $match[1]; } if ($odd_symbol) { for ($j = $i; $j >= 0; --$j) { $t = mb_substr($txt, $j, 1, 'UTF-8'); if ($odd_symbol == '-' && (is_cyr($t) || is_hyphen($t) || $t === "'") || $odd_symbol != '-' && !is_space($t)) { $chain_left = $t . $chain_left; } else { break; } if (mb_substr($chain_left, -1) === $odd_symbol) { $chain_left = mb_substr($chain_left, 0, -1); } } for ($j = $i + 1; $j < mb_strlen($txt, 'UTF-8'); ++$j) { $t = mb_substr($txt, $j, 1, 'UTF-8'); if ($odd_symbol == '-' && (is_cyr($t) || is_hyphen($t) || $t === "'") || $odd_symbol != '-' && !is_space($t)) { $chain_right .= $t; } else { break; } if (mb_substr($chain_right, 0, 1) === $odd_symbol) { $chain_right = mb_substr($chain_right, 1); } } $chain = $chain_left . $odd_symbol . $chain_right; } $vector = array_merge(char_class($char), char_class($nextchar), array(is_number($prevchar), is_number($nnextchar), $odd_symbol == '-' ? is_dict_chain($chain) : 0, $odd_symbol == '-' ? is_suffix($chain_right) : 0, is_same_pm($char, $nextchar), $odd_symbol && $odd_symbol != '-' ? looks_like_url($chain, $chain_right) : 0, $odd_symbol && $odd_symbol != '-' ? is_exception($chain, $exceptions) : 0, $odd_symbol == '-' ? is_prefix($chain_left, $prefixes) : 0, $odd_symbol == ':' && $chain_right !== '' ? looks_like_time($chain_left, $chain_right) : 0)); $vector = implode('', $vector); if (isset($coeff[bindec($vector)])) { $sum = $coeff[bindec($vector)]; } else { $sum = 0.5; } $token .= $char; if ($sum > 0) { $token = trim($token); if ($token !== '') { $out[] = array($token, $sum, bindec($vector) . '=' . $vector); } $token = ''; } } return $out; }