Subversion Repositories oidplus

Rev

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

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2021 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. include '../../../3p/vts_vnag/vnag_framework.inc.php';
  21. include '../../../includes/oidplus.inc.php';
  22.  
  23. OIDplus::init(false);
  24.  
  25. if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminVNagVersionCheck', false)) {
  26.         throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
  27. }
  28.  
  29. class VNagMonitorDummy extends VNag {
  30.  
  31.         private $status;
  32.  
  33.         private $content;
  34.  
  35.         public function __construct($status, $content) {
  36.                 parent::__construct();
  37.                 $this->status = $status;
  38.                 $this->content = $content;
  39.         }
  40.  
  41.         protected function cbRun($optional_args = array()) {
  42.                 $this->setStatus($this->status);
  43.                 $this->setHeadline($this->content);
  44.         }
  45. }
  46.  
  47. $installType = OIDplus::getInstallType();
  48.  
  49. if ($installType === 'ambigous') {
  50.         $out_stat = VNag::STATUS_CRITICAL;
  51.         $out_msg  = 'Multiple version files/directories (oidplus_version.txt, .git and .svn) are existing! Therefore, the version is ambiguous!'; // do not translate
  52. } else if ($installType === 'unknown') {
  53.         $out_stat = VNag::STATUS_CRITICAL;
  54.         $out_msg  = 'The version cannot be determined, and the update needs to be applied manually!'; // do not translate
  55. } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
  56.         $local_installation = OIDplus::getVersion();
  57.         try {
  58.                 $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
  59.                 $newest_version = 'svn-' . $svn->getVersion();
  60.         } catch (Exception $e) {
  61.                 $newest_version = false;
  62.         }
  63.  
  64.         $requireInfo = ($installType === 'svn-wc') ? 'shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension' : 'shell access with Git client'; // do not translate
  65.         $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
  66.  
  67.         if (!$newest_version) {
  68.                 $out_stat = VNag::STATUS_CRITICAL;
  69.                 $out_msg  = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate
  70.         } else if (!$local_installation) {
  71.                 $out_stat = VNag::STATUS_WARNING;
  72.                 $out_msg  = 'OIDplus could not determine its version (Required: ' . $requireInfo . '). Please update your system manually via the "' . $updateCommand . '" command regularly.'; // do not translate
  73.         } else if ($local_installation == $newest_version) {
  74.                 $out_stat = VNag::STATUS_OK;
  75.                 $out_msg  = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  76.         } else {
  77.                 $out_stat = VNag::STATUS_WARNING;
  78.                 $out_msg  = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  79.         }
  80. } else if ($installType === 'svn-snapshot') {
  81.         $local_installation = OIDplus::getVersion();
  82.         try {
  83.                 $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
  84.                 $newest_version = 'svn-' . $svn->getVersion();
  85.         } catch (Exception $e) {
  86.                 $newest_version = false;
  87.         }
  88.  
  89.         if (!$newest_version) {
  90.                 $out_stat = VNag::STATUS_CRITICAL;
  91.                 $out_msg  = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate
  92.         } else if ($local_installation == $newest_version) {
  93.                 $out_stat = VNag::STATUS_OK;
  94.                 $out_msg  = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  95.         } else {
  96.                 $out_stat = VNag::STATUS_WARNING;
  97.                 $out_msg  = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  98.         }
  99. }
  100.  
  101. $job = new VNagMonitorDummy($out_stat, $out_msg);
  102. $job->http_visual_output = VNag::OUTPUT_ALWAYS;
  103. if (OIDplus::getPkiStatus(true)) {
  104.         $job->privkey = OIDplus::config()->getValue('oidplus_private_key');
  105. }
  106. $job->run();
  107. unset($job);
  108.