diff --git a/lib/common.class.php b/lib/common.class.php index 7eca7a5a6..b66f0ac8c 100644 --- a/lib/common.class.php +++ b/lib/common.class.php @@ -990,17 +990,15 @@ function checkAccess($object_type, $object_id) function registerError($code = 'custom', $details = '') { - DebMes("Error registered (type: $code): ".$details); + $e = new \Exception; + $backtrace=$e->getTraceAsString(); + + DebMes("Error registered (type: $code):\n".$details."\nBacktrace:\n".$backtrace,'error'); $code = trim($code); if ($code == 'sql') { return 0; } - - if (!$code) - { - $code = 'custom'; - } $error_rec = SQLSelectOne("SELECT * FROM system_errors WHERE CODE LIKE '" . DBSafe($code) . "'"); @@ -1012,13 +1010,12 @@ function registerError($code = 'custom', $details = '') } $error_rec['LATEST_UPDATE'] = date('Y-m-d H:i:s'); - $error_rec['ACTIVE'] = (int)$error_rec['ACTIVE'] + 1; + @$error_rec['ACTIVE'] = (int)$error_rec['ACTIVE'] + 1; SQLUpdate('system_errors', $error_rec); $history_rec = array(); - $history_rec['ERROR_ID'] = $error_rec['ID']; - $history_rec['COMMENTS'] = $details; + $history_rec['COMMENTS'] = $details."\nBacktrace:\n".$backtrace; $history_rec['ADDED'] = $error_rec['LATEST_UPDATE']; //Temporary disabled @@ -1031,7 +1028,6 @@ function registerError($code = 'custom', $details = '') $history_rec['EVENTS_DATA'] = getURL($xrayUrl . 'events', 0); $history_rec['DEBUG_DATA'] = getURL($xrayUrl . 'debmes', 0); */ - $history_rec['ID'] = SQLInsert('system_errors_data', $history_rec); if (!$error_rec['KEEP_HISTORY']) diff --git a/lib/errors.class.php b/lib/errors.class.php index 583d5ced7..318e6db77 100644 --- a/lib/errors.class.php +++ b/lib/errors.class.php @@ -39,67 +39,49 @@ class custom_error * @param int $short Short (default 0) * @return void */ - public function __construct($description, $stop = 0, $short = 0) + public function __construct($description, $stop = 0) { $script = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; - $description = $script . "\nError:\n" . $description; - //$log = getLogger($this); - //$log->error($description); - //$backtrace=debug_backtrace(); - //print_r($backtrace);exit; - DebMes($description.' ('.__FILE__.')'); - - if (defined("DEBUG_MODE")) - { - if (!$short) - { - $this->alert(nl2br($description)); - } - else - { - echo nl2br($description); - } + if (!mb_detect_encoding($description, 'UTF-8', true)) { + $description = iconv('windows-1251','UTF-8',$description); } - else - { - if (!$short) - { - $this->alert(""); - } - else - { - echo "Warning...
"; - } + + $e = new \Exception; + if (defined("DEBUG_MODE")) { + $content=<< + + Error + + + + + + + + +
+

Error

+

Details

+
$script
$description
+

Backtrace

+
{$e->getTraceAsString()}
+
+ <<< Back + Reload page + Go to Backup section +
+
+ + +FF; + echo $content; } - - sendmail("errors@" . PROJECT_DOMAIN, PROJECT_BUGTRACK, "Error reporting: $script", $description); - + //sendmail("errors@" . PROJECT_DOMAIN, PROJECT_BUGTRACK, "Error reporting: $script", $description); if ($stop) exit; } - /** - * Error processing - * used to show and log error/warning message - * - * @access private - * - * @param string $description error description - * @return void - */ - public function alert($description) - { - echo ""; - echo " 
"; - echo ""; - echo ""; - echo ""; - echo "
"; - echo "

Sorry, page is temporary unavailable.
"; - echo "
Please try again later.

"; - echo "

<<< Back to previous page

"; - echo "

$description

