Skip to content

Commit 7d4360a

Browse files
committed
Added server part of the aps installer.
1 parent 55e2201 commit 7d4360a

File tree

9 files changed

+943
-5
lines changed

9 files changed

+943
-5
lines changed

install/sql/incremental/upd_0034.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ CREATE TABLE IF NOT EXISTS `aps_packages` (
4646
`category` varchar(255) NOT NULL,
4747
`version` varchar(20) NOT NULL,
4848
`release` int(4) NOT NULL,
49+
`package_url` TEXT NOT NULL,
4950
`package_status` int(1) NOT NULL DEFAULT '2',
5051
PRIMARY KEY (`id`)
5152
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

install/sql/ispconfig3.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ CREATE TABLE IF NOT EXISTS `aps_packages` (
9494
`category` varchar(255) NOT NULL,
9595
`version` varchar(20) NOT NULL,
9696
`release` int(4) NOT NULL,
97+
`package_url` TEXT NOT NULL,
9798
`package_status` int(1) NOT NULL DEFAULT '2',
9899
PRIMARY KEY (`id`)
99100
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

interface/lib/classes/aps_crawler.inc.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
class ApsCrawler extends ApsBase
3636
{
37+
38+
public $app_download_url_list = array();
39+
3740
/**
3841
* Constructor
3942
*
@@ -290,6 +293,8 @@ public function startCrawler()
290293
$app_dl = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='aps']/@href");
291294
$app_filesize = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='aps']/@length");
292295
$app_metafile = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='meta']/@href");
296+
297+
$this->app_download_url_list[$app_name.'-'.$new_ver.'.app.zip'] = $app_dl;
293298

294299
// Skip ASP.net packages because they can't be used at all
295300
$asp_handler = parent::getXPathValue($sxe, '//aspnet:handler');
@@ -476,12 +481,13 @@ public function parseFolderToDB()
476481
$path_query = $this->db->queryAllRecords('SELECT path AS Path FROM aps_packages;');
477482
foreach($path_query as $path) $existing_packages[] = $path['Path'];
478483
$diff = array_diff($existing_packages, $pkg_list);
479-
foreach($diff as $todelete)
484+
foreach($diff as $todelete) {
480485
/*$this->db->query("UPDATE aps_packages SET package_status = '".PACKAGE_ERROR_NOMETA."'
481486
WHERE path = '".$this->db->quote($todelete)."';");*/
482487
$tmp = $this->db->queryOneRecord("SELECT id FROM aps_packages WHERE path = '".$this->db->quote($todelete)."';");
483488
$this->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_ERROR_NOMETA, 'id', $tmp['id']);
484489
unset($tmp);
490+
}
485491

486492
// Register all new packages
487493
$new_packages = array_diff($pkg_list, $existing_packages);
@@ -515,10 +521,10 @@ public function parseFolderToDB()
515521
".$this->db->quote($pkg_release).", ".PACKAGE_ENABLED.");");
516522
*/
517523

518-
$insert_data = "(`path`, `name`, `category`, `version`, `release`, `package_status`) VALUES
524+
$insert_data = "(`path`, `name`, `category`, `version`, `release`, `package_url`, `package_status`) VALUES
519525
('".$this->db->quote($pkg)."', '".$this->db->quote($pkg_name)."',
520526
'".$this->db->quote($pkg_category)."', '".$this->db->quote($pkg_version)."',
521-
".$this->db->quote($pkg_release).", ".PACKAGE_ENABLED.");";
527+
".$this->db->quote($pkg_release).", '".$this->db->quote($this->app_download_url_list[$pkg])."', ".PACKAGE_ENABLED.");";
522528

523529
$this->app->db->datalogInsert('aps_packages', $insert_data, 'id');
524530
}

interface/lib/classes/aps_guicontroller.inc.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ public function createPackageInstance($settings, $packageid)
199199
{
200200
global $app;
201201

202+
include_once(ISPC_WEB_PATH.'/sites/tools.inc.php');
203+
202204
$webserver_id = 0;
203205
$websrv = $this->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '".$this->db->quote($settings['main_domain'])."';");
204206
if(!empty($websrv)) $webserver_id = $websrv['server_id'];
@@ -256,9 +258,11 @@ public function createPackageInstance($settings, $packageid)
256258
if($tmp['number'] == 0) break;
257259
}
258260

