Simple Groupware PHP Cross Reference Groupware Applications

Source: /src/updater.php - 255 lines - 11211 bytes - Summary - Text - Print

   1  <?php
   2      /**************************************************************************\
   3      * Simple Groupware 0.743                                                   *
   4      * http://www.simple-groupware.de                                           *
   5      * Copyright (C) 2002-2012 by Thomas Bley                                   *
   6      * ------------------------------------------------------------------------ *
   7      *  This program is free software; you can redistribute it and/or           *
   8      *  modify it under the terms of the GNU General Public License Version 2   *
   9      *  as published by the Free Software Foundation; only version 2            *
  10      *  of the License, no later version.                                       *
  11      *                                                                          *
  12      *  This program is distributed in the hope that it will be useful,         *
  13      *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  14      *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
  15      *  GNU General Public License for more details.                            *
  16      *                                                                          *
  17      *  You should have received a copy of the GNU General Public License       *
  18      *  Version 2 along with this program; if not, write to the Free Software   *
  19      *  Foundation, Inc., 59 Temple Place - Suite 330, Boston,                  *
  20      *  MA  02111-1307, USA.                                                    *
  21      \**************************************************************************/
  22  
  23  define("NOCONTENT",true);
  24  
  25  require ("index.php");
  26  @set_time_limit(1800);
  27  
  28  if (!sys_is_super_admin($_SESSION["username"])) sys_die("{t}Not allowed. Please log in as super administrator.{/t}");
  29  
  30  setup::out('
  31  <html>
  32  <head>
  33  <title>Simple Groupware</title>
  34  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  35  <style>
  36    body, h2, img, div, table.data, a {
  37      background-color: #FFFFFF; color: #666666; font-size: 13px; font-family: Arial, Helvetica, Verdana, sans-serif;
  38    }
  39    a,input { color: #0000FF; }
  40    input {
  41      font-size: 11px; background-color: #F5F5F5; border: 1px solid #AAAAAA; height: 18px;
  42      vertical-align: middle; padding-left: 5px; padding-right: 5px; border-radius: 10px;
  43    }
  44    .checkbox { border: 0px; background-color: transparent; }
  45    .submit { color: #0000FF; background-color: #FFFFFF; width: 125px; font-weight: bold; }
  46    .border {
  47      border-bottom: 1px solid black;
  48    }
  49    .headline {
  50      letter-spacing: 2px;
  51      font-size: 18px;
  52      font-weight: bold;
  53    }
  54  </style>
  55  <script>
  56  function change_links(nobackup) {
  57    var objs = document.getElementsByTagName("a");
  58    for (var i=0; i<objs.length; i++) {
  59      objs[i].href = objs[i].href.replace("updater.php?nobackup=1&","updater.php?");
  60      if (nobackup) {
  61        objs[i].href = objs[i].href.replace("updater.php?","updater.php?nobackup=1&");
  62  } } }
  63  </script>
  64  </head>
  65  <body>
  66  <div class="border headline">Simple Groupware '.CORE_VERSION_STRING.'</div>
  67  ');
  68  setup::out("<a href='index.php'>{t}Back{/t}</a><br>");
  69  
  70  $mirrors = array(
  71    "sourceforge" => array(
  72      "name" => "Sourceforge.net",
  73      "url" => "http://sourceforge.net/export/rss2_projnews.php?group_id=96330",
  74      "pattern" => "!<title>simple groupware ([^ ]+) released.*?</title>.*?<pubdate>([^<]+)!msi",
  75      "source" => "http://sourceforge.net/projects/simplgroup/files/simplegroupware/%s/SimpleGroupware_%s.tar.gz",
  76    ),
  77    "google" => array(
  78      "name" => "Google Code",
  79      "url" => "http://code.google.com/feeds/p/simplegroupware/downloads/basic",
  80      "pattern" => "!simplegroupware_(.+?)\.tar\.gz.+?<updated>([^<]+)!msi",
  81      "source" => "http://simplegroupware.googlecode.com/files/SimpleGroupware_%s.tar.gz",
  82    ),
  83  );
  84  
  85  $mirror_id = "sourceforge";
  86  if (!empty($_REQUEST["mirror"]) and in_array($_REQUEST["mirror"],array_keys($mirrors))) $mirror_id = $_REQUEST["mirror"];
  87  $mirror = $mirrors[$mirror_id];
  88  
  89  $folders = array("../","../old/","../docs/","../lang/","../import/","../src/","../bin/");
  90  foreach ($folders as $folder) {
  91    if (!is_writable($folder)) setup::out_exit(sprintf("[1] {t}Please give write access to %s{/t}",$folder));
  92  }
  93  if ((empty($_REQUEST["release"]) and empty($_REQUEST["cfile"])) or !sys_validate_token()) {
  94    setup::out("
  95      <div style='color:#ff0000;'>
  96      <b>{t}Warning{/t}</b>:<br>
  97      - Please make a complete backup of your database (e.g. using phpMyAdmin)<br>
  98      - Please make a complete backup of your sgs folder (e.g. /var/www/htdocs/sgs/)<br>
  99      - Make sure both backups are complete!
 100      </div>
 101    ");
 102  
 103    setup::out("{t}Downloading update list{/t} ...<br>");
 104  
 105    $ctx = stream_context_create(array("http" => array("timeout" => 5))); 
 106    $data = @file_get_contents($mirror["url"],0,$ctx);
 107    preg_match_all($mirror["pattern"], $data, $match);
 108  
 109    if (!empty($match[1]) and $data!="") {
 110        $found = false;
 111      foreach ($match[1] as $key=>$item) {
 112        if ($key > 4) break;
 113        if (strpos("@".$item, CORE_VERSION_STRING) and !DEBUG) break;
 114        if (!empty($match[3][$key]) and strtotime($match[3][$key])+3600 > time()) continue;
 115        $found = true;
 116        $check = true;
 117        
 118        if (!empty($match[2][$key])) {
 119          preg_match("/php (\d+\.\d+\.\d+)/i", $match[2][$key], $match_version);
 120          if (!empty($match_version[1]) and version_compare(PHP_VERSION, $match_version[1], "<")) {
 121            setup::out(sprintf("{t}Setup needs php with at least version %s !{/t}", $match_version[1]));
 122            $check = false;
 123          }
 124          preg_match("/".SETUP_DB_TYPE." (\d+\.\d+\.\d+)/i", $match[2][$key], $match_version);
 125          if (!empty($match_version[1])) {
 126            $db_version = str_replace(".","",$match_version[1]);
 127            $curr_version = sgsml_parser::sql_version();
 128            if ($curr_version < $db_version) {
 129              setup::out(sprintf("{t}Wrong database-version (%s). Please use at least %s !{/t}", $curr_version, $match_version[1]));
 130              $check = false;
 131        } } }
 132        if ($check) {
 133          setup::out("<a href='updater.php?mirror=".$mirror_id."&token=".modify::get_form_token()."&release=".$item."'>{t}I n s t a l l{/t}</a>&nbsp; Simple Groupware ", false);
 134          setup::out($item." (<a target='_blank' href='http://www.simple-groupware.de/cms/Release-".str_replace(".","-",$item)."'>Changelog</a>)<br>");
 135        }
 136      }
 137      if (!$found) setup::out("{t}Already running latest release.{/t}<br>");
 138    } else {
 139      setup::out(sprintf("{t}Connection error: %s [%s]{/t}", $mirror["url"], "HTTP")."<br>".strip_tags($data,"<br><p><h1><center>"));
 140    }
 141  
 142    setup::out("{t}Server{/t}: <b>".$mirror["name"]."</b>, {t}use mirror from{/t}: ", false);
 143    foreach ($mirrors as $key => $sel_mirror) {
 144      if ($key==$mirror_id) continue;
 145      setup::out("<a href='updater.php?mirror=".$key."'>".$sel_mirror["name"]."</a> ");
 146    }
 147  
 148    setup::out("<br/>{t}Package from local file system (.tar.gz){/t}:<br/>{t}current path{/t}: ".str_replace("\\","/",getcwd())."/<br/>");
 149  
 150    $dir = opendir("./");
 151    while (($file=readdir($dir))) {
 152      if ($file!="." and $file!=".." and preg_match("|^SimpleGroupware\_.*?.tar\.gz\$|i",$file)) {
 153        setup::out("<a href='updater.php?token=".modify::get_form_token()."&cfile=".$file."'>{t}I n s t a l l{/t}</a>&nbsp; ".$file."<br/>");
 154      }
 155    }
 156    closedir($dir);
 157  
 158    setup::out("<form method='POST'><input type='hidden' name='token' value='".modify::get_form_token()."'><input type='text' name='cfile' value='/tmp/SimpleGroupware_0.xyz.tar.gz' style='width:300px;'>&nbsp;<input type='submit' class='submit' value='{t}I n s t a l l{/t}'><br>");
 159  
 160    setup::out("<input type='checkbox' name='nobackup' value='1' onchange='change_links(this.checked);'/> {t}Don't move old files to 'old/'{/t}</form>");
 161    setup::out_exit('<div style="border-top: 1px solid black;">Powered by Simple Groupware, Copyright (C) 2002-2012 by Thomas Bley.</div></div></body></html>');
 162  } else if (!empty($_REQUEST["cfile"])) {
 163    $source = $_REQUEST["cfile"];
 164    if (!file_exists($source) or filesize($source) < 3*1024*1024) sys_die("{t}Error{/t}: file-check [0] ".$source);
 165  } else {
 166    $release = "latest";
 167    if ($release=="latest" or !is_numeric($_REQUEST["release"])) {
 168      $data = @file_get_contents($mirror["url"]);
 169      if ($data!="") preg_match($mirror["pattern"], $data, $match);
 170      if (!empty($match[1])) $release = $match[1];
 171    }
 172    $source = sprintf($mirror["source"], $release, $release);
 173  }
 174  
 175  $temp_folder = SIMPLE_CACHE."/updater/";
 176  sys_mkdir($temp_folder);
 177  $target = $temp_folder.substr(basename($source),0,-3);
 178  
 179  setup::out("{t}Download{/t}: ".$source." ...");
 180  if ($fz = gzopen($source,"r") and $fp = fopen($target,"w")) {
 181    $i = 0;
 182    while (!gzeof($fz)) {
 183      $i++;
 184      setup::out(".",false);
 185      if ($i%160==0) setup::out();
 186      fwrite($fp,gzread($fz, 16384));
 187    }
 188    gzclose($fz);
 189    fclose($fp);
 190  } else sys_die("{t}Error{/t}: gzopen [1] ".$source);
 191  
 192  setup::out();
 193  if (!file_exists($target) or filesize($target) < 5*1024*1024) sys_die("{t}Error{/t}: file-check [2] Filesize: ".filesize($target)." ".$target);
 194  
 195  setup::out(sprintf("{t}Processing %s ...{/t}",basename($target)));
 196  require ("lib/tar/Tar.php");
 197  
 198  $tar_object = new Archive_Tar($target);
 199  $tar_object->setErrorHandling(PEAR_ERROR_PRINT);
 200  $tar_object->extract($temp_folder);
 201  
 202  $file_list = $tar_object->ListContent();
 203  if (!is_array($file_list) or !isset($file_list[0]["filename"]) or !is_dir($temp_folder.$file_list[0]["filename"])) {
 204    sys_die("{t}Error{/t}: tar [3] ".$target);
 205  }
 206  foreach ($file_list as $file) sys_chmod($temp_folder.$file["filename"]);
 207  @unlink($target);
 208  
 209  chdir("../old/");
 210  
 211  $base = "../";
 212  setup::out(sprintf("{t}Processing %s ...{/t}","{t}Folders{/t}"));
 213  $folders = array("src","bin","lang","import","docs");
 214  foreach ($folders as $folder) {
 215    if (file_exists($base.$folder."/") and !file_exists($base."old/".$folder."_".CORE_VERSION."/")) {
 216      if (!empty($_REQUEST["nobackup"])) {
 217        dirs_delete_all($base.$folder."/");
 218      } else {
 219        rename($base.$folder."/",$base."old/".$folder."_".CORE_VERSION."/");
 220  } } }
 221  if (is_dir($base."src/") or is_dir($base."bin/")) sys_die("{t}Error{/t}: rename [4]");
 222  
 223  $source_folder = $temp_folder.$file_list[0]["filename"];
 224  foreach ($folders as $folder) {
 225    if (is_dir($source_folder.$folder."/") and !is_dir($base.$folder."/")) {
 226      rename($source_folder.$folder."/",$base.$folder."/");
 227    }
 228  }
 229  if (!is_dir($base."src/") or !is_dir($base."bin/")) sys_die("{t}Error{/t}: rename [5]");
 230  
 231  dirs_delete_all($source_folder);
 232  
 233  setup::out(sprintf("{t}Processing %s ...{/t}","config.php"));
 234  
 235  $old = SIMPLE_STORE."/config_old.php";
 236  if (file_exists($old)) rename($old,SIMPLE_STORE."/config_".time().".php");
 237  rename(SIMPLE_STORE."/config.php",$old);
 238  touch($old);
 239  
 240  setup::out(sprintf("{t}Processing %s ...{/t}","{t}translations{/t}"));
 241  setup::build_trans(SETUP_LANGUAGE,"../src/","../bin/");
 242  
 243  chdir("../bin/");
 244  setup::out(sprintf("{t}Processing %s ...{/t}","{t}customizations{/t}"));
 245  setup::build_customizing(SIMPLE_CUSTOM."customize.php");
 246  
 247  $dir = opendir(SIMPLE_EXT);
 248  while (($file=readdir($dir))) {
 249    if ($file!="." and $file!=".." and file_exists(SIMPLE_EXT.$file."/update.php")) {
 250      setup::out(sprintf("{t}Processing %s ...{/t}",SIMPLE_EXT.$file."/update.php"));
 251      require(SIMPLE_EXT.$file."/update.php");
 252    }
 253  }
 254  setup::out("<br><a href='index.php'>{t}C O N T I N U E{/t}</a><finished>");
 255  setup::out('<br><div style="border-top: 1px solid black;">Powered by Simple Groupware, Copyright (C) 2002-2012 by Thomas Bley.</div></div></body></html>');

title

Description

title

Description

title

Description

title

title

Body