Esempio n. 1
0
function getUpdateInfo()
{
    //require_once($homedir."/classes/http/http.php");
    Yii::import('application.libraries.admin.http.http');
    $http = new http();
    $http->timeout = 0;
    $http->data_timeout = 0;
    $http->user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
    $http->GetRequestArguments("http://update.limesurvey.org?build=" . Yii::app()->getConfig("buildnumber"), $arguments);
    $updateinfo = false;
    $error = $http->Open($arguments);
    $error = $http->SendRequest($arguments);
    $http->ReadReplyHeaders($headers);
    if ($error == "") {
        $body = '';
        $full_body = '';
        for (;;) {
            $error = $http->ReadReplyBody($body, 10000);
            if ($error != "" || strlen($body) == 0) {
                break;
            }
            $full_body .= $body;
        }
        $updateinfo = json_decode($full_body, true);
        if ($http->response_status != '200') {
            $updateinfo['errorcode'] = $http->response_status;
            $updateinfo['errorhtml'] = $full_body;
        }
    } else {
        $updateinfo['errorcode'] = $error;
        $updateinfo['errorhtml'] = $error;
    }
    unset($http);
    return $updateinfo;
}
Esempio n. 2
0
 private function _RunUpdaterUpdate()
 {
     $clang = $this->getController()->lang;
     $versionnumber = Yii::app()->getConfig("versionnumber");
     $buildnumber = Yii::app()->getConfig("buildnumber");
     $tempdir = Yii::app()->getConfig("tempdir");
     $http = new http();
     /* Connection timeout */
     $http->timeout = 0;
     /* Data transfer timeout */
     $http->data_timeout = 0;
     $http->user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
     $http->GetRequestArguments("http://update.limesurvey.org?updaterbuild={$buildnumber}", $arguments);
     $updateinfo = false;
     $error = $http->Open($arguments);
     $error = $http->SendRequest($arguments);
     $http->ReadReplyHeaders($headers);
     if ($error == "") {
         $body = '';
         $full_body = '';
         for (;;) {
             $error = $http->ReadReplyBody($body, 10000);
             if ($error != "" || strlen($body) == 0) {
                 break;
             }
             $full_body .= $body;
         }
         $updateinfo = json_decode($full_body, true);
         if ($http->response_status != '200') {
             $updateinfo['errorcode'] = $http->response_status;
             $updateinfo['errorhtml'] = $full_body;
         }
     } else {
         $updateinfo['errorcode'] = $error;
         $updateinfo['errorhtml'] = $error;
     }
     unset($http);
     if ((int) $updateinfo['UpdaterRevision'] <= $buildnumber) {
         // There is no newer updater version on the server
         return true;
     }
     if (!is_writable($tempdir) || !is_writable(APPPATH . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'update.php')) {
         $error = true;
     }
     //  Download the zip file, unpack it and replace the updater file accordingly
     // Create DB and file backups now
     $downloaderror = false;
     $http = new http();
     // Allow redirects
     $http->follow_redirect = 1;
     /* Connection timeout */
     $http->timeout = 0;
     /* Data transfer timeout */
     $http->data_timeout = 0;
     $http->user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
     $http->GetRequestArguments("http://update.limesurvey.org/updates/downloadupdater/{$this->updaterversion}", $arguments);
     $httperror = $http->Open($arguments);
     $httperror = $http->SendRequest($arguments);
     $http->ReadReplyHeaders($headers);
     if ($headers['content-type'] == 'text/html') {
         @unlink($tempdir . '/updater.zip');
     } elseif ($httperror == '') {
         $body = '';
         $full_body = '';
         for (;;) {
             $httperror = $http->ReadReplyBody($body, 100000);
             if ($httperror != "" || strlen($body) == 0) {
                 break;
             }
             $full_body .= $body;
         }
         file_put_contents($tempdir . '/updater.zip', $full_body);
     }
     $aData['httperror'] = $httperror;
     //Now unzip the new updater over the existing ones.
     if (file_exists($tempdir . '/updater.zip')) {
         Yii::app()->loadLibrary("admin/pclzip/pclzip", array('p_zipname' => $tempdir . '/updater.zip'));
         $archive = new PclZip(array('p_zipname' => $tempdir . '/updater.zip'));
         if ($archive->extract(PCLZIP_OPT_PATH, APPPATH . '/controllers/admin/', PCLZIP_OPT_REPLACE_NEWER) == 0) {
             die("Error : " . $archive->errorInfo(true));
         } else {
             unlink($tempdir . '/updater.zip');
         }
         $updater_exists = true;
     } else {
         $updater_exists = false;
         $error = true;
     }
     $aData['updater_exists'] = $updater_exists;
 }