コード例 #1
0
	You should have received a copy of the GNU General Public License
	along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// INIT
define('PHOROMATIC_SERVER', true);
define('REMOTE_ACCESS', true);
// XXX TODO: Is this still used with new Phoromatic?
ini_set('memory_limit', '4G');
define('PTS_MODE', 'WEB_CLIENT');
define('PTS_AUTO_LOAD_OBJECTS', true);
//error_reporting(E_ALL);
include '../../pts-core.php';
pts_core::init();
if (isset($_GET['repo'])) {
    readfile(phoromatic_server::find_download_cache());
    pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' requested a copy of the download cache JSON');
} else {
    if (isset($_GET['download'])) {
        $requested_file = str_replace(array('..', '/'), null, $_GET['download']);
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' is attempting to download ' . $requested_file . ' from the download cache');
        if (($dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)))) && is_file($dc . $requested_file)) {
            $file_path = $dc . $requested_file;
        } else {
            if (is_file(PTS_DOWNLOAD_CACHE_PATH . $requested_file)) {
                $file_path = PTS_DOWNLOAD_CACHE_PATH . $requested_file;
            } else {
                if (is_file(PTS_SHARE_PATH . 'download-cache/' . $requested_file)) {
                    $file_path = PTS_SHARE_PATH . 'download-cache/' . $requested_file;
                } else {
                    if (is_file('/var/cache/phoronix-test-suite/download-cache/' . $requested_file)) {
 protected function process_data(&$user, &$msg)
 {
     $decoded_msg = $this->decode_data($user, $msg);
     //echo 'DECODED: '; var_dump($decoded_msg);
     //echo 'DECODED MSG: ' . $decoded_msg . PHP_EOL;
     foreach (explode(' ;; ', $decoded_msg) as $single_msg) {
         $json = json_decode($single_msg, true);
         if ($json && isset($json['phoromatic']['event'])) {
             switch ($json['phoromatic']['event']) {
                 case 'ping':
                     $j['phoromatic']['event'] = 'pong';
                     $j['phoromatic']['time'] = time();
                     $this->send_json_data($user->socket, $j);
                     break;
                 case 'pts-version':
                     $j['phoromatic']['event'] = 'pts-version';
                     $j['phoromatic']['response'] = pts_core::program_title(true);
                     $this->send_json_data($user->socket, $j);
                     break;
                 case 'core-version':
                     $version = PTS_CORE_VERSION;
                     $this->send_data($user->socket, $version);
                     break;
                 case 'download-cache':
                     $dc = json_decode(file_get_contents(phoromatic_server::find_download_cache()), true);
                     $j['phoromatic']['event'] = 'download-cache';
                     $j['phoromatic']['download-cache'] = $dc;
                     $this->send_json_data($user->socket, $j);
                     break;
                 case 'check':
                     $j['phoromatic']['event'] = 'check';
                     $j['phoromatic']['task'] = 'quit-testing';
                     $this->send_json_data($user->socket, $j);
                     break;
             }
         }
     }
 }