public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / admin / listmodules.php
100644 656 lines (584 sloc) 21.761 kb
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
$CMS_ADMIN_PAGE=1;
$LOAD_ALL_MODULES=1;
 
require_once("../include.php");
 
check_login();
 
$module = "";
if (isset($_GET["module"])) $module = $_GET["module"];
 
$plugin = "";
if (isset($_GET["plugin"])) $plugin = $_GET["plugin"];
 
$action = "";
if (isset($_GET["action"])) $action = $_GET["action"];
 
$allowoverwritemodules = 0;
if (isset($_POST["allowoverwrite"])) $allowoverwritemodules = $_POST["allowoverwrite"];
 
$autoinstallupgrade = 0; // keep this here for a bit, just incase
 
$userid = get_userid();
$access = check_permission($userid, "Modify Modules");
 
$smarty = new Smarty_CMS($gCms->config);
 
include_once("header.php");
 
if ($access)
  {
    if ($action == "chmod" )
      {
  $result = chmod_r( $config['root_path'].DIRECTORY_SEPARATOR.
       'modules'.DIRECTORY_SEPARATOR.$module, 0777 );
  if( !$result )
   {
   echo '<div class="pagecontainer">';
   echo '<p class="pageheader">'.lang('moduleerrormessage', array($module)).'</p>';          
   echo lang('cantchmodfiles');
   echo "</div>";
   echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';
   include_once("footer.php");
   }
  else
   {
   redirect("listmodules.php");
   }
      }
 
    if ($action == "exportxml")
      {
  // get our xml
  $message = '';
  $files = 0;
  $object = $gCms->modules[$module]['object'];
  $xmltxt = $object->CreateXMLPackage($message,$files);
  if( $files == 0 )
   {
   echo "<p class=\"error\">".lang('errornofilesexported')."</p>";
   }
  else
   {
   $xmlname = $object->GetName().'-'.$object->GetVersion().'.xml';
 
   // and send the file
   while(@ob_end_clean());
   header('Content-Description: File Transfer');
   header('Content-Type: application/force-download');
   header('Content-Disposition: attachment; filename='.$xmlname);
   // header('Content-Type: text/xml');
   echo $xmltxt;
   exit();
   }
      }
 
    if ($action == "importxml" )
      {
  $fieldName = "browse_xml";
  if (!isset ($_FILES[$fieldName]) || !isset ($_FILES)
   || !is_array ($_FILES[$fieldName]) || !$_FILES[$fieldName]['name'])
   {
   echo $themeObject->ShowErrors(lang('noxmlfileuploaded'));
   }
  else
   {
   // normalize the file variable
   $file = $_FILES[$fieldName];
 
   // $file['tmp_name'] is the file we have to parse
   $xml = file_get_contents( $file['tmp_name'] );
 
   // and parse it
   $result = ModuleOperations::ExpandXMLPackage( $xml, $allowoverwritemodules );
   // at this point, all of the files in that module may have become unusable
   // in the current version of cms.
   if( !$result )
   {
    echo $themeObject->ShowErrors(ModuleOperations::GetLastError());
   }
   else if( $autoinstallupgrade == 0 )
   {
    // no auto install or upgrade
    redirect("listmodules.php");
   }
   // note, wishy, when you dig in here next, everything below here
   // can probably go.
   /*
   else if( !isset( $gCms->modules[$result['name']] ) )
   {
   // looks like we're installing this module
   redirect("listmodules.php?action=install&module=".$result['name']);
   }
   else
   {
   // allow the auto upgrade stuff to do it's thing
   // need new version and old version
   $oldversion = $gCms->modules[$result['name']]['object']->GetVersion();
   $newversion = $result['version'];
   redirect("listmodules.php?action=upgrade&module=".$result['name']."&oldversion=".$oldversion."&newversion=".$newversion);
   }
   */
   }
      }
 
    if ($action == "install")
      {
  $result = ModuleOperations::InstallModule($module,false);
  if( $result[0] == false )
   {
   echo '<div class="pagecontainer">';
   echo '<p class="pageheader">'.lang('moduleerrormessage', $module).'</p>';          
   echo $result[1];
   echo "</div>";
   echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';
   include_once("footer.php");
   exit;
   }
  else
   {
   $content = $gCms->modules[$module]['object']->InstallPostMessage();
   if( $content != FALSE )
   {
    //Redirect right away so that the installed module shows in the menu
    redirect('listmodules.php?action=showpostinstall&module='.$module);
   }
   // all is good, but no postinstall message
   redirect("listmodules.php");
   }
      }
 
    if ($action == 'showpostinstall')
      {
  // this is probably dead code now
  if (isset($gCms->modules[$module]))
   {
   $modinstance = $gCms->modules[$module]['object'];
   if ($modinstance->InstallPostMessage() != FALSE)
   {
    @ob_start();
    echo $modinstance->InstallPostMessage();
    $content = @ob_get_contents();
    @ob_end_clean();
    echo '<div class="pagecontainer">';
    echo '<p class="pageheader">'.lang('moduleinstallmessage', array($module)).'</p>';          
    echo $content;
    echo "</div>";
    echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';          
    include_once("footer.php");
    exit;
   }
   }
      }
 
    if ($action == 'remove')
      {
  $result = recursive_delete( $config['root_path'].DIRECTORY_SEPARATOR.
         'modules'.DIRECTORY_SEPARATOR.$module );
  if( !$result )
   {
   echo '<div class="pagecontainer">';
   echo '<p class="pageheader">'.lang('moduleerrormessage', array($module)).'</p>';          
   echo lang('cantremovefiles');
   echo "</div>";
   echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';
   include_once("footer.php");
   }
  else
   {
   redirect("listmodules.php");
   }
      }
 
    if ($action == 'upgrade')
      {
  $result = ModuleOperations::UpgradeModule( $module, $_GET['oldversion'], $_GET['newversion'] );  
  if( !$result )
   {
   @ob_start();
   echo ModuleOperations::GetLastError();
   $content = @ob_get_contents();
   @ob_end_clean();
   echo $themeObject->ShowErrors(lang('moduleupgradeerror'));
   echo '<div class="pagecontainer">';
   echo '<p class="pageheader">'.lang('moduleerrormessage', array($module)).'</p>';          
   echo $content;
   echo "</div>";
   echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';
   include_once("footer.php");
   exit;
   }
  redirect("listmodules.php");
      }
 
 
    if ($action == "uninstall")
      {
  if (isset($gCms->modules[$module]))
   {
   $modinstance = $gCms->modules[$module]['object'];
   $result = $modinstance->Uninstall();
 
            #now insert a record
   if (!isset($result) || $result === FALSE)
   {
                #now delete the record
    $query = "DELETE FROM ".cms_db_prefix()."modules WHERE module_name = ?";
    $db->Execute($query, array($module));
 
                #delete any dependencies
    $query = "DELETE FROM ".cms_db_prefix()."module_deps WHERE child_module = ?";
    $db->Execute($query, array($module));
 
    Events::SendEvent('Core', 'ModuleUninstalled', array('name' => $module));
 
                #and show the uninstallpost if necessary...
    if ($modinstance->UninstallPostMessage() != FALSE)
     {
     //Redirect right away so that the uninstalled module is removed from the menu
     redirect('listmodules.php?action=showpostuninstall&module='.$module);
     }
   }
   else
   {
    //TODO: Echo error
   }
   }
 
  redirect("listmodules.php");
      }
  
    if ($action == 'showpostuninstall')
      {
  // this is probably dead code now
  if (isset($gCms->modules[$module]))
   {
   $modinstance = $gCms->modules[$module]['object'];
   if ($modinstance->UninstallPostMessage() != FALSE)
   {
    @ob_start();
    echo $modinstance->UninstallPostMessage();
    $content = @ob_get_contents();
    @ob_end_clean();
    echo '<div class="pagecontainer">';
    echo '<p class="pageheader">'.lang('moduleuninstallmessage', array($module)).'</p>';          
    echo $content;
    echo "</div>";
    echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';          
    include_once("footer.php");
    exit;
   }
   }
      }
 
    if ($action == "settrue")
      {
  $query = "UPDATE ".cms_db_prefix()."modules SET active = ? WHERE module_name = ?";
  $db->Execute($query, array(1,$module));
  redirect("listmodules.php");
      }
 
    if ($action == "setfalse")
      {
  $query = "UPDATE ".cms_db_prefix()."modules SET active = ? WHERE module_name = ?";
  $db->Execute($query, array(0,$module));
  redirect("listmodules.php");
      }
  }
 
