Subversion Repositories oidplus

Rev

Rev 1278 | Rev 1375 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPageAdminSoftwareUpdate extends OIDplusPagePluginAdmin
  27.         implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 /* getNotifications */
  28. {
  29.  
  30.         /**
  31.          * @param bool $html
  32.          * @return void
  33.          */
  34.         public function init(bool $html=true) {
  35.         }
  36.  
  37.         /**
  38.          * @return string
  39.          */
  40.         private function getGitCommand(): string {
  41.                 return 'git --git-dir='.escapeshellarg(OIDplus::findGitFolder()).' --work-tree='.escapeshellarg(OIDplus::localpath()).' -C "" pull origin master -s recursive -X theirs';
  42.         }
  43.  
  44.         /**
  45.          * @return string
  46.          */
  47.         private function getSvnCommand(): string {
  48.                 return 'svn update --accept theirs-full';
  49.         }
  50.  
  51.         /**
  52.          * @param array $params
  53.          * @return array
  54.          * @throws OIDplusException
  55.          */
  56.         private function action_Update(array $params): array {
  57.                 @set_time_limit(0);
  58.  
  59.                 if (!OIDplus::authUtils()->isAdminLoggedIn()) {
  60.                         throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), null, 401);
  61.                 }
  62.  
  63.                 if (OIDplus::getInstallType() === 'git-wc') {
  64.                         $cmd = $this->getGitCommand().' 2>&1';
  65.  
  66.                         $ec = -1;
  67.                         $out = array();
  68.                         exec($cmd, $out, $ec);
  69.  
  70.                         $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
  71.                         if ($ec === 0) {
  72.                                 $rev = 'HEAD'; // do not translate
  73.                                 return array("status" => 0, "content" => $res, "rev" => $rev);
  74.                         } else {
  75.                                 return array("status" => -1, "error" => $res, "content" => "");
  76.                         }
  77.                 }
  78.                 else if (OIDplus::getInstallType() === 'svn-wc') {
  79.                         $cmd = $this->getSvnCommand().' 2>&1';
  80.  
  81.                         $ec = -1;
  82.                         $out = array();
  83.                         exec($cmd, $out, $ec);
  84.  
  85.                         $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
  86.                         if ($ec === 0) {
  87.                                 $rev = 'HEAD'; // do not translate
  88.                                 return array("status" => 0, "content" => $res, "rev" => $rev);
  89.                         } else {
  90.                                 return array("status" => -1, "error" => $res, "content" => "");
  91.                         }
  92.                 }
  93.                 else if (OIDplus::getInstallType() === 'svn-snapshot') {
  94.  
  95.                         $rev = $params['rev'];
  96.  
  97.                         $update_version = $params['update_version'] ?? 1;
  98.                         if (($update_version != 1) && ($update_version != 2)) {
  99.                                 throw new OIDplusException(_L('Unknown update version'));
  100.                         }
  101.  
  102.                         // Download and unzip
  103.  
  104.                         $cont = false;
  105.                         for ($retry=1; $retry<=3; $retry++) {
  106.                                 if (function_exists('gzdecode')) {
  107.                                         $url = sprintf(OIDplus::getEditionInfo()['update_package_gz'], $rev-1, $rev);
  108.                                         $cont = url_get_contents($url);
  109.                                         if ($cont !== false) $cont = @gzdecode($cont);
  110.                                 } else {
  111.                                         $url = sprintf(OIDplus::getEditionInfo()['update_package'], $rev-1, $rev);
  112.                                         $cont = url_get_contents($url);
  113.                                 }
  114.                                 if ($cont !== false) {
  115.                                         break;
  116.                                 } else {
  117.                                         sleep(1);
  118.                                 }
  119.                         }
  120.                         if ($cont === false) throw new OIDplusException(_L("Update %1 could not be downloaded from ViaThinkSoft server. Please try again later.",$rev));
  121.  
  122.                         // Check signature...
  123.  
  124.                         if (function_exists('openssl_verify')) {
  125.  
  126.                                 $m = array();
  127.                                 if (!preg_match('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', $cont, $m)) {
  128.                                         throw new OIDplusException(_L("Update package file of revision %1 not digitally signed",$rev));
  129.                                 }
  130.                                 $signature = base64_decode($m[1]);
  131.  
  132.                                 $naked = preg_replace('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', '', $cont);
  133.                                 $hash = hash("sha256", $naked."update_".($rev-1)."_to_".($rev).".txt");
  134.  
  135.                                 $public_key = file_get_contents(__DIR__.'/public.pem');
  136.                                 if (!openssl_verify($hash, $signature, $public_key, OPENSSL_ALGO_SHA256)) {
  137.                                         throw new OIDplusException(_L("Update package file of revision %1: Signature invalid",$rev));
  138.                                 }
  139.  
  140.                         }
  141.  
  142.                         // All OK! Now write the file
  143.  
  144.                         $tmp_filename = 'update_'.generateRandomString(10).'.tmp.php';
  145.                         $local_file = OIDplus::localpath().$tmp_filename;
  146.  
  147.                         @file_put_contents($local_file, $cont);
  148.  
  149.                         if (!file_exists($local_file) || (@file_get_contents($local_file) !== $cont)) {
  150.                                 throw new OIDplusException(_L('Update file could not written. Probably there are no write-permissions to the root folder.'));
  151.                         }
  152.  
  153.                         if ($update_version == 1) {
  154.                                 // Now call the written file
  155.                                 // Note: we may not use eval($cont) because the script uses die(),
  156.                                 // and things in the script might collide with currently (un)loaded source code files, shutdown procedues, etc.
  157.                                 $web_file = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE).$tmp_filename; // NOT canonical URL! This might fail with reverse proxies which can only be executed from outside
  158.                                 $res = url_get_contents($web_file);
  159.                                 if ($res === false) {
  160.                                         throw new OIDplusException(_L('Update-script %1 could not be executed',$web_file));
  161.                                 }
  162.                                 return array("status" => 0, "content" => $res, "rev" => $rev);
  163.                         } else if ($update_version == 2) {
  164.                                 // In this version, the client will call the web-update file.
  165.                                 // This has the advantage that it will also work if the system is htpasswd protected
  166.                                 return array("status" => 0, "update_file" => $tmp_filename, "rev" => $rev);
  167.                         } else {
  168.                                 throw new OIDplusException(_L("Unexpected update version"));
  169.                         }
  170.                 }
  171.                 else {
  172.                         throw new OIDplusException(_L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!'));
  173.                 }
  174.         }
  175.  
  176.         /**
  177.          * @param string $actionID
  178.          * @param array $params
  179.          * @return array
  180.          * @throws OIDplusException
  181.          */
  182.         public function action(string $actionID, array $params): array {
  183.                 if ($actionID == 'update_now') {
  184.                         return $this->action_Update($params);
  185.                 } else {
  186.                         return parent::action($actionID, $params);
  187.                 }
  188.         }
  189.  
  190.         /**
  191.          * @param string $id
  192.          * @param array $out
  193.          * @param bool $handled
  194.          * @return void
  195.          * @throws OIDplusException
  196.          */
  197.         public function gui(string $id, array &$out, bool &$handled) {
  198.                 if ($id == 'oidplus:software_update') {
  199.                         @set_time_limit(0);
  200.  
  201.                         $handled = true;
  202.                         $out['title'] = _L('Software update');
  203.                         $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
  204.  
  205.                         if (!OIDplus::authUtils()->isAdminLoggedIn()) {
  206.                                 throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
  207.                         }
  208.  
  209.                         $out['text'] .= '<div id="update_versioninfo">';
  210.  
  211.                         $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
  212.  
  213.                         if (isset(OIDplus::getEditionInfo()['svnrepo']) && (OIDplus::getEditionInfo()['svnrepo'] != '')) {
  214.                                 $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co %1</code> and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['svnrepo']).'/trunk/');
  215.                                 if (!str_starts_with(PHP_OS, 'WIN')) {
  216.                                         $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','svn update');
  217.                                 }
  218.                                 $out['text'] .= '</p>';
  219.                         } else {
  220.                                 $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','GIT').'</p>';
  221.                         }
  222.  
  223.                         if (isset(OIDplus::getEditionInfo()['gitrepo']) && (OIDplus::getEditionInfo()['gitrepo'] != '')) {
  224.                                 $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Install OIDplus using the Git client in your SSH/Linux shell using the command <code>git clone %1</code> and update it regularly with the command <code>git pull</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['gitrepo'].'.git'));
  225.                                 if (!str_starts_with(PHP_OS, 'WIN')) {
  226.                                         $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','git pull');
  227.                                 }
  228.                                 $out['text'] .= '</p>';
  229.                         } else {
  230.                                 $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','SVN').'</p>';
  231.                         }
  232.  
  233.                         if (isset(OIDplus::getEditionInfo()['downloadpage']) && (OIDplus::getEditionInfo()['downloadpage'] != '')) {
  234.                                 $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Install OIDplus by downloading a TAR.GZ file from %1, which contains an SVN snapshot, and extract it to your webspace. The TAR.GZ file contains a file named ".version.php" which contains the SVN revision of the snapshot. This update-tool will then try to update your files on-the-fly by downloading them from the ViaThinkSoft SVN repository directly into your webspace directory. A change conflict detection is NOT implemented. It is required that the files on your webspace have create/write/delete permissions. Only recommended if you have no access to the SSH/Linux shell.','<a href="'.OIDplus::getEditionInfo()['downloadpage'].'">'.parse_url(OIDplus::getEditionInfo()['downloadpage'])['host'].'</a>').'</p>';
  235.                         } else {
  236.                                 $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','Snapshot').'</p>';
  237.                         }
  238.  
  239.  
  240.                         $out['text'] .= '<hr>';
  241.  
  242.                         $installType = OIDplus::getInstallType();
  243.  
  244.                         if ($installType === 'ambigous') {
  245.                                 $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!').'</font>';
  246.                                 $out['text'] .= '</div>';
  247.                         } else if ($installType === 'unknown') {
  248.                                 $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
  249.                                 $out['text'] .= '</div>';
  250.                         } else if (($installType === 'svn-wc') || ($installType === 'git-wc') || ($installType === 'svn-snapshot')) {
  251.                                 if ($installType === 'svn-wc') {
  252.                                         $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
  253.                                         $requireInfo = _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension');
  254.                                         $updateCommand = $this->getSvnCommand();
  255.                                 } else if ($installType === 'git-wc') {
  256.                                         $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
  257.                                         $requireInfo = _L('shell access with Git client');
  258.                                         $updateCommand = $this->getGitCommand();
  259.                                 } else if ($installType === 'svn-snapshot') {
  260.                                         $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with .version.php file).').'</p>';
  261.                                         $requireInfo = ''; // unused
  262.                                         $updateCommand = ''; // unused
  263.                                 } else {
  264.                                         assert(false);
  265.                                 }
  266.  
  267.                                 $local_installation = OIDplus::getVersion();
  268.                                 $newest_version = $this->getLatestRevision();
  269.  
  270.                                 $out['text'] .= _L('Local installation: %1',($local_installation ?: _L('unknown'))).'<br>';
  271.                                 $out['text'] .= _L('Latest published version: %1',($newest_version ?: _L('unknown'))).'<br><br>';
  272.  
  273.                                 if (!$newest_version) {
  274.                                         if (!url_get_contents_available(true, $reason)) {
  275.                                                 $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'.$reason.'</p>';
  276.                                         } else {
  277.                                                 $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'._L('Probably the ViaThinkSoft server could not be reached.').'</font></p>';
  278.                                         }
  279.                                         $out['text'] .= '</div>';
  280.                                 } else if (!$local_installation) {
  281.                                         if ($installType === 'svn-snapshot') {
  282.                                                 $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version.').'</font></p>';
  283.                                         } else {
  284.                                                 $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version. (Required: %1). Please update your system manually via the "%2" command regularly.',$requireInfo,$updateCommand).'</font></p>';
  285.                                         }
  286.                                         $out['text'] .= '</div>';
  287.                                 } else if (version_compare($local_installation, $newest_version) >= 0) {
  288.                                         $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
  289.                                         $out['text'] .= '</div>';
  290.                                 } else {
  291.                                         if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
  292.                                                 $out['text'] .= '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>';
  293.                                                 $out['text'] .= '<p>'._L('Alternatively, click this button to execute the command through the web-interface (command execution and write permissions required).').'</p>';
  294.                                         }
  295.  
  296.                                         $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.((int)substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>';
  297.  
  298.                                         // TODO: Open "system_file_check" without page reload.
  299.                                         // TODO: Only show link if the plugin is installed
  300.                                         $out['text'] .= '<p><font color="red">'.mb_strtoupper(_L('Warning')).': '._L('Please make a backup of your files before updating. In case of an error, the OIDplus system (including this update-assistant) might become unavailable. Also, since the web-update does not contain collision-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost! (<a href="%1">Click here to check which files have been modified</a>) In case the update fails, you can download and extract the complete <a href="%s">SVN-Snapshot TAR.GZ file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.','?goto='.urlencode('oidplus:system_file_check'),OIDplus::getEditionInfo()['downloadpage']).'</font></p>';
  301.  
  302.                                         $out['text'] .= '</div>';
  303.  
  304.                                         $out['text'] .= $this->showPreview($local_installation, $newest_version);
  305.                                 }
  306.                         }
  307.                 } else {
  308.                         $handled = false;
  309.                 }
  310.         }
  311.  
  312.         /**
  313.          * @param array $json
  314.          * @param string|null $ra_email
  315.          * @param bool $nonjs
  316.          * @param string $req_goto
  317.          * @return bool
  318.          * @throws OIDplusException
  319.          */
  320.         public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
  321.                 if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
  322.  
  323.                 if (file_exists(__DIR__.'/img/main_icon16.png')) {
  324.                         $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
  325.                 } else {
  326.                         $tree_icon = null; // default icon (folder)
  327.                 }
  328.  
  329.                 $json[] = array(
  330.                         'id' => 'oidplus:software_update',
  331.                         'icon' => $tree_icon,
  332.                         'text' => _L('Software update')
  333.                 );
  334.  
  335.                 return true;
  336.         }
  337.  
  338.         /**
  339.          * @param string $request
  340.          * @return array|false
  341.          */
  342.         public function tree_search(string $request) {
  343.                 return false;
  344.         }
  345.  
  346.         /**
  347.          * @var string|null
  348.          */
  349.         private $releases_ser = null;
  350.  
  351.         /**
  352.          * @param string $local_ver
  353.          * @return false|string
  354.          */
  355.         private function showChangelog(string $local_ver) {
  356.  
  357.                 try {
  358.                         if (is_null($this->releases_ser)) {
  359.                                 if (function_exists('gzdecode')) {
  360.                                         $url = OIDplus::getEditionInfo()['revisionlog_gz'];
  361.                                         $cont = url_get_contents($url);
  362.                                         if ($cont !== false) $cont = @gzdecode($cont);
  363.                                 } else {
  364.                                         $url = OIDplus::getEditionInfo()['revisionlog'];
  365.                                         $cont = url_get_contents($url);
  366.                                 }
  367.                                 if ($cont === false) return false;
  368.                                 $this->releases_ser = $cont;
  369.                         } else {
  370.                                 $cont = $this->releases_ser;
  371.                         }
  372.                         $content = '';
  373.                         $ary = @unserialize($cont);
  374.                         if ($ary === false) return false;
  375.                         krsort($ary);
  376.                         foreach ($ary as $rev => $data) {
  377.                                 if (version_compare("svn-$rev", $local_ver) <= 0) continue;
  378.                                 $comment = empty($data['msg']) ? _L('No comment') : $data['msg'];
  379.                                 $tex = _L("New revision %1 by %2",$rev,$data['author'])." (".$data['date'].") ";
  380.                                 $content .= trim($tex . str_replace("\n", "\n".str_repeat(' ', strlen($tex)), $comment));
  381.                                 $content .= "\n";
  382.                         }
  383.                         return $content;
  384.                 } catch (\Exception $e) {
  385.                         return false;
  386.                 }
  387.  
  388.         }
  389.  
  390.         /**
  391.          * @return false|string
  392.          */
  393.         private function getLatestRevision() {
  394.                 try {
  395.                         if (is_null($this->releases_ser)) {
  396.                                 if (function_exists('gzdecode')) {
  397.                                         $url = OIDplus::getEditionInfo()['revisionlog_gz'];
  398.                                         $cont = url_get_contents($url);
  399.                                         if ($cont !== false) $cont = @gzdecode($cont);
  400.                                 } else {
  401.                                         $url = OIDplus::getEditionInfo()['revisionlog'];
  402.                                         $cont = url_get_contents($url);
  403.                                 }
  404.                                 if ($cont === false) return false;
  405.                                 $this->releases_ser = $cont;
  406.                         } else {
  407.                                 $cont = $this->releases_ser;
  408.                         }
  409.                         $ary = @unserialize($cont);
  410.                         if ($ary === false) return false;
  411.                         krsort($ary);
  412.                         $max_rev = array_keys($ary)[0];
  413.                         return 'svn-' . $max_rev;
  414.                 } catch (\Exception $e) {
  415.                         return false;
  416.                 }
  417.         }
  418.  
  419.         /**
  420.          * @param string $local_installation
  421.          * @param string $newest_version
  422.          * @return string
  423.          */
  424.         private function showPreview(string $local_installation, string $newest_version): string {
  425.                 $out = '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
  426.  
  427.                 ob_start();
  428.                 try {
  429.                         $cont = $this->showChangelog($local_installation);
  430.                 } catch (\Exception $e) {
  431.                         $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
  432.                         $cont = _L('Error: %1',$htmlmsg);
  433.                 }
  434.                 ob_end_clean();
  435.  
  436.                 $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", "$cont\n");
  437.                 $cont = preg_replace('@\\*\\*\\*(.+)\\n@', '<strong>!!!\\1</strong>'."\n", "$cont\n");
  438.  
  439.                 $out .= '<pre id="update_infobox">'.$cont.'</pre>';
  440.  
  441.                 return $out;
  442.         }
  443.  
  444.         /**
  445.          * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
  446.          * @param string|null $user
  447.          * @return array
  448.          * @throws OIDplusException
  449.          */
  450.         public function getNotifications(string $user=null): array {
  451.                 $notifications = array();
  452.                 if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
  453.  
  454.                         // Following code is based on the VNag plugin (admin 901) code
  455.  
  456.                         $installType = OIDplus::getInstallType();
  457.  
  458.                         if ($installType === 'ambigous') {
  459.                                 $out_stat = 'WARN';
  460.                                 $out_msg  = _L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!');
  461.                         } else if ($installType === 'unknown') {
  462.                                 $out_stat = 'WARN';
  463.                                 $out_msg  = _L('The version cannot be determined, and the update needs to be applied manually!');
  464.                         } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
  465.                                 if (!url_get_contents_available(true, $reason)) {
  466.                                         $out_stat = 'WARN';
  467.                                         $out_msg  = _L('OIDplus could not determine the latest version.').' '.$reason;
  468.                                 } else {
  469.                                         $local_installation = OIDplus::getVersion();
  470.                                         $newest_version = $this->getLatestRevision();
  471.  
  472.                                         $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
  473.                                         $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
  474.  
  475.                                         if (!$newest_version) {
  476.                                                 $out_stat = 'WARN';
  477.                                                 $out_msg = _L('OIDplus could not determine the latest version.') . ' ' . _L('Probably the ViaThinkSoft server could not be reached.');
  478.                                         } else if (!$local_installation) {
  479.                                                 $out_stat = 'WARN';
  480.                                                 $out_msg = _L('OIDplus could not determine its version (Required: %1). Please update your system manually via the "%2" command regularly.', $requireInfo, $updateCommand);
  481.                                         } else if (version_compare($local_installation, $newest_version) >= 0) {
  482.                                                 $out_stat = 'INFO';
  483.                                                 $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
  484.                                         } else {
  485.                                                 $out_stat = 'WARN';
  486.                                                 $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
  487.                                         }
  488.                                 }
  489.                         } else if ($installType === 'svn-snapshot') {
  490.                                 if (!url_get_contents_available(true, $reason)) {
  491.                                         $out_stat = 'WARN';
  492.                                         $out_msg  = _L('OIDplus could not determine the latest version.').' '.$reason;
  493.                                 } else {
  494.                                         $local_installation = OIDplus::getVersion();
  495.                                         $newest_version = $this->getLatestRevision();
  496.  
  497.                                         if (!$newest_version) {
  498.                                                 $out_stat = 'WARN';
  499.                                                 $out_msg = _L('OIDplus could not determine the latest version.') . ' ' . _L('Probably the ViaThinkSoft server could not be reached.');
  500.                                         } else if (!$local_installation) {
  501.                                                 $out_stat = 'WARN';
  502.                                                 $out_msg = _L('OIDplus could not determine its version. Please update your system manually by downloading the latest archive file from oidplus.com.');
  503.                                         } else if (version_compare($local_installation, $newest_version) >= 0) {
  504.                                                 $out_stat = 'INFO';
  505.                                                 $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
  506.                                         } else {
  507.                                                 $out_stat = 'WARN';
  508.                                                 $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
  509.                                         }
  510.                                 }
  511.                         } else {
  512.                                 assert(false);
  513.                                 return $notifications;
  514.                         }
  515.  
  516.                         if ($out_stat != 'INFO') {
  517.                                 $out_msg = '<a '.OIDplus::gui()->link('oidplus:software_update').'>'._L('Software update').'</a>: ' . $out_msg;
  518.  
  519.                                 $notifications[] = new OIDplusNotification($out_stat, $out_msg);
  520.                         }
  521.  
  522.                 }
  523.                 return $notifications;
  524.         }
  525.  
  526. }
  527.