Falko Timme
2015-01-08 ebe5df76efc18b1ad17bb02447b6d9c041c7cbee
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) {
70                 $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '$backup_id'";
71                 $tmp = $app->db->queryOneRecord($sql);
72                 if($tmp['number'] == 0) {
73                     $message .= $wb['download_info_txt'];
74                     $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
75                         "VALUES (".
76                         (int)$this->form->dataRecord['server_id'] . ", " .
77                         time() . ", " .
78                         "'backup_download', " .
79                         "'".$backup_id."', " .
80                         "'pending', " .
81                         "''" .
82                         ")";
83                     $app->db->query($sql);
84                 } else {
85                     $error .= $wb['download_pending_txt'];
5a43e7 86                 }
7fe908 87             }
MC 88             if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
89                 $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'";
90                 $tmp = $app->db->queryOneRecord($sql);
91                 if($tmp['number'] == 0) {
92                     $message .= $wb['restore_info_txt'];
93                     $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
94                         "VALUES (".
95                         (int)$this->form->dataRecord['server_id'] . ", " .
96                         time() . ", " .
97                         "'backup_restore', " .
98                         "'".$backup_id."', " .
99                         "'pending', " .
100                         "''" .
101                         ")";
102                     $app->db->query($sql);
103                 } else {
104                     $error .= $wb['restore_pending_txt'];
105                 }
106             }
5a43e7 107
7fe908 108         }
5a43e7 109
7fe908 110         //* Get the data
ebe5df 111         $server_ids = array();
604c0c 112         $web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->form->id));
ebe5df 113         $database = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE parent_domain_id = ".$app->functions->intval($this->form->id));
FT 114         if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
115         if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
116         $server_ids = array_unique($server_ids);
117         $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 118         $records = $app->db->queryAllRecords($sql);
5a43e7 119
7fe908 120         $bgcolor = "#FFFFFF";
MC 121         if(is_array($records)) {
122             foreach($records as $rec) {
5a43e7 123
7fe908 124                 // Change of color
MC 125                 $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
126                 $rec["bgcolor"] = $bgcolor;
127
128                 $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
129                 $rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
130
131                 $records_new[] = $rec;
132             }
133         }
134
135         $listTpl->setLoop('records', @$records_new);
136
137         $listTpl->setVar('parent_id', $this->form->id);
138         $listTpl->setVar('msg', $message);
139         $listTpl->setVar('error', $error);
140
141         // Setting Returnto information in the session
142         $list_name = 'backup_list';
143         // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
144         $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
145         $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
146         $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
147         $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
148         $_SESSION["s"]["form"]["return_to"] = $list_name;
149
150         return $listTpl->grab();
151     }
152
5a43e7 153 }
T 154
7fe908 155 ?>