This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | if (!defined('BASEPATH')) { |
||
4 | exit('No direct script access allowed'); |
||
5 | } |
||
6 | |||
7 | /** |
||
8 | * Image CMS |
||
9 | * |
||
10 | * Backup Class |
||
11 | * |
||
12 | * @property Lib_admin lib_admin |
||
13 | */ |
||
14 | class Backup extends BaseAdminController |
||
15 | { |
||
16 | |||
17 | View Code Duplication | public function __construct() { |
|
18 | parent::__construct(); |
||
19 | |||
20 | $this->load->library('DX_Auth'); |
||
21 | admin_or_redirect(); |
||
22 | |||
23 | $this->load->library('form_validation'); |
||
24 | $this->load->library('lib_admin'); |
||
25 | $this->lib_admin->init_settings(); |
||
26 | } |
||
27 | |||
28 | public function save_settings() { |
||
29 | $backup = \libraries\Backup::create(); |
||
30 | |||
31 | $this->form_validation->set_rules('backup_maxsize', lang('backup_maxsize must be numeric', 'admin'), 'trim|numeric'); |
||
32 | |||
33 | if ($this->form_validation->run() == FALSE) { |
||
34 | showMessage(validation_errors(), '', 'r'); |
||
35 | |||
36 | } else { |
||
37 | |||
38 | $settings = [ |
||
39 | 'backup_del_status' => $this->input->post('backup_del_status') ?: 0, |
||
40 | 'backup_term' => $this->input->post('backup_term') ?: 6, |
||
41 | 'backup_maxsize' => $this->input->post('backup_maxsize') ?: 1000, |
||
42 | ]; |
||
43 | |||
44 | $bad = []; |
||
45 | foreach ($settings as $key => $value) { |
||
46 | if (false == $backup->setSetting($key, $value)) { |
||
47 | $bad[] = $key; |
||
48 | } |
||
49 | } |
||
50 | View Code Duplication | if (count($bad) > 0) { |
|
51 | showMessage(lang('Some of settings not saved', 'admin'), 'Error', 'r'); |
||
52 | } else { |
||
53 | showMessage(lang('Settings saved', 'admin')); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
58 | public function file_actions() { |
||
59 | $file = trim($this->input->post('file')); |
||
60 | $locked = $this->input->post('locked') ?: null; |
||
61 | switch ($this->input->post('action')) { |
||
62 | case 'backup_lock': |
||
63 | $this->filesLocking($file, $locked); |
||
64 | $dataTitle = $locked ? lang('unlock', 'admin') : lang('lock', 'admin'); |
||
65 | echo json_encode(['locked' => $locked, 'dataTitle' => lang($dataTitle, 'admin')]); |
||
66 | break; |
||
67 | case 'backup_delete': |
||
68 | $bool = \libraries\Backup::create()->deleteFile($file); |
||
69 | echo json_encode(['deleted' => $bool ? 'deleted' : 'error']); |
||
70 | break; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | public function download_file() { |
||
75 | echo 'file'; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param string $file |
||
80 | */ |
||
81 | protected function filesLocking($file, $locked) { |
||
82 | $backup = \libraries\Backup::create(); |
||
83 | $lockedFiles = $backup->getSetting('lockedFiles'); |
||
84 | if (!is_array($lockedFiles)) { |
||
85 | $lockedFiles = []; |
||
86 | } |
||
87 | if (in_array($file, $lockedFiles) && (int) $locked == 0) { |
||
88 | foreach ($lockedFiles as $key => $file_) { |
||
89 | if ($file == $file_) { |
||
90 | unset($lockedFiles[$key]); |
||
91 | } |
||
92 | } |
||
93 | } else { |
||
94 | $lockedFiles[] = $file; |
||
95 | } |
||
96 | $backup->setSetting('lockedFiles', $lockedFiles); |
||
0 ignored issues
–
show
|
|||
97 | } |
||
98 | |||
99 | public function index() { |
||
100 | $backup = \libraries\Backup::create(); |
||
101 | |||
102 | $del_status = $backup->getSetting('backup_del_status'); |
||
103 | $maxSize = $backup->getSetting('backup_maxsize'); |
||
104 | $term = $backup->getSetting('backup_term'); |
||
105 | |||
106 | $files = $backup->backupFiles(); |
||
107 | |||
108 | $this->template->add_array( |
||
109 | [ |
||
110 | 'user' => $this->get_admin_info(), |
||
111 | 'backup_del_status' => $del_status == null ? 0 : $del_status, |
||
112 | 'backup_term' => $term == null ? 6 : $term, |
||
113 | 'backup_maxsize' => $maxSize == null ? 1000 : $maxSize, |
||
114 | 'files' => $files, |
||
115 | ] |
||
116 | ); |
||
117 | |||
118 | $this->template->show('backup', false); |
||
119 | } |
||
120 | |||
121 | // Create backup file |
||
122 | |||
123 | public function create() { |
||
124 | if (!file_exists(BACKUPFOLDER)) { |
||
125 | mkdir(BACKUPFOLDER); |
||
126 | chmod(BACKUPFOLDER, 0777); |
||
127 | } |
||
128 | |||
129 | if (!is_really_writable(BACKUPFOLDER)) { |
||
130 | showMessage(langf('Directory |0| has no writing permission', 'admin', [BACKUPFOLDER]), false, 'r'); |
||
131 | exit; |
||
132 | } |
||
133 | switch ($this->input->post('save_type')) { |
||
134 | case 'local': |
||
135 | return jsCode("window.location = '" . site_url('admin/backup/force_download/' . $this->input->post('file_type')) . "'"); |
||
136 | |||
137 | case 'server': |
||
138 | $this->load->helper('file'); |
||
139 | |||
140 | $backup = \libraries\Backup::create(); |
||
141 | $deleteOld = $backup->getSetting('backup_del_status'); |
||
142 | if ($deleteOld == 1) { |
||
143 | $deleteData = $backup->deleteOldFiles(); |
||
144 | } else { |
||
145 | $deleteData = null; |
||
146 | } |
||
147 | if (FALSE !== $backup->createBackup($this->input->post('file_type'))) { |
||
148 | $message = lang('Backup copying has been completed', 'admin'); |
||
149 | if (is_array($deleteData)) { |
||
150 | $mb = number_format($deleteData['size'] / 1024 / 1024, 2); |
||
151 | $message .= "<br /> Deleted {$deleteData['count']} files on {$mb} Mb"; |
||
152 | } |
||
153 | showMessage($message); |
||
154 | } |
||
155 | break; |
||
156 | |||
157 | case 'email': |
||
158 | $this->send_to_email(); |
||
159 | break; |
||
160 | } |
||
161 | pjax('/admin/backup'); |
||
162 | } |
||
163 | |||
164 | private function send_to_email() { |
||
165 | $this->load->library('email'); |
||
166 | $this->load->library('form_validation'); |
||
167 | $this->load->helper('file'); |
||
168 | |||
169 | $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); |
||
170 | |||
171 | if ($this->form_validation->run($this) == false) { |
||
172 | showMessage(validation_errors(), false, 'r'); |
||
173 | } else { |
||
174 | $user = $this->get_admin_info(); |
||
175 | |||
176 | $fileName = \libraries\Backup::create()->createBackup($this->input->post('file_type'), 'sql'); |
||
177 | |||
178 | $this->email->to($this->input->post('email')); |
||
179 | $this->email->from($user['email']); |
||
180 | $this->email->subject(lang('Backup copying', 'admin') . date('d-m-Y H:i:s')); |
||
181 | $this->email->message(' '); |
||
182 | $this->email->attach($fileName); |
||
183 | $this->email->send(); |
||
184 | |||
185 | @unlink($fileName); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
186 | |||
187 | $this->done(); |
||
188 | } |
||
189 | pjax('/admin/backup'); |
||
190 | } |
||
191 | |||
192 | // Direct download |
||
193 | |||
194 | public function force_download($file_type) { |
||
195 | $this->load->helper('download'); |
||
196 | $fileName = \libraries\Backup::create()->createBackup($file_type, 'sql'); |
||
197 | $fileContents = file_get_contents($fileName); |
||
198 | force_download(pathinfo($fileName, PATHINFO_BASENAME), $fileContents); |
||
199 | } |
||
200 | |||
201 | private function done() { |
||
202 | showMessage(lang('Backup copying has been completed', 'admin')); |
||
203 | } |
||
204 | |||
205 | private function get_admin_info() { |
||
206 | return $this->db->get_where('users', ['id' => $this->dx_auth->get_user_id()])->row_array(); |
||
207 | } |
||
208 | |||
209 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: