Skip to content
Snippets Groups Projects
Commit 7d4360a0 authored by tbrehm's avatar tbrehm
Browse files

Added server part of the aps installer.

parent 55e22012
No related branches found
No related tags found
2 merge requests!46Master,!21Master
......@@ -46,6 +46,7 @@ CREATE TABLE IF NOT EXISTS `aps_packages` (
`category` varchar(255) NOT NULL,
`version` varchar(20) NOT NULL,
`release` int(4) NOT NULL,
`package_url` TEXT NOT NULL,
`package_status` int(1) NOT NULL DEFAULT '2',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
......
......@@ -94,6 +94,7 @@ CREATE TABLE IF NOT EXISTS `aps_packages` (
`category` varchar(255) NOT NULL,
`version` varchar(20) NOT NULL,
`release` int(4) NOT NULL,
`package_url` TEXT NOT NULL,
`package_status` int(1) NOT NULL DEFAULT '2',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
......
......@@ -34,6 +34,9 @@ require_once('aps_base.inc.php');
class ApsCrawler extends ApsBase
{
public $app_download_url_list = array();
/**
* Constructor
*
......@@ -290,6 +293,8 @@ class ApsCrawler extends ApsBase
$app_dl = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='aps']/@href");
$app_filesize = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='aps']/@length");
$app_metafile = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='meta']/@href");
$this->app_download_url_list[$app_name.'-'.$new_ver.'.app.zip'] = $app_dl;
// Skip ASP.net packages because they can't be used at all
$asp_handler = parent::getXPathValue($sxe, '//aspnet:handler');
......@@ -476,12 +481,13 @@ class ApsCrawler extends ApsBase
$path_query = $this->db->queryAllRecords('SELECT path AS Path FROM aps_packages;');
foreach($path_query as $path) $existing_packages[] = $path['Path'];
$diff = array_diff($existing_packages, $pkg_list);
foreach($diff as $todelete)
foreach($diff as $todelete) {
/*$this->db->query("UPDATE aps_packages SET package_status = '".PACKAGE_ERROR_NOMETA."'
WHERE path = '".$this->db->quote($todelete)."';");*/
$tmp = $this->db->queryOneRecord("SELECT id FROM aps_packages WHERE path = '".$this->db->quote($todelete)."';");
$this->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_ERROR_NOMETA, 'id', $tmp['id']);
unset($tmp);
}
// Register all new packages
$new_packages = array_diff($pkg_list, $existing_packages);
......@@ -515,10 +521,10 @@ class ApsCrawler extends ApsBase
".$this->db->quote($pkg_release).", ".PACKAGE_ENABLED.");");
*/
$insert_data = "(`path`, `name`, `category`, `version`, `release`, `package_status`) VALUES
$insert_data = "(`path`, `name`, `category`, `version`, `release`, `package_url`, `package_status`) VALUES
('".$this->db->quote($pkg)."', '".$this->db->quote($pkg_name)."',
'".$this->db->quote($pkg_category)."', '".$this->db->quote($pkg_version)."',
".$this->db->quote($pkg_release).", ".PACKAGE_ENABLED.");";
".$this->db->quote($pkg_release).", '".$this->db->quote($this->app_download_url_list[$pkg])."', ".PACKAGE_ENABLED.");";
$this->app->db->datalogInsert('aps_packages', $insert_data, 'id');
}
......
......@@ -199,6 +199,8 @@ class ApsGUIController extends ApsBase
{
global $app;
include_once(ISPC_WEB_PATH.'/sites/tools.inc.php');
$webserver_id = 0;
$websrv = $this->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '".$this->db->quote($settings['main_domain'])."';");
if(!empty($websrv)) $webserver_id = $websrv['server_id'];
......@@ -256,9 +258,11 @@ class ApsGUIController extends ApsBase
if($tmp['number'] == 0) break;
}
$mysql_db_password = $settings['main_database_password'];
//* Create the mysql database
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `parent_domain_id`, `type`, `database_name`, `database_user`, `database_password`, `database_charset`, `remote_access`, `remote_ips`, `backup_copies`, `active`, `backup_interval`)
VALUES( ".$websrv['sys_userid'].", ".$websrv['sys_groupid'].", 'riud', '".$websrv['sys_perm_group']."', '', $mysql_db_server_id, ".$websrv['domain_id'].", 'mysql', '$mysql_db_name', '$mysql_db_user', '$mysql_db_password', '', '$mysql_db_remote_access', '$mysql_db_remote_ips', ".$websrv['backup_copies'].", 'y', '".$websrv['backup_interval']."')";
VALUES( ".$websrv['sys_userid'].", ".$websrv['sys_groupid'].", 'riud', '".$websrv['sys_perm_group']."', '', $mysql_db_server_id, ".$websrv['domain_id'].", 'mysql', '$mysql_db_name', '$mysql_db_user', PASSWORD('$mysql_db_password'), '', '$mysql_db_remote_access', '$mysql_db_remote_ips', ".$websrv['backup_copies'].", 'y', '".$websrv['backup_interval']."')";
$app->db->datalogInsert('web_database', $insert_data, 'database_id');
//* Add db details to package settings
......
......@@ -32,6 +32,9 @@ require_once('../../lib/app.inc.php');
//require_once('classes/class.crawler.php');
$app->load('aps_crawler');
if(!@ini_get('allow_url_fopen')) $app->error('allow_url_fopen is not enabled');
if(!function_exists('curl_version')) $app->error('cURL is not available');
$log_prefix = 'APS crawler cron: ';
$aps = new ApsCrawler($app, true); // true = Interface mode, false = Server mode
......
<?php
/*
Copyright (c) 2012, ISPConfig UG
Contributors: web wack creations, http://www.web-wack.at
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Constants describing instances
define('INSTANCE_PENDING', 0);
define('INSTANCE_INSTALL', 1);
define('INSTANCE_ERROR', 2);
define('INSTANCE_SUCCESS', 3);
define('INSTANCE_REMOVE', 4);
// Constants describing packages
define('PACKAGE_LOCKED', 1);
define('PACKAGE_ENABLED', 2);
define('PACKAGE_OUTDATED', 3);
define('PACKAGE_ERROR_NOMETA', 4);
class ApsBase
{
protected $app = null;
protected $db = null;
protected $log_prefix = '';
protected $fetch_url = '';
protected $aps_version = '';
protected $packages_dir = '';
protected $temp_pkg_dir = '';
protected $interface_pkg_dir = '';
protected $interface_mode = false; // server mode by default
/**
* Constructor
*
* @param $app the application instance (db handle + log method)
* @param $interface_mode act in interface (true) or server mode (false)
* @param $log_prefix a prefix to set before all log entries
*/
public function __construct($app, $log_prefix = 'APS: ', $interface_mode = false)
{
$this->db = $app->db;
$this->app = $app;
$this->log_prefix = $log_prefix;
$this->interface_mode = $interface_mode;
$this->fetch_url = 'apscatalog.com';
$this->aps_version = '1';
$this->packages_dir = ISPC_ROOT_PATH.'/aps_packages';
$this->interface_pkg_dir = ISPC_ROOT_PATH.'/web/sites/aps_meta_packages';
}
/**
* Converts a given value to it's native representation in 1024 units
*
* @param $value the size to convert
* @return integer and string
*/
public function convertSize($value)
{
$unit = array('Bytes', 'KB', 'MB', 'GB', 'TB');
return @round($value/pow(1024, ($i = floor(log($value, 1024)))), 2).' '.$unit[$i];
}
/**
* Determine a specific xpath from a given SimpleXMLElement handle. If the
* element is found, it's string representation is returned. If not,
* the return value will stay empty
*
* @param $xml_handle the SimpleXMLElement handle
* @param $query the XPath query
* @param $array define whether to return an array or a string
* @return $ret the return string
*/
protected function getXPathValue($xml_handle, $query, $array = false)
{
$ret = '';
$xp_result = @($xml_handle->xpath($query)) ? $xml_handle->xpath($query) : false;
if($xp_result !== false) $ret = (($array === false) ? (string)$xp_result[0] : $xp_result);
return $ret;
}
}
?>
\ No newline at end of file
This diff is collapsed.
......@@ -52,7 +52,19 @@ class web_module {
'web_folder_user_delete',
'web_backup_insert',
'web_backup_update',
'web_backup_delete');
'web_backup_delete',
'aps_instance_insert',
'aps_instance_update',
'aps_instance_delete',
'aps_instance_setting_insert',
'aps_instance_setting_update',
'aps_instance_setting_delete',
'aps_package_insert',
'aps_package_update',
'aps_package_delete',
'aps_setting_insert',
'aps_setting_update',
'aps_setting_delete');
//* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin.
......@@ -98,6 +110,10 @@ class web_module {
$app->modules->registerTableHook('web_folder','web_module','process');
$app->modules->registerTableHook('web_folder_user','web_module','process');
$app->modules->registerTableHook('web_backup','web_module','process');
$app->modules->registerTableHook('aps_instances','web_module','process');
$app->modules->registerTableHook('aps_instances_settings','web_module','process');
$app->modules->registerTableHook('aps_packages','web_module','process');
$app->modules->registerTableHook('aps_settings','web_module','process');
// Register service
$app->services->registerService('httpd','web_module','restartHttpd');
......@@ -149,6 +165,26 @@ class web_module {
if($action == 'u') $app->plugins->raiseEvent('web_backup_update',$data);
if($action == 'd') $app->plugins->raiseEvent('web_backup_delete',$data);
break;
case 'aps_instances':
if($action == 'i') $app->plugins->raiseEvent('aps_instance_insert',$data);
if($action == 'u') $app->plugins->raiseEvent('aps_instance_update',$data);
if($action == 'd') $app->plugins->raiseEvent('aps_instance_delete',$data);
break;
case 'aps_instances_settings':
if($action == 'i') $app->plugins->raiseEvent('aps_instance_setting_insert',$data);
if($action == 'u') $app->plugins->raiseEvent('aps_instance_setting_update',$data);
if($action == 'd') $app->plugins->raiseEvent('aps_instance_setting_delete',$data);
break;
case 'aps_packages':
if($action == 'i') $app->plugins->raiseEvent('aps_package_insert',$data);
if($action == 'u') $app->plugins->raiseEvent('aps_package_update',$data);
if($action == 'd') $app->plugins->raiseEvent('aps_package_delete',$data);
break;
case 'aps_settings':
if($action == 'i') $app->plugins->raiseEvent('aps_setting_insert',$data);
if($action == 'u') $app->plugins->raiseEvent('aps_setting_update',$data);
if($action == 'd') $app->plugins->raiseEvent('aps_setting_delete',$data);
break;
} // end switch
} // end function
......
<?php
/*
Copyright (c) 2012, ISPConfig UG
Contributors: web wack creations, http://www.web-wack.at
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
require_once(ISPC_ROOT_PATH.'/lib/classes/aps_installer.inc.php');
//require_once(ISPC_ROOT_PATH.'/lib/classes/class.installer.php');
class aps_plugin
{
public $plugin_name = 'aps_plugin';
public $class_name = 'aps_plugin';
//* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin.
function onInstall() {
global $conf;
if($conf['services']['web'] == true) {
return true;
} else {
return false;
}
}
/**
* This method gets called when the plugin is loaded
*/
public function onLoad()
{
global $app;
// Register the available events
$app->plugins->registerEvent('aps_instance_install', $this->plugin_name, 'install');
$app->plugins->registerEvent('aps_instance_update', $this->plugin_name, 'install');
$app->plugins->registerEvent('aps_instance_delete', $this->plugin_name, 'delete');
}
/**
* (Re-)install a package
*/
public function install($event_name, $data)
{
global $app, $conf;
$app->log("Starting APS install",LOGLEVEL_DEBUG);
if(!isset($data['new']['id'])) return false;
$instanceid = $data['new']['id'];
if($data['new']['instance_status'] == INSTANCE_INSTALL) {
$aps = new ApsInstaller($app);
$app->log("Running installHandler",LOGLEVEL_DEBUG);
$aps->installHandler($instanceid, 'install');
}
}
/**
* Update an existing instance (currently unused)
*/
/*
public function update($event_name, $data)
{
}
*/
/**
* Uninstall an instance
*/
public function delete($event_name, $data)
{
global $app, $conf;
if(!isset($data['new']['id'])) return false;
$instanceid = $data['new']['id'];
if($data['new']['instance_status'] == INSTANCE_REMOVE) {
$aps = new ApsInstaller($app);
$aps->installHandler($instanceid, 'install');
}
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment