Skip to content

Commit 1390c8b

Browse files
committed
Implemented: FS#1251 - Add option to software installer to create databases
Implemented: FS#1252 - Add permission system based on user / password to app installer
1 parent dfd031a commit 1390c8b

15 files changed

+352
-27
lines changed

install/sql/ispconfig3.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ CREATE TABLE `software_package` (
745745
`package_description` text,
746746
`package_version` varchar(8) default NULL,
747747
`package_type` enum('ispconfig','app','web') NOT NULL default 'app',
748+
`package_installable` enum('yes','no','key') NOT NULL default 'yes',
749+
`package_requires_db` enum('no','mysql') NOT NULL default 'no',
750+
`package_key` varchar(255) NOT NULL,
751+
`package_config` text,
748752
PRIMARY KEY (`package_id`),
749753
UNIQUE KEY `package_name` (`package_name`)
750754
) ENGINE=MyISAM AUTO_INCREMENT=1;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb["repo_name_txt"] = 'Repository';
3+
$wb["repo_url_txt"] = 'URL';
4+
$wb["repo_username_txt"] = 'User (optional)';
5+
$wb["repo_password_txt"] = 'Password (optional)';
6+
$wb["active_txt"] = 'Active';
7+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$wb["head_txt"] = 'Install software package';
3+
$wb["install_key_txt"] = 'Enter install key';
4+
$wb["btn_save_txt"] = 'Start Installation';
5+
$wb["btn_cancel_txt"] = 'Cancel';
6+
?>

interface/web/admin/lib/lang/en_software_package_list.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ $wb['installed_txt'] = 'Status';
44
$wb['package_title_txt'] = 'Package';
55
$wb['package_description_txt'] = 'Description';
66
$wb['action_txt'] = 'Action';
7+
$wb['toolsarea_head_txt'] = 'Packages';
8+
$wb['repoupdate_txt'] = 'Update package list';
79
?>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2010, Till Brehm, projektfarm Gmbh
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+
require_once('../../lib/config.inc.php');
32+
require_once('../../lib/app.inc.php');
33+
34+
//* Check permissions for module
35+
$app->auth->check_module_permissions('admin');
36+
37+
//* This is only allowed for administrators
38+
if(!$app->auth->is_admin()) die('only allowed for administrators.');
39+
40+
$package_name = $app->db->quote($_REQUEST['package']);
41+
$install_server_id = intval($_REQUEST['server_id']);
42+
$install_key = $app->db->quote(trim($_REQUEST['install_key']));
43+
44+
$package = $app->db->queryOneRecord("SELECT * FROM software_package WHERE package_name = '$package_name'");
45+
46+
$install_key_verified = false;
47+
$message_err = '';
48+
$message_ok = '';
49+
50+
//* verify the key
51+
if($package['package_installable'] == 'key' && $install_key != '') {
52+
53+
$repo = $app->db->queryOneRecord("SELECT * FROM software_repo WHERE software_repo_id = ".$package['software_repo_id']);
54+
55+
$client = new SoapClient(null, array('location' => $repo['repo_url'],
56+
'uri' => $repo['repo_url']));
57+
58+
$install_key_verified = $client->check_installable($package_name, $install_key, $repo['repo_username'], $repo['repo_password']);
59+
60+
if($install_key_verified == false) {
61+
//$install_key = '';
62+
$message_err = 'Verification of the key failed.';
63+
} else {
64+
// Store the verified key into the database
65+
$app->db->datalogUpdate('software_package', "package_key = '$install_key'", 'package_id',$package['package_id']);
66+
}
67+
} else {
68+
$message_ok = 'Please enter the software key for the package.';
69+
}
70+
71+
//* Install packages, if all requirements are fullfilled.
72+
if($install_server_id > 0 && $package_name != '' && ($package['package_installable'] == 'yes' || $install_key_verified == true)) {
73+
$sql = "SELECT software_update_id, package_name, update_title FROM software_update WHERE type = 'full' AND package_name = '$package_name' ORDER BY v1 DESC, v2 DESC, v3 DESC, v4 DESC LIMIT 0,1";
74+
$tmp = $app->db->queryOneRecord($sql);
75+
$software_update_id = $tmp['software_update_id'];
76+
77+
//* if package requires a DB and there is no data for a db in config, then we create this data now
78+
if($package['package_requires_db'] == 'mysql') {
79+
$app->uses('ini_parser,getconf');
80+
81+
$package_config_array = array();
82+
if(trim($package['package_config']) != '') {
83+
$package_config_array = $app->ini_parser->parse_ini_string(stripslashes($package['package_config']));
84+
}
85+
86+
if(!isset($package_config_array['mysql'])) {
87+
$package_config_array['mysql'] = array( 'database_name' => 'ispapp'.$package['package_id'],
88+
'database_user' => 'ispapp'.$package['package_id'],
89+
'database_password' => md5(mt_rand()),
90+
'database_host' => 'localhost');
91+
$package_config_str = $app->ini_parser->get_ini_string($package_config_array);
92+
$app->db->datalogUpdate('software_package', "package_config = '".$app->db->quote($package_config_str)."'", 'package_id',$package['package_id']);
93+
}
94+
}
95+
96+
//* Add the record to start the install process
97+
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$install_server_id', '$software_update_id','installing')";
98+
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
99+
$message_ok = 'Starting package installation '."<a href=\"#\" onClick=\"submitForm('pageForm','admin/software_package_list.php');\">".$app->lng('next')."</a>";
100+
101+
}
102+
103+
if(count($_POST) > 2 && $install_key == '') {
104+
$message_ok = 'Please enter the software key.';
105+
}
106+
107+
//* Show key input form
108+
if($package['package_installable'] == 'key' && !$install_key_verified) {
109+
$insert_key = true;
110+
} else {
111+
$insert_key = false;
112+
}
113+
114+
// Loading the template
115+
$app->uses('tpl');
116+
$app->tpl->newTemplate("form.tpl.htm");
117+
$app->tpl->setInclude('content_tpl','templates/software_package_install.htm');
118+
119+
$app->tpl->setVar('message_ok',$message_ok);
120+
$app->tpl->setVar('message_err',$message_err);
121+
$app->tpl->setVar('insert_key',$insert_key);
122+
$app->tpl->setVar('install_key',$install_key);
123+
$app->tpl->setVar('package_name',$package_name);
124+
$app->tpl->setVar('server_id',$install_server_id);
125+
126+
127+
include_once('lib/lang/en_software_package_install.lng');
128+
$app->tpl->setVar($wb);
129+
130+
131+
$app->tpl_defaults();
132+
$app->tpl->pparse();
133+
134+
?>

