Skip to content

Commit e2d6ed9

Browse files
committed
- added basic update script
- improved several functions in site module - added server classes to restart services
1 parent b4c7507 commit e2d6ed9

File tree

20 files changed

+3676
-72
lines changed

20 files changed

+3676
-72
lines changed

install/install.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,19 @@
115115
spamd
116116
*/
117117

118-
exec("/etc/init.d/mysql restart");
119-
exec("/etc/init.d/postfix restart");
120-
exec("/etc/init.d/saslauthd restart");
121-
exec("/etc/init.d/amavis restart");
122-
exec("/etc/init.d/clamav-daemon restart");
123-
exec("/etc/init.d/courier-authdaemon restart");
124-
exec("/etc/init.d/courier-imap restart");
125-
exec("/etc/init.d/courier-imap-ssl restart");
126-
exec("/etc/init.d/courier-pop restart");
127-
exec("/etc/init.d/courier-pop-ssl restart");
128-
exec("/etc/init.d/apache2 restart");
118+
swriteln('Restarting services ...');
119+
system("/etc/init.d/mysql restart");
120+
system("/etc/init.d/postfix restart");
121+
system("/etc/init.d/saslauthd restart");
122+
system("/etc/init.d/amavis restart");
123+
system("/etc/init.d/clamav-daemon restart");
124+
system("/etc/init.d/courier-authdaemon restart");
125+
system("/etc/init.d/courier-imap restart");
126+
system("/etc/init.d/courier-imap-ssl restart");
127+
system("/etc/init.d/courier-pop restart");
128+
system("/etc/init.d/courier-pop-ssl restart");
129+
system("/etc/init.d/apache2 restart");
130+
system("/etc/init.d/pure-ftpd-mysql restart");
129131

130132
echo "Installation finished.\n";
131133

install/lib/installer_base.lib.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ function configure_pureftpd() {
467467
wf($conf["dist_pureftpd_config_dir"].'/'.$configfile,$content);
468468
exec('chmod 600 '.$conf["dist_pureftpd_config_dir"].'/'.$configfile);
469469
exec('chown root:root '.$conf["dist_pureftpd_config_dir"].'/'.$configfile);
470+
// enable chrooting
471+
exec('echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone');
470472

471473
}
472474

install/sql/ispconfig3.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ CREATE TABLE `server` (
404404
-- Daten für Tabelle `server`
405405
--
406406

407+
INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 1, 'riud', 'riud', 'r', 'Server 1', 1, 1, 1, 1, 1, 1, '[global]\nwebserver=apache\nmailserver=postfix\ndnsserver=mydns\n\n[mail]\nmodule=postfix_mysql\nmaildir_path=/home/vmail/[domain]/[localpart]/\nhomedir_path=/home/vmail/\nmailuser_uid=5000\nmailuser_gid=5000\nmailuser_name=vmail\nmailuser_group=vmail\n\n[getmail]\ngetmail_config_dir=/etc/getmail\n\n[web]\nwebsite_path=/var/clients/client[client_id]/web[website_id]\nwebsite_symlinks=/var/www/[website_domain]/:/var/clients/client[client_id]/[website_domain]/\n\n', 0, 1);
408+
407409
-- --------------------------------------------------------
408410

409411
--

