Marius Cramer
2013-11-20 56364927166c1a0e15166433613add7f300ef7f6
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
604c0c 111         $web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->form->id));
TB 112         $sql = "SELECT * FROM web_backup WHERE parent_domain_id = ".$app->functions->intval($this->form->id)." AND server_id = ".$app->functions->intval($web['server_id'])." ORDER BY tstamp DESC, backup_type ASC";
7fe908 113         $records = $app->db->queryAllRecords($sql);
5a43e7 114
7fe908 115         $bgcolor = "#FFFFFF";
MC 116         if(is_array($records)) {
117             foreach($records as $rec) {
5a43e7 118
7fe908 119                 // Change of color
MC 120                 $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
121                 $rec["bgcolor"] = $bgcolor;
122
123                 $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
124                 $rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
125
126                 $records_new[] = $rec;
127             }
128         }
129
130         $listTpl->setLoop('records', @$records_new);
131
132         $listTpl->setVar('parent_id', $this->form->id);
133         $listTpl->setVar('msg', $message);
134         $listTpl->setVar('error', $error);
135
136         // Setting Returnto information in the session
137         $list_name = 'backup_list';
138         // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
139         $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
140         $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
141         $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
142         $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
143         $_SESSION["s"]["form"]["return_to"] = $list_name;
144
145         return $listTpl->grab();
146     }
147
5a43e7 148 }
T 149
7fe908 150 ?>