261+
$mysql_db_password = $settings['main_database_password'];
262+
259263
//* Create the mysql database
260264
$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`)
261-
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']."')";
265+
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']."')";
262266
$app->db->datalogInsert('web_database', $insert_data, 'database_id');
263267

264268
//* Add db details to package settings

interface/web/sites/aps_cron_apscrawler_if.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
//require_once('classes/class.crawler.php');
3333
$app->load('aps_crawler');
3434

35+
if(!@ini_get('allow_url_fopen')) $app->error('allow_url_fopen is not enabled');
36+
if(!function_exists('curl_version')) $app->error('cURL is not available');
37+
3538
$log_prefix = 'APS crawler cron: ';
3639

3740
$aps = new ApsCrawler($app, true); // true = Interface mode, false = Server mode
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/*
3+
Copyright (c) 2012, ISPConfig UG
4+
Contributors: web wack creations, http://www.web-wack.at
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
// Constants describing instances
32+
define('INSTANCE_PENDING', 0);
33+
define('INSTANCE_INSTALL', 1);
34+
define('INSTANCE_ERROR', 2);
35+
define('INSTANCE_SUCCESS', 3);
36+
define('INSTANCE_REMOVE', 4);
37+
38+
// Constants describing packages
39+
define('PACKAGE_LOCKED', 1);
40+
define('PACKAGE_ENABLED', 2);
41+
define('PACKAGE_OUTDATED', 3);
42+
define('PACKAGE_ERROR_NOMETA', 4);
43+
44+
class ApsBase
45+
{
46+
protected $app = null;
47+
protected $db = null;
48+
49+
protected $log_prefix = '';
50+
protected $fetch_url = '';
51+
protected $aps_version = '';
52+
protected $packages_dir = '';
53+
protected $temp_pkg_dir = '';
54+
protected $interface_pkg_dir = '';
55+
protected $interface_mode = false; // server mode by default
56+
57+
/**
58+
* Constructor
59+
*
60+
* @param $app the application instance (db handle + log method)
61+
* @param $interface_mode act in interface (true) or server mode (false)
62+
* @param $log_prefix a prefix to set before all log entries
63+
*/
64+
public function __construct($app, $log_prefix = 'APS: ', $interface_mode = false)
65+
{
66+
$this->db = $app->db;
67+
$this->app = $app;
68+
69+
$this->log_prefix = $log_prefix;
70+
$this->interface_mode = $interface_mode;
71+
$this->fetch_url = 'apscatalog.com';
72+
$this->aps_version = '1';
73+
$this->packages_dir = ISPC_ROOT_PATH.'/aps_packages';
74+
$this->interface_pkg_dir = ISPC_ROOT_PATH.'/web/sites/aps_meta_packages';
75+
}
76+
77+
/**
78+
* Converts a given value to it's native representation in 1024 units
79+
*
80+
* @param $value the size to convert
81+
* @return integer and string
82+
*/
83+
public function convertSize($value)
84+
{
85+
$unit = array('Bytes', 'KB', 'MB', 'GB', 'TB');
86+
return @round($value/pow(1024, ($i = floor(log($value, 1024)))), 2).' '.$unit[$i];
87+
}
88+
89+
/**
90+
* Determine a specific xpath from a given SimpleXMLElement handle. If the
91+
* element is found, it's string representation is returned. If not,
92+
* the return value will stay empty
93+
*
94+
* @param $xml_handle the SimpleXMLElement handle
95+
* @param $query the XPath query
96+
* @param $array define whether to return an array or a string
97+
* @return $ret the return string
98+
*/
99+
protected function getXPathValue($xml_handle, $query, $array = false)
100+
{
101+
$ret = '';
102+
103+
$xp_result = @($xml_handle->xpath($query)) ? $xml_handle->xpath($query) : false;
104+
if($xp_result !== false) $ret = (($array === false) ? (string)$xp_result[0] : $xp_result);
105+
106+
return $ret;
107+
}
108+
}
109+
?>

0 commit comments

Comments
 (0)