-
Notifications
You must be signed in to change notification settings - Fork 0
/
jextupdater.php
181 lines (163 loc) · 6.41 KB
/
jextupdater.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
* @package Extensions Live Updater Plugin for Joomla
* @version 2.0
* @company WEB EXPERT SERVICES LTD
* @developer Stergios Zgouletas <[email protected]>
* @link http://www.web-expert.gr
* @copyright Copyright (C) 2007-2023 Web-Expert.gr All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Plugin\CMSPlugin as JPlugin;
use Joomla\String\StringHelper as JString;
use Joomla\CMS\Uri\Uri as JURI;
use Joomla\CMS\Filesystem\Folder as JFolder;
use Joomla\CMS\Filesystem\File as JFile;
use Joomla\CMS\Plugin\PluginHelper as JPluginHelper;
use Joomla\CMS\Component\ComponentHelper as JComponentHelper;
use Joomla\CMS\Module\ModuleHelper as JModuleHelper;
use Joomla\Registry\Registry as JRegistry;
class plgSystemJExtUpdater extends JPlugin
{
protected $app;
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
if(!$this->app) $this->app=JFactory::getApplication();
}
public function onInstallerBeforePackageDownload(&$url, &$headers)
{
//Performance Check
if(strpos($url,'=JExtUpdater')===false) return true;
//Security Reasons
$allowedKeyNames=array('dlid','key','licensekey','downloadkey','downloadid','download');
$query=parse_url($url, PHP_URL_QUERY);
parse_str($query,$params);
//Check Params if are compatible with current live update system
if(empty($params) || !array_key_exists('extname',$params) || !array_key_exists('type',$params) || empty($params['extname']) || empty($params['type']))
{
return true;
}
if(!isset($params['license']) || empty($params['license']))
{
$params['license']='free';
}
if(!isset($params['keyparam']) || empty($params['keyparam']) || !in_array(strtolower($params['keyparam']),$allowedKeyNames))
{
$params['keyparam']=reset($allowedKeyNames);
}
$ddlKey='dlid';
if(isset($params['ddlkey']) && !empty($params['ddlkey']))
{
$ddlKey=JString::trim(strip_tags($params['ddlkey']));
}
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
$extensionClassName=ucfirst(strtolower($params['extname']));
$params['domain']=rtrim(str_replace(array('https:','http:','www.'),'',JURI::root()),'/');
$params['serverip']=$_SERVER['SERVER_ADDR'];
$params['php']=PHP_VERSION;
$params['ioncube']=function_exists('ioncube_loader_version')?ioncube_loader_version():'';
$params['joomla']=JVERSION;
$params[$ddlKey]=null; //reset if exists
if($params['type']=='module')
{
$module = JModuleHelper::getModule('mod_'.$params['extname']);
$extensionParams = class_exists('JRegistry')? new JRegistry($module->params) : new JParameter($module->params);
if(JFile::exists(JPATH_ROOT.DS.'modules'.DS.'mod_'.$params['extname'].DS.'helper.php'))
{
$class='mod'.$extensionClassName.'Helper';
require_once(JPATH_ROOT.DS.'modules'.DS.'mod_'.$params['extname'].DS.'helper.php');
if(method_exists($class,'onUpdateBeforePackageDownload'))
{
$result=$class::onUpdateBeforePackageDownload($extensionParams,$params,$url,$headers);
if(is_bool($result)) return $result;
}
}
}
elseif($params['type']=='plugin')
{
$plugin = JPluginHelper::getPlugin($params['plgtype'],$params['extname']);
$extensionParams = class_exists('JRegistry')? new JRegistry($plugin->params) : new JParameter($plugin->params);
$keyParameter=$extensionParams->get($params['keyparam'],'');
//VM extensions are tricky
if(empty($keyParameter) && ($params['plgtype']=='vmpayment' || $params['plgtype']=='vmshipment'))
{
$db = JFactory::getDBO();
$type=substr($params['plgtype'],2);
$paramKey=$type.'_params';
$db->setQuery('SELECT '.$db->quoteName($paramKey).' FROM '.$db->quoteName('#__virtuemart_'.$type.'methods').' WHERE '.$db->quoteName($type.'_element').'='.$db->quote($params['extname']).' ORDER BY `published` DESC LIMIT 10;');
$vmPluginDataList=$db->loadObjectList();
foreach($vmPluginDataList as $vmPlugin)
{
$vmPluginData=$vmPlugin->$paramKey;
if(!empty($vmPluginData))
{
$vmparams=array();
foreach(explode('|',$vmPluginData) as $ps)
{
if(empty($ps)) continue;
$p=@explode('=',$ps,2);
$vmparams[$p[0]]=@json_decode($p[1]);
}
$vmparams = class_exists('JRegistry')? new JRegistry($vmparams) : new JParameter($vmparams);
if(!empty($vmparams->get($params['keyparam'],'')))
{
$extensionParams->merge($vmparams);
break;
}
}
}
if(JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php'))
{
if(!class_exists ('VmConfig')) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
$config = VmConfig::loadConfig();
}
if (!class_exists('vmPSPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');
}
JPluginHelper::importPlugin($params['plgtype'],$params['extname']);
$result=$this->trigger('onUpdateBeforePackageDownload', array($extensionParams,$params,$url,$headers));
if(is_bool($result)) return $result;
}
elseif($params['type']=='component')
{
$extensionParams = JComponentHelper::getParams('com_'.$params['extname']);
if(JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_'.$params['extname'].DS.'helpers'.DS.'update.php'))
{
$class='com'.$extensionClassName.'Update';
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_'.$params['extname'].DS.'helpers'.DS.'update.php');
if(method_exists($class,'onUpdateBeforePackageDownload'))
{
$result=$class::onUpdateBeforePackageDownload($extensionParams,$params,$url,$headers);
if(is_bool($result)) return $result;
}
}
}
else
{
return true;
}
//Key is Only for Paid Extensions
if($params['license']!='free')
{
$params[$ddlKey]=preg_replace("/[^a-zA-Z0-9_-]/",'',$extensionParams->get($params['keyparam'],$params[$ddlKey]));
}
$params=array_filter($params); //clean empty values
$url=str_replace($query,http_build_query($params),$url);
return true;
}
function trigger($event,$params=array())
{
if(version_compare(JVERSION,'4.0.0','ge'))
{
$rsp= $this->app->triggerEvent($event,$params);
}
else
{
$dispatcher = version_compare(JVERSION,'3.0','ge')?JEventDispatcher::getInstance():JDispatcher::getInstance();
$rsp= $dispatcher->trigger($event,$params);
}
return $rsp;
}
}