PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/e107_admin/admin.php

https://github.com/CasperGemini/e107
PHP | 356 lines | 232 code | 96 blank | 28 comment | 66 complexity | 2973da93cce00b8a85ffd5fc28185950 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2009 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. *
  10. *
  11. * $Source: /cvs_backup/e107_0.8/e107_admin/admin.php,v $
  12. * $Revision$
  13. * $Date$
  14. * $Author$
  15. */
  16. require_once('../class2.php');
  17. include_once(e107::coreTemplatePath('admin_icons')); // Needs to be loaded before infopanel AND in boot.php
  18. if(vartrue($_GET['iframe']) == 1)
  19. {
  20. define('e_IFRAME', true);
  21. }
  22. $e_sub_cat = 'main';
  23. if (varset($pref['adminstyle'])=='cascade' || varset($pref['adminstyle'])=='beginner') // Deprecated Admin-include.
  24. {
  25. $pref['adminstyle'] = 'infopanel';
  26. }
  27. if(strpos($pref['adminstyle'], 'infopanel') === 0)
  28. {
  29. require_once(e_ADMIN.'includes/'.$pref['adminstyle'].'.php');
  30. $_class = 'adminstyle_'.$pref['adminstyle'];
  31. if(class_exists($_class, false))
  32. {
  33. $adp = new $_class;
  34. }
  35. else $adp = new adminstyle_infopanel;
  36. }
  37. require_once(e_ADMIN.'boot.php');
  38. require_once(e_ADMIN.'auth.php');
  39. require_once(e_HANDLER.'upload_handler.php');
  40. new admin_start;
  41. $mes = e107::getMessage();
  42. if (!isset($pref['adminstyle'])) $pref['adminstyle'] = 'infopanel'; // Shouldn't be needed - but just in case
  43. class admin_start
  44. {
  45. private $incompat = array(
  46. 'banhelper' => 1.7,
  47. 'slir_admin' => 1.0,
  48. 'facebook_like' => 0.7,
  49. 'unanswered' => 1.4,
  50. 'lightwindow' => '1.0b',
  51. 'aa_jquery' => 1.2,
  52. 'who' => 1.0,
  53. 'ratings' => 4.2,
  54. 'e107slider' => 0.1
  55. );
  56. private $allowed_types = null;
  57. function __construct()
  58. {
  59. $this->checkWritable();
  60. $this->checkHtmlarea();
  61. $this->checkIncompatiblePlugins();
  62. $this->checkFileTypes();
  63. $this->checkSuspiciousFiles();
  64. }
  65. function checkWritable()
  66. {
  67. $mes = e107::getMessage();
  68. if(deftrue('e_MEDIA') && is_dir(e_MEDIA) && !is_writable(e_MEDIA))
  69. {
  70. $mes->addWarning("The folder ".e_MEDIA." is not writable. Please correct before proceeding.");
  71. }
  72. if(deftrue('e_SYSTEM') && is_dir(e_SYSTEM) && !is_writable(e_SYSTEM))
  73. {
  74. $mes->addWarning("The folder ".e_SYSTEM." is not writable. Please correct before proceeding.");
  75. }
  76. }
  77. function checkHtmlarea()
  78. {
  79. $mes = e107::getMessage();
  80. if (is_dir(e_ADMIN.'htmlarea') || is_dir(e_HANDLER.'htmlarea'))
  81. {
  82. $mes->addWarning($HANDLERS_DIRECTORY."htmlarea/<br />".$ADMIN_DIRECTORY."htmlarea/");
  83. }
  84. }
  85. function checkIncompatiblePlugins()
  86. {
  87. $mes = e107::getMessage();
  88. $installedPlugs = e107::getPref('plug_installed');
  89. $inCompatText = "";
  90. $incompatFolders = array_keys($this->incompat);
  91. foreach($this->incompat as $folder => $version)
  92. {
  93. if(vartrue($installedPlugs[$folder]) && $version == $installedPlugs[$folder])
  94. {
  95. $inCompatText .= "<li>".$folder." v".$installedPlugs[$folder]."</li>";
  96. }
  97. }
  98. if($inCompatText)
  99. {
  100. $text = "<ul>".$inCompatText."</ul>";
  101. $mes->addWarning("The following plugins are not compatible with this version of e107 and should be uninstalled: ".$text."<a class='btn' href='".e_ADMIN."plugin.php'>uninstall</a>");
  102. }
  103. }
  104. function checkFileTypes()
  105. {
  106. $mes = e107::getMessage();
  107. $this->allowed_types = get_filetypes(); // Get allowed types according to filetypes.xml or filetypes.php
  108. if (count($this->allowed_types) == 0)
  109. {
  110. $this->allowed_types = array('zip' => 1, 'gz' => 1, 'jpg' => 1, 'png' => 1, 'gif' => 1);
  111. $mes->addInfo("Setting default filetypes: ".implode(', ',array_keys($this->allowed_types)));
  112. }
  113. }
  114. function checkSuspiciousFiles()
  115. {
  116. $mes = e107::getMessage();
  117. $public = array(e_UPLOAD, e_AVATAR_UPLOAD);
  118. $exceptions = array(".","..","/","CVS","avatars","Thumbs.db",".ftpquota",".htaccess","php.ini",".cvsignore",'e107.htaccess');
  119. //TODO use $file-class to grab list and perform this check.
  120. foreach ($public as $dir)
  121. {
  122. if (is_dir($dir))
  123. {
  124. if ($dh = opendir($dir))
  125. {
  126. while (($file = readdir($dh)) !== false)
  127. {
  128. if (is_dir($dir."/".$file) == FALSE && !in_array($file,$exceptions))
  129. {
  130. $fext = substr(strrchr($file, "."), 1);
  131. if (!array_key_exists(strtolower($fext),$this->allowed_types) )
  132. {
  133. if ($file == 'index.html' || $file == "null.txt")
  134. {
  135. if (filesize($dir.'/'.$file))
  136. {
  137. $potential[] = str_replace('../', '', $dir).'/'.$file;
  138. }
  139. }
  140. else
  141. {
  142. $potential[] = str_replace('../', '', $dir).'/'.$file;
  143. }
  144. }
  145. }
  146. }
  147. closedir($dh);
  148. }
  149. }
  150. }
  151. if (isset($potential))
  152. {
  153. //$text = ADLAN_ERR_3."<br /><br />";
  154. $mes->addWarning(ADLAN_ERR_3);
  155. $text = '<ul>';
  156. foreach ($potential as $p_file)
  157. {
  158. $text .= '<li>'.$p_file.'</li>';
  159. }
  160. $mes->addWarning($text);
  161. //$ns -> tablerender(ADLAN_ERR_1, $text);
  162. }
  163. }
  164. }
  165. // ---------------------------------------------------------
  166. // auto db update
  167. if ('0' == ADMINPERMS)
  168. {
  169. $sc = e107::getScBatch('admin');
  170. echo $tp->parseTemplate('{ADMIN_COREUPDATE=alert}',true, $sc);
  171. require_once(e_ADMIN.'update_routines.php');
  172. update_check();
  173. }
  174. // end auto db update
  175. /*
  176. if (e_QUERY == 'purge' && getperms('0'))
  177. {
  178. $admin_log->purge_log_events(false);
  179. }
  180. */
  181. $td = 1;
  182. // DEPRECATED
  183. function render_links($link, $title, $description, $perms, $icon = FALSE, $mode = FALSE)
  184. {
  185. return e107::getNav()->renderAdminButton($link, $title, $description, $perms, $icon, $mode);
  186. }
  187. function render_clean() // still used by classis, tabbed etc.
  188. {
  189. global $td;
  190. $text = "";
  191. while ($td <= ADLINK_COLS)
  192. {
  193. $text .= "<td class='td' style='width:20%;'></td>";
  194. $td++;
  195. }
  196. $text .= "</tr>";
  197. $td = 1;
  198. return $text;
  199. }
  200. if(is_object($adp))
  201. {
  202. $adp->render();
  203. }
  204. else
  205. {
  206. require_once(e_ADMIN.'includes/'.$pref['adminstyle'].'.php');
  207. }
  208. function admin_info()
  209. {
  210. global $tp;
  211. $width = (getperms('0')) ? "33%" : "50%";
  212. $ADMIN_INFO_TEMPLATE = "
  213. <div style='text-align:center'>
  214. <table style='width: 100%; border-collapse:collapse; border-spacing:0px;'>
  215. <tr>
  216. <td style='width: ".$width."; vertical-align: top'>
  217. {ADMIN_STATUS}
  218. </td>
  219. <td style='width:".$width."; vertical-align: top'>
  220. {ADMIN_LATEST}
  221. </td>";
  222. if(getperms('0'))
  223. {
  224. $ADMIN_INFO_TEMPLATE .= "
  225. <td style='width:".$width."; vertical-align: top'>{ADMIN_LOG}</td>";
  226. }
  227. $ADMIN_INFO_TEMPLATE .= "
  228. </tr></table></div>";
  229. return $tp->parseTemplate($ADMIN_INFO_TEMPLATE);
  230. }
  231. function status_request()
  232. {
  233. global $pref;
  234. if ($pref['adminstyle'] == 'classis' || $pref['adminstyle'] == 'cascade' || $pref['adminstyle'] == 'beginner' || $pref['adminstyle'] == 'tabbed') {
  235. return TRUE;
  236. } else {
  237. return FALSE;
  238. }
  239. }
  240. function latest_request()
  241. {
  242. global $pref;
  243. if ($pref['adminstyle'] == 'classis' || $pref['adminstyle'] == 'cascade' || $pref['adminstyle'] == 'beginner' || $pref['adminstyle'] == 'tabbed') {
  244. return TRUE;
  245. } else {
  246. return FALSE;
  247. }
  248. }
  249. function log_request()
  250. {
  251. global $pref;
  252. if ($pref['adminstyle'] == 'classis' || $pref['adminstyle'] == 'cascade'|| $pref['adminstyle'] == 'beginner' || $pref['adminstyle'] == 'tabbed') {
  253. return TRUE;
  254. } else {
  255. return FALSE;
  256. }
  257. }
  258. // getPlugLinks() - moved to sitelinks_class.php : pluginLinks();
  259. require_once("footer.php");
  260. ?>