Falko Timme
2015-01-09 3d06bad1c292ddef53dc384f96bbef7e1cd3725d
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
59             $domain_backup = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_backup WHERE backup_id = ".$backup_id);
60
61             $check_perm = 'u';
62             if($_GET['backup_action'] == 'download') $check_perm = 'r'; // only check read permissions on download, not update permissions
63
64             $get_domain = $app->db->queryOneRecord("SELECT domain_id FROM web_domain WHERE domain_id = ".$app->functions->intval($domain_backup["parent_domain_id"])." AND ".$app->tform->getAuthSQL($check_perm));
65             if(empty($get_domain) || !$get_domain) {
66                 $app->error($app->tform->lng('no_domain_perm'));
67             }
68
69             if($_GET['backup_action'] == 'download' && $backup_id > 0) {
3d06ba 70                 $server_id = $this->form->dataRecord['server_id'];
FT 71                 $backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ".$backup_id);
72                 if($backup['server_id'] > 0) $server_id = $backup['server_id'];
7fe908 73                 $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '$backup_id'";
MC 74                 $tmp = $app->db->queryOneRecord($sql);
75                 if($tmp['number'] == 0) {
76                     $message .= $wb['download_info_txt'];
77                     $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
78                         "VALUES (".
3d06ba 79                         (int)$server_id . ", " .
7fe908 80                         time() . ", " .
MC 81                         "'backup_download', " .
82                         "'".$backup_id."', " .
83                         "'pending', " .
84                         "''" .
85                         ")";
86                     $app->db->query($sql);
87                 } else {
88                     $error .= $wb['download_pending_txt'];
5a43e7 89                 }
7fe908 90             }
MC 91             if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
3d06ba 92                 $server_id = $this->form->dataRecord['server_id'];
FT 93                 $backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ".$backup_id);
94                 if($backup['server_id'] > 0) $server_id = $backup['server_id'];
7fe908 95                 $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'";
MC 96                 $tmp = $app->db->queryOneRecord($sql);
97                 if($tmp['number'] == 0) {
98                     $message .= $wb['restore_info_txt'];
99                     $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
100                         "VALUES (".
3d06ba 101                         (int)$server_id . ", " .
7fe908 102                         time() . ", " .
MC 103                         "'backup_restore', " .
104                         "'".$backup_id."', " .
105                         "'pending', " .
106                         "''" .
107                         ")";
108                     $app->db->query($sql);
109                 } else {
110                     $error .= $wb['restore_pending_txt'];
111                 }
112             }
5a43e7 113
7fe908 114         }
5a43e7 115
7fe908 116         //* Get the data
ebe5df 117         $server_ids = array();
604c0c 118         $web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->form->id));
3d06ba 119         $databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = ".$app->functions->intval($this->form->id));
ebe5df 120         if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
3d06ba 121         if(is_array($databases) && !empty($databases)){
FT 122             foreach($databases as $database){
123                 if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
124             }
125         }
ebe5df 126         $server_ids = array_unique($server_ids);
FT 127         $sql = "SELECT * FROM web_backup WHERE parent_domain_id = ".$app->functions->intval($this->form->id)." AND server_id IN (".implode(',', $server_ids).") ORDER BY tstamp DESC, backup_type ASC";
7fe908 128         $records = $app->db->queryAllRecords($sql);
5a43e7 129
7fe908 130         $bgcolor = "#FFFFFF";
MC 131         if(is_array($records)) {
132             foreach($records as $rec) {
5a43e7 133
7fe908 134                 // Change of color
MC 135                 $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
136                 $rec["bgcolor"] = $bgcolor;
137
138                 $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
139                 $rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
3d06ba 140                 
FT 141                 $rec['download_available'] = true;
142                 if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;
7fe908 143
MC 144                 $records_new[] = $rec;
145             }
146         }
147
148         $listTpl->setLoop('records', @$records_new);
149
150         $listTpl->setVar('parent_id', $this->form->id);
151         $listTpl->setVar('msg', $message);
152         $listTpl->setVar('error', $error);
153
154         // Setting Returnto information in the session
155         $list_name = 'backup_list';
156         // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
157         $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
158         $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
159         $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
160         $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
161         $_SESSION["s"]["form"]["return_to"] = $list_name;
162
163         return $listTpl->grab();
164     }
165
5a43e7 166 }
T 167
7fe908 168 ?>