Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
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'];
7fe908 88                 $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 89                 $tmp = $app->db->queryOneRecord($sql);
90                 if($tmp['number'] == 0) {
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             }
5a43e7 99
7fe908 100         }
5a43e7 101
7fe908 102         //* Get the data
ebe5df 103         $server_ids = array();
cc7a82 104         $web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->form->id);
MC 105         $databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = ?", $this->form->id);
f75777 106         if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
FT 107         if(is_array($databases) && !empty($databases)){
108             foreach($databases as $database){
109                 if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
110             }
111         }
112         $server_ids = array_unique($server_ids);
cc7a82 113         $sql = "SELECT * FROM web_backup WHERE parent_domain_id = ? AND server_id IN ? ORDER BY tstamp DESC, backup_type ASC";
MC 114         $records = $app->db->queryAllRecords($sql, $this->form->id, $server_ids);
5a43e7 115
7fe908 116         $bgcolor = "#FFFFFF";
MC 117         if(is_array($records)) {
118             foreach($records as $rec) {
5a43e7 119
7fe908 120                 // Change of color
MC 121                 $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
122                 $rec["bgcolor"] = $bgcolor;
123
124                 $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
125                 $rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
f75777 126                 
FT 127                 $rec['download_available'] = true;
128                 if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;
2c408f 129                 
MC 130                 if($rec['filesize'] > 0){
131                     $rec['filesize'] = $app->functions->currency_format($rec['filesize']/(1024*1024), 'client').' MB';
132                 }
7fe908 133
MC 134                 $records_new[] = $rec;
135             }
136         }
137
138         $listTpl->setLoop('records', @$records_new);
139
140         $listTpl->setVar('parent_id', $this->form->id);
141         $listTpl->setVar('msg', $message);
142         $listTpl->setVar('error', $error);
143
144         // Setting Returnto information in the session
145         $list_name = 'backup_list';
146         // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
147         $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
148         $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
149         $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
150         $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
151         $_SESSION["s"]["form"]["return_to"] = $list_name;
152
153         return $listTpl->grab();
154     }
155
5a43e7 156 }
T 157
7fe908 158 ?>