install/update.php

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, 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+
/*
32+
ISPConfig 3 installer.
33+
*/
34+
35+
// Include the library with the basic installer functions
36+
require_once('lib/install.lib.php');
37+
38+
// Include the base class of the installer class
39+
require_once('lib/installer_base.lib.php');
40+
41+
$distname = get_distname();
42+
43+
include_once("/usr/local/ispconfig/server/lib/config.inc.php");
44+
$conf_old = $conf;
45+
unset $conf;
46+
47+
// Include the distribution specific installer class library
48+
// and configuration
49+
include_once('dist/lib/'.$distname.'.lib.php');
50+
include_once('dist/conf/'.$distname.'.conf.php');
51+
52+
// Set the mysql login information
53+
$conf["mysql_server_host"] = $conf_old["db_host"];
54+
$conf["mysql_server_database"] = $conf_old["db_database"];
55+
$conf["mysql_server_ispconfig_user"] = $conf_old["db_user"];
56+
$conf["mysql_server_ispconfig_password"] = $conf_old["db_password"];
57+
58+
$inst = new installer();
59+
60+
61+
echo "This application will update ISPConfig 3 on your server.\n";
62+
63+
// $conf["language"] = $inst->request_language();
64+
65+
// TODO: all other queries, for testing I will setup everything in $conf
66+
67+
// Initialize the MySQL server connection
68+
include_once('lib/mysql.lib.php');
69+
$inst->db = new db();
70+
71+
// Database update is a bit brute force and should be rebuild later ;)
72+
73+
// export the current database data
74+
exec("mysqldump -h $conf[mysql_server_host] -u $conf[mysql_server_ispconfig_user] -p$conf[mysql_server_ispconfig_password] -c -t --add-drop-table --add-locks --all --quick --lock-tables $conf[mysql_server_database] > existing_db.sql &> /dev/null");
75+
76+
// Delete the old database
77+
exec("/etc/init.d/mysql stop");
78+
exec("rm -rf /var/lib/mysql/".$conf["db_database"]);
79+
exec("/etc/init.d/mysql start");
80+
81+
// Create the mysql database
82+
$inst->configure_database();
83+
84+
// empty all databases
85+
$db_tables = $inst->db->getTables();
86+
foreach($db_tables as $table) {
87+
$inst->db->query("TRUNCATE $table");
88+
}
89+
90+
// load old data back into database
91+
exec("mysql -h $conf[mysql_server_host] -u $conf[mysql_server_ispconfig_user] -p$conf[mysql_server_ispconfig_password] $conf[mysql_server_database] < existing_db.sql &> /dev/null");
92+
93+
// Configure postfix
94+
$inst->configure_postfix();
95+
96+
// Configure saslauthd
97+
swriteln('Configuring SASL');
98+
$inst->configure_saslauthd();
99+
100+
101+
// Configure PAM
102+
swriteln('Configuring PAM');
103+
$inst->configure_pam();
104+
105+
// Configure courier
106+
swriteln('Configuring Courier');
107+
$inst->configure_courier();
108+
109+
// Configure Spamasassin
110+
swriteln('Configuring Spamassassin');
111+
$inst->configure_spamassassin();
112+
113+
// Configure Amavis
114+
swriteln('Configuring Amavisd');
115+
$inst->configure_amavis();
116+
117+
// Configure Getmail
118+
swriteln('Configuring Getmail');
119+
$inst->configure_getmail();
120+
121+
// Configure Getmail
122+
swriteln('Configuring Pureftpd');
123+
$inst->configure_pureftpd();
124+
125+
// Configure ISPConfig
126+
swriteln('Installing ISPConfig');
127+
$inst->install_ispconfig();
128+
129+
// Configure ISPConfig
130+
swriteln('Installing Crontab');
131+
$inst->install_crontab();
132+
133+
134+
/*
135+
Restart services:
136+
*/
137+
138+
swriteln('Restarting services ...');
139+
system("/etc/init.d/mysql restart");
140+
system("/etc/init.d/postfix restart");
141+
system("/etc/init.d/saslauthd restart");
142+
system("/etc/init.d/amavis restart");
143+
system("/etc/init.d/clamav-daemon restart");
144+
system("/etc/init.d/courier-authdaemon restart");
145+
system("/etc/init.d/courier-imap restart");
146+
system("/etc/init.d/courier-imap-ssl restart");
147+
system("/etc/init.d/courier-pop restart");
148+
system("/etc/init.d/courier-pop-ssl restart");
149+
system("/etc/init.d/apache2 restart");
150+
system("/etc/init.d/pure-ftpd-mysql restart");
151+
152+
echo "Update finished.\n";
153+
154+
155+
?>

interface/lib/classes/tform.inc.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,7 @@ function getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $sql_ext_whe
766766
$app->error("Primary ID fehlt!");
767767
}
768768
}
769-
770-
// Daten in History tabelle speichern
771-
if($this->errorMessage == '' and $this->formDef['db_history'] == 'yes') $this->datalogSave($action,$primary_id,$record);
769+
772770
return $sql;
773771
}
774772

@@ -839,11 +837,16 @@ function showForm() {
839837
// Set Wordbook for this form
840838

841839
$app->tpl->setVar($this->wordbook);
842-
}
843-
840+
}
844841

842+
function getDataRecord($primary_id) {
843+
global $app;
844+
$sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
845+
return $app->db->queryOneRecord($sql);
846+
}
847+
845848

