Exemple #1
0
function checkGreenTables()
{
    $q = new mysql();
    if (!$q->TABLE_EXISTS("query", "greensql")) {
        echo "Starting......: " . date("H:i:s") . " GreenSQL creating query table\n";
        $sql = "CREATE table query(\n\t\tqueryid int unsigned NOT NULL auto_increment primary key,\n\t\tproxyid        int unsigned NOT NULL default '0',\n\t\tperm           smallint unsigned NOT NULL default 1,\n\t\tdb_name        char(50) NOT NULL,\n\t\tquery          text NOT NULL,\n\t\tINDEX(proxyid,db_name)\n\t\t) DEFAULT CHARSET=utf8;\n\t\t";
        $q->QUERY_SQL($sql, "greensql");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " GreenSQL failed {$q->mysql_error}\n";
        }
    }
    if (!$q->TABLE_EXISTS("proxy", "greensql")) {
        echo "Starting......: " . date("H:i:s") . " GreenSQL creating proxy table\n";
        $sql = "\n\t\t\tCREATE table proxy\n\t\t\t(\n\t\t\tproxyid        int unsigned NOT NULL auto_increment primary key,\n\t\t\tproxyname      char(50) NOT NULL default '',\n\t\t\tfrontend_ip    char(20) NOT NULL default '',\n\t\t\tfrontend_port  smallint unsigned NOT NULL default 0,\n\t\t\tbackend_server char(50) NOT NULL default '',\n\t\t\tbackend_ip     char(20) NOT NULL default '',\n\t\t\tbackend_port   smallint unsigned NOT NULL default 0,\n\t\t\tdbtype         char(20) NOT NULL default 'mysql',\n\t\t\tstatus         smallint unsigned NOT NULL default '1'\n\t\t\t) DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "greensql");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " GreenSQL failed {$q->mysql_error}\n";
        }
        $q->QUERY_SQL("insert into proxy values (1,'Default MySQL Proxy','127.0.0.1',3305,'localhost','127.0.0.1',3306,'mysql',1);", "greensql");
        $q->QUERY_SQL("insert into proxy values (2,'Default PgSQL Proxy','127.0.0.1',5431,'localhost','127.0.0.1',5432,'pgsql',1);", "greensql");
    }
    if (!$q->TABLE_EXISTS("db_perm", "greensql")) {
        echo "Starting......: " . date("H:i:s") . " GreenSQL creating db_perm table\n";
        $sql = "CREATE table db_perm\n\t\t\t(\n\t\t\tdbpid          int unsigned NOT NULL auto_increment primary key,\n\t\t\tproxyid        int unsigned NOT NULL default '0',\n\t\t\tdb_name        char(50) NOT NULL,\n\t\t\tperms          bigint unsigned NOT NULL default '0',\n\t\t\tperms2         bigint unsigned NOT NULL default '0',\n\t\t\tstatus         smallint unsigned NOT NULL default '0',\n\t\t\tsysdbtype      char(20) NOT NULL default 'user_db',\n\t\t\tstatus_changed datetime NOT NULL default '00-00-0000 00:00:00',\n\t\t\tINDEX (proxyid, db_name)\n\t\t\t) DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "greensql");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " GreenSQL failed {$q->mysql_error}\n";
        }
        $q->QUERY_SQL("insert into db_perm (dbpid, proxyid, db_name, sysdbtype) values (1,0,'default mysql db', 'default_mysql');", "greensql");
        $q->QUERY_SQL("insert into db_perm (dbpid, proxyid, db_name, sysdbtype) values (2,0,'no-name mysql db', 'empty_mysql');", "greensql");
        $q->QUERY_SQL("insert into db_perm (dbpid, proxyid, db_name, sysdbtype) values (3,0,'default pgsql db', 'default_pgsql');", "greensql");
    }
    if (!$q->TABLE_EXISTS("admin", "greensql")) {
        echo "Starting......: " . date("H:i:s") . " GreenSQL creating admin table\n";
        $sql = "CREATE table admin(\n\t\t\tadminid         int unsigned NOT NULL auto_increment primary key,\n\t\t\tname           char(50) NOT NULL default '',\n\t\t\tpwd            char(50) NOT NULL default '',\n\t\t\temail          char(50) NOT NULL default ''\n\t\t\t) DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "greensql");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " GreenSQL failed {$q->mysql_error}\n";
        }
        $q->QUERY_SQL("insert into admin values(1,'admin',sha1('pwd'),'');", "greensql");
    }
    if (!$q->TABLE_EXISTS("alert", "greensql")) {
        echo "Starting......: " . date("H:i:s") . " GreenSQL creating alert table\n";
        $sql = "CREATE table alert\n\t\t\t(\n\t\t\talertid             int unsigned NOT NULL auto_increment primary key,\n\t\t\tagroupid            int unsigned NOT NULL default '0',\n\t\t\tevent_time          datetime NOT NULL default '00-00-0000 00:00:00',\n\t\t\trisk                smallint unsigned NOT NULL default '0',\n\t\t\tblock               smallint unsigned NOT NULL default '0',\n\t\t\tdbuser              varchar(50) NOT NULL default '',\n\t\t\tuserip              varchar(50) NOT NULL default '',\n\t\t\tquery               text NOT NULL,\n\t\t\treason              text NOT NULL,\n\t\t\tINDEX (agroupid)\n\t\t\t) DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "greensql");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " GreenSQL failed {$q->mysql_error}\n";
        }
    }
    if (!$q->TABLE_EXISTS("alert_group", "greensql")) {
        echo "Starting......: " . date("H:i:s") . " GreenSQL creating alert_group table\n";
        $sql = "CREATE table alert_group(\n\t\t\tagroupid            int unsigned NOT NULL auto_increment primary key,\n\t\t\tproxyid             int unsigned NOT NULL default '1',\n\t\t\tdb_name             char(50) NOT NULL default '',\n\t\t\tupdate_time         datetime NOT NULL default '00-00-0000 00:00:00',\n\t\t\tstatus              smallint NOT NULL default 0,\n\t\t\tpattern             text NOT NULL,\n\t\t\tINDEX(update_time)\n\t\t\t)";
        $q->QUERY_SQL($sql, "greensql");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " GreenSQL failed {$q->mysql_error}\n";
        }
    }
    echo "Starting......: " . date("H:i:s") . " GreenSQL check tables done...\n";
}
function Save()
{
    $q = new mysql();
    if (!$q->TABLE_EXISTS("storage_containers", "artica_backup")) {
        $sql = "CREATE TABLE IF NOT EXISTS `artica_backup`.`storage_containers` (\n\t\t\t\t`groupid` VARCHAR( 255 ) NOT NULL,\n\t\t\t\t`enabled` smallint( 1 ) NOT NULL,\n\t\t\t\t`maxsize` INT UNSIGNED ,\n\t\t\t\t`directory` VARCHAR( 255 ) NOT NULL,\n\t\t\t\t PRIMARY KEY ( `groupid` ),\n\t\t\t\t KEY `enabled`(`enabled`)\n\t\t\t\t) ENGINE=MYISAM;";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    $_POST["directory"] = mysql_escape_string2($_POST["directory"]);
    $gid = mysql_escape_string2($_POST["gid"]);
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM storage_containers WHERE `groupid`='{$gid}'", "artica_backup"));
    //echo "$gid = {$ligne["directory"]} Enabled={$_POST["enabled"]}\n";
    if ($ligne["directory"] != null) {
        $q->QUERY_SQL("UPDATE storage_containers SET `maxsize`='{$_POST["maxsize"]}',\n\t\tenabled='{$_POST["enabled"]}',`directory`='{$_POST["directory"]}' WHERE `groupid`='{$gid}'", "artica_backup");
    } else {
        $q->QUERY_SQL("INSERT IGNORE INTO storage_containers (groupid,enabled,maxsize,`directory`)\n\t\t\t\tVALUES ('{$gid}','{$_POST["enabled"]}','{$_POST["maxsize"]}','{$_POST["directory"]}')", "artica_backup");
    }
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
}
Exemple #3
0
function table()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $t = time();
    $dnsmasq_address_text = $tpl->_ENGINE_parse_body("{dnsmasq_address_text}");
    $hosts = $tpl->_ENGINE_parse_body("{hosts}");
    $addr = $tpl->_ENGINE_parse_body("{addr}");
    $new_interface = $tpl->_ENGINE_parse_body("{new_interface}");
    $rulename = $tpl->_ENGINE_parse_body("{rulename}");
    $explain = $tpl->javascript_parse_text("{explain}");
    $title = $tpl->_ENGINE_parse_body("{rules}");
    $category = $tpl->_ENGINE_parse_body("{category}");
    $enabled = $tpl->_ENGINE_parse_body("{enabled}");
    $q = new mysql();
    if (!$q->TABLE_EXISTS("suricata_rules_packages", "artica_backup")) {
        $sql = "CREATE TABLE IF NOT EXISTS `artica_backup`.`suricata_rules_packages` (\n\t\t`rulefile` VARCHAR(128) NOT NULL PRIMARY KEY ,\n\t\t`category` VARCHAR(40) NOT NULL,\n\t\t`enabled` smallint(1) NOT NULL DEFAULT 0,\n\t\tINDEX ( `category`),\n\t\tINDEX ( `enabled`)\n\t\t)";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    }
    if ($q->COUNT_ROWS("suricata_rules_packages", "artica_backup") == 0) {
        $sql = "INSERT IGNORE INTO suricata_rules_packages (rulefile,enabled,category) VALUES \n\t\t\t\t('botcc.rules',0,'DMZ'),('ciarmy.rules',0,'DMZ'),('compromised.rules','0','DMZ'),\n\t\t\t\t('drop.rules',1,'DMZ'),\n\t\t\t\t('dshield.rules',1,'DMZ'),('snort.rules',1,'ALL'),\n\t\t\t\t('emerging-activex.rules',1,'WEB'),\n\t\t\t\t('emerging-attack_response.rules',1,'ALL'),\n\t\t\t\t('emerging-chat.rules',0,'WEB'),\n\t\t\t\t('emerging-current_events.rules',0,'ALL'),\n\t\t\t\t('emerging-dns.rules',0,'DMZ'),\n\t\t\t\t('emerging-dos.rules',0,'DMZ'),\n\t\t\t\t('emerging-exploit.rules',0,'DMZ'),\n\t\t\t\t('emerging-ftp.rules',0,'DMZ'),\n\t\t\t\t('emerging-games.rules',0,'ALL'),\n\t\t\t\t('emerging-icmp_info.rules',0,'ALL'),\n\t\t\t\t('emerging-icmp.rules',0,'ALL'),\n\t\t\t\t('emerging-imap.rules',0,'DMZ'),\n\t\t\t\t('emerging-inappropriate.rules',0,'WEB'),\n\t\t\t\t('emerging-malware.rules',1,'WEB'),\n\t\t\t\t('emerging-mobile_malware.rules',0,'WEB'),\n\t\t\t\t('emerging-netbios.rules',0,'ALL'),\n\t\t\t\t('emerging-p2p.rules',0,'WEB'),\n\t\t\t\t('emerging-policy.rules',1,'WEB'),\n\t\t\t\t('emerging-pop3.rules',0,'DMZ'),\n\t\t\t\t('emerging-rpc.rules',0,'ALL'),\n\t\t\t\t('emerging-scada.rules',0,'ALL'),\n\t\t\t\t('emerging-scan.rules',1,'ALL'),\n\t\t\t\t('emerging-shellcode.rules',1,'ALL'),\n\t\t\t\t('emerging-smtp.rules',0,'DMZ'),\n\t\t\t\t('emerging-snmp.rules',0,'ALL'),\n\t\t\t\t('emerging-sql.rules',0,'ALL'),\n\t\t\t\t('emerging-telnet.rules',0,'ALL'),\n\t\t\t\t('emerging-tftp.rules',0,'ALL'),\n\t\t\t\t('emerging-trojan.rules',1,'ALL'),\n\t\t\t\t('emerging-user_agents.rules',0,'ALL'),\n\t\t\t\t('emerging-voip.rules',0,'ALL'),\n\t\t\t\t('emerging-web_client.rules',1,'HTTP'),\n\t\t\t\t('emerging-web_server.rules',0,'HTTP'),\n\t\t\t\t('emerging-web_specific_apps.rules',0,'HTTP'),\n\t\t\t\t('emerging-worm.rules',1,'ALL'),\n\t\t\t\t('tor.rules',0,'ALL'),\n\t\t\t\t('decoder-events.rules',0,'ALL'),\n\t\t\t\t('stream-events.rules',0,'ALL'),\n\t\t\t\t('http-events.rules',0,'HTTP'),\n\t\t\t\t('smtp-events.rules',0,'DMZ'),\n\t\t\t\t('dns-events.rules',0,'DMZ'),\n\t\t\t\t('tls-events.rules',0,'DMZ')";
        $q->QUERY_SQL($sql, 'artica_backup');
    }
    $apply = $tpl->javascript_parse_text("{apply}");
    $buttons = "\n\tbuttons : [\n\t\n\t{name: '<strong style=font-size:18px>{$apply}</strong>', bclass: 'Apply', onpress : Apply{$t}},\n\t],";
    $html = "\n\t\n\t\n\t<table class='TABLE_SURICATA_MAIN_RULES' style='display: none' id='TABLE_SURICATA_MAIN_RULES'\n\tstyle='width:100%'></table>\n\t<script>\n\t\$(document).ready(function(){\n\tvar md5H='';\n\t\$('#TABLE_SURICATA_MAIN_RULES').flexigrid({\n\turl: '{$page}?list=yes',\n\tdataType: 'json',\n\tcolModel : [\n\t\n\t{display: '<span style=font-size:22px>{$rulename}</span>', name : 'rulefile', width : 300, sortable : true, align: 'left'},\n\t{display: '<span style=font-size:22px>{$category}</span>', name : 'category', width : 156, sortable : true, align: 'center'},\n\t{display: '<span style=font-size:22px>{$explain}</span>', name : 'none', width : 833, sortable : false, align: 'left'},\n\t{display: '<span style=font-size:22px>{$enabled}</span>', name : 'enabled', width : 105, sortable : true, align: 'center'},\n\n\t],\n\t{$buttons}\nsearchitems : [\n\t\t{display: '{$rulename}', name : 'rulefile'},\n\t\t{display: '{$category}', name : 'category'},\n\t\t\n\n\t],\t\n\tsortname: 'rulefile',\n\tsortorder: 'asc',\n\tusepager: true,\n\ttitle: '<span style=font-size:30px>{$title}</span>',\n\tuseRp: true,\n\trp: 50,\n\tshowTableToggleBtn: false,\n\twidth: '99%',\n\theight: 550,\n\tsingleSelect: true,\n\trpOptions: [10, 20, 30, 50,100,200]\n\t\n\t});\n\t});\n\t\n\t\nfunction Add{$t}(){\n\tLoadjs('{$page}?add-interface-js=yes&t={$t}');\n}\nvar xSuricataRuleEnabled= function (obj) {\n\tvar results=obj.responseText;\n\tif(results.length>0){alert(results);return;}\n\t\$('#TABLE_SURICATA_MAIN_RULES').flexReload();\n}\n\t\nfunction SuricataRuleEnabled(filename){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('filename',filename);\n\tXHR.sendAndLoad('{$page}', 'POST',xSuricataRuleEnabled);\n}\nfunction Apply{$t}(){\n\tLoadjs('suricata.progress.php');\n}\n</script>\n\t\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
Exemple #4
0
function status()
{
    $tpl = new templates();
    $page = CurrentPageName();
    $script = null;
    if (is_file("ressources/logs/global.status.ini")) {
        $ini = new Bs_IniHandler("ressources/logs/global.status.ini");
    } else {
        writelogs("ressources/logs/global.status.ini no such file");
        $sock = new sockets();
        $datas = base64_decode($sock->getFrameWork('cmd.php?Global-Applications-Status=yes'));
        $ini = new Bs_IniHandler($datas);
    }
    $sock = new sockets();
    $datas = $sock->getFrameWork('cmd.php?refresh-status=yes');
    $status = DAEMON_STATUS_ROUND("CLAMAV", $ini, null, 1);
    $q = new mysql();
    if ($q->TABLE_EXISTS("clamd_mem", "artica_events")) {
        if ($q->COUNT_ROWS("clamd_mem", "artica_events") > 1) {
            $script = "LoadAjax('clamd-graphs','{$page}?clamd-graphs=yes');";
        }
    }
    $html = "\n\t<div style='width:100%'>{$status}</div>\n\t<center style='margin-top:10px' id='clamd-graphs'></center>\n\t\n\t<script>\n\t\t{$script}\n\t</script>\n\t\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
function BuildDayTable()
{
    $q = new mysql();
    $q->BuildTables();
    if (!$q->TABLE_EXISTS('smtp_logs_day', 'artica_events')) {
        send_email_events("Mysql error on smtp_logs_day table", "Artica was unable to create or detect smtp_logs_day table...", "system");
        return false;
    }
    $today = date('Y-m-d');
    $sql = "SELECT COUNT(id) as tcount,delivery_domain,DATE_FORMAT(time_stamp,'%Y-%m-%d') as tdate,bounce_error FROM \n\tsmtp_logs \n\tGROUP BY delivery_domain,tdate,bounce_error HAVING tdate<'{$today}' ORDER BY tdate DESC";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "Wrong sql query {$q->mysql_error}\n";
        write_syslog("Wrong sql query {$q->mysql_error}", __FILE__);
        return false;
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $count = $count + 1;
        $emails = $ligne["tcount"];
        $delivery_domain = $ligne["delivery_domain"];
        $date = $ligne["tdate"];
        $bounce_error = $ligne["bounce_error"];
        $md5 = md5($delivery_domain . $date . $bounce_error . $emails);
        $sql = "INSERT INTO smtp_logs_day (`key`,`day`,`delivery_domain`,`bounce_error`,`emails`)\n\t\tVALUES('{$md5}','{$date}','{$delivery_domain}','{$bounce_error}','{$emails}')";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            echo "Wrong sql query {$q->mysql_error}\n";
            write_syslog("Wrong sql query \"{$sql}\" {$q->mysql_error}", __FILE__);
            return false;
        }
    }
    return true;
}
function js_tabs()
{
    $page = CurrentPageName();
    if ($_GET["servername"] != null) {
        $q = new mysql();
        $table_name = $q->APACHE_TABLE_NAME($_GET["servername"]);
        if ($q->TABLE_EXISTS($table_name, "apachelogs")) {
            $array["statistics"] = '{statistics}';
        }
        $table_name = "apache_stats_" . date('Ym');
        $sql = "SELECT COUNT(servername) as tcount FROM {$table_name} WHERE servername='{$_GET["servername"]}'";
        if ($q->mysql_error) {
            if (!preg_match("#doesn.+?t exist#", $q->mysql_error)) {
                echo "<H2>{$q->mysql_error}</H2>";
            }
        } else {
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        }
        if ($ligne["tcount"] > 0) {
            $array["today"] = "{last_24h}";
        }
    }
    $font = 18;
    while (list($num, $ligne) = each($array)) {
        $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"{$page}?{$num}=yes\"><span span style='font-size:{$font}px'>{$ligne}</span></a></li>\n");
    }
    echo build_artica_tabs($html, "main_config_freewebstatus");
}
function fixdb()
{
    $q = new mysql();
    if (!$q->TABLE_EXISTS('Profile', 'obm2')) {
        write_syslog("Create Profile table in obm2 database", __FILE__);
        $sql = "CREATE TABLE `Profile` (\n\t  `profile_id` int(8) NOT NULL auto_increment,\n\t  `profile_domain_id` int(8) NOT NULL,\n\t  `profile_timeupdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n\t  `profile_timecreate` timestamp NOT NULL default '0000-00-00 00:00:00',\n\t  `profile_userupdate` int(8) default NULL,\n\t  `profile_usercreate` int(8) default NULL,\n\t  `profile_name` varchar(64) default NULL,\n\t  PRIMARY KEY  (`profile_id`)\n\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "obm2");
    }
    if (!$q->TABLE_EXISTS('ProfileModule', 'obm2')) {
        write_syslog("Create ProfileModule table in obm2 database", __FILE__);
        $sql = "CREATE TABLE `ProfileModule` (\n\t  `profilemodule_id` int(8) NOT NULL auto_increment,\n\t  `profilemodule_domain_id` int(8) NOT NULL,\n\t  `profilemodule_profile_id` int(8) default NULL,\n\t  `profilemodule_module_name` varchar(64) NOT NULL default '',\n\t  `profilemodule_right` int(2) default NULL,\n\t  PRIMARY KEY  (`profilemodule_id`),\n\t  KEY `profilemodule_profile_id_profile_id_fkey` (`profilemodule_profile_id`),\n\t  CONSTRAINT `profilemodule_profile_id_profile_id_fkey` FOREIGN KEY (`profilemodule_profile_id`) REFERENCES `Profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE\n\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "obm2");
    }
    if (!$q->TABLE_EXISTS('ProfileModule', 'obm2')) {
        write_syslog("Create ProfileModule table in obm2 database", __FILE__);
        $sql = "\n\t\tCREATE TABLE `ProfileProperty` (\n\t\t  `profileproperty_id` int(8) NOT NULL auto_increment,\n\t\t  `profileproperty_profile_id` int(8) default NULL,\n\t\t  `profileproperty_name` varchar(32) NOT NULL default '',\n\t\t  `profileproperty_value` text NOT NULL,\n\t\t  PRIMARY KEY  (`profileproperty_id`),\n\t\t  KEY `profileproperty_profile_id_profile_id_fkey` (`profileproperty_profile_id`),\n\t\t  CONSTRAINT `profileproperty_profile_id_profile_id_fkey` FOREIGN KEY (`profileproperty_profile_id`) REFERENCES `Profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        $q->QUERY_SQL($sql, "obm2");
    }
}
function CheckTables()
{
    $q = new mysql();
    $tables = array("accesslog", "accountinfo", "bios", "blacklist_macaddresses", "blacklist_serials", "config", "conntrack", "controllers", "deleted_equiv", "deploy", "devices", "devicetype", "dico_ignored", "dico_soft", "download_affect_rules", "download_available", "download_enable", "download_history", "download_servers", "drives", "engine_mutex", "engine_persistent", "files", "groups", "groups_cache", "hardware", "hardware_osname_cache", "inputs", "javainfo", "locks", "memories", "modems", "monitors", "netmap", "networks", "network_devices", "operators", "ports", "printers", "prolog_conntrack", "regconfig", "registry", "registry_name_cache", "registry_regvalue_cache", "slots", "softwares", "softwares_name_cache", "sounds", "storages", "subnet", "tags", "videos", "virtualmachines");
    while (list($num, $table) = each($tables)) {
        if (!$q->TABLE_EXISTS($table, "ocsweb")) {
            return false;
        }
    }
    return true;
}
function popup()
{
    $uid = $_GET["uid"];
    $t = $_GET["t"];
    $sql = "SELECT script_code FROM logon_scriptsusers WHERE uid='{$uid}'";
    $q = new mysql();
    if (!$q->TABLE_EXISTS("logon_scriptsusers", "artica_backup")) {
        $q->BuildTables();
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    $ligne["script_code"] = base64_decode($ligne["script_code"]);
    $_POST["script_data"] = str_replace("\n\n", "\n", $_POST["script_data"]);
    $html = "\n\t<div style='font-size:13px' class=explain>{LOGON_SCRIPT_TEXT}<br>\n\t{LOGON_SCRIPT_PUT}</div>\n\t<div style='float:right;margin-bottom:8px;'>" . imgtootltip("delete-32.png", "{delete}", "LOGON_SCRIPT_DEL{$t}()") . "</div>\n\t<textarea id='script_code{$t}' style='width:100%;height:350px;overflow:auto; font-family: \"Courier New\", Courier, monospace;padding:3px'>" . $ligne["script_code"] . "</textarea>\n\t<div style='text-align:right'><hr>" . button("{apply}", "LOGON_SCRIPT_SAVE{$t}()", "18px") . "</div>";
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
function migrate()
{
    $q = new mysql();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtime = "/etc/artica-postfix/pids/exec.suricata.hourly.migrate.time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $timeExec = $unix->file_time_min($pidtime);
    if ($timeExec < 60) {
        return;
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $hostname = $unix->hostname_g();
    if (!$q->TABLE_EXISTS("suricata_events", "artica_events")) {
        return;
    }
    $results = $q->QUERY_SQL("SELECT * FROM suricata_events", "artica_events");
    $postgres = new postgres_sql();
    $postgres->suricata_tables();
    while ($ligne = mysql_fetch_assoc($results)) {
        $src_ip = $ligne["src_ip"];
        $zDate = $ligne["zDate"];
        $dst_ip = $ligne["dst_ip"];
        $dst_port = $ligne["dst_port"];
        $proto = $ligne["proto"];
        $signature = $ligne["signature"];
        $xcount = $ligne["xcount"];
        $severity = $ligne["severity"];
        $f[] = "('{$zDate}','{$src_ip}','{$dst_ip}','{$proto}','{$dst_port}','{$signature}','{$severity}','{$xcount}','{$hostname}')";
    }
    if (count($f) > 0) {
        $prefix = "INSERT INTO suricata_events (zDate,src_ip,dst_ip,proto,dst_port,signature,severity,xcount,proxyname) VALUES ";
        $postgres->QUERY_SQL($prefix . @implode(",", $f));
        if (!$postgres->ok) {
            return;
        }
        $q->QUERY_SQL("DROP TABLE suricata_events", "artica_events");
    }
}
function main_table()
{
    $t = time();
    $page = CurrentPageName();
    $tpl = new templates();
    $users = new usersMenus();
    $sock = new sockets();
    $q = new mysql();
    if (!$q->TABLE_EXISTS("sender_dependent_relay_host", "artica_backup")) {
        $q->BuildTables();
    }
    if ($_GET["hostname"] == null) {
        $_GET["hostname"] = "master";
    }
    $t = time();
    $domain = $tpl->_ENGINE_parse_body("{sender_domain_email}");
    $are_you_sure_to_delete = $tpl->javascript_parse_text("{are_you_sure_to_delete}");
    $relay = $tpl->javascript_parse_text("{relay}");
    $MX_lookups = $tpl->javascript_parse_text("{MX_lookups}");
    $delete = $tpl->javascript_parse_text("{delete}");
    $InternetDomainsAsOnlySubdomains = $sock->GET_INFO("InternetDomainsAsOnlySubdomains");
    if (!is_numeric($InternetDomainsAsOnlySubdomains)) {
        $InternetDomainsAsOnlySubdomains = 0;
    }
    $add_local_domain_form_text = $tpl->javascript_parse_text("{add_local_domain_form}");
    $add_local_domain = $tpl->_ENGINE_parse_body("{add_local_domain}");
    $sender_dependent_relayhost_maps_title = $tpl->_ENGINE_parse_body("{sender_dependent_relayhost_maps_title}");
    $ouescape = urlencode($ou);
    $networks = $tpl->javascript_parse_text("{networks}");
    $hostname = $_GET["hostname"];
    $apply = $tpl->javascript_parse_text("{apply}");
    $about2 = $tpl->javascript_parse_text("{about2}");
    $title = $tpl->javascript_parse_text("{smtpd_sasl_exceptions_networks_text}");
    $add_sender_routing_rule = $tpl->_ENGINE_parse_body("{add_new_network}");
    $explain = $tpl->javascript_parse_text("{smtpd_sasl_exceptions_networks_explain}");
    $give_the_new_network = $tpl->javascript_parse_text("{give the new network}");
    $buttons = "\n\tbuttons : [\n\t{name: '{$add_sender_routing_rule}', bclass: 'add', onpress : newrule{$t}},\n\t{name: '{$apply}', bclass: 'recycle', onpress : apply{$t}},\n\t{name: '{$about2}', bclass: 'help', onpress : Help{$t}},\n\t],";
    $html = "\n\t<input type='hidden' id='ou' value='{$ou}'>\n\t<table class='SMTP_SASL_EXCEPT_TABLE' style='display: none' id='SMTP_SASL_EXCEPT_TABLE' style='width:100%'></table>\n\t<script>\n\t\$(document).ready(function(){\n\t\$('#SMTP_SASL_EXCEPT_TABLE').flexigrid({\n\turl: '{$page}?list=yes&hostname={$hostname}&t={$t}',\n\tdataType: 'json',\n\tcolModel : [\n\t{display: '{$networks}', name : 'domain', width : 749, sortable : true, align: 'left'},\n\t{display: '{$delete};', name : 'delete', width : 90, sortable : false, align: 'center'},\n\t],\n\t{$buttons}\n\tsearchitems : [\n\t{display: '{$domain}', name : 'domain'},\n\t],\n\tsortname: 'domain',\n\tsortorder: 'asc',\n\tusepager: true,\n\ttitle: '<span style=font-size:16px>{$title}</span>',\n\tuseRp: true,\n\trp: 50,\n\tshowTableToggleBtn: false,\n\twidth: '99%',\n\theight: '550',\n\tsingleSelect: true,\n\trpOptions: [10, 20, 30, 50,100,200]\n\n});\n});\n\nfunction  Help{$t}(){\nalert('{$explain}');\n}\n\nvar xnewrule{$t}= function (obj) {\n\t\$('#SMTP_SASL_EXCEPT_TABLE').flexReload();\n\n}\n\t\t\n\n\nfunction newrule{$t}(){\n\tvar a=prompt('{$give_the_new_network}');\n\tif(!a){\n\t\treturn;\n\t}\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('smtpd_sasl_exceptions_networks_add',a);\n\tXHR.sendAndLoad('{$page}', 'GET',xnewrule{$t});\n}\n\t\nfunction  apply{$t}(){\n\tLoadjs('postfix.sasl.progress.php');\n}\n\nfunction smtpd_sasl_exceptions_delete(id_encrypted){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('smtpd_sasl_exceptions_networks_del',id_encrypted);\n\tXHR.sendAndLoad('{$page}', 'GET', xnewrule{$t});\n}\n\n</script>\n";
    echo $html;
}
Exemple #12
0
function Save()
{
    $q = new mysql();
    if (!$q->TABLE_EXISTS("iptables_webint", "artica_backup")) {
        $sql = "CREATE TABLE IF NOT EXISTS `artica_backup`.`iptables_webint` (\n\t\t\t\t`ID` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t`pattern` VARCHAR(128) NOT NULL,\n\t\t\t\t UNIQUE KEY `pattern` (`pattern`)\n\t\t\t\t) ENGINE=MYISAM;";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            echo "{$q->mysql_error}";
        }
    }
    if ($_POST["ipaddr"] != null) {
        $q->QUERY_SQL("INSERT IGNORE INTO `iptables_webint` (`pattern`) VALUES('{$_POST["ipaddr"]}')", 'artica_backup');
        if (!$q->ok) {
            echo "{$q->mysql_error}";
        }
    }
    if ($_POST["cdir"] != null) {
        $q->QUERY_SQL("INSERT IGNORE INTO `iptables_webint` (`pattern`) VALUES('{$_POST["cdir"]}')", 'artica_backup');
        if (!$q->ok) {
            echo "{$q->mysql_error}";
        }
    }
}
function popup()
{
    $infos = infos();
    $sock = new sockets();
    $page = CurrentPageName();
    $alx = $sock->getFrameWork("system.php?modinfo=alx");
    $ModeProbeAlx = intval($sock->GET_INFO("ModeProbeAlx"));
    $q = new mysql();
    $DIVS = array();
    $js = array();
    if ($q->TABLE_EXISTS("RXTX_HOUR", "artica_events")) {
        $results = $q->QUERY_SQL("SELECT ETH FROM RXTX_HOUR GROUP BY ETH", "artica_events");
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $ETH = $ligne["ETH"];
            $nic = new system_nic($ETH);
            $DIVS[] = "<hr><div style='font-size:30px;margin-top:20px'>{$ETH} [{$nic->IPADDR}] - {$nic->NICNAME} - {$nic->netzone}</div>";
            $DIVS[] = "<div style='width:1460px;height:350px' id='{$ETH}-RX-hour' class=form></div>";
            $DIVS[] = "<div style='width:1460px;height:350px' id='{$ETH}-TX-hour' class=form></div>";
            $DIVS[] = "<div style='width:1460px;height:350px' id='{$ETH}-RX-week' class=form></div>";
            $DIVS[] = "<div style='width:1460px;height:350px' id='{$ETH}-TX-week' class=form></div>";
            $js[] = "Loadjs('{$page}?eth-hour=yes&type=RX&ETH={$ETH}')";
            $js[] = "Loadjs('{$page}?eth-hour=yes&type=TX&ETH={$ETH}')";
            $js[] = "Loadjs('{$page}?eth-week=yes&type=RX&ETH={$ETH}')";
            $js[] = "Loadjs('{$page}?eth-week=yes&type=TX&ETH={$ETH}')";
        }
    }
    $t = time();
    if ($alx == "TRUE") {
        $alxform = Paragraphe_switch_img("{qualcomm_atheros}", "{qualcomm_atheros_explain}", "ModeProbeAlx", $ModeProbeAlx, null, 1450);
    } else {
        $alxform = Paragraphe_switch_disable("{qualcomm_atheros}", "{qualcomm_atheros_explain}", "ModeProbeAlx", 0, null, 1450);
    }
    //$gateway=Paragraphe('relayhost.png','{APP_ARTICA_GAYTEWAY}','{APP_ARTICA_GAYTEWAY_TEXT}',"javascript:Loadjs('index.gateway.php?script=yes')");
    $html = "\n\t<div style='width:98%' class=form>\n\t{$alxform}\t\t\n\t{$gateway}\n\t<div style='margin-top:20px;text-align:right'><hr>" . button("{apply}", "Save{$t}()", 32) . "</div>\n\t</div>\n\t\n\t<div style='width:98%' class=form>\n\t<div style='font-size:26px;font-weight:bold'>{network_hardware_infos_text}</div>\n\t<br>\n\t<div style='width:98%;height:300px;overflow:auto;'>{$infos}</div>\n\t</div>\n\t" . @implode("\n", $DIVS) . "\n<script>\nvar xSave{$t}=function (obj) {\n\tLoadjs('network.restart.php');\n}\n\t\nfunction Save{$t}(){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('ModeProbeAlx',document.getElementById('ModeProbeAlx').value);\n\tXHR.sendAndLoad('{$page}', 'POST',xSave{$t});\n}\n" . @implode("\n", $js) . "\n</script>\t\n\t";
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
function content()
{
    $q = new mysql();
    $tpl = new templates();
    $t = time();
    $page = CurrentPageName();
    if (!$q->TABLE_EXISTS("records", "powerdns")) {
        echo $tpl->_ENGINE_parse_body(FATAL_ERROR_SHOW_128("{error_missing_tables_click_to_repair}") . "\n\t\t<hr>\n\t\t<center id='{$t}'>" . button("{repair}", "RepairPDNSTables()", "22px") . "</center>\n\t\t<script>\n\tvar x_RepairPDNSTables=function (obj) {\n\t\t\tvar results=obj.responseText;\n\t\t\tif(results.length>0){alert(results);}\n\t\t\tMyHref('{$page}');\n\t}\n\tfunction RepairPDNSTables(){\n\t\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('RepairPDNSTables','yes');\n\t\tAnimateDiv('{$t}');\n\t\tXHR.sendAndLoad('pdns.mysql.php', 'POST',x_RepairPDNSTables);\n\t}\n\t</script>\n\t");
        return;
    }
    $sock = new sockets();
    $boot = new boostrap_form();
    $button = button("{new_item}", "NewPDNSEntry2()", 16);
    $SearchQuery = $boot->SearchFormGen("name,content,explainthis", "search-records");
    $EnablePDNS = $sock->GET_INFO("EnablePDNS");
    if (!is_numeric($EnablePDNS)) {
        $EnablePDNS = 0;
    }
    if ($EnablePDNS == 0) {
        $error = "<div class=text-infoWarn>{EnablePDNS_disable_text}</div>";
    }
    $html = "\n\t {$error}\n\t <table style='width:100%'>\n\t <tr>\n\t <td>{$button}</td>\n\t <td></td>\n\t </tr>\n\t </table>\n\t {$SearchQuery}\n\t <script>\n\t \tExecuteByClassName('SearchFunction');\n\t </script>\n\t ";
    echo $tpl->_ENGINE_parse_body($html);
}
function smtpd_client_restrictions_popup()
{
    $ou = $_GET["ou"];
    $sock = new sockets();
    $users = new usersMenus();
    $q = new mysql();
    if (!$q->TABLE_EXISTS("smptd_client_access", "artica_backup")) {
        $q->check_storage_table(true);
    }
    $sql = "SELECT `configuration` FROM smptd_client_access WHERE `ou`='{$ou}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        echo $q->mysql_error_html();
        die;
    }
    $MAIN = unserialize(base64_decode($ligne["configuration"]));
    $reject_unknown_client_hostname = $MAIN['reject_unknown_client_hostname'];
    $reject_unknown_reverse_client_hostname = $MAIN['reject_unknown_reverse_client_hostname'];
    $reject_unknown_sender_domain = $MAIN['reject_unknown_sender_domain'];
    $reject_invalid_hostname = $MAIN['reject_invalid_hostname'];
    $reject_non_fqdn_sender = $MAIN['reject_non_fqdn_sender'];
    $disable_vrfy_command = $MAIN['disable_vrfy_command'];
    $enforce_helo_restrictions = intval($MAIN['enforce_helo_restrictions']);
    if (!$users->POSTFIX_PCRE_COMPLIANCE) {
        $EnableGenericrDNSClients = 0;
        $EnableGenericrDNSClientsDisabled = 1;
        $EnableGenericrDNSClientsDisabledText = "<br><i><span style='color:#d32d2d;font-size:11px'>{EnableGenericrDNSClientsDisabledText}</span></i>";
    }
    $t = time();
    $page = CurrentPageName();
    $html = "\n\n\n\n\t\n\t<div style='font-size:30px;margin-bottom:50px'>{safety_standards}</div>\n\t<div class=explain style='font-size:18px'>{smtpd_client_restrictions_text}</div>\n\t<div id='smtpd_client_restrictions_div' style='width:98%' class=form>\n\t" . Paragraphe_switch_img("{reject_unknown_client_hostname}", "{reject_unknown_client_hostname_text}", "reject_unknown_client_hostname-{$t}", $reject_unknown_client_hostname, null, 1400) . "\n\t" . Paragraphe_switch_img("{reject_unknown_reverse_client_hostname}", "{reject_unknown_reverse_client_hostname_text}", "reject_unknown_reverse_client_hostname-{$t}", $reject_unknown_reverse_client_hostname, null, 1400) . "\n\t" . Paragraphe_switch_img("{reject_unknown_sender_domain}", "{reject_unknown_sender_domain_text}", "reject_unknown_sender_domain-{$t}", $reject_unknown_sender_domain, null, 1400) . "\n\t" . Paragraphe_switch_img("{reject_invalid_hostname}", "{reject_invalid_hostname_text}", "reject_invalid_hostname-{$t}", $reject_invalid_hostname, null, 1400) . "\n\t" . Paragraphe_switch_img("{reject_non_fqdn_sender}", "{reject_non_fqdn_sender_text}", "reject_non_fqdn_sender-{$t}", $reject_non_fqdn_sender, null, 1400) . "\n\t</table>\n\t</div>\n\n\t<div style='width:100%;text-align:right'><hr>\n\t" . button("{apply}", "Save{$t}()", 45) . "\n\t\n\t</div>\n<script>\nvar xSave{$t}= function (obj) {\n\tvar tempvalue=obj.responseText;\n\tif(tempvalue.length>3){alert(tempvalue);}\n\t\n}\n\t\nfunction Save{$t}(){\n\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('ou','{$ou}');\n\t\tXHR.appendData('reject_unknown_client_hostname',document.getElementById('reject_unknown_client_hostname-{$t}').value);\n\t\tXHR.appendData('reject_unknown_reverse_client_hostname',document.getElementById('reject_unknown_reverse_client_hostname-{$t}').value);\n\t\tXHR.appendData('reject_unknown_sender_domain',document.getElementById('reject_unknown_sender_domain-{$t}').value);\n\t\tXHR.appendData('reject_invalid_hostname',document.getElementById('reject_invalid_hostname-{$t}').value);\n\t\tXHR.appendData('reject_non_fqdn_sender',document.getElementById('reject_non_fqdn_sender-{$t}').value);\n\t\tXHR.sendAndLoad('{$page}', 'GET',xSave{$t});\t\n\t}\n</script>\t\t\t\n\t";
    //smtpd_client_connection_rate_limit = 100
    //smtpd_client_recipient_rate_limit = 20
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html, "postfix.index.php");
}
Exemple #16
0
function popup_dansguardian_main()
{
    $table = true;
    $mysql = new mysql();
    $mysqlSquid = new mysql_squid_builder();
    $users = new usersMenus();
    if (!$mysqlSquid->TABLE_EXISTS("dansguardian_categories", "artica_backup")) {
        $table = false;
    }
    if (!$mysql->TABLE_EXISTS("dansguardian_files", "artica_backup")) {
        $table = false;
    }
    if (!$mysql->TABLE_EXISTS("dansguardian_rules", "artica_backup")) {
        $table = false;
    }
    if (!$mysql->TABLE_EXISTS("dansguardian_weightedphraselist", "artica_backup")) {
        $table = false;
    }
    if (!$mysql->TABLE_EXISTS("dansguardian_ipgroups", "artica_backup")) {
        $table = false;
    }
    if (!$mysql->TABLE_EXISTS("dansguardian_whitelists", "artica_events")) {
        $table = false;
    }
    if (!$table) {
        popup_mysql_error();
        exit;
    }
    $page = CurrentPageName();
    $performances = Paragraphe("folder-tasks2-64.png", "{performances}", '{performances_text}', "javascript:YahooWin(500,'{$page}?main=performances');");
    $content_scanner = Paragraphe("64-webscanner.png", "{content_scanner}", '{content_scanner_text}', "javascript:YahooWin(651,'{$page}?main=scanner');");
    $download = Paragraphe("icon-download.gif", "{download}", '{download_text}', "javascript:YahooWin(600,'{$page}?main=download');");
    $rules = Paragraphe("folder-rules2-64.png", "{rules}", '{rules_text}', "javascript:YahooWin(600,'{$page}?popup-rules=yes');");
    $apply = applysettings_dansguardian();
    $squidguardweb = Paragraphe("parameters2-64-grey.png", "{banned_page_webservice}", "{banned_page_webservice_text}", null);
    $sock = new sockets();
    $logsize = trim($sock->getfile('DansGuardianLogSize'));
    $dansguardian_enabled = $sock->GET_INFO("DansGuardianEnabled");
    if ($dansguardian_enabled == null) {
        $dansguardian_enabled = 0;
        $sock->SET_INFO("DansGuardianEnabled", 0);
    }
    $squidGuardEnabled = $sock->GET_INFO("squidGuardEnabled");
    if ($squidGuardEnabled == null) {
        $squidGuardEnabled = 0;
        $sock->SET_INFO("squidGuardEnabled", 0);
    }
    $cicap_enabled = $sock->GET_INFO('CicapEnabled');
    $EnableUfdbGuard = $sock->GET_INFO("EnableUfdbGuard");
    $EnableSquidClamav = $sock->GET_INFO("EnableSquidClamav");
    $others = "\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td valign='top' class=caption nowrap>{logs_size}:</td>\n\t\t\t<td style='width:99%' valign='top'><strong>{$logsize}&nbsp;Ko</strong></td>\n\t\t\t<td>" . imgtootltip('22-recycle.png', '{rotate_logs}', "DansGuardianRotateLogs();") . "</td>\n\t\t</tr>\n\t\t</table>\n\t\t\t\n\t\t\n\t\n\t\n\t";
    if ($_GET["switch"] == "from-squid") {
        $OnMouseOver = "OnMouseOver=\";this.style.cursor='pointer'\"";
        $OnMouseOut = "OnMouseOut=\"this.style.cursor='default'\"";
        $from_squid = "<div style='padding:3px;font-size:13px'>{web_proxy}&nbsp;&raquo;<span {$OnMouseOver} {$OnMouseOut} OnClick=\"javascript:Loadjs('squid.newbee.php?yes=yes&#bullet#')\" >{filters}</span></div>";
    }
    $simple_intro = "{danseguardian_simple_intro}";
    if ($squidGuardEnabled == 1) {
        $simple_intro = "{squidguard_simple_intro}";
        $tool = "<div style='text-align:right'>" . texttooltip("&laquo;&nbsp;{squidguard_testrules}&nbsp;&raquo;", "{squidguard_testrules}", "Loadjs('squidguard.tests.php')", null, 0, "font-size:14px") . "</div>";
    }
    if ($EnableUfdbGuard == 1) {
        $simple_intro = "{ufdbguard_simple_intro}";
        $tool = null;
        $others = null;
    }
    $html = "\n\t <table style='width:100%;'>\n\t \t<tr>\n\t\t \t\t<td valign='top'>\n\t\t \t\t\t<img src='img/bg_dansguardian.png'>\n\t\t \t\t\t\n\t\t \t\t\t{$others}\n\t\t  \t\t</td>\n\t\t  \t\t<td valign='top'>\n\t\t  \t\t\t<p  style='font-size:13px'>{$from_squid}{$simple_intro}</p>\n\t\t  \t\t\t{$tool}\n\t\t  \t\t</td>\n\t\t  \t</tr>\n\t\t  </table>";
    $blackcomputer = Paragraphe("64-black-computer.png", "{black_ip_group}", '{black_ip_group_text}', "javascript:Loadjs('dansguardian.bannediplist.php');");
    $whitecomputer = Paragraphe("64-white-computer.png", "{white_ip_group}", '{white_ip_group_text}', "javascript:Loadjs('dansguardian.exceptioniplist.php');");
    $template = Paragraphe("banned-template-64.png", "{template_label}", '{template_explain}', "javascript:s_PopUp('dansguardian.template.php',800,800)");
    $denywebistes = Paragraphe('folder-64-denywebistes.png', '{deny_websites}', '{deny_websites_text}', "javascript:Loadjs('squid.popups.php?script=url_regex')");
    $whitelisting = Paragraphe('domain-whitelist-64-grey.png', '{www_whitelisting}', '{www_whitelisting_text}');
    // -> $cicap_enabled
    $cicap_dnsbl = Paragraphe("64-cop-acls-dnsbl.png", "{CICAP_DNSBL}", "{CICAP_DNSBL_TEXT}", "javascript:Loadjs('c-icap.dnsbl.php')");
    if ($cicap_enabled == 0) {
        $cicap_dnsbl = null;
    }
    if (!$users->C_ICAP_DNSBL) {
        $cicap_dnsbl = null;
    }
    if ($dansguardian_enabled == 0) {
        $download = null;
        $performances = null;
        $content_scanner = null;
        $apply = null;
    }
    writelogs("squidGuardEnabled={$squidGuardEnabled} - EnableUfdbGuard={$EnableUfdbGuard}", __FUNCTION__, __FILE__, __LINE__);
    if ($squidGuardEnabled == 1) {
        $squidguard_status = Paragraphe('squidguard-status-64.png', '{squidguard_status}', '{squidguard_status_text}', "javascript:Loadjs('squidguard.status.php')");
        $squidguardweb = Paragraphe("parameters2-64.png", "{banned_page_webservice}", "{banned_page_webservice_text}", "javascript:Loadjs('squidguardweb.php')");
        $whitelisting = Paragraphe('domain-whitelist-64.png', '{www_whitelisting}', '{www_whitelisting_text}', "javascript:Loadjs('squid.filters.whitelisting.php')");
        $whitelisting = Paragraphe('domain-whitelist-64.png', '{www_whitelisting}', '{www_whitelisting_text}', "javascript:echo('under construction')");
    }
    if ($EnableUfdbGuard == 1) {
        $squidguardweb = Paragraphe("parameters2-64.png", "{banned_page_webservice}", "{banned_page_webservice_text}", "javascript:Loadjs('squidguardweb.php')");
        $whitelisting = Paragraphe('domain-whitelist-64.png', '{www_whitelisting}', '{www_whitelisting_text}', "javascript:Loadjs('squid.filters.whitelisting.php')");
        $whitelisting = Paragraphe('domain-whitelist-64.png', '{www_whitelisting}', '{www_whitelisting_text}', "javascript:echo('under construction')");
    }
    if ($EnableSquidClamav == 1) {
        $squidguardweb = Paragraphe("parameters2-64.png", "{banned_page_webservice}", "{banned_page_webservice_text}", "javascript:Loadjs('squidguardweb.php')");
    }
    if ($users->APP_UFDBGUARD_INSTALLED) {
        $ufdbguard_settings = Paragraphe("filter-sieve-64.png", "{APP_UFDBGUARD}", "{APP_UFDBGUARD_PARAMETERS}", "javascript:Loadjs('ufdbguard.php')");
    }
    $tr[] = $apply;
    $tr[] = $whitelisting;
    $tr[] = $squidguard_status;
    $tr[] = $denywebistes;
    $tr[] = $cicap_dnsbl;
    $tr[] = $blackcomputer;
    $tr[] = $whitecomputer;
    $tr[] = $download;
    $tr[] = $ufdbguard_settings;
    $tr[] = $performances;
    $tr[] = $content_scanner;
    $tr[] = $template;
    $tr[] = $squidguardweb;
    $tables[] = "<table style='width:100%'><tr>";
    $t = 0;
    while (list($key, $line) = each($tr)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        $t = $t + 1;
        $tables[] = "<td valign='top'>{$line}</td>";
        if ($t == 3) {
            $t = 0;
            $tables[] = "</tr><tr>";
        }
    }
    if ($t < 3) {
        for ($i = 0; $i <= $t; $i++) {
            $tables[] = "<td valign='top'>&nbsp;</td>";
        }
    }
    $tables[] = "</table>";
    $html = $html . implode("\n", $tables);
    $tpl = new templates();
    $html = $tpl->_ENGINE_parse_body($html, "squid.newbee.php,squid.index.php");
    echo $html;
}
function bridge_list(){
	$q=new mysql();
	$tpl=new templates();
	$database="artica_backup";
	$table="nics_bridge";
	$MyPage=CurrentPageName();
	$t=$_GET["t"];
	
	if(!$q->TABLE_EXISTS("nics_bridge", "artica_backup")){
		json_error_show("nics_bridge no such table...",1);
	}
	
	$sock=new sockets();
	$net=new networking();
	$ip=new IP();
	$interfaces=unserialize(base64_decode($sock->getFrameWork("cmd.php?ifconfig-interfaces=yes")));
	$ERROR_NO_PRIVS=$tpl->javascript_parse_text("{ERROR_NO_PRIVS}");
	$DisableNetworksManagement=$sock->GET_INFO("DisableNetworksManagement");
	if($DisableNetworksManagement==null){$DisableNetworksManagement=0;}
	
	if(isset($_POST["sortname"])){
		if($_POST["sortname"]<>null){
			$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
		}
	}
	
	if (isset($_POST['page'])) {$page = $_POST['page'];}
	
	$searchstring=string_to_flexquery();
	if($searchstring<>null){
		$sql="SELECT COUNT( * ) AS tcount FROM $table WHERE 1 $searchstring";
		$ligne=mysql_fetch_array($q->QUERY_SQL($sql,$database));
		if(!$q->ok){json_error_show($q->mysql_error."<hr>".$sql,1);}
		$total = $ligne["tcount"];
	
	}else{
		$total = $q->COUNT_ROWS($table, $database);
	}
	
	if (isset($_POST['rp'])) {$rp = $_POST['rp'];}
	if(!is_numeric($page)){$page=1;}
	if(!is_numeric($rp)){$rp=50;}
	$pageStart = ($page-1)*$rp;
	$limitSql = "LIMIT $pageStart, $rp";
	
	
	
	$sql="SELECT * FROM `$table` WHERE 1 $searchstring $ORDER $limitSql";
	$results = $q->QUERY_SQL($sql,$database);
	if(!$q->ok){json_error_show($q->mysql_error."<hr>".$sql,1);}
	
	
	$data = array();
	$data['page'] = $page;
	$data['total'] = $total;
	$data['rows'] = array();
	if(mysql_num_rows($results)==0){json_error_show("No rule set...",1);}
	
	
	while ($ligne = mysql_fetch_assoc($results)) {
		$md=md5(serialize($ligne));
		$color="black";
		$ip=new IP();
		$cdir=$ligne["cdir"];
		$eth="br{$ligne["ID"]}";
		$eth_text="br{$ligne["ID"]}";
		
		if($ligne["cdir"]==null){
			$ligne["cdir"]=$net->array_TCP[$ligne["nic"]];
			$eth=$ligne["nic"];
		}
		
		if($ligne["cdir"]==null){
			$ligne["cdir"]=$net->array_TCP[$ligne["nic"]];
			$eth=$ligne["nic"];
		}
		$img="folder-network-48.png";
		
			
		$delete=imgsimple("delete-32.png",null,"Loadjs('$MyPage?network-bridge-delete-js={$ligne['ID']}&t=$t',true)");
		
		$js="Loadjs('$MyPage?network-bridge-js=yes&ID={$ligne['ID']}&t=$t',true);";
		$href="<a href=\"javascript:blur();\" OnClick=\"javascript:$js\" style='font-size:18px;color:$color;font-weight:normal;text-decoration:underline'>";
	
		
		$a=$ip->parseCIDR($cdir);
		if($a[0]==0){
			$img="warning-panneau-24.png";
			$cdir="<span style='color:red'>$cdir</span>";
		}
		$delete=imgsimple("delete-32.png",null,"Loadjs('$MyPage?network-bridge-delete-js={$ligne['ID']}&t=$t',true)");
	
		$js="Loadjs('$MyPage?network-bridge-js=yes&ID={$ligne['ID']}&t=$t',true);";
		$href="<a href=\"javascript:blur();\" OnClick=\"javascript:$js\" style='font-size:18px;color:$color;font-weight:normal;text-decoration:underline'>";
		$bridgedTo=bridgedTo($ligne["ID"]);
		$data['rows'][] = array(
			'id' => $ligne['ID'],
			'cell' => array(
				"<span style='font-size:18px;font-weight:bold;color:$color'>{$ligne['ID']}</span>",
				"<span style='font-size:18px;font-weight:normal;color:$color'>$href$eth_text</a></span>",
				"
				<span style='margin:5px;float:right'>
					<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('$MyPage?network-bridge-associates-js=yes&ID={$ligne['ID']}&t=$t',true);\">
					<img src='img/add-32.png'></a>
				</span>		
				<span style='font-size:18px;font-weight:normal;color:$color'>

				{$ligne["name"]}
				$bridgedTo
				
				</span>",
				"<span style='font-size:18px;font-weight:normal;color:$color'>{$ligne["ipaddr"]}</span>",
				"<span style='font-size:18px;font-weight:normal;color:$color'>{$ligne["netmask"]}</span>",
				$delete
			)
		);
	}
	
	
echo json_encode($data);
}	
function Bridges_list(){
	
	
	$t=$_GET["t"];
	$tpl=new templates();
	$MyPage=CurrentPageName();
	$q=new mysql();
	$users=new usersMenus();
	$sock=new sockets();
	$xtime=$_GET["xtime"];
	$table="iptables_bridge";
	$search='%';
	$database="artica_backup";	
	$page=1;
	$FORCE_FILTER=null;
	$tcp=new networking();
	
	if(!$q->TABLE_EXISTS($table, $database)){json_error_show("`$table` doesn't exists...");}
	if($q->COUNT_ROWS($table, $database)==0){json_error_show("No rule");}

	if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}}	
	if(isset($_POST['page'])) {$page = $_POST['page'];}
	
	$searchstring=string_to_flexquery();
	if($searchstring<>null){
		$sql="SELECT COUNT(*) as TCOUNT FROM $table WHERE 1 $FORCE_FILTER $searchstring";
		$ligne=mysql_fetch_array($q->QUERY_SQL($sql,$database));
		$total = $ligne["TCOUNT"];
		
	}else{
		$sql="SELECT COUNT(*) as TCOUNT FROM $table WHERE 1 $FORCE_FILTER";
		$ligne=mysql_fetch_array($q->QUERY_SQL($sql,$database));
		$total = $ligne["TCOUNT"];
	}
	
	if (isset($_POST['rp'])) {$rp = $_POST['rp'];}	
	

	
	$pageStart = ($page-1)*$rp;
	$limitSql = "LIMIT $pageStart, $rp";
	
	$sql="SELECT *  FROM $table WHERE 1 $searchstring $FORCE_FILTER $ORDER $limitSql";	
	writelogs($sql,__FUNCTION__,__FILE__,__LINE__);
	$results = $q->QUERY_SQL($sql,$database);
	
	$data = array();
	$data['page'] = $page;
	$data['total'] = $total;
	$data['rows'] = array();
	
	if(!$q->ok){json_error_show($q->mysql_error);}	

	while ($ligne = mysql_fetch_assoc($results)) {
	$zmd5=md5(serialize($ligne));
	$color="black";
	$ipaddrinfos=VirtualNicInfosIPaddr($ligne["nics_virtuals_id"]);
	$nic_linked=$ligne["nic_linked"];
	$infos=$tcp->GetNicInfos($nic_linked);	
	$rulesIcon=imgsimple("script-32.png","{rules}","BridgeRules({$ligne["ID"]})");
	$delete=imgsimple("delete-24.png","{delete}","BridgeDelete({$ligne["ID"]},'$zmd5')");
	$data['rows'][] = array(
		'id' => "$zmd5",
		'cell' => array(
			"<span style='font-size:16px;color:$color'><img src='img/folder-network-32.png'></span>",
			"<span style='font-size:16px;color:$color'>{$ipaddrinfos["ETH"]} ({$ipaddrinfos["IPADDR"]})</span>",
			"<span style='font-size:16px;color:$color'><img src='img/arrow-right-32.png'></span>",
			"<span style='font-size:16px;color:$color'>$nic_linked ({$infos["IPADDR"]})</strong></span>",
			"<span style='font-size:16px;color:$color'>$rulesIcon</span>",
			"<span style='font-size:16px;color:$color'>$delete</span>",
			)
		);
	}
	
	
