コード例 #1
0
ファイル: common_helper.php プロジェクト: rouben/LimeSurvey
function getUpdateInfo()
{
    if (getGlobalSetting('SessionName') == '') {
        setGlobalSetting('SessionName', randomChars(64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ!"$%&/()=?`+*~#",;.:abcdefghijklmnopqrstuvwxyz123456789'));
    }
    Yii::import('application.libraries.admin.http.httpRequestIt');
    $http = new httpRequestIt();
    $http->proxy_host_name = Yii::app()->getConfig("proxy_host_name", "");
    $http->proxy_host_port = Yii::app()->getConfig("proxy_host_port", 80);
    $http->timeout = 0;
    $http->data_timeout = 0;
    $http->user_agent = "LimeSurvey " . Yii::app()->getConfig("versionnumber") . " build " . Yii::app()->getConfig("buildnumber");
    $http->GetRequestArguments("http://update.limesurvey.org?build=" . Yii::app()->getConfig("buildnumber") . '&id=' . md5(getGlobalSetting('SessionName')) . '&crosscheck=true', $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;
}
コード例 #2
0
ファイル: update.php プロジェクト: josetorerobueno/test_repo
 private function _RunUpdaterUpdate()
 {
     $clang = $this->getController()->lang;
     $versionnumber = Yii::app()->getConfig("versionnumber");
     $buildnumber = Yii::app()->getConfig("buildnumber");
     $tempdir = Yii::app()->getConfig("tempdir");
     Yii::import('application.libraries.admin.http.httpRequestIt');
     $oHTTPRequest = new httpRequestIt();
     $oHTTPRequest->proxy_host_name = Yii::app()->getConfig("proxy_host_name", "");
     $oHTTPRequest->proxy_host_port = Yii::app()->getConfig("proxy_host_port", 80);
     /* Connection timeout */
     $oHTTPRequest->timeout = 0;
     /* Data transfer timeout */
     $oHTTPRequest->data_timeout = 0;
     $oHTTPRequest->user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
     $oHTTPRequest->GetRequestArguments($this->getProtocol() . "update.limesurvey.org?updaterbuild={$buildnumber}", $arguments);
     $updateinfo = false;
     $error = $oHTTPRequest->Open($arguments);
     $error = $oHTTPRequest->SendRequest($arguments);
     $oHTTPRequest->ReadReplyHeaders($headers);
     if ($error == "") {
         $body = '';
         $full_body = '';
         for (;;) {
             $error = $oHTTPRequest->ReadReplyBody($body, 10000);
             if ($error != "" || strlen($body) == 0) {
                 break;
             }
             $full_body .= $body;
         }
         $updateinfo = json_decode($full_body, true);
         if ($oHTTPRequest->response_status != '200') {
             $updateinfo['errorcode'] = $oHTTPRequest->response_status;
             $updateinfo['errorhtml'] = $full_body;
         }
     } else {
         $updateinfo['errorcode'] = $error;
         $updateinfo['errorhtml'] = $error;
     }
     unset($oHTTPRequest);
     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;
     Yii::import('application.libraries.admin.http.httpRequestIt');
     $oHTTPRequest = new httpRequestIt();
     $oHTTPRequest->proxy_host_name = Yii::app()->getConfig("proxy_host_name", "");
     $oHTTPRequest->proxy_host_port = Yii::app()->getConfig("proxy_host_port", 80);
     // Allow redirects
     $oHTTPRequest->follow_redirect = 1;
     /* Connection timeout */
     $oHTTPRequest->timeout = 0;
     /* Data transfer timeout */
     $oHTTPRequest->data_timeout = 0;
     $oHTTPRequest->user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
     $oHTTPRequest->GetRequestArguments($this->getProtocol() . "update.limesurvey.org/updates/downloadupdater/{$updateinfo['UpdaterRevision']}", $arguments);
     $oHTTPRequesterror = $oHTTPRequest->Open($arguments);
     $oHTTPRequesterror = $oHTTPRequest->SendRequest($arguments);
     $oHTTPRequest->ReadReplyHeaders($headers);
     if ($headers['content-type'] == 'text/html') {
         @unlink($tempdir . '/updater.zip');
     } elseif ($oHTTPRequesterror == '') {
         $body = '';
         $full_body = '';
         for (;;) {
             $oHTTPRequesterror = $oHTTPRequest->ReadReplyBody($body, 100000);
             if ($oHTTPRequesterror != "" || strlen($body) == 0) {
                 break;
             }
             $full_body .= $body;
         }
         file_put_contents($tempdir . '/updater.zip', $full_body);
     }
     $aData['httperror'] = $oHTTPRequesterror;
     //Now unzip the new updater over the existing ones.
     if (file_exists($tempdir . '/updater.zip')) {
         Yii::app()->loadLibrary("admin/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;
 }
コード例 #3
0
ファイル: update.php プロジェクト: krsandesh/LimeSurvey
 function step4()
 {
     $buildnumber = Yii::app()->getConfig("buildnumber");
     $tempdir = Yii::app()->getConfig("tempdir");
     $updatebuild = getGlobalSetting("updatebuild");
     $rootdir = Yii::app()->getConfig("rootdir");
     $publicdir = Yii::app()->getConfig("publicdir");
     $tempdir = Yii::app()->getConfig("tempdir");
     $aDatabasetype = Yii::app()->db->getDriverName();
     // Request the list with changed files from the server
     $aData = array();
     if (!isset(Yii::app()->session['updateinfo'])) {
         if ($updateinfo['error'] == 1) {
         }
     } else {
         $updateinfo = Yii::app()->session['updateinfo'];
     }
     // this is the last step - Download the zip file, unpack it and replace files accordingly
     // Create DB and file backups now
     $downloaderror = false;
     Yii::import('application.libraries.admin.http.httpRequestIt');
     $http = new httpRequestIt();
     $http->proxy_host_name = Yii::app()->getConfig("proxy_host_name", "");
     $http->proxy_host_port = Yii::app()->getConfig("proxy_host_port", 80);
     // 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($this->getProtocol() . "update.limesurvey.org/updates/download/{$updateinfo['downloadid']}", $arguments);
     $http->RestoreCookies(Yii::app()->session['updatesession']);
     $error = $http->Open($arguments);
     $error = $http->SendRequest($arguments);
     $http->ReadReplyHeaders($headers);
     if ($headers['content-type'] == 'text/html') {
         @unlink($tempdir . '/update.zip');
     } else {
         if ($error == '') {
             $body = '';
             $pFile = fopen($tempdir . '/update.zip', 'w');
             for (;;) {
                 $error = $http->ReadReplyBody($body, 100000);
                 if ($error != "" || strlen($body) == 0) {
                     break;
                 }
                 fwrite($pFile, $body);
             }
             fclose($pFile);
         } else {
             print $error;
         }
     }
     //Now unzip the new files over the existing ones.
     $new_files = false;
     if (file_exists($tempdir . '/update.zip')) {
         Yii::app()->loadLibrary("admin/pclzip");
         $archive = new PclZip($tempdir . '/update.zip');
         if ($archive->extract(PCLZIP_OPT_PATH, $rootdir . '/', PCLZIP_OPT_REPLACE_NEWER) == 0) {
             die("Error : " . $archive->errorInfo(true));
         } else {
             $new_files = true;
             unlink($tempdir . '/update.zip');
         }
     } else {
         $downloaderror = true;
     }
     // Now remove all files that are to be deleted according to update process
     // This happens after unzipping
     foreach ($updateinfo['files'] as $afile) {
         if ($afile['type'] == 'D' && file_exists($rootdir . $afile['file'])) {
             if (is_file($rootdir . $afile['file'])) {
                 @unlink($rootdir . $afile['file']);
             } else {
                 rmdirr($rootdir . $afile['file']);
             }
         }
     }
     $aData['new_files'] = $new_files;
     $aData['downloaderror'] = $downloaderror;
     //  PclTraceDisplay();
     // Now we have to update version.php
     if (!$downloaderror) {
         @ini_set('auto_detect_line_endings', true);
         $versionlines = file($rootdir . '/application/config/version.php');
         $handle = fopen($rootdir . '/application/config/version.php', "w");
         foreach ($versionlines as $line) {
             if (strpos($line, 'buildnumber') !== false) {
                 $line = '$config[\'buildnumber\'] = ' . Yii::app()->session['updateinfo']['toversion'] . ';' . "\r\n";
             }
             fwrite($handle, $line);
         }
         fclose($handle);
     }
     setGlobalSetting('updateavailable', '0');
     setGlobalSetting('updatebuild', '');
     setGlobalSetting('updateversions', '');
     // We redirect here because the  files might have been overwritten earlier
     // and classes may have been changed that would be needed in the view
     Yii::app()->session['installlstep4b'] = $aData;
     Yii::app()->getController()->redirect(array('/admin/update/sa/step4b'));
 }