]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/Backups.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Administration / Backups.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 if (!is_admin($GLOBALS['current_user']))
40 {
41    sugar_die("Unauthorized access to administration.");
42 }
43
44
45 require_once('include/utils/zip_utils.php');
46
47 $form_action = "index.php?module=Administration&action=Backups";
48
49 $backup_dir = "";
50 $backup_zip = "";
51 $run        = "confirm";
52 $input_disabled = "";
53 global $mod_strings;
54 $errors = array();
55
56 // process "run" commands
57 if( isset( $_REQUEST['run'] ) && ($_REQUEST['run'] != "") ){
58     $run = $_REQUEST['run'];
59
60     $backup_dir = $_REQUEST['backup_dir'];
61     $backup_zip = $_REQUEST['backup_zip'];
62
63     if( $run == "confirm" ){
64         if( $backup_dir == "" ){
65             $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_ERROR'];
66         }
67         if( $backup_zip == "" ){
68             $errors[] = $mod_strings['LBL_BACKUP_FILENAME_ERROR'];
69         }
70
71         if( sizeof($errors) > 0 ){
72             return( $errors );
73         }
74
75         if( !is_dir( $backup_dir ) ){
76             if( !mkdir_recursive( $backup_dir ) ){
77                 $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_EXISTS'];
78             }
79         }
80
81         if( !is_writable( $backup_dir ) ){
82             $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_NOT_WRITABLE'];
83         }
84
85         if( is_file( "$backup_dir/$backup_zip" ) ){
86             $errors[] = $mod_strings['LBL_BACKUP_FILE_EXISTS'];
87         }
88         if( is_dir( "$backup_dir/$backup_zip" ) ){
89             $errors[] = $mod_strings['LBL_BACKUP_FILE_AS_SUB'];
90         }
91         if( sizeof( $errors ) == 0 ){
92             $run = "confirmed";
93             $input_disabled = "readonly";
94         }
95     }
96     else if( $run == "confirmed" ){
97         ini_set( "memory_limit", "-1" );
98         ini_set( "max_execution_time", "0" );
99         zip_dir( ".", "$backup_dir/$backup_zip" );
100         $run = "done";
101     }
102 }
103 if( sizeof($errors) > 0 ){
104     foreach( $errors as $error ){
105         print( "<font color=\"red\">$error</font><br>" );
106     }
107 }
108 if( $run == "done" ){
109     $size = filesize( "$backup_dir/$backup_zip" );
110     print( $mod_strings['LBL_BACKUP_FILE_STORED'] . " $backup_dir/$backup_zip ($size bytes).<br>\n" );
111     print( "<a href=\"index.php?module=Administration&action=index\">" . $mod_strings['LBL_BACKUP_BACK_HOME']. "</a>\n" );
112 }
113 else{
114 ?>
115
116     <?php 
117     echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_BACKUPS_TITLE'], true); 
118     echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_1']; ?>
119     <br>
120     <?php echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_2']; ?><br>
121     <form action="<?php print( $form_action );?>" method="post">
122     <table>
123     <tr>
124         <td><?php echo $mod_strings['LBL_BACKUP_DIRECTORY']; ?><br><i><?php echo $mod_strings['LBL_BACKUP_DIRECTORY_WRITABLE']; ?></i></td>
125         <td><input size="100" type="input" name="backup_dir" <?php print( $input_disabled );?> value="<?php print( $backup_dir );?>"/></td>
126     </tr>
127     <tr>
128         <td><?php echo $mod_strings['LBL_BACKUP_FILENAME']; ?></td>
129         <td><input type="input" name="backup_zip" <?php print( $input_disabled );?> value="<?php print( $backup_zip );?>"/></td>
130     </tr>
131     </table>
132     <input type=hidden name="run" value="<?php print( $run );?>" />
133
134 <?php
135     switch( $run ){
136         case "confirm":
137 ?>
138             <input type="submit" value="<?php echo $mod_strings['LBL_BACKUP_CONFIRM']; ?>" />
139 <?php
140             break;
141         case "confirmed":
142 ?>
143             <?php echo $mod_strings['LBL_BACKUP_CONFIRMED']; ?><br>
144             <input type="submit" value="<?php echo $mod_strings['LBL_BACKUP_RUN_BACKUP']; ?>" />
145 <?php
146             break;
147     }
148 ?>
149
150     </form>
151
152 <?php
153 }   // end if/else of $run options
154 $GLOBALS['log']->info( "Backups" );
155 ?>