echo json_encode($data);

}
Exemple #19
0
function items()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql();
    $t = $_GET["tt"];
    $search = '%';
    $table = "texttoldap";
    $page = 1;
    $FORCE_FILTER = null;
    $total = 0;
    if (!$q->TABLE_EXISTS("texttoldap", "artica_backup")) {
        $q->BuildTables();
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS("texttoldap", "artica_backup");
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    if (is_numeric($rp)) {
        $limitSql = "LIMIT {$pageStart}, {$rp}";
    }
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    $no_rule = $tpl->_ENGINE_parse_body("{no_rule}");
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}");
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data {$sql}");
    }
    $fontsize = "14";
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $NICNAME = null;
        $delete = imgsimple("delete-32.png", null, "Loadjs('{$MyPage}?remove-connection-js={$ligne["ID"]}&t={$_GET["t"]}&t-rule={$_GET["t-rule"]}&tt={$_GET["tt"]}')");
        $editjs = "<a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:Loadjs('{$MyPage}?js=yes&connection-id={$ligne['ID']}&t={$_GET["t"]}',true);\"\n\t\tstyle='font-size:{$fontsize}px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $connection = $ligne["connection"];
        $folder = $ligne["folder"];
        $hostname = $ligne["hostname"];
        $filename = $ligne["filename"];
        $ldap_group = $ligne["ldapgroup"];
        $ldap_group_text = "-";
        if ($ligne["ldapgroup"] > 0) {
            $gp = new groups($ligne["ldapgroup"]);
            $ldap_group_text = $gp->groupName;
        }
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array("<span style='font-size:{$fontsize}px;font-weight:bold;color:{$color}'>{$editjs}{$connection}</span>", "<span style='font-size:{$fontsize}px;font-weight:bold;color:{$color}'>{$editjs}{$folder}</a></span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$hostname}</span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$filename}</span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$ldap_group_text}</span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$delete}</span>"));
    }
    echo json_encode($data);
}
Exemple #20
0
function status()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $main = new maincf_multi($_GET["instance"]);
    $array_filters = unserialize(base64_decode($main->GET_BIGDATA("PluginsEnabled")));
    $reconfigure = Paragraphe("64-settings-refresh.png", "{generate_config}", "{postfix_reconfigure_text}", "javascript:postfwd2Reconfigure()");
    $q = new mysql();
    if (!$q->TABLE_EXISTS('postfwd2', 'artica_backup')) {
        $q->check_postfwd2_table();
        $q = new mysql();
        if (!$q->TABLE_EXISTS('postfwd2', 'artica_backup')) {
            echo "<H2>Table postfwd2 -> artica_backup failed</H2>";
        }
    }
    $html = "\n\t<table style='width:100%'>\n\t<tr>\n\t<td valign='top'>\n\t\t<div style='font-size:18px'>{APP_POSTFWD2}</div>\n\t\t<div style='text-align:right;padding-top:5px;border-top:1px solid #CCCCCC'><i style='font-size:14px'>&laquo;&nbsp;{instance}:{$_GET["instance"]}&nbsp;&raquo;</i></div>\n\t\t<p>&nbsp;</p>\n\t\t<div class=explain style='font-size:14px'>{POSTFWD2_ABOUT}</div>\n\t</td>\n\t<td valign='top' style='width:270px'>\n\t\t<table style='width:99%' class=form>\n\t\t\t<tr>\n\t\t\t\t<td class=legend>{enable_service}</td>\n\t\t\t\t<td>" . Field_checkbox("EnablePOSTFWD2", 1, $array_filters["APP_POSTFWD2"], "EnablePOSTFWD2Check()") . "</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>&nbsp;</p>\n\t\t<div id='postfwd2-status'></div>\n\t\t<p>&nbsp;</p>\n\t\t{$reconfigure}\n\t</tr>\n\t</table>\n\t\n\t<script>\n\t\n\tvar x_EnablePOSTFWD2Check= function (obj) {\n\t\tvar tempvalue=obj.responseText;\n\t\tif(tempvalue.length>3){alert(tempvalue);}\t\n\t\tRefreshTab('main_config_postfwd2');\n\t\tif(IsFunctionExists('RefreshTabMainMultiConfigPostfix')){RefreshTabMainMultiConfigPostfix();}\n\t\t\n\t}\t\t\n\t\n\tfunction EnablePOSTFWD2Check(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('EnablePOSTFWD2').checked){XHR.appendData('EnablePOSTFWD2',1);}else{XHR.appendData('EnablePOSTFWD2',0);}\n\t\tXHR.appendData('instance','{$_GET["instance"]}');\t\n\t\tXHR.sendAndLoad('{$page}', 'GET',x_EnablePOSTFWD2Check);\n\t\t}\t\t\n\t\n\t\tfunction Postfwd2Status(){\n\t\t\tLoadAjax('postfwd2-status','{$page}?service-status=yes&instance={$_GET["instance"]}');\n\t\t}\n\t\t\n\t\tfunction postfwd2Reconfigure(){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('instance','{$_GET["instance"]}');\n\t\t\tXHR.appendData('reconfigure','yes');\t\t\n\t\t\tXHR.sendAndLoad('{$page}', 'GET',x_EnablePOSTFWD2Check);\n\t\t}\n\t\t\n\t\tPostfwd2Status();\n\t</script>";
    echo $tpl->_ENGINE_parse_body($html);
}
function main_table()
{
    $t = time();
    $page = CurrentPageName();
    $tpl = new templates();
    $users = new usersMenus();
    $sock = new sockets();
    $q = new mysql();
    if (!$q->TABLE_EXISTS("sender_dependent_relay_host", "artica_backup")) {
        $q->BuildTables();
    }
    $t = time();
    $domain = $tpl->_ENGINE_parse_body("{sender_domain_email}");
    $are_you_sure_to_delete = $tpl->javascript_parse_text("{are_you_sure_to_delete}");
    $relay = $tpl->javascript_parse_text("{relay}");
    $MX_lookups = $tpl->javascript_parse_text("{MX_lookups}");
    $delete = $tpl->javascript_parse_text("{delete}");
    $InternetDomainsAsOnlySubdomains = $sock->GET_INFO("InternetDomainsAsOnlySubdomains");
    if (!is_numeric($InternetDomainsAsOnlySubdomains)) {
        $InternetDomainsAsOnlySubdomains = 0;
    }
    $add_local_domain_form_text = $tpl->javascript_parse_text("{add_local_domain_form}");
    $add_local_domain = $tpl->_ENGINE_parse_body("{add_local_domain}");
    $sender_dependent_relayhost_maps_title = $tpl->_ENGINE_parse_body("{sender_dependent_relayhost_maps_title}");
    $ouescape = urlencode($ou);
    $destination = $tpl->javascript_parse_text("{destination}");
    $hostname = $_GET["hostname"];
    $apply = $tpl->javascript_parse_text("{apply}");
    $about2 = $tpl->javascript_parse_text("{about2}");
    $add_sender_routing_rule = $tpl->_ENGINE_parse_body("{add_sender_routing_rule}");
    $add_remote_domain = Paragraphe("64-remotedomain-add.png", '{add_relay_domain}', '{add_relay_domain_text}', "javascript:AddRemoteDomain_form(\"{$ou}\",\"new domain\")", "add_relay_domain", 210);
    $buttons = "\n\tbuttons : [\n\t{name: '{$add_sender_routing_rule}', bclass: 'add', onpress : add_sender_routing_rule{$t}},\n\t{name: '{$apply}', bclass: 'apply', onpress : apply_sender_routing_rule{$t}},\n\t{name: '{$about2}', bclass: 'help', onpress : Help{$t}},\n\t],";
    $explain = $tpl->javascript_parse_text("{postfix_transport_senders_explain}");
    $html = "\n\t<input type='hidden' id='ou' value='{$ou}'>\n\t<table class='SENDER_DEPENDENT_RELAY_HOST' style='display: none' id='SENDER_DEPENDENT_RELAY_HOST' style='width:100%'></table>\n\t<script>\n\t\$(document).ready(function(){\n\t\$('#SENDER_DEPENDENT_RELAY_HOST').flexigrid({\n\turl: '{$page}?relay-sender-table-list=yes&hostname={$hostname}&t={$t}',\n\tdataType: 'json',\n\tcolModel : [\n\t{display: '{$domain}', name : 'domain', width : 428, sortable : true, align: 'left'},\n\t{display: '{$relay}', name : 'relay', width :260, sortable : true, align: 'left'},\n\t{display: 'AUTH', name : 'zOrders', width : 50, sortable : false, align: 'center'},\n\t{display: 'UP', name : 'zOrders', width : 50, sortable : true, align: 'center'},\n\t{display: 'DOWN', name : 'zOrders', width : 50, sortable : true, align: 'center'},\n\t{display: '{$delete};', name : 'delete', width : 75, sortable : false, align: 'center'},\n\t],\n\t{$buttons}\n\tsearchitems : [\n\t{display: '{$domain}', name : 'domain'},\n\t{display: '{$relay}', name : 'relay'},\n\t],\n\tsortname: 'zOrders',\n\tsortorder: 'asc',\n\tusepager: true,\n\ttitle: '',\n\tuseRp: true,\n\trp: 50,\n\tshowTableToggleBtn: false,\n\twidth: '99%',\n\theight: '550',\n\tsingleSelect: true,\n\trpOptions: [10, 20, 30, 50,100,200]\n\n});\n});\n\nfunction  Help{$t}(){\nalert('{$explain}');\n}\n\nvar RefreshTable{$t}= function (obj) {\n\tvar results=obj.responseText;\n\tif (results.length>0){alert(results);return;}\n\t\$('#SENDER_DEPENDENT_RELAY_HOST').flexReload();\n}\n\nfunction MoveSubRuleLinks{$t}(mkey,direction){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('item-move', mkey);\n\tXHR.appendData('direction', direction);\n\tXHR.appendData('hostname', '{$hostname}');\n\tXHR.sendAndLoad('{$page}', 'POST',RefreshTable{$t});\t\n}\n\nfunction add_sender_routing_rule{$t}(){\n\tLoadjs('{$page}?item-js=yes&zmd5=&hostname={$hostname}');\n}\n\nfunction sender_routing_ruleED{$t}(domainName){\n\tYahooWin3(552,'postfix.routing.table.php?SenderTable=yes&domainName='+domainName+'&t={$t}','{$sender_dependent_relayhost_maps_title}::'+domainName);\n}\n\n\nfunction apply_sender_routing_rule{$t}(){\n\tLoadjs('postfix.sender.routing.progress.php?hostname={$hostname}');\n\n}\n\n</script>\n";
    echo $html;
}
Exemple #22
0
function events($severity, $subject, $content)
{
    // 0 -> RED, 1 -> WARN, 2 -> INFO
    $file = basename(__FILE__);
    if (function_exists("debug_backtrace")) {
        $trace = debug_backtrace();
        if (isset($trace[1])) {
            $function = $trace[1]["function"];
            $line = $trace[1]["line"];
        }
    }
    $zdate = date("Y-m-d H:i:s");
    $q = new mysql();
    if (!$q->TABLE_EXISTS("hotspot_admin_mysql", "artica_events")) {
        $sql = "CREATE TABLE IF NOT EXISTS `artica_events`.`hotspot_admin_mysql` (\n\t\t\t`ID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`zDate` TIMESTAMP NOT NULL ,\n\t\t\t`content` MEDIUMTEXT NOT NULL ,\n\t\t\t`subject` VARCHAR( 255 ) NOT NULL ,\n\t\t\t`function` VARCHAR( 60 ) NOT NULL ,\n\t\t\t`filename` VARCHAR( 50 ) NOT NULL ,\n\t\t\t`line` INT( 10 ) NOT NULL ,\n\t\t\t`severity` smallint( 1 ) NOT NULL ,\n\t\t\t`TASKID` BIGINT UNSIGNED ,\n\t\t\tPRIMARY KEY (`ID`),\n\t\t\t  KEY `zDate` (`zDate`),\n\t\t\t  KEY `subject` (`subject`),\n\t\t\t  KEY `function` (`function`),\n\t\t\t  KEY `filename` (`filename`),\n\t\t\t  KEY `severity` (`severity`)\n\t\t\t) ENGINE=MYISAM;";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
            return;
        }
    }
    $q->QUERY_SQL("INSERT IGNORE INTO `hotspot_admin_mysql`\n\t\t\t(`zDate`,`content`,`subject`,`function`,`filename`,`line`,`severity`) VALUES\n\t\t\t('{$zdate}','{$content}','{$subject}','{$function}','{$file}','{$line}','{$severity}')", "artica_events");
}
function ParseKav4UriLogs()
{
    $users = new usersMenus();
    if (!$users->KAV4PROXY_INSTALLED) {
        die;
    }
    $unix = new unix();
    if (system_is_overloaded(basename(__FILE__))) {
        if ($GLOBALS["VERBOSE"]) {
            "System overloaded\n";
        }
        return;
    }
    if (!$GLOBALS["NO_PID_CHECKS"]) {
        if (stats_pid()) {
            return;
        }
    }
    $tablename = "Kav4Proxy_" . date('Y') . date('m');
    if ($GLOBALS["VERBOSE"]) {
        echo "Table {$tablename}/artica_events...\n";
    }
    $q = new mysql();
    if (!$q->TABLE_EXISTS($tablename, "artica_events")) {
        $sql = "CREATE TABLE `artica_events`.`{$tablename}` (\n\t\t`zmd5` VARCHAR( 90 ) NOT NULL ,\n\t\t`zDate` DATETIME NOT NULL ,\n\t\t`size` INT UNSIGNED NOT NULL,\n\t\t`status` VARCHAR( 40 ) NOT NULL ,\n\t\t`ICAP_SERVER` VARCHAR( 40 ) NOT NULL ,\n\t\t`uid` VARCHAR( 128 ) NOT NULL ,\n\t\t`client` VARCHAR( 40 ) NOT NULL ,\n\t\t`uri` VARCHAR( 255 ) NOT NULL ,\n\t\t`country` VARCHAR( 90 ) NOT NULL ,\n\t\t`sitename` VARCHAR( 128 ) NOT NULL ,\n\t\t`category` VARCHAR( 90 ) NOT NULL ,\n\t\tPRIMARY KEY ( `zmd5` ) ,\n\t\tKEY `zDate` (`zDate`),\n\t\tKEY `size` (`size`),\n\t\tKEY `status` (`status`),\n\t\tKEY `ICAP_SERVER` (`ICAP_SERVER`),\n\t\tKEY `uid` (`uid`),\n\t\tKEY `client` (`client`),\n\t\tKEY `country` (`country`),\n\t\tKEY `sitename` (`sitename`),\n\t\tINDEX ( `category` )\n\t\t)";
        $q->QUERY_SQL($sql, "artica_events");
        if ($GLOBALS["VERBOSE"]) {
            echo "Table {$tablename}/artica_events failed...\n";
        }
        if (!$q->ok) {
            $unix->send_email_events("Unable to create {$tablename}/artica_events", "Kaspersky statistics has been aborted\n{$q->mysql_error}", "proxy");
            return;
        }
    }
    $WorkingDirectory = "/var/log/artica-postfix/kav4Server-queue";
    $WorkingDirectoryError = "/var/log/artica-postfix/kav4Server-errors";
    if (!is_dir($WorkingDirectoryError)) {
        @mkdir($WorkingDirectoryError, 0600, true);
    }
    if (!($handle = @opendir($WorkingDirectory))) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$WorkingDirectory} no such directory\n";
        }
        return;
    }
    //$newArray=array("DATE" =>$date,"SIZE"=>$size,"STATUS"=>$status,"ICAP_SERVER"=>$icap_server,"UID"=>$uid,
    //"CLIENT"=>$clientip,"URI"=>$uri,"COUNTRY"=>$Country,"SITENAME"=>$sitename);
    if ($GLOBALS["VERBOSE"]) {
        echo "Processing {$WorkingDirectory}\n";
    }
    $prefixsql = "INSERT IGNORE INTO {$tablename} (`zmd5`,`zDate`,`size`,`status`,`ICAP_SERVER`,`uid`,`client`,`uri`,`country`,`sitename`) VALUES ";
    while (false !== ($filename = readdir($handle))) {
        $targetFile = "{$WorkingDirectory}/{$filename}";
        if ($GLOBALS["VERBOSE"]) {
            echo "Processing {$targetFile}\n";
        }
        if (!is_file($targetFile)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Processing {$targetFile} no such file\n";
            }
            continue;
        }
        $array = unserialize(@file_get_contents($targetFile));
        if (!is_array($array)) {
            @unlink($targetFile);
            if ($GLOBALS["VERBOSE"]) {
                echo "Processing {$targetFile} not an array\n";
            }
            continue;
        }
        $md5 = md5(serialize($array));
        $suffix[] = "('{$md5}','{$array["DATE"]}','{$array["SIZE"]}','{$array["STATUS"]}','{$array["ICAP_SERVER"]}',\n\t\t'{$array["UID"]}','{$array["CLIENT"]}','{$array["URI"]}','{$array["COUNTRY"]}',\n\t\t'{$array["SITENAME"]}')";
        @unlink($targetFile);
        if (count($suffix) > 500) {
            $d = $d + count($suffix);
            $sql = "{$prefixsql} " . @implode(",", $suffix);
            $q->QUERY_SQL($sql, "artica_events");
            if (!$q->ok) {
                @file_put_contents($sql, "{$WorkingDirectoryError}/" . md5($sql) . ".err");
                $unix->send_email_events("kav4proxy statistics Mysql error", "{$q->mysql_error}\nProcess has been aborted and saved in {$WorkingDirectoryError} directory", "proxy");
            }
            if (system_is_overloaded(basename(__FILE__))) {
                $unix->send_email_events("kav4proxy statistics aborted du to overload computer", "Will retry in next cycle", "proxy");
                return;
            }
        }
    }
    if (count($suffix) > 1) {
        $d = $d + count($suffix);
        $sql = "{$prefixsql} " . @implode(",", $suffix);
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            @file_put_contents($sql, "{$WorkingDirectoryError}/" . md5($sql) . "err");
            $unix->send_email_events("kav4proxy statistics Mysql error", "{$q->mysql_error}\nProcess has been aborted and saved in {$WorkingDirectoryError} directory", "proxy");
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "processed {$d} files\n";
    }
}
function items_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql();
    if (!$q->TABLE_EXISTS("phpmyadminsecu", "artica_backup")) {
        $q->BuildTables();
    }
    $t = $_GET["t"];
    $search = '%';
    $table = "phpmyadminsecu";
    $database = "artica_backup";
    $page = 1;
    $ORDER = null;
    $FORCE_FILTER = null;
    if ($q->COUNT_ROWS($table, $database) == 0) {
        $data['page'] = $page;
        $data['total'] = $total;
        $data['rows'] = array();
        echo json_encode($data);
        return;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS($table, $database);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if ($OnlyEnabled) {
        $limitSql = null;
    }
    $sql = "SELECT *  FROM `{$table}` WHERE 1 {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
    }
    $typeA[0] = "{ip_address}";
    $typeA[1] = "{hostname}";
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $md5 = md5($ligne["ID"] . $ligne["pattern"]);
        $js = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?item-js=yes&table={$t}&ID={$ligne["ID"]}');\"\n\t\tstyle='font-size:16px;color:{$color};text-decoration:underline'>";
        $delete = imgtootltip("delete-24.png", "{delete}", "DeletedMysqlItemDen('{$ligne["ID"]}','{$md5}')");
        $enable = Field_checkbox($md5, 1, $ligne["enabled"], "MysqlEnableItem('{$md5}','{$ligne["ID"]}')");
        $data['rows'][] = array('id' => $md5, 'cell' => array("{$js}{$ligne["pattern"]}</a>", $tpl->_ENGINE_parse_body("<span style='font-size:14px;color:{$color}'>{$js}{$typeA[$ligne["type"]]}</a></span>"), "<div style='margin-top:5px'>{$enable}</div>", $delete));
    }
    echo json_encode($data);
}
function table_blacklist_items()
{
    $myPage = CurrentPageName();
    $t = $_GET["t"];
    $tpl = new templates();
    $table = "`contacts_blacklist`";
    $uid = $_SESSION["uid"];
    $search = '%';
    $database = "artica_backup";
    $page = 1;
    $FORCE_FILTER = " AND uid='{$uid}'";
    $q = new mysql();
    if (!$q->TABLE_EXISTS($table, "artica_backup")) {
        json_error_show("{$table}: No such table", 0, true);
    }
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("{$table}: Empty", 0, true);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show($q->mysql_error);
        }
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show($q->mysql_error);
        }
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    while ($ligne = mysql_fetch_assoc($results)) {
        $sender = $ligne["sender"];
        $md = $ligne["md5"];
        $color = "black";
        $delete = imgsimple("delete-32.png", null, "BlackDel{$t}('{$sender}','{$md}')");
        $enabled = $ligne["enabled"];
        if ($enabled == 0) {
            $color = "#847F7F";
        }
        $move = imgsimple("arrow-blue-left-32.png", null, "MoveToWhite{$t}('{$md}','{$sender}')");
        $enablechk = Field_checkbox("enable_{$md}", 1, $enabled, "BlckEnable{$t}('{$md}')");
        //$subject=mime_decode($subject);
        $data['rows'][] = array('id' => $md, 'cell' => array("<span style='font-size:18px;color:{$color};font-weight:bold'>{$sender}</a></span>", "<span style='font-size:18px;color:{$color}'>{$enablechk}</a></span>", "<span style='font-size:18px;color:{$color}'>{$move}</a></span>", "<span style='font-size:18px;color:{$color}'>{$delete}</a></span>"));
    }
    echo json_encode($data);
}
Exemple #26
0
function add_memory_value($memory)
{
    $q = new mysql();
    if (!$q->TABLE_EXISTS("nginx_mem", "artica_events")) {
        $sql = "CREATE TABLE `nginx_mem`  (\n\t\t\t  `zDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t  `xmemory` DEC(10,2) NOT NULL ,\n\t\t\t  UNIQUE KEY `zDate` (`zDate`),\n\t\t\t\tKEY `memory` (`xmemory`)\n\t\t\t\t) ENGINE=MYISAM;";
        $q->QUERY_SQL($sql, "artica_events");
    }
    $q->QUERY_SQL("INSERT IGNORE INTO nginx_mem (`xmemory`) VALUES ('{$memory}')", "artica_events");
}
Exemple #27
0
    if (preg_match("#Unknown database#", $q->mysql_error)) {
        writelogs("Unknown database detected, -> q->BuildTables();", __FUNCTION__, __FILE__, __LINE__);
        $q->BuildTables();
        return;
    }
    if (preg_match("#Access denied for user#", $q->mysql_error)) {
        $error = urlencode(base64_encode($q->mysql_error));
        echo "\n\t\t\t<script>\n\t\t\t\tLoadjs('admin.mysql.error.php?error={$error}');\n\t\t\t</script>\n\t\t\t";
        return;
    }
    echo $q->mysql_error;
    return;
}
$count = mysql_num_rows($results);
echo "<center style='margin-bottom:10px'>";
if (!$q->TABLE_EXISTS("loadavg", "artica_events")) {
    $q->BuildTables();
}
// --------------------------------------------------------------------------------------
$mysql_num_rows = mysql_num_rows($results);
if ($mysql_num_rows == 0) {
    $mysql_num_rows = $q->COUNT_ROWS('loadavg', "artica_events");
    writelogs("mysql return no rows from a table of {$allrows} rows ", __FUNCTION__, __FILE__, __LINE__);
    if ($mysql_num_rows > 10) {
        $sql = "SELECT AVG( `load` ) AS sload, DATE_FORMAT( stime, '%h:%i' ) AS ttime FROM `loadavg` WHERE `stime` > DATE_SUB( NOW( ) , INTERVAL 200 MINUTE ) GROUP BY ttime ORDER BY `ttime` ASC";
        $results = $q->QUERY_SQL($sql, "artica_events");
        $mysql_num_rows = mysql_num_rows($results);
    }
}
if (!$q->ok) {
    echo $q->mysql_error;
Exemple #28
0
function backup($ID)
{
    $date_start = time();
    $sock = new sockets();
    $q = new mysql();
    $unix = new unix();
    $users = new usersMenus();
    $GLOBALS["RESOURCE_MOUNTED"] = true;
    $sql = "SELECT * FROM backup_schedules WHERE ID='{$ID}'";
    if ($GLOBALS["VERBOSE"]) {
        backup_events($ID, "initialization", "{$sql}", __LINE__);
    }
    $mount_path = "/opt/artica/mounts/backup/{$ID}";
    if (!$q->TABLE_EXISTS("backup_storages", "artica_backup", true)) {
        $q->BuildTables();
        if (!$q->TABLE_EXISTS("backup_storages", "artica_backup", true)) {
            backup_events($ID, "initialization", "ERROR, backup_storages, no such table", __LINE__);
            return;
        }
    }
    $servername = $users->fqdn;
    $servername = str_replace('.(none)', "", $servername);
    $servername = str_replace(')', "", $servername);
    $servername = str_replace('(', "", $servername);
    $GLOBALS["MYSERVERNAME"] = $servername;
    $ExecBackupDeadAfterH = $sock->GET_INFO("ExecBackupDeadAfterH");
    if (!is_numeric($ExecBackupDeadAfterH)) {
        $ExecBackupDeadAfterH = 2;
    }
    if ($ExecBackupDeadAfterH < 2) {
        $ExecBackupDeadAfterH = 2;
    }
    $ExecBackupDeadAfterH = $ExecBackupDeadAfterH * 60;
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        send_email_events("Backup Task {$ID}:: Mysql database error !", "Aborting backup\n{$q->mysql_error}", "backup");
        backup_events($ID, "initialization", "ERROR, Mysql database error\n{$q->mysql_error}", __LINE__);
        return false;
    }
    if (!$GLOBALS["ONNLY_MOUNT"]) {
        $pid = $ligne["pid"];
        if ($unix->process_exists($pid)) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($time > $ExecBackupDeadAfterH) {
                send_email_events("Backup Task {$ID}:: Already instance {$pid} running since {$time}Mn", "The old process was killed and a new backup task will be performed\nstatus:\n\n{$unix->proc_status}", "backup");
            } else {
                send_email_events("Backup Task {$ID}:: Already instance {$pid} running since {$time}Mn", "Aborting backup\n{$unix->proc_status}", "backup");
                backup_events($ID, "initialization", "ERROR, Already instance {$pid} running since {$time}Mn", $unix->proc_status);
                return false;
            }
        }
    }
    $sql = "UPDATE backup_schedules set pid='" . getmypid() . "' WHERE ID='{$ID}'";
    $q->QUERY_SQL($sql, "artica_backup");
    $ressources = unserialize(base64_decode($ligne["datasbackup"]));
    if (count($ressources) == 0) {
        backup_events($ID, "initialization", "ERROR,No source specified");
        send_email_events("Backup Task {$ID}::  No source specified", "Aborting backup", "backup");
        return false;
    }
    if ($ressources["OPTIONS"]["STOP_IMAP"] == 1) {
        $GLOBALS["NO_STOP_CYRUS"] = " --no-cyrus-stop";
    }
    $backup = new backup_protocols();
    $resource_type = $ligne["resource_type"];
    $pattern = $ligne["pattern"];
    $first_ressource = $backup->extractFirsRessource($ligne["pattern"]);
    $container = $ligne["container"];
    backup_events($ID, "initialization", "resource: {$resource_type} -> {$first_ressource}", __LINE__);
    if ($resource_type == null) {
        backup_events($ID, "initialization", "ERROR,No resource specified");
        send_email_events("Backup Task {$ID}:: No resource specified !", "Aborting backup", "backup");
        return false;
    }
    if ($resource_type == "smb") {
        $GLOBALS["CAN_CLEAN_CONTAINERS"] = true;
        $mounted_path_sep = "/";
        if (!mount_smb($pattern, $ID, true)) {
            backup_events($ID, "initialization", "ERROR,{$first_ressource} unable to mount mount_smb()", __LINE__);
            send_email_events("Backup Task {$ID}::  resource: {$first_ressource} unable to mount", "Aborting backup", "backup");
            return false;
        }
        $GLOBALS["PCOPY"] = true;
    }
    if ($resource_type == "ssh") {
        $GLOBALS["CAN_CLEAN_CONTAINERS"] = true;
        $mounted_path_sep = "/";
        if (!mount_ssh($pattern, $ID, true)) {
            backup_events($ID, "initialization", "ERROR,{$first_ressource} unable to mount mount_ssh()", __LINE__);
            send_email_events("Backup Task {$ID}::  resource: {$first_ressource} unable to mount to remote ssh service", "Aborting backup", "backup");
            return false;
        }
        $GLOBALS["PCOPY"] = true;
    }
    if ($resource_type == "usb") {
        $GLOBALS["CAN_CLEAN_CONTAINERS"] = true;
        $mounted_path_sep = "/";
        if (!mount_usb($pattern, $ID, true)) {
            backup_events($ID, "initialization", "ERROR,{$first_ressource} unable to mount mount_usb()", __LINE__);
            send_email_events("Backup Task {$ID}::  resource: {$first_ressource} unable to mount", "Aborting backup", "backup");
            return false;
        }
        backup_events($ID, "initialization", "INFO, using external device trough USB", __LINE__);
        $GLOBALS["PCOPY"] = true;
    }
    if ($resource_type == "rsync") {
        $mounted_path_sep = null;
        $mount_path = null;
        $GLOBALS["RESOURCE_MOUNTED"] = false;
        $GLOBALS["USE_RSYNC"] = true;
        $GLOBALS["NO_UMOUNT"] = true;
        $GLOBALS["CAN_CLEAN_CONTAINERS"] = false;
        if (!mount_rsync($pattern, $ID, true)) {
            backup_events($ID, "initialization", "ERROR,{$first_ressource} unable to connect");
            send_email_events("Backup Task {$ID}::  resource: {$first_ressource} unable to connect", "Aborting backup", "backup");
            return false;
        } else {
            backup_events($ID, "initialization", "INFO,{$first_ressource} connect success");
        }
    }
    if ($resource_type == "automount") {
        $mounted_path_sep = "/";
        $mount_path = $first_ressource;
        $GLOBALS["RESOURCE_MOUNTED"] = false;
        $GLOBALS["USE_RSYNC"] = true;
        $GLOBALS["NO_UMOUNT"] = true;
        $GLOBALS["CAN_CLEAN_CONTAINERS"] = true;
        $GLOBALS["MOUNTED_PATH_FINAL"] = $first_ressource;
        CheckCommandLineCopy();
        if (!mount_automount($pattern, $ID, true)) {
            backup_events($ID, "initialization", "ERROR,{$first_ressource} unable to connect");
            send_email_events("Backup Task {$ID}::  resource: {$first_ressource} unable to connect", "Aborting backup", "backup");
            return false;
        }
        backup_events($ID, "initialization", "INFO,{$first_ressource} connect success");
        $GLOBALS["PCOPY"] = true;
    }
    if ($resource_type == "local") {
        $mounted_path_sep = "/";
        $mount_path = $first_ressource;
        $GLOBALS["RESOURCE_MOUNTED"] = false;
        $GLOBALS["CAN_CLEAN_CONTAINERS"] = true;
        $GLOBALS["USE_RSYNC"] = true;
        $GLOBALS["NO_UMOUNT"] = true;
        $GLOBALS["MOUNTED_PATH_FINAL"] = $first_ressource;
        CheckCommandLineCopy();
        if (!is_dir($first_ressource)) {
            backup_events($ID, "initialization", "{$first_ressource} directory doesn't exsits, create it..", __LINE__);
            @mkdir($first_ressource, 0755, true);
        }
        if (!is_dir($first_ressource)) {
            backup_events($ID, "initialization", "{$first_ressource} no such directory permission denied", __LINE__);
            send_email_events("Backup Task {$ID}::  resource: {$first_ressource} no such directory", "Aborting backup", "backup");
            return false;
        }
        backup_events($ID, "initialization", "INFO,{$first_ressource} success");
        $GLOBALS["PCOPY"] = true;
    }
    if ($GLOBALS["ONLY_TESTS"]) {
        if ($GLOBALS["RESOURCE_MOUNTED"]) {
            writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]:umount {$mount_path}", __FUNCTION__, __FILE__, __LINE__);
            exec("umount -l {$mount_path}");
        }
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: terminated...", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if ($GLOBALS["ONNLY_MOUNT"]) {
        return $mount_path;
    }
    if ($container == "daily") {
        backup_events($ID, "initialization", "INFO, Daily container", __LINE__);
        $DirectoryContainer = "backup." . date('Y-m-d') . "/{$servername}";
        $GLOBAL["BACKUP_MEMORY_SQL"]["CONTAINER"] = $DirectoryContainer;
        $mount_path_final = $mount_path . $mounted_path_sep . $DirectoryContainer;
    } else {
        backup_events($ID, "initialization", "INFO, Weekly container", __LINE__);
        $DirectoryContainer = "backup." . date('Y-W') . "/{$servername}";
        $GLOBAL["BACKUP_MEMORY_SQL"]["CONTAINER"] = $DirectoryContainer;
        $mount_path_final = $mount_path . $mounted_path_sep . $DirectoryContainer;
    }
    if ($GLOBALS["DEBUG"]) {
        $cmd_verb = " --verbose";
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: Verbose mode detected", __FUNCTION__, __FILE__, __LINE__);
    }
    @mkdir($mount_path_final, 0755, true);
    if (!$GLOBALS["NO_STANDARD_BACKUP"]) {
        $GLOBALS["MOUNTED_PATH_FINAL"] = $mount_path_final;
        $WhatToBackup_ar = null;
        $BACKUP_WWW_ALREADY_DONE = array();
        $BACKUP_WEBGET_ALREADY_DONE = array();
        $BACKUP_INSTANCES_ALREADY_DONE = array();
        while (list($num, $WhatToBackup) = each($ressources)) {
            if (is_array($WhatToBackup)) {
                $WhatToBackup_ar = implode(",", $WhatToBackup);
                backup_events($ID, "initialization", "INFO, WhatToBackup Array = {$WhatToBackup_ar}", __LINE__);
                continue;
            }
            if ($WhatToBackup == "all") {
                backup_events($ID, "initialization", "INFO, Backup starting Running macro all cyrus, mysql, LDAP, Artica...", __LINE__);
                send_email_events("Backup Task {$ID}:: Backup starting Running macro all ", "Backup is running", "backup");
                if ($users->cyrus_imapd_installed) {
                    backup_events($ID, "initialization", "INFO, cyrus-imapd mailboxes processing");
                    backup_cyrus($ID);
                }
                backup_events($ID, "initialization", "INFO, LDAP Database processing", __LINE__);
                backup_ldap($ID);
                backup_events($ID, "initialization", "INFO, MySQL Database processing", __LINE__);
                backup_mysql($ID, 0);
                backup_events($ID, "initialization", "INFO, Restarting MySQL service...", __LINE__);
                mysql_admin_mysql(0, "Restarting mysql service.", null, __FILE__, __LINE__);
                shell_exec("/etc/init.d/mysql restart");
                backup_events($ID, "initialization", "INFO, Artica settings processing", __LINE__);
                backup_artica($ID);
                if ($users->ZARAFA_INSTALLED) {
                    if ($sock->GET_INFO("ZarafaStoreOutside") == 1) {
                        backup_events($ID, "initialization", "INFO, Zarafa external attachments processing...");
                        backup_ZarafaOutside($ID);
                    }
                }
                backup_events($ID, "initialization", "continue to next process", __LINE__);
                continue;
            }
            if (preg_match("#MYSQLINSTANCE:([0-9]+)#", $WhatToBackup, $re)) {
                $instance_id = $re[1];
                backup_events($ID, "initialization", "INFO, Backup starting backup MySQL instance Number:{$instance_id}", __LINE__);
                if ($instance_id > 0) {
                    if (!isset($BACKUP_INSTANCES_ALREADY_DONE[$instance_id])) {
                        backup_mysql($ID, $instance_id);
                        $BACKUP_INSTANCES_ALREADY_DONE[$instance_id] = true;
                    }
                }
                continue;
            }
            if (preg_match("#FREEWEB:(.+)#", $WhatToBackup, $re)) {
                $sitename = $re[1];
                backup_events($ID, "initialization", "INFO, Backup starting backup Website  {$sitename}", __LINE__);
                if (!isset($BACKUP_WWW_ALREADY_DONE[$sitename])) {
                    backup_freewebs($ID, $sitename);
                    $BACKUP_INSTANCES_ALREADY_DONE[$sitename] = true;
                }
                continue;
            }
            if (preg_match("#WEBGET:(.+)#", $WhatToBackup, $re)) {
                if (!isset($BACKUP_WEBGET_ALREADY_DONE[$re[1]])) {
                    $arr = unserialize(base64_decode($re[1]));
                    if (!is_array($arr)) {
                        backup_events($ID, "initialization", "ERROR, WEBGET `{$re[1]}` is not an array...", __LINE__);
                        continue;
                    }
                    backup_events($ID, "initialization", "INFO, Backup remote Artica FreeWebs Website {$arr["RemoteArticaSite"]} from source {$arr["RemoteArticaServer"]}", __LINE__);
                    backup_webget($ID, $arr);
                }
                continue;
            }
            backup_events($ID, "initialization", "INFO, `{$WhatToBackup}` could not understood", __LINE__);
        }
    }
    $sql = "SELECT * FROM backup_folders WHERE taskid={$ID}";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        if (strpos($q->mysql_error, "gone away")) {
            backup_events($ID, "personal", "ERROR, mysql {$q->mysql_error} Restarting MySQL server (Patch p.20130807)", __LINE__);
            mysql_admin_mysql(0, "Restarting mysql service.", $q->mysql_error, __FILE__, __LINE__);
            shell_exec("/etc/init.d/mysql restart");
            $q = new mysql();
            $results = $q->QUERY_SQL($sql, "artica_backup");
        }
    }
    if (!$q->ok) {
        backup_events($ID, "personal", "ERROR, mysql {$q->mysql_error}", __LINE__);
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $dd1 = time();
        if ($ligne["recursive"] == 1) {
            $recursive = " --recursive";
        } else {
            $recursive = null;
        }
        $path = trim(base64_decode($ligne["path"]));
        if (!is_dir($path)) {
            backup_events($ID, "personal", "ERROR, [{$path}] no such file or directory", __LINE__);
            continue;
        }
        backup_events($ID, "personal", "INFO, Backup starting for {$path}", __LINE__);
        send_email_events("Backup Task {$ID}:: Backup starting {$path}", "Backup is running for path {$path}", "backup");
        backup_mkdir($path);
        $results = backup_copy($path, $path, $ID);
        $calculate = distanceOfTimeInWords($dd1, time());
        backup_events($ID, "personal", "INFO, Backup finish for {$path}\n{$results} {$calculate}", __LINE__);
    }
    writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: Calculate directory size on {$mount_path_final}", __FUNCTION__, __FILE__, __LINE__);
    $du = $unix->find_program("du");
    $dut1 = time();
    $nice = $unix->EXEC_NICE();
    $cmd = "{$nice}{$du} -s {$mount_path_final}";
    exec($cmd, $du_results);
    $calculate = distanceOfTimeInWords($dut1, time());
    $BackupSize = 0;
    if (preg_match("#^([0-9]+)\\s+#", @implode("", $du_results), $re)) {
        $BackupSize = $re[1];
        backup_events($ID, "initialization", "INFO, backup size {$BackupSize} bytes time:{$calculate}", __LINE__);
    }
    if ($GLOBALS["CAN_CLEAN_CONTAINERS"]) {
        backup_events($ID, "initialization", "INFO, cleaning containers....", __LINE__);
        CleanContainers($ID, $mount_path_final);
    } else {
        backup_events($ID, "initialization", "INFO, cannot clean containers, check protocols....", __LINE__);
    }
    $GLOBAL["BACKUP_MEMORY_SQL"]["mount_path_final"] = $mount_path_final;
    $zmd5 = md5("{$GLOBAL["BACKUP_MEMORY_SQL"]["CONTAINER"]}{$GLOBALS["MYSERVERNAME"]}");
    $cnx_params = addslashes(base64_encode(serialize($GLOBAL["BACKUP_MEMORY_SQL"])));
    $sql = "INSERT IGNORE INTO backup_storages (`taskid`,`size`,`cnx_params`,`zmd5`) VALUES('{$ID}','{$BackupSize}','{$cnx_params}','{$zmd5}')";
    $q->QUERY_SQL($sql, "artica_backup");
    $sql = "UPDATE backup_storages SET `size`='{$BackupSize}' WHERE `zmd5`='{$zmd5}'";
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        backup_events($ID, "initialization", "ERROR, {$q->mysql_error}", __LINE__);
    }
    if (!$GLOBALS["NO_UMOUNT"]) {
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]:umount {$mount_path_final}", __FUNCTION__, __FILE__, __LINE__);
        if (preg_match("#^\\/opt\\/artica\\/mounts\\/backup\\/[0-9]+(.+)#", $mount_path_final, $re)) {
            $mount_path_final = str_replace($re[1], "", $mount_path_final);
            writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]:translated to {$mount_path_final}", __FUNCTION__, __FILE__, __LINE__);
        }
        backup_events($ID, "initialization", "INFO, umount {$mount_path_final}", __LINE__);
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]:umount {$mount_path_final}", __FUNCTION__, __FILE__, __LINE__);
        exec("umount -l {$mount_path_final} 2>&1", $resultsUmount);
        if (count($resultsUmount) > 0) {
            writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]:umount : ----- \n" . @implode("\n", $resultsUmount) . "\n", __FUNCTION__, __FILE__, __LINE__);
        }
    }
    $date_end = time();
    $calculate = distanceOfTimeInWords($date_start, $date_end);
    backup_events($ID, "TIME", "INFO, Time: {$calculate} ({$mount_path_final})", __LINE__);
    backup_events($ID, "initialization", "INFO, Backup task terminated", __LINE__);
    send_email_events("Backup Task {$ID}:: Backup stopping", "Backup is stopped", "backup");
    shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.cleanfiles.php");
}
function alias_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql();
    $t = $_GET["t"];
    $search = '%';
    $table = "freewebs_openbasedir";
    $database = "artica_backup";
    $page = 1;
    $FORCE_FILTER = " servername='{$_GET["servername"]}'";
    if (!$q->TABLE_EXISTS("freewebs_openbasedir", "artica_backup")) {
        json_error_show("freewebs_openbasedir no such table");
    }
    if ($q->COUNT_ROWS("freewebs_openbasedir", 'artica_backup') == 0) {
        json_error_show("No data");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . $_POST["query"] . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    $sock = new sockets();
    while ($ligne = mysql_fetch_assoc($results)) {
        $delete = imgsimple("delete-24.png", "{delete}", "FreeWebDelAlias{$t}('{$ligne["ID"]}')");
        $data['rows'][] = array('id' => "{$ligne["ID"]}", 'cell' => array("<span style='font-size:16px;'>{$ligne["directory"]}</a></span>", $delete));
    }
    echo json_encode($data);
}
Exemple #30
0
function items()
{
    $myPage = CurrentPageName();
    $tpl = new templates();
    $q = new mysql();
    $table = "`zarafa_backup`";
    $database = "artica_backup";
    $FORCE_FILTER = "";
    if (!$q->TABLE_EXISTS($table, $database)) {
        json_error_show("{$table}: No such table", 0, true);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show($q->mysql_error);
        }
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS($table, $database);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show(1, "no data");
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $ligne["filesize"] = FormatBytes($ligne["filesize"] / 1024);
        $ligne["filepath"] = basename($ligne["filepath"]);
        $ligne["ztime"] = $tpl->_ENGINE_parse_body("{$ligne["ztime"]}");
        $time = strtotime($ligne["zDate"]);
        $xdate = $tpl->_ENGINE_parse_body(date("Y {l} {F} d H:i", $time));
        $data['rows'][] = array('id' => $ligne["ID"], 'cell' => array("<span style='font-size:18px;color:{$color}'>{$xdate}</a></span>", "<span style='font-size:18px;color:{$color}'>{$urljs}{$ligne["filepath"]}</a></span>", "<span style='font-size:18px;color:{$color}'>{$urljs}{$ligne["filesize"]}</a></span>", "<span style='font-size:18px;color:{$color}'>{$urljs}{$ligne["ztime"]}</a></span>", "<span style='font-size:18px;color:{$color}'>{$urljs}&nbsp;</a></span>", "<span style='font-size:18px;color:{$color}'>{$urljs}&nbsp;</a></span>"));
    }
    echo json_encode($data);
}