1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | $service = &$arr[0]; |
---|
6 | |
---|
7 | $service->addMethod( |
---|
8 | 'pwg.plugins.update', |
---|
9 | 'ws_plugins_update', |
---|
10 | array( |
---|
11 | 'id' => array(), |
---|
12 | 'revision' => array(), |
---|
13 | 'pwg_token' => array(), |
---|
14 | ), |
---|
15 | 'Update a plugin. Webmaster only.' |
---|
16 | ); |
---|
17 | |
---|
18 | $service->addMethod( |
---|
19 | 'pwg.themes.update', |
---|
20 | 'ws_themes_update', |
---|
21 | array( |
---|
22 | 'id' => array(), |
---|
23 | 'revision' => array(), |
---|
24 | 'pwg_token' => array(), |
---|
25 | ), |
---|
26 | 'Update a theme. Webmaster only.' |
---|
27 | ); |
---|
28 | |
---|
29 | $service->addMethod( |
---|
30 | 'pwg.languages.update', |
---|
31 | 'ws_languages_update', |
---|
32 | array( |
---|
33 | 'id' => array(), |
---|
34 | 'revision'=> array(), |
---|
35 | 'pwg_token' => array(), |
---|
36 | ), |
---|
37 | 'Update a language. Webmaster only.' |
---|
38 | ); |
---|
39 | |
---|
40 | $service->addMethod( |
---|
41 | 'pwg.extensions.checkUpdates', |
---|
42 | 'ws_extensions_checkupdates', |
---|
43 | array(), |
---|
44 | 'Check if piwigo or extensions are up to date.' |
---|
45 | ); |
---|
46 | |
---|
47 | $service->addMethod( |
---|
48 | 'pwg.extensions.ignoreUpdates', |
---|
49 | 'ws_extensions_ignoreupdates', |
---|
50 | array( |
---|
51 | 'type' => array('default'=>null), |
---|
52 | 'id' => array('default'=>null), |
---|
53 | 'reset' => array('default'=>null), |
---|
54 | 'pwg_token' => array(), |
---|
55 | ), |
---|
56 | 'Ignore an extension if it need update.' |
---|
57 | ); |
---|
58 | |
---|
59 | function ws_plugins_update($params, &$service) |
---|
60 | { |
---|
61 | if (!is_webmaster()) |
---|
62 | { |
---|
63 | return new PwgError(401, l10n('Webmaster status is required.')); |
---|
64 | } |
---|
65 | |
---|
66 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
67 | { |
---|
68 | return new PwgError(403, 'Invalid security token'); |
---|
69 | } |
---|
70 | |
---|
71 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
72 | include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); |
---|
73 | $plugins = new plugins(); |
---|
74 | |
---|
75 | if (empty($params['id']) or empty($params['revision'])) |
---|
76 | { |
---|
77 | return new PwgError(null, 'Wrong parameters'); |
---|
78 | } |
---|
79 | |
---|
80 | $plugin_id = $params['id']; |
---|
81 | $revision = $params['revision']; |
---|
82 | |
---|
83 | if (isset($plugins->db_plugins_by_id[$plugin_id]) |
---|
84 | and $plugins->db_plugins_by_id[$plugin_id]['state'] == 'active' |
---|
85 | and $plugin_id != 'autoupdate') |
---|
86 | { |
---|
87 | $plugins->perform_action('deactivate', $plugin_id); |
---|
88 | |
---|
89 | redirect(PHPWG_ROOT_PATH |
---|
90 | . 'ws.php' |
---|
91 | . '?method=pwg.plugins.update' |
---|
92 | . '&revision=' . $revision |
---|
93 | . '&id=' . $plugin_id |
---|
94 | . '&reactivate=true' |
---|
95 | . '&pwg_token=' . get_pwg_token() |
---|
96 | . '&format=json' |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | $upgrade_status = $plugins->extract_plugin_files('upgrade', $revision, $plugin_id); |
---|
101 | |
---|
102 | if (isset($params['reactivate'])) |
---|
103 | { |
---|
104 | $plugins->perform_action('activate', $plugin_id); |
---|
105 | } |
---|
106 | |
---|
107 | global $template; |
---|
108 | $template->delete_compiled_templates(); |
---|
109 | |
---|
110 | switch ($upgrade_status) |
---|
111 | { |
---|
112 | case 'ok': |
---|
113 | return sprintf(l10n('%s has been successfully upgraded.'), $plugins->fs_plugins[$plugin_id]['name']); |
---|
114 | |
---|
115 | case 'temp_path_error': |
---|
116 | return new PwgError(null, l10n('Can\'t create temporary file.')); |
---|
117 | |
---|
118 | case 'dl_archive_error': |
---|
119 | return new PwgError(null, l10n('Can\'t download archive.')); |
---|
120 | |
---|
121 | case 'archive_error': |
---|
122 | return new PwgError(null, l10n('Can\'t read or extract archive.')); |
---|
123 | |
---|
124 | default: |
---|
125 | return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status)); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | function ws_themes_update($params, &$service) |
---|
130 | { |
---|
131 | if (!is_webmaster()) |
---|
132 | { |
---|
133 | return new PwgError(401, l10n('Webmaster status is required.')); |
---|
134 | } |
---|
135 | |
---|
136 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
137 | { |
---|
138 | return new PwgError(403, 'Invalid security token'); |
---|
139 | } |
---|
140 | |
---|
141 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
142 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
143 | $themes = new themes(); |
---|
144 | |
---|
145 | $theme_id = $params['id']; |
---|
146 | $revision = $params['revision']; |
---|
147 | |
---|
148 | $upgrade_status = $themes->extract_theme_files('upgrade', $revision, $theme_id); |
---|
149 | |
---|
150 | global $template; |
---|
151 | $template->delete_compiled_templates(); |
---|
152 | |
---|
153 | switch ($upgrade_status) |
---|
154 | { |
---|
155 | case 'ok': |
---|
156 | return sprintf(l10n('%s has been successfully upgraded.'), $themes->fs_themes[$theme_id]['name']); |
---|
157 | |
---|
158 | case 'temp_path_error': |
---|
159 | return new PwgError(null, l10n('Can\'t create temporary file.')); |
---|
160 | |
---|
161 | case 'dl_archive_error': |
---|
162 | return new PwgError(null, l10n('Can\'t download archive.')); |
---|
163 | |
---|
164 | case 'archive_error': |
---|
165 | return new PwgError(null, l10n('Can\'t read or extract archive.')); |
---|
166 | |
---|
167 | default: |
---|
168 | return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status)); |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | function ws_languages_update($params, &$service) |
---|
173 | { |
---|
174 | if (!is_webmaster()) |
---|
175 | { |
---|
176 | return new PwgError(401, l10n('Webmaster status is required.')); |
---|
177 | } |
---|
178 | |
---|
179 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
180 | { |
---|
181 | return new PwgError(403, 'Invalid security token'); |
---|
182 | } |
---|
183 | |
---|
184 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
185 | include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php'); |
---|
186 | $languages = new languages(); |
---|
187 | |
---|
188 | $language_id = $params['id']; |
---|
189 | $revision = $params['revision']; |
---|
190 | |
---|
191 | $upgrade_status = $languages->extract_language_files('upgrade', $revision, $language_id); |
---|
192 | |
---|
193 | global $template; |
---|
194 | $template->delete_compiled_templates(); |
---|
195 | |
---|
196 | switch ($upgrade_status) |
---|
197 | { |
---|
198 | case 'ok': |
---|
199 | return sprintf(l10n('%s has been successfully upgraded.'), $languages->fs_languages[$language_id]['name']); |
---|
200 | |
---|
201 | case 'temp_path_error': |
---|
202 | return new PwgError(null, l10n('Can\'t create temporary file.')); |
---|
203 | |
---|
204 | case 'dl_archive_error': |
---|
205 | return new PwgError(null, l10n('Can\'t download archive.')); |
---|
206 | |
---|
207 | case 'archive_error': |
---|
208 | return new PwgError(null, l10n('Can\'t read or extract archive.')); |
---|
209 | |
---|
210 | default: |
---|
211 | return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status)); |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | function ws_extensions_checkupdates($params, &$service) |
---|
216 | { |
---|
217 | define('IN_ADMIN', true); |
---|
218 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
219 | include_once(AUTOUPDATE_PATH.'include/autoupdate.class.php'); |
---|
220 | $autoupdate = new autoupdate(); |
---|
221 | |
---|
222 | if (!is_webmaster()) |
---|
223 | { |
---|
224 | return new PwgError(401, 'Access denied'); |
---|
225 | } |
---|
226 | |
---|
227 | // Check if gallery or plugins are up to date |
---|
228 | load_language('plugin.lang', dirname(dirname(__FILE__)).'/'); |
---|
229 | |
---|
230 | function autoupdate_error() |
---|
231 | { |
---|
232 | unset($_SESSION['extensions_need_update']); |
---|
233 | return new PwgError(null, 'An error occured'); |
---|
234 | } |
---|
235 | |
---|
236 | if (!isset($_SESSION['need_update'])) |
---|
237 | $autoupdate->check_piwigo_upgrade(); |
---|
238 | |
---|
239 | if ($_SESSION['need_update']) |
---|
240 | return 'piwigo_upgrade'; |
---|
241 | |
---|
242 | // Gallery is up to date -> check extensions |
---|
243 | if (!isset($_SESSION['extensions_need_update'])) |
---|
244 | $autoupdate->check_extensions(); |
---|
245 | else |
---|
246 | $autoupdate->check_updated_extensions(); |
---|
247 | |
---|
248 | if (!empty($_SESSION['extensions_need_update'])) |
---|
249 | return 'ext_upgrade'; |
---|
250 | elseif ($_SESSION['need_update'] === false and $_SESSION['extensions_need_update'] === array()) |
---|
251 | return 'up_to_date'; |
---|
252 | |
---|
253 | autoupdate_error(); |
---|
254 | } |
---|
255 | |
---|
256 | function ws_extensions_ignoreupdates($params, &$service) |
---|
257 | { |
---|
258 | global $conf; |
---|
259 | |
---|
260 | define('IN_ADMIN', true); |
---|
261 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
262 | |
---|
263 | if (!is_webmaster()) |
---|
264 | { |
---|
265 | return new PwgError(401, 'Access denied'); |
---|
266 | } |
---|
267 | |
---|
268 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
269 | { |
---|
270 | return new PwgError(403, 'Invalid security token'); |
---|
271 | } |
---|
272 | |
---|
273 | if ($params['reset']) |
---|
274 | { |
---|
275 | $conf['AU_ignore'] = array('plugins'=>array(),'themes'=>array(),'languages'=>array()); |
---|
276 | conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore']))); |
---|
277 | unset($_SESSION['extensions_need_update']); |
---|
278 | return true; |
---|
279 | } |
---|
280 | |
---|
281 | if (empty($params['id']) or empty($params['type']) |
---|
282 | or !in_array($params['type'], array('plugins', 'themes', 'languages'))) |
---|
283 | { |
---|
284 | return new PwgError(null, 'Invalid parameters'); |
---|
285 | } |
---|
286 | |
---|
287 | // Add or remove plugin from ignore list |
---|
288 | if (!in_array($params['id'], $conf['AU_ignore'][$params['type']])) |
---|
289 | { |
---|
290 | array_push($conf['AU_ignore'][$params['type']], $params['id']); |
---|
291 | } |
---|
292 | conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore']))); |
---|
293 | unset($_SESSION['extensions_need_update']); |
---|
294 | return true; |
---|
295 | } |
---|
296 | |
---|
297 | ?> |
---|