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.';
    }
    if ($passwdOld != $passwd) {
 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;
 }