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");
}
Ejemplo n.º 2
0
function databases_list_fill()
{
    $unix = new unix();
    if (system_is_overloaded(basename(__FILE__))) {
        writelogs("Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pidfileTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            writelogs("Already process {$pid} exists", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        $time = $unix->file_time_min($pidfileTime);
        if ($time < 20) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Minimal time = 20Mn (current is {$time}Mn)\n";
            }
            return;
        }
        @unlink($pidfileTime);
        @file_put_contents($pidfileTime, time());
        @file_put_contents($pidfile, getmypid());
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "databases_list_fill() executed\n";
    }
    $prefix = "INSERT IGNORE INTO mysqldbs (databasename,TableCount,dbsize) VALUES ";
    $q = new mysql();
    if (!$q->TABLE_EXISTS('mysqldbs', 'artica_backup')) {
        if ($GLOBALS["VERBOSE"]) {
            echo "check_storage_table()\n";
        }
        $q->check_storage_table(true);
    }
    eventsDB("DATABASE_LIST_SIMPLE()", __LINE__);
    $databases = $q->DATABASE_LIST_SIMPLE();
    eventsDB("DATABASE_LIST_SIMPLE() fone", __LINE__);
    eventsDB("Found " . count($databases) . " databases -> dROP mysqldbtables", __LINE__);
    $q->QUERY_SQL("DROP TABLE mysqldbtables", "artica_backup");
    eventsDB("BuildTables()...", __LINE__);
    if (!class_exists("mysql_builder")) {
        include_once dirname(__FILE__) . "/ressources/class.mysql.builder.inc";
    }
    $t = new mysql_builder();
    $t->check_mysql_dbtables();
    while (list($database, $ligne) = each($databases)) {
        eventsDB("-> databases_list_tables({$database})...", __LINE__);
        $rr = databases_list_tables($database);
        $TableCount = $rr[0];
        $Size = $rr[1];
        eventsDB("Found database `{$database}` {$TableCount} tables ({$Size})", __LINE__);
        $f[] = "('{$database}','{$TableCount}','{$Size}')";
    }
    if (count($f) > 0) {
        eventsDB("Inbjecting " . count($f) . " elements...", __LINE__);
        $q->QUERY_SQL("TRUNCATE TABLE mysqldbs", "artica_backup");
        $q->QUERY_SQL($prefix . @implode(",", $f), "artica_backup");
    }
    eventsDB("multi_databases_parse()", __LINE__);
    multi_databases_parse();
    eventsDB("multi_databases_parse() done...", __LINE__);
    @file_put_contents($pidfileTime, time());
}
Ejemplo n.º 3
0
function CheckTables()
{
    $q = new mysql();
    if (!$q->TABLE_EXISTS('adgroups', 'artica_backup')) {
        $sql = "CREATE TABLE `artica_backup`.`adgroups` (\n\t\t\t`gpid` BIGINT UNSIGNED NOT NULL,\n\t\t\t`groupname` VARCHAR( 128 ) NOT NULL ,\n\t\t\t PRIMARY KEY (`gpid`),\n\t\t\t KEY `groupname` (`groupname`)\n\t\t\t )";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            writelogs("Fatal: {$q->mysql_error}", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        }
    }
    if (!$q->TABLE_EXISTS('adusers', 'artica_backup')) {
        $sql = "CREATE TABLE IF NOT EXISTS `adusers` (\n\t\t\t\t  `gpid` BIGINT UNSIGNED NOT NULL,\n\t\t\t\t  `uid` varchar(128) NOT NULL,\n\t\t\t\t  KEY `gpid` (`gpid`),\n\t\t\t\t  KEY `uid` (`uid`)\n\t\t\t\t)";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            writelogs("Fatal: {$q->mysql_error}", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        }
    }
    if (!$q->TABLE_EXISTS('adgroups', 'artica_backup')) {
        return false;
    }
    if (!$q->TABLE_EXISTS('adusers', 'artica_backup')) {
        return false;
    }
    $q->check_storage_table(true);
    return true;
}
Ejemplo n.º 4
0
    transfert();
    die;
}
$_GET["DOMAINS"] = null;
$_GET["FALSE_EMAILS"] = null;
$_GET["EMAILS"] = null;
include_once dirname(__FILE__) . '/framework/frame.class.inc';
if (posix_getuid() != 0) {
    die("Cannot be used in web server mode\n\n");
}
if (!Build_pid_func(__FILE__, "MAIN")) {
    events(basename(__FILE__) . " Already executed.. aborting the process");
    die;
}
$q = new mysql();
$q->check_storage_table(true);
$sock = new sockets();
if ($sock->GET_INFO("KeepArticaMysqlError") != 1) {
    DeleteMysqlError();
}
$quarantine_dir = "/tmp/savemail";
@mkdir("{$quarantine_dir}");
@chmod("{$quarantine_dir}", 0777);
$files = DirList($quarantine_dir);
$count = 0;
$pid = getmypid();
$max = count($files);
$date1 = date('H:i:s');
if (count($files) > 0) {
    events("Processing " . count($files) . " files in {$quarantine_dir}");
}
Ejemplo n.º 5
0
    transfert();
    die;
}
$_GET["DOMAINS"] = null;
$_GET["FALSE_EMAILS"] = null;
$_GET["EMAILS"] = null;
include_once dirname(__FILE__) . '/framework/frame.class.inc';
if (posix_getuid() != 0) {
    die("Cannot be used in web server mode\n\n");
}
if (!Build_pid_func(__FILE__, "MAIN")) {
    events(basename(__FILE__) . " Already executed.. aborting the process");
    die;
}
$q = new mysql();
$q->check_storage_table();
$sock = new sockets();
if ($sock->GET_INFO("KeepArticaMysqlError") != 1) {
    DeleteMysqlError();
}
$quarantine_dir = "/tmp/savemail";
@mkdir("{$quarantine_dir}");
@chmod("{$quarantine_dir}", 0777);
$files = DirList($quarantine_dir);
$count = 0;
$pid = getmypid();
$max = count($files);
$date1 = date('H:i:s');
events("Processing " . count($files) . " files in {$quarantine_dir}");
while (list($num, $file) = each($files)) {
    events("################################################################### {$count}/{$max})");
Ejemplo n.º 6
0
function table_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql();
    $fontsize = "22px";
    $cs = 0;
    $page = 1;
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $_POST["query"] = trim($_POST["query"]);
    $FORCE = 1;
    $search = '%';
    $table = "philesight";
    if ($_GET["dev"] != null) {
        $FORCE = " ((partition='{$_GET["dev"]}') OR (hd='{$_GET["dev"]}'))";
    }
    $page = 1;
    if (!$q->TABLE_EXISTS($table, "artica_backup")) {
        $q->check_storage_table();
    }
    if (!$q->TABLE_EXISTS($table, "artica_backup")) {
        json_error_show("{$table} no such table", 1);
    }
    $total = 0;
    if ($q->COUNT_ROWS($table, "artica_backup") == 0) {
        json_error_show("no data", 1);
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE}  {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            if (preg_match("#marked as crashed#", $q->mysql_error)) {
                $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
            }
        }
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS($table, "artica_backup");
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$searchstring} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        if (preg_match("#marked as crashed#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
        }
    }
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}", 0);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $uuid = urlencode($_GET["uuid"]);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $color = "black";
        $icon = "&nbsp;";
        $directory = $ligne["directory"];
        $md5 = md5($directory);
        $partition = $ligne["partition"];
        $hd = $ligne["hd"];
        $maxtime = $ligne["maxtime"];
        $lastscan = $ligne["lastscan"];
        $USED = $ligne["USED"];
        $FREEMB = $ligne["FREEMB"];
        if ($lastscan > 0) {
            $lastscan = date("Y-m-d H:i:s", $lastscan);
        }
        if ($ligne["enabled"] == 0) {
            $color = "#8a8a8a";
        }
        $FREEMB = FormatBytes($FREEMB * 1024);
        $directoryenc = urlencode($directory);
        $jslink = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('{$MyPage}?directory-js=yes&directory={$directoryenc}');\" \n\t\tstyle='font-size:{$fontsize};text-decoration:underline;color:{$color}'>";
        $distance = $tpl->_ENGINE_parse_body(distanceOfTimeInWords($ligne["lastscan"], time(), true));
        if (is_file("/usr/share/artica-postfix/img/philesight/{$md5}.png")) {
            $icon = imgsimple("graph-32.png", null, "Loadjs('{$MyPage}?graph-js={$directoryenc}')");
        }
        $delete = imgsimple("delete-32.png", null, "Loadjs('{$MyPage}?delete-js={$directoryenc}')");
        $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array("<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$lastscan}</a></span><br><i>{$distance}</i>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$directory}</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$partition}</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$hd}</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$USED}%</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$FREEMB}</a></span>", "<center style='font-size:{$fontsize};color:{$color}'>{$icon}</a></center>", "<center style='font-size:{$fontsize};color:{$color}'>{$delete}</a></center>"));
    }
    echo json_encode($data);
}
Ejemplo n.º 7
0
function tabs()
{
    $tpl = new templates();
    $page = CurrentPageName();
    $q = new mysql();
    $database = $_GET["database"];
    if (!is_numeric($_GET["instance-id"])) {
        $_GET["instance-id"] = 0;
    }
    $instance_id = $_GET["instance-id"];
    $array["params"] = "{backup_parameters}";
    if (!$q->TABLE_EXISTS("mysqldb_backup_containers", "artica_backup")) {
        $q->check_storage_table(true);
    }
    if (!$q->TABLE_EXISTS("mysqldb_backup_containers", "artica_backup")) {
        echo "mysqldb_backup_containers no such table....\n";
    }
    $md5 = md5("{$database}{$instance_id}");
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(*) as tcount FROM mysqldb_backup_containers WHERE `md5`='{$md5}'", "artica_backup"));
    if (!$q->ok) {
        echo $q->mysql_error . "<hr>";
    }
    if ($ligne["tcount"] > 0) {
        $array["containers"] = "{$ligne["tcount"]} {containers}";
    }
    while (list($num, $ligne) = each($array)) {
        $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"{$page}?{$num}=yes&instance-id={$_GET["instance-id"]}&database={$database}\"><span style='font-size:14px'>{$ligne}</span></a></li>\n");
    }
    echo "\n\t<div id=main_config_mysql_backup style='width:100%;font-size:14px'>\n\t\t<ul>" . implode("\n", $html) . "</ul>\n\t</div>\n\t\t<script>\n\t\t\t\t\$(document).ready(function(){\n\t\t\t\t\t\$('#main_config_mysql_backup').tabs();\n\t\t\t\t});\n\t\t</script>";
}
Ejemplo n.º 8
0
function nmap_scan_results()
{
    if (!is_file("/etc/artica-postfix/nmap.map")) {
        return;
    }
    $f = explode("\n", @file_get_contents("/etc/artica-postfix/nmap.map"));
    $ipaddr = null;
    $computer = array();
    while (list($index, $ligne) = each($f)) {
        $ligne = trim($ligne);
        if ($ligne == null) {
            continue;
        }
        if ($ligne == "PORT  STATE  SERVICE") {
            continue;
        }
        if (strpos("    {$ligne}", "Network Distance:") > 0) {
            continue;
        }
        if (strpos("    {$ligne}", "tcp closed tcpmux") > 0) {
            continue;
        }
        if (strpos("    {$ligne}", "Too many fingerprints match") > 0) {
            continue;
        }
        if (strpos("    {$ligne}", "OS detection performed. Please report") > 0) {
            continue;
        }
        if (strpos("    {$ligne}", "OSScan results may be unreliable") > 0) {
            continue;
        }
        if (strpos("    {$ligne}", "/tcp filtered") > 0) {
            continue;
        }
        if (preg_match("#Nmap scan report for\\s+(.+?)\\s+\\(([0-9\\.]+)#", $ligne, $re)) {
            $ipaddr = $re[2];
            $computer[$ipaddr]["IPADDR"] = $re[2];
            $computer[$ipaddr]["HOSTNAME"] = trim($re[1]);
            if ($GLOBALS["VERBOSE"]) {
                echo "Found IP:{$ipaddr} hostname=`{$re[1]}` in `{$ligne}`\n";
            }
            $LOGS[] = "Found {$ipaddr} hostname= {$re[1]}";
            continue;
        }
        if (preg_match("#Interesting ports on (.*?)\\s+\\(([0-9\\.]+)\\)#", $ligne, $re)) {
            $ipaddr = $re[2];
            $computer[$ipaddr]["IPADDR"] = $re[2];
            $computer[$ipaddr]["HOSTNAME"] = trim($re[1]);
            if ($GLOBALS["VERBOSE"]) {
                echo "Found IP:{$ipaddr} hostname=`{$re[1]}` in `{$ligne}`\n";
            }
            $LOGS[] = "Found {$ipaddr} hostname= {$re[1]}";
            continue;
        }
        if (preg_match("#Interesting ports on ([0-9\\.]+):#", $ligne, $re)) {
            $ipaddr = $re[1];
            $computer[$ipaddr]["IPADDR"] = $re[1];
            if ($GLOBALS["VERBOSE"]) {
                echo "Found IP:{$ipaddr} only in `{$ligne}`\n";
            }
            $LOGS[] = "Found {$ipaddr} only";
            continue;
        }
        if (preg_match("#Nmap scan report for ([0-9\\.]+)\$#", trim($ligne), $re)) {
            $ipaddr = $re[1];
            $computer[$ipaddr]["IPADDR"] = $re[1];
            if ($GLOBALS["VERBOSE"]) {
                echo "[{$ipaddr}]: Found IP address `{$ipaddr}` without computername in `{$ligne}`\n";
            }
            $LOGS[] = "Found {$ipaddr} without computername ";
            continue;
        }
        if (preg_match("#^MAC Address:\\s+([0-9A-Z:]+)\$#", trim($ligne), $re)) {
            if (trim($ipaddr) == null) {
                continue;
            }
            if (isset($MACSSCAN[trim($re[1])])) {
                continue;
            }
            $computer[$ipaddr]["MAC"] = trim($re[1]);
            $LOGS[] = "Found {$ipaddr} with mac {$re[1]} ";
            if ($GLOBALS["VERBOSE"]) {
                echo "[{$ipaddr}]: Found mac {$re[1]} in `{$ligne}`\n";
            }
            $MACSSCAN[trim($re[1])] = true;
            continue;
        }
        if (preg_match("#^MAC Address:(.+).+?\\((.+?)\\)#", $ligne, $re)) {
            if (trim($ipaddr) == null) {
                continue;
            }
            if (isset($MACSSCAN[trim($re[1])])) {
                continue;
            }
            $MACSSCAN[trim($re[1])] = true;
            $computer[$ipaddr]["MAC"] = trim($re[1]);
            $computer[$ipaddr]["MACHINE_TYPE"] = trim($re[2]);
            if ($GLOBALS["VERBOSE"]) {
                echo "[{$ipaddr}]: Found mac {$re[1]} and machine type {$re[2]} in `{$ligne}`\n";
            }
            $LOGS[] = "Found {$ipaddr} with mac {$re[1]} and machine type {$re[2]}";
            continue;
        }
        if (preg_match("#^Running:(.+)#", $ligne, $re)) {
            if (trim($ipaddr) == null) {
                continue;
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "Found running in `{$line}`\n";
            }
            $computer[$ipaddr]["RUNNING"] = trim($re[1]);
            continue;
        }
        if (preg_match("#^OS details:(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "[{$ipaddr}]: Found OS {$re[1]} in `{$ligne}`\n";
            }
            $LOGS[] = "Found {$ipaddr} with OS {$re[1]}";
            $computer[$ipaddr]["OS"] = trim($re[1]);
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "[{$ipaddr}]: Not understood in `{$ligne}`\n";
        }
    }
    nmap_logs(count($f) . " analyzed lines", @implode("\n", $LOGS));
    $c = 0;
    $prefix_sql = "INSERT IGNORE INTO computers_lastscan (`MAC`, `zDate`,`ipaddr`,`hostname`,`Info`) VALUES ";
    while (list($ipaddr, $array) = each($computer)) {
        if (!isset($array["MAC"])) {
            continue;
        }
        $mac = trim($array["MAC"]);
        if (isset($already[$mac])) {
            continue;
        }
        if ($mac == null) {
            continue;
        }
        $c++;
        $already[$mac] = true;
        $ldap_ipaddr = null;
        $ComputerRealName = null;
        $uid = null;
        $RAISON = array();
        if (!isset($array["HOSTNAME"])) {
            $array["HOSTNAME"] = null;
        }
        if (!isset($array["OS"])) {
            $array["OS"] = null;
        }
        if (!isset($array["RUNNING"])) {
            $array["RUNNING"] = null;
        }
        if (!isset($array["MACHINE_TYPE"])) {
            $array["MACHINE_TYPE"] = null;
        }
        $date = date('Y-m-d H:i:s');
        $infos = addslashes($array["OS"] . " Type:{$array["MACHINE_TYPE"]} ");
        $SQLAD[] = "('{$mac}','{$date}','{$ipaddr}','{$array["HOSTNAME"]}','{$infos}')";
        $cmp = new computers(null);
        $uid = $cmp->ComputerIDFromMAC($mac);
        if ($uid != null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$mac} = {$uid}\n";
            }
            $cmp = new computers($uid);
            $ldap_ipaddr = $cmp->ComputerIP;
            $ComputerRealName = $cmp->ComputerRealName;
            if ($GLOBALS["VERBOSE"]) {
                echo "{$mac} = {$uid}\nLDAP:{$ldap_ipaddr}<>NMAP:{$ipaddr}\nLDAP CMP:{$ComputerRealName}<>NMAP:{$array["HOSTNAME"]}";
            }
            if ($array["HOSTNAME"] != null) {
                $EXPECTED_UID = strtoupper($array["HOSTNAME"]) . "\$";
                if ($EXPECTED_UID != $uid) {
                    $RAISON[] = "UID: {$uid} is different from {$EXPECTED_UID}";
                    nmap_logs("EDIT UID: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid);
                    $cmp->update_uid($EXPECTED_UID);
                }
            }
            if ($ldap_ipaddr != $ipaddr) {
                writelogs("Change {$ldap_ipaddr} -> to {$ipaddr} for  {$cmp->uid}", __FUNCTION__, __FILE__, __LINE__);
                $RAISON[] = "LDAP IP ADDR: {$ldap_ipaddr} is different from {$ipaddr}";
                $RAISON[] = "DN: {$cmp->dn}";
                $RAISON[] = "UID: {$cmp->uid}";
                $RAISON[] = "MAC: {$cmp->ComputerMacAddress}";
                if (!$cmp->update_ipaddr($ipaddr)) {
                    $RAISON[] = "ERROR:{$cmp->ldap_last_error}";
                }
                nmap_logs("EDIT IP: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid);
            }
            if ($array["OS"] != null) {
                if (strtolower($cmp->ComputerOS == "Unknown")) {
                    $cmp->ComputerOS = null;
                }
                if ($cmp->ComputerOS == null) {
                    $RAISON[] = "LDAP OS: {$cmp->ComputerOS} is different from {$array["OS"]}";
                    nmap_logs("EDIT OS: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid);
                    $cmp->update_OS($array["OS"]);
                }
            }
        } else {
            if ($array["HOSTNAME"] != null) {
                $uid = "{$array["HOSTNAME"]}\$";
            } else {
                continue;
            }
            nmap_logs("ADD NEW: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), "{$uid}");
            $cmp = new computers();
            $cmp->ComputerIP = $ipaddr;
            $cmp->ComputerMacAddress = $mac;
            $cmp->uid = "{$uid}";
            $cmp->ComputerOS = $array["OS"];
            $cmp->ComputerRunning = $array["RUNNING"];
            $cmp->ComputerMachineType = $array["MACHINE_TYPE"];
            $cmp->Add();
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "*** " . count($SQLAD) . " MYsql queries...***\n";
    }
    system_admin_events("{$c} hosts analyzed in networks", __FUNCTION__, __FILE__, __LINE__, "nmap");
    nmap_logs("{$c} hosts analyzed in networks", @file_get_contents("/etc/artica-postfix/nmap.map"), null);
    if (count($SQLAD) > 0) {
        $q = new mysql();
        $q->QUERY_SQL("DROP TABLE computers_lastscan", "artica_backup");
        $q->check_storage_table(true);
        $final = $prefix_sql . @implode(",", $SQLAD);
        if ($GLOBALS["VERBOSE"]) {
            echo "*** {$final} ***\n";
        }
        $q->QUERY_SQL($prefix_sql . @implode(",", $SQLAD), "artica_backup");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    }
    @unlink("/etc/artica-postfix/nmap.map");
    //print_r($computer);
}
Ejemplo n.º 9
-1
function Scan_mysql_dirs()
{
    $GLOBALS["INDEXED"] = 0;
    $GLOBALS["SKIPPED"] = 0;
    $GLOBALS["DIRS"] = array();
    $unix = new unix();
    $GLOBALS["omindex"] = $unix->find_program("omindex");
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        system_admin_events("Already instance executed pid:{$olpid}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $q = new mysql();
    $q->check_storage_table(true);
    $localdatabase = "/usr/share/artica-postfix/LocalDatabases";
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM xapian_folders";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $t1 = time();
    if (!is_file($GLOBALS["omindex"])) {
        system_admin_events("omindex no such binary, aborting", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $autofs = new autofs();
    $autofs->automounts_Browse();
    $count = 0;
    while ($ligne = mysql_fetch_assoc($results)) {
        $directory = $ligne["directory"];
        $database = "{$localdatabase}/samba." . md5($directory) . ".db";
        $depth = $ligne["depth"];
        $maxsize = $ligne["maxsize"];
        $samplsize = $ligne["sample-size"];
        $lang = $ligne["lang"];
        $WebCopyID = $ligne["WebCopyID"];
        $autmountdn = $ligne["autmountdn"];
        if ($lang == null) {
            $lang = "english";
        }
        $indexed = $ligne["indexed"];
        if (!is_numeric($samplsize)) {
            $samplsize = 512;
        }
        if (!is_numeric($maxsize)) {
            $maxsize = 60;
        }
        if (!is_numeric($depth)) {
            $depth = 0;
        }
        $BaseUrl = $directory;
        if ($WebCopyID > 0) {
            $directory = WebCopyIDDirectory($WebCopyID);
            $BaseUrl = WebCopyIDAddresses($WebCopyID) . "/";
        }
        if ($autmountdn != null) {
            if (!isset($autofs->hash_by_dn[$autmountdn])) {
                system_admin_events("Fatal.. {$autmountdn} no such connection", __FUNCTION__, __FILE__, __LINE__, "xapian");
                continue;
            }
            $autmountdn_array = $autofs->hash_by_dn[$autmountdn];
            $directory = "/automounts/{$autmountdn_array["FOLDER"]}";
            $autmountdn_infos = $autmountdn_array["INFOS"];
            if (!isset($autmountdn_infos["BROWSER_URI"])) {
                system_admin_events("Fatal.. {$autmountdn} external protocol error", __FUNCTION__, __FILE__, __LINE__, "xapian");
                continue;
            }
            $BaseUrl = $autmountdn_infos["BROWSER_URI"];
        }
        if (!is_dir($database)) {
            @mkdir($database, 0755, true);
        }
        if (!is_dir($directory)) {
            system_admin_events("{$directory}, no such directory", __FUNCTION__, __FILE__, __LINE__, "xapian");
            continue;
        }
        $t = time();
        $cmd = "{$nice}{$GLOBALS["omindex"]} -l {$depth} -s {$lang} -E {$samplsize} -m {$maxsize}M --follow -D \"{$database}\" -U \"{$BaseUrl}\" \"{$directory}\" 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        $GLOBALS["DIRS"]["{$directory}"] = true;
        $results_scan = array();
        exec($cmd, $results_scan);
        $dirRes = ParseLogs($results_scan);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $DatabaseSize = $unix->DIRSIZE_BYTES($database);
        $count++;
        $indexed = $indexed + $dirRes[0];
        system_admin_events("scanned {$directory} took {$took} indexed:{$indexed} skipped:{$dirRes[1]}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        $q->QUERY_SQL("UPDATE xapian_folders SET ScannedTime=NOW(),indexed={$indexed},DatabasePath='{$database}',DatabaseSize='{$DatabaseSize}'\n\t\n\t\tWHERE ID={$ligne["ID"]}", "artica_backup");
        if (!$q->ok) {
            system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        }
    }
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    system_admin_events("scanned {$count} directorie(s) took {$took}", __FUNCTION__, __FILE__, __LINE__, "xapian");
}