function markRecProcessed($sessionId) { global $DB; $sth1 = $DB->dbh->prepare("UPDATE FmClientSession SET Processed=? WHERE SessionId=?"); $sth1->execute(array(1, $sessionId)); if ($sth1->errorInfo()[1]) { printLogAndDie("DB error: " . $sth1->errorInfo()[2]); } return ''; }
} } } if (!array_key_exists('month', $options) || !preg_match('/^\\d+$/', $options['month'])) { printLogAndDie("invalid parameters"); } $result = ''; // result data to send $monthName = ''; $serverName = ''; // Select and calculate sum here $stmt = "SELECT OwnerName,ServerName,DATE_FORMAT(StartDate,'%M %Y') as MonthName, ROUND(SUM(TIMESTAMPDIFF(SECOND, StartDate, EndDate))/60) as UsedMinutes " . "FROM FmClientSession " . "WHERE MONTH(StartDate) = MONTH(CURDATE()-INTERVAL ? MONTH) and YEAR(StartDate) = YEAR(CURDATE()-INTERVAL ? MONTH) " . "AND ConnectionType=? " . "GROUP BY OwnerName ORDER BY OwnerName"; $sth = $DB->dbh->prepare($stmt); $sth->execute(array($options['month'], $options['month'], FM_CONN_PAID)); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } while ($rec = $sth->fetch(PDO::FETCH_ASSOC)) { $monthName = $rec['MonthName']; // All the records have the same month name $serverName = $rec['ServerName']; // All the records have the same server name $billedMin = $rec['UsedMinutes'] - $CONFIG['FM_FREE_USAGE_TIME'] * 60; $result .= "<TR>" . "<TD>" . $rec['OwnerName'] . "</TD>" . "<TD style='text-align:right'>" . $rec['UsedMinutes'] . "</TD>" . "<TD style='text-align:right'>" . ($billedMin < 0 ? 0 : $billedMin) . "</TD>" . "</TR>"; } // Send stat $mail = new PHPMailer(); //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $CONFIG['MAIL_HOST'];
$res = shell_exec($checkCmd); } else { $res = $ssh->exec($checkCmd); } $log->message("Check server result: " . $res); if ($res && !preg_match('/^Error:/m', $res)) { // No errors in result string updateStatusFile($options['status'], "Server started"); $log->message("Server started"); exit; // Server restarted, exit here } } catch (Exception $e) { // Some error updateStatusFile($options['status'], "Error checking server status"); printLogAndDie("Send check command error: " . $e->getMessage()); } updateStatusFile($options['status'], 'Trying to start server (attempt #' . $tryCnt . ')'); try { // Try to start server if ($config['main']['fms_server'] == 'LOCAL') { $res = shell_exec($startCmd); } else { $res = $ssh->exec($startCmd); } $log->message("Start server (iteration {$tryCnt}) result: " . $res); } catch (Exception $e) { // Some error $log->message("Start server error: " . $e->getMessage()); } $tryCnt++;
function CleanUpDB() { global $DB, $CONFIG; $sth = $DB->dbh->prepare("DELETE FROM FmAccessLog WHERE DATEDIFF(NOW(),LogDate) > ?"); $sth->execute(array($CONFIG['DB_RECORDS_LIFETIME'])); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } $sth = $DB->dbh->prepare("DELETE FROM FmClientSession WHERE DATEDIFF(NOW(),StartDate) > ?"); $sth->execute(array($CONFIG['DB_RECORDS_LIFETIME'])); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } }
function markLogRecord($sessionId, $id) { global $DB; $sth = $DB->dbh->prepare("UPDATE FmAccessLog SET SessionId=? WHERE Id=?"); $sth->execute(array($sessionId, $id)); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } }
function loadDir($dir) { global $SKIP_FOLDERS; $dirContent = array(); // Dir content $dirContent['SIZE'] = 0; // Initialize structure $dirContent['DIRS'] = array(); $dirContent['FILES'] = array(); $fsobj = new COM('Scripting.FileSystemObject', null, CP_UTF8); // Requires extension=php_com_dotnet.dll try { // Try to write on the page $folderObj = $fsobj->GetFolder($dir); } catch (Exception $e) { // Some wiki error printLogAndDie("Error loading folder " . $dir . ": " . $e->getMessage()); } foreach ($folderObj->Files as $fileObj) { // Check files in dir $dirContent['FILES'][$fileObj->Name] = $fileObj->Size; // Store file and it's size $dirContent['SIZE'] += $fileObj->Size; // Add file's size to total size } foreach ($folderObj->SubFolders as $subFolderObj) { // Check subdirectories if (in_array($subFolderObj->Name, $SKIP_FOLDERS)) { // Skip this folder continue; } $dirContent['DIRS'][$subFolderObj->Name] = array(); // Init new dir structure $subDirContent = loadDir($dir . '/' . $subFolderObj->Name); // Load subdir data $dirContent['DIRS'][$subFolderObj->Name] = $subDirContent; // Store subdir data $dirContent['SIZE'] += $subDirContent['SIZE']; // Add subdir size to total size } return $dirContent; // Return Dir content }