-
Notifications
You must be signed in to change notification settings - Fork 9
/
modules.php
326 lines (313 loc) · 13.5 KB
/
modules.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
// addnews ready
// translator ready
// mail ready
require_once("common.php");
require_once("lib/http.php");
require_once("lib/sanitize.php");
check_su_access(SU_MANAGE_MODULES);
tlschema("modulemanage");
page_header("Module Manager");
require_once("lib/superusernav.php");
superusernav();
addnav("Module Categories");
addnav("",$REQUEST_URI);
$op = httpget('op');
$module = httpget('module');
if ($op == 'mass'){
if (httppost("activate")) $op = "activate";
if (httppost("deactivate")) $op = "deactivate";
if (httppost("uninstall")) $op = "uninstall";
if (httppost("reinstall")) $op = "reinstall";
if (httppost("install")) $op = "install";
$module = httppost("module");
}
$theOp = $op;
if (is_array($module)){
$modules = $module;
}else{
if ($module) $modules = array($module);
else $modules = array();
}
foreach ($modules as $key=>$module) {
$op = $theOp;
output("`2Performing `^%s`2 on `%%s`0`n", translate_inline($op), $module);
if($op=="install"){
if (install_module($module)){
}else{
httpset('cat','');
output("`\$Error, module could not be installed!`n`n");
}
$op="";
httpset('op', "");
massinvalidate("hook");
massinvalidate("module-prepare");
}elseif($op=="uninstall"){
if (uninstall_module($module)) {
} else {
output("`\$Error, module could not be uninstalled!`n`n");
output("Unable to inject module. Module not uninstalled.`n");
}
$op="";
httpset('op', "");
massinvalidate("hook");
massinvalidate("module-prepare");
invalidatedatacache("inject-$module");
}elseif($op=="activate"){
activate_module($module);
$op="";
httpset('op', "");
invalidatedatacache("inject-$module");
massinvalidate("hook");
massinvalidate("module-prepare");
injectmodule($module, true);
}elseif($op=="deactivate"){
deactivate_module($module);
$op="";
httpset('op', "");
invalidatedatacache("inject-$module");
massinvalidate("module-prepare");
}elseif($op=="reinstall"){
$sql = "UPDATE " . db_prefix("modules") . " SET filemoddate='".DATETIME_DATEMIN."' WHERE modulename='$module'";
db_query($sql);
// We don't care about the return value here at all.
$op="";
httpset('op', "");
invalidatedatacache("inject-$module");
massinvalidate("hook");
massinvalidate("module-prepare");
injectmodule($module, true);
}
}
$install_status = get_module_install_status();
$uninstmodules = $install_status['uninstalledmodules'];
$seencats = $install_status['installedcategories'];
$ucount = $install_status['uninstcount'];
addnav(array(" ?Uninstalled - (%s modules)", $ucount), "modules.php");
foreach ($seencats as $cat=>$count) {
$category = $cat;
if (strpos($cat,"|") !== false) {
//header included
$m_header = strtok($cat,"|");
$category = strtok("|");
addnav($m_header);
} else {
addnav("Module Categories");
}
addnav(array(" ?%s - (%s modules)", $category, $count), "modules.php?cat=$cat");
}
$cat = httpget('cat');
if ($op==""){
if ($cat) {
$sortby=httpget('sortby');
if (!$sortby) $sortby="installdate";
$order=httpget('order');
$tcat = translate_inline($cat);
output("`n`b%s Modules`b`n", $tcat);
$deactivate = translate_inline("Deactivate");
$activate = translate_inline("Activate");
$uninstall = translate_inline("Uninstall");
$reinstall = translate_inline("Reinstall");
$strsettings = translate_inline("Settings");
$strnosettings = translate_inline("`\$No Settings`0");
$uninstallconfirm = translate_inline("Are you sure you wish to uninstall this module? All user preferences and module settings will be lost. If you wish to temporarily remove access to the module, you may simply deactivate it.");
$status = translate_inline("Status");
$mname = translate_inline("Module Name");
$ops = translate_inline("Ops");
$mauth = translate_inline("Module Author");
$inon = translate_inline("Installed On");
$installstr = translate_inline("by %s");
$active = translate_inline("`@Active`0");
$inactive = translate_inline("`\$Inactive`0");
rawoutput("<form action='modules.php?op=mass&cat=$cat' method='POST'>");
addnav("","modules.php?op=mass&cat=$cat");
rawoutput("<table border='0' cellpadding='2' cellspacing='1' bgcolor='#999999'>",true);
rawoutput("<tr class='trhead'><td> </td><td>$ops</td><td><a href='modules.php?cat=$cat&sortby=active&order=".($sortby=="active"?!$order:1)."'>$status</a></td><td><a href='modules.php?cat=$cat&sortby=formalname&order=".($sortby=="formalname"?!$order:1)."'>$mname</a></td><td><a href='modules.php?cat=$cat&sortby=moduleauthor&order=".($sortby=="moduleauthor"?!$order:1)."'>$mauth</a></td><td><a href='modules.php?cat=$cat&sortby=installdate&order=".($sortby=="installdate"?!$order:0)."'>$inon</a></td></tr>");
addnav("","modules.php?cat=$cat&sortby=active&order=".($sortby=="active"?!$order:1));
addnav("","modules.php?cat=$cat&sortby=formalname&order=".($sortby=="formalname"?!$order:1));
addnav("","modules.php?cat=$cat&sortby=moduleauthor&order=".($sortby=="moduleauthor"?!$order:1));
addnav("","modules.php?cat=$cat&sortby=installdate&order=".($sortby=="installdate"?$order:0));
$sql = "SELECT * FROM " . db_prefix("modules") . " WHERE category='".db_real_escape_string($cat)."' ORDER BY ".$sortby." ".($order?"ASC":"DESC");
$result = db_query($sql);
if (db_num_rows($result)==0){
rawoutput("<tr class='trlight'><td colspan='6' align='center'>");
output("`i-- No Modules Installed--`i");
rawoutput("</td></tr>");
}
$number=db_num_rows($result);
for ($i=0;$i<$number;$i++){
$row = db_fetch_assoc($result);
rawoutput("<tr class='".($i%2?"trlight":"trdark")."'>",true);
rawoutput("<td nowrap valign='top'>");
rawoutput("<input type='checkbox' name='module[]' value=\"{$row['modulename']}\">");
rawoutput("</td><td valign='top' nowrap>[ ");
if ($row['active']){
rawoutput("<a href='modules.php?op=deactivate&module={$row['modulename']}&cat=$cat'>");
output_notl($deactivate);
rawoutput("</a>");
addnav("","modules.php?op=deactivate&module={$row['modulename']}&cat=$cat");
}else{
rawoutput("<a href='modules.php?op=activate&module={$row['modulename']}&cat=$cat'>");
output_notl($activate);
rawoutput("</a>");
addnav("","modules.php?op=activate&module={$row['modulename']}&cat=$cat");
}
rawoutput(" |<a href='modules.php?op=uninstall&module={$row['modulename']}&cat=$cat' onClick='return confirm(\"$uninstallconfirm\");'>");
output_notl($uninstall);
rawoutput("</a>");
addnav("","modules.php?op=uninstall&module={$row['modulename']}&cat=$cat");
rawoutput(" | <a href='modules.php?op=reinstall&module={$row['modulename']}&cat=$cat'>");
output_notl($reinstall);
rawoutput("</a>");
addnav("","modules.php?op=reinstall&module={$row['modulename']}&cat=$cat");
if ($session['user']['superuser'] & SU_EDIT_CONFIG) {
if (strstr($row['infokeys'], "|settings|")) {
rawoutput(" | <a href='configuration.php?op=modulesettings&module={$row['modulename']}'>");
output_notl($strsettings);
rawoutput("</a>");
addnav("","configuration.php?op=modulesettings&module={$row['modulename']}");
} else {
output_notl(" | %s", $strnosettings);
}
}
rawoutput(" ]</td><td valign='top'>");
output_notl($row['active']?$active:$inactive);
require_once("lib/sanitize.php");
rawoutput("</td><td nowrap valign='top'><span title=\"".
(isset($row['description'])&&$row['description']?
$row['description']:sanitize($row['formalname']))."\">");
output_notl("%s", $row['formalname']);
rawoutput("<br>");
output_notl("(%s) V%s", $row['modulename'],$row['version']);
rawoutput("</span></td><td valign='top'>");
output_notl("`#%s`0", $row['moduleauthor'], true);
rawoutput("</td><td nowrap valign='top'>");
$line = sprintf($installstr, $row['installedby']);
output_notl("%s", $row['installdate']);
rawoutput("<br>");
output_notl("%s", $line);
rawoutput("</td></tr>");
}
rawoutput("</table><br />");
$activate = translate_inline("Activate");
$deactivate = translate_inline("Deactivate");
$reinstall = translate_inline("Reinstall");
$uninstall = translate_inline("Uninstall");
rawoutput("<input type='submit' name='activate' class='button' value='$activate'>");
rawoutput("<input type='submit' name='deactivate' class='button' value='$deactivate'>");
rawoutput("<input type='submit' name='reinstall' class='button' value='$reinstall'>");
rawoutput("<input type='submit' name='uninstall' class='button' value='$uninstall'>");
rawoutput("</form>");
} else {
$sorting=httpget('sorting');
if (!$sorting) $sorting="shortname";
$order=httpget('order');
output("`bUninstalled Modules`b`n");
$install = translate_inline("Install");
$mname = translate_inline("Module Name");
$ops = translate_inline("Ops");
$mauth = translate_inline("Module Author");
$categ = translate_inline("Category");
$fname = translate_inline("Filename");
rawoutput("<form action='modules.php?op=mass&cat=$cat' method='POST'>");
addnav("","modules.php?op=mass&cat=$cat");
rawoutput("<table border='0' cellpadding='2' cellspacing='1' bgcolor='#999999'>",true);
rawoutput("<tr class='trhead'><td> </td><td>$ops</td><td><a href='modules.php?sorting=name&order=".($sorting=="name"?!$order:0)."'>$mname</a></td><td><a href='modules.php?sorting=author&order=".($sorting=="author"?!$order:0)."'>$mauth</a></td><td><a href='modules.php?sorting=category&order=".($sorting=="category"?!$order:0)."'>$categ</a></td><td><a href='modules.php?sorting=shortname&order=".($sorting=="shortname"?!$order:0)."'>$fname</a></td></tr>");
addnav("","modules.php?sorting=name&order=".($sorting=="name"?!$order:0));
addnav("","modules.php?sorting=author&order=".($sorting=="author"?!$order:0));
addnav("","modules.php?sorting=category&order=".($sorting=="category"?!$order:0));
addnav("","modules.php?sorting=shortname&order=".($sorting=="shortname"?!$order:0));
$invalidmodule = array(
"version"=>"",
"author"=>"",
"category"=>"",
"download"=>"",
"invalid"=>true,
);
if (count($uninstmodules) > 0) {
$count = 0;
$moduleinfo=array();
$sortby=array();
$numberarray=array();
foreach($uninstmodules as $key=>$shortname) {
//test if the file is a valid module or a lib file/whatever that got in, maybe even malcode that does not have module form
$file = file_get_contents("modules/$shortname.php");
if (strpos($file,$shortname."_getmoduleinfo")===false ||
//strpos($file,$shortname."_dohook")===false ||
//do_hook is not a necessity
strpos($file,$shortname."_install")===false ||
strpos($file,$shortname."_uninstall")===false) {
//here the files has neither do_hook nor getinfo, which means it won't execute as a module here --> block it + notify the admin who is the manage modules section
$temp=array_merge($invalidmodule,array("name"=>$shortname.".php ".appoencode(translate_inline("(`\$Invalid Module! Contact Author or check file!`0)"))));
} else {
$temp= get_module_info($shortname);
}
//end of testing
if (!$temp || empty($temp)) continue;
$temp['shortname']=$shortname;
array_push($moduleinfo,$temp);
array_push($sortby,full_sanitize($temp[$sorting]));
array_push($numberarray,$count);
$count++;
}
array_multisort($sortby,($order?SORT_DESC:SORT_ASC),$numberarray,($order?SORT_DESC:SORT_ASC));
for ($a=0;$a<count($moduleinfo);$a++) {
$i=$numberarray[$a];
rawoutput("<tr class='".($i%2?"trlight":"trdark")."'>");
if (isset($moduleinfo[$i]['invalid']) && $moduleinfo[$i]['invalid']===true) {
rawoutput("<td></td><td nowrap valign='top'>");
output("Not installable");
rawoutput("</td>");
} else {
rawoutput("<td><input type='checkbox' name='module[]' value='{$moduleinfo[$i]['shortname']}'></td>");
rawoutput("<td nowrap valign='top'>");
rawoutput("[ <a href='modules.php?op=install&module={$moduleinfo[$i]['shortname']}&cat={$moduleinfo[$i]['category']}'>");
output_notl($install);
rawoutput("</a>]</td>");
addnav("","modules.php?op=install&module={$moduleinfo[$i]['shortname']}&cat={$moduleinfo[$i]['category']}");
}
rawoutput("<td nowrap valign='top'><span title=\"".
(isset($moduleinfo[$i]['description'])&&
$moduleinfo[$i]['description'] ?
$moduleinfo[$i]['description'] :
sanitize($moduleinfo[$i]['name']))."\">");
rawoutput($moduleinfo[$i]['name']." ".$moduleinfo[$i]['version']);
rawoutput("</span></td><td valign='top'>");
output_notl("`#%s`0", $moduleinfo[$i]['author'], true);
rawoutput("</td><td valign='top'>");
rawoutput($moduleinfo[$i]['category']);
rawoutput("</td><td valign='top'>");
rawoutput($moduleinfo[$i]['shortname'] . ".php");
rawoutput("</td>");
rawoutput("</tr>");
if (isset($moduleinfo[$i]['requires']) && is_array($moduleinfo[$i]['requires']) && count($moduleinfo[$i]['requires']) > 0){
rawoutput("<tr class='".($i%2?"trlight":"trdark")."'>");
rawoutput("<td> </td>");
rawoutput("<td colspan='6'>");
output("`bRequires:`b`n");
foreach ($moduleinfo[$i]['requires'] as $key=>$val) {
$info = explode("|",$val);
if (module_check_requirements(array($key=>$val))){
output_notl("`@");
}else{
output_notl("`\$");
}
output_notl("$key {$info[0]} -- {$info[1]}`n");
}
rawoutput("</td>");
rawoutput("</tr>");
}
$count++;
}
} else {
rawoutput("<tr class='trlight'><td colspan='6' align='center'>");
output("`i--No uninstalled modules were found--`i");
rawoutput("</td></tr>");
}
rawoutput("</table><br />");
$install = translate_inline("Install");
rawoutput("<input type='submit' name='install' class='button' value='$install'>");
}
}
page_footer();
?>