11 define(
'RMCLOCATION',
'updates');
12 include_once
'../../include/cp_header.php';
21 'message' => $message,
25 echo json_encode(
$ret);
38 $updates = unserialize(base64_decode(file_get_contents($updfile)));
41 $rmTpl->add_style(
'updates.css',
'rmcommon');
42 $rmTpl->add_local_script(
'updates.js',
'rmcommon',
'include');
43 $rmTpl->add_head_script(
'var xoToken = "'.$xoopsSecurity->createToken().
'";');
44 $rmTpl->add_head_script(
'var langUpdated = "'.
__(
'Item updated!',
'rmcommon').
'";');
46 $rmTpl->add_help(
__(
'Updates Help',
'rmcommon'),
'http://www.xoopsmexico.net/docs/common-utilities/actualizaciones-automaticas/standalone/1/');
48 $ftpserver = parse_url(XOOPS_URL);
49 $ftpserver = $ftpserver[
'host'];
51 $pathinfo = parse_url(XOOPS_URL);
52 $ftpdir = str_replace($pathinfo[
'scheme'].
'://'.$pathinfo[
'host'],
'', XOOPS_URL);
56 include $rmTpl->get_template(
'rmc_updates.php',
'module',
'rmcommon');
69 $xoopsLogger->activated =
false;
72 $updates = unserialize(base64_decode(file_get_contents($updfile)));
74 include $rmTpl->get_template(
'ajax/rmc_updates_list.php',
'module',
'rmcommon');
85 $xoopsLogger->activated =
false;
92 $data = json_decode(file_get_contents(
$url.
'&action=update-details'),
true);
98 $files = unserialize(base64_decode(
$data[
'data'][
'files']));
100 include $rmTpl->get_template(
'ajax/rmc_files_list.php',
'module',
'rmcommon');
103 'details' =>
$data[
'data'][
'details'],
104 'files' => ob_get_clean()
116 $xoopsLogger->activated =
false;
128 $response = json_decode(file_get_contents(
$url.
'&action=login'.($cred!=
'' ?
'&l='.$cred :
'')),
true);
129 if($response[
'error']==1)
134 if(!is_dir(XOOPS_CACHE_PATH.
'/updates/'))
135 mkdir(XOOPS_CACHE_PATH.
'/updates/', 511);
137 if(!file_put_contents(XOOPS_CACHE_PATH.
'/updates/'.
$type.
'-'.
$dir.
'.zip', file_get_contents($response[
'data'][
'url'])))
138 jsonReturn(
__(
'Unable to download update file!',
'rmcommon'));
141 $zip =
new ZipArchive();
142 $res = $zip->open(XOOPS_CACHE_PATH.
'/updates/'.
$type.
'-'.
$dir.
'.zip');
144 jsonReturn(
__(
'ERROR: unable to open downloaded zip file!',
'rmcommon'));
147 $source = XOOPS_CACHE_PATH.
'/updates/'.
$type.
'-'.
$dir;
149 $rmUtil->delete_directory($source);
151 $zip->extractTo($source);
154 unlink(XOOPS_CACHE_PATH.
'/updates/'.
$type.
'-'.
$dir.
'.zip');
157 $details = json_decode(file_get_contents(
$url.
'&action=update-details'),
true);
158 if($details[
'error']==1)
161 $files = unserialize(base64_decode($details[
'data'][
'files']));
165 $target = XOOPS_ROOT_PATH.
'/modules/';
167 $target .=
'rmcommon/plugins/'.$dir;
179 $fpath = $source . $item[
'path'] . ($item[
'path']!=
'/' ?
'/' :
'') . $item[
'name'];
181 if($item[
'type']==
'directory'){
183 if($item[
'action']==
'delete')
184 is_dir(
$target.$item[
'path'].
'/'.$item[
'name']) ? $rmUtil->delete_directory(str_replace($source,
$target, $fpath)) : null;
186 !is_dir(
$target.$item[
'path'].
'/'.$item[
'name']) ? mkdir(str_replace($source,
$target, $fpath)) : null;
191 if($item[
'action']==
'delete')
192 is_file(
$target.$item[
'path'].
'/'.$item[
'name']) ? unlink(str_replace($source,
$target, $fpath)) : null;
194 copy($fpath, str_replace($source,
$target, $fpath));
196 if($item[
'action']==
'run')
197 $runFiles[] = str_replace(XOOPS_ROOT_PATH, XOOPS_URL, str_replace($source,
$target, $fpath));
206 jsonReturn(
__(
'FTP configuration not specified!',
'rmcommon'));
209 if($ftp_server==
'' || $ftp_user==
'' || $ftp_pass==
'')
210 jsonReturn(
__(
'FTP configuration not valid!',
'rmcommon'));
213 $ftpConfig->server = $ftp_server;
214 $ftpConfig->user = $ftp_user;
215 $ftpConfig->pass = $ftp_pass;
216 $ftpConfig->dir = $ftp_dir;
217 $ftpConfig->port = $ftp_port>0 ? $ftp_port : 21;
219 $ftp =
new RMFtpClient($ftp_server, $ftp_port>0 ? $ftp_port : 21, $ftp_user, $ftp_pass);
222 jsonReturn(sprintf(
__(
'Unable to connect FTP server %s',
'rmcommon'),
'<strong>'.$ftp_server.
'</strong>'));
224 $ftpConfig->base = $ftpConfig->dir .
'/modules/'.(
$type==
'plugin' ?
'rmcommon/plugins/' :
'').
$dir;
225 $ftpConfig->source = $source;
235 $updates = unserialize(base64_decode(file_get_contents(XOOPS_CACHE_PATH.
'/updates.chk')));
237 foreach($updates[
'updates'] as $upd){
239 if($upd[
'data'][
'type'] ==
$type && $upd[
'data'][
'dir']==
$dir)
continue;
244 file_put_contents(XOOPS_CACHE_PATH.
'/updates.chk', base64_encode(serialize(array(
'date'=>$updates[
'date'],
'total'=>intval($updates[
'total'])-1,
'updates'=>$new))));
247 $rmUtil->delete_directory($source);
249 if(!empty($runFiles))
250 jsonReturn(
__(
'Executing files...',
'rmcommon'), 0, array(
'run'=>json_encode($runFiles)));
252 jsonReturn(sprintf(
__(
'%s has been updated',
'rmcommon'),
'<strong>'.
$dir.
'</strong>'), 0);
259 switch (
$file[
'action']){
263 if(
$file[
'type']==
'directory' &&
$file[
'name']!=
''){
272 if(
$file[
'type']==
'file')
273 putContents($ftpConfig->base.$file[
'path'].($file[
'path']!=
'/' ?
'/' :
'').$file[
'name'], $ftpConfig->source.$file[
'path'].($file[
'path']!=
'/' ?
'/' :
'').
$file[
'name'], $ftp);
275 chmodFile($ftpConfig->base.$file[
'path'].($file[
'path']!=
'/' ?
'/' :
'').$file[
'name'],
$file[
'mode'], $ftp);
278 if (
$file[
'action']==
'run' &&
$file[
'type']==
'file')
279 $runFiles[] = $ftpConfig->target.$file[
'path'].($file[
'path']!=
'/' ?
'/' :
'').
$file[
'name'];
285 if(
$file[
'type']==
'directory')
286 deleteFTPDir($ftpConfig->base.$file[
'path'].($file[
'path']!=
'/' ?
'/' :
'').$file[
'name'], $ftp);
288 $ftp->delete($ftpConfig->base.$file[
'path'].($file[
'path']!=
'/' ?
'/' :
'').$file[
'name']);
300 $ftp->
chdir($ftpConfig->base);
304 if (!$ftp->
isDir($ftpConfig->base.$path))
305 $ftp->
mkdir($ftpConfig->base.$path);
312 return $ftp->chmod($mode,
$file);
319 $res = $ftp->put(
$file, $source, FTP_BINARY);
327 $list = $ftp->nlist(
$dir);
328 foreach($list as $item){
329 if ($item==
'.' || $item==
'..')
continue;
330 if ($ftp->isDir(
$dir.$item)){
333 $ftp->delete(
$dir.$item);
346 $xoopsLogger->activated =
false;
357 $response = json_decode(file_get_contents(
$url.
'&action=login'.($cred!=
'' ?
'&l='.$cred :
'')),
true);
358 if($response[
'error']==1)
361 if(!is_dir(XOOPS_CACHE_PATH.
'/updates/'))
362 mkdir(XOOPS_CACHE_PATH.
'/updates/', 511);
364 if(!file_put_contents(XOOPS_CACHE_PATH.
'/updates/'.
$type.
'-'.
$dir.
'.zip', file_get_contents($response[
'data'][
'url'])))
365 jsonReturn(
__(
'Unable to download update file!',
'rmcommon'));
390 header(
'Content-type: application/zip');
391 header(
'Cache-control: no-store');
392 header(
'Expires: 0');
393 header(
'Content-disposition: attachment; filename='.urlencode(
$tfile));
394 header(
'Content-Transfer-Encoding: binary');
395 header(
'Content-Lenght: '.filesize(
$file));
396 header(
'Last-Modified: '.gmdate(
"D, d M Y H:i:s",
$file).
'GMT');
412 case 'update-details':