interface/web/admin/software_package_list.php

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
//* Get the latest packages from the repositorys and insert them in the local database
4141
$packages_added = 0;
4242
$repos = $app->db->queryAllRecords("SELECT software_repo_id, repo_url, repo_username, repo_password FROM software_repo WHERE active = 'y'");
43-
if(is_array($repos)) {
43+
if(is_array($repos) && isset($_GET['action']) && $_GET['action'] == 'repoupdate' ) {
4444
foreach($repos as $repo) {
4545
$client = new SoapClient(null, array('location' => $repo['repo_url'],
4646
'uri' => $repo['repo_url']));
@@ -50,16 +50,26 @@
5050
foreach($packages as $p) {
5151
$package_name = $app->db->quote($p['name']);
5252
$tmp = $app->db->queryOneRecord("SELECT package_id FROM software_package WHERE package_name = '$package_name'");
53+
54+
$package_title = $app->db->quote($p['title']);
55+
$package_description = $app->db->quote($p['description']);
56+
$software_repo_id = intval($repo['software_repo_id']);
57+
$package_type = $app->db->quote($p['type']);
58+
$package_installable = $app->db->quote($p['installable']);
59+
$package_requires_db = $app->db->quote($p['requires_db']);
60+
5361
if(empty($tmp['package_id'])) {
54-
55-
$package_title = $app->db->quote($p['title']);
56-
$package_description = $app->db->quote($p['description']);
57-
$software_repo_id = intval($repo['software_repo_id']);
58-
$package_type = $app->db->quote($p['type']);
59-
60-
$sql = "INSERT INTO software_package (software_repo_id, package_name, package_title, package_description,package_type) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description','$package_type')";
61-
$app->db->query($sql);
62+
//$sql = "INSERT INTO software_package (software_repo_id, package_name, package_title, package_description,package_type,package_installable,package_requires_db) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description','$package_type','$package_installable','$package_requires_db')";
63+
//$app->db->query($sql);
64+
$insert_data = "(software_repo_id, package_name, package_title, package_description,package_type,package_installable,package_requires_db) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description','$package_type','$package_installable','$package_requires_db')";
65+
$app->db->datalogInsert('software_package', $insert_data, 'package_id');
6266
$packages_added++;
67+
} else {
68+
//$sql = "UPDATE software_package SET software_repo_id = $software_repo_id, package_title = '$package_title', package_description = '$package_description', package_type = '$package_type', package_installable = '$package_installable', package_requires_db = '$package_requires_db' WHERE package_name = '$package_name'";
69+
//$app->db->query($sql);
70+
$update_data = "software_repo_id = $software_repo_id, package_title = '$package_title', package_description = '$package_description', package_type = '$package_type', package_installable = '$package_installable', package_requires_db = '$package_requires_db'";
71+
//echo $update_data;
72+
$app->db->datalogUpdate('software_package', $update_data, 'package_id',$tmp['package_id']);
6373
}
6474
}
6575
}
@@ -93,10 +103,13 @@
93103
$tmp = $app->db->queryOneRecord($sql);
94104
if(!isset($tmp['software_update_id'])) {
95105
// Insert the update in the datbase
96-
$sql = "INSERT INTO software_update (software_repo_id, package_name, update_url, update_md5, update_dependencies, update_title, v1, v2, v3, v4, type)
97-
VALUES ($software_repo_id, '$package_name', '$update_url', '$update_md5', '$update_dependencies', '$update_title', '$v1', '$v2', '$v3', '$v4', '$type')";
106+
//$sql = "INSERT INTO software_update (software_repo_id, package_name, update_url, update_md5, update_dependencies, update_title, v1, v2, v3, v4, type)
107+
//VALUES ($software_repo_id, '$package_name', '$update_url', '$update_md5', '$update_dependencies', '$update_title', '$v1', '$v2', '$v3', '$v4', '$type')";
98108
//die($sql);
99-
$app->db->query($sql);
109+
//$app->db->query($sql);
110+
$insert_data = "(software_repo_id, package_name, update_url, update_md5, update_dependencies, update_title, v1, v2, v3, v4, type)
111+
VALUES ($software_repo_id, '$package_name', '$update_url', '$update_md5', '$update_dependencies', '$update_title', '$v1', '$v2', '$v3', '$v4', '$type')";
112+
$app->db->datalogInsert('software_update', $insert_data, 'software_update_id');
100113
}
101114

102115
}
@@ -107,6 +120,7 @@
107120
}
108121

109122
//* Install packages, if GET Request
123+
/*
110124
if(isset($_GET['action']) && $_GET['action'] == 'install' && $_GET['package'] != '' && $_GET['server_id'] > 0) {
111125
$package_name = $app->db->quote($_GET['package']);
112126
$server_id = intval($_GET['server_id']);
@@ -117,8 +131,8 @@
117131
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installing')";
118132
// $insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installed')";
119133
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
120-
121134
}
135+
*/
122136

123137

124138