"; - } } /** diff --git a/lib/module.class.php b/lib/module.class.php index 54cdf2cbc..cece6b586 100644 --- a/lib/module.class.php +++ b/lib/module.class.php @@ -540,8 +540,10 @@ public function dbInstall($data) SQLExec($sql); $result = SQLGetFields($table); - foreach($result as $row) { - $tbl_fields[$table][$row['Field']]=1; + if (is_array($result)) { + foreach($result as $row) { + $tbl_fields[$table][$row['Field']]=1; + } } } diff --git a/lib/mysqli.class.php b/lib/mysqli.class.php index d9b4a856c..992dd2e61 100644 --- a/lib/mysqli.class.php +++ b/lib/mysqli.class.php @@ -78,6 +78,9 @@ class mysql */ var $pingTimeout; + + public $connected; + /** * MySQL constructor @@ -111,17 +114,36 @@ public function __construct($host, $port, $user, $password, $database) public function Connect() { // connects to database + + /*if (preg_match('/firefox/is',$_SERVER['HTTP_USER_AGENT'])) { + $this->host='127.0.0.3'; + } + */ + if ($this->port) { - $this->dbh = mysqli_connect(''.$this->host . ":" . $this->port, $this->user, $this->password); + $this->dbh = @mysqli_connect(''.$this->host . ":" . $this->port, $this->user, $this->password); } else { - $this->dbh = mysqli_connect(''.$this->host , $this->user, $this->password); + $this->dbh = @mysqli_connect(''.$this->host , $this->user, $this->password); + } + + $this->connected = false; + + if (!$this->dbh) { + $err_no = mysqli_connect_errno(); + $err_details = mysqli_connect_error(); + Define('NO_DATABASE_CONNECTION',1); + registerError('sqlconn', $err_no . ": " . $err_details); + //new custom_error($err_no . ": " . $err_details, 1); + return 0; } $db_select = mysqli_select_db($this->dbh, $this->dbName); - if (!$db_select) { - $this->Error(); + if (!$db_select) { + Define('NO_DATABASE_CONNECTION',1); + $this->Error("Selecting db: ".$this->dbName, 0); return 0; } else { + $this->connected = true; $this->latestTransaction=time(); $this->Exec("SET NAMES 'utf8';"); $this->Exec("SET CHARACTER SET 'utf8';"); @@ -142,6 +164,7 @@ public function Connect() public function Exec($query) { + if (!$this->connected) return false; if ((time()-$this->latestTransaction)>$this->pingTimeout) { $this->Ping(); } @@ -175,7 +198,7 @@ public function Exec($query) */ public function Select($query) { - + if (!$this->connected) return false; $res = array(); if ($result = $this->Exec($query)) @@ -204,6 +227,7 @@ public function Select($query) */ public function SelectOne($query) { + if (!$this->connected) return false; if ($result = $this->Exec($query)) { $rec = mysqli_fetch_array($result, MYSQL_ASSOC); @@ -219,8 +243,6 @@ public function SelectOne($query) public function Ping() { - - //DebMes("mysqli db ping"); $test_query = "SHOW TABLES FROM ".$this->dbName; $result = @mysqli_query($this->dbh, $test_query); $tblCnt = 0; @@ -252,6 +274,7 @@ public function Ping() */ public function Update($table, $data, $ndx = "ID") { + if (!$this->connected) return false; $qry = "UPDATE `$table` SET "; foreach ($data as $field => $value) @@ -293,9 +316,9 @@ public function Update($table, $data, $ndx = "ID") */ public function Insert($table, &$data) { + if (!$this->connected) return false; $fields = ""; $values = ""; - foreach ($data as $field => $value) { if (is_Numeric($field)) continue; @@ -325,6 +348,7 @@ public function Insert($table, &$data) */ public function Disconnect() { + if (!$this->connected) return false; mysqli_close($this->dbh); } @@ -337,6 +361,7 @@ public function Disconnect() */ public function DbSafe($str) { + if (!$this->connected) return $str; $str = mysqli_real_escape_string($this->dbh, $str); $str = str_replace("%", "\%", $str); return $str; @@ -364,10 +389,8 @@ public function DbSafe1($str) * @access private * @return int */ - public function Error($query = "") + public function Error($query = "", $stop = 1) { - - $err_no = mysqli_errno($this->dbh); $err_details = mysqli_error($this->dbh); if (preg_match('/Unknown column/is',$err_details)) { @@ -375,8 +398,7 @@ public function Error($query = "") //header("Location:".ROOTHTML);exit; } registerError('sql', $err_no . ": " . $err_details . "\n$query"); - new custom_error($err_no . ": " . $err_details . "
$query", 1); - + new custom_error($err_no . ": " . $err_details . "
$query", $stop); return 1; } @@ -472,7 +494,11 @@ function SQLExec($query) function DbSafe($in) { global $db; - return $db->DbSafe($in); + if (is_object($db)) { + return $db->DbSafe($in); + } else { + return $in; + } } /** @@ -487,7 +513,11 @@ function DbSafe($in) function SQLSelect($query) { global $db; - return $db->Select($query); + if (is_object($db)) { + return $db->Select($query); + } else { + return false; + } } /** @@ -502,7 +532,11 @@ function SQLSelect($query) function SQLSelectOne($query) { global $db; - return $db->SelectOne($query); + if (is_object($db)) { + return $db->SelectOne($query); + } else { + return false; + } } /** @@ -518,7 +552,11 @@ function SQLSelectOne($query) function SQLInsert($table, &$record) { global $db; - return $db->Insert($table, $record); + if (is_object($db)) { + return $db->Insert($table, $record); + } else { + return false; + } } /** @@ -531,7 +569,11 @@ function SQLInsert($table, &$record) function SQLUpdate($table, $record, $ndx = 'ID') { global $db; - return $db->Update($table, $record, $ndx); + if (is_object($db)) { + return $db->Update($table, $record, $ndx); + } else { + return false; + } } /** @@ -551,11 +593,19 @@ function SQLUpdateInsert($table, &$record, $ndx = 'ID') if (isset($record[$ndx])) { - return $db->Update($table, $record, $ndx); + if (is_object($db)) { + return $db->Update($table, $record, $ndx); + } else { + return false; + } } else { - $record[$ndx] = $db->Insert($table, $record); + if (is_object($db)) { + $record[$ndx] = $db->Insert($table, $record); + } else { + return false; + } return $record[$ndx]; } } @@ -585,6 +635,10 @@ function SQLInsertUpdate($table, &$record, $ndx = 'ID') * @access public */ function SQLGetFields($table) { + global $db; + if (!is_object($db) || !$db->connected) { + return false; + } $result = SQLExec("SHOW FIELDS FROM $table"); $res=array(); while ($rec = mysqli_fetch_array($result, MYSQL_ASSOC)) @@ -606,7 +660,11 @@ function SQLGetIndexes($table) { function SQLPing() { global $db; - return $db->Ping(); + if (is_object($db)) { + return $db->Ping(); + } else { + return false; + } } diff --git a/lib/threads.php b/lib/threads.php index 566bfaf82..a4ab691a5 100644 --- a/lib/threads.php +++ b/lib/threads.php @@ -46,7 +46,8 @@ public function newThread($filename, $params = array()) { if (!file_exists($filename)) { - throw new ThreadsException('FILE_NOT_FOUND'); + DebMes("Cannot start thread '$filename' -- FILE NOT FOUND"); + return false; } $params = addcslashes(serialize($params), '"'); @@ -93,8 +94,10 @@ public function newXThread($filename, $display = '101', $params = array()) if (IsWindowsOS()) throw new ThreadsException('FOR_LINUX_ONLY'); - if (!file_exists($filename)) - throw new ThreadsException('FILE_NOT_FOUND'); + if (!file_exists($filename)) { + DebMes("Cannot start thread '$filename' -- FILE NOT FOUND"); + return false; + } $params = addcslashes(serialize($params), '"'); $command = 'DISPLAY=:' . $display . ' ' . $this->phpPath . ' ' . $filename . ' --params "' . $params . '"'; diff --git a/load_settings.php b/load_settings.php index 1246b662f..0e513e738 100644 --- a/load_settings.php +++ b/load_settings.php @@ -18,18 +18,23 @@ for ($i = 0; $i < $total; $i ++) Define('SETTINGS_' . $settings[$i]['NAME'], $settings[$i]['VALUE']); +if (!defined('SETTINGS_SITE_LANGUAGE')) { + Define('SETTINGS_SITE_LANGUAGE','en'); +} + // language selection by settings if (SETTINGS_SITE_LANGUAGE && file_exists(ROOT . 'languages/' . SETTINGS_SITE_LANGUAGE . '.php')) include_once (ROOT . 'languages/' . SETTINGS_SITE_LANGUAGE . '.php'); include_once (ROOT . 'languages/default.php'); -if (defined('SETTINGS_SITE_TIMEZONE')) -{ - ini_set('date.timezone', SETTINGS_SITE_TIMEZONE); - date_default_timezone_set(SETTINGS_SITE_TIMEZONE); +if (!defined('SETTINGS_SITE_TIMEZONE')) { + Define('SETTINGS_SITE_TIMEZONE','Europe/Minsk'); } +ini_set('date.timezone', SETTINGS_SITE_TIMEZONE); +date_default_timezone_set(SETTINGS_SITE_TIMEZONE); + function timezone_offset_string( $offset ) { return sprintf( "%s%02d:%02d", ( $offset >= 0 ) ? '+' : '-', abs( $offset / 3600 ), abs( $offset % 3600 ) ); @@ -39,7 +44,12 @@ function timezone_offset_string( $offset ) SQLExec("SET time_zone = '".$offset_text."';"); -if (($_SERVER['REQUEST_METHOD']=='GET' || $_SERVER['REQUEST_METHOD']=='POST') && defined('WAIT_FOR_MAIN_CYCLE') && WAIT_FOR_MAIN_CYCLE==1 && !preg_match('/clear_all_history\.php/', $_SERVER['REQUEST_URI'])) { +if (($_SERVER['REQUEST_METHOD']=='GET' || $_SERVER['REQUEST_METHOD']=='POST') && + defined('WAIT_FOR_MAIN_CYCLE') && + WAIT_FOR_MAIN_CYCLE==1 && + !preg_match('/clear_all_history\.php/', $_SERVER['REQUEST_URI']) && + !defined('NO_DATABASE_CONNECTION')) +{ $maincycleUpdate=getGlobal('cycle_mainRun'); if ((time()-$maincycleUpdate)>60) { //main cycle is offline echo "Main cycle is down. Please check background processes status."; diff --git a/modules/control_access/control_access.class.php b/modules/control_access/control_access.class.php index 1e7f65a83..6ce471b28 100644 --- a/modules/control_access/control_access.class.php +++ b/modules/control_access/control_access.class.php @@ -320,6 +320,10 @@ function run() { // -------------------------------------------------------------------- function checkAccess($action = "", $log = 0) { + + if (defined('NO_DATABASE_CONNECTION')) { + return 1; + } global $session; if ($session->data['USER_ID'] == 1) diff --git a/modules/control_modules/control_modules.class.php b/modules/control_modules/control_modules.class.php index 0741b96cf..1880a6d5f 100644 --- a/modules/control_modules/control_modules.class.php +++ b/modules/control_modules/control_modules.class.php @@ -181,6 +181,11 @@ function install($parent_name = "") { parent::install($parent_name); + global $db; + if (!is_object($db) || !$db->connected) { + return false; + } + $this->getModulesList(); $lst = $this->modules; diff --git a/modules/panel.class.php b/modules/panel.class.php index 1cd1228d3..caae54d7d 100644 --- a/modules/panel.class.php +++ b/modules/panel.class.php @@ -41,6 +41,12 @@ function run() Define('ALTERNATIVE_TEMPLATES', 'templates_alt'); global $action; + + if (defined('NO_DATABASE_CONNECTION')) { + if (!$action) $action = 'saverestore'; + $this->print = 1; + } + if (!$this->action && $action) { $this->action = $action; } @@ -81,7 +87,7 @@ function run() } } - if (IsSet($session->data["AUTHORIZED"])) { + if (IsSet($session->data["AUTHORIZED"]) || defined('NO_DATABASE_CONNECTION')) { $this->authorized = 1; } else { $tmp = SQLSelectOne("SELECT ID FROM users WHERE IS_ADMIN=1"); diff --git a/modules/saverestore/saverestore.class.php b/modules/saverestore/saverestore.class.php index 770d6b1bd..df1f61645 100644 --- a/modules/saverestore/saverestore.class.php +++ b/modules/saverestore/saverestore.class.php @@ -1,1750 +1,1804 @@ http://smartliving.ru/ -* @version 0.6 (2010-08-30) WINDOWS ONLY! -*/ + * я┐╜я┐╜я┐╜я┐╜я┐╜я┐╜я┐╜я┐╜я┐╜я┐╜ + * + * Saverestore + * + * @package MajorDoMo + * @author Serge Dzheigalo http://smartliving.ru/ + * @version 0.6 (2010-08-30) WINDOWS ONLY! + */ // // Define('UPDATER_URL', 'http://updates.au78.com/updates/'); -class saverestore extends module { -/** -* saverestore -* -* Module class constructor -* -* @access private -*/ -function saverestore() { - $this->name="saverestore"; - $this->title="<#LANG_MODULE_SAVERESTORE#>"; - $this->module_category="<#LANG_SECTION_SYSTEM#>"; - $this->checkInstalled(); -} -/** -* saveParams -* -* Saving module parameters -* -* @access public -*/ -function saveParams($data=1) { - $data=array(); - if (IsSet($this->id)) { - $data["id"]=$this->id; - } - if (IsSet($this->view_mode)) { - $data["view_mode"]=$this->view_mode; - } - if (IsSet($this->edit_mode)) { - $data["edit_mode"]=$this->edit_mode; - } - if (IsSet($this->tab)) { - $data["tab"]=$this->tab; - } - return parent::saveParams($data); -} -/** -* getParams -* -* Getting module parameters from query string -* -* @access public -*/ -function getParams() { - global $id; - global $mode; - global $view_mode; - global $edit_mode; - global $tab; - if (isset($id)) { - $this->id=$id; - } - if (isset($mode)) { - $this->mode=$mode; - } - if (isset($view_mode)) { - $this->view_mode=$view_mode; - } - if (isset($edit_mode)) { - $this->edit_mode=$edit_mode; - } - if (isset($tab)) { - $this->tab=$tab; - } -} -/** -* Run -* -* Description -* -* @access public -*/ -function run() { - global $session; - $out=array(); - if ($this->action=='admin') { - $this->admin($out); - } else { - $this->usual($out); - } - if (IsSet($this->owner->action)) { - $out['PARENT_ACTION']=$this->owner->action; - } - if (IsSet($this->owner->name)) { - $out['PARENT_NAME']=$this->owner->name; - } - $out['VIEW_MODE']=$this->view_mode; - $out['EDIT_MODE']=$this->edit_mode; - $out['MODE']=$this->mode; - $out['ACTION']=$this->action; - if ($this->single_rec) { - $out['SINGLE_REC']=1; - } - $this->data=$out; - $p=new parser(DIR_TEMPLATES.$this->name."/".$this->name.".html", $this->data, $this); - $this->result=$p->result; -} -/** -* BackEnd -* -* Module backend -* -* @access public -*/ -function admin(&$out) { - - - global $err_msg; - if ($err_msg) { - $out['ERR_MSG']=$err_msg; - } - global $ok_msg; - if ($ok_msg) { - $out['OK_MSG']=$ok_msg; - } - - $this->getConfig(); - - if (is_dir(ROOT.'saverestore/temp')) { - $out['CLEAR_FIRST']=1; - } - - - $this->getConfig(); - - if (defined('MASTER_UPDATE_URL') && MASTER_UPDATE_URL!='') { - $github_feed_url=MASTER_UPDATE_URL; - $github_feed_url=str_replace('/archive/','/commits/',$github_feed_url); - $github_feed_url=str_replace('.tar.gz','.atom',$github_feed_url); - } else { - $github_feed_url='https://github.com/sergejey/majordomo/commits/master.atom'; - } - $github_feed=getURL($github_feed_url, 30*60); - - if ($github_feed!='') { - @$tmp=GetXMLTree($github_feed); - @$data=XMLTreeToArray($tmp); - @$items=$data['feed']['entry']; - if (is_array($items)) { - $total=count($items); - if ($total) { - if ($total>5) { - $total=5; +class saverestore extends module +{ + /** + * saverestore + * + * Module class constructor + * + * @access private + */ + function saverestore() + { + $this->name = "saverestore"; + $this->title = "<#LANG_MODULE_SAVERESTORE#>"; + $this->module_category = "<#LANG_SECTION_SYSTEM#>"; + $this->checkInstalled(); } - //print_r($items);exit; - for($i=0;$i<$total;$i++) { - $itm=array(); - $itm['ID']=trim($items[$i]['id']['textvalue']); - $itm['ID']=preg_replace('/.+Commit\//is', '', $itm['ID']); - $itm['TITLE']=trim($items[$i]['title']['textvalue']); - $itm['AUTHOR']=$items[$i]['author']['name']['textvalue']; - $itm['LINK']=$items[$i]['link']['href']; - $itm['UPDATED']=strtotime($items[$i]['updated']['textvalue']); - $itm['UPDATE_TEXT']=date('m/d/Y H:i', $itm['UPDATED']); - $out['UPDATES'][]=$itm; + + /** + * saveParams + * + * Saving module parameters + * + * @access public + */ + function saveParams($data = 1) + { + $data = array(); + if (IsSet($this->id)) { + $data["id"] = $this->id; + } + if (IsSet($this->view_mode)) { + $data["view_mode"] = $this->view_mode; + } + if (IsSet($this->edit_mode)) { + $data["edit_mode"] = $this->edit_mode; + } + if (IsSet($this->tab)) { + $data["tab"] = $this->tab; + } + return parent::saveParams($data); } - $out['LATEST_ID']=$out['UPDATES'][0]['ID']; - if ($out['LATEST_ID']!='' && $out['LATEST_ID']==$this->config['LATEST_UPDATED_ID']) { - $out['NO_NEED_TO_UPDATE']=1; + + /** + * getParams + * + * Getting module parameters from query string + * + * @access public + */ + function getParams() + { + global $id; + global $mode; + global $view_mode; + global $edit_mode; + global $tab; + if (isset($id)) { + $this->id = $id; + } + if (isset($mode)) { + $this->mode = $mode; + } + if (isset($view_mode)) { + $this->view_mode = $view_mode; + } + if (isset($edit_mode)) { + $this->edit_mode = $edit_mode; + } + if (isset($tab)) { + $this->tab = $tab; + } } - //print_r($out['UPDATES']); - //exit; - } - } - } + /** + * Run + * + * Description + * + * @access public + */ + function run() + { + global $session; + $out = array(); + if ($this->action == 'admin') { + $this->admin($out); + } else { + $this->usual($out); + } + if (IsSet($this->owner->action)) { + $out['PARENT_ACTION'] = $this->owner->action; + } + if (IsSet($this->owner->name)) { + $out['PARENT_NAME'] = $this->owner->name; + } + $out['VIEW_MODE'] = $this->view_mode; + $out['EDIT_MODE'] = $this->edit_mode; + $out['MODE'] = $this->mode; + $out['ACTION'] = $this->action; + if ($this->single_rec) { + $out['SINGLE_REC'] = 1; + } + $this->data = $out; + $p = new parser(DIR_TEMPLATES . $this->name . "/" . $this->name . ".html", $this->data, $this); + $this->result = $p->result; + } + + /** + * BackEnd + * + * Module backend + * + * @access public + */ + function admin(&$out) + { + + + global $err_msg; + if ($err_msg) { + $out['ERR_MSG'] = $err_msg; + } + global $ok_msg; + if ($ok_msg) { + $out['OK_MSG'] = $ok_msg; + } + $this->getConfig(); - if ($this->mode=='savedetails') { + if (is_dir(ROOT . 'saverestore/temp')) { + $out['CLEAR_FIRST'] = 1; + } - global $ftp_host; - global $ftp_username; - global $ftp_password; - global $ftp_folder; - global $ftp_clear; + $this->getConfig(); - if ($ftp_clear) { - $this->config['FTP_USERNAME']=''; - $this->config['FTP_PASSWORD']=''; - $this->saveConfig(); - $this->redirect("?"); - } + if (defined('MASTER_UPDATE_URL') && MASTER_UPDATE_URL != '') { + $github_feed_url = MASTER_UPDATE_URL; + $github_feed_url = str_replace('/archive/', '/commits/', $github_feed_url); + $github_feed_url = str_replace('.tar.gz', '.atom', $github_feed_url); + } else { + $github_feed_url = 'https://github.com/sergejey/majordomo/commits/master.atom'; + } + $github_feed = getURL($github_feed_url, 30 * 60); + + if ($github_feed != '') { + @$tmp = GetXMLTree($github_feed); + @$data = XMLTreeToArray($tmp); + @$items = $data['feed']['entry']; + if (is_array($items)) { + $total = count($items); + if ($total) { + if ($total > 5) { + $total = 5; + } + //print_r($items);exit; + for ($i = 0; $i < $total; $i++) { + $itm = array(); + $itm['ID'] = trim($items[$i]['id']['textvalue']); + $itm['ID'] = preg_replace('/.+Commit\//is', '', $itm['ID']); + $itm['TITLE'] = trim($items[$i]['title']['textvalue']); + $itm['AUTHOR'] = $items[$i]['author']['name']['textvalue']; + $itm['LINK'] = $items[$i]['link']['href']; + $itm['UPDATED'] = strtotime($items[$i]['updated']['textvalue']); + $itm['UPDATE_TEXT'] = date('m/d/Y H:i', $itm['UPDATED']); + $out['UPDATES'][] = $itm; + } + $out['LATEST_ID'] = $out['UPDATES'][0]['ID']; + if ($out['LATEST_ID'] != '' && $out['LATEST_ID'] == $this->config['LATEST_UPDATED_ID']) { + $out['NO_NEED_TO_UPDATE'] = 1; + } + //print_r($out['UPDATES']); + //exit; + } + } + } - $out['FTP_HOST']=$ftp_host; - $out['FTP_USERNAME']=$ftp_username; - $out['FTP_PASSWORD']=$ftp_password; - $out['FTP_FOLDER']=$ftp_folder; + if ($this->mode == 'savedetails') { - $conn_id = @ftp_connect($ftp_host); - if ($conn_id) { + global $ftp_host; + global $ftp_username; + global $ftp_password; + global $ftp_folder; + global $ftp_clear; - $login_result = @ftp_login($conn_id, $ftp_username, $ftp_password); - if ($login_result) { - $systyp=ftp_systype($conn_id); - if (!preg_match('/\/$/', $ftp_folder)) { - $ftp_folder.='/'; - } + if ($ftp_clear) { + $this->config['FTP_USERNAME'] = ''; + $this->config['FTP_PASSWORD'] = ''; + $this->saveConfig(); + $this->redirect("?"); + } - if (@ftp_chdir($conn_id, $ftp_folder.'saverestore')) { - $this->config['FTP_HOST']=$ftp_host; - $this->config['FTP_USERNAME']=$ftp_username; - $this->config['FTP_PASSWORD']=$ftp_password; - $this->config['FTP_FOLDER']=$ftp_folder; - $this->saveConfig(); - $this->redirect("?"); - } else { - $out['FTP_ERR']='Incorrect folder ('.$ftp_folder.')'; - } - } else { - $out['FTP_ERR']='Incorrect username/password'; - } + $out['FTP_HOST'] = $ftp_host; + $out['FTP_USERNAME'] = $ftp_username; + $out['FTP_PASSWORD'] = $ftp_password; + $out['FTP_FOLDER'] = $ftp_folder; + + + $conn_id = @ftp_connect($ftp_host); + if ($conn_id) { + + $login_result = @ftp_login($conn_id, $ftp_username, $ftp_password); + if ($login_result) { + $systyp = ftp_systype($conn_id); - ftp_close($conn_id); + if (!preg_match('/\/$/', $ftp_folder)) { + $ftp_folder .= '/'; + } - } else { - $out['FTP_ERR']='Cannot connect to host ('.$ftp_host.')'; - } + if (@ftp_chdir($conn_id, $ftp_folder . 'saverestore')) { + $this->config['FTP_HOST'] = $ftp_host; + $this->config['FTP_USERNAME'] = $ftp_username; + $this->config['FTP_PASSWORD'] = $ftp_password; + $this->config['FTP_FOLDER'] = $ftp_folder; + $this->saveConfig(); + $this->redirect("?"); + } else { + $out['FTP_ERR'] = 'Incorrect folder (' . $ftp_folder . ')'; + } + } else { + $out['FTP_ERR'] = 'Incorrect username/password'; + } - } + ftp_close($conn_id); - if ($this->mode!='savedetails') { - $out['FTP_HOST']=$this->config['FTP_HOST']; - $out['FTP_USERNAME']=$this->config['FTP_USERNAME']; - $out['FTP_PASSWORD']=$this->config['FTP_PASSWORD']; - $out['FTP_FOLDER']=$this->config['FTP_FOLDER']; - } + } else { + $out['FTP_ERR'] = 'Cannot connect to host (' . $ftp_host . ')'; + } + + } + + if ($this->mode != 'savedetails') { + $out['FTP_HOST'] = $this->config['FTP_HOST']; + $out['FTP_USERNAME'] = $this->config['FTP_USERNAME']; + $out['FTP_PASSWORD'] = $this->config['FTP_PASSWORD']; + $out['FTP_FOLDER'] = $this->config['FTP_FOLDER']; + } // if ($this->mode=='' || $this->mode=='upload' || $this->mode=='savedetails') { - $method='ftp'; - if( function_exists('getmyuid') && function_exists('fileowner') ){ - $temp_file = tempnam ("./saverestore/", "FOO"); - if (file_exists($temp_file)) { - $method = 'direct'; - unlink($temp_file); - } - } - $out['METHOD']=$method; - $this->method=$method; + $method = 'ftp'; + if (function_exists('getmyuid') && function_exists('fileowner')) { + $temp_file = tempnam("./saverestore/", "FOO"); + if (file_exists($temp_file)) { + $method = 'direct'; + unlink($temp_file); + } + } + $out['METHOD'] = $method; + $this->method = $method; // } - if ($this->mode=='clear') { - set_time_limit(0); - $this->removeTree(ROOT.'saverestore/temp'); - global $with_extensions; - if ($with_extensions) { - $this->redirect("?(panel:{action=market})&md=market&mode=update_all"); - } - $this->redirect("?err_msg=".urlencode($err_msg)."&ok_msg=".urlencode($ok_msg)); - } - - - if ($this->mode=='checksubmit') { - $this->checkSubmit($out); - } - - if ($this->mode=='uploadupdates') { - $this->uploadUpdates($out); - } - - if ($this->mode=='checkupdates') { - $this->checkupdatesSVN($out); - } - - if ($this->mode=='downloadupdates') { - $this->downloadupdatesSVN($out); - } - - if ($this->mode=='checkapps') { - $this->checkApps($out); - } - - if ($this->mode=='downloadapps') { - $this->downloadApps($out); - } - - - if ($this->mode=='upload') { - $this->upload($out); - //$this->redirect("?mode=clear"); - } - if ($this->mode=='dump') { - $this->dump($out); - $this->redirect("?mode=clear"); - //$this->redirect("?"); - } - - if ($this->mode=='delete') { - global $file; - @unlink(ROOT.'saverestore/'.$file); - $this->redirect("?"); - } - - if ($this->mode=='getlatest') { - $this->getLatest($out); - } - - if ($this->mode=='getlatest_iframe') { - global $with_extensions; - $out['WITH_EXTENSIONS']=$with_extensions; - - global $backup; - $out['BACKUP']=$backup; - global $data; - $out['DATA']=$data; - global $code; - $out['CODE']=$code; - global $files; - $out['FILES']=$files; - global $design; - $out['DESIGN']=$design; - - } - - - - $source=ROOT.'saverestore'; - $currentdir=getcwd(); - chdir($source); - array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files); - chdir($currentdir); - $out['FILES']=array(); - foreach($files as $file){ - $tmp=array(); - $tmp['FILENAME']=$file; - $tmp['FILESIZE']=number_format((filesize($source."/".$file)/1024/1024), 2); - $out['FILES'][]=$tmp; - } + if ($this->mode == 'clear') { + set_time_limit(0); + $this->removeTree(ROOT . 'saverestore/temp'); + @unlink(ROOT."modules/control_modules/installed"); + global $with_extensions; + if ($with_extensions) { + $this->redirect("?(panel:{action=market})&md=market&mode=update_all"); + } + $this->redirect("?err_msg=" . urlencode($err_msg) . "&ok_msg=" . urlencode($ok_msg)); + } + if ($this->mode == 'checksubmit') { + $this->checkSubmit($out); + } -} + if ($this->mode == 'uploadupdates') { + $this->uploadUpdates($out); + } + if ($this->mode == 'checkupdates') { + $this->checkupdatesSVN($out); + } - /** - * Title - * - * Description - * - * @access public - */ - function getLatest(&$out, $iframe=0) { + if ($this->mode == 'downloadupdates') { + $this->downloadupdatesSVN($out); + } - - if (defined('MASTER_UPDATE_URL') && MASTER_UPDATE_URL!='') { - $url=MASTER_UPDATE_URL; - } else { - $url='https://github.com/sergejey/majordomo/archive/master.tar.gz'; - } - $this->url=$url; + if ($this->mode == 'checkapps') { + $this->checkApps($out); + } - set_time_limit(0); + if ($this->mode == 'downloadapps') { + $this->downloadApps($out); + } - if (!is_dir(ROOT.'saverestore')) { - @umask(0); - @mkdir(ROOT.'saverestore', 0777); - } - $filename=ROOT.'saverestore/master.tgz'; + if ($this->mode == 'upload') { + $this->upload($out); + //$this->redirect("?mode=clear"); + } + if ($this->mode == 'dump') { + $this->dump($out); + $this->redirect("?mode=clear"); + //$this->redirect("?"); + } - @unlink(ROOT.'saverestore/master.tgz'); - @unlink(ROOT.'saverestore/master.tar'); + if ($this->mode == 'delete') { + global $file; + @unlink(ROOT . 'saverestore/' . $file); + $this->redirect("?"); + } - $f = fopen($filename, 'wb'); - if ($f == FALSE){ - $this->redirect("?err_msg=".urlencode("Cannot open ".$filename." for writing")); - } + if ($this->mode == 'getlatest') { + $this->getLatest($out); + } - if ($iframe) { - $this->echonow("Downloading $url ... "); - } + if ($this->mode == 'getlatest_iframe') { + global $with_extensions; + $out['WITH_EXTENSIONS'] = $with_extensions; + + global $backup; + $out['BACKUP'] = $backup; + global $data; + $out['DATA'] = $data; + global $code; + $out['CODE'] = $code; + global $files; + $out['FILES'] = $files; + global $design; + $out['DESIGN'] = $design; + + } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($ch, CURLOPT_FILE, $f); - $incoming = curl_exec($ch); - curl_close($ch); - @fclose($f); + $source = ROOT . 'saverestore'; + $currentdir = getcwd(); + chdir($source); + array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files); + if (defined('SETTINGS_BACKUP_PATH') && SETTINGS_BACKUP_PATH != '' && is_dir(SETTINGS_BACKUP_PATH)) { + $backups_dir=SETTINGS_BACKUP_PATH; + } else { + $backups_dir=DOC_ROOT . '/backup'; + } + chdir($backups_dir); + $backups = glob("*"); + if (is_array($backups)) { + foreach($backups as $backup_folder) { + $files[]=$backups_dir.'/'.$backup_folder; + } + } + chdir($currentdir); + $out['FILES'] = array(); + foreach ($files as $file) { + $tmp = array(); + $tmp['FILENAME'] = $file; + if (is_file($source . "/" . $file)) { + $tmp['FILESIZE'] = number_format((filesize($source . "/" . $file) / 1024 / 1024), 2); + $tmp['TITLE']=basename($file); + } else { + $tmp['TITLE']='Backup '.basename($file); + } + $out['FILES'][] = $tmp; + } - if (file_exists($filename)) { - if ($iframe) { - $this->echonow(" OK
", "green"); } - global $code; - global $data; - global $design; - $code=1; - $data=1; //fix - $design=1; - $out['BACKUP']=1; - $this->dump($out, $iframe); - $this->removeTree(ROOT.'saverestore/temp', $iframe); - - if (!$iframe) { - global $with_extensions; - $folder='majordomo-master'; - $basename=basename($this->url); - if ($basename!='master.tar.gz') { - $basename=str_replace('.tar.gz', '', $basename); - $folder=str_replace('master', $basename, $folder); - } - $this->redirect("?mode=upload&restore=".urlencode('master.tgz')."&folder=".urlencode($folder)."&with_extensions=".$with_extensions); - } else { - return 1; - } + /** + * Title + * + * Description + * + * @access public + */ + function getLatest(&$out, $iframe = 0) + { - } else { - if ($iframe) { - $this->echonow("Cannot download file
", "red");exit; - } else { - $this->redirect("?err_msg=".urlencode("Cannot download ".$url)); - } - } - } - - - function echonow($msg, $color='') { - if ($color) { - echo ''; - } - echo $msg; - if ($color) { - echo ''; - } - echo str_repeat(' ', 16*1024); - flush(); - ob_flush(); - } + if (defined('MASTER_UPDATE_URL') && MASTER_UPDATE_URL != '') { + $url = MASTER_UPDATE_URL; + } else { + $url = 'https://github.com/sergejey/majordomo/archive/master.tar.gz'; + } + $this->url = $url; -/** -* Title -* -* Description -* -* @access public -*/ - function uploadUpdates(&$out) { - global $to_submit; - global $pack_folders; + set_time_limit(0); + + if (!is_dir(ROOT . 'saverestore')) { + @umask(0); + @mkdir(ROOT . 'saverestore', 0777); + } + $filename = ROOT . 'saverestore/master.tgz'; - $total=count($to_submit); + @unlink(ROOT . 'saverestore/master.tgz'); + @unlink(ROOT . 'saverestore/master.tar'); - umask(0); + $f = fopen($filename, 'wb'); + if ($f == FALSE) { + $this->redirect("?err_msg=" . urlencode("Cannot open " . $filename . " for writing")); + } - $copied_dirs=array(); + if ($iframe) { + $this->echonow("Downloading $url ... "); + } - if (mkdir(ROOT.'saverestore/temp', 0777)) { - for($i=0;$i<$total;$i++) { - $this->copyFile(ROOT.$to_submit[$i], ROOT.'saverestore/temp/'.$to_submit[$i]); - if (is_array($pack_folders) && in_array($to_submit[$i], $pack_folders) && !$copied_dirs[dirname(ROOT.'saverestore/temp/'.$to_submit[$i])]) { - $this->copyTree(dirname(ROOT.$to_submit[$i]), dirname(ROOT.'saverestore/temp/'.$to_submit[$i])); - $copied_dirs[dirname(ROOT.'saverestore/temp/'.$to_submit[$i])]=1; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); + curl_setopt($ch, CURLOPT_FILE, $f); + $incoming = curl_exec($ch); + + curl_close($ch); + @fclose($f); + + if (file_exists($filename)) { + + if ($iframe) { + $this->echonow(" OK
", "green"); + } + + + global $code; + global $data; + global $design; + $code = 1; + $data = 1; //fix + $design = 1; + $out['BACKUP'] = 1; + $this->dump($out, $iframe); + $this->removeTree(ROOT . 'saverestore/temp', $iframe); + + if (!$iframe) { + global $with_extensions; + $folder = 'majordomo-master'; + $basename = basename($this->url); + if ($basename != 'master.tar.gz') { + $basename = str_replace('.tar.gz', '', $basename); + $folder = str_replace('master', $basename, $folder); + } + $this->redirect("?mode=upload&restore=" . urlencode('master.tgz') . "&folder=" . urlencode($folder) . "&with_extensions=" . $with_extensions); + } else { + return 1; + } + + } else { + + if ($iframe) { + $this->echonow("Cannot download file
", "red"); + exit; + } else { + $this->redirect("?err_msg=" . urlencode("Cannot download " . $url)); + } + } } - if (file_exists(dirname(ROOT.'saverestore/temp/'.$to_submit[$i]).'/installed')) { - @unlink(dirname(ROOT.'saverestore/temp/'.$to_submit[$i]).'/installed'); + + + function echonow($msg, $color = '') + { + if ($color) { + echo ''; + } + echo $msg; + if ($color) { + echo ''; + } + echo str_repeat(' ', 16 * 1024); + flush(); + ob_flush(); } - } - } - // packing into tar.gz - $tar_name='submit_'.date('Y-m-d__h-i-s').'.tgz'; + /** + * Title + * + * Description + * + * @access public + */ + function uploadUpdates(&$out) + { + global $to_submit; + global $pack_folders; - chdir(ROOT.'saverestore/temp'); - exec('tar cvzf ../'.$tar_name.' .'); - chdir('../../'); - $this->removeTree(ROOT.'saverestore/temp'); - // sending to remote server + $total = count($to_submit); - $repository_url=UPDATER_URL; + umask(0); - if (defined('UPDATES_REPOSITORY_NAME')) { - $repository_name=UPDATES_REPOSITORY_NAME; - } else { - $repository_name='default'; - } + $copied_dirs = array(); - $to_send=array(); - global $name; - $to_send['NAME']=$name; - setCookie('SUBMIT_NAME', $name, 0, '/'); + if (mkdir(ROOT . 'saverestore/temp', 0777)) { + for ($i = 0; $i < $total; $i++) { + $this->copyFile(ROOT . $to_submit[$i], ROOT . 'saverestore/temp/' . $to_submit[$i]); + if (is_array($pack_folders) && in_array($to_submit[$i], $pack_folders) && !$copied_dirs[dirname(ROOT . 'saverestore/temp/' . $to_submit[$i])]) { + $this->copyTree(dirname(ROOT . $to_submit[$i]), dirname(ROOT . 'saverestore/temp/' . $to_submit[$i])); + $copied_dirs[dirname(ROOT . 'saverestore/temp/' . $to_submit[$i])] = 1; + } + if (file_exists(dirname(ROOT . 'saverestore/temp/' . $to_submit[$i]) . '/installed')) { + @unlink(dirname(ROOT . 'saverestore/temp/' . $to_submit[$i]) . '/installed'); + } + } + } - global $email; - $to_send['EMAIL']=$email; - setCookie('SUBMIT_EMAIL', $email, 0, '/'); + // packing into tar.gz + $tar_name = 'submit_' . date('Y-m-d__h-i-s') . '.tgz'; - global $description; - $to_send['DESCRIPTION']=$description; - $to_send['FILES']=$to_submit; + chdir(ROOT . 'saverestore/temp'); + exec('tar cvzf ../' . $tar_name . ' .'); + chdir('../../'); + $this->removeTree(ROOT . 'saverestore/temp'); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); + // sending to remote server - $post = array( - "file"=>"@".ROOT.'saverestore/'.$tar_name, - "mode"=>"upload_updates", - "repository"=>$repository_name, - "host"=>$_SERVER['HTTP_HOST'], - "data"=>serialize($to_send) - ); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + $repository_url = UPDATER_URL; - //curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=upload_updates&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&data=".$to_send); - - $incoming = curl_exec($ch); + if (defined('UPDATES_REPOSITORY_NAME')) { + $repository_name = UPDATES_REPOSITORY_NAME; + } else { + $repository_name = 'default'; + } - curl_close($ch); + $to_send = array(); + global $name; + $to_send['NAME'] = $name; + setCookie('SUBMIT_NAME', $name, 0, '/'); - $result=unserialize($incoming); + global $email; + $to_send['EMAIL'] = $email; + setCookie('SUBMIT_EMAIL', $email, 0, '/'); - $ok_msg='Error sending files to repository! ';//.$incoming - if ($result['MESSAGE']) { - $ok_msg=$result['MESSAGE']; - } + global $description; + $to_send['DESCRIPTION'] = $description; + $to_send['FILES'] = $to_submit; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + $post = array( + "file" => "@" . ROOT . 'saverestore/' . $tar_name, + "mode" => "upload_updates", + "repository" => $repository_name, + "host" => $_SERVER['HTTP_HOST'], + "data" => serialize($to_send) + ); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); - if ($result['STATUS']=='OK') { - global $with_extensions; - $this->redirect("?mode=clear&ok_msg=".urlencode($ok_msg)."&with_extensions=".$with_extensions); - } else { - $this->redirect("?mode=clear&err_msg=".urlencode($ok_msg)); - } - - //exit; - + //curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=upload_updates&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&data=".$to_send); - } + $incoming = curl_exec($ch); -/** -* Title -* -* Description -* -* @access public -*/ - function checkSubmit(&$out) { + curl_close($ch); - $res1=$this->checkEFiles('.', 0); - $res2=$this->checkEFiles('./modules', 1); - $res3=$this->checkEFiles('./templates', 1); - $res4=$this->checkEFiles('./lib', 0); + $result = unserialize($incoming); - $res=array_merge($res1, $res2, $res3, $res4); + $ok_msg = 'Error sending files to repository! ';//.$incoming + if ($result['MESSAGE']) { + $ok_msg = $result['MESSAGE']; + } - $to_send=serialize($res); - $repository_url=UPDATER_URL; + if ($result['STATUS'] == 'OK') { + global $with_extensions; + $this->redirect("?mode=clear&ok_msg=" . urlencode($ok_msg) . "&with_extensions=" . $with_extensions); + } else { + $this->redirect("?mode=clear&err_msg=" . urlencode($ok_msg)); + } - if (defined('UPDATES_REPOSITORY_NAME')) { - $repository_name=UPDATES_REPOSITORY_NAME; - } else { - $repository_name='default'; - } + //exit; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=check_submit&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&data=".$to_send); - - $incoming = curl_exec($ch); + } - curl_close($ch); + /** + * Title + * + * Description + * + * @access public + */ + function checkSubmit(&$out) + { - //echo $incoming;exit; + $res1 = $this->checkEFiles('.', 0); + $res2 = $this->checkEFiles('./modules', 1); + $res3 = $this->checkEFiles('./templates', 1); + $res4 = $this->checkEFiles('./lib', 0); + $res = array_merge($res1, $res2, $res3, $res4); - $result=unserialize($incoming); + $to_send = serialize($res); - //echo $repository_url; - //echo($result);exit; + $repository_url = UPDATER_URL; - if ($result['STATUS']!='OK') { - $out['ERROR_CHECK']=1; - if ($result['MESSAGE']) { - $out['ERROR_MESSAGE']=$result['MESSAGE']; - } else { - $out['ERROR_MESSAGE']='Cannot connect to updates server'; - } - } else { - $out['OK_CHECKSUBMIT']=1; - - //print_r($result['TO_SUBMIT']);exit; - - if (is_array($result['TO_SUBMIT'])) { - foreach($result['TO_SUBMIT'] as $f=>$v) { - $tmp=array('FILE'=>$f, 'VERSION'=>$v, 'L_VERSION'=>$res[$f]); - if (preg_match('/\/modules\/.+\/.+/is', $f) || preg_match('/\/templates\/.+\/.+/is', $f)) { - $tmp['PACK_FOLDER']=1; - } - $out['TO_SUBMIT'][]=$tmp; - } - } else { - $out['NO_SUBMIT']=1; - } - } + if (defined('UPDATES_REPOSITORY_NAME')) { + $repository_name = UPDATES_REPOSITORY_NAME; + } else { + $repository_name = 'default'; + } - $out['NAME']=$_COOKIE['SUBMIT_NAME']; - $out['EMAIL']=$_COOKIE['SUBMIT_EMAIL']; - - } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=check_submit&repository=" . $repository_name . "&host=" . $_SERVER['HTTP_HOST'] . "&data=" . $to_send); -/** -* Title -* -* Description -* -* @access public -*/ - function downloadUpdates(&$out) { - global $to_update; - - $repository_url=UPDATER_URL; - - if (defined('UPDATES_REPOSITORY_NAME')) { - $repository_name=UPDATES_REPOSITORY_NAME; - } else { - $repository_name='default'; - } - - // preparing update - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=prepare&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&data=".serialize($to_update)); - $incoming = curl_exec($ch); - curl_close($ch); - - $res=unserialize($incoming); - - if ($res['STATUS']=='OK' && $res['DOWNLOAD_FILE']!='') { - // downloading update - $filename=ROOT.'saverestore/'.$res['DOWNLOAD_FILE']; - $f = fopen($filename, 'wb'); - if ($f == FALSE){ - //print "File not opened
"; - //exit; - $this->redirect("?err_msg=".urlencode("Cannot open ".$filename." for writing")); - } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); - curl_setopt($ch, CURLOPT_FILE, $f); - - curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=download&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&file=".$res['DOWNLOAD_FILE']); - - $incoming = curl_exec($ch); - - curl_close($ch); - @fclose($f); - - if (file_exists($filename) && filesize($filename)>0) { - // backing up current code version - global $code; - global $data; - $code=1; - $data=1; - $out['BACKUP']=1; - $this->dump($out); - $this->removeTree(ROOT.'saverestore/temp'); - // installing update - $this->redirect("?mode=upload&restore=".urlencode($res['DOWNLOAD_FILE'])); - } else { - $this->redirect("?err_msg=".urlencode("Error downloading update")); - } - } - - exit; - - } + $incoming = curl_exec($ch); -/** -* Title -* -* Description -* -* @access public -*/ - function downloadApps(&$out) { - global $to_install; - - - $repository_url=UPDATER_URL; - - if (defined('UPDATES_REPOSITORY_NAME')) { - $repository_name=UPDATES_REPOSITORY_NAME; - } else { - $repository_name='default'; - } - - // preparing update - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=prepareapps&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&data=".serialize($to_install)); - $incoming = curl_exec($ch); - curl_close($ch); - - //echo $incoming;exit; - - $res=unserialize($incoming); - - if ($res['STATUS']=='OK' && $res['DOWNLOAD_FILE']!='') { - // downloading update - $filename=ROOT.'saverestore/'.$res['DOWNLOAD_FILE']; - $f = fopen($filename, 'wb'); - if ($f == FALSE){ - //print "File not opened
"; - //exit; - $this->redirect("?err_msg=".urlencode("Cannot open ".$filename." for writing")); - } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); - curl_setopt($ch, CURLOPT_FILE, $f); - - curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=download&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&file=".$res['DOWNLOAD_FILE']); - - $incoming = curl_exec($ch); - - curl_close($ch); - @fclose($f); - - if (file_exists($filename) && filesize($filename)>0) { - // backing up current code version - global $code; - global $data; - $code=1; - $data=1; - $out['BACKUP']=1; - $this->dump($out); - $this->removeTree(ROOT.'saverestore/temp'); - // installing update - $this->redirect("?mode=upload&restore=".urlencode($res['DOWNLOAD_FILE'])); - } else { - $this->redirect("?err_msg=".urlencode("Error downloading update")); - } - } - - exit; - - } + curl_close($ch); + //echo $incoming;exit; -/** -* Title -* -* Description -* -* @access public -*/ - function checkApps(&$out) { - - $res=array(); - $d='./modules'; - if ($dir = @opendir($d)) { - while (($file = readdir($dir)) !== false) { - if (is_dir($d.'/'.$file) - && ($file!='..') - && ($file!='.') - && ($file!='control_access') - && ($file!='control_modules') - ) { - $res[]=$file; - } - } - } - $to_send=serialize($res); + $result = unserialize($incoming); - $repository_url=UPDATER_URL; + //echo $repository_url; + //echo($result);exit; - if (defined('UPDATES_REPOSITORY_NAME')) { - $repository_name=UPDATES_REPOSITORY_NAME; - } else { - $repository_name='default'; - } + if ($result['STATUS'] != 'OK') { + $out['ERROR_CHECK'] = 1; + if ($result['MESSAGE']) { + $out['ERROR_MESSAGE'] = $result['MESSAGE']; + } else { + $out['ERROR_MESSAGE'] = 'Cannot connect to updates server'; + } + } else { + $out['OK_CHECKSUBMIT'] = 1; + + //print_r($result['TO_SUBMIT']);exit; + + if (is_array($result['TO_SUBMIT'])) { + foreach ($result['TO_SUBMIT'] as $f => $v) { + $tmp = array('FILE' => $f, 'VERSION' => $v, 'L_VERSION' => $res[$f]); + if (preg_match('/\/modules\/.+\/.+/is', $f) || preg_match('/\/templates\/.+\/.+/is', $f)) { + $tmp['PACK_FOLDER'] = 1; + } + $out['TO_SUBMIT'][] = $tmp; + } + } else { + $out['NO_SUBMIT'] = 1; + } + } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); + $out['NAME'] = $_COOKIE['SUBMIT_NAME']; + $out['EMAIL'] = $_COOKIE['SUBMIT_EMAIL']; - curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=checkapps&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&data=".$to_send); - - $incoming = curl_exec($ch); + } - curl_close($ch); - //echo $incoming;exit; + /** + * Title + * + * Description + * + * @access public + */ + function downloadUpdates(&$out) + { + global $to_update; - $result=unserialize($incoming); + $repository_url = UPDATER_URL; - if ($result['STATUS']!='OK') { + if (defined('UPDATES_REPOSITORY_NAME')) { + $repository_name = UPDATES_REPOSITORY_NAME; + } else { + $repository_name = 'default'; + } + + // preparing update + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=prepare&repository=" . $repository_name . "&host=" . $_SERVER['HTTP_HOST'] . "&data=" . serialize($to_update)); + $incoming = curl_exec($ch); + curl_close($ch); + + $res = unserialize($incoming); + + if ($res['STATUS'] == 'OK' && $res['DOWNLOAD_FILE'] != '') { + // downloading update + $filename = ROOT . 'saverestore/' . $res['DOWNLOAD_FILE']; + $f = fopen($filename, 'wb'); + if ($f == FALSE) { + //print "File not opened
"; + //exit; + $this->redirect("?err_msg=" . urlencode("Cannot open " . $filename . " for writing")); + } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_FILE, $f); + + curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=download&repository=" . $repository_name . "&host=" . $_SERVER['HTTP_HOST'] . "&file=" . $res['DOWNLOAD_FILE']); + + $incoming = curl_exec($ch); + + curl_close($ch); + @fclose($f); + + if (file_exists($filename) && filesize($filename) > 0) { + // backing up current code version + global $code; + global $data; + $code = 1; + $data = 1; + $out['BACKUP'] = 1; + $this->dump($out); + $this->removeTree(ROOT . 'saverestore/temp'); + // installing update + $this->redirect("?mode=upload&restore=" . urlencode($res['DOWNLOAD_FILE'])); + } else { + $this->redirect("?err_msg=" . urlencode("Error downloading update")); + } + } + + exit; - if ($result['MESSAGE']) { - $out['ERROR_MESSAGE']=$result['MESSAGE']; - } else { - $out['ERROR_MESSAGE']='Cannot connect to updates server'; } - $this->redirect("?err_msg=".urlencode($out['ERROR_MESSAGE'])); - - } else { - $out['OK_BROWSE']=1; - if (is_array($result['TO_INSTALL'])) { - $out['TO_INSTALL']=$result['TO_INSTALL']; - /* - foreach($result['TO_UPDATE'] as $f=>$v) { - $out['TO_INSTALL'][]=array('FILE'=>$f, 'VERSION'=>$v); - } + + /** + * Title + * + * Description + * + * @access public */ - } else { - $out['NO_MODULES']=1; - } - } - - } + function downloadApps(&$out) + { + global $to_install; -/** -* Title -* -* Description -* -* @access public -*/ - function downloadUpdatesSVN(&$out) { - - global $code; - global $data; - $code=1; - $data=1; - $out['BACKUP']=1; - $this->dump($out); - $this->removeTree(ROOT.'saverestore/temp'); - - include_once DIR_MODULES.'saverestore/phpsvnclient.php'; - $url = 'http://majordomo-sl.googlecode.com/svn/'; - $phpsvnclient = new phpsvnclient($url); - set_time_limit(0); - global $to_update; - - $total=count($to_update); - for($i=0;$i<$total;$i++) { - $path='trunk/'.$to_update[$i]; - $file_content = $phpsvnclient->getFile($path); - if (!is_dir(dirname(ROOT.$to_update[$i]))) { - @mkdir(dirname(ROOT.$to_update[$i]), 0777); - } - @SaveFile(ROOT.$to_update[$i], $file_content); - if (file_exists(dirname(ROOT.$to_update[$i]).'/installed')) { - @unlink(dirname(ROOT.$to_update[$i]).'/installed'); - } - } - - $this->redirect("?ok_msg=".urlencode('Files have been updated!')); - - } + $repository_url = UPDATER_URL; -/** -* Title -* -* Description -* -* @access public -*/ - function checkUpdatesSVN(&$out) { - include_once DIR_MODULES.'saverestore/phpsvnclient.php'; - - $url = 'http://majordomo-sl.googlecode.com/svn/'; - - $phpsvnclient = new phpsvnclient($url); - - set_time_limit(0); - //$phpsvnclient->createOrUpdateWorkingCopy('trunk/', ROOT.'saverestore/temp', true); - - $cached_name=ROOT.'saverestore/svn_tree.txt'; - if (!file_exists($cached_name) || (time()-filemtime($cached_name)>8*60*60)) { - $directory_tree = $phpsvnclient->getDirectoryTree('/trunk/'); - SaveFile($cached_name, serialize($directory_tree)); - } else { - $directory_tree=unserialize(LoadFile($cached_name)); - } - - $updated=array(); - $total=count($directory_tree); - for($i=0;$i<$total;$i++) { - $item=$directory_tree[$i]; - if ($item['type']!='file' || $item['path']=='trunk/config.php') { - continue; - } - $filename=str_replace('trunk/', ROOT, $item['path']); - @$fsize=filesize($filename); - $r_rfsize=$item['size']; - if ($fsize!=$r_rfsize || !file_exists($filename)) { - $updated[]=$item; - } - - } - - - $out['OK_CHECK']=1; - if (!$updated[0]) { - $out['NO_UPDATES']=1; - } else { - foreach($updated as $item) { - $item['path']=str_replace('trunk/', '', $item['path']); - $out['TO_UPDATE'][]=array('FILE'=>$item['path'], 'VERSION'=>$item['version'].' ('.$item['last-mod'].')'); - } - } - - } -/** -* Title -* -* Description -* -* @access public -*/ - function checkUpdates(&$out) { + if (defined('UPDATES_REPOSITORY_NAME')) { + $repository_name = UPDATES_REPOSITORY_NAME; + } else { + $repository_name = 'default'; + } - $res1=$this->checkEFiles('.', 0); - $res2=$this->checkEFiles('./modules', 1); - $res3=$this->checkEFiles('./templates', 1); - $res4=$this->checkEFiles('./lib', 0); + // preparing update + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=prepareapps&repository=" . $repository_name . "&host=" . $_SERVER['HTTP_HOST'] . "&data=" . serialize($to_install)); + $incoming = curl_exec($ch); + curl_close($ch); + + //echo $incoming;exit; + + $res = unserialize($incoming); + + if ($res['STATUS'] == 'OK' && $res['DOWNLOAD_FILE'] != '') { + // downloading update + $filename = ROOT . 'saverestore/' . $res['DOWNLOAD_FILE']; + $f = fopen($filename, 'wb'); + if ($f == FALSE) { + //print "File not opened
"; + //exit; + $this->redirect("?err_msg=" . urlencode("Cannot open " . $filename . " for writing")); + } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_FILE, $f); + + curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=download&repository=" . $repository_name . "&host=" . $_SERVER['HTTP_HOST'] . "&file=" . $res['DOWNLOAD_FILE']); + + $incoming = curl_exec($ch); + + curl_close($ch); + @fclose($f); + + if (file_exists($filename) && filesize($filename) > 0) { + // backing up current code version + global $code; + global $data; + $code = 1; + $data = 1; + $out['BACKUP'] = 1; + $this->dump($out); + $this->removeTree(ROOT . 'saverestore/temp'); + // installing update + $this->redirect("?mode=upload&restore=" . urlencode($res['DOWNLOAD_FILE'])); + } else { + $this->redirect("?err_msg=" . urlencode("Error downloading update")); + } + } - $res=array_merge($res1, $res2, $res3, $res4); + exit; - $to_send=serialize($res); + } - $repository_url=UPDATER_URL; - if (defined('UPDATES_REPOSITORY_NAME')) { - $repository_name=UPDATES_REPOSITORY_NAME; - } else { - $repository_name='default'; - } + /** + * Title + * + * Description + * + * @access public + */ + function checkApps(&$out) + { + + $res = array(); + $d = './modules'; + if ($dir = @opendir($d)) { + while (($file = readdir($dir)) !== false) { + if (is_dir($d . '/' . $file) + && ($file != '..') + && ($file != '.') + && ($file != 'control_access') + && ($file != 'control_modules') + ) { + $res[] = $file; + } + } + } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $repository_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); + $to_send = serialize($res); - curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=check&repository=".$repository_name."&host=".$_SERVER['HTTP_HOST']."&data=".$to_send); - - $incoming = curl_exec($ch); + $repository_url = UPDATER_URL; - curl_close($ch); + if (defined('UPDATES_REPOSITORY_NAME')) { + $repository_name = UPDATES_REPOSITORY_NAME; + } else { + $repository_name = 'default'; + } - //echo $incoming;exit; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=checkapps&repository=" . $repository_name . "&host=" . $_SERVER['HTTP_HOST'] . "&data=" . $to_send); - $result=unserialize($incoming); + $incoming = curl_exec($ch); - //echo $repository_url; - //echo($result);exit; + curl_close($ch); - if ($result['STATUS']!='OK') { - $out['ERROR_CHECK']=1; - if ($result['MESSAGE']) { - $out['ERROR_MESSAGE']=$result['MESSAGE']; - } else { - $out['ERROR_MESSAGE']='Cannot connect to updates server'; - } - } else { - $out['OK_CHECK']=1; - if (is_array($result['TO_UPDATE'])) { - foreach($result['TO_UPDATE'] as $f=>$v) { - $out['TO_UPDATE'][]=array('FILE'=>$f, 'VERSION'=>$v); - } - } else { - $out['NO_UPDATES']=1; - } - } + //echo $incoming;exit; + $result = unserialize($incoming); - //exec('curl ...') + if ($result['STATUS'] != 'OK') { - } + if ($result['MESSAGE']) { + $out['ERROR_MESSAGE'] = $result['MESSAGE']; + } else { + $out['ERROR_MESSAGE'] = 'Cannot connect to updates server'; + } + $this->redirect("?err_msg=" . urlencode($out['ERROR_MESSAGE'])); -/** -* Title -* -* Description -* -* @access public -*/ - function checkEFiles($d, $max_level=0, $level=0) { - - - $res=array(); - - if (!is_dir($d)) { - return $res; - } - - if ($dir = @opendir($d)) { - while (($file = readdir($dir)) !== false) { - if (Is_Dir($d."/".$file) && ($file!='.') && ($file!='..')) { - //echo "
Dir ".$d."/".$file; - if ($level<$max_level) { - $res2=$this->checkEFiles($d."/".$file, $max_level, ($level+1)); - if (is_array($res2)) { - $res=array_merge($res, $res2); - } - } - } elseif (Is_File($d."/".$file) && - (preg_match('/\.php$/', $file) || preg_match('/\.css$/', $file) || preg_match('/\.html$/', $file) || preg_match('/\.js$/', $file))) { - - if ($file=='config.php') { - continue; - } - - //echo "
".$d.'/'.$file; - $version=''; - $content=LoadFile($d.'/'.$file); - if (preg_match('/@version (.+?)\n/is', $content, $m)) { - $version=trim($m[1]); - //echo "
".$d.'/'.$file.' - '.$version; - } elseif (preg_match('/\.class\.php$/is', $file)) { - // echo "
".$d.'/'.$file.' - '.'unknown'; - //$version='unknown'; - } - - if ($version!='') { - $res[$d.'/'.$file]=$version; - } + } else { + $out['OK_BROWSE'] = 1; + if (is_array($result['TO_INSTALL'])) { + $out['TO_INSTALL'] = $result['TO_INSTALL']; + /* + foreach($result['TO_UPDATE'] as $f=>$v) { + $out['TO_INSTALL'][]=array('FILE'=>$f, 'VERSION'=>$v); + } + */ + } else { + $out['NO_MODULES'] = 1; + } + } } - } - closedir($dir); - } - return $res; -} + /** + * Title + * + * Description + * + * @access public + */ + function downloadUpdatesSVN(&$out) + { + + global $code; + global $data; + $code = 1; + $data = 1; + $out['BACKUP'] = 1; + $this->dump($out); + $this->removeTree(ROOT . 'saverestore/temp'); + + include_once DIR_MODULES . 'saverestore/phpsvnclient.php'; + $url = 'http://majordomo-sl.googlecode.com/svn/'; + $phpsvnclient = new phpsvnclient($url); + set_time_limit(0); + global $to_update; + + $total = count($to_update); + for ($i = 0; $i < $total; $i++) { + $path = 'trunk/' . $to_update[$i]; + $file_content = $phpsvnclient->getFile($path); + if (!is_dir(dirname(ROOT . $to_update[$i]))) { + @mkdir(dirname(ROOT . $to_update[$i]), 0777); + } + @SaveFile(ROOT . $to_update[$i], $file_content); + if (file_exists(dirname(ROOT . $to_update[$i]) . '/installed')) { + @unlink(dirname(ROOT . $to_update[$i]) . '/installed'); + } + } - /** - * Title - * - * Description - * - * @access public - */ - function extractVersion($s) { - $o_version=preg_replace('/\(.+/', '', $s); - $o_version=preg_replace('/[^\d]/', '', $o_version); - $o_version=(float)substr($o_version, 0, 1).'.'.substr($o_version, 1, strlen($o_version)-1); - return $o_version; - } + $this->redirect("?ok_msg=" . urlencode('Files have been updated!')); -/** -* Title -* -* Description -* -* @access public -*/ - function isNewer($o_version, $r_version) { - - $o_version=$this->extractVersion($o_version); - $r_version=$this->extractVersion($r_version); + } - //$r_version+=0.1; // just for testing - //echo $o_version.' to '.$r_version."
"; + /** + * Title + * + * Description + * + * @access public + */ + function checkUpdatesSVN(&$out) + { + include_once DIR_MODULES . 'saverestore/phpsvnclient.php'; - if ($o_version<$r_version) { - return 1; - } + $url = 'http://majordomo-sl.googlecode.com/svn/'; - return 0; - } + $phpsvnclient = new phpsvnclient($url); + + set_time_limit(0); + //$phpsvnclient->createOrUpdateWorkingCopy('trunk/', ROOT.'saverestore/temp', true); + + $cached_name = ROOT . 'saverestore/svn_tree.txt'; + if (!file_exists($cached_name) || (time() - filemtime($cached_name) > 8 * 60 * 60)) { + $directory_tree = $phpsvnclient->getDirectoryTree('/trunk/'); + SaveFile($cached_name, serialize($directory_tree)); + } else { + $directory_tree = unserialize(LoadFile($cached_name)); + } + + $updated = array(); + $total = count($directory_tree); + for ($i = 0; $i < $total; $i++) { + $item = $directory_tree[$i]; + if ($item['type'] != 'file' || $item['path'] == 'trunk/config.php') { + continue; + } + $filename = str_replace('trunk/', ROOT, $item['path']); + @$fsize = filesize($filename); + $r_rfsize = $item['size']; + if ($fsize != $r_rfsize || !file_exists($filename)) { + $updated[] = $item; + } + + } + + + $out['OK_CHECK'] = 1; + if (!$updated[0]) { + $out['NO_UPDATES'] = 1; + } else { + foreach ($updated as $item) { + $item['path'] = str_replace('trunk/', '', $item['path']); + $out['TO_UPDATE'][] = array('FILE' => $item['path'], 'VERSION' => $item['version'] . ' (' . $item['last-mod'] . ')'); + } + } -/** -* Title -* -* Description -* -* @access public -*/ -function getLocalFilesTree($dir, $pattern, $ex_pattern, &$log, $verbose) { - $res=array(); - - $destination=$dir; - - if (!Is_Dir($destination)) { - return $res; // cannot create destination path - } - - if ($dir = @opendir($destination)) { - while (($file = readdir($dir)) !== false) { - if (Is_Dir($destination."/".$file) && ($file!='.') && ($file!='..')) { - $sub_ar=$this->getLocalFilesTree($destination."/".$file, $pattern, $ex_pattern, $log, $verbose); - $res = array_merge ($res, $sub_ar); - } elseif (Is_File($destination."/".$file)) { - - $fl=array(); - $fl['FILENAME']=str_replace('//', '/', $destination."/".$file); - $fl['FILENAME_SHORT']=str_replace('//', '/', $file); - $fl['SIZE']=filesize($fl['FILENAME']); - if (preg_match('/'.$pattern.'/is', $fl['FILENAME_SHORT']) && ($ex_pattern=='' || !preg_match('/'.$ex_pattern.'/is', $fl['FILENAME_SHORT']))) { - $res[]=$fl; - } } - } - closedir($dir); - } - return $res; -} + /** + * Title + * + * Description + * + * @access public + */ + function checkUpdates(&$out) + { -/** -* Title -* -* Description -* -* @access public -*/ - function upload(&$out, $iframe=0) { + $res1 = $this->checkEFiles('.', 0); + $res2 = $this->checkEFiles('./modules', 1); + $res3 = $this->checkEFiles('./templates', 1); + $res4 = $this->checkEFiles('./lib', 0); - set_time_limit(0); - global $restore; - global $file; - global $file_name; - global $folder; + $res = array_merge($res1, $res2, $res3, $res4); - if (!$folder) - $folder = IsWindowsOS() ? '/.' : '/'; - else - $folder = '/' . $folder; + $to_send = serialize($res); - if ($restore!='') { - //$file=ROOT.'saverestore/'.$restore; - $file=$restore; - } elseif ($file!='') { - copy($file, ROOT.'saverestore/'.$file_name); - //$file=ROOT.'saverestore/'.$file_name; - $file=$file_name; - } + $repository_url = UPDATER_URL; - umask(0); - @mkdir(ROOT.'saverestore/temp', 0777); + if (defined('UPDATES_REPOSITORY_NAME')) { + $repository_name = UPDATES_REPOSITORY_NAME; + } else { + $repository_name = 'default'; + } - if ($iframe) { - $this->echonow("Applying updates.
"); - } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $repository_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 600); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, "mode=check&repository=" . $repository_name . "&host=" . $_SERVER['HTTP_HOST'] . "&data=" . $to_send); - if ($file!='') { // && mkdir(ROOT.'saverestore/temp', 0777) + $incoming = curl_exec($ch); - chdir(ROOT.'saverestore/temp'); + curl_close($ch); - if ($iframe) { - $this->echonow("Unpacking $file ... "); - } - if (IsWindowsOS()) - { - // for windows only - exec(DOC_ROOT.'/gunzip ../'.$file, $output, $res); - exec(DOC_ROOT.'/tar xvf ../'.str_replace('.tgz', '.tar', $file), $output, $res); - //@unlink('../'.str_replace('.tgz', '.tar', $file)); - } - else - { - exec('tar xzvf ../'.$file, $output, $res); - } - - @unlink(ROOT.'saverestore/temp'.$folder.'/config.php'); + //echo $incoming;exit; - //print_r($output);exit; - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + $result = unserialize($incoming); + //echo $repository_url; + //echo($result);exit; + if ($result['STATUS'] != 'OK') { + $out['ERROR_CHECK'] = 1; + if ($result['MESSAGE']) { + $out['ERROR_MESSAGE'] = $result['MESSAGE']; + } else { + $out['ERROR_MESSAGE'] = 'Cannot connect to updates server'; + } + } else { + $out['OK_CHECK'] = 1; + if (is_array($result['TO_UPDATE'])) { + foreach ($result['TO_UPDATE'] as $f => $v) { + $out['TO_UPDATE'][] = array('FILE' => $f, 'VERSION' => $v); + } + } else { + $out['NO_UPDATES'] = 1; + } + } - chdir('../../'); - $ignores=SQLSelect("SELECT * FROM ignore_updates ORDER BY NAME"); - $total=count($ignores); - for($i=0;$i<$total;$i++) { - $name=$ignores[$i]['NAME']; - if (is_dir(ROOT.'saverestore/temp/modules/'.$name)) { - $this->removeTree(ROOT.'saverestore/temp/modules/'.$name); - } - if (is_dir(ROOT.'saverestore/temp/templates/'.$name)) { - $this->removeTree(ROOT.'saverestore/temp/templates/'.$name); - } - } + //exec('curl ...') - if ($iframe) { - $this->echonow("Updating files ... "); - } + } + /** + * Title + * + * Description + * + * @access public + */ + function checkEFiles($d, $max_level = 0, $level = 0) + { - // UPDATING FILES DIRECTLY - $this->copyTree(ROOT.'saverestore/temp'.$folder, ROOT, 1); // restore all files - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + $res = array(); - if (file_exists(ROOT.'saverestore/temp'.$folder.'/dump.sql')) { - // data restore - if ($iframe) { - $this->echonow("Restoring database ... "); - } - $this->restoredatabase(ROOT.'saverestore/temp'.$folder.'/dump.sql'); - $this->echonow(" OK
", 'green'); + if (!is_dir($d)) { + return $res; } + if ($dir = @opendir($d)) { + while (($file = readdir($dir)) !== false) { + if (Is_Dir($d . "/" . $file) && ($file != '.') && ($file != '..')) { + //echo "
Dir ".$d."/".$file; + if ($level < $max_level) { + $res2 = $this->checkEFiles($d . "/" . $file, $max_level, ($level + 1)); + if (is_array($res2)) { + $res = array_merge($res, $res2); + } + } + } elseif (Is_File($d . "/" . $file) && + (preg_match('/\.php$/', $file) || preg_match('/\.css$/', $file) || preg_match('/\.html$/', $file) || preg_match('/\.js$/', $file)) + ) { + + if ($file == 'config.php') { + continue; + } + + //echo "
".$d.'/'.$file; + $version = ''; + $content = LoadFile($d . '/' . $file); + if (preg_match('/@version (.+?)\n/is', $content, $m)) { + $version = trim($m[1]); + //echo "
".$d.'/'.$file.' - '.$version; + } elseif (preg_match('/\.class\.php$/is', $file)) { + // echo "
".$d.'/'.$file.' - '.'unknown'; + //$version='unknown'; + } + + if ($version != '') { + $res[$d . '/' . $file] = $version; + } + + } + + } + closedir($dir); + } + return $res; - if ($iframe) { - $this->echonow("Re-installing modules ... "); - } + } - //if (is_dir(ROOT.'saverestore/temp/'.$folder.'modules')) { - // code restore - $source=ROOT.'modules'; - if ($dir = @opendir($source)) { - while (($file = readdir($dir)) !== false) { - if (Is_Dir($source."/".$file) && ($file!='.') && ($file!='..')) { // && !file_exists($source."/".$file."/installed") - @unlink(ROOT."modules/".$file."/installed"); - } - } - } - @unlink(ROOT."modules/control_modules/installed"); + /** + * Title + * + * Description + * + * @access public + */ + function extractVersion($s) + { + $o_version = preg_replace('/\(.+/', '', $s); + $o_version = preg_replace('/[^\d]/', '', $o_version); + $o_version = (float)substr($o_version, 0, 1) . '.' . substr($o_version, 1, strlen($o_version) - 1); + return $o_version; + } - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + /** + * Title + * + * Description + * + * @access public + */ + function isNewer($o_version, $r_version) + { + $o_version = $this->extractVersion($o_version); + $r_version = $this->extractVersion($r_version); - //} + //$r_version+=0.1; // just for testing + //echo $o_version.' to '.$r_version."
"; + if ($o_version < $r_version) { + return 1; + } + return 0; + } - if ($iframe) { - $this->echonow("Rebooting system ... "); - } + /** + * Title + * + * Description + * + * @access public + */ + function getLocalFilesTree($dir, $pattern, $ex_pattern, &$log, $verbose) + { + $res = array(); - @SaveFile(ROOT.'reboot', 'updated'); - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + $destination = $dir; + if (!Is_Dir($destination)) { + return $res; // cannot create destination path + } - $this->config['LATEST_UPDATED_ID']=$out['LATEST_ID']; + if ($dir = @opendir($destination)) { + while (($file = readdir($dir)) !== false) { + if (Is_Dir($destination . "/" . $file) && ($file != '.') && ($file != '..')) { + $sub_ar = $this->getLocalFilesTree($destination . "/" . $file, $pattern, $ex_pattern, $log, $verbose); + $res = array_merge($res, $sub_ar); + } elseif (Is_File($destination . "/" . $file)) { + $fl = array(); + $fl['FILENAME'] = str_replace('//', '/', $destination . "/" . $file); + $fl['FILENAME_SHORT'] = str_replace('//', '/', $file); + $fl['MTIME']=filemtime($fl['FILENAME']); + $fl['SIZE'] = filesize($fl['FILENAME']); + if (preg_match('/' . $pattern . '/is', $fl['FILENAME_SHORT']) && ($ex_pattern == '' || !preg_match('/' . $ex_pattern . '/is', $fl['FILENAME_SHORT']))) { + $res[] = $fl; + } + } + } + closedir($dir); + } - setGlobal('UpdateVersion', $this->config['LATEST_UPDATED_ID']); + return $res; + } - $this->saveConfig(); + /** + * Title + * + * Description + * + * @access public + */ + function upload(&$out, $iframe = 0) + { + + set_time_limit(0); + global $restore; + global $file; + global $file_name; + global $folder; global $with_extensions; - if ($iframe) { - return 1; - } else { - $this->redirect("?mode=clear&ok_msg=".urlencode("Updates Installed!")."&with_extensions=".$with_extensions); + if (!$folder) + $folder = IsWindowsOS() ? '/.' : '/'; + else + $folder = '/' . $folder; + + if ($restore != '') { + //$file=ROOT.'saverestore/'.$restore; + $file = $restore; + $file_name = basename($file); + } elseif ($file != '') { + move_uploaded_file($file, ROOT . 'saverestore/' . $file_name); + $file = $file_name; } - } - /* - require 'Tar.php'; - $tar_object = new Archive_Tar($file); - if ($tar_object->extract(ROOT.'skins/'.$basename)) { - $out['OK_EXT']=1; - } else { - $out['ERR_FORMAT']=1; - } - */ - } + if ($iframe) { + $this->echonow("Applying updates.
"); + } + + if ($file != '' && preg_match('/\.sql$/', $file_name) && file_exists(ROOT . 'saverestore/' . $file)) { + // restore database only + if ($iframe) { + $this->echonow("Restoring database from $file ... "); + } + $this->restoredatabase(ROOT . 'saverestore/' . $file); + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + if ($iframe) { + return 1; + } else { + $this->redirect("?mode=clear&ok_msg=" . urlencode("Database restored!")); + } + } elseif ($file != '' && is_dir($file)) { + if ($iframe) { + $this->echonow("Updating files ... "); + } + $this->copyTree($file, ROOT, 1); // restore all files + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + $db_filename=$file.'/'.DB_NAME . ".sql"; + if (file_exists($db_filename)) { + if ($iframe) { + $this->echonow("Restoring database from $db_filename ... "); + } + $this->restoredatabase($db_filename); + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + } + if ($iframe) { + return 1; + } else { + $this->redirect("?mode=clear&ok_msg=" . urlencode("Database restored!")); + } + } elseif ($file != '') { + // unpack archive + umask(0); + @mkdir(ROOT . 'saverestore/temp', 0777); + chdir(ROOT . 'saverestore/temp'); + if ($iframe) { + $this->echonow("Unpacking $file ... "); + } + if (IsWindowsOS()) { + exec(DOC_ROOT . '/gunzip ../' . $file, $output, $res); + exec(DOC_ROOT . '/tar xvf ../' . str_replace('.tgz', '.tar', $file), $output, $res); + } else { + exec('tar xzvf ../' . $file, $output, $res); + } + @unlink(ROOT . 'saverestore/temp' . $folder . '/config.php'); + + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + + chdir('../../'); + $ignores = SQLSelect("SELECT * FROM ignore_updates ORDER BY NAME"); + $total = count($ignores); + for ($i = 0; $i < $total; $i++) { + $name = $ignores[$i]['NAME']; + if (is_dir(ROOT . 'saverestore/temp/modules/' . $name)) { + $this->removeTree(ROOT . 'saverestore/temp/modules/' . $name); + } + if (is_dir(ROOT . 'saverestore/temp/templates/' . $name)) { + $this->removeTree(ROOT . 'saverestore/temp/templates/' . $name); + } + } + + if ($iframe) { + $this->echonow("Updating files ... "); + } + + // UPDATING FILES DIRECTLY + $this->copyTree(ROOT . 'saverestore/temp' . $folder, ROOT, 1); // restore all files + + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + + if (file_exists(ROOT . 'saverestore/temp' . $folder . '/dump.sql')) { + // data restore + if ($iframe) { + $this->echonow("Restoring database ... "); + } + $this->restoredatabase(ROOT . 'saverestore/temp' . $folder . '/dump.sql'); + $this->echonow(" OK
", 'green'); + } + + + if ($iframe) { + $this->echonow("Re-installing modules ... "); + } + + //if (is_dir(ROOT.'saverestore/temp/'.$folder.'modules')) { + // code restore + $source = ROOT . 'modules'; + if ($dir = @opendir($source)) { + while (($file = readdir($dir)) !== false) { + if (Is_Dir($source . "/" . $file) && ($file != '.') && ($file != '..')) { // && !file_exists($source."/".$file."/installed") + @unlink(ROOT . "modules/" . $file . "/installed"); + } + } + } + @unlink(ROOT . "modules/control_modules/installed"); + + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + if ($iframe) { + $this->echonow("Rebooting system ... "); + } + @SaveFile(ROOT . 'reboot', 'updated'); + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + + $this->config['LATEST_UPDATED_ID'] = $out['LATEST_ID']; + setGlobal('UpdateVersion', $this->config['LATEST_UPDATED_ID']); + $this->saveConfig(); + + if ($iframe) { + return 1; + } else { + $this->redirect("?mode=clear&ok_msg=" . urlencode("Updates Installed!") . "&with_extensions=" . $with_extensions); + } + + } -/** -* Title -* -* Description -* -* @access public -*/ - function dump(&$out, $iframe=0) { - - if ($iframe) { - $this->echonow("Working on backup.
"); - } - - - if (mkdir(ROOT.'saverestore/temp', 0777)) { - // DESIGN - global $design; - if ($design) { - - if ($iframe) { - $this->echonow("Saving design ... "); } - $tar_name.='design_'; - $this->copyTree(ROOT.'templates', ROOT.'saverestore/temp/templates'); - $this->copyTree(ROOT.'img', ROOT.'saverestore/temp/img'); - $this->copyTree(ROOT.'js', ROOT.'saverestore/temp/js'); + /** + * Title + * + * Description + * + * @access public + */ + function dump(&$out, $iframe = 0) + { - - $pt=array('\.css'); - $this->copyFiles(ROOT, ROOT.'saverestore/temp', 0, $pt); + if ($iframe) { + $this->echonow("Working on backup.
"); + } - $pt=array('\.swf'); - $this->copyFiles(ROOT, ROOT.'saverestore/temp', 0, $pt); - $pt=array('\.htc'); - $this->copyFiles(ROOT, ROOT.'saverestore/temp', 0, $pt); + if (mkdir(ROOT . 'saverestore/temp', 0777)) { + // DESIGN + global $design; + if ($design) { - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + if ($iframe) { + $this->echonow("Saving design ... "); + } + $tar_name .= 'design_'; + $this->copyTree(ROOT . 'templates', ROOT . 'saverestore/temp/templates'); + $this->copyTree(ROOT . 'img', ROOT . 'saverestore/temp/img'); + $this->copyTree(ROOT . 'js', ROOT . 'saverestore/temp/js'); - } - // CODE - global $code; - if ($code) { + $pt = array('\.css'); + $this->copyFiles(ROOT, ROOT . 'saverestore/temp', 0, $pt); - if ($iframe) { - $this->echonow("Saving code ... "); - } + $pt = array('\.swf'); + $this->copyFiles(ROOT, ROOT . 'saverestore/temp', 0, $pt); + $pt = array('\.htc'); + $this->copyFiles(ROOT, ROOT . 'saverestore/temp', 0, $pt); - $tar_name.='code_'; - - $this->copyTree(ROOT.'lib', ROOT.'saverestore/temp/lib'); - $this->copyTree(ROOT.'modules', ROOT.'saverestore/temp/modules'); - $this->copyTree(ROOT.'scripts', ROOT.'saverestore/temp/scripts'); - $this->copyTree(ROOT.'languages', ROOT.'saverestore/temp/languages'); + if ($iframe) { + $this->echonow(" OK
", 'green'); + } - $pt=array('\.php'); - $this->copyFiles(ROOT, ROOT.'saverestore/temp', 0, $pt); - @unlink(ROOT.'saverestore/temp/config.php'); - $this->copyTree(ROOT.'forum', ROOT.'saverestore/temp/forum'); - @unlink(ROOT.'saverestore/temp/forum/config.php'); + } - if (!$design) { - $this->copyTree(ROOT.'js', ROOT.'saverestore/temp/js'); - $this->copyTree(ROOT.'templates', ROOT.'saverestore/temp/templates'); - } + // CODE + global $code; + if ($code) { - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + if ($iframe) { + $this->echonow("Saving code ... "); + } - } + $tar_name .= 'code_'; - // DATA - global $data; - if ($data) { + $this->copyTree(ROOT . 'lib', ROOT . 'saverestore/temp/lib'); + $this->copyTree(ROOT . 'modules', ROOT . 'saverestore/temp/modules'); + $this->copyTree(ROOT . 'scripts', ROOT . 'saverestore/temp/scripts'); + $this->copyTree(ROOT . 'languages', ROOT . 'saverestore/temp/languages'); - if ($iframe) { - $this->echonow("Saving data ... "); - } + $pt = array('\.php'); + $this->copyFiles(ROOT, ROOT . 'saverestore/temp', 0, $pt); + @unlink(ROOT . 'saverestore/temp/config.php'); - $tar_name.='data_'; - $this->copyTree(ROOT.'cms', ROOT.'saverestore/temp/cms'); - $this->backupdatabase(ROOT.'saverestore/temp/dump.sql'); + $this->copyTree(ROOT . 'forum', ROOT . 'saverestore/temp/forum'); + @unlink(ROOT . 'saverestore/temp/forum/config.php'); - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + if (!$design) { + $this->copyTree(ROOT . 'js', ROOT . 'saverestore/temp/js'); + $this->copyTree(ROOT . 'templates', ROOT . 'saverestore/temp/templates'); + } + if ($iframe) { + $this->echonow(" OK
", 'green'); + } - } - - // FILES - global $files; - if ($files) { - $tar_name.='files_'; - } - - - // packing into tar.gz - $tar_name .= date('Y-m-d__h-i-s'); - $tar_name .= IsWindowsOS() ? '.tar' : '.tgz'; - - if (isset($out['BACKUP'])) - $tar_name = 'backup_' . $tar_name; - - if ($iframe) { - $this->echonow("Packing $tar_name ... "); - } - - - if (IsWindowsOS()) - { - $result=exec('tar.exe --strip-components=2 -C ./saverestore/temp/ -cvf ./saverestore/'.$tar_name.' ./'); - $new_name=str_replace('.tar', '.tar.gz', $tar_name); - $result=exec('gzip.exe ./saverestore/'.$tar_name); - if (file_exists('./saverestore/'.$new_name)) { - $tar_name = $new_name; - } - } - else - { - chdir(ROOT.'saverestore/temp'); - exec('tar cvzf ../'.$tar_name.' .'); - chdir('../../'); - } - - if ($iframe) { - $this->echonow(" OK
", 'green'); - } + } - if (defined('SETTINGS_BACKUP_PATH') && SETTINGS_BACKUP_PATH!='' && file_exists(ROOT.'saverestore/'.$tar_name)) { - if ($iframe) { - $this->echonow("Copying to ".$dest.$tar_name." ... "); - } - $dest=SETTINGS_BACKUP_PATH; - @copy(ROOT.'saverestore/'.$tar_name, $dest.$tar_name); - if ($iframe) { - $this->echonow(" OK
", 'green'); + // DATA + global $data; + if ($data) { + + if ($iframe) { + $this->echonow("Saving data ... "); + } + + $tar_name .= 'data_'; + $this->copyTree(ROOT . 'cms', ROOT . 'saverestore/temp/cms'); + $this->backupdatabase(ROOT . 'saverestore/temp/dump.sql'); + + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + + + } + + // FILES + global $files; + if ($files) { + $tar_name .= 'files_'; + } + + + // packing into tar.gz + $tar_name .= date('Y-m-d__h-i-s'); + $tar_name .= IsWindowsOS() ? '.tar' : '.tgz'; + + if (isset($out['BACKUP'])) + $tar_name = 'backup_' . $tar_name; + + if ($iframe) { + $this->echonow("Packing $tar_name ... "); + } + + + if (IsWindowsOS()) { + $result = exec('tar.exe --strip-components=2 -C ./saverestore/temp/ -cvf ./saverestore/' . $tar_name . ' ./'); + $new_name = str_replace('.tar', '.tar.gz', $tar_name); + $result = exec('gzip.exe ./saverestore/' . $tar_name); + if (file_exists('./saverestore/' . $new_name)) { + $tar_name = $new_name; + } + } else { + chdir(ROOT . 'saverestore/temp'); + exec('tar cvzf ../' . $tar_name . ' .'); + chdir('../../'); + } + + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + + + if (defined('SETTINGS_BACKUP_PATH') && SETTINGS_BACKUP_PATH != '' && file_exists(ROOT . 'saverestore/' . $tar_name)) { + if ($iframe) { + $this->echonow("Copying to " . $dest . $tar_name . " ... "); + } + $dest = SETTINGS_BACKUP_PATH; + @copy(ROOT . 'saverestore/' . $tar_name, $dest . $tar_name); + if ($iframe) { + $this->echonow(" OK
", 'green'); + } + } + + + } + return $tar_name; } - } + /** + * Title + * + * Description + * + * @access public + */ + function restoredatabase($filename) + { + $mysql_path = (substr(php_uname(), 0, 7) == "Windows") ? SERVER_ROOT . "/server/mysql/bin/mysql" : 'mysql'; + $mysqlParam = " -u " . DB_USER; + if (DB_PASSWORD != '') $mysqlParam .= " -p" . DB_PASSWORD; + $mysqlParam .= " " . DB_NAME . " <" . $filename; + exec($mysql_path . $mysqlParam); + SQLExec("DELETE FROM cached_values"); + setGlobal('cycle_mainRun',time()); + } - } - return $tar_name; - } + /** + * Title + * + * Description + * + * @access public + */ + function backupdatabase($filename) + { + if (defined('PATH_TO_MYSQLDUMP')) + $pathToMysqlDump = PATH_TO_MYSQLDUMP; + else + $pathToMysqlDump = IsWindowsOS() ? SERVER_ROOT . "/server/mysql/bin/mysqldump" : "/usr/bin/mysqldump"; + + exec($pathToMysqlDump . " --user=" . DB_USER . " --password=" . DB_PASSWORD . " --no-create-db --add-drop-table --databases " . DB_NAME . ">" . $filename); + } -/** -* Title -* -* Description -* -* @access public -*/ - function restoredatabase($filename) { - $data=LoadFile($filename); - $data=str_replace("\r", "", $data); - $data.="\n"; - $query=explode(";\n",$data); - for ($i=0;$i < count($query)-1;$i++) { - if ($query[$i]{0}!="#") SQLExec($query[$i]); - } - } + /** + * removeTree + * + * remove directory tree + * + * @access public + */ + function removeTree($destination, $iframe = 0) + { -/** -* Title -* -* Description -* -* @access public -*/ - function backupdatabase($filename) { - if (defined('PATH_TO_MYSQLDUMP')) - $pathToMysqlDump = PATH_TO_MYSQLDUMP; - else - $pathToMysqlDump = IsWindowsOS() ? SERVER_ROOT . "/server/mysql/bin/mysqldump" : "/usr/bin/mysqldump"; + $res = 1; - exec($pathToMysqlDump . " --user=".DB_USER." --password=" . DB_PASSWORD . " --no-create-db --add-drop-table --databases " . DB_NAME . ">" . $filename); -} + if (!Is_Dir($destination)) { + return 0; // cannot create destination path + } + if ($dir = @opendir($destination)) { -/** -* removeTree -* -* remove directory tree -* -* @access public -*/ - function removeTree($destination, $iframe=0) { + if ($iframe) { + $this->echonow("Removing dir $destination ... "); + } - $res=1; - if (!Is_Dir($destination)) { - return 0; // cannot create destination path - } - if ($dir = @opendir($destination)) { + while (($file = readdir($dir)) !== false) { + if (Is_Dir($destination . "/" . $file) && ($file != '.') && ($file != '..')) { + $res = $this->removeTree($destination . "/" . $file); + } elseif (Is_File($destination . "/" . $file)) { + $res = @unlink($destination . "/" . $file); + } + } + closedir($dir); + $res = @rmdir($destination); - if ($iframe) { - $this->echonow("Removing dir $destination ... "); - } + if ($iframe) { + $this->echonow("OK
", "green"); + } - while (($file = readdir($dir)) !== false) { - if (Is_Dir($destination."/".$file) && ($file!='.') && ($file!='..')) { - $res=$this->removeTree($destination."/".$file); - } elseif (Is_File($destination."/".$file)) { - $res=@unlink($destination."/".$file); + } + return $res; } - } - closedir($dir); - $res=@rmdir($destination); - if ($iframe) { - $this->echonow("OK
", "green"); - } + /** + * copyTree + * + * Copy source directory tree to destination directory + * + * @access public + */ + function copyTree($source, $destination, $over = 0, $patterns = 0) + { - } - return $res; - } + $res = 1; + + //Remove last slash '/' in source and destination - slash was added when copy + $source = preg_replace("#/$#", "", $source); + $destination = preg_replace("#/$#", "", $destination); + + if (!Is_Dir($source)) { + return 0; // cannot create destination path + } + + if (!Is_Dir($destination)) { + if (!mkdir($destination)) { + return 0; // cannot create destination path + } + } + + + if ($dir = @opendir($source)) { + while (($file = readdir($dir)) !== false) { + if (Is_Dir($source . "/" . $file) && ($file != '.') && ($file != '..')) { + $res = $this->copyTree($source . "/" . $file, $destination . "/" . $file, $over, $patterns); + } elseif (Is_File($source . "/" . $file) && (!file_exists($destination . "/" . $file) || $over)) { + if (!is_array($patterns)) { + $ok_to_copy = 1; + } else { + $ok_to_copy = 0; + $total = count($patterns); + for ($i = 0; $i < $total; $i++) { + if (preg_match('/' . $patterns[$i] . '/is', $file)) { + $ok_to_copy = 1; + } + } + } + if ($ok_to_copy) { + $res = copy($source . "/" . $file, $destination . "/" . $file); + } + } + } + closedir($dir); + } + return $res; -/** -* copyTree -* -* Copy source directory tree to destination directory -* -* @access public -*/ - function copyTree($source, $destination, $over=0, $patterns=0) { - - - $res=1; - - //Remove last slash '/' in source and destination - slash was added when copy - $source = preg_replace("#/$#", "", $source); - $destination = preg_replace("#/$#", "", $destination); - - if (!Is_Dir($source)) { - return 0; // cannot create destination path - } - - if (!Is_Dir($destination)) { - if (!mkdir($destination)) { - return 0; // cannot create destination path - } - } - - - if ($dir = @opendir($source)) { - while (($file = readdir($dir)) !== false) { - if (Is_Dir($source."/".$file) && ($file!='.') && ($file!='..')) { - $res=$this->copyTree($source."/".$file, $destination."/".$file, $over, $patterns); - } elseif (Is_File($source."/".$file) && (!file_exists($destination."/".$file) || $over)) { - if (!is_array($patterns)) { - $ok_to_copy=1; - } else { - $ok_to_copy=0; - $total=count($patterns); - for($i=0;$i<$total;$i++) { - if (preg_match('/'.$patterns[$i].'/is', $file)) { - $ok_to_copy=1; - } - } - } - if ($ok_to_copy) { - $res=copy($source."/".$file, $destination."/".$file); - } } - } - closedir($dir); - } - return $res; - - } - - function copyFile($source, $destination) { - $tmp=explode('/', $destination); - $total=count($tmp); - if ($total>0) { - $d=$tmp[0]; - for($i=1;$i<($total-1);$i++) { - $d.='/'.$tmp[$i]; - if (!is_dir($d)) { - mkdir($d); + + function copyFile($source, $destination) + { + $tmp = explode('/', $destination); + $total = count($tmp); + if ($total > 0) { + $d = $tmp[0]; + for ($i = 1; $i < ($total - 1); $i++) { + $d .= '/' . $tmp[$i]; + if (!is_dir($d)) { + mkdir($d); + } + } + } + return copy($source, $destination); + } - } - } - return copy($source, $destination); - - } - - function copyFiles($source, $destination, $over=0, $patterns=0) { - - $res=1; - - if (!Is_Dir($source)) { - return 0; // cannot create destination path - } - - if (!Is_Dir($destination)) { - if (!mkdir($destination)) { - return 0; // cannot create destination path - } - } - - - if ($dir = @opendir($source)) { - while (($file = readdir($dir)) !== false) { - if (Is_Dir($source."/".$file) && ($file!='.') && ($file!='..')) { - //$res=$this->copyTree($source."/".$file, $destination."/".$file, $over, $patterns); - } elseif (Is_File($source."/".$file) && (!file_exists($destination."/".$file) || $over)) { - if (!is_array($patterns)) { - $ok_to_copy=1; - } else { - $ok_to_copy=0; - $total=count($patterns); - for($i=0;$i<$total;$i++) { - if (preg_match('/'.$patterns[$i].'/is', $file)) { - $ok_to_copy=1; - } - } - } - if ($ok_to_copy) { - $res=copy($source."/".$file, $destination."/".$file); - } + + function copyFiles($source, $destination, $over = 0, $patterns = 0) + { + + $res = 1; + + if (!Is_Dir($source)) { + return 0; // cannot create destination path + } + + if (!Is_Dir($destination)) { + if (!mkdir($destination)) { + return 0; // cannot create destination path + } + } + + + if ($dir = @opendir($source)) { + while (($file = readdir($dir)) !== false) { + if (Is_Dir($source . "/" . $file) && ($file != '.') && ($file != '..')) { + //$res=$this->copyTree($source."/".$file, $destination."/".$file, $over, $patterns); + } elseif (Is_File($source . "/" . $file) && (!file_exists($destination . "/" . $file) || $over)) { + if (!is_array($patterns)) { + $ok_to_copy = 1; + } else { + $ok_to_copy = 0; + $total = count($patterns); + for ($i = 0; $i < $total; $i++) { + if (preg_match('/' . $patterns[$i] . '/is', $file)) { + $ok_to_copy = 1; + } + } + } + if ($ok_to_copy) { + $res = copy($source . "/" . $file, $destination . "/" . $file); + } + } + } + closedir($dir); + } + return $res; } - } - closedir($dir); - } - return $res; - } -/* -*/ + /* + */ -function ftpget($conn_id, $local_file, $remote_file, $mode) { - global $lset_dirs; - $l_dir=dirname($local_file); - if (!isSet($lset_dirs[$l_dir])) { + function ftpget($conn_id, $local_file, $remote_file, $mode) + { + global $lset_dirs; + $l_dir = dirname($local_file); + if (!isSet($lset_dirs[$l_dir])) { // echo "zz"; - if (!is_dir($l_dir)) { - $this->lmkdir($l_dir); - } - $lset_dirs[$l_dir]=1; - } - $res=ftp_get($conn_id, $local_file, $remote_file, $mode); - return $res; -} + if (!is_dir($l_dir)) { + $this->lmkdir($l_dir); + } + $lset_dirs[$l_dir] = 1; + } + $res = ftp_get($conn_id, $local_file, $remote_file, $mode); + return $res; + } -function ftpmkdir($conn_id, $ftp_dir) -{ - global $set_dirs; - - $tmp = explode('/', $ftp_dir); - $res_dir = $tmp[0]; - $tmpCnt = count($tmp); - - for ($i = 1; $i < $tmpCnt; $i++) - { - $res_dir .= '/' . $tmp[$i]; - - if (!isset($set_dirs[$res_dir])) - { - $set_dirs[$res_dir] = 1; - - if (!@ftp_chdir($conn_id, $res_dir)) - { - ftp_mkdir($conn_id,$res_dir); - } - } - } -} + function ftpmkdir($conn_id, $ftp_dir) + { + global $set_dirs; -function ftpdelete($conn_id, $filename) { - $res=ftp_delete($conn_id, $filename); - return $res; -} + $tmp = explode('/', $ftp_dir); + $res_dir = $tmp[0]; + $tmpCnt = count($tmp); + for ($i = 1; $i < $tmpCnt; $i++) { + $res_dir .= '/' . $tmp[$i]; -function ftpput($conn_id, $remote_file, $local_file, $mode) { - global $set_dirs; - $ftp_dir=dirname($remote_file); - if (!IsSet($set_dirs[$ftp_dir])) { - if (! @ftp_chdir($conn_id, $ftp_dir)) { - $this->ftpmkdir($conn_id,$ftp_dir) ; - } - $set_dirs[$ftp_dir]=1; - } - $res=ftp_put( $conn_id, $remote_file, $local_file, $mode); - return $res; -} + if (!isset($set_dirs[$res_dir])) { + $set_dirs[$res_dir] = 1; + if (!@ftp_chdir($conn_id, $res_dir)) { + ftp_mkdir($conn_id, $res_dir); + } + } + } + } -/** -* FrontEnd -* -* Module frontend -* -* @access public -*/ -function usual(&$out) { - $this->admin($out); -} -/** -* Install -* -* Module installation routine -* -* @access private -*/ - function install($parent_name="") { - if (!Is_Dir(ROOT."./saverestore")) { - mkdir(ROOT."./saverestore", 0777); - } - parent::install($parent_name); - } + function ftpdelete($conn_id, $filename) + { + $res = ftp_delete($conn_id, $filename); + return $res; + } + + + function ftpput($conn_id, $remote_file, $local_file, $mode) + { + global $set_dirs; + $ftp_dir = dirname($remote_file); + if (!IsSet($set_dirs[$ftp_dir])) { + if (!@ftp_chdir($conn_id, $ftp_dir)) { + $this->ftpmkdir($conn_id, $ftp_dir); + } + $set_dirs[$ftp_dir] = 1; + } + $res = ftp_put($conn_id, $remote_file, $local_file, $mode); + return $res; + } + + + /** + * FrontEnd + * + * Module frontend + * + * @access public + */ + function usual(&$out) + { + $this->admin($out); + } + + /** + * Install + * + * Module installation routine + * + * @access private + */ + function install($parent_name = "") + { + if (!Is_Dir(ROOT . "./saverestore")) { + mkdir(ROOT . "./saverestore", 0777); + } + parent::install($parent_name); + } // -------------------------------------------------------------------- } + /* * * TW9kdWxlIGNyZWF0ZWQgU2VwIDE2LCAyMDA4IHVzaW5nIFNlcmdlIEouIHdpemFyZCAoQWN0aXZlVW5pdCBJbmMgd3d3LmFjdGl2ZXVuaXQuY29tKQ== diff --git a/modules/saverestore/update_iframe.php b/modules/saverestore/update_iframe.php index 5dbb53bbd..032fabaa3 100644 --- a/modules/saverestore/update_iframe.php +++ b/modules/saverestore/update_iframe.php @@ -61,6 +61,7 @@ $sv->echonow("Removing temporary files ... "); $sv->removeTree(ROOT.'saverestore/temp'); + @unlink(ROOT."modules/control_modules/installed"); $sv->echonow(" OK
", 'green'); $sv->echonow("Main system updated!
", 'green'); diff --git a/templates/saverestore/action_admin.html b/templates/saverestore/action_admin.html index 68798c44a..f072e1883 100644 --- a/templates/saverestore/action_admin.html +++ b/templates/saverestore/action_admin.html @@ -81,16 +81,23 @@ [#if FILES#]  
- +
[#begin FILES#] - - - + + [#if "<#CLEAR_FIRST#>"!="1"#] - + + [#endif#] + + [#if FILESIZE!=""#] + + + [#else#] + [#endif#] - [#end FILES#]
[#FILENAME#][#FILESIZE#] MbDownload[#TITLE#][#if FILESIZE!=""#][#FILESIZE#] Mb[#else#] [#endif#]<#LANG_RESTORE#><#LANG_RESTORE#>Download + +  X
diff --git a/templates/system_errors/action_admin.html b/templates/system_errors/action_admin.html index ca831c03e..95b6b65c3 100644 --- a/templates/system_errors/action_admin.html +++ b/templates/system_errors/action_admin.html @@ -20,6 +20,7 @@ <#LANG_HISTORY#> +  
[#endif ID#] [#if TAB=""#] [#inc system_errors_edit_default.html#] diff --git a/templates/system_errors/system_errors_edit_history.html b/templates/system_errors/system_errors_edit_history.html index e3cbf1c27..b78eaaf95 100644 --- a/templates/system_errors/system_errors_edit_history.html +++ b/templates/system_errors/system_errors_edit_history.html @@ -54,7 +54,7 @@ [#begin HISTORY#] [#ADDED#] - [#COMMENTS#] +
[#COMMENTS#]
[#end HISTORY#] diff --git a/write_error.php b/write_error.php index e6b5a0d04..d30e14e98 100644 --- a/write_error.php +++ b/write_error.php @@ -15,5 +15,5 @@ if ($error) { echo $error; - DebMes("JAVASCRIPT Error: " . $error); + //DebMes("JAVASCRIPT Error: " . $error); }