public function Run($id = null) { echo $this->Title('NZB'); $count = 0; $query = 'SELECT "postcat"."postid","posts"."subject" FROM "postcat" LEFT JOIN "posts" ON ("posts"."id" = "postcat"."postid") ' . 'WHERE ("postcat"."nzb_date" < "postcat"."updated") ORDER BY "postcat"."post_date" DESC '; $rs = static::$conn->Execute($query); while ($row = $rs->Fetch()) { echo $row['postid'] . ' :: ' . SafeHTML($row['subject']) . '<br />'; // Create parent folder if it doesn't exist yet if (!file_exists(dirname(Post::NZBFile($row['postid'])))) { mkdir(dirname(Post::NZBFile($row['postid'])), 0755, true); } // Write NZB file file_put_contents(Post::NZBFile($row['postid']), Post::NZB($row['postid'])); // Update DB if (file_exists(Post::NZBFile($row['postid']))) { static::$conn->AutoUpdate('postcat', array('nzb_date' => time()), 'postid = ?', $row['postid']); } $count++; // Abort if processing if to much NZB files to process if (GetMicroTime() - $this->time['start'] > self::TIME_LIMIT) { break; } } echo '<p><b>' . $count . '</b> NZB files processed.</p>'; }
function NICELog($log, $mode, $type) { $this->debug_msg = array("", "CRITICAL", "ERROR", "NOTICE", "4", "INFO", "6", "DEBUG", "8"); $this->debug_mode = $mode; $this->type = $type; $this->log = $log; $this->starttime = GetMicroTime(); }
function IsTimeEnough() { $timeDiff = round(DEADLINE - GetMicroTime(), 3); if ($timeDiff > 0) { return true; } else { return false; } }
function CloseLog($msg) { if ($this->log == "false") { return; } $laptime = GetMicroTime() - $this->starttime; $this->WriteLog(INFO, "END " . $this->type . " " . $msg . " Laptime:[" . round($laptime, 3) . "sec]"); $this->WriteLog(INFO, "==============================================================="); fclose($this->handle); }
function CleanUp() { global $DB; $days = COption::GetOptionInt("mail", "time_keep_log", B_MAIL_KEEP_LOG); $strSql = "DELETE FROM b_mail_log WHERE DATE_INSERT < DATE_ADD(now(), INTERVAL -" . intval($days) . " DAY)"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $mt = GetMicroTime(); $dbr = $DB->Query("SELECT MS.ID FROM b_mail_message MS, b_mail_mailbox MB WHERE MS.MAILBOX_ID=MB.ID AND MB.MAX_KEEP_DAYS>0 AND MS.DATE_INSERT < DATE_ADD(now(), INTERVAL -MB.MAX_KEEP_DAYS DAY)"); while ($ar = $dbr->Fetch()) { CMailMessage::Delete($ar["ID"]); if (GetMicroTime() - $mt > 10 * 1000) { break; } } return "CMailbox::CleanUp();"; }
function DNSLookUP() { $starttime = GetMicroTime(); $ip = @gethostbyname($this->host); if ($ip) { $this->ip = $ip; } else { $this->error("Hostname " . $this->host . " could not be resolved"); return DNS_LOOKUP_ERR; } $this->dns_laptime = round(GetMicroTime() - $starttime, 3); if ($this->dns_laptime > DNS_LOOKUP_TIMEOUT) { return DNS_LOOKUP_TIMEOUT_ERR; } return OK; }
function QuerySet($Query) { /*///////////////////////////////////////////////////////////// Author: Plottery Corp. Created: v1.0.0 - 2010-11-27 Revisions: None Purpose: Runs a query on the database where a several records are expected as a result Returns: Number of rows, recordset and query time -OR- false */ ///////////////////////////////////////////////////////////// global $DBConnection; $Time = GetMicroTime(); $Result = mysql_query($Query, $DBConnection); if (!$Result) { return false; } if (mysql_num_rows($Result) == false || mysql_num_rows($Result) == 0) { return array(0, null, GetMicroTime() - $Time); } else { return array(mysql_num_rows($Result), $Result, GetMicroTime() - $Time); } }
public function Execute($query) { if (!$this->connected) { $this->Open(); } // Get extra arguments (for prepared statements) $args = array(); if (func_num_args() > 1) { $args = func_get_args(); if (isset($args[1]) && is_array($args[1])) { $args = array_values($args[1]); } else { array_shift($args); } // Use all arguments as values (except query of course) } $start = GetMicroTime(); // Passed existing statement as first argument if (is_object($query) && $query instanceof mysqli_stmt) { $result = $this->ExecuteStatement($query, $args); } elseif (strpos($query, '?') !== false && func_num_args() > 1 && count($args) > 0) { $statement = parent::prepare($query); if ($this->errno) { throw new SQLException($this->error, $this->errno, (string) $query); } $result = $this->ExecuteStatement($statement, $args); } else { $result = parent::query($query, MYSQLI_STORE_RESULT); if ($this->errno) { throw new SQLException($this->error, $this->errno, (string) $query); } } // Get meta data (for SELECT from prepared statment) if ($result instanceof mysqli_stmt) { $meta = $result->result_metadata(); if ($this->errno) { throw new SQLException($this->error, $this->errno, (string) $query); } } $end = GetMicroTime(); self::$stats['count']++; self::$stats['duration'] += $end - $start; // Return record set (if rows returned from query) if (is_object($result) && $result instanceof mysqli_result) { return new MySQLRecordSet($result); } elseif (is_object($result) && $result instanceof mysqli_stmt && isset($meta) && is_object($meta)) { return new MySQLRecordSet($result, $meta); } else { return $result; } }
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. VerliAdmin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VerliAdmin; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ $script_start = GetMicroTime($script_start); $script_end = GetMicroTime(); $scrpt_time = Round($script_end - $script_start, 4); StoreQueries($DB_hub); ?> <BR> <TABLE class="footer"> <TR> <TD class="left" nowrap><?PrintF("<FONT class=\"b\">".$text_page_time."</FONT>", $scrpt_time);?></TD> <?IF(MySQL == "MySQL"){?><TD class="left" nowrap><?Print "<FONT class=\"b\">".$text_queries."</FONT> : ".($DB_hub->mysql_queries * 1)." / ".Number_Format($_COOKIE['queries']);?></TD><?}?> <TD class="right b" nowrap><A href="http://bohyn.czechweb.cz/" title="bohyn.czechweb.cz">VerliAdmin v<?Print VA_VERSION;?></A>, © by <A href="mailto:support@verliadmin.wz.cz">bohyn</A> </TD> </TR> </TABLE> <BR><BR>
function CTimeStr() { return MicroTimeToStr(GetMicroTime()); }
/** * Performs a query. * * Performs a query, logging the time spent running it, any errors, and the optional log message. * * @param string $query The query to be run. * @param string $log (optional) A message to put in the query log. * @return mixed A result set on success, false on error. * @access public */ public function query($query, $log = '') { $start = GetMicroTime(); $this->_log['N']++; $this->_log[$this->_log['N']]['Q'] = $query; $autotrans = false; if (empty($this->_transaction_depth)) { $autotrans = true; $this->begin(); } $rez = @pg_query($this->_connection, $query); if ($rez === false) { $err = pg_last_error($this->_connection); $this->_log[$this->_log['N']]['E'] = $err; if ($autotrans) { $this->rollback(); } trigger_error("SQL Error - See backtrace for more information: {$err} in query {$query}", E_USER_WARNING); } else { if ($autotrans) { $this->commit(); } } $time = round(GetMicroTime() - $start, 4); if (!empty($log)) { $this->_log[$this->_log['N']]['L'] = $log; } $this->_log[$this->_log['N']]['T'] = $time; $this->_log['T'] += $time; return $rez; }
protected function Stats() { $this->time['end'] = GetMicroTime(); $duration = $this->time['end'] - $this->time['start']; return '<p><i>Statistics</i><br />' . "\n" . 'Total time: <b>' . number_format($duration, 2) . '</b> seconds (' . 'php: ' . number_format(abs($duration - static::$conn->duration), 3) . 's - ' . 'memory: ' . number_format(memory_get_peak_usage() / 1048576, 1) . ' MiB - ' . 'sql: ' . number_format(static::$conn->duration, 3) . 's / ' . static::$conn->count . " queries)</p>\n"; }
public function Save() { $hash = hash('sha512', GetMicroTime() . rand() . rand() . rand()); $hash = hash_hmac('sha512', $hash, file_get_contents('/dev/urandom', null, null, 0, 4096)); $this->hash = $hash; $_COOKIE[Token::COOKIE] = $hash; setcookie(Token::COOKIE, $hash, time() + Token::TTL, '/', static::$config['url']['domain'], false, true); $this->created = time(); parent::Save(); }
<?php // die('Upgrading PostgreSQL; try again later...'); ignore_user_abort(true); define('E_SQL_ERROR', E_USER_WARNING, true); require_once __DIR__ . '/library/datetime.php'; $GLOBALS['output_timer'] = GetMicroTime(); require_once __DIR__ . '/sql_engines/postgresql.php'; require_once __DIR__ . '/config.php'; $GLOBALS['sql'] = new SQLEnginePostgres($GLOBALS['sql_username'], $GLOBALS['sql_password'], $GLOBALS['sql_socket'], $GLOBALS['sql_hostname'], $GLOBALS['sql_port'], $GLOBALS['sql_database'], $GLOBALS['sql_persistent']); if ($GLOBALS['sql']->connect() === false) { trigger_error('Could not connect to the SQL server.', E_USER_ERROR); }
protected function DetectSpam() { $spam = 0; $ids = array(); // .EXE files are instantly suspect as virus or spam $query = 'SELECT "id" FROM "posts" ' . 'WHERE ("stats" LIKE \'%exe%\') ' . 'AND ("subject" NOT LIKE \'%rockman%\') ' . 'AND ("subject" NOT LIKE \'%megaman%\') ' . 'AND ("subject" NOT LIKE \'%baldr%\') ' . 'AND ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("hidden" = 0) '; // Only match posts not already hidden $rs = static::$conn->Execute($query); while ($row = $rs->Fetch()) { $ids[$row['id']] = intval($row['id']); Post::Queue($row['id']); } // Posts with keyword "keygen" are 99.999% probable spam $query = 'SELECT "id" FROM "posts" ' . 'WHERE ("subject" LIKE \'%keygen%\') ' . 'AND ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("hidden" = 0) '; // Only match posts not already hidden $rs = static::$conn->Execute($query); while ($row = $rs->Fetch()) { $ids[$row['id']] = intval($row['id']); Post::Queue($row['id']); } // Posts with keyword "compressed]" (with bracket at end) are 99.999% probable spam $query = 'SELECT "id" FROM "posts" ' . 'WHERE ("subject" LIKE \'%compressed]%\') ' . 'AND ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("hidden" = 0) '; // Only match posts not already hidden $rs = static::$conn->Execute($query); while ($row = $rs->Fetch()) { $ids[$row['id']] = intval($row['id']); Post::Queue($row['id']); } // Posts with keywords "crack" *and* "serial" are 99.999% probable spam $query = 'SELECT "id" FROM "posts" ' . 'WHERE ("subject" LIKE \'%crack%\') AND ("subject" LIKE \'%serial%\') ' . 'AND ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("hidden" = 0) '; // Only match posts not already hidden $rs = static::$conn->Execute($query); while ($row = $rs->Fetch()) { $ids[$row['id']] = intval($row['id']); Post::Queue($row['id']); } // Posts with keyword "WMV" are 99.999% probable spam $query = 'SELECT "id" FROM "posts" ' . 'WHERE ("subject" LIKE \'%wmv%\') ' . 'AND ("stats" NOT LIKE \'%par%\') ' . 'AND ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("hidden" = 0) ' . 'AND ("updated" < ?) '; $rs = static::$conn->Execute($query, time() - self::RECENT_THRESHOLD); while ($row = $rs->Fetch()) { $ids[$row['id']] = intval($row['id']); Post::Queue($row['id']); } // Match posts as spam if an article matches the subject of an article from existing spam post $start = GetMicroTime(); $query = 'SELECT "id" FROM "posts" ' . 'WHERE ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("hidden" = 0) ' . 'AND ("updated" > ?) ' . 'ORDER BY RAND() '; $rs = static::$conn->Execute($query, time() - self::MATCH_RECENT); while ($row = $rs->Fetch()) { // Find all articles associated with a post $rs2 = static::$conn->Execute('SELECT "id","subject" FROM "articles" WHERE ("postid" = ?) ', $row['id']); while ($row2 = $rs2->Fetch()) { $subject = $row2['subject']; $result = preg_match_all('/([\\[\\(]*)(\\d+|\\*)(\\s*of\\s*|\\s*von\\s*|\\s*[\\\\\\/-]\\s*)(\\d+)([\\)\\]]*)/i', $row2['subject'], $matches); if ($result) { // Only replace part indicators that are NOT at the start of the subject line, otherwise matching is very db intensive foreach ($matches[0] as $key => $match) { if (strpos($row2['subject'], $match) > 0) { $subject = str_replace($match, '%', $subject); } } $subject = preg_replace('/\\%{2,}/', '%', $subject); } // Count number of articles with same subject that are associated with posts marked as hidden $query = 'SELECT COUNT(*) AS "total" FROM "articles" INNER JOIN "posts" ON ("posts"."id" = "articles"."postid") ' . 'WHERE ("articles"."id" != ?) ' . 'AND ("articles"."postid" > 0) ' . 'AND ("articles"."subject" LIKE ?) ' . 'AND ("posts"."hidden" = 1) '; $rs3 = static::$conn->Execute($query, $row2['id'], $subject); $row3 = $rs3->Fetch(); if ($row3['total'] > 0) { // Non-zero response = subject matches known spam post $ids[$row['id']] = intval($row['id']); Post::Queue($row['id']); } // These checks can be extremely time consuming, so limit time allowed if (GetMicroTime() - $start > self::SPAM_TIME_LIMIT) { break 2; } } } // Find spam by checking all authors who made posts without any typical files like NZB, NFO, SFV etc. $start = GetMicroTime(); $query = 'SELECT "authorid",subject FROM "posts" ' . 'WHERE ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("hidden" = 0) ' . 'AND ("updated" > ?) ' . 'AND ("updated" < ?) ' . 'GROUP BY "authorid" ' . 'ORDER BY RAND() '; $rs = static::$conn->Execute($query, time() - self::MATCH_RECENT, time() - self::RECENT_THRESHOLD); while ($row = $rs->Fetch()) { // First get data on all posts $query = 'SELECT COUNT(*) AS "total", SUM("files") AS "total_files",ROUND((SUM("size") / SUM("files")) / (1024*1024)) AS "avg_size" FROM "posts" ' . 'WHERE ("authorid" = ?) ' . 'AND ("updated" > ?) '; $rs2 = static::$conn->Execute($query, $row['authorid'], time() - self::MATCH_RANGE); $row2 = $rs2->Fetch(); // Then get data on all posts except those with typical files (NZB, NFO, SFV etc) $query = 'SELECT COUNT(*) AS "total", SUM("files") AS "total_files",ROUND((SUM("size") / SUM("files")) / (1024*1024)) AS "avg_size" FROM "posts" ' . 'WHERE ("authorid" = ?) ' . 'AND ("stats" NOT LIKE \'%nzb%\') ' . 'AND ("stats" NOT LIKE \'%sfv%\') ' . 'AND ("stats" NOT LIKE \'%md5%\') ' . 'AND ("stats" NOT LIKE \'%nfo%\') ' . 'AND ("stats" NOT LIKE \'%jpg%\') ' . 'AND ("stats" NOT LIKE \'%gif%\') ' . 'AND ("stats" NOT LIKE \'%png%\') ' . 'AND ("stats" NOT LIKE \'%mp3%\') ' . 'AND ("stats" NOT LIKE \'%ogg%\') ' . 'AND ("stats" NOT LIKE \'%flac%\') ' . 'AND ("updated" > ?) '; $rs3 = static::$conn->Execute($query, $row['authorid'], time() - self::MATCH_RANGE); $row3 = $rs3->Fetch(); // Only process authors that do not post any NZB, NFO, SFV (etc) files in ANY of their posts at all (total posts from both queries above is the SAME) if ($row2['total'] == $row3['total'] && $row2['total'] > self::SPAM_POST_THRESHOLD && $row2['avg_size'] < self::SPAM_SIZE_THRESHOLD) { $rs4 = static::$conn->Execute('SELECT "id" FROM "posts" WHERE ("authorid" = ?) AND ("hidden" = 0) ', $row['authorid']); while ($row4 = $rs4->Fetch()) { $ids[$row4['id']] = intval($row4['id']); Post::Queue($row4['id']); } } // These checks can be extremely time consuming, so limit time allowed if (GetMicroTime() - $start > self::SPAM_TIME_LIMIT) { break; } } // Author 34 (Default Yenc Power-Post user) is suspect - mark any post without typical files (NZB, NFO, SFV etc) as spam $query = 'SELECT "id" FROM "posts" ' . 'WHERE ("authorid" = 34) ' . 'AND ("stats" NOT LIKE \'%nzb%\') ' . 'AND ("stats" NOT LIKE \'%sfv%\') ' . 'AND ("stats" NOT LIKE \'%md5%\') ' . 'AND ("stats" NOT LIKE \'%nfo%\') ' . 'AND ("stats" NOT LIKE \'%jpg%\') ' . 'AND ("stats" NOT LIKE \'%gif%\') ' . 'AND ("stats" NOT LIKE \'%png%\') ' . 'AND ("stats" NOT LIKE \'%mp3%\') ' . 'AND ("stats" NOT LIKE \'%ogg%\') ' . 'AND ("stats" NOT LIKE \'%flac%\') ' . 'AND ("hidden" = 0) ' . 'AND ("updated" > ?) ' . 'AND ("updated" < ?) '; $rs = static::$conn->Execute($query, time() - self::MATCH_RECENT, time() - self::RECENT_THRESHOLD); while ($row = $rs->Fetch()) { $ids[$row['id']] = intval($row['id']); Post::Queue($row['id']); } // Check authors with high spam percentage and mark all remaining posts as spam as well (IMPORTANT: only works if "hidden" flag is at most "1" and NOT any higher!) $query = 'SELECT "authorid",ROUND((SUM("hidden") / COUNT(*)) * 100) AS "spam", COUNT(*) AS "total", SUM("hidden") AS "total_hidden" FROM "posts" ' . 'WHERE ("authorid" NOT IN (' . implode(',', $GLOBALS['goodauthors']) . ')) ' . 'AND ("authorid" NOT IN (34,201)) ' . 'GROUP BY "authorid" '; $rs = static::$conn->Execute($query); while ($row = $rs->Fetch()) { // Continue if spam percentage is 20% or higher but not already 100% if ($row['spam'] > 20 && $row['total'] != $row['total_hidden']) { $rs2 = static::$conn->Execute('SELECT "id" FROM "posts" WHERE ("authorid" = ?) AND ("hidden" = 0) ', $row['authorid']); while ($row2 = $rs2->Fetch()) { $ids[$row2['id']] = intval($row2['id']); Post::Queue($row2['id']); } } // Alternatively if author has one or more hidden files (but not 100%) and one of them is a .EXE file assume everything is spam if ($row['total_hidden'] > 0 && $row['total'] != $row['total_hidden']) { $rs2 = static::$conn->Execute('SELECT COUNT(*) AS "total" FROM "posts" WHERE ("authorid" = ?) AND ("hidden" = 1) AND ("stats" LIKE \'%exe%\') ', $row['authorid']); $row2 = $rs2->Fetch(); if ($row2['total'] > 0) { // .EXE file found: mark all as spam $rs2 = static::$conn->Execute('SELECT "id" FROM "posts" WHERE ("authorid" = ?) AND ("hidden" = 0) ', $row['authorid']); while ($row2 = $rs2->Fetch()) { $ids[$row2['id']] = intval($row2['id']); Post::Queue($row2['id']); } } } } // Mark all collected post IDs as hidden if (count($ids) > 0) { static::$conn->Execute('UPDATE "posts" SET "hidden" = 1, "updated" = UNIX_TIMESTAMP() WHERE "id" IN (' . implode(',', $ids) . ') '); $spam += static::$conn->affected_rows; } echo '<p>Marked <b>' . $spam . '</b> posts as spam.</p>'; // Update posts (mainly to remove postcat for entries that are now hidden) Post::Update(); }
function GenerateContentIdPrefix() { $cid = strtoupper(md5(GetMicroTime())); $cid = substr($cid, 0, 8) . '.' . substr($cid, 8, 8) . '.' . substr($cid, 16, 8) . '.' . substr($cid, 24, 8); return $cid; }
function InternalQuery(&$cmd) { $sql = $this->InternalParse($cmd); if (DEBUG_ENABLE) { $t1 = GetMicroTime(); $res = @mysql_query($sql, $this->conn); $t2 = GetMicroTime(); if ($res) { $dt = $t2 - $t1; DebugWrite("<b>Success [</b>" . htmlspecialchars($sql) . "<b>] " . mysql_affected_rows($this->conn) . " rows affected</b> (" . $dt . ")", $dt < 0.1 ? MSG_SUCCESS : MSG_ACCENT); } else { DebugWrite("<b>Failed [</b>" . htmlspecialchars($sql) . "<b>] " . mysql_error($this->conn) . "</b>", MSG_ERROR); } } else { $res = @mysql_query($sql, $this->conn); } return $res; }
public function Execute($query) { if (!$this->connected) { $this->Open(); } // Get extra arguments (for prepared statements) $args = array(); if (func_num_args() > 1) { $args = func_get_args(); if (isset($args[1]) && is_array($args[1])) { $args = array_values($args[1]); } else { array_shift($args); } // Use all arguments as values (except query of course) } try { $start = GetMicroTime(); // Passed existing statement as first argument if (is_object($query) && $query instanceof PostgreSQLStatement) { $statement = $query; $query = $statement->query; $result = pg_execute($this->connection, $statement->name, $args); } elseif (strpos($query, '?') !== false && func_num_args() > 1 && count($args) > 0) { $statement = new PostgreSQLStatement($query); // Prepare statement if it doesn't exist already if (!isset($this->statements[$statement->name])) { $result = pg_prepare($this->connection, $statement->name, $statement->query); if ($result !== false) { $this->statements[$statement->name]['name'] = $statement->name; } } // Execute statement if it exists (or was just prepared succesfully) if (isset($this->statements[$statement->name])) { $result = pg_execute($this->connection, $statement->name, $args); } } else { $statement = null; $result = pg_query($query); } // Check for errors if ($result === false) { throw new SQLException(pg_last_error($this->connection), 0, (string) $query); } $end = GetMicroTime(); self::$stats['count']++; self::$stats['duration'] += $end - $start; $this->affected_rows = pg_affected_rows($result); return new PostgreSQLRecordSet($result, $statement); } catch (Exception $e) { throw new SQLException(pg_last_error($this->connection), 0, (string) $query); } }