- fixed root_db connection in openRootDB()
This commit is contained in:
@@ -45,7 +45,7 @@ class ApsInstaller extends ApsParser
|
|||||||
{
|
{
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->db_root = $db_root;
|
$this->db_root = $db_root;
|
||||||
$this->RootDir = dirname(dirname(__FILE__)) . '/';
|
$this->RootDir = dirname(dirname(dirname(dirname(__FILE__)))) . '/';
|
||||||
$this->Hosts = $settings['system']['mysql_access_host'];
|
$this->Hosts = $settings['system']['mysql_access_host'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class ApsUpdater extends ApsParser
|
|||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->RequestDomain = 'apscatalog.com';
|
$this->RequestDomain = 'apscatalog.com';
|
||||||
$this->RootUrl = '/1/';
|
$this->RootUrl = '/1/';
|
||||||
$this->RootDir = dirname(dirname(__FILE__)) . '/';
|
$this->RootDir = dirname(dirname(dirname(dirname(__FILE__)))) . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,9 +56,9 @@ class ApsUpdater extends ApsParser
|
|||||||
|
|
||||||
//return if allow_url_fopen is disabled
|
//return if allow_url_fopen is disabled
|
||||||
|
|
||||||
if(ini_get('allow_url_fopen') == '0')
|
if(!ini_get('allow_url_fopen'))
|
||||||
{
|
{
|
||||||
echo ("The APS updater cronjob requires that allow_url_fopen is enabled for the PHP CLI binary!\n");
|
echo "The APS updater cronjob requires that allow_url_fopen is enabled for the PHP CLI binary!\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,87 +79,96 @@ class ApsUpdater extends ApsParser
|
|||||||
//fetch all vendors
|
//fetch all vendors
|
||||||
|
|
||||||
$Vendors = self::FetchSubUrls($this->RootUrl);
|
$Vendors = self::FetchSubUrls($this->RootUrl);
|
||||||
foreach($Vendors as $Vendor)
|
if($Vendors !== false)
|
||||||
{
|
{
|
||||||
//fetch all applications from vendors
|
foreach($Vendors as $Vendor)
|
||||||
|
|
||||||
$Applications = self::FetchSubUrls($this->RootUrl . $Vendor);
|
|
||||||
foreach($Applications as $Application)
|
|
||||||
{
|
{
|
||||||
//get newest version of package which is already installed
|
//fetch all applications from vendors
|
||||||
|
|
||||||
$CurrentVersion = '';
|
$Applications = self::FetchSubUrls($this->RootUrl . $Vendor);
|
||||||
$Result = $this->db->query('SELECT * FROM `' . TABLE_APS_PACKAGES . '` WHERE `Name` = "' . $this->db->escape(substr($Application, 0, -1)) . '"');
|
if($Applications !== false)
|
||||||
|
|
||||||
while($Row = $this->db->fetch_array($Result))
|
|
||||||
{
|
{
|
||||||
if(version_compare($Row['Version'] . '-' . $Row['Release'], $CurrentVersion) == 1)
|
foreach($Applications as $Application)
|
||||||
{
|
{
|
||||||
$CurrentVersion = $Row['Version'] . '-' . $Row['Release'];
|
//get newest version of package which is already installed
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->db->num_rows($Result) != 0)
|
$CurrentVersion = '';
|
||||||
{
|
$Result = $this->db->query('SELECT * FROM `' . TABLE_APS_PACKAGES . '` WHERE `Name` = "' . $this->db->escape(substr($Application, 0, -1)) . '"');
|
||||||
//package already installed in system, search for newer version
|
|
||||||
|
|
||||||
if($Task['Task'] != TASK_SYSTEM_UPDATE)continue;
|
while($Row = $this->db->fetch_array($Result))
|
||||||
|
|
||||||
//fetch different versions of application from distribution server
|
|
||||||
|
|
||||||
$NewerVersion = '';
|
|
||||||
$Versions = self::FetchSubUrls($this->RootUrl . $Vendor . $Application);
|
|
||||||
foreach($Versions as $Version)
|
|
||||||
{
|
|
||||||
$OnlineVersion = substr($Version, 0, -1);
|
|
||||||
|
|
||||||
//is package newer than current version?
|
|
||||||
|
|
||||||
if(version_compare($OnlineVersion, $CurrentVersion) == 1)
|
|
||||||
{
|
{
|
||||||
//is new package newer than another one found before?
|
if(version_compare($Row['Version'] . '-' . $Row['Release'], $CurrentVersion) == 1)
|
||||||
|
|
||||||
if(version_compare($OnlineVersion, $NewerVersion) == 1)
|
|
||||||
{
|
{
|
||||||
$NewerVersion = $OnlineVersion;
|
$CurrentVersion = $Row['Version'] . '-' . $Row['Release'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if($NewerVersion != '')
|
if($this->db->num_rows($Result) != 0)
|
||||||
{
|
|
||||||
//download package as an update
|
|
||||||
|
|
||||||
self::DownloadPackage($this->RootUrl . $Vendor . $Application . $NewerVersion, substr($Application, 0, -1), $NewerVersion);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if($Task['Task'] != TASK_SYSTEM_DOWNLOAD)continue;
|
|
||||||
|
|
||||||
//new packages
|
|
||||||
|
|
||||||
$NewVersion = '';
|
|
||||||
$Versions = self::FetchSubUrls($this->RootUrl . $Vendor . $Application);
|
|
||||||
foreach($Versions as $Version)
|
|
||||||
{
|
|
||||||
$OnlineVersion = substr($Version, 0, -1);
|
|
||||||
|
|
||||||
//is package newer than another one found before?
|
|
||||||
|
|
||||||
if(version_compare($OnlineVersion, $NewVersion) == 1)
|
|
||||||
{
|
{
|
||||||
$NewVersion = $OnlineVersion;
|
//package already installed in system, search for newer version
|
||||||
|
|
||||||
|
if($Task['Task'] != TASK_SYSTEM_UPDATE)continue;
|
||||||
|
|
||||||
|
//fetch different versions of application from distribution server
|
||||||
|
|
||||||
|
$NewerVersion = '';
|
||||||
|
$Versions = self::FetchSubUrls($this->RootUrl . $Vendor . $Application);
|
||||||
|
if($Versions !== false)
|
||||||
|
{
|
||||||
|
foreach($Versions as $Version)
|
||||||
|
{
|
||||||
|
$OnlineVersion = substr($Version, 0, -1);
|
||||||
|
|
||||||
|
//is package newer than current version?
|
||||||
|
|
||||||
|
if(version_compare($OnlineVersion, $CurrentVersion) == 1)
|
||||||
|
{
|
||||||
|
//is new package newer than another one found before?
|
||||||
|
|
||||||
|
if(version_compare($OnlineVersion, $NewerVersion) == 1)
|
||||||
|
{
|
||||||
|
$NewerVersion = $OnlineVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($NewerVersion != '')
|
||||||
|
{
|
||||||
|
//download package as an update
|
||||||
|
|
||||||
|
self::DownloadPackage($this->RootUrl . $Vendor . $Application . $NewerVersion, substr($Application, 0, -1), $NewerVersion);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
if($Task['Task'] != TASK_SYSTEM_DOWNLOAD)continue;
|
||||||
|
|
||||||
if($NewVersion != '')
|
//new packages
|
||||||
{
|
|
||||||
//download package as a new one
|
|
||||||
|
|
||||||
self::DownloadPackage($this->RootUrl . $Vendor . $Application . $NewVersion, substr($Application, 0, -1), $NewVersion);
|
$NewVersion = '';
|
||||||
continue;
|
$Versions = self::FetchSubUrls($this->RootUrl . $Vendor . $Application);
|
||||||
|
foreach($Versions as $Version)
|
||||||
|
{
|
||||||
|
$OnlineVersion = substr($Version, 0, -1);
|
||||||
|
|
||||||
|
//is package newer than another one found before?
|
||||||
|
|
||||||
|
if(version_compare($OnlineVersion, $NewVersion) == 1)
|
||||||
|
{
|
||||||
|
$NewVersion = $OnlineVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($NewVersion != '')
|
||||||
|
{
|
||||||
|
//download package as a new one
|
||||||
|
|
||||||
|
self::DownloadPackage($this->RootUrl . $Vendor . $Application . $NewVersion, substr($Application, 0, -1), $NewVersion);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,16 +245,16 @@ class ApsUpdater extends ApsParser
|
|||||||
|
|
||||||
$Content = @file('http://' . $this->RequestDomain . $Url);
|
$Content = @file('http://' . $this->RequestDomain . $Url);
|
||||||
|
|
||||||
if($Content != false)
|
if($Content !== false)
|
||||||
{
|
{
|
||||||
foreach($Content as $Temp)
|
foreach($Content as $Temp)
|
||||||
{
|
{
|
||||||
//skip empty lines
|
//skip empty lines
|
||||||
|
|
||||||
if($Temp != "\r\n"
|
if($Temp != "\r\n"
|
||||||
&& $Temp != "\r"
|
&& $Temp != "\r"
|
||||||
&& $Temp != "\n"
|
&& $Temp != "\n"
|
||||||
&& $Temp != "")
|
&& $Temp != "")
|
||||||
{
|
{
|
||||||
//remove unwanted characters
|
//remove unwanted characters
|
||||||
|
|
||||||
|
|||||||
@@ -30,26 +30,24 @@ function openRootDB($debugHandler, $lockfile)
|
|||||||
{
|
{
|
||||||
global $db_root;
|
global $db_root;
|
||||||
|
|
||||||
// If one cronscript needs root, it should say $needrootdb = true before the include
|
require ('./lib/userdata.inc.php');
|
||||||
if(isset($needrootdb)
|
$db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], '');
|
||||||
&& $needrootdb === true)
|
|
||||||
|
if($db_root->link_id == 0)
|
||||||
{
|
{
|
||||||
$db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], '');
|
/**
|
||||||
|
* Do not proceed further if no database connection could be established
|
||||||
|
*/
|
||||||
|
|
||||||
if($db_root->link_id == 0)
|
fclose($debugHandler);
|
||||||
{
|
unlink($lockfile);
|
||||||
/**
|
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
|
||||||
* Do not proceed further if no database connection could be established
|
|
||||||
*/
|
|
||||||
|
|
||||||
fclose($debugHandler);
|
|
||||||
unlink($lockfile);
|
|
||||||
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($db_root->password);
|
|
||||||
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($db_root->password);
|
||||||
|
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
|
||||||
|
|
||||||
|
unset($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeRootDB()
|
function closeRootDB()
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ function showUpdateStep($task = null, $needs_status = true)
|
|||||||
* outputs [OK] (success), [??] (warning) or [!!] (failure)
|
* outputs [OK] (success), [??] (warning) or [!!] (failure)
|
||||||
* of the last update-step
|
* of the last update-step
|
||||||
*
|
*
|
||||||
* @param int status (0 = success, 1 = warning, -1 = failure)
|
* @param int status (0 = success, 1 = warning, 2 = failure)
|
||||||
*
|
*
|
||||||
* @return string formatted output and log-entry
|
* @return string formatted output and log-entry
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user