Guest User

Untitled

a guest
May 23rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.36 KB | None | 0 0
  1. <?php
  2. /**
  3. * Forum Passwords
  4. * Moderator control panel plugin: Forum password tool
  5. * Last Updated: October 23rd, 2011
  6. *
  7. * @author Tomato
  8. * @copyright Tomato (c) 2011
  9. * @version 1.1.0 (10100)
  10. *
  11. */
  12.  
  13. if ( ! defined( 'IN_IPB' ) )
  14. {
  15. print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
  16. exit();
  17. }
  18.  
  19. class plugin_forumpass_forumpassword
  20. {
  21. /**
  22. * Registry Object Shortcuts
  23. *
  24. * @var $registry
  25. * @var $DB
  26. * @var $settings
  27. * @var $request
  28. * @var $lang
  29. * @var $member
  30. * @var $memberData
  31. * @var $cache
  32. * @var $caches
  33. */
  34. protected $registry;
  35. protected $DB;
  36. protected $settings;
  37. protected $request;
  38. protected $lang;
  39. protected $member;
  40. protected $memberData;
  41. protected $cache;
  42. protected $caches;
  43.  
  44. /**
  45. * Main function executed automatically by the controller
  46. *
  47. * @param object $registry Registry object
  48. * @return @e void
  49. */
  50. public function __construct( ipsRegistry $registry )
  51. {
  52. //-----------------------------------------
  53. // Make shortcuts
  54. //-----------------------------------------
  55.  
  56. $this->registry = $registry;
  57. $this->DB = $this->registry->DB();
  58. $this->settings =& $this->registry->fetchSettings();
  59. $this->request =& $this->registry->fetchRequest();
  60. $this->member = $this->registry->member();
  61. $this->memberData =& $this->registry->member()->fetchMemberData();
  62. $this->cache = $this->registry->cache();
  63. $this->caches =& $this->registry->cache()->fetchCaches();
  64. $this->lang = $this->registry->class_localization;
  65.  
  66. $this->registry->getClass('class_localization')->loadLanguageFile( array( 'public_modcp'), 'forumpass' );
  67. }
  68.  
  69. /**
  70. * Returns the primary tab key for the navigation bar
  71. *
  72. * @return @e string
  73. */
  74. public function getPrimaryTab()
  75. {
  76. return 'forumpassword';
  77. }
  78.  
  79. /**
  80. * Returns the secondary tab key for the navigation bar
  81. *
  82. * @return @e string
  83. */
  84. public function getSecondaryTab()
  85. {
  86. return 'forumpassword';
  87. }
  88.  
  89. /**
  90. * Determine if we can view tab
  91. *
  92. * @param array $permissions Moderator permissions
  93. * @return @e bool
  94. */
  95. public function canView()
  96. {
  97. if( $this->memberData['mgroup_others'] )
  98. {
  99. $mgroup_others_query = ' OR group_id IN ( '. IPSText::cleanPermString( $this->memberData['mgroup_others'] ) .' )';
  100. }
  101.  
  102. /* Check Permissions */
  103. $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'can_view_pass = 1 AND member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query, 'limit' => array(0,1) ) );
  104. $this->DB->execute();
  105. if ( $mod = $this->DB->fetch() )
  106. {
  107. return true;
  108. }
  109.  
  110. return false;
  111. }
  112.  
  113. /**
  114. * Execute plugin
  115. *
  116. * @param array $permissions Moderator permissions
  117. * @return @e string
  118. */
  119. public function executePlugin( $permissions )
  120. {
  121. //-----------------------------------------
  122. // Check permissions
  123. //-----------------------------------------
  124.  
  125. if( !$this->canView( $permissions ) )
  126. {
  127. return '';
  128. }
  129.  
  130. //-----------------------------------------
  131. // Doing something else?
  132. //-----------------------------------------
  133.  
  134. switch( $this->request['_do'] )
  135. {
  136. case 'edit':
  137. return $this->_edit();
  138. break;
  139.  
  140. case 'save':
  141. return $this->_save();
  142. break;
  143. }
  144.  
  145. $perpage = 15;
  146. $st = ( $this->request['st'] > 0 ) ? intval( $this->request['st'] ) : 0;
  147. $can_view = 0;
  148. $can_edit = 0;
  149. $mods_edit_string = '';
  150. $mods_view_string = '';
  151.  
  152. if( $this->memberData['mgroup_others'] )
  153. {
  154. $mgroup_others_query = ' OR group_id IN ( '. IPSText::cleanPermString( $this->memberData['mgroup_others'] ) .' )';
  155. }
  156.  
  157. $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query ) );
  158. $this->DB->execute();
  159. while ( $mod = $this->DB->fetch() )
  160. {
  161. if( $mod['can_edit_pass'] AND $mod['can_view_pass'] )
  162. {
  163. $can_edit = 1;
  164. $mod['forum_id'] = substr( $mod['forum_id'], 1 );
  165. $mods_edit_string .= $mod['forum_id'];
  166. }
  167.  
  168. if( $mod['can_view_pass'] )
  169. {
  170. $can_view = 1;
  171. $mod['forum_id'] = substr( $mod['forum_id'], 1 );
  172. $mods_view_string .= $mod['forum_id'];
  173. }
  174. }
  175.  
  176. $mods_edit_array = explode( ',', $mods_edit_string );
  177. $mods_view_array = explode( ',', $mods_view_string );
  178. $mods_array = array_merge( IPSLib::cleanIntArray($mods_edit_array), IPSLib::cleanIntArray($mods_view_array) );
  179. $mods_array = array_unique( $mods_array );
  180.  
  181. $forums_view_string = implode( ',', IPSLib::cleanIntArray($mods_array) );
  182. $forums_view_string = ( $forums_view_string != '' ) ? $forums_view_string : 0;
  183.  
  184. $total = $this->DB->buildAndFetch( array( 'select' => 'count(*) as count', 'from' => 'forums', 'where' => 'password != "" AND id IN ( '.$forums_view_string.' )' ) );
  185.  
  186. /* Build a list of the forums with passwords */
  187. $this->DB->build( array( 'select' => 'f.*,m.members_seo_name,m.member_id,m.members_display_name,m.member_group_id',
  188. 'from' => array( 'forums' => 'f'),
  189. 'where' => 'password != "" AND id IN ( '.$forums_view_string.' )',
  190. 'add_join' => array(
  191. 0 => array ( 'from' => array( 'members' => 'm' ),
  192. 'where' => 'f.last_password_change_mid=m.member_id' ) ),
  193. 'order' => 'f.name ASC',
  194. 'limit' => array( $st, $perpage ) ) );
  195. $this->DB->execute();
  196. while ( $forum = $this->DB->fetch() )
  197. {
  198. if ( $forum['member_id'] > 0 )
  199. {
  200. $forum['members_display_name'] = IPSMember::makeNameFormatted( $forum['members_display_name'], $forum['member_group_id'] );
  201. $forum['member_formatted'] = IPSMember::makeProfileLink( $forum['members_display_name'], $forum['member_id'], $forum['members_seo_name'] );
  202. }
  203.  
  204. $forum['last_password_change'] = $this->registry->getClass( 'class_localization')->getDate( $forum['last_password_change'], $format='LONG', $relative='true' );
  205. if ( in_array( $forum['id'], $mods_edit_array ) )
  206. {
  207. $forum['edit'] = 1;
  208. }
  209. $forums[] = $forum;
  210. }
  211.  
  212. /* Generate our pages */
  213. $pages = $this->registry->output->generatePagination( array( 'totalItems' => $total['count'],
  214. 'itemsPerPage' => $perpage,
  215. 'currentStartValue' => $st,
  216. 'baseUrl' => "app=core&module=modcp&fromapp=forumpass&tab=forumpass",
  217. ) );
  218.  
  219. return $this->registry->getClass('output')->getTemplate('forumpass')->modForumPass($forums,$pages);
  220. }
  221.  
  222. /**
  223. * Edit password screen
  224. *
  225. * @return string HTML
  226. */
  227. protected function _edit()
  228. {
  229. $fid = ( $this->request['fid'] > 0 ) ? intval( $this->request['fid'] ) : 0;
  230. $fromforum = intval( $this->request['fromf'] ) ? 1 : 0;
  231.  
  232. /* Check ID */
  233. if( ! $fid )
  234. {
  235. $this->registry->getClass('output')->showError( $this->lang->words['forumpass_nofid'] );
  236. }
  237.  
  238. /* Check Permissions */
  239. $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'can_edit_pass = 1 AND can_view_pass = 1 AND forum_id LIKE "%,'.$fid.',%" AND member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query ) );
  240. $this->DB->execute();
  241. if ( ! $mod = $this->DB->fetch() )
  242. {
  243. $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noedit'] );
  244. }
  245.  
  246. /* Load Forum */
  247. $forum = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'forums', 'where' => 'id=' . $fid ) );
  248.  
  249. if( ! $forum['id'] )
  250. {
  251. $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noforum'] );
  252. }
  253.  
  254. if ( $forum['last_password_change_mid'] > 0 )
  255. {
  256. $last_editor = IPSMember::load( $forum['last_password_change_mid'] );
  257.  
  258. $forum['members_display_name'] = IPSMember::makeNameFormatted( $last_editor['members_display_name'], $last_editor['member_group_id'] );
  259. $forum['member_formatted'] = IPSMember::makeProfileLink( $forum['members_display_name'], $last_editor['member_id'], $last_editor['members_seo_name'] );
  260. }
  261.  
  262. $forum['last_password_change'] = $this->registry->getClass( 'class_localization')->getDate( $forum['last_password_change'], $format='LONG', $relative='true' );
  263.  
  264. $forum['redir'] = $fromforum;
  265.  
  266. return $this->registry->getClass('output')->getTemplate('forumpass')->modForumPassForm( $forum );
  267. }
  268.  
  269. /**
  270. * Save our password
  271. *
  272. * @return void Outputs to screen
  273. */
  274. protected function _save()
  275. {
  276. $fid = ( $this->request['fid'] > 0 ) ? intval( $this->request['fid'] ) : 0;
  277. $password = $this->request['pass'];
  278. $time = time();
  279. $redir = intval( $this->request['redir'] ) ? 1 : 0;
  280.  
  281. /* Check ID */
  282. if( ! $fid )
  283. {
  284. $this->registry->getClass('output')->showError( $this->lang->words['forumpass_nofid'] );
  285. }
  286.  
  287. /* Check Permissions */
  288. $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'can_edit_pass = 1 AND can_view_pass = 1 AND forum_id LIKE "%,'.$fid.',%" AND member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query ) );
  289. $this->DB->execute();
  290. if ( ! $mod = $this->DB->fetch() )
  291. {
  292. $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noedit'] );
  293. }
  294.  
  295. /* Load Forum */
  296. $forum = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'forums', 'where' => 'id=' . $fid ) );
  297.  
  298. if( ! $forum['id'] )
  299. {
  300. $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noforum'] );
  301. }
  302.  
  303. if( trim( $password ) == '' || ! $password )
  304. {
  305. $this->registry->getClass('output')->showError( $this->lang->words['forumpass_nopass'] );
  306. }
  307.  
  308. $password = substr( $password, 0, 32 );
  309.  
  310. /* Update our forum */
  311. $this->DB->update( 'forums', array( 'password' => $password, 'last_password_change' => $time, 'last_password_change_mid' => $this->memberData['member_id'] ), 'id='.$fid );
  312.  
  313. $password = IPSText::parseCleanValue( $password );
  314.  
  315. $this->DB->insert( 'moderator_logs', array(
  316. 'forum_id' => intval( $fid ),
  317. 'member_id' => $this->memberData['member_id'],
  318. 'member_name' => $this->memberData['members_display_name'],
  319. 'ip_address' => $this->member->ip_address,
  320. 'http_referer' => htmlspecialchars( getenv('HTTP_REFERER') ),
  321. 'ctime' => time(),
  322. 'action' => sprintf( $this->lang->words['forumpass_changepass'], $forum['name'], $password),
  323. 'query_string' => htmlspecialchars( getenv('QUERY_STRING') ),
  324. ) );
  325.  
  326. //$this->registry->output->silentRedirect( $this->settings['base_url']."app=core&module=modcp&fromapp=forumpass&tab=forumpassword&edited=1" );
  327.  
  328. if ( $redir )
  329. {
  330. $this->registry->output->redirectScreen( $this->lang->words['forumpass_passchanged'], $this->settings['base_url']."showforum={$fid}", $forum['name_seo'], 'showforum' );
  331. }
  332. else
  333. {
  334. $this->registry->output->redirectScreen( $this->lang->words['forumpass_passchanged'], $this->settings['base_url']."app=core&module=modcp&fromapp=forumpass&tab=forumpassword" );
  335. }
  336. }
  337. }
  338.  
  339. ?>
Add Comment
Please, Sign In to add comment