root/modules/branches/2.10/backup/page.backup_restore.php

Revision 13600, 4.3 kB (checked in by mbrevda, 1 year ago)

finalize warm standby resotre options, needs a new framework AND TESTING. ALWAYS relaod after a standard restore

Line 
1 <?php
2 if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
3 $get_vars = array(
4                 'action'            => '',
5                 'display'            => '',
6                 'id'                => '',
7                 'path'                => '',
8                 'restore_path'        => '',
9                 'restore_source'    => '',
10                 'restore'            => '',
11                 'submit'            => '',
12                 'upload'            => ''
13                 );
14
15 foreach ($get_vars as $k => $v) {
16     $var[$k] = isset($_REQUEST[$k]) ? $_REQUEST[$k] : $v;
17 }
18
19 //set action to delete if delete was pressed instead of submit
20 if ($var['submit'] == _('Download') && $var['action'] == 'backup_list') {
21     $var['action'] = 'download';
22 }
23
24 //set action to view if only id is set
25 if ($var['action'] == '' && $var['id']) {
26     $var['action'] = 'browseserver';
27 }
28
29 //action actions
30 switch ($var['action']) {
31     case 'download':
32         $var['restore_path'] = backup_restore_locate_file($var['id'], $var['restore_path']);
33         $_SESSION['backup_restore_path'] = $var['restore_path'];
34         download_file($var['restore_path']);
35         break;
36     case 'upload':
37
38         //make sure our file was uploaded
39         if (!is_uploaded_file($_FILES['upload']['tmp_name'])) {
40             echo _('Error uploading file!');
41             $var['action'] = '';
42             break;
43
44         }
45         
46         //ensure uploaded file is a valid tar file
47         exec(fpbx_which('tar') . ' -tf ' . $_FILES['upload']['tmp_name'], $array, $ret_code);
48         if ($ret_code !== 0) {
49             echo _('Error verifying uploaded file!');
50             $var['action'] = '';
51             break;
52         }
53         
54         $dest = $amp_conf['ASTSPOOLDIR']
55                 . '/tmp/'
56                 . 'backuptmp-suser-'
57                 . time() . '-'
58                 . basename($_FILES['upload']['name']);
59         move_uploaded_file($_FILES['upload']['tmp_name'], $dest);
60         
61         //$var['restore_path'] = $dest;
62         $_SESSION['backup_restore_path'] = $dest;
63         break;
64     case 'list_dir':
65         echo json_encode(backup_jstree_list_dir($var['id'], $var['path']));
66         exit;
67         break;
68     case 'backup_list':
69         //prepare file + ensure that its local
70         if(!isset($_SESSION['backup_restore_path'])) {
71             $var['restore_path'] = backup_restore_locate_file($var['id'], $var['restore_path']);
72             
73             /*
74              * being that this is an absolute file path
75              * and being that we arent going to be sanitizing/sanity checking this path anymore
76              * store it in the session so that the user cant manipulate it
77              */
78             $_SESSION['backup_restore_path'] = $var['restore_path'];
79         }
80         break;
81     case 'restore':
82         backup_restore($_SESSION['backup_restore_path'], $var['restore']);
83         do_reload(true);//reload freepbx //TODO: make this optional from the resotre page
84         break;
85     default:
86         //if backup_restore_path is already set, we probobly dont want that any more. delete it
87         if (isset($_SESSION['backup_restore_path'])) {
88             unset($_SESSION['backup_restore_path']);
89         }
90         break;
91 }
92
93 //rnav
94 $var['servers'] = backup_get_server('all');
95 echo load_view(dirname(__FILE__) . '/views/rnav/restore.php', $var);;
96
97
98 //view actions
99 switch ($var['action']) {
100     case 'browseserver':
101         echo load_view(dirname(__FILE__) . '/views/restore/browseserver.php', $var);
102         break;
103     case 'upload':
104     case 'backup_list':
105         $var['servers'] = backup_get_server('all');
106         $var['templates'] = backup_get_template('all_detailed');
107         
108         //transalate variables
109         //TODO: make this anonymous once we require php 5.3
110         function callback(&$var) {
111             $var = backup__($var);
112         }
113         array_walk_recursive($var['servers'], 'callback');
114         array_walk_recursive($var['templates'], 'callback');
115         
116         if (is_array($var['restore_path'])) {
117             //TODO: if $var['restore_path'] is an array, that means it contains an error + error
118             // message. Do something with the error meesage
119             break;
120         }
121         
122         //try to get a manifest, and continue if we did
123         if ($var['manifest'] = backup_get_manifest_tarball($_SESSION['backup_restore_path'])) {
124             echo load_view(dirname(__FILE__) . '/views/restore/backup_list.php', $var);
125             break;
126         }
127         
128         //we didnt get a manifest. Maybe this is a legacy backup?
129         $var['restore_path']    = backup_migrate_legacy($_SESSION['backup_restore_path']);
130         $var['manifest']        = backup_get_manifest_tarball($var['restore_path']);
131         if ($var['restore_path'] && $var['manifest']) {
132             $_SESSION['backup_restore_path'] = $var['restore_path'];
133             echo load_view(dirname(__FILE__) . '/views/restore/backup_list.php', $var);
134             break;
135         }
136         
137         //still here? oops, something is really broken
138         echo _('Invalid backup for or undefined error');
139
140         dbug($_SESSION['backup_restore_path'], $var);
141         break;
142     default:
143         echo load_view(dirname(__FILE__) . '/views/restore/restore.php', $var);
144         break;
145 }
146 ?>
147
Note: See TracBrowser for help on using the browser.