Skip to content

Commit 5a43e7a

Browse files
committed
- Implemented new backup and restore functions for websites and databases (see also FS#1389)
- Added "actions" framework in server to replace the functions provided by the core modules - Moved system update function from remoteactins core module to software update plugin.
1 parent 819fd7f commit 5a43e7a

32 files changed

+804
-166
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ALTER TABLE `web_database` ADD `parent_domain_id` int(11) unsigned NOT NULL DEFAULT '0' AFTER `server_id`;
2+
ALTER TABLE `web_database` ADD `backup_interval` VARCHAR( 255 ) NOT NULL DEFAULT 'none', ADD `backup_copies` INT NOT NULL DEFAULT '1' AFTER `remote_ips`;
3+
CREATE TABLE `web_backup` (
4+
`backup_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
5+
`server_id` int(10) unsigned NOT NULL,
6+
`parent_domain_id` int(10) unsigned NOT NULL,
7+
`backup_type` enum('web','mysql') NOT NULL DEFAULT 'web',
8+
`backup_mode` varchar(64) NOT NULL DEFAULT '',
9+
`tstamp` int(10) unsigned NOT NULL,
10+
`filename` varchar(255) NOT NULL,
11+
PRIMARY KEY (`backup_id`)
12+
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

install/sql/ispconfig3.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,23 @@ CREATE TABLE `webdav_user` (
14371437

14381438
-- --------------------------------------------------------
14391439

1440+
--
1441+
-- Table structure for table `web_backup`
1442+
--
1443+
1444+
CREATE TABLE `web_backup` (
1445+
`backup_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
1446+
`server_id` int(10) unsigned NOT NULL,
1447+
`parent_domain_id` int(10) unsigned NOT NULL,
1448+
`backup_type` enum('web','mysql') NOT NULL DEFAULT 'web',
1449+
`backup_mode` varchar(64) NOT NULL DEFAULT '',
1450+
`tstamp` int(10) unsigned NOT NULL,
1451+
`filename` varchar(255) NOT NULL,
1452+
PRIMARY KEY (`backup_id`)
1453+
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
1454+
1455+
-- --------------------------------------------------------
1456+
14401457
--
14411458
-- Table structure for table `web_database`
14421459
--
@@ -1449,13 +1466,16 @@ CREATE TABLE `web_database` (
14491466
`sys_perm_group` varchar(5) DEFAULT NULL,
14501467
`sys_perm_other` varchar(5) DEFAULT NULL,
14511468
`server_id` int(11) unsigned NOT NULL DEFAULT '0',
1469+
`parent_domain_id` int(11) unsigned NOT NULL DEFAULT '0',
14521470
`type` varchar(16) NOT NULL DEFAULT 'y',
14531471
`database_name` varchar(64) DEFAULT NULL,
14541472
`database_user` varchar(64) DEFAULT NULL,
14551473
`database_password` varchar(64) DEFAULT NULL,
14561474
`database_charset` varchar(64) DEFAULT NULL,
14571475
`remote_access` enum('n','y') NOT NULL DEFAULT 'y',
14581476
`remote_ips` text NOT NULL,
1477+
`backup_interval` VARCHAR( 255 ) NOT NULL DEFAULT 'none',
1478+
`backup_copies` INT NOT NULL DEFAULT '1',
14591479
`active` enum('n','y') NOT NULL DEFAULT 'y',
14601480
PRIMARY KEY (`database_id`)
14611481
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

install/tpl/server.ini.master

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ hostname=server1.domain.tld
1313
nameservers=192.168.0.1,192.168.0.2
1414
loglevel=2
1515
backup_dir=/var/backup
16-
backup_dir_ftpread=n
16+
backup_mode=rootgz
1717

1818
[mail]
1919
module=postfix_mysql
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2012, Till Brehm, ISPConfig UG
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+
class plugin_backuplist extends plugin_base {
32+
33+
var $module;
34+
var $form;
35+
var $tab;
36+
var $record_id;
37+
var $formdef;
38+
var $options;
39+
40+
function onShow() {
41+
42+
global $app;
43+
44+
$listTpl = new tpl;
45+
$listTpl->newTemplate('templates/web_backup_list.htm');
46+
47+
//* Loading language file
48+
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_web_backup_list.lng";
49+
include($lng_file);
50+
$listTpl->setVar($wb);
51+
52+
$message = '';
53+
$error = '';
54+
55+
if(isset($_GET['backup_action'])) {
56+
$backup_id = intval($_GET['backup_id']);
57+
58+
if($_GET['backup_action'] == 'download' && $backup_id > 0) {
59+
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '$backup_id'";
60+
$tmp = $app->db->queryOneRecord($sql);
61+
if($tmp['number'] == 0) {
62+
$message .= $wb['download_info_txt'];
63+
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
64+
"VALUES (".
65+
(int)$this->form->dataRecord['server_id'] . ", " .
66+
time() . ", " .
67+
"'backup_download', " .
68+
"'".$backup_id."', " .
69+
"'pending', " .
70+
"''" .
71+
")";
72+
$app->db->query($sql);
73+
} else {
74+
$error .= $wb['download_pending_txt'];
75+
}
76+
}
77+
if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
78+
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'";
79+
$tmp = $app->db->queryOneRecord($sql);
80+
if($tmp['number'] == 0) {
81+
$message .= $wb['restore_info_txt'];
82+
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
83+
"VALUES (".
84+
(int)$this->form->dataRecord['server_id'] . ", " .
85+
time() . ", " .
86+
"'backup_restore', " .
87+
"'".$backup_id."', " .
88+
"'pending', " .
89+
"''" .
90+
")";
91+
$app->db->query($sql);
92+
} else {
93+
$error .= $wb['restore_pending_txt'];
94+
}
95+
}
96+
97+
}
98+
99+
//* Get the data
100+
$sql = "SELECT * FROM web_backup WHERE parent_domain_id = ".$this->form->id." ORDER BY tstamp DESC, backup_type ASC";
101+
$records = $app->db->queryAllRecords($sql);
102+
103+
$bgcolor = "#FFFFFF";
104+
if(is_array($records)) {
105+
foreach($records as $rec) {
106+
107+
// Change of color
108+
$bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
109+
$rec["bgcolor"] = $bgcolor;
110+
111+
$rec['date'] = date($app->lng('conf_format_datetime'),$rec['tstamp']);
112+
$rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
113+
114+
$records_new[] = $rec;
115+
}
116+
}
117+
118+
$listTpl->setLoop('records',@$records_new);
119+
120+
$listTpl->setVar('parent_id',$this->form->id);
121+
$listTpl->setVar('msg',$message);
122+
$listTpl->setVar('error',$error);
123+
124+
// Setting Returnto information in the session
125+
$list_name = 'backup_list';
126+
// $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
127+
$_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
128+
$_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
129+
$_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
130+
$_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
131+
$_SESSION["s"]["form"]["return_to"] = $list_name;
132+
133+
return $listTpl->grab();
134+
}
135+
136+
}
137+
138+
?>

interface/web/admin/form/server_config.tform.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@
138138
'width' => '40',
139139
'maxlength' => '255'
140140
),
141-
'backup_dir_ftpread' => array(
141+
'backup_mode' => array(
142142
'datatype' => 'VARCHAR',
143-
'formtype' => 'CHECKBOX',
144-
'default' => 'y',
145-
'value' => array(0 => 'n', 1 => 'y')
143+
'formtype' => 'SELECT',
144+
'default' => 'userzip',
145+
'value' => array('userzip' => 'backup_mode_userzip', 'rootgz' => 'backup_mode_rootgz'),
146+
'width' => '40',
147+
'maxlength' => '255'
146148
),
147149
##################################
148150
# ENDE Datatable fields

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ $wb["network_config_warning_txt"] = 'The network configuration option is only av
8787
$wb["CA_path_txt"] = 'CA Path';
8888
$wb["CA_pass_txt"] = 'CA passphrase';
8989
$wb["fastcgi_config_syntax_txt"] = 'FastCGI config syntax';
90-
$wb["backup_dir_ftpread_txt"] = 'Backup dir. readable for website FTP users.';
90+
$wb["backup_mode_txt"] = 'Backup mode';
91+
$wb["backup_mode_userzip"] = 'Backup web files owned by web user as zip';
92+
$wb["backup_mode_rootgz"] = 'Backup all files in web directory as root user';
9193
$wb["server_type_txt"] = 'Server Type';
9294
$wb["nginx_vhost_conf_dir_txt"] = 'Nginx Vhost config dir';
9395
$wb["nginx_vhost_conf_enabled_dir_txt"] = 'Nginx Vhost config enabled dir';
@@ -153,7 +155,6 @@ $wb["set_folder_permissions_on_update_txt"] = 'Set folder permissions on update'
153155
$wb["add_web_users_to_sshusers_group_txt"] = 'Add web users to -sshusers- group';
154156
$wb["connect_userid_to_webid_txt"] = 'Connect Linux userid to webid';
155157
$wb["connect_userid_to_webid_start_txt"] = 'Start ID for userid/webid connect';
156-
157158
$wb["realtime_blackhole_list_txt"] = 'Real-time Blackhole List';
158159
$wb["realtime_blackhole_list_note_txt"] = '(Separate RBL\'s with commas)';
159160
?>

interface/web/admin/templates/server_config_server_edit.htm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ <h2><tmpl_var name="list_head_txt"></h2>
4343
<input name="backup_dir" id="backup_dir" value="{tmpl_var name='backup_dir'}" size="40" maxlength="255" type="text" class="textInput" />
4444
</div>
4545
<div class="ctrlHolder">
46-
<p class="label">{tmpl_var name='backup_dir_ftpread_txt'}</p>
47-
<div class="multiField">
48-
{tmpl_var name='backup_dir_ftpread'}
49-
</div>
50-
</div>
46+
<label for="backup_mode">{tmpl_var name='backup_mode_txt'}</label>
47+
<select name="backup_mode" id="backup_mode" class="selectInput">
48+
{tmpl_var name='backup_mode'}
49+
</select>
50+
</div>
5151
</fieldset>
5252

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

interface/web/js/scrigo.js.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ function del_record(link,confirmation) {
269269
}
270270
}
271271

272+
function confirm_action(link,confirmation) {
273+
if(window.confirm(confirmation)) {
274+
loadContent(link);
275+
}
276+
}
277+
272278
function loadContentInto(elementid,pagename) {
273279
var pageContentObject2 = jQuery.ajax({ type: "GET",
274280
url: pagename,

interface/web/mail/mail_user_edit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ function onAfterInsert() {
231231
// Spamfilter policy
232232
$policy_id = intval($this->dataRecord["policy"]);
233233
if($policy_id > 0) {
234-
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '".mysql_real_escape_string($this->dataRecord["email"])."'");
234+
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '".$app->db->quote($this->dataRecord["email"])."'");
235235
if($tmp_user["id"] > 0) {
236236
// There is already a record that we will update
237237
$app->db->datalogUpdate('spamfilter_users', "policy_id = $policy_id", 'id', $tmp_user["id"]);
238238
} else {
239239
// We create a new record
240240
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`)
241-
VALUES (".$_SESSION["s"]["user"]["userid"].", ".$domain["sys_groupid"].", 'riud', 'riud', '', ".$domain["server_id"].", 10, ".$policy_id.", '".mysql_real_escape_string($this->dataRecord["email"])."', '".mysql_real_escape_string($this->dataRecord["email"])."', 'Y')";
241+
VALUES (".$_SESSION["s"]["user"]["userid"].", ".$domain["sys_groupid"].", 'riud', 'riud', '', ".$domain["server_id"].", 10, ".$policy_id.", '".$app->db->quote($this->dataRecord["email"])."', '".$app->db->quote($this->dataRecord["email"])."', 'Y')";
242242
$app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
243243
}
244244
} // endif spamfilter policy
@@ -266,15 +266,15 @@ function onAfterUpdate() {
266266

267267
// Spamfilter policy
268268
$policy_id = intval($this->dataRecord["policy"]);
269-
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '".mysql_real_escape_string($this->dataRecord["email"])."'");
269+
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '".$app->db->quote($this->dataRecord["email"])."'");
270270
if($policy_id > 0) {
271271
if($tmp_user["id"] > 0) {
272272
// There is already a record that we will update
273273
$app->db->datalogUpdate('spamfilter_users', "policy_id = $policy_id", 'id', $tmp_user["id"]);
274274
} else {
275275
// We create a new record
276276
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`)
277-
VALUES (".$_SESSION["s"]["user"]["userid"].", ".$domain["sys_groupid"].", 'riud', 'riud', '', ".$domain["server_id"].", 10, ".$policy_id.", '".mysql_real_escape_string($this->dataRecord["email"])."', '".mysql_real_escape_string($this->dataRecord["email"])."', 'Y')";
277+
VALUES (".$_SESSION["s"]["user"]["userid"].", ".$domain["sys_groupid"].", 'riud', 'riud', '', ".$domain["server_id"].", 10, ".$policy_id.", '".$app->db->quote($this->dataRecord["email"])."', '".$app->db->quote($this->dataRecord["email"])."', 'Y')";
278278
$app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
279279
}
280280
}else {

0 commit comments

Comments
 (0)