@@ -139,15 +153,19 @@
139153
$version = $inst['v1'].'.'.$inst['v2'].'.'.$inst['v3'].'.'.$inst['v4'];
140154

141155
if($inst['status'] == 'installed') {
142-
$installed_txt .= $s['server_name'].": Installed version $version<br />";
156+
$installed_txt .= $s['server_name'].": ".$app->lng("Installed version $version")."<br />";
143157
} elseif ($inst['status'] == 'installing') {
144-
$installed_txt .= $s['server_name'].": Installation in progress<br />";
158+
$installed_txt .= $s['server_name'].": ".$app->lng("Installation in progress")."<br />";
145159
} elseif ($inst['status'] == 'failed') {
146-
$installed_txt .= $s['server_name'].": Installation failed<br />";
160+
$installed_txt .= $s['server_name'].": ".$app->lng("Installation failed")."<br />";
147161
} elseif ($inst['status'] == 'deleting') {
148-
$installed_txt .= $s['server_name'].": Deletion in progress<br />";
162+
$installed_txt .= $s['server_name'].": ".$app->lng("Deletion in progress")."<br />";
149163
} else {
150-
$installed_txt .= $s['server_name'].": <a href=\"#\" onClick=\"loadContent('admin/software_package_list.php?action=install&package=".$p["package_name"]."&server_id=".$s["server_id"]."');\">Install now</a><br />";
164+
if($p['package_installable'] == 'no') {
165+
$installed_txt .= $s['server_name'].": ".$app->lng("Package can not be installed.")."<br />";
166+
} else {
167+
$installed_txt .= $s['server_name'].": <a href=\"#\" onClick=\"loadContent('admin/software_package_install.php?package=".$p["package_name"]."&server_id=".$s["server_id"]."');\">Install now</a><br />";
168+
}
151169
}
152170
}
153171
$packages[$key]['installed'] = $installed_txt;

interface/web/admin/templates/language_add.htm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ <h2><tmpl_var name="list_head_txt"></h2>
1616
<input name="lng_new" id="lng_new" value="" size="30" maxlength="255" type="text" class="textInput formLengthHalf" />
1717
<p class="formHint">{tmpl_var name='language_new_hint_txt'}</p>
1818
</div>
19-
</fieldset>
19+
2020

2121
<input type="hidden" name="id" value="{tmpl_var name='id'}">
2222

2323
<div class="buttonHolder buttons">
2424
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_add.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
2525
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
2626
</div>
27+
28+
</fieldset>
29+
2730
</div>
2831

2932
</div>

interface/web/admin/templates/language_complete.htm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ <h2><tmpl_var name="list_head_txt"></h2>
1818
{tmpl_var name='language_option'}
1919
</select>
2020
</div>
21-
</fieldset>
21+
2222

23-
<div class="buttonHolder buttons" style="margin-top: -100px;">
23+
<div class="buttonHolder buttons">
2424
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_complete.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
2525
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
2626
</div>
27+
28+
</fieldset>
29+
2730
</div>
2831

2932
</div>

interface/web/admin/templates/language_edit.htm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ <h2><tmpl_var name="list_head_txt"></h2>
2424
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_edit.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
2525
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php?lng_select={tmpl_var name='lang'}');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
2626
</div>
27+
28+
29+
2730
</div>
2831

2932
</div>

interface/web/admin/templates/language_export.htm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
1111
{tmpl_var name='language_option'}
1212
</select>
1313
</div>
14-
</fieldset>
14+
1515

1616
<tmpl_if name="msg">
1717
<div id="OKMsg"><p><tmpl_var name="msg"></p></div>
@@ -23,6 +23,9 @@ <h2><tmpl_var name="list_head_txt"></h2>
2323
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_export.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
2424
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
2525
</div>
26+
27+
</fieldset>
28+
2629
</div>
2730

2831
</div>

0 commit comments

Comments
 (0)