function monitorProcessWatch($parentProcessId)
{
    $m = new _MeasurePerformance();
    $mysql = new _MySQL();
    $mysql->connect(Setup::$connectionArray);
    $parallelProcessesMonitors = Setup::$settings['max_monitor_processes'];
    $monitorProcesses = array();
    $processCountMonitors = 0;
    $ipDomain = false;
    while (true) {
        // are we still running?
        if (!Utilities::is_process_running($parentProcessId)) {
            _Logging::appLog("Parent Stopped - monitorStartWatch exited");
            exit;
        }
        $processCountMonitors = count($monitorProcesses);
        if ($processCountMonitors < $parallelProcessesMonitors) {
            $ipDomain = Utilities::getNextMonitor($mysql);
            if ($ipDomain !== false) {
                // start it
                $cmd = 'php ' . dirname(__FILE__) . '/monitorJob.php -h ' . escapeshellarg($ipDomain);
                $pid = Utilities::run_in_background($cmd);
                $m->work(1);
                $monitorProcesses[] = $pid;
            }
        }
        // was there any work?
        if ($ipDomain === false) {
            sleep(10);
            //10 seconds
        } else {
            usleep(10000);
            //ideal time 10ms
        }
        // delete finished processes
        for ($x = 0; $x < $processCountMonitors; $x++) {
            if (isset($monitorProcesses[$x])) {
                if (!Utilities::is_process_running($monitorProcesses[$x])) {
                    unset($monitorProcesses[$x]);
                }
            }
        }
        // fix array index
        $monitorProcesses = array_values($monitorProcesses);
        $processCountMonitors = count($monitorProcesses);
        //randomly reset counter every now and then
        if (mt_rand(1, 2000) == 1) {
            $m->endWork();
            _Logging::appLog("App Avg Hosts/sec: {$m->avgPerformance}\tMonitor Threads: {$processCountMonitors}/{$parallelProcessesMonitors}");
            $m = new _MeasurePerformance();
        }
    }
}
}
$titlePreFix = "account";
$message = array();
$username = array_key_exists('username', $_POST) ? substr(trim($_POST['username']), 0, 100) : '';
$noticeEmailAddresses = array_key_exists('noticeEmailAddresses', $_POST) ? substr($_POST['noticeEmailAddresses'], 0, 8000) : '';
$textMessageEmails = array_key_exists('textMessageEmails', $_POST) ? substr($_POST['textMessageEmails'], 0, 8000) : '';
$passwd = array_key_exists('passwd', $_POST) ? substr($_POST['passwd'], 0, 32) : '';
$passwdOld = array_key_exists('passwdOld', $_POST) ? substr($_POST['passwdOld'], 0, 32) : '';
$apiKey = array_key_exists('apiKey', $_POST) ? substr($_POST['apiKey'], 0, 32) : '';
$disableEmailNotices = array_key_exists('disableEmailNotices', $_POST) ? (int) $_POST['disableEmailNotices'] : 0;
$beenChecked = array_key_exists('beenChecked', $_POST) ? (int) $_POST['beenChecked'] : 0;
$twitterHandle = array_key_exists('twitterHandle', $_POST) ? substr(trim($_POST['twitterHandle']), 0, 15) : '';
$twitterHandle = str_replace('@', '', $twitterHandle);
$apiCallbackURL = array_key_exists('apiCallbackURL', $_POST) ? substr(trim($_POST['apiCallbackURL']), 0, 2000) : '';
$testUrl = array_key_exists('testUrl', $_GET) ? $_GET['testUrl'] : '';
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
// audit check frequency
$checkFrequency = array_key_exists('checkFrequency', $_POST) ? $_POST['checkFrequency'] : '';
if ($testUrl != '') {
    if (Utilities::testAPICallback($testUrl)) {
        echo 'true';
    } else {
        echo 'false';
    }
    exit;
}
if (isset($_POST["submit"])) {
    if ($passwd == '') {
        $message[] = 'You must select a password.';
    }
<?php

class_exists('Setup', false) or (include 'classes/Setup.class.php');
class_exists('Utilities', false) or (include 'classes/Utilities.class.php');
class_exists('_MySQL', false) or (include 'classes/_MySQL.class.php');
if (Utilities::isLoggedIn() === false) {
    header('Location: login.php?location=' . urlencode('hosts.php'));
    exit;
}
$host = array_key_exists('host', $_POST) ? $_POST['host'] : '';
$toggle = array_key_exists('toggle', $_POST) ? (int) $_POST['toggle'] : 0;
$titlePreFix = "Block Lists";
$user = Utilities::getAccount();
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
if ($host != '') {
    if ($toggle == 0) {
        $mysql->runQuery("\n\t\t\tupdate blockLists\n\t\t\tset isActive = '0'\n\t\t\twhere md5(host) = '" . $mysql->escape($host) . "'");
    } else {
        $mysql->runQuery("\n\t\t\tupdate blockLists\n\t\t\tset isActive = '1'\n\t\t\twhere md5(host) = '" . $mysql->escape($host) . "'");
    }
    exit;
}
$sql = "\nselect *\nfrom blockLists\norder by isActive desc, blocksToday desc\n";
$rs = $mysql->runQuery($sql);
include 'header.inc.php';
include 'accountSubnav.inc.php';
?>

<script src="js/jquery.tablesorter.min.js"></script>
class_exists('Utilities', false) or (include 'classes/Utilities.class.php');
class_exists('Twitter', false) or (include 'classes/Twitter.class.php');
class_exists('_MySQL', false) or (include 'classes/_MySQL.class.php');
class_exists('PHPMailer', false) or (include 'classes/class.phpmailer.php');
if (Utilities::isLoggedIn() === false) {
    header('Location: login.php');
    exit;
}
$titlePreFix = "Edit Monitor Group";
$params = array_merge($_GET, $_POST);
$id = array_key_exists('id', $params) ? (int) $params['id'] : 0;
$groupName = array_key_exists('groupName', $params) ? substr(trim($params['groupName']), 0, 100) : '';
$domains = array_key_exists('domains', $params) ? trim(strtolower($params['domains'])) : '';
$ips = array_key_exists('ips', $params) ? trim($params['ips']) : '';
$deleteGroup = array_key_exists('deleteGroup', $params) ? trim($params['deleteGroup']) : '';
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
if ($deleteGroup != '') {
    $mysql->runQuery("delete from monitorGroup where id = {$id}");
    $mysql->runQuery("delete from monitors where monitorGroupId = {$id}");
    echo "<script>window.location='monitorGroup.php';</script>";
    exit;
}
if (isset($_POST["submit"])) {
    //TODO: make sure blacklists are domains with an ip address on them
    if ($id !== 0) {
        //update
        $mysql->runQuery("\n\t\t\tupdate monitorGroup set groupName = '" . $mysql->escape($groupName) . "',\n\t\t\t\tips = '" . $mysql->escape($ips) . "',\n\t\t\t\tdomains = '" . $mysql->escape($domains) . "'\n\t\t\twhere id = {$id}\n\t\t\t");
    } else {
        $mysql->runQuery("\n\t\t\tinsert into monitorGroup set groupName = '" . $mysql->escape($groupName) . "',\n\t\t\t\tips = '" . $mysql->escape($ips) . "',\n\t\t\t\tdomains = '" . $mysql->escape($domains) . "'\n\t\t\t");
        $id = $mysql->identity;
 public static function validateLogin($userName, $passwd, $api = false, $apiKey = '')
 {
     $mysql = new _MySQL();
     $mysql->connect(Setup::$connectionArray);
     $sql = "\n\t\tselect username\n\t\tfrom users\n\t\twhere ";
     if (trim($apiKey) != '') {
         $sql .= " apiKey = '" . $mysql->escape($apiKey) . "'";
     } else {
         $sql .= " passwd = '" . $mysql->escape(md5($passwd)) . "' \n\t\t\tand username = '******'";
     }
     $rs = $mysql->runQuery($sql);
     $id = 0;
     while ($row = mysqli_fetch_array($rs, MYSQL_ASSOC)) {
         $id = 1;
     }
     $mysql->close();
     return $id;
 }
Exemple #6
0
     Utilities::updateIPs($data);
     $result['status'] = 'success';
     break;
 case 'checkHostStatus':
     $result['status'] = 'success';
     Utilities::setBlockLists();
     $result['result'] = Utilities::checkBlacklists($data);
     break;
 case 'blacklistStatus':
     $localCache = new _FileCache('blacklistmonitor-api', 90);
     $cacheKey = md5("{$username}|{$passwd}|{$apiKey}|{$type}|{$data}");
     $cacheData = $localCache->get($cacheKey);
     if ($cacheData !== false) {
         output($cacheData);
     }
     $mysql = new _MySQL();
     $mysql->connect(Setup::$connectionArray);
     $searchSQL = '';
     switch ($data) {
         case 'changed':
             $searchSQL .= " and lastStatusChanged = 1 ";
             break;
         case 'blocked':
             $searchSQL .= " and isBlocked = 1 ";
             break;
         case 'clean':
             $searchSQL .= " and isBlocked = 0 ";
             break;
         case 'all':
         default:
     }
//prevent non cli access
if (php_sapi_name() !== 'cli') {
    exit;
}
$dir = dirname(dirname(__FILE__));
class_exists('Setup', false) or (include $dir . '/classes/Setup.class.php');
class_exists('Utilities', false) or (include $dir . '/classes/Utilities.class.php');
class_exists('_MySQL', false) or (include $dir . '/classes/_MySQL.class.php');
class_exists('_Logging', false) or (include $dir . '/classes/_Logging.class.php');
$options = getopt("h:");
$options['h'] = isset($options['h']) ? trim($options['h']) : '';
if ($options['h'] == '') {
    _Logging::appLog("monitorJob called without params");
    exit;
}
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
$rs = $mysql->runQuery("\n\tselect *\n\tfrom monitors\n\twhere ipDomain = '" . $mysql->escape($options['h']) . "'");
while ($row = mysqli_fetch_array($rs, MYSQL_ASSOC)) {
    $monitor = $row;
}
// get blacklists
Utilities::setBlockLists();
if (empty(Utilities::$domainBlacklists) === true && empty(Utilities::$ipBlacklists) === true) {
    _Logging::appLog("no blacklists configured");
    exit;
}
//update monitor
$result = serialize(Utilities::checkBlacklists($monitor['ipDomain']));
$isBlocked = Utilities::$isBlocked;
$rdns = Utilities::lookupHostDNS($monitor['ipDomain']);
class_exists('Setup', false) or (include $dir . '/classes/Setup.class.php');
class_exists('Utilities', false) or (include $dir . '/classes/Utilities.class.php');
class_exists('Twitter', false) or (include $dir . '/classes/Twitter.class.php');
class_exists('_MySQL', false) or (include $dir . '/classes/_MySQL.class.php');
class_exists('_Logging', false) or (include $dir . '/classes/_Logging.class.php');
class_exists('_MeasurePerformance', false) or (include $dir . '/classes/_MeasurePerformance.class.php');
class_exists('PHPMailer', false) or (include $dir . '/classes/class.phpmailer.php');
class_exists('SMTP', false) or (include $dir . '/classes/class.smtp.php');
$options = getopt("i:");
$parentProcessId = isset($options['i']) ? (int) $options['i'] : 0;
if ($parentProcessId == 0) {
    _Logging::appLog("userJob called without all params");
    exit;
}
$m = new _MeasurePerformance();
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
// get the user data
$user = Utilities::getAccount();
_Logging::appLog("user job started");
// get the accounts blacklists
Utilities::setBlockLists();
if (empty(Utilities::$domainBlacklists) === true && empty(Utilities::$ipBlacklists) === true) {
    _Logging::appLog("no blacklists configured");
    // mark this one as ran
    $mysql->runQuery("update users set beenChecked = 1, lastChecked = '" . date('Y-m-d H:i:s') . "'");
    exit;
}
//anything to monitor?
$monitorCount = Utilities::getHostCount($mysql);
if ($monitorCount == 0) {
class_exists('Setup', false) or (include 'classes/Setup.class.php');
class_exists('Utilities', false) or (include 'classes/Utilities.class.php');
class_exists('_MySQL', false) or (include 'classes/_MySQL.class.php');
$searchS = array_key_exists('searchS', $_GET) ? trim($_GET['searchS']) : '';
$oc = array_key_exists('oc', $_GET) ? (int) $_GET['oc'] : 4;
$hostType = array_key_exists('ht', $_GET) ? $_GET['ht'] : 'all';
$monitorGroupId = array_key_exists('monitorGroupId', $_GET) ? (int) $_GET['monitorGroupId'] : 0;
$limit = array_key_exists('l', $_GET) ? (int) $_GET['l'] : 100;
if (Utilities::isLoggedIn() === false) {
    header('Location: login.php?location=' . urlencode('hosts.php'));
    exit;
}
$titlePreFix = "Hosts";
$user = Utilities::getAccount();
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
$searchSQL = "";
$hostTypeSQL = "";
$orderSQL = " order by ";
$limitSQL = $limit > 0 ? " limit {$limit} " : '';
switch ($oc) {
    case 1:
        $searchSQL .= " and lastStatusChanged = 1 ";
        $orderSQL .= " lastStatusChangeTime desc ";
        break;
    case 2:
        $searchSQL .= " and isBlocked = 1 ";
        $orderSQL .= " lastStatusChangeTime desc ";
        break;
    case 3:
<?php

class_exists('Setup', false) or (include 'classes/Setup.class.php');
class_exists('Utilities', false) or (include 'classes/Utilities.class.php');
class_exists('_MySQL', false) or (include 'classes/_MySQL.class.php');
$host = array_key_exists('host', $_GET) ? trim($_GET['host']) : '';
if (Utilities::isLoggedIn() === false) {
    header('Location: login.php?location=' . urlencode('hosts.php'));
    exit;
}
$titlePreFix = "history | {$host}";
$user = Utilities::getAccount();
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
$daysOfHistory = Setup::$settings['history_keep_days'];
$cutoffDate = date('Y-m-d', strtotime("-{$daysOfHistory} days"));
$sql = "\nselect isBlocked,monitorTime,rDNS,status\nfrom monitorHistory\nwhere ipDomain = '" . $mysql->escape($host) . "'\n\tand monitorTime >= '" . $mysql->escape($cutoffDate) . "'\norder by monitorTime desc\n";
$rs = $mysql->runQuery($sql);
?>

<?php 
include 'header.inc.php';
include 'accountSubnav.inc.php';
?>
<script src="js/jquery.tablesorter.min.js"></script>
<script>
$(document).ready(function() { 
	$("#hostTable").tablesorter(); 
	} 
);
</script>
Exemple #11
0
#!/usr/bin/php
<?php 
set_time_limit(0);
//prevent non cli access
if (php_sapi_name() !== 'cli') {
    exit;
}
$dir = dirname(dirname(__FILE__));
class_exists('Setup', false) or (include $dir . '/classes/Setup.class.php');
class_exists('Utilities', false) or (include $dir . '/classes/Utilities.class.php');
class_exists('_MySQL', false) or (include $dir . '/classes/_MySQL.class.php');
class_exists('_Logging', false) or (include $dir . '/classes/_Logging.class.php');
$options = getopt("r:");
$options['r'] = isset($options['r']) ? $options['r'] : '';
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
if ($options['r'] == 'blockListStats') {
    $mysql->runQuery("update blockLists set blocksYesterday = blocksToday, cleanYesterday = cleanToday; ");
    $mysql->runQuery("update blockLists set blocksToday = 0, cleanToday = 0; ");
    _Logging::appLog("block list stats updated");
}
if ($options['r'] == 'weekly') {
    $mysql->runQuery("update users set beenChecked = 0 where checkFrequency = 'weekly';");
    _Logging::appLog("weekly reset");
}
if ($options['r'] == 'daily') {
    $mysql->runQuery("update users set beenChecked = 0 where checkFrequency = 'daily';");
    _Logging::appLog("daily reset");
}
if ($options['r'] == '8hour') {
    $mysql->runQuery("update users set beenChecked = 0 where checkFrequency = '8hour';");
<?php

class_exists('Setup', false) or (include 'classes/Setup.class.php');
class_exists('Utilities', false) or (include 'classes/Utilities.class.php');
class_exists('_MySQL', false) or (include 'classes/_MySQL.class.php');
$groupName = array_key_exists('searchS', $_GET) ? trim($_GET['searchS']) : '';
if (Utilities::isLoggedIn() === false) {
    header('Location: login.php?location=' . urlencode('monitorGroup.php'));
    exit;
}
$titlePreFix = "Monitor Groups";
$user = Utilities::getAccount();
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
$sql = "\nselect g.*,\n\t(select count(*) from monitors where g.id = monitorGroupId) as hostCount,\n\t(select count(*) from monitors where isBlocked = 1 and g.id = monitorGroupId) as hostCountError,\n\t(select count(*) from monitors where lastStatusChanged = 1 and isBlocked = 1 and g.id = monitorGroupId) as hostRecentBlock\nfrom monitorGroup g\norder by g.groupName\n";
$rs = $mysql->runQuery($sql);
include 'header.inc.php';
include 'accountSubnav.inc.php';
?>

<script src="js/jquery.tablesorter.min.js"></script>

<script>
$(document).ready(function() { 
	$("#hostGroupTable").tablesorter();
});
</script>

<div>
<ul class="nav nav-pills">
	<li role="presentation"><a href="editHostGroup.php">New Group</a></li>