function bruteForceCheck($userName, $uType, $lockedAt) { include '../connection.php'; $unixTime = mktime(date("H"), date("i"), date("s"), date('n'), date('j'), date('Y')); if ($uType == 1) { $query = "SELECT dID\n\t\t\t\t\t\tFROM drivers\n\t\t\t\t\t\tWHERE dUsername = '******'"; } else { if ($uType == 0) { $query = "SELECT sID\n\t\t\t\t\t\tFROM superusers\n\t\t\t\t\t\tWHERE sUsername = '******'"; } } $sql = $db->query($query); $row = $sql->fetch_array(); $uID = $row['0']; if (isLocked($uID, $uType, $lockedAt)) { if ($uType == 0) { $msg = checkUnlock($uID); } else { $msg = "your account is locked out"; } return array(true, $msg); } else { return array(false); } }
function ScanFiles() { $GLOBALS["UUIDS"] = array(); $pids = $GLOBALS["CLASS_UNIX"]->PIDOF_PATTERN_ALL(basename(__FILE__)); $MaxInstances = round($GLOBALS["LogFileDeamonMaxInstances"] * 2); $GLOBALS["PREFIX_LOGSTATS"] = "Instances " . count($pids) . "/{$MaxInstances}"; if (count($pids) > $MaxInstances) { events("Running instances:" . count($pids) . " " . @implode(",", $pids) . " Too many instances agains {$GLOBALS["LogFileDeamonMaxInstances"]}*1.7={$MaxInstances} SKIP TASK"); while (list($xpid, $ligne) = each($pids)) { $cmdline = @file_get_contents("/proc/{$xpid}/cmdline"); events("Running instance:{$xpid} {$cmdline}"); } return; } $Files = $GLOBALS["CLASS_UNIX"]->DirFiles("/home/artica/squid/META_EVENTS_QUEUE"); $MAX = count($Files); if ($GLOBALS["VERBOSE"]) { echo "{$MAX} files\n"; } $c = 0; while (list($filename, $none) = each($Files)) { $path = "/home/artica/squid/META_EVENTS_QUEUE/{$filename}"; $LOCK_FILE = "/home/artica/squid/META_EVENTS_QUEUE/{$filename}.LCK"; $Time = $GLOBALS["CLASS_UNIX"]->file_time_sec($path); $c++; if (preg_match("#\\.LCK\$#", $filename)) { $filenameB = str_replace(".LCK", "", $filename); if (!is_file("/home/artica/squid/META_EVENTS_QUEUE/{$filenameB}")) { @unlink($path); } continue; } if (isLocked($path)) { continue; } @file_put_contents($LOCK_FILE, getmypid()); meta_events("PARSING {$path}"); if (!ParseFile($path)) { meta_events("*** PARSE {$path} FAILED ****"); if ($GLOBALS["VERBOSE"]) { echo "*** PARSE {$path} FAILED ****\n"; } @unlink($LOCK_FILE); continue; } @unlink($path); @unlink($LOCK_FILE); } meta_events(count($GLOBALS["UUIDS"]) . " uuid to analyze"); while (list($uuid, $rows) = each($GLOBALS["UUIDS"])) { hourly_to_daily($uuid); daily_to_monthly($uuid); } }
function lock(eZContentObject $object) { while (true) { if (isLocked($object)) { sleep(1); } else { break; } } $rowPending = array('action' => 'creating_translation', 'param' => $object->attribute('id')); $pendingItem = new eZPendingActions($rowPending); $pendingItem->store(); }
function initialize() { if (isLocked()) { die("Already running.\n"); } register_shutdown_function('terminate'); try { $config_path = dirname(__FILE__) . '/../config.ini'; if (!file_exists($config_path)) { throw new Exception("File not found.\n"); } $config = parse_ini_file($config_path, true); $GLOBALS['config'] = $config; } catch (Exception $e) { exit("Configuration file not found. Exiting...\n"); } echo "Starting up PlexVera...\n"; }
global $_MYDAEMON_SHOULD_STOP; global $_MYDAEMON_SHOULD_QUERY; //logging -> yes or no $logging = $config['installedpackages']['ifbwstats']['config'][0]['logging']; if ($logging == 'yes') { global $logfile; $logfile = fopen("/tmp/ifbwstats-daemon.log", "a") or die("Error Reading File"); $parentpid = getmypid(); fwrite($logfile, date('Y-m-d H:i:s') . " Startup - Parent PID is: " . $parentpid . "\n"); } if ($g['platform'] == 'cdrom') { fwrite($logfile, date('Y-m-d H:i:s') . " Daemon will not run on CD Rom platform, exiting... \n"); fclose($logfile); exit; } if (isLocked()) { if ($logging == 'yes') { fwrite($logfile, date('Y-m-d H:i:s') . " Daemon is already running, exiting second instance (" . getmypid() . ") \n"); } fclose($logfile); exit; } // endless loop while (1) { if (isset($_MYDAEMON_SHOULD_STOP) and $_MYDAEMON_SHOULD_STOP) { break; } $pidA = pcntl_fork(); if ($pidA) { // parent process runs here // wait until the child has finished processing then end the script
case $task_send_reminder: $cmd = sendReportsMailScript() . " " . $weeks[0] . " remind "; $DIS_AdminMessage = "Command: {$cmd}<br/>\n"; $DIS_AdminMessage .= "<hr>"; $DIS_AdminMessage .= "<pre>"; ob_start(); $result = system($cmd); $DIS_AdminMessage .= ob_get_contents(); ob_end_clean(); $DIS_AdminMessage .= "</pre>"; break; case $task_switch_lock: $DIS_AdminMessage = "Switch Locks<br/>\n"; while (list($key, $val) = each($weeks)) { $week = $val; if (isLocked($year, $week)) { $DIS_AdminMessage .= "Task [{$task}]: UnLock of Reporting {$week} of {$year} ...<br/>\n"; ob_start(); unLockWeekFilesFor($year, $week); $DIS_AdminMessage .= ob_get_contents(); ob_end_clean(); $DIS_AdminMessage .= "File for week {$week} of the year {$year} unLocked<br/>\n"; } else { $DIS_AdminMessage .= "Task [{$task}]: lock of Reporting {$week} of {$year} ...<br/>\n"; ob_start(); lockWeekFilesFor($year, $week); $DIS_AdminMessage .= ob_get_contents(); ob_end_clean(); $DIS_AdminMessage .= "File for week {$week} of the year {$year} locked<br/>\n"; } }
function getDrivers($id, $count) { include '../connection.php'; if ($count == "all") { $query = "SELECT *\n FROM drivers\n ORDER BY dLastName ASC"; } elseif ($count == "search") { $query = "SELECT *\n FROM drivers\n WHERE dFirstName LIKE '%{$id}%' OR dLastName LIKE '%{$id}%' OR dUsername LIKE '%{$id}%'\n ORDER BY dLastName ASC"; } $sql = $db->query($query); $row_cnt = $sql->num_rows; if ($row_cnt == 0) { if ($count == "all") { echo "<div class='alert alert-warning fade in msg'>There are currently no drivers in the database.</div>"; } if ($count == "search") { echo "<div class='alert alert-warning fade in msg'>There are currently no drivers that match your query.</div>"; } } else { echo "<table id='driverTable' class='alignleft table table-hover'>\n <thead class='tableHead'>\n <tr>\n <th width='25%'><i class='fa fa-check-square'></iclass></th>\n <th width='5%'>ID</th>\n <th width='10%'>Name</th>\n <th width='10%'>Username</th>\n <th width='15%'>Vehicle</th>\n <th width='10%'>Vehicle Tag</th>\n <th width='10%'>Insurance</th>\n <th width='10%'>Insurance Policy</th>\n <th width='5%'>Status</th>\n </tr>\n </thead>\n <tbody>"; while ($info = $sql->fetch_array()) { if ($info['dActive'] == 1) { $active = "Yes"; $action = "Deactivate"; } else { $active = "No"; $action = "Activate"; } if (isRetired($info['dID'])) { $dlabel = "Retire"; $status = "Active"; $step = 0; } else { $dlabel = "Re-enable"; $status = "Retired"; $step = 1; } if (isLocked($info['dID'])) { $locked = '<a onclick="unlockDriver(' . $info['dID'] . ')" class="dTableButton btn btn-xs btn-danger">Unlock Driver</a>'; } else { $locked = ""; } echo "<tr data-status='" . $status . "'>\n <td>\n <a href='driverEdit.php?dID=" . $info['dID'] . "' class='dTableButton btn btn-xs btn-success' data-driverID='" . $info['dID'] . "'>Edit</a>\t\t\t\t\t\t\n <a onclick='retireDriver(" . $info['dID'] . ", " . $step . ")' class='dTableButton btn btn-xs btn-success' data-driverID='" . $info['dID'] . "'>" . $dlabel . " Driver</a>\n " . $locked . "\n </td>\n <td>" . $info['dID'] . "</td>\n <td>" . $info['dLastName'] . ", " . $info['dFirstName'] . "</td>\n <td>" . $info['dUsername'] . "</td>\n <td>" . $info['dVehicleYear'] . " " . $info['dVehicleMake'] . " " . $info['dVehicleModel'] . "</td>\n <td>" . $info['dVehicleTag'] . "</td>\n <td>" . $info['dInsuranceCo'] . "</td>\n <td>" . $info['dInsurancePolicy'] . "</td>\n <td>" . $status . "</td>\n </tr>"; } echo "</tbody></table>"; } }
/** * Action hear * It returns the positions that an element can smell, if these positions have an element * * @param Element Element * * @return array Positions */ function hear($element) { $position = $element->getPosition(); switch (get_class($element)) { case 'Rabbit': $hearRange = $_POST['hearRabbit']; break; case 'Wolf': $hearRange = $_POST['hearWolf']; break; } $rowStart = $position[0] - $hearRange; $colStart = $position[1] - $hearRange; $rowEnd = $position[0] + $hearRange; $colEnd = $position[1] + $hearRange; $numRabbit = 0; $numWolf = 0; $numCarrot = 0; while ($rowStart <= $rowEnd) { while ($colStart <= $colEnd) { if (!isLocked($rowStart, $colStart)) { if (!($rowStart == $position[0] && $colStart == $position[1]) && get_class(getWorld()[$rowStart][$colStart]) != 'Ground') { $currentElement = get_class(getWorld()[$rowStart][$colStart]); switch ($currentElement) { case 'Rabbit': $numRabbit++; break; case 'Wolf': $numWolf++; break; case 'Carrot': $numCarrot++; break; } } } $colStart++; } $colStart = $position[1] - $hearRange; $rowStart++; } writeFileCSV('Log', array(getTime(), '', get_class($element), $element->getId(), '[ ' . $position[0] . ' - ' . $position[1] . ' ]', '', 'hear', 'Rabbit (' . $numRabbit . '), Wolf (' . $numWolf . '), Carrot(' . $numCarrot . ')')); return array('Rabbit' => $numRabbit, 'Wolf' => $numWolf, 'Carrot' => $numCarrot); }
function STATS_BuildCurrentTable() { $unix = new unix(); $maxInstances = 3; $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__)); if (count($pids) > $maxInstances) { if ($GLOBALS["VERBOSE"]) { echo count($pids) . " > {$maxInstances}\n"; } events(count($pids) . " > {$maxInstances}, aborting"); die; } $pidefile = "/etc/artica-postfix/pids/exec.postfix-stats.php.STATS_BuildCurrentTable.pid"; $pid = $unix->get_pid_from_file($pidefile); if ($unix->process_exists($pid)) { die; } file_put_contents($pidefile, $pid); $unix = new unix(); $timefile = "/etc/artica-postfix/pids/exec.postfix-stats.php.STATS_BuildCurrentTable.time"; $timesched = $unix->file_time_min($timefile); if ($timesched < 1) { events("{$timesched}Mn need at least 1mn"); return; } @unlink($timefile); @file_put_contents($timefile, time()); $Files = $unix->DirFiles("/home/artica/postfix/postfix/logger", "^realtime\\.[0-9]+\\.db"); events(count($Files) . " realtime files to parse..."); $current = "realtime." . date("YmdHi") . ".db"; $c = 0; while (list($filename, $none) = each($Files)) { $c++; if ($filename == $current) { continue; } if (!preg_match("#^realtime\\.[0-9]+\\.db\$#", $filename, $re)) { continue; } $path = "/home/artica/postfix/postfix/logger/{$filename}"; $LOCKFILE = "{$path}.LCK"; if (isLocked($path)) { continue; } @unlink($LOCKFILE); @file_put_contents($LOCKFILE, getmypid()); if (!STATS_BuildCurrentTable_parse($path)) { @unlink($LOCKFILE); continue; } echo "Remove {$path}\n"; @unlink($path); @unlink($LOCKFILE); } events("STATS_CNX_ACCEPT()"); STATS_CNX_ACCEPT(); events("STATS_BuildCurrentWeek()"); STATS_BuildCurrentWeek(); events("STATS_hourly_cnx_to_daily_cnx()"); STATS_hourly_cnx_to_daily_cnx(); }
function lockContent($type, $contentid, $userid) { $result = false; if (isLocked($type, $contentid) == NULL) { $date = new DateTime(); //change UTC time zone $date->setTimezone(new DateTimeZone('GMT')); $query = db_insert('carrefour_lock_content')->fields(array('carrefour_user_lock', 'carrefour_content_type_lock', 'carrefour_content_lock', 'carrefour_cron_lock_time')); $value = array('carrefour_user_lock' => $userid, 'carrefour_content_type_lock' => $type, 'carrefour_content_lock' => $contentid, 'carrefour_cron_lock_time' => $date->getTimestamp()); $query->values($value); $query->execute(); } return $result; }
<?php $registry =& registry::getInstance(); $user =& user::getInstance(); if (isLocked('login')) { throw new Exception('You are not allowed to log out!'); } else { $user->logout(); } http_response::back();