/** * create a database if necessary and setup environment variables * * @param xml instance of a valid xml object with a parsed APP-META.xml file * @param row current entry from the database for app to handle * @param task numeric code to specify what to do */ private function PrepareDatabase($Xml, $Row, $Task) { $XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db'); if ($this->aps_version == '1.0') { // the good ole way $XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db'); } else { // since 1.1 $Xml->registerXPathNamespace('db', 'http://apstandard.com/ns/1/db'); $XmlDb = new DynamicProperties(); $XmlDb->db->id = getXPathValue($Xml, '//db:id'); } if ($XmlDb->db->id) { //database management $NewDatabase = 'web' . $Row['CustomerID'] . 'aps' . $Row['InstanceID']; $result = $this->db->query('SELECT * FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID']) . ' AND `Name` = "main_database_password"'); $Row3 = $this->db->fetch_array($result); $DbPassword = $Row3['Value']; if ($Task == TASK_INSTALL) { $this->db_root->query('DROP DATABASE IF EXISTS `' . $this->db->escape($NewDatabase) . '`'); $this->db_root->query('CREATE DATABASE IF NOT EXISTS `' . $this->db->escape($NewDatabase) . '`'); foreach (array_map('trim', explode(',', $this->Hosts)) as $DatabaseHost) { $this->db_root->query('GRANT ALL PRIVILEGES ON `' . $this->db->escape($NewDatabase) . '`.* TO `' . $this->db->escape($NewDatabase) . '`@`' . $this->db->escape($DatabaseHost) . '` IDENTIFIED BY \'password\''); $this->db_root->query('SET PASSWORD FOR `' . $this->db->escape($NewDatabase) . '`@`' . $this->db->escape($DatabaseHost) . '` = PASSWORD(\'' . $DbPassword . '\')'); } $this->db_root->query('FLUSH PRIVILEGES'); /* * add database to customers databases, #272 */ $databasedescription = $Xml->name . ' ' . $Xml->version . ' (Release ' . $Xml->release . ')'; $result = $this->db->query('INSERT INTO `' . TABLE_PANEL_DATABASES . '` (`customerid`, `databasename`, `description`, `dbserver`, `apsdb`) VALUES ("' . (int) $Row['CustomerID'] . '", "' . $this->db->escape($NewDatabase) . '", "' . $this->db->escape($databasedescription) . '", "0", "1")'); $result = $this->db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `mysqls_used`=`mysqls_used`+1 WHERE `customerid`="' . (int) $Row['CustomerID'] . '"'); } //get first mysql access host $AccessHosts = array_map('trim', explode(',', $this->Hosts)); //environment variables putenv('DB_' . $XmlDb->db->id . '_TYPE=mysql'); putenv('DB_' . $XmlDb->db->id . '_NAME=' . $NewDatabase); putenv('DB_' . $XmlDb->db->id . '_LOGIN='******'DB_' . $XmlDb->db->id . '_PASSWORD='******'DB_' . $XmlDb->db->id . '_HOST=' . $AccessHosts[0]); putenv('DB_' . $XmlDb->db->id . '_PORT=3306'); putenv('DB_' . $XmlDb->db->id . '_VERSION=' . mysql_get_server_info()); } }
/** * show informations for a package in basic or detailed view * * @param packageid id of package from database * @param mode verbosity of data to view (basic|advanced) * @return error false / success none */ private function ShowPackageInfo($PackageId, $All = false) { global $lng, $filename, $s, $page, $action, $userinfo; $Data = ''; $Fieldname = ''; $Fieldvalue = ''; $Groupname = ''; if (!self::IsValidPackageId($PackageId, true)) { return false; } $result = $this->db->query('SELECT * FROM `' . TABLE_APS_PACKAGES . '` WHERE `ID` = ' . $this->db->escape($PackageId)); $Row = $this->db->fetch_array($result); $Xml = self::GetXmlFromFile('./packages/' . $Row['Path'] . '/APP-META.xml'); //return if parse of xml file has failed if ($Xml == false) { return false; } $Icon = './images/Classic/default.png'; $this->aps_version = isset($Xml->attributes()->version) ? (string) $Xml->attributes()->version : '1.0'; //show icon and basic data if ($this->aps_version != '1.0') { $iconpath = $Xml->presentation->icon['path']; $Summary = htmlspecialchars($Xml->presentation->summary); $categories = $Xml->presentation->categories; $languages = $Xml->presentation->languages; $description = $Xml->presentation->description; $changelogs = $Xml->presentation->changelog; $license = $Xml->service->license; $screenshots = $Xml->presentation->screenshot; } else { $iconpath = $Xml->icon['path']; $Summary = htmlspecialchars($Xml->summary); $categories = $Xml->categories; $languages = $Xml->languages; $description = $Xml->description; $changelogs = $Xml->changelog; $license = $Xml->license; $screenshots = $Xml->screenshot; } if ($iconpath) { $Icon = './packages/' . $Row['Path'] . '/' . basename($iconpath); } $Fieldname = $lng['aps']['version']; $Fieldvalue = $Xml->version . ' (Release ' . $Xml->release . ')'; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); //show website if ($Xml->homepage) { $Fieldname = $lng['aps']['homepage']; $Fieldvalue = '<a target="_blank" href="' . htmlspecialchars($Xml->homepage) . '">' . htmlspecialchars($Xml->homepage) . '</a>'; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } //show size after installation if ($Xml->{'installed-size'}) { $Fieldname = $lng['aps']['installed_size']; $Fieldvalue = 'ca. ' . number_format(intval($Xml->{'installed-size'}) / (1024 * 1024), 2) . ' MB'; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } //show categories if ($categories) { $Temp = ''; foreach ($categories->category as $_categories) { $Temp .= htmlspecialchars($_categories[0]) . '<br/>'; } $Fieldname = $lng['aps']['categories']; $Fieldvalue = $Temp; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } //show available languages if ($languages) { $Temp = ''; foreach ($languages->language as $_languages) { $Temp .= $_languages[0] . ' '; } $Fieldname = $lng['aps']['languages']; $Fieldvalue = $Temp; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } //show more information if ($All == true) { $Fieldname = $lng['aps']['long_description']; $Fieldvalue = htmlspecialchars($description); eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); //show config script language if ($Xml->{'configuration-script-language'}) { $Fieldname = $lng['aps']['configscript']; $Fieldvalue = $Xml->{'configuration-script-language'}; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } //show changelog $Temp = '<ul>'; foreach ($changelogs->version as $Versions) { $Temp .= '<li><strong>' . $Versions['version'] . ' (Release ' . $Versions['release'] . ')</strong>'; $Temp .= '<ul>'; foreach ($Versions->entry as $Entries) { $Temp .= '<li>' . $Entries[0] . '</li>'; } $Temp .= '</ul></li>'; } $Temp .= '</ul>'; $Fieldname = $lng['aps']['changelog']; $Fieldvalue = $Temp; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); //show license if ($license) { if ($license->text->file) { $Temp = ''; if ($license->text->name) { $Temp = $license->text->name . '<br/>'; } $Temp .= '<form name="license" action="#"><textarea name="text" rows="10" cols="70">'; $FileContent = file_get_contents('./packages/' . $Row['Path'] . '/license.txt'); $Temp .= htmlentities($FileContent, ENT_QUOTES, 'ISO-8859-1'); $Temp .= '</textarea></form>'; $Fieldname = $lng['aps']['license']; $Fieldvalue = $Temp; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } else { $Fieldname = $lng['aps']['license']; $Fieldvalue = '<a target="_blank" href="' . htmlspecialchars($license->text->url) . '">' . $lng['aps']['linktolicense'] . '</a>'; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } } //show screenshots if ($screenshots) { $Count = 0; $Temp = ''; foreach ($screenshots as $Screenshot) { $Count += 1; $Temp .= '<img src="./packages/' . $Row['Path'] . '/' . basename($Screenshot['path']) . '" alt="' . $Screenshot->description . '"/><br/><em>' . $Screenshot->description . '</em><br/>'; if (count($screenshots) != $Count) { $Temp .= '<br/>'; } } $Fieldname = $lng['aps']['screenshots']; $Fieldvalue = $Temp; eval("\$Data.=\"" . getTemplate("aps/data") . "\";"); } } /* * check if packages needs a database * and if the customer has contingent for that, #272 */ if ($this->aps_version == '1.0') { // the good ole way $XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db'); } else { // since 1.1 $Xml->registerXPathNamespace('db', 'http://apstandard.com/ns/1/db'); $XmlDb = new DynamicProperties(); $XmlDb->db->id = getXPathValue($Xml, '//db:id'); } if ($XmlDb->db->id) { if ($userinfo['mysqls_used'] < $userinfo['mysqls'] || $userinfo['mysqls'] == '-1') { $can_use_db = true; } else { $can_use_db = false; } } else { $can_use_db = true; } $db_info = ''; if (!$can_use_db) { $db_info = $lng['aps']['packageneedsdb']; } eval("echo \"" . getTemplate("aps/package") . "\";"); unset($Xml); }