Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
5a43e7 1 <?php
T 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
7fe908 33     var $module;
MC 34     var $form;
35     var $tab;
36     var $record_id;
37     var $formdef;
38     var $options;
5a43e7 39
7fe908 40     function onShow() {
5a43e7 41
7fe908 42         global $app;
MC 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 = $app->functions->intval($_GET['backup_id']);
57
58             //* check if the user is  owner of the parent domain
cc7a82 59             $domain_backup = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_backup WHERE backup_id = ?", $backup_id);
7fe908 60
MC 61             $check_perm = 'u';
62             if($_GET['backup_action'] == 'download') $check_perm = 'r'; // only check read permissions on download, not update permissions
63
cc7a82 64             $get_domain = $app->db->queryOneRecord("SELECT domain_id FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL($check_perm), $domain_backup["parent_domain_id"]);
7fe908 65             if(empty($get_domain) || !$get_domain) {
MC 66                 $app->error($app->tform->lng('no_domain_perm'));
67             }
68
69             if($_GET['backup_action'] == 'download' && $backup_id > 0) {
f75777 70                 $server_id = $this->form->dataRecord['server_id'];
cc7a82 71                 $backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ?", $backup_id);
f75777 72                 if($backup['server_id'] > 0) $server_id = $backup['server_id'];
cc7a82 73                 $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = ?";
MC 74                 $tmp = $app->db->queryOneRecord($sql, $backup_id);
7fe908 75                 if($tmp['number'] == 0) {
MC 76                     $message .= $wb['download_info_txt'];
77                     $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
cc7a82 78                         "VALUES (?, UNIX_TIMESTAMP(), 'backup_download', ?, 'pending', '')";
MC 79                     $app->db->query($sql, $server_id, $backup_id);
7fe908 80                 } else {
MC 81                     $error .= $wb['download_pending_txt'];
5a43e7 82                 }
7fe908 83             }
MC 84             if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
f75777 85                 $server_id = $this->form->dataRecord['server_id'];
cc7a82 86                 $backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ?", $backup_id);
f75777 87                 if($backup['server_id'] > 0) $server_id = $backup['server_id'];
aa365c 88                 $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = ?";
R 89                 $tmp = $app->db->queryOneRecord($sql, $backup_id);
7fe908 90                 if($tmp['number'] == 0) {
MC 91                     $message .= $wb['restore_info_txt'];
92                     $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
cc7a82 93                         "VALUES (?, UNIX_TIMESTAMP(), 'backup_restore', ?, 'pending', '')";
MC 94                     $app->db->query($sql, $server_id, $backup_id);
7fe908 95                 } else {
MC 96                     $error .= $wb['restore_pending_txt'];
97                 }
98             }
634132 99             if($_GET['backup_action'] == 'delete' && $backup_id > 0) {
D 100                 $server_id = $this->form->dataRecord['server_id'];
aa365c 101                 $backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ?", $backup_id);
634132 102                 if($backup['server_id'] > 0) $server_id = $backup['server_id'];
aa365c 103                 $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_delete' AND action_param = ?";
R 104                 $tmp = $app->db->queryOneRecord($sql, $backup_id);
634132 105                 if($tmp['number'] == 0) {
D 106                     $message .= $wb['delete_info_txt'];
107                     $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
aa365c 108                         "VALUES (?, UNIX_TIMESTAMP(), 'backup_delete', ?, 'pending', '')";
R 109                     $app->db->query($sql, $server_id, $backup_id);
634132 110                 } else {
D 111                     $error .= $wb['delete_pending_txt'];
112                 }
113             }
5a43e7 114
7fe908 115         }
5a43e7 116
7fe908 117         //* Get the data
ebe5df 118         $server_ids = array();
cc7a82 119         $web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->form->id);
MC 120         $databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = ?", $this->form->id);
f75777 121         if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
FT 122         if(is_array($databases) && !empty($databases)){
123             foreach($databases as $database){
124                 if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
125             }
126         }
127         $server_ids = array_unique($server_ids);
cc7a82 128         $sql = "SELECT * FROM web_backup WHERE parent_domain_id = ? AND server_id IN ? ORDER BY tstamp DESC, backup_type ASC";
MC 129         $records = $app->db->queryAllRecords($sql, $this->form->id, $server_ids);
5a43e7 130
7fe908 131         $bgcolor = "#FFFFFF";
MC 132         if(is_array($records)) {
133             foreach($records as $rec) {
5a43e7 134
7fe908 135                 // Change of color
MC 136                 $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
137                 $rec["bgcolor"] = $bgcolor;
138
139                 $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
140                 $rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
f75777 141                 
FT 142                 $rec['download_available'] = true;
143                 if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;
2c408f 144                 
MC 145                 if($rec['filesize'] > 0){
146                     $rec['filesize'] = $app->functions->currency_format($rec['filesize']/(1024*1024), 'client').' MB';
147                 }
7fe908 148
MC 149                 $records_new[] = $rec;
150             }
151         }
152
153         $listTpl->setLoop('records', @$records_new);
154
155         $listTpl->setVar('parent_id', $this->form->id);
156         $listTpl->setVar('msg', $message);
157         $listTpl->setVar('error', $error);
158
159         // Setting Returnto information in the session
160         $list_name = 'backup_list';
161         // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
162         $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
163         $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
164         $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
165         $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
166         $_SESSION["s"]["form"]["return_to"] = $list_name;
167
168         return $listTpl->grab();
169     }
170
5a43e7 171 }
T 172
7fe908 173 ?>