include_once("header.php");
 
if ($action == "showmoduleabout")
  {
    if (isset($gCms->modules[$module]['object']))
      {
  echo '<div class="pagecontainer">';
  echo '<p class="pageheader">'.lang('moduleabout', array($module)).'</p>';
  echo $gCms->modules[$module]['object']->GetAbout();
  echo "</div>";
      }
    echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';
  }
 else if ($action == "showmodulehelp")
   {
     if (isset($gCms->modules[$module]['object']))
       {
   echo '<div class="pagecontainer">';
   echo $themeObject->ShowHeader(lang('modulehelp', array($module)), '', lang('wikihelp', $module), 'wiki');
   echo $gCms->modules[$module]['object']->GetHelpPage();
   echo "</div>";
       }
     echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';
   }
 else if ($action == 'missingdeps')
   {
     echo '<div class="pagecontainer">';
     echo '<p class="pageheader">'.lang('depsformodule', array($module)).'</p>';
     echo '<table cellspacing="0" class="AdminTable">';
     echo '<thead>';
     echo '<tr><th>'.lang('name').'</th><th>'.lang('minimumversion').'</th><th>'.lang('installed').'</th></tr>';
     echo '</thead>';
     echo '<tbody>';
 
     if (isset($gCms->modules[$module]))
       {
   $modinstance = $gCms->modules[$module]['object'];
   if (count($modinstance->GetDependencies()) > 0) #Check for any deps
   {
   $curclass = 'row1';
#Now check to see if we can satisfy any deps
   debug_buffer($modinstance->GetDependencies(), 'deps in module');
   foreach ($modinstance->GetDependencies() as $onedepkey=>$onedepvalue)
   {
     echo '<tr class="'.$curclass.'"><td>'.$onedepkey.'</td><td>'.$onedepvalue.'</td><td>';
 
     $havedep = false;
 
     if (isset($gCms->modules[$onedepkey]) &&
     $gCms->modules[$onedepkey]['installed'] == true &&
     $gCms->modules[$onedepkey]['active'] == true &&
     version_compare($gCms->modules[$onedepkey]['object']->GetVersion(), $onedepvalue) > -1)
     {
     $havedep = true;
     }
 
     echo lang(($havedep?'true':'false'));
     echo '</td></tr>';
     ($curclass=="row1"?$curclass="row2":$curclass="row1");
   }
   }
       }
 
     echo '</tbody>';
     echo '</table>';
     echo '</div>';
     echo '<p class="pageback"><a class="pageback" href="listmodules.php">&#171; '.lang('back').'</a></p>';
   }
 else
   {
 
     if ($action != "" && !$access) {
       echo "<p class=\"error\">".lang('needpermissionto', array('Modify Modules'))."</p>";
     }
 
     if (count($gCms->modules) > 0) {
       
       $query = "SELECT * from ".cms_db_prefix()."modules";
       $result = $db->Execute($query);
       while ($result && $row = $result->FetchRow()) {
   $dbm[$row['module_name']]['Status'] = $row['status'];
   $dbm[$row['module_name']]['Version'] = $row['version'];
   $dbm[$row['module_name']]['Active'] = ($row['active'] == 1?true:false);
       }
 
       ?>
 
   <div class="pagecontainer">
   <div class="pageoverflow">
<?php
  
       if (isset($_SESSION['modules_messages']) && count($_SESSION['modules_messages']) > 0)
   {
   echo '<ul class="messages">';
  
   // do we need to worry about this for XSS?
   foreach ($_SESSION['modules_messages'] as $onemessage)
   {
   echo "<li>" . $onemessage . "</li>";
   }
   echo "</ul>";
   unset($_SESSION['modules_messages']);
   }
       
       ?>
 
<?php echo $themeObject->ShowHeader('modules').'</div>'; ?>
   <table cellspacing="0" class="pagetable">
   <thead>
   <tr>
   <th><?php echo lang('name')?></th>
   <th><?php echo lang('version')?></th>
   <th><?php echo lang('status')?></th>
   <th class="pagepos"><?php echo lang('active')?></th>
   <th><?php echo lang('action')?></th>
   <th><?php echo lang('help')?></th>
   <th><?php echo lang('about')?></th>
   <th><?php echo lang('export')?></th>
   </tr>
   </thead>
   <tbody>
<?php
  
       $curclass = "row1";
       // construct true/false button images
       $image_true = $themeObject->DisplayImage('icons/system/true.gif', lang('true'),'','','systemicon');
       $image_false = $themeObject->DisplayImage('icons/system/false.gif', lang('false'),'','','systemicon');
 
       foreach($gCms->modules as $key=>$value)
   {
   $modinstance = $value['object'];
   $is_sysmodule = (array_search( $key, $gCms->cmssystemmodules ) !== FALSE);
   $namecol = $key;
   $versioncol = "&nbsp;";
   $statuscol = "&nbsp;";
   $statusspans = false;
   $actioncol = "&nbsp;";
   $activecol = "&nbsp;";
   $helpcol = "&nbsp;";
   $aboutcol = "&nbsp;";
 
   $xmlcol = "&nbsp;";
//    if( !$is_sysmodule )
//    {
   $xmlcol = '<a href="listmodules.php?action=exportxml&amp;module='.$key.'"><img border="0" src="../images/cms/xml_rss.gif" alt="'.lang('xml').'" /></a>';
//    }
 
   //Is there help?
   if ($modinstance->GetHelp() != '')
   {
   $namecol = "<a href=\"listmodules.php?action=showmodulehelp&amp;module=".$key."\">".$key."</a>";
   }
 
   // check these modules permissions to see if we can uninstall this thing
   $permsok = is_directory_writable( $config['root_path'].DIRECTORY_SEPARATOR.
           'modules'.DIRECTORY_SEPARATOR.$key );
 
           #Make sure it's a valid module for this version of CMSMS
   if (version_compare($modinstance->MinimumCMSVersion(), $CMS_VERSION) == 1)
   {
   // Fix undefined index error if module is not already installed.
   if (FALSE == empty($dbm[$key]['Version'])) {
     echo "<td>".$dbm[$key]['Version']."</td>";
   }
               $statuscol = '<span class="important">'.lang('minimumversionrequired').': '.$modinstance->MinimumCMSVersion().'</span>';
   $xmlcol = "&nbsp;";
   $statusspans = true;
   }
   else if (version_compare($modinstance->MaximumCMSVersion(), $CMS_VERSION) == -1)
   {
   // Fix undefined index error if module is not already installed.
   if (FALSE == empty($dbm[$key]['Version'])) {
     echo "<td>".$dbm[$key]['Version']."</td>";
   }
   $statuspans = true;
   $xmlcol = "&nbsp;";
   $statuscol = lang('maximumversionsupported').': '.$modinstance->MaximumCMSVersion();
   }
   else if (!isset($dbm[$key])) #Not installed, lets put up the install button
   {
   $brokendeps = 0;
 
   $dependencies = $modinstance->GetDependencies();
 
   if (count($dependencies) > 0) #Check for any deps
     {
                   #Now check to see if we can satisfy any deps
     foreach ($dependencies as $onedepkey=>$onedepvalue)
     {
     if (!isset($gCms->modules[$onedepkey]) ||
    &nb