846-
function datalogSave($action,$primary_id,$record_new) {
849+
function datalogSave($action,$primary_id, $record_old, $record_new) {
847850
global $app,$conf;
848851

849852
// Füge Backticks nur bei unvollständigen Tabellennamen ein
@@ -852,31 +855,42 @@ function datalogSave($action,$primary_id,$record_new) {
852855
} else {
853856
$escape = '`';
854857
}
855-
856-
if($action == "UPDATE") {
858+
859+
/*
860+
if($action == "UPDATE" or $action == "DELETE") {
857861
$sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
858862
$record_old = $app->db->queryOneRecord($sql);
859863
} else {
860864
$record_old = array();
861865
}
866+
*/
862867

863868
$diffrec = array();
864869

865-
if(is_array($record_new)) {
870+
if(is_array($record_new) && count($record_new) > 0) {
866871
foreach($record_new as $key => $val) {
867872
if($record_old[$key] != $val) {
868873
// Record has changed
869874
$diffrec[$key] = array('old' => $record_old[$key],
870875
'new' => $val);
871876
}
872877
}
878+
} elseif(is_array($record_old)) {
879+
foreach($record_old as $key => $val) {
880+
if($record_new[$key] != $val) {
881+
// Record has changed
882+
$diffrec[$key] = array('new' => $record_new[$key],
883+
'old' => $val);
884+
}
885+
}
873886
}
874887
$this->diffrec = $diffrec;
875888

889+
876890
// Full diff records for ISPConfig, they have a different format then the simple diffrec
877891
$diffrec_full = array();
878892

879-
if(is_array($record_old)) {
893+
if(is_array($record_old) && count($record_old) > 0) {
880894
foreach($record_old as $key => $val) {
881895
if(isset($record_new[$key]) && $record_new[$key] != $val) {
882896
// Record has changed
@@ -887,6 +901,17 @@ function datalogSave($action,$primary_id,$record_new) {
887901
$diffrec_full['new'][$key] = $val;
888902
}
889903
}
904+
} elseif(is_array($record_new)) {
905+
foreach($record_new as $key => $val) {
906+
if(isset($record_new[$key]) && $record_old[$key] != $val) {
907+
// Record has changed
908+
$diffrec_full['new'][$key] = $val;
909+
$diffrec_full['old'][$key] = $record_old[$key];
910+
} else {
911+
$diffrec_full['new'][$key] = $val;
912+
$diffrec_full['old'][$key] = $val;
913+
}
914+
}
890915
}
891916

892917
/*
@@ -903,7 +928,11 @@ function datalogSave($action,$primary_id,$record_new) {
903928
$diffstr = $app->db->quote(serialize($diffrec_full));
904929
$username = $app->db->quote($_SESSION["s"]["user"]["username"]);
905930
$dbidx = $this->formDef['db_table_idx'].":".$primary_id;
906-
$action = ($action == 'INSERT')?'i':'u';
931+
// $action = ($action == 'INSERT')?'i':'u';
932+
933+
if($action == 'INSERT') $action = 'i';
934+
if($action == 'UPDATE') $action = 'u';
935+
if($action == 'DELETE') $action = 'd';
907936
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('".$this->formDef['db_table']."','$dbidx','$server_id','$action','".time()."','$username','$diffstr')";
908937
$app->db->query($sql);
909938
}

interface/lib/classes/tform_actions.inc.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ function onUpdate() {
102102
$ext_where = '';
103103
$sql = $app->tform->getSQL($this->dataRecord,$app->tform->getCurrentTab(),'UPDATE',$this->id,$ext_where);
104104
if($app->tform->errorMessage == '') {
105+
106+
if($app->tform->formDef['db_history'] == 'yes') {
107+
$old_data_record = $app->tform->getDataRecord($this->id);
108+
}
105109

106110
if(!empty($sql)) {
107-
$app->db->query($sql);
111+
$app->db->query($sql);
108112
if($app->db->errorMessage != '') die($app->db->errorMessage);
109113
}
110114

@@ -118,6 +122,14 @@ function onUpdate() {
118122
}
119123

120124
$this->onAfterUpdate();
125+
126+
// Write data history (sys_datalog)
127+
if($app->tform->formDef['db_history'] == 'yes') {
128+
$new_data_record = $app->tform->getDataRecord($this->id);
129+
$app->tform->datalogSave('UPDATE',$this->id,$old_data_record,$new_data_record);
130+
unset($new_data_record);
131+
unset($old_data_record);
132+
}
121133

122134
if($_REQUEST["next_tab"] == '') {
123135
$list_name = $_SESSION["s"]["form"]["return_to"];
@@ -176,6 +188,13 @@ function onInsert() {
176188

177189
$this->onAfterInsert();
178190

191+
// Write data history (sys_datalog)
192+
if($app->tform->formDef['db_history'] == 'yes') {
193+
$new_data_record = $app->tform->getDataRecord($this->id);
194+
$app->tform->datalogSave('INSERT',$this->id,array(),$new_data_record);
195+
unset($new_data_record);
196+
}
197+
179198

180199
if($_REQUEST["next_tab"] == '') {
181200
$list_name = $_SESSION["s"]["form"]["return_to"];
@@ -260,20 +279,10 @@ function onDelete() {
260279
$record_old = $app->db->queryOneRecord("SELECT * FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = ".$this->id);
261280

262281
// Saving record to datalog when db_history enabled
263-
if($form["db_history"] == 'yes') {
264-
$diffrec = array();
265-
266-
foreach($record_old as $key => $val) {
267-
// Record has changed
268-
$diffrec[$key] = array('old' => $val,
269-
'new' => '');
270-
}
271-
272-
$diffstr = $app->db->quote(serialize($diffrec));
273-
$username = $app->db->quote($_SESSION["s"]["user"]["username"]);
274-
$dbidx = $app->tform->formDef['db_table_idx'].":".$this->id;
275-
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,action,tstamp,user,data) VALUES ('".$app->tform->formDef['db_table']."','$dbidx','d','".time()."','$username','$diffstr')";
276-
$app->db->query($sql);
282+
if($app->tform->formDef["db_history"] == 'yes') {
283+
$old_data_record = $app->tform->getDataRecord($this->id);
284+
$app->tform->datalogSave('DELETE',$this->id,$old_data_record,array());
285+
unset($old_data_record);
277286
}
278287

279288
$app->db->query("DELETE FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = ".$this->id);

0 commit comments

Comments
 (0)