PHP Classes

File: views/update.php

Recommend this page to a friend!
  Classes of Axel Hahn  >  Pimped Apache Status  >  views/update.php  >  Download  
File: views/update.php
Role: Example script
Content type: text/plain
Description: Sample output
Class: Pimped Apache Status
Display the requests handled by an Apache server
Author: By
Last change: 2018-02-04 - v1.28
* use explicit tmpdir value
Date: 2 years ago
Size: 4,189 bytes
 

 

Contents

Class file image Download
<?php

/*
 * PIMPED APACHE-STATUS
 *
 * view: update
 */

$sApproot=dirname(__DIR__);
$sZipfile = getTempdir() . '/__pimpapachestat-latest.zip';
$sTargetPath = $sApproot;
$sLatestUrl=$aEnv["links"]["update"]['download']['url'];

if (!
array_key_exists('doinstall', $_GET)) {
   
// ------------------------------------------------------------
    // step 1: welcome
    // ------------------------------------------------------------
   
$sUpdateInfo=checkUpdate(true);
   
$content = '<h3 id="h3' . md5($sServer) . '">' . $aUserCfg['icons']['update.php'] .' '. $aLangTxt["lblUpdate"] . '</h3>'
           
. '<div class="subh3"><br>'
           
. (hasNewVersion($sUpdateInfo)
                ?
' '.$aLangTxt['lblUpdateNewerVerionAvailable'].'<br>'
               
:'<div class="hintbox">'.$aLangTxt['lblUpdateNoNewerVerionAvailable'].'</div>'
               
)
            .
'<br>'
           
. sprintf($aLangTxt["lblUpdateHints"], $sLatestUrl)
            .
'</div>'
           
. '<a href="' . getNewQs(array('doinstall' => 'download')) . '"'
           
. ' class="btn btn-default"'
           
. '>' . $aLangTxt["lblUpdateContinue"] . '</a>';
} else {
    switch (
$_GET['doinstall']) {
       
       
// ------------------------------------------------------------
        // step 2: download
        // ------------------------------------------------------------
       
case 'download':
           
$content = '<h3 id="h3' . md5($sServer) . '">' . $aUserCfg['icons']['update.php'] .' '. $aLangTxt["lblUpdate"] . '</h3>'
                   
. '<div class="subh3">';


            if (
file_exists($sZipfile)) {
               
unlink($sZipfile);
            }
           
           
$sLatestVersionUrl = httpFollowUrl($sLatestUrl);
           
           
$content.= $sLatestUrl . '<br> --&gt; GET ' . $sLatestVersionUrl;
           
$sData = httpGet($sLatestVersionUrl);
           
$content.=' ('.strlen($sData) . ')<br>';
       
            if (
strlen($sData) > 100000) {
               
file_put_contents($sZipfile, $sData);
                if (
file_exists($sZipfile)) {
                   
$content.='<br><strong>'.$aLangTxt['lblUpdateDonwloadDone'].'</strong>'
                           
. '</div><a href="' . getNewQs(array('doinstall' => 'unzip')) . '"'
                           
. ' class="btn btn-default"'
                           
. '>' . $aLangTxt["lblUpdateContinue"] . '</a>';
                } else {
                   
$content.=$aLangTxt['lblUpdateDonwloadFailed'] . '</div>';
                }
            } else {
               
$content.=$aLangTxt['lblUpdateDonwloadFailed'] . '</div>';
            }

            break;
           
       
// ------------------------------------------------------------
        // step 3: unzip downloaded file
        // ------------------------------------------------------------
       
case 'unzip':
           
$content = '<h3 id="h3' . md5($sServer) . '">' . $aUserCfg['icons']['update.php'] .' '. $aLangTxt["lblUpdate"] . '</h3>'
                   
. '<div class="subh3">';
           
$content.=sprintf($aLangTxt['lblUpdateUnzipFile'], $sZipfile, $sTargetPath) . '<br><br>';
           
           
$zip = new ZipArchive;
           
           
$res = $zip->open($sZipfile);
            if (
$res === TRUE) {
               
// extract it to the path we determined above
               
$zip->extractTo($sTargetPath);
               
$zip->close();
               
$content.=$aLangTxt['lblUpdateUnzipOK'] . '</div>'
                   
. '<a href="?"'
                       
. ' class="btn btn-default"'
                       
. '>' . $aLangTxt["lblUpdateContinue"] . '</a>';
               
unlink($sZipfile);
            } else {
               
$content.=$aLangTxt['lblUpdateUnzipFailed'] . '</div>';
            }
            break;
       
/*
        case 'postunzip':
            $content = '<h3 id="h3' . md5($sServer) . '">' . $aLangTxt["lblUpdate"] . '</h3>'
                    . '<div class="h3">';
            $content.='</div>';
            break;
        */
       
default:
            break;
    }
}


echo
$content;


For more information send a message to info at phpclasses dot org.