function rules_save() { $q = new mysql(); $rulename = $q->mysql_real_escape_string2($_GET["rule_name"]); if ($rulename == null) { $rulename = $_GET["rule_name"]; } $delay_pool_net = $_GET["delay_pool_net"]; $delay_pool_net = $delay_pool_net * 1000; $delay_pool_net = $delay_pool_net / 8; $delay_pool_max_file = $_GET["delay_pool_max_file"]; $delay_pool_max_file = $delay_pool_max_file * 1000; $delay_pool_max_file = $delay_pool_max_file / 8; $delay_pool_limit = $_GET["delay_pool_limit"]; $delay_pool_limit = $delay_pool_limit * 1000; $delay_pool_limit = $delay_pool_limit / 8; $delay_pool_net = "{$delay_pool_net}/{$delay_pool_net}"; $delay_pool_net2 = "{$delay_pool_limit}/{$delay_pool_max_file}"; $sql = "INSERT INTO squid_pools (rulename,total_net,total_users)\n\tVALUES('{$_GET["rule_name"]}','{$delay_pool_net}','{$delay_pool_net2}')"; if ($_GET["ID"] > 0) { $sql = "UPDATE squid_pools\n\t\tSET rulename='{$rulename}',\n\t\ttotal_net='{$delay_pool_net}',\n\t\ttotal_users='{$delay_pool_net2}',\n\t\tenable='{$_GET["enable"]}'\n\t\tWHERE ID={$_GET["ID"]}\n\t\t"; } $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo $q->mysql_error; return; } $sock = new sockets(); $sock->getFrameWork("cmd.php?squid-reload=yes"); }
function task_computers_events($text) { $sql = "SELECT events FROM computers_deploy_tasks_sub WHERE ID={$GLOBALS[__FILE__]["SUBTASKID"]}"; $q = new mysql(); $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup')); $datas = unserialize(base64_decode($ligne["events"])); $text = date('m-d H:i:s') . " {$text}"; echo $text . "\n"; $text = $q->mysql_real_escape_string2($text); $text = htmlentities($text); $datas[] = "<div>{$text}</div>"; $translate = base64_encode(serialize($datas)); $sql = "UPDATE computers_deploy_tasks_sub SET events='{$translate}' WHERE ID={$GLOBALS[__FILE__]["SUBTASKID"]}"; $q = new mysql(); $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "{$sql} {$q->mysql_error}\n"; } }
function user_agent_ban_search() { $query = "*" . $_GET["user-agent-ban-search"] . "*"; $query = str_replace("**", "*", $query); $q = new mysql(); $query = $q->mysql_real_escape_string2($query); $query = str_replace("*", "%", $query); $limit = 50; if (strlen($query) > 2) { $limit = 150; } $sql = "SELECT * FROM UserAgents WHERE string LIKE '{$query}' ORDER BY browser,string LIMIT 0,50"; $results = $q->QUERY_SQL($sql, "artica_backup"); $html = "<table class=tableView style='width:99%'>\n\t\t\t\t<thead class=thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th width=1% nowrap colspan=3> </td>\n\t\t\t\t</tr>\n\t\t\t\t</thead>"; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($cl == "oddRow") { $cl = null; } else { $cl = "oddRow"; } $html = $html . "\n\t\t<tr class={$cl}>\n\t\t\t<td width=1% nowrap><code style='font-size:10px'>{$ligne["browser"]}</code></td>\n\t\t\t<td width=99%><code style='font-size:10px'>{$ligne["string"]}</td>\n\t\t\t<td width=1%><span id='id_{$ligne["unique_key"]}'>" . Field_checkbox("{$ligne["unique_key"]}", 1, 0, "AddBanUserAgent('{$ligne["unique_key"]}')") . "</span></td>\n\t\t</tr>"; } $html = $html . "</table>"; $tpl = new templates(); echo $tpl->_ENGINE_parse_body($html); }
function rules_save(){ $q=new mysql(); $rulename=$q->mysql_real_escape_string2($_GET["rule_name"]); if($rulename==null){$rulename=$_GET["rule_name"];} $delay_pool_net=$_GET["delay_pool_net"]; $delay_pool_net=$delay_pool_net*1000; $delay_pool_net=$delay_pool_net/8; $delay_pool_max_file=$_GET["delay_pool_max_file"]; $delay_pool_max_file=$delay_pool_max_file*1000; $delay_pool_max_file=$delay_pool_max_file/8; $delay_pool_limit=$_GET["delay_pool_limit"]; $delay_pool_limit=$delay_pool_limit*1000; $delay_pool_limit=$delay_pool_limit/8; $delay_pool_net="$delay_pool_net/$delay_pool_net"; $delay_pool_net2="$delay_pool_limit/$delay_pool_max_file"; $rule_class=$_GET["rule_class"]; if(!is_numeric($rule_class)){$rule_class=2;} $sql="INSERT INTO squid_pools (rulename,total_net,total_users,rule_class) VALUES('{$_GET["rule_name"]}','$delay_pool_net','$delay_pool_net2',$rule_class)"; if($_GET["ID"]>0){ $sql="UPDATE squid_pools SET rulename='$rulename', total_net='$delay_pool_net', total_users='$delay_pool_net2', rule_class=$rule_class, enable='{$_GET["enable"]}' WHERE ID={$_GET["ID"]} "; } $q->QUERY_SQL($sql,'artica_backup'); if(!$q->ok){echo $q->mysql_error;return;} $sock=new sockets();$sock->getFrameWork("cmd.php?squid-reload=yes"); }
function rules_save() { $q = new mysql(); $q->CheckTablesSquid(); $rulename = $q->mysql_real_escape_string2(url_decode_special_tool($_POST["rule_name"])); if ($rulename == null) { $rulename = "New rule"; } $rule_class = 2; $sql = "CREATE TABLE IF NOT EXISTS `artica_backup`.`squid_pools` (\n\t\t\t`ID` INT(10) AUTO_INCREMENT PRIMARY KEY,\n\t\t\t`rulename` VARCHAR( 255 ) NOT NULL ,\n\t\t\t`rule_class` INT( 1 ) NOT NULL DEFAULT '2',\n\t\t\t`total_net_enabled` smallint(1) NOT NULL DEFAULT 0,\n\t\t\t`total_net_max` BIGINT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t`total_net` VARCHAR( 90 ) NOT NULL ,\n\t\t\t`total_net_band` BIGINT UNSIGNED NOT NULL,\n\t\t\t`total_computer_enabled` smallint(1) NOT NULL DEFAULT 0,\n\t\t\t`total_computer_max` BIGINT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t`total_computer_band` BIGINT UNSIGNED NOT NULL ,\n\t\t\t`total_member_enabled` smallint(1) NOT NULL DEFAULT 0,\n\t\t\t`total_member_max` BIGINT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t`total_member_band` BIGINT UNSIGNED NOT NULL ,\t\t\t\n\t\t\t`total_user_enabled` smallint(1) NOT NULL DEFAULT 0,\n\t\t\t`total_user_max` BIGINT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t`total_user_band` BIGINT UNSIGNED NOT NULL ,\n\t\t\t`total_users` VARCHAR( 90 ) NOT NULL ,\n\t\t\tINDEX ( `rulename` )) ENGINE=MYISAM;"; $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->FIELD_EXISTS("squid_pools", "total_member_enabled", "artica_backup")) { $sql = "ALTER TABLE `squid_pools` ADD `total_member_enabled` smallint(1) NOT NULL DEFAULT '0',ADD INDEX ( `total_member_enabled` )"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "{$q->mysql_error}\n{$sql}"; return; } } if (!$q->FIELD_EXISTS("squid_pools", "total_member_max", "artica_backup")) { $sql = "ALTER TABLE `squid_pools` ADD `total_member_max` BIGINT UNSIGNED NOT NULL DEFAULT '0',ADD INDEX ( `total_member_max` )"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "{$q->mysql_error}\n{$sql}"; return; } } if (!$q->FIELD_EXISTS("squid_pools", "total_member_band", "artica_backup")) { $sql = "ALTER TABLE `squid_pools` ADD `total_member_band` BIGINT UNSIGNED NOT NULL DEFAULT '0',ADD INDEX ( `total_member_band` )"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "{$q->mysql_error}\n{$sql}"; return; } } $total_net_max = intval($_POST["total_net_max"]); $total_net_max = $total_net_max * 1024; $total_net_max = $total_net_max * 1024; $total_computer_max = intval($_POST["total_computer_max"]); $total_computer_max = $total_computer_max * 1024; $total_computer_max = $total_computer_max * 1024; $total_user_max = intval($_POST["total_user_max"]); $total_user_max = $total_user_max * 1024; $total_user_max = $total_user_max * 1024; $total_net_band = intval($_POST["total_net_band"]); $total_net_band = $total_net_band * 1000; $total_net_band = $total_net_band / 8; $total_computer_band = intval($_POST["total_computer_band"]); $total_computer_band = $total_computer_band * 1000; $total_computer_band = $total_computer_band / 8; $total_user_band = intval($_POST["total_user_band"]); $total_user_band = $total_user_band * 1000; $total_user_band = $total_user_band / 8; $total_member_band = intval($_POST["total_member_band"]); $total_member_band = $total_user_band * 1000; $total_member_band = $total_user_band / 8; $total_member_max = intval($_POST["total_member_max"]); $total_member_max = $total_member_max * 1024; $total_member_max = $total_member_max * 1024; $total_user_enabled = intval($_POST["totaluserenabled"]); $total_member_enabled = intval($_POST["total_member_enabled"]); $total_net_enabled = intval($_POST["total_net_enabled"]); $total_computer_enabled = intval($_POST["total_computer_enabled"]); $sql = "INSERT INTO squid_pools (rulename,total_user_enabled,total_net_enabled,total_computer_enabled,total_member_enabled,\n\ttotal_net_max,total_computer_max,total_user_max,total_net_band,total_computer_band,total_user_band\n\t)\n\tVALUES('{$rulename}','{$total_user_enabled}','{$total_net_enabled}','{$total_computer_enabled}','{$total_member_enabled}',\n\t'{$total_net_max}','{$total_computer_max}','{$total_user_max}','{$total_net_band}','{$total_computer_band}','{$total_user_band}'\n\t)"; if ($_POST["ID"] > 0) { $sql = "UPDATE squid_pools\n\t\tSET rulename='{$rulename}',\n\t\ttotal_user_enabled='{$total_user_enabled}',\n\t\ttotal_net_enabled='{$total_net_enabled}',\n\t\ttotal_member_enabled='{$total_member_enabled}',\n\t\ttotal_computer_enabled='{$total_computer_enabled}',\n\t\ttotal_net_max='{$total_net_max}',\n\t\ttotal_computer_max='{$total_computer_max}',\n\t\ttotal_user_max='{$total_user_max}',\n\t\ttotal_member_max='{$total_member_max}',\n\t\ttotal_net_band='{$total_net_band}',\n\t\ttotal_computer_band='{$total_computer_band}',\n\t\ttotal_member_band='{$total_member_band}',\n\t\ttotal_user_band='{$total_user_band}',\n\t\tenable='{$_POST["enable"]}'\n\t\tWHERE ID='{$_POST["ID"]}'\n\t\t"; } $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo $q->mysql_error . "\n{$sql}\n"; return; } }
function ParseEvents(){ ParseReboot(); $path="/var/log/artica-postfix/events"; $f=new filesClasses(); $hash=$f->DirListTable($path); if(!is_array($hash)){return null;} $users=new usersMenus(); $sock=new sockets(); $ArticaMetaEnabled=$sock->GET_INFO("ArticaMetaEnabled"); echo date('Y-m-d h:i:s')." " .count($hash) . " file(s) notifications...\n"; events(count($hash) . " file(s) notifications..."); if(count($hash)==0){return;} if($ArticaMetaEnabled==1){ $meta=new artica_meta(); $datasToSend=base64_encode(serialize($meta->GLOBAL_ARRAY)); $ArticaMetaHostname=$meta->ArticaMetaHostname; events("ArticaMetaEnabled: \"$ArticaMetaEnabled\" -> ($ArticaMetaHostname)"); } $mysql=new mysql(); while (list ($num, $file) = each ($hash)){ $text=null; $processname=null; $date=null; $context=null; $subject=null; $recipient=null; $bigtext=@file_get_contents($path.'/'.$file); echo date('Y-m-d h:i:s')." Parsing $file ". strlen($bigtext)." bytes text\n"; $ini=new Bs_IniHandler(); if(preg_match("#<text>(.+?)</text>#is",$bigtext,$re)){ $text=$re[1]; if(strlen($text)>0){ $bigtext=str_replace($re[0],'',$bigtext); } } if(preg_match("#<attachedfiles>(.+?)</attachedfiles>#is",$bigtext,$re)){ $files_text=addslashes($re[1]); } $ini->loadString($bigtext); $processname=$ini->_params["LOG"]["processname"]; $date=$ini->_params["LOG"]["date"]; $context=$ini->_params["LOG"]["context"]; if($context=="YTowOnt9"){$context="system";} $subject=$ini->_params["LOG"]["subject"]; $recipient=$ini->_params["LOG"]["recipient"]; if(strlen($text)<2){ $text=$ini->_params["LOG"]["text"]; } $arrayToSend["context"]=$context; $arrayToSend["subject"]=$subject; $arrayToSend["text"]=$text; $arrayToSend["date"]=$date; echo date('Y-m-d h:i:s')." Parsing subject $subject ". strlen($text)." bytes text\n"; writelogs("New notification: $subject (". strlen($text)." bytes) $date",__FUNCTION__,__FILE__,__LINE__); $event_id=time(); //$text=addslashes($text); $text=$mysql->mysql_real_escape_string2($text); $subject=addslashes($subject); $sql="INSERT IGNORE INTO events (zDate,hostname, process,text,context,content,attached_files,recipient,event_id) VALUES( '$date', '$mysql->hostname', '$processname', '$subject', '$context','$text','$files_text','$recipient','$event_id')"; if(!$mysql->UseMysql){ $sql="INSERT IGNORE INTO events (id,zDate,hostname, process,text,context,content,attached_files,recipient,event_id) VALUES( '$event_id','$date', '$users->hostname', '$processname', '$subject', '$context','$text','$files_text','$recipient','$event_id')"; } events(date('Y-m-d h:i:s')." run mysql query -> $subject"); if(!$mysql->QUERY_SQL($sql,'artica_events')){ events("Mysql error keep $path/$file;"); events("Fatal: $mysql->mysql_error",__FUNCTION__,__FILE__,__LINE__); if(preg_match("#Access denied for user.+?using password:#",$mysql->mysql_error)){ events("Access denied for user password: $mysql->mysql_server@$mysql->mysql_admin:$mysql->mysql_password detected"); if(($mysql->mysql_server=="127.0.0.1") OR ($mysql->mysql_server=="localhost")){ $ldap=new clladp(); $unix=new unix(); $ldap->ldap_password=$unix->shellEscapeChars($ldap->ldap_password); writelogs("Try to change the mysql password: /usr/share/artica-postfix/bin/artica-install --change-mysqlroot --inline root \"secret\"",__FUNCTION__,__FILE__,__LINE__); exec("/usr/share/artica-postfix/bin/artica-install --change-mysqlroot --inline root \"secret\" 2>&1",$chroot); writelogs("Chaning password="******"\n",$chroot),__FUNCTION__,__FILE__,__LINE__); die(); } } if(preg_match("#Unknown column#",$mysql->mysql_error)){events("->BuildTables()");$mysql->BuildTables();} if(preg_match("#Unknown database#",$mysql->mysql_error)){events("->BuildTables()");$mysql->BuildTables();} if(preg_match("#connect to local MySQL server through socket#",$mysql->mysql_error)){shell_exec("/etc/init.d/artica-postfix start mysql &");} writelogs("$sql",__FUNCTION__,__FILE__,__LINE__); break; } unlink($path.'/'.$file); if($ArticaMetaEnabled==1){ $pidfile="/etc/artica-postfix/pids/exec.artica.meta.php.SendStatus.pid"; $sock=new sockets(); $ArticaMetaPoolTimeMin=$sock->GET_INFO("ArticaMetaPoolTimeMin"); if(!is_numeric($ArticaMetaPoolTimeMin)){$ArticaMetaPoolTimeMin=15;} if($ArticaMetaPoolTimeMin<2){$ArticaMetaPoolTimeMin=15;} $minutes=file_time_min($pidfile); if($minutes<round(($ArticaMetaPoolTimeMin/2.5))){ $meta->events(basename($pidfile).":{$minutes}<".round(($ArticaMetaPoolTimeMin/2.5))."Mn, aborting",__FUNCTION__,__FILE__,__LINE__); return; } $http=new httpget(); $meta->events("Send notification \"{$arrayToSend["subject"]}\" to Artica Meta",__FUNCTION__,__FILE__,__LINE__); $metaconsole=$http->send("$ArticaMetaHostname/lic.status.notifs.php","post",array( "DATAS"=>$datasToSend, "NOTIF"=>base64_encode(serialize($arrayToSend)) )); events("META CONSOLE: $metaconsole aborting notifications"); if($metaconsole=="FAILED_CONNECT"){ $meta->events("Result:\"$metaconsole\"",__FUNCTION__,__FILE__,__LINE__); return; } if(!is_file("/etc/artica-postfix/artica-meta.tasks")){ if(preg_match("#<TASKS>(.+?)</TASKS>#is",$metaconsole,$re)){ $meta->events("Save tasks to /etc/artica-postfix/artica-meta.tasks",__FUNCTION__,__FILE__,__LINE__); @file_put_contents("/etc/artica-postfix/artica-meta.tasks",$re[1]); $cmd=LOCATE_PHP5_BIN()." ".dirname(__FILE__)."/exec.artica.meta.tasks.php >/dev/null 2>&1 &"; $meta->events("TASKS ->$cmd",__FUNCTION__,__FILE__,__LINE__); shell_exec($cmd); } } } $text=addslashes($text); $context=addslashes($context); $subject=addslashes($subject); } if(count($hash)>0){events(count($hash). " events queue parsed...");} if($ArticaMetaEnabled==1){ if(is_file("/etc/artica-postfix/artica-meta.tasks")){ $NICE=EXEC_NICE(); shell_exec($NICE.LOCATE_PHP5_BIN2()." ".dirname(__FILE__)."/exec.artica.meta.tasks.php &"); } } }