From 397c6d5038da36152d94c7dfefdc4a0e786f62f2 Mon Sep 17 00:00:00 2001 From: justnx Date: Thu, 18 Jul 2013 14:09:22 +0200 Subject: [PATCH] Removed discontinued Update/AutoUpdate logic --- app/bin/upgrade-to-v3-autoup.php | 595 --------- app/cron/class.AutoupdateProcess.php | 181 --- .../Distribution/class.AutoUpdateClient.php | 1121 ----------------- .../LibWebta/library/Distribution/tests.php | 92 -- app/src/LibWebta/tests/tests.php | 5 +- app/src/autoload.php | 3 +- app/src/class.AutoupEventHandler.php | 13 - app/src/prepend.inc.php | 5 +- app/src/structs/struct.CONFIG.php | 15 +- app/src/types/enum.UPDATE_STATUS.php | 31 - app/templates/admin/product_info.tpl | 45 +- app/templates/updating.tpl | 5 - app/www/admin/product_info.php | 31 - app/www/admin/src/prepend.inc.php | 11 +- app/www/admin/update_report.php | 16 - app/www/admin/updates.php | 161 --- app/www/client/src/prepend.inc.php | 6 - app/www/server/whois.php | 6 +- app/www/src/prepend.inc.php | 13 - app/www/updating.php | 5 - sql/database.sql | 1 - 21 files changed, 9 insertions(+), 2352 deletions(-) delete mode 100644 app/bin/upgrade-to-v3-autoup.php delete mode 100644 app/cron/class.AutoupdateProcess.php delete mode 100644 app/src/LibWebta/library/Distribution/class.AutoUpdateClient.php delete mode 100644 app/src/LibWebta/library/Distribution/tests.php delete mode 100644 app/src/class.AutoupEventHandler.php delete mode 100644 app/src/types/enum.UPDATE_STATUS.php delete mode 100644 app/templates/updating.tpl delete mode 100644 app/www/admin/update_report.php delete mode 100644 app/www/admin/updates.php delete mode 100644 app/www/src/prepend.inc.php delete mode 100644 app/www/updating.php diff --git a/app/bin/upgrade-to-v3-autoup.php b/app/bin/upgrade-to-v3-autoup.php deleted file mode 100644 index abc63b1..0000000 --- a/app/bin/upgrade-to-v3-autoup.php +++ /dev/null @@ -1,595 +0,0 @@ -StartTrans(); - - try - { - if (count($Db->GetAll("SHOW COLUMNS FROM contacts LIKE 'groupname'")) == 1) - { - $mess = "Database {$Db->database} is already upgraded to v3"; - print $mess."\n"; - - Log::Log($mess, E_USER_NOTICE); - exit(); - } - - // run migratins - foreach ($migration_query_list as $sql) - { - Log::Log(sprintf("Executing migration SQL query: %s", $sql), E_USER_NOTICE); - $Db->Execute($sql); - } - - Log::Log("Execute EPPDRS_Upgrade_Autoup::Run", E_USER_NOTICE); - - // run convertation - EPPDRS_Upgrade_Autoup::Run($Db); - - // run cleanup - foreach ($cleanup_query_list as $sql) - { - Log::Log(sprintf("Execute cleanup SQL: %s", $sql), E_USER_NOTICE); - $Db->Execute($sql); - } - } - catch (Exception $e) - { - print "Error: {$e->getMessage()}\n"; - Log::Log(sprintf("Error: %s", $e->getMessage()), E_USER_ERROR); - $Db->RollbackTrans(); - exit(); - } - - $Db->CompleteTrans(); - - - - - class EPPDRS_Upgrade_Autoup - { - private $Db; - - /** - * @var RegistryModuleFactory - */ - private $RegistryFactory; - - /** - * @var Crypto - */ - private $Crypto; - - /** - * @var array - */ - private $TableList; - - private $ModuleConfigKeyMap = array( - 'EPPGR' => array( - // old => new - 'CLID' => 'CLID', - 'UseSSL' => 'UseSSLCert', - 'Password' => 'Password', - 'ClientPrefix' => 'ClientPrefix', - 'SSLpwd' => 'SSLpwd', - 'Login' => 'Login', - 'ServerHost' => 'ServerHost' - // SSLCertPath - ), - 'EPPLU' => array( - // old => new - 'Login' => 'Login', - 'Password' => 'Password', - 'ServerHost' => 'ServerHost', - 'ServerPort' => 'ServerPort' - ), - 'OnlineNIC' => array( - // old => new - 'Login' => 'Login', - 'Password' => 'Password', - 'ServerHost' => 'ServerHost', - 'ServerPort' => 'ServerPort' - ), - 'SRSPlus' => array( - // old => new - 'email' => 'Email', - 'Login' => 'Login', - 'testmode' => 'TestMode', - 'host' => 'Host', - 'gpgpass' => 'GPGPass', - 'gpg_path' => 'GPGPath', - 'gpg_home_dir' => 'GPGHomeDir' - ), - 'COCCAEPP1' => array( - // old => new - 'Login' => 'Login', - 'Password' => 'Password', - 'ServerHost' => 'ServerHost', - 'ServerPort' => 'ServerPort' - ), - 'COCCAEPP2' => array( - // old => new - 'Login' => 'Login', - 'Password' => 'Password', - 'ServerHost' => 'ServerHost', - 'ServerPort' => 'ServerPort' - ), - 'COCCAEPP3' => array( - // old => new - 'Login' => 'Login', - 'Password' => 'Password', - 'ServerHost' => 'ServerHost', - 'ServerPort' => 'ServerPort' - ) - ); - - private $ModuleNameMap = array( - // old => new - 'EPPGR' => 'EPPGR', - 'EPPLU' => 'EPPLU', - 'OnlineNIC' => 'OnlineNIC', - 'SRSPlus' => 'SRSPlus', - 'GenericEPP' => 'GenericEPP', - // Â ñòàðîé âåðñèè ïåðåïóòàíû ìîäóëè COCCAEPP1 è COCCAEPP2 - 'ccTLDCOCCA1' => 'COCCAEPP2', - 'ccTLDCOCCA2' => 'COCCAEPP1', - 'ccTLDCOCCA3' => 'COCCAEPP3' - ); - - private $ModuleNameMapFlip = array(); - - - private $FailedActiveDomains = array(); - - //// - // Options - // - private $SaveFailedAsPending = true; - private $GPGHomeDir = '/root/.gnupg'; - - public function __construct($Db) - { - foreach ($options as $flag => $b) - { - $this->{$flag} = $b; - } - - $this->Db = $Db; - $this->RegistryFactory = RegistryModuleFactory::GetInstance(); - $this->Crypto = $GLOBALS['Crypto']; - - - $this->ModuleNameMapFlip = array_flip($this->ModuleNameMap); - } - - public function GetSkipList () - { - return array( - //'ConvertConfig', - //'ConvertRegistryModules', - //'ConvertModulesPricing', - //'ConvertPaymentModules', - //'ConvertUsers', - //'ConvertDiscounts', - //'ConvertInvoices', - //'ConvertZones', - //'ConvertUserSettings', - // Works only on customer server or our Web3 - //'ConvertDomains', - //'ConvertActiveDomains', - //'ConvertInactiveDomains', - //'ConvertContacts' - ); - } - - public function ConvertRegistryModules () - { - $this->Log('Convert registry modules'); - - //// - // Modules - // - $module_rset = $this->Db->GetAll('SELECT * FROM modules'); - foreach ($module_rset as &$row) - { - // Map old module name to new - $row['name'] = $this->ModuleNameMap[$row['name']]; - } - $this->TruncateTable('modules'); - $this->BulkInsert('modules', $module_rset); - - - //// - // Modules configuration - // - $this->CreateTableCopy('modules_config'); - $this->TruncateTable('modules_config'); - foreach ($this->ModuleConfigKeyMap as $module_name => $key_map) - { - // Get old module name - $old_module_name = $this->ModuleNameMapFlip[$module_name]; - - // Check that module was installed - $module_setuped = (int)$this->Db->GetOne( - 'SELECT COUNT(*) FROM modules WHERE name = ?', - array($old_module_name) - ); - if (!$module_setuped) - { - // Module was not installed - continue; - } - - // Get module configuration from old DB - $module_config = array(); - foreach ($key_map as $key_old => $key_new) - { - $module_config[$key_new] = $this->Db->GetOne( - 'SELECT value FROM v2_modules_config WHERE `key` = ? AND module_name = ?', - array($key_old, $old_module_name) - ); - } - - // Apply module specific configuration - if ($module_name == 'EPPGR') - { - $module_config['SSLCertPath'] = $GLOBALS['modules_path'] . '/registries/EPPGR/ssl/cert.pem'; - } - - - $Crypto = $GLOBALS['Crypto']; - $Registry = $this->RegistryFactory->GetRegistryByName($module_name); - - $this->Log("Convert $module_name config"); - foreach ($Registry->GetModule()->GetConfigurationForm()->ListFields() as $Field) - { - $this->Db->Execute( - "INSERT modules_config - SET - `title` = ?, - `type` = ?, - `key` = ?, - `value` = ?, - `module_name` = ?", - array( - $Field->Title, - $Field->FieldType, - $Field->Name, - $Crypto->Encrypt($module_config[$Field->Name], LICENSE_FLAGS::REGISTERED_TO), - $module_name - ) - ); - } - } - } - - public function ConvertPricing () - { - $this->Log('Convert modules pricing'); - - // Covert tlds - $tld_rowset = $this->Db->GetAll('SELECT * FROM tlds'); - foreach ($tld_rowset as &$row) - { - $row['modulename'] = $this->ModuleNameMap[$row['modulename']]; - } - - $this->TruncateTable('tlds'); - $this->BulkInsert('tlds', $tld_rowset); - } - - public function ConvertUsers () - { - $this->Log('Convert users'); - - $skip_fields = array( - 'opt_canMtech', 'opt_canMbill', - 'opt_canbulkregister', 'isres', - 'tax', 'idnumber', 'mobile' - ); - $phone_fields = array( - 'phone', 'fax' - ); - $Phone = Phone::GetInstance(); - - $user_data = $this->Db->GetAll('SELECT * FROM users'); - foreach ($user_data as &$row) - { - // Process skipped fields - foreach ($skip_fields as $f) - { - unset($row[$f]); - } - - // Convert phone and fax - foreach ($phone_fields as $f) - { - if ($row[$f]) - { - $chunks = str_split(preg_replace("/[^0-9]+/", "", $row[$f]), 3); - $e164 = trim("+".array_shift($chunks).".".implode("", $chunks)); - $row[$f] = $Phone->E164ToPhone($e164); - } - } - } - - $this->TruncateTable('users'); - $this->BulkInsert('users', $user_data); - } - - public function ConvertPaymentModules () - { - $this->Log('Convert payment modules'); - - // Copy pmodules table - $pmodule_rset = $this->Db->GetAll('SELECT * FROM pmodules'); - foreach ($pmodule_rset as &$row) - { - if ($row['name'] == 'offline_payment') - { - $row['name'] = 'OfflineBank'; - } - } - $this->TruncateTable('pmodules'); - $this->BulkInsert('pmodules', $pmodule_rset); - - - // For each pmodule copy config settings - $pmodule_config = array(); - $Crypto = $GLOBALS['Crypto']; - foreach ($pmodule_rset as $pmodule) - { - // Get old config form for current pmodule - $rset = $this->Db->GetAll( - 'SELECT * FROM pmodules_config WHERE module_name = ?', - array($pmodule['name']) - ); - foreach ($rset as $row) - { - // Encrypt config value - $row['value'] = $this->Crypto->Encrypt($row['key'], LICENSE_FLAGS::REGISTERED_TO); - // Push it to pmodule config - $pmodule_config[] = $row; - } - } - - $this->TruncateTable('pmodules_config'); - $this->BulkInsert('pmodules_config', $pmodule_config); - } - - - public function ConvertInvoices () - { - $this->Log('Convert invoices'); - - $invoice_data = $this->Db->GetAll('SELECT * FROM invoices'); - foreach ($invoice_data as &$row) - { - if ($row['gate'] == 'offline_payment') - { - $row['gate'] = 'OfflineBank'; - } - unset($row['proccessed']); - } - $this->TruncateTable('invoices'); - $this->BulkInsert('invoices', $invoice_data); - } - - public function ConvertContacts () - { - $map = array( - 'disclose_name' => 'name', - 'disclose_org' => 'org', - 'disclose_addr' => 'addr', - 'disclose_voice' => 'voice', - 'disclose_fax' => 'fax', - 'disclose_email' => 'email' - ); - foreach ($map as $table_field => $name) - { - $sql = " - INSERT INTO contacts_discloses (`contactid`, `field_name`, `value`) - SELECT c.clid, '{$name}', c.{$table_field} - FROM contacts AS c - WHERE c.{$table_field} = '1' - "; - - $this->Db->Execute(" - INSERT INTO contacts_discloses (`contactid`, `field_name`, `value`) - SELECT c.clid, '{$name}', c.{$table_field} - FROM contacts AS c - WHERE c.{$table_field} = '1' - "); - } - - $contact_data = $this->Db->GetAll('SELECT * FROM contacts'); - foreach ($contact_data as $i => &$contact_row) - { - $Registry = $this->RegistryFactory->GetRegistryByExtension($contact_row['TLD'], $db_check = false); - $Contact = $Registry->NewContactInstance($contact_row['type']); - $contact_row['groupname'] = $Contact->GroupName; - $contact_row['strict_fields'] = '0'; - } - $this->TruncateTable('contacts'); - $this->BulkInsert('contacts', $contact_data); - - - $Phone = Phone::GetInstance(); - - $phone_data = $this->Db->GetAll(" - SELECT * FROM contacts_data - WHERE `field` = 'voice' OR `field` = 'fax' - "); - - foreach ($phone_data as $phone_row) - { - if ($phone_row['value']) - { - $chunks = str_split(preg_replace("/[^0-9]+/", "", $phone_row['value']), 3); - $e164 = trim("+".array_shift($chunks).".".implode("", $chunks)); - $phone_row['value'] = $Phone->E164ToPhone($e164); - - $this->Db->Execute(" - INSERT INTO contacts_data SET `contactid` = ?, `field` = ?, `value` = ?", - array($phone_row['contactid'], "{$phone_row['field']}_display", $phone_row['value']) - ); - } - } - } - - private function Log ($message, $level=E_USER_NOTICE) - { - Log::Log(sprintf("%s", $message), $level); - - if ($level == E_USER_ERROR) - { - print "Error: $message\n"; - } - else - { - print "$message\n"; - } - flush(); - } - - private function CreateTableCopy ($table1 /* table2 ... tableN */) - { - foreach (func_get_args() as $table) - { - $this->Db->Execute("CREATE TEMPORARY TABLE v2_{$table} AS SELECT * FROM {$table}"); - } - } - - private function BulkInsert ($table, $data) - { - if (!count($data)) - return; - - $this->Log(sprintf('Insert data in new %s', $table)); - - // Create data bind - $bind = array(); - foreach (array_keys($data[0]) as $k) - { - $bind[] = "`$k` = ?"; - } - $stmt = 'INSERT INTO ' . $table . ' SET ' . join(', ', $bind); - - foreach ($data as $row) - { - $this->Db->Execute($stmt, array_values($row)); - } - } - - private function Insert ($table, $row) - { - // Create data bind - $bind = array(); - foreach (array_keys($row) as $k) - { - $bind[] = "`$k` = ?"; - } - $stmt = 'INSERT INTO ' . $table . ' SET ' . join(', ', $bind); - - $this->Db->Execute($stmt, array_values($row)); - } - - private function TruncateTable ($table1 /* table2 ... tableN */) - { - foreach ($tables=func_get_args() as $table) - $this->Db->Execute("TRUNCATE TABLE {$table}"); - } - - private function PingDatabase ($Db) - { - if ($Db->connectionId instanceof mysqli) - { - $Db->connectionId->ping(); - } - } - - private function OldTableExists ($table1 /* table2 ... tableN */) - { - $arg_table_list = func_get_args(); - $intersect = array_values(array_intersect($this->TableList, $arg_table_list)); - sort($intersect); - sort($arg_table_list); - - return $intersect == $arg_table_list; - } - - private function OldColumnExists ($table, $column) - { - return count($this->DbOld->GetAll("SHOW COLUMNS FROM {$table} LIKE '{$column}'")) == 1; - } - - public static function Run ($Db) - { - $Upgrade = new EPPDRS_Upgrade_Autoup($Db); - $skip_list = $Upgrade->GetSkipList(); - - $Ref = new ReflectionObject($Upgrade); - foreach ($Ref->getMethods() as $Method) - { - $method_name = $Method->getName(); - if ( - strpos($method_name, 'Convert') === 0 && - $Method->isPublic() && - !in_array($method_name, $skip_list) - ) - { - print "\n+ Run {$method_name} \n"; - $Method->invoke($Upgrade); - } - } - } - } - - -?> \ No newline at end of file diff --git a/app/cron/class.AutoupdateProcess.php b/app/cron/class.AutoupdateProcess.php deleted file mode 100644 index 7161902..0000000 --- a/app/cron/class.AutoupdateProcess.php +++ /dev/null @@ -1,181 +0,0 @@ -SetInterface("PublicLicenseService"); - - $chk_result = $license_service->CheckLicense($license_uuid); - Log::Log(var_export($chk_result, true)); - Log::Log("License check result: " - . ($chk_result->valid ? "VALID" : "NOT-VALID") - . ". {$chk_result->message}", E_USER_NOTICE); - - if (!$chk_result->valid) - { - Log::Log("License check detected that license not valid. Future autoupdates will be disabled"); - } - } - } - - $AutoUpdateClient = new AutoUpdateClient(); - $AutoUpdateClient->TarCmd = CONFIG::$TAR_PATH; - $AutoUpdateClient->PhpCmd = CONFIG::$PHP_PATH; - - // - // Prepare - // - foreach ((array)$AUTOUP_SERVICES as $svc) - $AutoUpdateClient->AddService($svc); - - if (CONTEXTS::$SECURITY_CONTEXT == SECURITY_CONTEXT::ZENDED) - { - $AutoUpdateClient->SetLicense($license_uuid); - } - - try - { - $AutoUpdateClient->SetProductID(CONFIG::$PRODUCT_ID); - $AutoUpdateClient->SetLocalRevision(CONFIG::$APP_REVISION); - // Bind event listener - $AutoUpdateClient->SetEventHandler(new AutoupEventHandler()); - - // Get most recent revision - $latest_rev = $AutoUpdateClient->GetLatestRevision(); - } - catch (Exception $e) - { - if (preg_match('/services failed while trying/', $e->getMessage())) { - Log::Log("Autoupdate server is down for maintenance", E_USER_WARNING); - return; - } else { - throw $e; - } - } - - // Check if we're running outdated copy. - if ($latest_rev > CONFIG::$APP_REVISION) - { - if (CONFIG::$UPDATE_STATUS != UPDATE_STATUS::AVAILABLE_AND_EMAIL_SENT && - CONFIG::$UPDATE_STATUS != UPDATE_STATUS::SCHEDULED) - { - $args = array("current_revision" => CONFIG::$APP_REVISION, "latest_revision" => $latest_rev); - mailer_send("root_updates_available.eml", $args, CONFIG::$EMAIL_ADMIN, CONFIG::$EMAIL_ADMINNAME); - $db->Execute("UPDATE config SET value=? WHERE `key`='update_status'", array(UPDATE_STATUS::AVAILABLE_AND_EMAIL_SENT)); - } - } - - - - /* - * Select approval flag from database - */ - if (CONFIG::$UPDATE_STATUS == UPDATE_STATUS::SCHEDULED) - { - $status = UPDATE_STATUS::NO_UPDATES; - - if ($AutoUpdateClient->LocalRevision < $AutoUpdateClient->GetLatestRevision()) - { - $db->Execute("UPDATE config SET value=? WHERE `key`='update_status'", array(UPDATE_STATUS::RUNNING)); - - try - { - $AutoUpdateClient->TarCmd = CONFIG::$TAR_PATH; - $AutoUpdateClient->SetTempDir(CACHE_PATH); - $AutoUpdateClient->SetAppPath(CONFIG::$PATH); - $AutoUpdateClient->XAgent = "AUTOUPDATE-EPPDRS"; - - // Update to latest - $AutoUpdateClient->UpdateToLatest(); - } - catch (Exception $e) - { - if (preg_match('/services failed while trying/', $e->getMessage())) { - Log::Log("Autoupdate server is down for maintenance", E_USER_WARNING); - } else { - Log::Log("Update failed: {$e->getMessage()}", E_ERROR); - } - $failed = true; - } - - file_put_contents(dirname(__FILE__)."/../etc/version", $AutoUpdateClient->LocalRevision); - - // Email Report - $report = $AutoUpdateClient->BuildReport(); - $status = ($failed) ? "Failed" : "Success"; - - if (!$AutoUpdateClient->SendReportLater) - { - $args = array("report" => $report, "status" => $status); - mailer_send("root_update_complete.eml", $args, CONFIG::$EMAIL_ADMIN, CONFIG::$EMAIL_ADMINNAME); - $email_status = "Send"; - } - else - $email_status = "Await"; - - $db->Execute("INSERT INTO updatelog SET dtupdate=NOW(), status=?, report=?, transactionid=?, from_revision=?, to_revision=?, email_status=?", - array($status, $report, TRANSACTION_ID, CONFIG::$APP_REVISION, $AutoUpdateClient->LocalRevision, $email_status)); - - if ($AutoUpdateClient->TargetUpdate->AutoScheduleNextUpdate == 1) - { - if ($AutoUpdateClient->LocalRevision != $AutoUpdateClient->GetLatestRevision()) - { - Log::Log("This update requires application reload. The next update will be installed on next cronjob run automatically.", E_USER_WARNING); - $status = UPDATE_STATUS::SCHEDULED; - } - } - } - - $db->Execute("UPDATE config SET value=? WHERE `key`='update_status'", array($status)); - } - - if (!$AutoUpdateClient->SendReportLater) - { - // Send all awaiting emails - $update_logs = $db->GetAll("SELECT * FROM updatelog WHERE email_status = 'Await'"); - if ($update_logs) - foreach ($update_logs as $update_log) - { - $args = array("report" => $update_log['report'], "status" => $update_log['status']); - mailer_send("root_update_complete.eml", $args, CONFIG::$EMAIL_ADMIN, CONFIG::$EMAIL_ADMINNAME); - $db->Execute("UPDATE updatelog SET email_status = ? WHERE id = ?", array("Send", $update_log["id"])); - } - } - - //xdebug_stop_trace(); - } - - public function OnEndForking() - { - - } - - public function StartThread($serverinfo) - { - - } - } -?> \ No newline at end of file diff --git a/app/src/LibWebta/library/Distribution/class.AutoUpdateClient.php b/app/src/LibWebta/library/Distribution/class.AutoUpdateClient.php deleted file mode 100644 index ed8ef9a..0000000 --- a/app/src/LibWebta/library/Distribution/class.AutoUpdateClient.php +++ /dev/null @@ -1,1121 +0,0 @@ - | - // +--------------------------------------------------------------------------+ - - Core::Load("IO/Basic/IOTool"); - Core::Load("System/Independent/Shell/ShellFactory"); - Core::Load("PE"); - - /** - * Update data type structure - * - */ - class Update - { - public $IsAutoUpdatePossible; - public $Notes; - public $Requirements; - public $DateReleased; - public $Revision; - public $FilesToUpdate; - public $FoldersToAdd; - public $FilesToAdd; - public $FilesToDelete; - public $FoldersToDelete; - public $Chmods; - public $Commands; - public $Scripts; - public $SQLQueries; - public $ChangelogFixed; - public $ChangelogAdded; - public $EventHandler; - public $LocalArchivePath; - public $InterruptAfter; - public $AutoScheduleNextUpdate; - public $DoBackupDatabase; - public $DoBackupTemplates; - } - - class AutoUpdateClient extends Core - { - - const TAR_CMD = "tar"; - - const PHP_CMD = "php"; - - /** - * List of URLs of auto-update services - * - * @var array - */ - public $ServiceURLs; - - /** - * A list of available updates - * - * @var array - */ - private $AllRevisions; - - /** - * Target Update object - * - * @var Update - */ - public $TargetUpdate; - - /** - * Temp directory with Update - * - * @var TempDir - */ - private $TempDir; - - /** - * Temp director for Update package extraction - * - * @var TempRoot - */ - public $TempRoot; - - /** - * License string used for validation during download - * - * @var string - */ - private $License; - - /** - * Local revision ID - * - * @var int - */ - public $LocalRevision; - - - /** - * text report of performed updates - * - * @var string - */ - private $ReportRows; - - - /** - * Path to tar binary - * - * @var unknown_type - */ - public $TarCmd; - - - /** - * Report string - * - * @var string - */ - public $Report; - - /** - * @var string - */ - public $SendReportLater; - - /** - * APP Path - * - * @var string - */ - private $AppPath; - - /** - * Shell instance - * - * @var Shell - */ - private $Shell; - - /** - * ADODB Instance - * - * @var ADODBConnection - */ - private $DB; - - /** - * System user name - * - * @var string - */ - private $Uname; - - /** - * Clean temporary files and collect garbage - * - */ - public function Dispose() - { - $this->RaiseEvent("Cleaning temporary folders/files"); - try - { - // FIXME: - IOTool::UnlinkRecursive($this->TempDir); - } catch (Exception $ex) - { - throw new Exception("Failed to clean temporary files"); - } - } - - /** - * Constructor - * - */ - function __construct() - { - $tmp_dir = ini_get("session.save_path") . "/" . uniqid("update-", true); - $this->TempDir = $tmp_dir; - // Use path from config or default one - - $this->TarCmd = self::TAR_CMD; - $this->PhpCmd = self::PHP_CMD; - - // Determine current user name - $this->Uname = $_SERVER["USER"] ? $_SERVER["USER"] : "current"; - - // Common objects - $this->DB = Core::GetDBInstance(null, true); - $this->Shell = ShellFactory::GetShellInstance(); - } - - /** - * Probe PHP binary - * - * @return string path to php binary - */ - public function ProbePHPBinary() - { - if (!$this->PhpCmd || !@is_executable($this->PhpCmd)) - { - $ret = $this->Shell->QueryRaw("which php"); - if ($ret && file_exists($ret) && is_executable($ret)) - { - $this->PhpCmd = $ret; - $found = true; - } - else - { - $ret = $this->Shell->QueryRaw("whereis php"); - $paths = explode(" ", $ret); - foreach ($paths as $path) - { - if ($path && @is_executable($path)) - { - $this->PhpCmd = $path; - $found = true; - break; - } - } - } - } - else - $found = true; - - if (!$found) - throw new Exception(sprintf("PHP binary not found or not executable by %s. Please update php binary path in Core Settings and make sure it is executable by %s", $this->Uname, $this->Uname)); - - return $this->PhpCmd; - } - - /** - * Destructor - * - */ - function __destruct() - { - //$this->Dispose(); - } - - /** - * Set a reference to an object to whom local events will be dispatched - * - * @param object $object - */ - public function SetEventHandler($object) - { - $this->EventHandler = $object; - } - - /** - * Set app path - * - * @param object $object - */ - public function SetAppPath($path) - { - $this->AppPath = $path; - } - - /** - * Add a new service url to the end of the list - * - * @param string $url - */ - public function AddService($url) - { - $this->ServiceURLs[] = $url; - } - - /** - * Set temp directory for Update archive extraction - * - */ - public function SetTempDir($dir) - { - $this->TempRoot = $dir; - } - - /** - * Set ProductID - * - */ - public function SetProductID($product_id) - { - $this->ProductID = $product_id; - } - - /** - * Set license string for validation during download - * - * @param string $lic - */ - public function SetLicense($lic) - { - $this->License = $lic; - } - - /** - * Set local revision - * - * @param int $revision - */ - public function SetLocalRevision($revision) - { - if (!is_array($this->AllRevisions)) - $this->ListRevisions(); - - if (!in_array($revision, $this->AllRevisions)) - throw new Exception(sprintf("Unknown local version %s.", $revision)); - - $this->LocalRevision = $revision; - } - - /** - * Add a new service url to the end of the list - * - * @param string $url - * @return string - */ - public function FetchManifest($url) - { - if (count($this->ServiceURLs) <= 0) - throw new Exception("No update services defined"); - - foreach ($this->ServiceURLs as $service_url) - { - $manifest_url = "{$service_url}/{$url}"; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $manifest_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_VERBOSE, 0); - - $xmlstr = curl_exec($ch); - if ($xmlstr) - { - if ("200" == ($status = curl_getinfo($ch, CURLINFO_HTTP_CODE))) - { - break; - } - else - { - $xmlstr = false; - Log::Log("Cannot fetch manifest. Http status: {$status}", E_USER_NOTICE); - } - } - else - { - Log::Log("Cannot fetch manifest. " . curl_error($ch), E_USER_NOTICE); - } - } - - // No service alive - if (!$xmlstr) - throw new Exception(sprintf("All services failed while trying to retrieve %s", $url)); - else - return $xmlstr; - } - - - public function GetUpdateObject($revision) - { - if (!$this->ProductID) - throw new Exception("No productID defined"); - $xmlstr = $this->FetchManifest("/{$this->ProductID}/updates/{$revision}.xml"); - $retval = new Update(); - - // Build an object of xml string - $xml = new SimpleXMLElement($xmlstr, LIBXML_NOCDATA); - $retval->IsAutoUpdatePossible = (bool)$xml["autoupdate"]; - $retval->DateReleased = (string)$xml["date"]; - $retval->Revision = (int)$xml["revision"]; - $retval->InterruptAfter = (int)$xml["interrupt_after"]; - $retval->AutoScheduleNextUpdate = (int)$xml["auto_shedule_next_update"]; - $retval->DoBackupDatabase = (int)$xml["do_backup_database"]; - $retval->DoBackupTemplates = (int)$xml["do_backup_templates"]; - $retval->SkipTarballDownload = (int)$xml["skip_tarball_download"]; - $retval->Notes = trim((string)$xml->notes); - - $send_report_later = (int)$xml["send_report_later"]; - if ($send_report_later) - $this->SendReportLater = 1; - - if ($retval->InterruptAfter) - $retval->Notes .= "
This update requires application reload. The next update will be installed on next cronjob run automatically."; - - // changelog/fixed - $retval->ChangelogFixed = array(); - foreach($xml->changelog->fixed as $item) - { - $retval->ChangelogFixed[] = trim((string)$item); - } - - // changelog/added - $retval->ChangelogAdded = array(); - foreach($xml->changelog->added as $item) - { - $retval->ChangelogAdded[] = trim((string)$item); - } - - - // delete/folder - $retval->FoldersToDelete = array(); - foreach($xml->delete->folder as $item) - { - $retval->FoldersToDelete[] = (string)$item; - } - - // delete/file - $retval->FilesToDelete = array(); - foreach($xml->delete->file as $item) - { - $retval->FilesToDelete[] = (string)$item; - } - - // add/folder - $retval->FoldersToAdd = array(); - foreach($xml->add->folder as $item) - { - $retval->FoldersToAdd[] = (string)$item; - } - - // add/file - $retval->FilesToAdd = array(); - foreach($xml->add->file as $item) - { - $retval->FilesToAdd[] = (string)$item; - } - - // update/file - $retval->FilesToUpdate = array(); - foreach($xml->update->file as $item) - { - $retval->FilesToUpdate[] = (string)$item; - } - - // chmods - foreach($xml->xpath("//file[@chmod!='']|//folder[@chmod!='']") as $item) - { - $retval->Chmods[(string)$item] = (string)$item["chmod"]; - } - - // SQL - $retval->SQLQueries = array(); - foreach($xml->sql->item as $item) - { - $retval->SQLQueries[] = (string)$item; - } - - // Execute - $retval->Commands = array(); - foreach($xml->execute->command as $item) - { - $retval->Commands[] = (string)$item; - } - $retval->Scripts = array(); - foreach($xml->execute->script as $item) - { - $retval->Scripts[] = (string)$item; - } - $retval->Requirements = array(); - - // versioncompat value strings - $cmp_strings = array( - "gt" => ">", - "lt" => "<", - "ge" => ">=", - "le" => "<=" - ); - - // requirements - foreach($xml->requirements->php->class_exists as $item) - { - $retval->Requirements["class_exists"][] = array( - "name" => (string)$item["name"], - "message" => (string)$item["message"], - "uri" => (string)$item["uri"], - "mandatory" => (int)$item["mandatory"] - ); - } - foreach($xml->requirements->php->function_exists as $item) - { - $retval->Requirements["function_exists"][] = array( - "name" => (string)$item["name"], - "message" => (string)$item["message"], - "uri" => (string)$item["uri"], - "mandatory" => (int)$item["mandatory"] - ); - } - - foreach($xml->requirements->php->expr as $item) - { - $retval->Requirements["expressions"][] = array( - "expression" => (string)$item["value"], - "message" => (string)$item["message"], - "uri" => (string)$item["uri"], - "mandatory" => (int)$item["mandatory"] - ); - } - - $retval->Requirements["phpversion"] = (string)$xml->requirements->php->version; - return($retval); - } - - /** - * Get a list of product Updates - * @param string $product_id ProductID - */ - public function ListRevisions() - { - if (!$this->ProductID) - throw new Exception("No productID defined"); - - $retval = array(); - $xmlstr = $this->FetchManifest("{$this->ProductID}/releases.xml"); - $xml = new SimpleXMLElement($xmlstr); - foreach ($xml->release as $release) - { - $retval[] = (int)$release["revision"]; - } - - // Sort descending - natsort($retval); - array_reverse($retval); - $this->AllRevisions = $retval; - - return ($retval); - } - - /** - * Get a maximum revision - * - * @return int - */ - public function GetLatestRevision() - { - return (int)max($this->ListRevisions()); - } - - /** - * Get a list of all needed updates from $from_revision to $to_revision - * @var int $target_revision Target revision - * @return array - */ - public function ListHops($from_revision, $to_revision) - { - if (!is_array($this->AllRevisions)) - $this->ListRevisions(); - - // Get a slice of array - $i=0; $offset=0; $len = 0; - foreach ($this->AllRevisions as $rel) - { - if ($rel == $from_revision) - $offset = $i; - if ($rel > $from_revision) - ++$len; - if ($rel == $to_revision) - break; - $i++; - } - $retval = $this->AllRevisions; - $retval = array_slice($retval, $offset+1, $len); - return($retval); - } - - /** - * Download update archive - * - */ - private function DownloadUpdate() - { - // Set URL and local out file - $url = "download/{$this->ProductID}/update/{$this->TargetUpdate->Revision}.tar.gz"; - $this->TargetUpdate->LocalArchivePath = "{$this->TempDir}/{$this->TargetUpdate->Revision}.tgz"; - - $this->RaiseEvent(sprintf("Downloading update from %s to %s", - $url, - $this->TargetUpdate->LocalArchivePath)); - - /* - * Download - */ - $ch = @curl_init(); - $outfile = @fopen($this->TargetUpdate->LocalArchivePath, 'wb'); - @curl_setopt_array($ch, - array( - CURLOPT_FILE => $outfile, - CURLOPT_BINARYTRANSFER => true, - CURLOPT_HEADER => 0, - CURLOPT_TIMEOUT => 60*5, // Five minutes, sir! - CURLOPT_FAILONERROR => true - ) - ); - - $headers = array( - "X-Webta-Agent: EPPDRS3000", - "X-CURLVER: ". implode(";", curl_version()) - ); - if ($this->License) - $headers[] = "X-License-Id: {$this->License}"; - - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - - // Try to download from all each registered 'service' - foreach ($this->ServiceURLs as $service_url) - { - curl_setopt($ch, CURLOPT_URL, "{$service_url}/{$url}"); - $this->RaiseEvent(sprintf("Downloading from '%s/%s'", $service_url, $url)); - $result = curl_exec($ch); - if ($result === true) - break; - } - - // No service alive - if (!$result) - throw new Exception(sprintf("All services failed while trying to download update archive '%s'. %s", - $url, - curl_error($ch))); - - @curl_close($ch); - @fclose($outfile); - } - - /** - * Untar archive - * - * @return unknown - */ - private function ExtractUpdate() - { - chdir($this->TempDir); - - $cmd = "cd {$this->TempDir} && \"{$this->TarCmd}\" -xzf \"{$this->TempDir}/{$this->TargetUpdate->Revision}.tgz\""; - $result = $this->Shell->ExecuteRaw($cmd); - $this->RaiseEvent("Extracting update ('{$cmd}')"); - - if (!$result) - $this->RaiseEventAndThrow(sprintf("Failed to extract update package (%s)", $cmd)); - else - chdir("{$this->TempDir}/app"); - return($result); - } - - - /** - * Atomic update to a specific Update from a previous one - * - */ - protected function Update($revision) - { - // print memory_get_usage(true) . " " . memory_get_usage()." Before update to r$revision\n"; - - if (!$this->LocalRevision) - throw new Exception("No LocalRevision defined"); - - // Create temp directory - $this->TempDir = "{$this->TempRoot}/" . uniqid("update-", true); - $mkresult = @mkdir($this->TempDir); - if (!$mkresult) - { - $this->RaiseEventAndThrow(sprintf("Failed to create temporary directory %s", $this->TempDir)); - } - - // Fetch a Update data and serialize to object - $this->TargetUpdate = $this->GetUpdateObject($revision); - - // print memory_get_usage(true) . " " . memory_get_usage()." GetUpdateObject\n"; - - // Check php path if php needed and throw exception if no executable php binary found - if (count($this->TargetUpdate->Commands) > 0) - { - $raw_cmd = implode("", $this->TargetUpdate->Commands); - if (stripos($raw_cmd, "%php_path%") !== false) - { - try - { - $php_path = $this->ProbePHPBinary(); - } - catch(Exception $e) - { - $this->RaiseEvent($e->getMessage()); - throw new Exception($e->getMessage(), $e->getCode()); - } - - foreach ($this->TargetUpdate->Commands as &$cmd) - $cmd = str_replace("%php_path%", $php_path, $cmd); - } - } - - if ($this->TargetUpdate->IsAutoUpdatePossible) - { - $this->RaiseEvent(sprintf("Begin SQL transaction.")); - // print memory_get_usage(true) . " " . memory_get_usage()." Begin SQL transaction.\n"; - $this->DB->StartTrans(); - - try - { - if (!$this->TargetUpdate->SkipTarballDownload) - { - // Download and extract Update - // print memory_get_usage(true) . " " . memory_get_usage()." Before Download and extract Update.\n"; - $this->DownloadUpdate($revision); - // print memory_get_usage(true) . " " . memory_get_usage()." After Download and extract Update.\n"; - - // Unpack archive - // print memory_get_usage(true) . " " . memory_get_usage()." Before Unpack archive.\n"; - $this->ExtractUpdate($revision); - // print memory_get_usage(true) . " " . memory_get_usage()." After Unpack archive.\n"; - // Now we are in {$this->TempDir}/app folder - } - - // Perform update actions - // print memory_get_usage(true) . " " . memory_get_usage()." Before Make backups.\n"; - $this->MakeBackups(); - // print memory_get_usage(true) . " " . memory_get_usage()." After Make backups.\n"; - - $this->ExecuteSQLQueries(); - - if (!$this->TargetUpdate->SkipTarballDownload) - { - // print memory_get_usage(true) . " " . memory_get_usage()." Before Add folders/files.\n"; - $this->AddFolders(); - $this->AddFiles(); - // print memory_get_usage(true) . " " . memory_get_usage()." After Add folders/files.\n"; - - $this->UpdateFiles(); - - $this->SetFSPermissions(); - } - } - catch (Exception $ex) - { - $this->RaiseEvent(sprintf("Rolling back SQL queries.")); - $this->DB->RollbackTrans(); - $this->RaiseEventAndThrow(sprintf("Update failed. %s", $ex->getMessage())); - } - - $this->RaiseEvent(sprintf("Commiting SQL transaction.")); - $this->DB->CompleteTrans(); - - // - // �� ������ ��������� ������� ����� ������ ���������� ����� ��������� �� deadlocks. - // - - $this->ExecuteCommands(); - - if (!$this->TargetUpdate->SkipTarballDownload) - { - $this->ExecuteScripts(); - - $this->DeleteFolders(); - $this->DeleteFiles(); - } - - } - else - { - $message = sprintf("It is not possible to automatically update to revision %s. Please perform manual update.", $revision); - throw new Exception($message); - } - $this->Dispose(); - $this->SetLocalRevision($this->TargetUpdate->Revision); - $this->RaiseEvent(sprintf("Update to version %d finished", $revision)); - - // print memory_get_usage(true) . " " . memory_get_usage()." After update to r$revision\n"; - } - - - private function SetFSPermissions() - { - // print "In SetFSPermissions \n"; - - $this->RaiseEvent("Setting permissions"); - foreach((array)$this->TargetUpdate->Chmods as $path => $perm) - { - $this->RaiseEvent("chmod {$perm} {$this->AppPath}/{$path}"); - - $result = chmod("{$this->AppPath}/{$path}", octdec($perm)); - if (!$result) - $this->RaiseEvent(sprintf("Failed to set permission '%s' on path '%s'", $perm, $path)); - } - - // print "Leave SetFSPermissions\n"; - } - - /** - * Execute shell commands - * @return void - */ - private function ExecuteCommands() - { - $this->RaiseEvent("Executing commands"); - $MP = new ManagedProcess(); - - foreach($this->TargetUpdate->Commands as $cmd) - { - $cmd = "cd {$this->AppPath} && {$cmd}"; - - $this->RaiseEvent(sprintf("Executing command '%s'", $cmd)); - - $MP->StdErr = null; - $MP->StdOut = null; - $MP->Execute($cmd); - - //$result = $this->Shell->ExecuteRaw($cmd); - - $this->RaiseEvent(sprintf("Result: STDOUT = '%s', STDERR= '%s'", $MP->StdOut, $MP->StdErr)); - - //if (!$result) - // $this->RaiseEvent(sprintf("Failed to execute command '%s'", $cmd)); - } - } - - /** - * Execute php scripts - * @return void - */ - private function ExecuteScripts() - { - $Mailer = Core::GetPHPSmartyMailerInstance(CONFIG::$EMAIL_DSN); - $this->RaiseEvent("Executing PHP scripts"); - /* We must prevent update from stopping execution - /* if any of invoked scripts raise error - */ - foreach($this->TargetUpdate->Scripts as $path) - { - $this->RaiseEvent(sprintf("Executing script '%s'", $this->AppPath . "/{$path}")); - - try - { - $result = include($this->AppPath . "/{$path}"); - } catch (Exception $e) - { - $this->RaiseEvent(sprintf("Failed to execute script %s", $path)); - } - if (!$result) - $this->RaiseEvent(sprintf("Failed to execute script %s", $path)); - } - } - - /** - * Make backups of templates and database if these are set in manifest - * - */ - private function MakeBackups() - { - - // Do we need to do any backups? - if ($this->TargetUpdate->DoBackupDatabase + $this->TargetUpdate->DoBackupTemplates >= 1) - { - $backup_root = "{$this->AppPath}/cache/autoup-backup-".date("Y-m-d-Hi"); - } - - // DB backup - if ($this->TargetUpdate->DoBackupDatabase == 1) - { - $backup_path = "{$backup_root}/mysql"; - // Forcefully create folder for mysql dump - @mkdir($backup_path, 0777, true); - @chmod($backup_path, 0777); - - $this->RaiseEvent(sprintf("Saving database backup to '%s/backup.sql'", $backup_path)); - $command = "mysqldump -h'{$this->DB->host}' -u'{$this->DB->username}' -p'{$this->DB->password}' {$this->DB->database} > {$backup_path}/backup.sql"; - $result = $this->Shell->ExecuteRaw($command); - if (!$result) - $this->RaiseEvent(sprintf("Failed to backup database using mysqldump binary. Make sure that mysqldump is in PATH and executable by %s user", $this->Uname)); - } - - // Templates backup - if ($this->TargetUpdate->DoBackupTemplates == 1) - { - $templates_path = "{$this->AppPath}/templates"; - $backup_path = "{$backup_root}/templates"; - @mkdir($backup_path, 0777, true); - @chmod($backup_path, 0777); - - $this->RaiseEvent(sprintf("Saving backup of templates to '%s'", $backup_path)); - - $cmd = "cp -Rf {$templates_path} {$backup_path}"; - $result = $this->Shell->ExecuteRaw($cmd); - if (!$result) - $this->RaiseEvent(sprintf("Failed to backup templates")); - } - } - - /** - * Execute SQL queries within one transaction - * @return void - */ - private function ExecuteSQLQueries() - { - $this->RaiseEvent("Executing SQL queries"); - - foreach($this->TargetUpdate->SQLQueries as $sql) - { - $this->RaiseEvent("Executing SQL: {$sql}"); - $this->DB->Execute($sql); - } - } - - - /** - * Delete files - * @return void - */ - private function DeleteFiles() - { - $this->RaiseEvent("Deleting files"); - foreach($this->TargetUpdate->FilesToDelete as $f) - { - $target_path = $this->AppPath . "/" . $f; - - $this->RaiseEvent(sprintf("Deleting '%s'", $target_path)); - - $result = unlink($target_path); - if (!$result) - { - $this->RaiseEvent(sprintf("Failed to delete file %s (%s)", $f, $target_path)); - } - } - } - - - /** - * Delete folders - * @return void - */ - private function DeleteFolders() - { - $this->RaiseEvent("Deleting folders"); - foreach($this->TargetUpdate->FoldersToDelete as $f) - { - $target_path = $this->AppPath . "/" . $f; - - $this->RaiseEvent(sprintf("Deleting '%s'", $target_path)); - - $result = IOTool::UnlinkRecursive($target_path); - if (!$result) - { - $this->RaiseEvent(sprintf("Failed to delete folder %s (%s)", $f, $target_path)); - } - } - } - - - /** - * Create folders - * @return void - */ - private function AddFolders() - { - $this->RaiseEvent("Creating folders"); - foreach($this->TargetUpdate->FoldersToAdd as $f) - { - $target_path = $this->AppPath . "/" . $f; - - $chmod = $this->TargetUpdate->Chmods[$f]; - if (!file_exists($target_path)) - { - if (!$chmod) - $chmod = 0755; - - $result = mkdir($target_path, $chmod, true); - @chmod($target_path, $chmod); - - if (!$result) - { - $this->RaiseEvent(sprintf("Failed to create folder %s (%s)", $f, $target_path)); - } - } - else - $this->RaiseEvent(sprintf("Folder %s (%s) already exists.. skipping", $f, $target_path)); - } - } - - - /** - * No differences to UpdateFiles() so far - * @return void - */ - private function AddFiles() - { - //set_error_handler(array(&$this, 'CopyErrorHandler')); - $this->RaiseEvent("Copying files"); - foreach($this->TargetUpdate->FilesToAdd as $f) - { - $source_path = "./".$f; - $target_path = $this->AppPath . "/" . $f; - - if (!file_exists($target_path)) - { - $result = copy($source_path, $target_path); - - - if (!$result) - { -// $this->RaiseEvent(sprintf("Failed to copy file %s ('%s' to '%s')", $f, $source_path, $target_path)); - } - } - else - $this->RaiseEvent(sprintf("Failed to copy file %s ('%s' to '%s'). File already exists", $f, $source_path, $target_path)); - } - } - - - /** - * Copy files over existing ones or update chmods - * @return void - */ - private function UpdateFiles() - { - // print memory_get_usage(true) . " " . memory_get_usage()." Before Update files\n"; - $this->RaiseEvent("Updating files"); - foreach($this->TargetUpdate->FilesToUpdate as $f) - { - $source_path = "./".$f; - $target_path = $this->AppPath . "/" . $f; - // print memory_get_usage(true) . " " . memory_get_usage()." Copying $source_path ... \n"; - $result = copy($source_path, $target_path); - // print memory_get_usage(true) . " " . memory_get_usage(). ($result ? " Ok\n" : " Failed\n"); - - if (!$result) - { -// print sprintf("Failed to copy file %s ('%s' to '%s')", $f, $source_path, $target_path); - $this->RaiseEvent(sprintf("Failed to copy file %s ('%s' to '%s')", $f, $source_path, $target_path)); - } - } - // print memory_get_usage(true) . " " . memory_get_usage()." After Update files\n"; - } - - - /** - * Update to a specific Update in few hops - * - * @param int $target_revision - */ - public function UpdateToRevision($target_revision) - { - // Get a list of update hops and update step-by-step iteratively - foreach ($this->ListHops($this->LocalRevision, $target_revision) as $revision) - { - $this->RaiseEvent(sprintf("Hop: Updating to version %s", $revision)); - try - { - $this->Update($revision); - } - catch (Exception $ex) - { - // PHP should have `finally` :( - $this->Dispose(); - throw new Exception($ex->getMessage()); - break; - } - - if ($this->TargetUpdate->InterruptAfter == 1) - { - break; - } - } - $this->RaiseEvent("Update finished"); - } - - /** - * Update to latest available revision - * - */ - public function UpdateToLatest() - { - $target_revision = $this->GetLatestRevision(); - $this->RaiseEvent(sprintf("Updating to latest version (%s)", $target_revision)); - $this->UpdateToRevision($target_revision); - } - - /** - * Notify Event listener - * - */ - private function RaiseEvent() - { - $args = func_get_args(); - $date = date("m.d.y H:i:s"); - $this->EventHandler->OnEvent("LogEvent", $args); - $this->ReportRows[] = $date . ":" . implode(";", $args); - } - - /** - * Notify Event listener and throw Exception - * - * @param string $oops - */ - private function RaiseEventAndThrow($oops) - { - $this->RaiseEvent($oops); - throw new Exception($oops); - } - - /** - * Build s string report - * - * @return unknown - */ - public function BuildReport() - { - return(implode("\r\n", $this->ReportRows)); - } - } -?> diff --git a/app/src/LibWebta/library/Distribution/tests.php b/app/src/LibWebta/library/Distribution/tests.php deleted file mode 100644 index c03c8ed..0000000 --- a/app/src/LibWebta/library/Distribution/tests.php +++ /dev/null @@ -1,92 +0,0 @@ -"; - var_dump(func_get_args()); - echo "
"; - } - } - - class Distribution_Test extends UnitTestCase - { - function __construct() - { - $this->UnitTestCase('Distribution'); - } - - function testAutoUpdateClient() - { - /* - $AutoUpdateClient = new AutoUpdateClient(); - - // Preparation - $AutoUpdateClient->AddService("http://k2:95/data"); - $AutoUpdateClient->AddService("http://autoup-1.webta.net/data"); - $AutoUpdateClient->SetProductID("epp-drs"); - $AutoUpdateClient->TarCmd = "C:\\\\windows\\tar.exe"; - // Set tmp directory - global $cachepath; - $AutoUpdateClient->SetTempDir($cachepath); - // Bind event listener - $AutoUpdateClient->BindEventListener(new EventListenerStub()); - - // Extract current license - $LicenseManager = new LicenseManager("Cheeshoo1ahph0pieH7Sei5a"); - $LicenseManager->LoadLicFiles("/src/epp-drs/app/etc"); - $LicenseManager->SetFrequency(0); - $lic = $LicenseManager->SelectWeakestLic(); - $AutoUpdateClient->SetLicense($lic); - - // Get a revisions list - $result = $AutoUpdateClient->ListRevisions(); - $this->assertTrue(is_array($result), "ListRevisions returned array"); - - // List Hops needed for update - $AutoUpdateClient->SetLocalRevision(565); - $hops = $AutoUpdateClient->ListHops(565, 570); - $this->assertTrue(count($hops) == 3, "ListHops returned array of correct length"); - - // Most recent revision - $result = $AutoUpdateClient->GetLatestRevision(); - $this->assertTrue(is_int($result), "GetLatestRevision returned number"); - - // Update! Yarr! - $AutoUpdateClient->UpdateToLatest(); - $report = $AutoUpdateClient->BuildReport(); - */ - } - } -?> diff --git a/app/src/LibWebta/tests/tests.php b/app/src/LibWebta/tests/tests.php index 29d024d..b6566e2 100644 --- a/app/src/LibWebta/tests/tests.php +++ b/app/src/LibWebta/tests/tests.php @@ -160,9 +160,6 @@ #require_once("{$libpath}/NET/REST/tests.php"); #$test_libwebta->addTestCase(new NET_REST_Test()); - // Distribution tests - require_once("{$libpath}/Distribution/tests.php"); - $test_libwebta->addTestCase(new Distribution_Test()); $sapi_type = php_sapi_name(); if (substr($sapi_type, 0, 3) != 'cli') @@ -174,4 +171,4 @@ $test_libwebta->run(new ShellReporter()); } -?> \ No newline at end of file +?> diff --git a/app/src/autoload.php b/app/src/autoload.php index cf6ebf3..ac5d817 100755 --- a/app/src/autoload.php +++ b/app/src/autoload.php @@ -10,7 +10,6 @@ function __autoload($class_name) "MailInvoiceObserver" => SRC_PATH."/observers/class.MailInvoiceObserver.php", "RegistryInvoiceObserver" => SRC_PATH."/observers/class.RegistryInvoiceObserver.php", "BalanceInvoiceObserver" => SRC_PATH."/observers/class.BalanceInvoiceObserver.php", - "AutoupEventHandler" => SRC_PATH."/class.AutoupEventHandler.php", "DataForm" => SRC_PATH."/class.DataForm.php", "DataFormField" => SRC_PATH."/class.DataFormField.php", "Punycode" => SRC_PATH."/class.Punycode.php", @@ -73,4 +72,4 @@ function __autoload($class_name) if (key_exists($class_name, $paths)) require_once $paths[$class_name]; } -?> \ No newline at end of file +?> diff --git a/app/src/class.AutoupEventHandler.php b/app/src/class.AutoupEventHandler.php deleted file mode 100644 index 30ac4df..0000000 --- a/app/src/class.AutoupEventHandler.php +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/app/src/prepend.inc.php b/app/src/prepend.inc.php index 4b0eb44..66b6013 100644 --- a/app/src/prepend.inc.php +++ b/app/src/prepend.inc.php @@ -7,7 +7,6 @@ define("DEFAULT_LOCALE", "en_US"); - $AUTOUP_SERVICES = array("http://autoup-1.webta.net/data"/*, "http://k2:95/data"*/); define("LICENSE_SERVICE_URL", "https://licserver.epp-drs.com/licserver.php"); // Start session @@ -133,7 +132,6 @@ function exception_handler($exception) require_once("{$srcpath}/types/enum.DOMAIN_STATUS.php"); require_once("{$srcpath}/types/enum.REGISTRY_RESPONSE_STATUS.php"); require_once("{$srcpath}/types/enum.CONTACT_TYPE.php"); - require_once("{$srcpath}/types/enum.UPDATE_STATUS.php"); require_once("{$srcpath}/types/enum.FORM_FIELD_TYPE.php"); require_once("{$srcpath}/types/enum.APPCONTEXT.php"); require_once("{$srcpath}/types/enum.SECURITY_CONTEXT.php"); @@ -169,7 +167,6 @@ function exception_handler($exception) Core::Load("UI/Smarty/Smarty.class.php", "{$srcpath}/Lib"); Core::Load("UI/Smarty/SmartyExt.class.php", "{$srcpath}/Lib"); Core::Load("Data/Validation/class.Validator.php"); - Core::Load("Distribution"); // // Load EPP-DRS classes @@ -554,4 +551,4 @@ function mailer_send($template_name = null, $mail_args = null, $email = null, $n break; } } -?> \ No newline at end of file +?> diff --git a/app/src/structs/struct.CONFIG.php b/app/src/structs/struct.CONFIG.php index 4b30cc2..699c261 100644 --- a/app/src/structs/struct.CONFIG.php +++ b/app/src/structs/struct.CONFIG.php @@ -233,20 +233,7 @@ final class CONFIG */ public static $ZENDID_PATH; - /** - * EPP-DRS update status. Member of UPDATE_STATUS - * - * @staticvar string - * @see UPDATE_STATUS - */ - public static $UPDATE_STATUS; - /** - * Equal to true is EPP-DRS being automatically updated in this moment. - * - * @staticvar string - */ - public static $ISUPDATERUNNING; /** * Unified postback URL for all payment modules that extend IPostBackPaymentModule. @@ -381,4 +368,4 @@ public static function GetValue($key) } } -?> \ No newline at end of file +?> diff --git a/app/src/types/enum.UPDATE_STATUS.php b/app/src/types/enum.UPDATE_STATUS.php deleted file mode 100644 index 6afe247..0000000 --- a/app/src/types/enum.UPDATE_STATUS.php +++ /dev/null @@ -1,31 +0,0 @@ - distribution. - * @category EPP-DRS - * @package Common - * @see http://webta.net/docs/wiki/epp-drs-api-docs - */ - - /** - * Contains possible values of EPP-DRS update status. Use CONFIG::UPDATE_STATUS to retrieve current update status in your code. - * @name UPDATE_STATUS - * @category EPP-DRS - * @package Common - * @author Alex Kovalyov - * @author Igor Savchenko - * @author Marat Komarov - * @see http://webta.net/docs/wiki/epp-drs-api-docs - */ - final class UPDATE_STATUS - { - const NO_UPDATES = 0; - - const AVAILABLE = 1; - - const SCHEDULED = 2; - - const AVAILABLE_AND_EMAIL_SENT = 3; - - const RUNNING = 4; - } -?> \ No newline at end of file diff --git a/app/templates/admin/product_info.tpl b/app/templates/admin/product_info.tpl index 7cf72cf..d894d2f 100644 --- a/app/templates/admin/product_info.tpl +++ b/app/templates/admin/product_info.tpl @@ -31,48 +31,5 @@ {include file="admin/inc/intable_footer.tpl" color="Gray"} {/if} - {if $is_autoup_server_down} - {include file="admin/inc/intable_header.tpl" header="Installed updates" color="Gray"} - - Auto-update server is down for maintenance. - - {include file="admin/inc/intable_footer.tpl" color="Gray"} - {else} - {if $rows|@count > 0} - {include file="admin/inc/intable_header.tpl" header="Installed updates" color="Gray"} - - - {include file="admin/inc/table_header.tpl" nofilter=1} - - - - - - - - - - - - {section name=id loop=$rows} - - - - - - - - {/section} - - - - -
DateReleases in this update Update detailsStatusReport
{$rows[id].dtupdate}{$rows[id].releases}View update details{$rows[id].status}View report
 
- {include file="admin/inc/table_footer.tpl" colspan=9 disable_footer_line=1} - - - {include file="admin/inc/intable_footer.tpl" color="Gray"} - {/if} - {/if} {include file="admin/inc/table_footer.tpl" disable_footer_line=1} -{include file="admin/inc/footer.tpl"} \ No newline at end of file +{include file="admin/inc/footer.tpl"} diff --git a/app/templates/updating.tpl b/app/templates/updating.tpl deleted file mode 100644 index c659b93..0000000 --- a/app/templates/updating.tpl +++ /dev/null @@ -1,5 +0,0 @@ -{include file="inc/header.tpl"} -
- Our systems are currently being upgraded. Please visit us again in few minutes. -
-{include file="inc/footer.tpl"} \ No newline at end of file diff --git a/app/www/admin/product_info.php b/app/www/admin/product_info.php index 77f5df8..a8bef1c 100644 --- a/app/www/admin/product_info.php +++ b/app/www/admin/product_info.php @@ -68,37 +68,6 @@ $license_check_result = unserialize($_SESSION["license_check_result"]); $display["expire_date"] = date("Y-m-d", $license_check_result->expire_date); } - - - $AutoUpdateClient = new AutoUpdateClient(); - - // - // Prepare - // - try - { - foreach ((array)$AUTOUP_SERVICES as $svc) - $AutoUpdateClient->AddService($svc); - - $AutoUpdateClient->SetProductID(CONFIG::$PRODUCT_ID); - $AutoUpdateClient->SetLocalRevision(CONFIG::$APP_REVISION); - - // Bind event listener - $AutoUpdateClient->SetEventHandler(new AutoupEventHandler()); - - $display["rows"] = $db->GetAll("SELECT * FROM updatelog ORDER BY id DESC"); - foreach ($display["rows"] as &$row) - { - $hops = array(); - $hops[] = $row["from_revision"]; - $hops = array_merge($hops, $AutoUpdateClient->ListHops($row["from_revision"], $row["to_revision"])); - $row["releases"] = implode(" → ", $hops); - } - } - catch(Exception $e) - { - $display["is_autoup_server_down"] = true; - } require_once ("src/append.inc.php"); ?> diff --git a/app/www/admin/src/prepend.inc.php b/app/www/admin/src/prepend.inc.php index 86dd8ca..fa30bd9 100644 --- a/app/www/admin/src/prepend.inc.php +++ b/app/www/admin/src/prepend.inc.php @@ -67,15 +67,6 @@ // template subfolder $tplpath = $display['tplpath'] = 'admin'; - if (CONFIG::$UPDATE_STATUS == UPDATE_STATUS::AVAILABLE || CONFIG::$UPDATE_STATUS == UPDATE_STATUS::AVAILABLE_AND_EMAIL_SENT) - { - $display["warn"] = "New updates available. Click here to see details and approve update."; - } - elseif(CONFIG::$UPDATE_STATUS == UPDATE_STATUS::SCHEDULED) - { - $display["warn"] = "Autoupdate scheduled. It will be performed with next auto-update cronjob run"; - } - if (CONTEXTS::$SECURITY_CONTEXT == SECURITY_CONTEXT::ZENDED && $_SESSION["license_check_result"]) { $chk_result = unserialize($_SESSION["license_check_result"]); @@ -94,4 +85,4 @@ } } -?> \ No newline at end of file +?> diff --git a/app/www/admin/update_report.php b/app/www/admin/update_report.php deleted file mode 100644 index 3ec3673..0000000 --- a/app/www/admin/update_report.php +++ /dev/null @@ -1,16 +0,0 @@ -GetRow("SELECT * FROM updatelog WHERE id=?", array($get_id)); - - if (!$updateinfo) - CoreUtils::Redirect("index.php"); - - $display["report"] = $updateinfo["report"]; - $display["transid"] = $updateinfo["transactionid"]; - - require_once ("src/append.inc.php"); -?> \ No newline at end of file diff --git a/app/www/admin/updates.php b/app/www/admin/updates.php deleted file mode 100644 index 84d5f25..0000000 --- a/app/www/admin/updates.php +++ /dev/null @@ -1,161 +0,0 @@ -GetRow("SELECT * FROM updatelog WHERE id=?", array($get_id)); - if (!$updateinfo) - CoreUtils::Redirect("index.php"); - - $display["isinfo"] = true; - - $display["title"] = "Information on installed update"; - } - else - { - $display["title"] = "Autoupdate"; - } - - $display["curr_revision"] = CONFIG::$APP_REVISION; - - if ($_POST) - { - if ($post_agree == 1 && $post_agree2 == 1) - { - $db->Execute("UPDATE config SET value='?' WHERE `key`='update_status'", array(UPDATE_STATUS::SCHEDULED)); - - $okmsg = "Update successfully scheduled."; - CoreUtils::Redirect("index.php"); - } - else - $err[] = "You must agree to backup responsibility assignment."; - } - - $AutoUpdateClient = new AutoUpdateClient(); - - // - // Prepare - // - foreach ((array)$AUTOUP_SERVICES as $svc) - $AutoUpdateClient->AddService($svc); - - $AutoUpdateClient->SetProductID(CONFIG::$PRODUCT_ID); - $AutoUpdateClient->SetLocalRevision(CONFIG::$APP_REVISION); - - // Bind event listener - $AutoUpdateClient->SetEventHandler(new AutoupEventHandler()); - - $latest_rev = $AutoUpdateClient->GetLatestRevision(); - $display["latest_rev"] = $latest_rev; - - if ($get_task == "info") - $hops = $AutoUpdateClient->ListHops($updateinfo["from_revision"], $updateinfo["to_revision"]); - else - $hops = $AutoUpdateClient->ListHops(CONFIG::$APP_REVISION, $latest_rev); - - $display["notes"] = array(); - $display["FilesToUpdate"] = array(); - $display["FoldersToAdd"] = array(); - $display["FilesToAdd"] = array(); - $display["FilesToDelete"] = array(); - $display["FoldersToDelete"] = array(); - $display["Chmods"] = array(); - $display["Commands"] = array(); - $display["Scripts"] = array(); - $display["SQLQueries"] = array(); - $display["ChangelogFixed"] = array(); - $display["ChangelogAdded"] = array(); - - if (count($hops) == 0) - { - $okmsg = _("No updates available. Your EPP-DRS is up to date."); - CoreUtils::Redirect("index.php"); - } - $display["r_errors"] = array(); - foreach ($hops as $hop) - { - $update_object = $AutoUpdateClient->GetUpdateObject($hop); - $display["hops"][$hop] = $update_object; - - $display["notes"][] = $update_object->Notes; - $display["FilesToUpdate"] = array_merge($display["FilesToUpdate"], array_flip((array)$update_object->FilesToUpdate)); - $display["FoldersToAdd"] = array_merge($display["FoldersToAdd"], array_flip((array)$update_object->FoldersToAdd)); - $display["FilesToAdd"] = array_merge($display["FilesToAdd"], array_flip((array)$update_object->FilesToAdd)); - $display["FilesToDelete"] = array_merge($display["FilesToDelete"], array_flip((array)$update_object->FilesToDelete)); - $display["FoldersToDelete"] = array_merge($display["FoldersToDelete"], array_flip((array)$update_object->FoldersToDelete)); - $display["Chmods"] = array_merge($display["Chmods"], (array)$update_object->Chmods); - $display["Commands"] = array_merge($display["Commands"], array_flip((array)$update_object->Commands)); - $display["Scripts"] = array_merge($display["Scripts"], array_flip((array)$update_object->Scripts)); - $display["SQLQueries"] = array_merge($display["SQLQueries"], array_flip((array)$update_object->SQLQueries)); - $display["ChangelogFixed"] = array_merge($display["ChangelogFixed"], (array)$update_object->ChangelogFixed); - $display["ChangelogAdded"] = array_merge($display["ChangelogAdded"], (array)$update_object->ChangelogAdded); - - if ($update_object->Requirements['phpversion'] != '') - { - $ver = (int)preg_replace("/[^0-9]+/", "", substr(PHP_VERSION, 0, 5)); - $req_ver = (int)preg_replace("/[^0-9]+/", "", $update_object->Requirements['phpversion']); - if ($ver < $req_ver) - $display["r_errors"][$hop][] = array(sprintf(_("This version requires PHP %s or higher."), $update_object->Requirements['phpversion'])); - - } - - if (count($update_object->Requirements['class_exists']) > 0) - { - foreach ($update_object->Requirements['class_exists'] as $req) - { - if (!class_exists($req['name'])) - { - $display["r_errors"][$hop][] = array($req['message'], $req['uri']); - - if ($req['mandatory'] == 1) - $display['mandatory_requirement_missing'] = true; - } - } - } - - if (count($update_object->Requirements['function_exists']) > 0) - { - foreach ($update_object->Requirements['function_exists'] as $req) - { - if (!function_exists($req['name'])) - { - $display["r_errors"][$hop][] = array($req['message'], $req['uri']); - - if ($req['mandatory'] == 1) - $display['mandatory_requirement_missing'] = true; - } - } - } - - if (count($update_object->Requirements['expressions']) > 0) - { - foreach ($update_object->Requirements['expressions'] as $req) - { - eval("\$result = {$req['expression']};"); - if (!$result) - { - $display["r_errors"][$hop][] = array($req['message'], $req['uri']); - - if ($req['mandatory'] == 1) - $display['mandatory_requirement_missing'] = true; - } - } - } - } - - $display["FilesToUpdate"] = array_flip($display["FilesToUpdate"]); - $display["FoldersToAdd"] = array_flip($display["FoldersToAdd"]); - $display["FilesToAdd"] = array_flip($display["FilesToAdd"]); - $display["FilesToDelete"] = array_flip($display["FilesToDelete"]); - $display["FoldersToDelete"] = array_flip($display["FoldersToDelete"]); - $display["Commands"] = array_flip($display["Commands"]); - $display["Scripts"] = array_flip($display["Scripts"]); - - $display["SQLQueries"] = array_flip($display["SQLQueries"]); - - - require_once ("src/append.inc.php"); -?> \ No newline at end of file diff --git a/app/www/client/src/prepend.inc.php b/app/www/client/src/prepend.inc.php index a63d9da..25caa10 100644 --- a/app/www/client/src/prepend.inc.php +++ b/app/www/client/src/prepend.inc.php @@ -91,10 +91,4 @@ } } - // Show autoup stub if we are in the proccess of updating - if (CONFIG::$UPDATE_STATUS == UPDATE_STATUS::RUNNING) - { - $smarty->display("updating.tpl"); - exit(); - } ?> diff --git a/app/www/server/whois.php b/app/www/server/whois.php index fab3ab9..11ea62e 100644 --- a/app/www/server/whois.php +++ b/app/www/server/whois.php @@ -3,7 +3,7 @@ include(dirname(__FILE__)."/../src/prepend.inc.php"); $attr = array_merge($_GET, $_POST); - + if ($attr["JS_SESSIONID"] != $_SESSION["JS_SESSIONID"] && !$_SERVER['HTTP_X_FLASH_VERSION']) $result = false; else @@ -42,7 +42,7 @@ $result = _("Failed to connect to whois server."); else { - $domain_name = Punycode::Encode("{$domainname}.{$TLD}"); + $domain_name = Punycode::Encode("{$domainname}.{$TLD}"); @fwrite($sock, "{$domain_name}\n"); while (!feof($sock)) { @@ -68,4 +68,4 @@ } echo json_encode($response); -?> \ No newline at end of file +?> diff --git a/app/www/src/prepend.inc.php b/app/www/src/prepend.inc.php deleted file mode 100644 index 5760811..0000000 --- a/app/www/src/prepend.inc.php +++ /dev/null @@ -1,13 +0,0 @@ -display("updating.tpl"); - exit(); - } -?> \ No newline at end of file diff --git a/app/www/updating.php b/app/www/updating.php deleted file mode 100644 index 6fcfd2f..0000000 --- a/app/www/updating.php +++ /dev/null @@ -1,5 +0,0 @@ -display("updating.tpl"); -?> \ No newline at end of file diff --git a/sql/database.sql b/sql/database.sql index 466dd4d..b36bc11 100644 --- a/sql/database.sql +++ b/sql/database.sql @@ -263,7 +263,6 @@ INSERT INTO `config` (`id`,`key`,`value`) VALUES (2,'menustyle','0'), (3,'user_prefix','u'), (4,'paging_items','20'), -(6,'update_status','0'), (7,'login','admin'), (8,'email_dsn',''), (9,'email_copy','1'),