コード例 #1
0
ファイル: Load.php プロジェクト: carriercomm/jbs
function __Error_Handler__($Number, $Error, $File, $Line)
{
    #-------------------------------------------------------------------------------
    $Message = SPrintF('[!!%s]-%s в линии %s файла %s', $Number, $Error, $Line, $File);
    #-------------------------------------------------------------------------------
    $__ERR_CODE =& $GLOBALS['__ERR_CODE'];
    #-------------------------------------------------------------------------------
    if ((int) $Error && $__ERR_CODE == 100) {
        $__ERR_CODE = $Error;
    }
    #-------------------------------------------------------------------------------
    Debug(SPrintF('[!] %s', $Message));
    //Debug(SPrintF('[!] %s',debug_print_backtrace()));
    #-------------------------------------------------------------------------------
    //Error_Reporting(E_ALL);
    #-------------------------------------------------------------------------------
    if (Error_Reporting()) {
        #-------------------------------------------------------------------------------
        $JBsErrorID = SPrintF('%s[%s]', HOST_ID, Md5(Implode(':', array($Number, $Error, $Line, $File))));
        #-------------------------------------------------------------------------------
        $__SYSLOG =& $GLOBALS['__SYSLOG'];
        #-------------------------------------------------------------------------------
        $Log = Implode("\n", $__SYSLOG);
        #-------------------------------------------------------------------------------
        Report($JBsErrorID, $JBsErrorID);
        #-------------------------------------------------------------------------------
        foreach (array(SYSTEM_PATH, '/tmp') as $Folder) {
            #-------------------------------------------------------------------------------
            $Path = SPrintF('%s/jbs-errors.log', $Folder);
            #-------------------------------------------------------------------------------
            if (File_Exists($Path)) {
                if (FileSize($Path) > 1024 * 1024) {
                    UnLink($Path);
                }
            }
            #-------------------------------------------------------------------------------
            umask(077);
            #-------------------------------------------------------------------------------
            if (!@File_Put_Contents($Path, SPrintF("%s\n\n%s\n\n", $JBsErrorID, $Log), FILE_APPEND)) {
                #-------------------------------------------------------------------------------
                Debug(SPrintF('[__Error_Handler__]: не удалось осуществить запись ошибки в системный лог (%s)', $Path));
                #-------------------------------------------------------------------------------
                continue;
                #-------------------------------------------------------------------------------
            }
            #-------------------------------------------------------------------------------
            break;
            #-------------------------------------------------------------------------------
        }
        #-------------------------------------------------------------------------------
        if (File_Exists(SPrintF('%s/DEBUG.OUT', SYSTEM_PATH)) || !isset($_SERVER["REMOTE_PORT"])) {
            #-------------------------------------------------------------------------------
            exit($Log);
        } else {
            #-------------------------------------------------------------------------------
            $Errors = array(100 => 'Ошибка выполнения', 101 => 'Неизвестный результат', 201 => 'Неверные параметры', 400 => 'Ошибка данных', 500 => 'Системная ошибка', 600 => 'Ошибка политики безопасности', 601 => 'Неверный реферер', 602 => 'Отсутствует реферер', 603 => 'Неверный ключ CSRF', 700 => 'Нарушение политики прав');
            #-------------------------------------------------------------------------------
            $FilePath = SPrintF('%s/hosts/root/templates/modules/Trigger.Error.html', SYSTEM_PATH);
            #-------------------------------------------------------------------------------
            if (Is_Readable($FilePath)) {
                #-------------------------------------------------------------------------------
                $Result = @File_Get_Contents($FilePath);
                #-------------------------------------------------------------------------------
            } else {
                #-------------------------------------------------------------------------------
                $Result = SPrintF("Cannot read error file: %s<BR />\nError: %%s<BR />\n<!--%%s-->\nErrorID: %%s\n<!--%%s-->", $FilePath);
                #-------------------------------------------------------------------------------
            }
            #-------------------------------------------------------------------------------
            $String = SPrintF('%s (%s)', $Errors[$__ERR_CODE], $__ERR_CODE);
            #-------------------------------------------------------------------------------
            @Header(SPrintF('JBs-ErrorID: %s', $JBsErrorID));
            #-------------------------------------------------------------------------------
            if (isset($_POST['XMLHttpRequest'])) {
                #-------------------------------------------------------------------------------
                $Answer = array('Error' => array('CodeID' => $__ERR_CODE, 'String' => $String), 'Status' => 'Error');
                #-------------------------------------------------------------------------------
                exit(JSON_Encode($Answer));
                #-------------------------------------------------------------------------------
            } else {
                #-------------------------------------------------------------------------------
                exit(SPrintF($Result, $String, $String, $JBsErrorID, Date('Y', Time())));
                #-------------------------------------------------------------------------------
            }
            #-------------------------------------------------------------------------------
        }
        #-------------------------------------------------------------------------------
    }
    #-------------------------------------------------------------------------------
}
コード例 #2
0
ファイル: update.php プロジェクト: RaptorFactor/SteamTracking
 private function HandleResponse($File, $Data)
 {
     if ($File === 'API/SupportedAPIList.json') {
         $Data = JSON_Decode($Data, true);
         if (!isset($Data['apilist']['interfaces'])) {
             return false;
         }
         foreach ($Data['apilist']['interfaces'] as $Interface) {
             $File = __DIR__ . '/API/' . $Interface['name'] . '.json';
             $Interface = JSON_Encode($Interface, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
             if (!File_Exists($File) || StrCmp(File_Get_Contents($File), $Interface) !== 0) {
                 File_Put_Contents($File, $Interface);
             }
         }
         return true;
     } else {
         if ($File === 'ClientManifest/steam_client_publicbeta_osx' || $File === 'ClientManifest/steam_cmd_publicbeta_osx') {
             foreach ($this->ClientArchives as $Archive) {
                 if (Preg_Match('/"' . Str_Replace('.', '\\.', $Archive) . '\\.([a-f0-9]{40})"/m', $Data, $Test) === 1) {
                     $Test = $Test[1];
                     if (!isset($this->ETags[$Archive]) || $this->ETags[$Archive] !== $Test) {
                         $this->Log('Downloading {lightblue}' . $Archive . '{normal} - checksum: ' . $Test);
                         $this->ETags[$Archive] = $Test;
                         $this->URLsToFetch[] = array('URL' => 'https://steamcdn-a.akamaihd.net/client/' . $Archive . '.' . $Test, 'File' => '.support/' . $Archive);
                     } else {
                         $this->Log('Matched {lightblue}' . $Archive . '{normal}, but we already have it cached');
                     }
                 } else {
                     $this->Log('{yellow}Failed to find {lightblue}' . $Archive);
                 }
             }
             unset($Test);
         } else {
             if ($File === 'Random/ValveGroup.json' || $File === 'Random/SteamModerators.json') {
                 LibXML_Use_Internal_Errors(true);
                 $Data = SimpleXML_Load_String($Data);
                 if ($Data === false || empty($Data->members->steamID64)) {
                     return false;
                 }
                 $Data = Array_Values((array) $Data->members->steamID64);
                 Sort($Data);
                 $Data = JSON_Encode($Data, JSON_PRETTY_PRINT);
             } else {
                 if ($File === 'Scripts/Dota2/heropickerdata.json') {
                     $Data = JSON_Decode($Data, true);
                     $Data = JSON_Encode($Data, JSON_PRETTY_PRINT);
                 } else {
                     if ($File === 'Scripts/Dota2/heropedia.js') {
                         $Data = preg_replace('/\\?v=[0-9]+/', '?v=ayyvalve', $Data);
                     } else {
                         if (SubStr($File, 0, 13) === 'ItemSchemaURL') {
                             $Data = JSON_Decode($Data, true);
                             if (isset($Data['result']['items_game_url'])) {
                                 $this->URLsToFetch[] = array('URL' => $Data['result']['items_game_url'], 'File' => str_replace('ItemSchemaURL', 'ItemSchema', $File));
                             }
                             return true;
                         } else {
                             if (SubStr($File, -4) === '.zip') {
                                 $File = __DIR__ . '/' . $File;
                                 File_Put_Contents($File, $Data);
                                 $Archive = SubStr(StrrChr($File, '/'), 1);
                                 if (SHA1_File($File) !== $this->ETags[$Archive]) {
                                     $this->Log('{lightred}Checksum mismatch for ' . $Archive);
                                     return false;
                                 }
                                 $this->ExtractClientArchives = true;
                                 return true;
                             } else {
                                 if (SubStr($File, -5) === '.html') {
                                     if (StrrPos($Data, '</html>') === false) {
                                         return false;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $File = __DIR__ . '/' . $File;
     $Folder = dirname($File);
     if (!is_dir($Folder)) {
         $this->Log('{lightblue}Creating ' . $Folder);
         mkdir($Folder, 0755, true);
     }
     if (File_Exists($File) && StrCmp(File_Get_Contents($File), $Data) === 0) {
         return false;
     }
     File_Put_Contents($File, $Data);
     return true;
 }
コード例 #3
0
ファイル: Patches.comp.php プロジェクト: carriercomm/jbs
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
$Tmp = System_Element('tmp');
if (Is_Error($Tmp)) {
    return SPrintF("---\n%s\n---\n", Implode("\n", Array_Slice($__SYSLOG, Count($__SYSLOG) - 20)));
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# файлик для хранения данных для соединения с БД
$MyCnf = SPrintF('%s/my.cnf', $Tmp);
#-------------------------------------------------------------------------------
if (File_Exists($MyCnf)) {
    UnLink($MyCnf);
}
#-------------------------------------------------------------------------------
if (!@File_Put_Contents($MyCnf, SPrintF("[client]\nhost = %s\nport = %u\nuser = %s\npassword = %s\n", $DBConnection['Server'], $DBConnection['Port'], $DBConnection['User'], $DBConnection['Password']))) {
    echo SPrintF('<P>Не удалось сохранить текущие настройки соединения с базой данных в файле (%s)</P>', $MyCnf);
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if ($Backup && !Preg_Match('/^Windows/', Php_UName('s'))) {
    #-------------------------------------------------------------------------------
    echo "-- Резервное копирование базы данных\n\n";
    #-------------------------------------------------------------------------------
    $Folder = SPrintF('%s/db', $Tmp);
    #-------------------------------------------------------------------------------
    if (!File_Exists($Folder)) {
        if (!@MkDir($Folder, 0777, TRUE)) {
            return ERROR | @Trigger_Error(500);
        }
    }
コード例 #4
0
ファイル: index.php プロジェクト: carriercomm/jbs
function __ShutDown_Function__()
{
    global $__SETTINGS, $__MESSAGES, $__ERRORS;
    echo '</TABLE>';
    if (Count($__MESSAGES)) {
        echo '<H2>Сообщения:</H2><UL class="Standard">';
        foreach ($__MESSAGES as $__MESSAGE) {
            echo SPrintF('<LI>%s</LI>', $__MESSAGE);
        }
        echo '</UL>';
    }
    if (Count($__ERRORS)) {
        echo '<H2>Ошибки выполнения:</H2><UL class="Standard">';
        foreach ($__ERRORS as $__ERROR) {
            echo SPrintF('<LI><PRE>%s</PRE></LI>', $__ERROR);
        }
        echo '</UL>';
    }
    if (File_Exists(SPrintF('%s/INSTALL', SYSTEM_PATH))) {
        if (!@File_Put_Contents(SETTINGS_FILE, JSON_Encode($__SETTINGS))) {
            echo SPrintF('<P>Не удалось сохранить текущие настройки установки в файле (%s)</P>', SETTINGS_FILE);
        }
    }
    echo <<<EOD
 </BODY>
</HTML>
EOD;
}