Subversion Repositories oidplus

Rev

Rev 240 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. declare(ticks=1);
  21.  
  22. set_time_limit(0);
  23.  
  24. require_once __DIR__ . '/../includes/oidplus.inc.php';
  25.  
  26. if (!file_exists(__DIR__ . '/../includes/config.inc.php')) {
  27.         // We need to do this, because we don't want to use OIDplus::init() in this updater (it should be independent as much as possible)
  28.         header('location:../setup/');
  29.         die('Redirecting to setup...');
  30. } else {
  31.         require_once __DIR__ . '/../includes/config.inc.php';
  32. }
  33.  
  34. require_once __DIR__ . '/includes/phpsvnclient.class.php';
  35. require_once __DIR__ . '/includes/http_class.class.php';
  36. require_once __DIR__ . '/includes/vnag_framework.inc.php';
  37.  
  38. define('OIDPLUS_REPO', 'https://svn.viathinksoft.com/svn/oidplus');
  39.  
  40. ?><!DOCTYPE html>
  41. <html lang="en">
  42.  
  43. <head>
  44.         <title>OIDplus Update</title>
  45.         <meta name="robots" content="noindex">
  46.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  47.         <link rel="stylesheet" href="../setup/setup.css">
  48.         <?php
  49.         if (RECAPTCHA_ENABLED) {
  50.         ?>
  51.         <script src="https://www.google.com/recaptcha/api.js"></script>
  52.         <?php
  53.         }
  54.         ?>
  55. </head>
  56.  
  57. <body>
  58.  
  59. <h1>Update OIDplus</h1>
  60.  
  61. <?php
  62.  
  63. if (isset($_REQUEST['update_now'])) {
  64.         if (RECAPTCHA_ENABLED) {
  65.                 $secret = RECAPTCHA_PRIVATE;
  66.                 $response = $_POST["g-recaptcha-response"];
  67.                 $verify = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
  68.                 $captcha_success = json_decode($verify);
  69.         }
  70.         if (RECAPTCHA_ENABLED && ($captcha_success->success==false)) {
  71.                 echo '<p><font color="red"><b>CAPTCHA not sucessfully verified</b></font></p>';
  72.                 echo '<p><a href="index.php">Try again</a></p>';
  73.         } else {
  74.                 if (!OIDplusAuthUtils::adminCheckPassword($_REQUEST['admin_password'])) {
  75.                         echo '<p><font color="red"><b>Wrong password</b></font></p>';
  76.                         echo '<p><a href="index.php">Try again</a></p>';
  77.                 } else {
  78.                         $svn = new phpsvnclient('https://svn.viathinksoft.com/svn/oidplus');
  79.                         $svn->versionFile = 'oidplus_version.txt';
  80.                         echo '<h2>Updating ...</h2>';
  81.                         echo '<pre>';
  82.                         $svn->updateWorkingCopy(dirname(__DIR__).'/oidplus_version.txt', '/trunk', dirname(__DIR__), false);
  83.                         echo '</pre>';
  84.                         echo '<p><a href="index.php">Back to update page</a></p>';
  85.                         echo '<hr>';
  86.                 }
  87.         }
  88.  
  89. } else {
  90.  
  91.         class VNagMonitorDummy extends VNag {
  92.                 private $status;
  93.                 private $content;
  94.  
  95.                 public function __construct($status, $content) {
  96.                         parent::__construct();
  97.                         $this->status = $status;
  98.                         $this->content = $content;
  99.                 }
  100.  
  101.                 protected function cbRun($optional_args=array()) {
  102.                         $this->setStatus($this->status);
  103.                         $this->setHeadline($this->content);
  104.                 }
  105.         }
  106.  
  107.         ?>
  108.  
  109.         <p><u>There are two possibilities how to keep OIDplus up-to-date:</u></p>
  110.  
  111.         <p><b>Method A</b>: Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co <?php echo OIDPLUS_REPO; ?>/trunk</code>
  112.         and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and also check for
  113.         conflicts. Highly recommended if you have a Shell/SSH access to your webspace!</p>
  114.  
  115.         <p><b>Method B:</b> Install OIDplus by downloading a ZIP file from www.viathinksoft.com, which contains a SVN snapshot, and extract it to your webspace.
  116.         The ZIP file contains a file named "oidplus_version.txt" which contains the SVN revision of the snapshot. This update-tool will then try to update your files
  117.         on-the-fly by downloading them from the ViaThinkSoft SVN repository directly into your webspace directory.
  118.         A change conflict detection is NOT implemented.
  119.         It is required that the files on your webspace have
  120.         create/write/delete permissions. Only recommended if you have no access to the SSH/Linux shell.</p>
  121.  
  122.         <hr>
  123.  
  124.         <?php
  125.  
  126.         $svn_wc_exists = is_dir(__DIR__ . '/../.svn');
  127.         $snapshot_exists = file_exists(__DIR__ . '/../oidplus_version.txt');
  128.  
  129.         if ($svn_wc_exists && $snapshot_exists) {
  130.                 echo '<font color="red">ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!</font>';
  131.                 $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, "ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!");
  132.                 $job->http_visual_output = false;
  133.                 $job->run();
  134.                 unset($job);
  135.         } else if (!$svn_wc_exists && !$snapshot_exists) {
  136.                 echo '<font color="red">ERROR: Neither oidplus_version.txt, nor .svn directory exist! Therefore, the version cannot be determined and the update needs to be applied manually!</font>';
  137.                 $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, "Neither oidplus_version.txt, nor .svn directory exist! Therefore, the version cannot be determined and the update needs to be applied manually!");
  138.                 $job->http_visual_output = false;
  139.                 $job->run();
  140.                 unset($job);
  141.         } else if ($svn_wc_exists) {
  142.                 echo '<p>You are using <b>method A</b> (SVN working copy).</p>';
  143.  
  144.                 $local_installation = OIDplus::getVersion();
  145.                 $svn = new phpsvnclient(OIDPLUS_REPO);
  146.                 $newest_version = 'svn-'.$svn->getVersion();
  147.                
  148.                 echo 'Local installation: ' . ($local_installation ? $local_installation : 'unknown') . '<br>';
  149.                 echo 'Latest published version: ' . ($newest_version ? $newest_version : 'unknown') . '<br>';
  150.  
  151.                 if (!$local_installation) {
  152.                         echo '<p><font color="red">The system could not determine the version of your system. (Required: svnupdate shell access or SQLite3). Please update your system manually via the SVN "update" command regularly.</font></p>';
  153.                 } else if ($local_installation == $newest_version) {
  154.                         echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>';
  155.  
  156.                         $job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)");
  157.                         $job->http_visual_output = false;
  158.                         $job->run();
  159.                         unset($job);
  160.                 } else {
  161.                         echo '<p><font color="blue">Please enter <code>svn update</code> into the SSH shell to update OIDplus to the latest version.</font></p>';
  162.  
  163.                         echo '<h2>Preview of update '.$local_installation.' &rarr; '.$newest_version.'</h2>';
  164.                         $svn = new phpsvnclient(OIDPLUS_REPO);
  165.                         echo '<pre>';
  166.                         $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', dirname(__DIR__), true);
  167.                         echo '</pre>';
  168.  
  169.                         $job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)");
  170.                         $job->http_visual_output = false;
  171.                         $job->run();
  172.                         unset($job);
  173.                 }
  174.         } else if ($snapshot_exists) {
  175.                 echo '<p>You are using <b>method B</b> (Snapshot ZIP file with oidplus_version.txt file).</p>';
  176.  
  177.                 $local_installation = OIDplus::getVersion();
  178.                 $svn = new phpsvnclient(OIDPLUS_REPO);
  179.                 $newest_version = 'svn-'.$svn->getVersion();
  180.  
  181.                 echo 'Local installation: ' . $local_installation.'<br>';
  182.                 echo 'Latest published version: ' . $newest_version.'<br>';
  183.  
  184.                 if ($local_installation == $newest_version) {
  185.                         echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>';
  186.  
  187.                         $job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)");
  188.                         $job->http_visual_output = false;
  189.                         $job->run();
  190.                         unset($job);
  191.                 } else {
  192.                         echo '<p><font color="blue">To update your OIDplus installation, please enter your password and click the button "Update NOW".</font></p>';
  193.                         echo '<p><font color="red">WARNING: Please make a backup of your files before updating. In case of an error, the OIDplus installation (including this update-assistant) might become unavailable. Also, since the web-update does not contain collission-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost!</font></p>';
  194.                         echo '<form method="POST" action="index.php">';
  195.  
  196.                         if (RECAPTCHA_ENABLED) {
  197.                                 echo '<noscript>';
  198.                                 echo '<p><font color="red">You need to enable JavaScript to solve the CAPTCHA.</font></p>';
  199.                                 echo '</noscript>';
  200.                                 echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>';
  201.                                 echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>';
  202.                         }
  203.  
  204.                         echo '<input type="hidden" name="update_now" value="1">';
  205.                         echo '<input type="password" name="admin_password">';
  206.                         echo '<input type="submit" value="Update NOW">';
  207.                         echo '</form>';
  208.  
  209.                         echo '<h2>Preview of update '.$local_installation.' &rarr; '.$newest_version.'</h2>';
  210.                         $svn = new phpsvnclient(OIDPLUS_REPO);
  211.                         echo '<pre>';
  212.                         $svn->updateWorkingCopy(dirname(__DIR__).'/oidplus_version.txt', '/trunk', dirname(__DIR__), true);
  213.                         echo '</pre>';
  214.  
  215.                         $job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)");
  216.                         $job->http_visual_output = false;
  217.                         $job->run();
  218.                         unset($job);
  219.                 }
  220.         }
  221.  
  222.         echo '<hr>';
  223.  
  224.         echo '<p><input type="button" onclick="document.location=\'../\'" value="Go back to OIDplus"></p>';
  225.  
  226.         echo '<br><p>Did you know that this page contains an invisible VNag tag? You can watch this page using the "webreader" plugin of VNag, and then monitor it with any Nagios compatible software! <a href="https://www.viathinksoft.com/projects/vnag">More information</a>.</p>';
  227. }
  228.  
  229. ?>
  230.  
  231. </body>
  232. </html>
  233.