PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/site/tmp/install_4a925da139185/admin/plugins/phpbb3/admin.php

https://bitbucket.org/manchas/jrobotz
PHP | 535 lines | 409 code | 73 blank | 53 comment | 60 complexity | 570f487929570c2a98dc14c2601e9d0d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion_phpBB3
  4. * @author JFusion development team
  5. * @copyright Copyright (C) 2008 JFusion. All rights reserved.
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. */
  8. // no direct access
  9. defined('_JEXEC' ) or die('Restricted access' );
  10. /**
  11. * JFusion Admin Class for phpBB3
  12. * For detailed descriptions on these functions please check the model.abstractadmin.php
  13. * @package JFusion_phpBB3
  14. */
  15. class JFusionAdmin_phpbb3 extends JFusionAdmin{
  16. function getJname()
  17. {
  18. return 'phpbb3';
  19. }
  20. function getTablename()
  21. {
  22. return 'users';
  23. }
  24. function setupFromPath($forumPath)
  25. {
  26. //check for trailing slash and generate file path
  27. if (substr($forumPath, -1) == DS) {
  28. $myfile = $forumPath . 'config.php';
  29. } else {
  30. $myfile = $forumPath . DS. 'config.php';
  31. }
  32. if (($file_handle = @fopen($myfile, 'r')) === FALSE) {
  33. JError::raiseWarning(500,JText::_('WIZARD_FAILURE'). ": $myfile " . JText::_('WIZARD_MANUAL'));
  34. $result = false;
  35. return $result;
  36. } else {
  37. //parse the file line by line to get only the config variables
  38. $file_handle = fopen($myfile, 'r');
  39. while (!feof($file_handle)) {
  40. $line = fgets($file_handle);
  41. if (strpos($line, '$') === 0) {
  42. //extract the name and value, it was coded to avoid the use of eval() function
  43. $vars = split("'", $line);
  44. $name = trim($vars[0], ' $=');
  45. $value = trim($vars[1], ' $=');
  46. $config[$name] = $value;
  47. }
  48. }
  49. fclose($file_handle);
  50. //save the parameters into array
  51. $params = array();
  52. $params['database_host'] = $config['dbhost'];
  53. $params['database_name'] = $config['dbname'];
  54. $params['database_user'] = $config['dbuser'];
  55. $params['database_password'] = $config['dbpasswd'];
  56. $params['database_prefix'] = $config['table_prefix'];
  57. $params['database_type'] = $config['dbms'];
  58. //create a connection to the database
  59. $options = array('driver' => $config['dbms'], 'host' => $config['dbhost'], 'user' => $config['dbuser'], 'password' => $config['dbpasswd'], 'database' => $config['dbname'], 'prefix' => $config['table_prefix'] );
  60. //Get configuration settings stored in the database
  61. $vdb =& JDatabase::getInstance($options);
  62. $query = "SELECT config_name, config_value FROM #__config WHERE config_name IN ('script_path', 'cookie_path', 'server_name', 'cookie_domain', 'cookie_name', 'allow_autologin');";
  63. if (JError::isError($vdb) || !$vdb ) {
  64. JError::raiseWarning(0, JText::_('NO_DATABASE'));
  65. $result = false;
  66. return $result;
  67. } else {
  68. $vdb->setQuery($query);
  69. $rows = $vdb->loadObjectList();
  70. foreach($rows as $row ) {
  71. $config[$row->config_name] = $row->config_value;
  72. }
  73. //store the new found parameters
  74. $params['cookie_path'] = $config['cookie_path'];
  75. $params['cookie_domain'] = $config['cookie_domain'];
  76. $params['cookie_prefix'] = $config['cookie_name'];
  77. $params['allow_autologin'] = $config['allow_autologin'];
  78. $params['source_path'] = $forumPath;
  79. }
  80. //check for trailing slash
  81. if (substr($config['server_name'], -1) == '/' && substr($config['script_path'], 0, 1) == '/') {
  82. //too many slashes, we need to remove one
  83. $params['source_url'] = $config['server_name'] . substr($config['script_path'],1);
  84. } else if (substr($config['server_name'], -1) == '/' || substr($config['script_path'], 0, 1) == '/') {
  85. //the correct number of slashes
  86. $params['source_url'] = $config['server_name'] . $config['script_path'];
  87. } else {
  88. //no slashes found, we need to add one
  89. $params['source_url'] = $config['server_name'] . '/' . $config['script_path'] ;
  90. }
  91. //return the parameters so it can be saved permanently
  92. return $params;
  93. }
  94. }
  95. function getUserList()
  96. {
  97. //getting the connection to the db
  98. $db = JFusionFactory::getDatabase($this->getJname());
  99. $query = 'SELECT username_clean as username, user_email as email, user_id as userid from #__users WHERE user_email NOT LIKE \'\' and user_email IS NOT NULL';
  100. $db->setQuery($query );
  101. //getting the results
  102. $userlist = $db->loadObjectList();
  103. return $userlist;
  104. }
  105. function getUserCount()
  106. {
  107. //getting the connection to the db
  108. $db = JFusionFactory::getDatabase($this->getJname());
  109. $query = 'SELECT count(*) from #__users WHERE user_email NOT LIKE \'\' and user_email IS NOT NULL ';
  110. $db->setQuery($query );
  111. //getting the results
  112. $no_users = $db->loadResult();
  113. return $no_users;
  114. }
  115. function getUsergroupList()
  116. {
  117. //get the connection to the db
  118. $db = JFusionFactory::getDatabase($this->getJname());
  119. $query = 'SELECT group_id as id, group_name as name from #__groups;';
  120. $db->setQuery($query );
  121. //getting the results
  122. return $db->loadObjectList();
  123. }
  124. function getDefaultUsergroup()
  125. {
  126. $params = JFusionFactory::getParams($this->getJname());
  127. $usergroup_id = $params->get('usergroup');
  128. //we want to output the usergroup name
  129. $db = JFusionFactory::getDatabase($this->getJname());
  130. $query = 'SELECT group_name from #__groups WHERE group_id = ' . $usergroup_id;
  131. $db->setQuery($query );
  132. return $db->loadResult();
  133. }
  134. function allowRegistration()
  135. {
  136. $db = JFusionFactory::getDatabase($this->getJname());
  137. $query = "SELECT config_value FROM #__config WHERE config_name = 'require_activation'";
  138. $db->setQuery($query );
  139. //getting the results
  140. $new_registration = $db->loadResult();
  141. if ($new_registration == 3) {
  142. $result = false;
  143. return $result;
  144. } else {
  145. $result = true;
  146. return $result;
  147. }
  148. }
  149. function generateRedirectCode()
  150. {
  151. $params = JFusionFactory::getParams($this->getJname());
  152. $joomla_params = JFusionFactory::getParams('joomla_int');
  153. $cookie_name = $params->get('cookie_prefix');
  154. $joomla_url = $joomla_params->get('source_url');
  155. $joomla_itemid = $params->get('redirect_itemid');
  156. //check to see if all vars are set
  157. if(empty($joomla_url)){
  158. JError::raiseWarning(0,JText::_('MISSING') . ' Joomla URL');
  159. return '';
  160. }
  161. if(empty($joomla_itemid)){
  162. JError::raiseWarning(0,JText::_('MISSING') . ' ItemID');
  163. return '';
  164. }
  165. //create the new redirection code
  166. $redirect_code = '
  167. //JFUSION REDIRECT START
  168. //SET SOME VARS
  169. if(!empty($_COOKIE[\'' . $cookie_name . '\'])){
  170. $current_userid = $_COOKIE[\'' . $cookie_name . '\'];
  171. } else {
  172. $current_userid = \'\';
  173. }
  174. $joomla_url = \''. $joomla_url . '\';
  175. $joomla_itemid = ' . $joomla_itemid .';
  176. ';
  177. $allow_mods =$params->get('mod_ids');
  178. if (!empty($allow_mods)){
  179. //get a userlist of mod ids
  180. $db = & JFusionFactory::getDatabase($this->getJname());
  181. $query = "SELECT b.user_id, a.group_name FROM #__groups as a INNER JOIN #__user_group as b ON a.group_id = b.group_id WHERE a.group_name = 'GLOBAL_MODERATORS' or a.group_name = 'ADMINISTRATORS'";
  182. $db->setQuery($query);
  183. $mod_list = $db-> loadObjectList();
  184. $mod_array = array();
  185. foreach ($mod_list as $mod_list){
  186. if(!isset($mod_array[$mod_list->user_id])){
  187. $mod_array[$mod_list->user_id] = $mod_list->user_id;
  188. }
  189. }
  190. $mod_ids = implode(",", $mod_array);
  191. $redirect_code .= '
  192. $mod_ids = array(' . $mod_ids . ');
  193. if(!defined(\'_JEXEC\') && !defined(\'ADMIN_START\') && $_GET[\'jfile\'] != \'file.php\' && !in_array($current_userid, $mod_ids))';
  194. } else {
  195. $redirect_code .= '
  196. if(!defined(\'_JEXEC\') && !defined(\'ADMIN_START\') && $_GET[\'jfile\'] != \'file.php\')';
  197. }
  198. $redirect_code .= '
  199. {
  200. $file = $_SERVER[\'SCRIPT_NAME\'];
  201. $break = Explode(\'/\', $file);
  202. $pfile = $break[count($break) - 1];
  203. $jfusion_url = $joomla_url . \'index.php?option=com_jfusion&Itemid=\' . $joomla_itemid . \'&jfile=\'.$pfile. \'&\' . $_SERVER[\'QUERY_STRING\'];
  204. header(\'Location: \' . $jfusion_url);
  205. }
  206. //JFUSION REDIRECT END
  207. ';
  208. return $redirect_code;
  209. }
  210. function enable_redirect_mod()
  211. {
  212. $error = 0;
  213. $error = 0;
  214. $reason = '';
  215. $mod_file = $this->getModFile('common.php',$error,$reason);
  216. if($error == 0) {
  217. //get the joomla path from the file
  218. jimport('joomla.filesystem.file');
  219. $file_data = JFile::read($mod_file);
  220. preg_match_all('/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms',$file_data,$matches);
  221. //remove any old code
  222. if(!empty($matches[1][0])){
  223. $search = '/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms';
  224. $file_data = preg_replace($search,'',$file_data);
  225. }
  226. $redirect_code = $this->generateRedirectCode();
  227. if(empty($redirect_code)){
  228. return;
  229. }
  230. $search = '/\<\?php/si';
  231. $replace = '<?php' . $redirect_code;
  232. $file_data = preg_replace($search,$replace,$file_data);
  233. JFile::write($mod_file, $file_data);
  234. }
  235. }
  236. function disable_redirect_mod()
  237. {
  238. $error = 0;
  239. $reason = '';
  240. $mod_file = $this->getModFile('common.php',$error,$reason);
  241. if($error == 0) {
  242. //get the joomla path from the file
  243. jimport('joomla.filesystem.file');
  244. $file_data = JFile::read($mod_file);
  245. $search = '/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/si';
  246. $file_data = preg_replace($search,'',$file_data);
  247. JFile::write($mod_file, $file_data);
  248. }
  249. }
  250. function outputJavascript(){
  251. ?>
  252. <script language="javascript" type="text/javascript">
  253. <!--
  254. function auth_mod(action) {
  255. var form = document.adminForm;
  256. form.customcommand.value = action;
  257. form.action.value = 'apply';
  258. submitform('saveconfig');
  259. return;
  260. }
  261. //-->
  262. </script>
  263. <?php
  264. }
  265. function show_redirect_mod($name, $value, $node, $control_name)
  266. {
  267. $error = 0;
  268. $reason = '';
  269. $mod_file = $this->getModFile('common.php',$error,$reason);
  270. if($error == 0) {
  271. //get the joomla path from the file
  272. jimport('joomla.filesystem.file');
  273. $file_data = JFile::read($mod_file);
  274. preg_match_all('/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms',$file_data,$matches);
  275. //compare it with our joomla path
  276. if(empty($matches[1][0])){
  277. $error = 1;
  278. $reason = JText::_('MOD_NOT_ENABLED');
  279. }
  280. }
  281. //add the javascript to enable buttons
  282. $this->outputJavascript();
  283. if ($error == 0){
  284. //return success
  285. $output = '<img src="components/com_jfusion/images/check_good.png" height="20px" width="20px">' . JText::_('REDIRECTION_MOD') . ' ' . JText::_('ENABLED');
  286. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'disable_redirect_mod\')">' . JText::_('MOD_DISABLE') . '</a>';
  287. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_redirect_mod\')">' . JText::_('MOD_UPDATE') . '</a>';
  288. return $output;
  289. } else {
  290. $output = '<img src="components/com_jfusion/images/check_bad.png" height="20px" width="20px">' . JText::_('REDIRECTION_MOD') . ' ' . JText::_('DISABLED') .': ' . $reason;
  291. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_redirect_mod\')">' . JText::_('MOD_ENABLE') . '</a>';
  292. return $output;
  293. }
  294. }
  295. function show_auth_mod($name, $value, $node, $control_name)
  296. {
  297. //do a database check to avoid fatal error with incorrect database settings
  298. $db = JFusionFactory::getDatabase($this->getJname());
  299. if (!method_exists($db,'setQuery')) {
  300. return JText::_('NO_DATABASE');
  301. }
  302. $error = 0;
  303. $reason = '';
  304. $mod_file = $this->getModFile('includes' .DS. 'auth' .DS. 'auth_jfusion.php',$error,$reason);
  305. if($error == 0) {
  306. //get the joomla path from the file
  307. jimport('joomla.filesystem.file');
  308. $file_data = JFile::read($mod_file);
  309. preg_match_all('/define\(\'JPATH_BASE\'\,(.*)\)/',$file_data,$matches);
  310. //compare it with our joomla path
  311. if($matches[1][0] != '\''. JPATH_SITE.'\''){
  312. $error = 1;
  313. $reason = JText::_('PATH') . ' ' . JText::_('INVALID');
  314. }
  315. }
  316. if ($error == 0){
  317. //check to see if the mod is enabled
  318. $query = 'SELECT config_value FROM #__config WHERE config_name = \'auth_method\'';
  319. $db->setQuery($query );
  320. $auth_method = $db->loadResult();
  321. if($auth_method != 'jfusion'){
  322. $error = 1;
  323. $reason = JText::_('MOD_NOT_ENABLED');
  324. }
  325. }
  326. //add the javascript to enable buttons
  327. $this->outputJavascript();
  328. if ($error == 0){
  329. //return success
  330. $output = '<img src="components/com_jfusion/images/check_good.png" height="20px" width="20px">' . JText::_('AUTHENTICATION_MOD') . ' ' . JText::_('ENABLED');
  331. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'disable_auth_mod\')">' . JText::_('MOD_DISABLE') . '</a>';
  332. return $output;
  333. } else {
  334. $output = '<img src="components/com_jfusion/images/check_bad.png" height="20px" width="20px">' . JText::_('AUTHENTICATION_MOD') . ' ' . JText::_('DISABLED') .': ' . $reason;
  335. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_auth_mod\')">' . JText::_('MOD_ENABLE') . '</a>';
  336. return $output;
  337. }
  338. }
  339. function enable_auth_mod()
  340. {
  341. $error = 0;
  342. $reason = '';
  343. $auth_file = $this->getModFile('includes' .DS. 'auth' .DS. 'auth_jfusion.php',$error,$reason);
  344. //see if the auth mod file exists
  345. if (!file_exists($auth_file)){
  346. jimport('joomla.filesystem.file');
  347. $copy_file = JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'plugins'.DS.$this->getJname().DS.'auth_jfusion.php';
  348. JFile::copy($copy_file,$auth_file);
  349. }
  350. //get the joomla path from the file
  351. jimport('joomla.filesystem.file');
  352. $file_data = JFile::read($auth_file);
  353. preg_match_all('/define\(\'JPATH_BASE\'\,(.*)\)/',$file_data,$matches);
  354. //compare it with our joomla path
  355. if($matches[1][0] != '\'' . JPATH_SITE . '\''){
  356. $file_data = preg_replace('/define\(\'JPATH_BASE\'\,(.*)\)/', 'define(\'JPATH_BASE\',\''.JPATH_SITE.'\')', $file_data);
  357. $file_data = preg_replace('/\$JFusionActivePlugin \=(.*?)\;/', '$JFusionActivePlugin =\''.$this->getJname() . '\';', $file_data);
  358. JFile::write($auth_file, $file_data);
  359. }
  360. //check to see if the mod is enabled
  361. $db = JFusionFactory::getDatabase($this->getJname());
  362. $query = 'SELECT config_value FROM #__config WHERE config_name = \'auth_method\'';
  363. $db->setQuery($query );
  364. $auth_method = $db->loadResult();
  365. if($auth_method != 'jfusion'){
  366. $query = 'UPDATE #__config SET config_value = \'jfusion\' WHERE config_name = \'auth_method\'';
  367. $db->setQuery($query );
  368. if (!$db->query()) {
  369. //there was an error saving the parameters
  370. JError::raiseWarning(0,$db->stderr());
  371. }
  372. }
  373. }
  374. function disable_auth_mod()
  375. {
  376. //check to see if the mod is enabled
  377. $db = JFusionFactory::getDatabase($this->getJname());
  378. $query = 'UPDATE #__config SET config_value = \'db\' WHERE config_name = \'auth_method\'';
  379. $db->setQuery($query );
  380. if (!$db->query()) {
  381. //there was an error saving the parameters
  382. JError::raiseWarning(0,$db->stderr());
  383. }
  384. //remove the file as well to allow for updates of the auth mod content
  385. $params = JFusionFactory::getParams($this->getJname());
  386. $path = $params->get('source_path');
  387. if (substr($path, -1) == DS) {
  388. $auth_file = $path . 'includes' .DS. 'auth' .DS. 'auth_jfusion.php';
  389. } else {
  390. $auth_file = $path .DS. 'includes' .DS. 'auth' .DS. 'auth_jfusion.php';
  391. }
  392. if (file_exists($auth_file)){
  393. jimport('joomla.filesystem.file');
  394. JFile::delete($auth_file);
  395. }
  396. }
  397. function show_quick_mod($name, $value, $node, $control_name)
  398. {
  399. $error = 0;
  400. $reason = '';
  401. $mod_file = $this->getModFile('mcp.php',$error,$reason);
  402. if($error == 0) {
  403. //get the joomla path from the file
  404. jimport('joomla.filesystem.file');
  405. $file_data = JFile::read($mod_file);
  406. preg_match_all('/global \$action/',$file_data,$matches);
  407. //compare it with our joomla path
  408. if(!isset($matches[0][0])){
  409. $error = 1;
  410. $reason = JText::_('MOD') . ' ' . JText::_('DISABLED');
  411. }
  412. }
  413. //add the javascript to enable buttons
  414. $this->outputJavascript();
  415. if ($error == 0){
  416. //return success
  417. $output = '<img src="components/com_jfusion/images/check_good.png" height="20px" width="20px">' . JText::_('QUICKTOOLS') . ' ' . JText::_('ENABLED');
  418. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'disable_quick_mod\')">' . JText::_('MOD_DISABLE') . '</a>';
  419. return $output;
  420. } else {
  421. $output = '<img src="components/com_jfusion/images/check_bad.png" height="20px" width="20px">' . JText::_('QUICKTOOLS') . ' ' . JText::_('DISABLED') .': ' . $reason;
  422. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_quick_mod\')">' . JText::_('MOD_ENABLE') . '</a>';
  423. return $output;
  424. }
  425. }
  426. function enable_quick_mod()
  427. {
  428. $error = 0;
  429. $reason = '';
  430. $mod_file = $this->getModFile('mcp.php',$error,$reason);
  431. if($error == 0) {
  432. //get the joomla path from the file
  433. jimport('joomla.filesystem.file');
  434. $file_data = JFile::read($mod_file);
  435. $search = '/\$action \= request_var/si';
  436. $replace = 'global $action; $action = request_var';
  437. $file_data = preg_replace($search,$replace,$file_data);
  438. JFile::write($mod_file, $file_data);
  439. }
  440. }
  441. function disable_quick_mod()
  442. {
  443. $error = 0;
  444. $reason = '';
  445. $mod_file = $this->getModFile('mcp.php',$error,$reason);
  446. if($error == 0) {
  447. //get the joomla path from the file
  448. jimport('joomla.filesystem.file');
  449. $file_data = JFile::read($mod_file);
  450. $search = '/global \$action\;/si';
  451. $file_data = preg_replace($search,'',$file_data);
  452. JFile::write($mod_file, $file_data);
  453. }
  454. }
  455. }