plugins/SpecialAdmin.php
changeset 326 ab66d6d1f1f4
parent 304 e2cb5f1432c8
parent 322 5f1cd51bf1be
child 328 dc838fd61a06
equal deleted inserted replaced
314:474f8be55943 326:ab66d6d1f1f4
     2 /*
     2 /*
     3 Plugin Name: Runt - the Enano administration panel
     3 Plugin Name: Runt - the Enano administration panel
     4 Plugin URI: http://enanocms.org/
     4 Plugin URI: http://enanocms.org/
     5 Description: Provides the page Special:Administration, which is the AJAX frontend to the various Admin pagelets. This plugin cannot be disabled.
     5 Description: Provides the page Special:Administration, which is the AJAX frontend to the various Admin pagelets. This plugin cannot be disabled.
     6 Author: Dan Fuhry
     6 Author: Dan Fuhry
     7 Version: 1.0.2
     7 Version: 1.0.3
     8 Author URI: http://enanocms.org/
     8 Author URI: http://enanocms.org/
     9 */
     9 */
    10 
    10 
    11 /*
    11 /*
    12  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    12  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
   528   
   528   
   529   if(isset($_POST['save']))
   529   if(isset($_POST['save']))
   530   {
   530   {
   531     if(isset($_POST['enable_uploads']) && getConfig('enable_uploads') != '1')
   531     if(isset($_POST['enable_uploads']) && getConfig('enable_uploads') != '1')
   532     {
   532     {
   533       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES("security","upload_enable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '");');
   533       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES(\'security\',\'upload_enable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\');');
   534       if ( !$q )
   534       if ( !$q )
   535         $db->_die();
   535         $db->_die();
   536       setConfig('enable_uploads', '1');
   536       setConfig('enable_uploads', '1');
   537     }
   537     }
   538     else if ( !isset($_POST['enable_uploads']) && getConfig('enable_uploads') == '1' )
   538     else if ( !isset($_POST['enable_uploads']) && getConfig('enable_uploads') == '1' )
   539     {
   539     {
   540       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES("security","upload_disable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '");');
   540       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES(\'security\',\'upload_disable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\');');
   541       if ( !$q )
   541       if ( !$q )
   542         $db->_die();
   542         $db->_die();
   543       setConfig('enable_uploads', '0');
   543       setConfig('enable_uploads', '0');
   544     }
   544     }
   545     if(isset($_POST['enable_imagemagick']) && getConfig('enable_imagemagick') != '1')
   545     if(isset($_POST['enable_imagemagick']) && getConfig('enable_imagemagick') != '1')
   546     {
   546     {
   547       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES("security","magick_enable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '");');
   547       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES(\'security\',\'magick_enable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\');');
   548       if ( !$q )
   548       if ( !$q )
   549         $db->_die();
   549         $db->_die();
   550       setConfig('enable_imagemagick', '1');
   550       setConfig('enable_imagemagick', '1');
   551     }
   551     }
   552     else if ( !isset($_POST['enable_imagemagick']) && getConfig('enable_imagemagick') == '1' )
   552     else if ( !isset($_POST['enable_imagemagick']) && getConfig('enable_imagemagick') == '1' )
   553     {
   553     {
   554       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES("security","magick_disable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '");');
   554       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES(\'security\',\'magick_disable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\');');
   555       if ( !$q )
   555       if ( !$q )
   556         $db->_die();
   556         $db->_die();
   557       setConfig('enable_imagemagick', '0');
   557       setConfig('enable_imagemagick', '0');
   558     }
   558     }
   559     if(isset($_POST['cache_thumbs']))
   559     if(isset($_POST['cache_thumbs']))
   564     {
   564     {
   565       setConfig('cache_thumbs', '0');
   565       setConfig('cache_thumbs', '0');
   566     }
   566     }
   567     if(isset($_POST['file_history']) && getConfig('file_history') != '1' )
   567     if(isset($_POST['file_history']) && getConfig('file_history') != '1' )
   568     {
   568     {
   569       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES("security","filehist_enable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '");');
   569       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES(\'security\',\'filehist_enable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\');');
   570       if ( !$q )
   570       if ( !$q )
   571         $db->_die();
   571         $db->_die();
   572       setConfig('file_history', '1');
   572       setConfig('file_history', '1');
   573     }
   573     }
   574     else if ( !isset($_POST['file_history']) && getConfig('file_history') == '1' )
   574     else if ( !isset($_POST['file_history']) && getConfig('file_history') == '1' )
   575     {
   575     {
   576       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES("security","filehist_disable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '");');
   576       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES(\'security\',\'filehist_disable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\');');
   577       if ( !$q )
   577       if ( !$q )
   578         $db->_die();
   578         $db->_die();
   579       setConfig('file_history', '0');
   579       setConfig('file_history', '0');
   580     }
   580     }
   581     if(file_exists($_POST['imagemagick_path']) && $_POST['imagemagick_path'] != getConfig('imagemagick_path'))
   581     if(file_exists($_POST['imagemagick_path']) && $_POST['imagemagick_path'] != getConfig('imagemagick_path'))
   582     {
   582     {
   583       $old = getConfig('imagemagick_path');
   583       $old = getConfig('imagemagick_path');
   584       $oldnew = "{$old}||{$_POST['imagemagick_path']}";
   584       $oldnew = "{$old}||{$_POST['imagemagick_path']}";
   585       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","magick_path",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($oldnew) . '");');
   585       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES(\'security\',\'magick_path\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\',\'' . $db->escape($oldnew) . '\');');
   586       if ( !$q )
   586       if ( !$q )
   587         $db->_die();
   587         $db->_die();
   588       setConfig('imagemagick_path', $_POST['imagemagick_path']);
   588       setConfig('imagemagick_path', $_POST['imagemagick_path']);
   589     }
   589     }
   590     else if ( $_POST['imagemagick_path'] != getConfig('imagemagick_path') )
   590     else if ( $_POST['imagemagick_path'] != getConfig('imagemagick_path') )
   649   if(isset($_GET['action']))
   649   if(isset($_GET['action']))
   650   {
   650   {
   651     switch($_GET['action'])
   651     switch($_GET['action'])
   652     {
   652     {
   653       case "enable":
   653       case "enable":
   654         $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","plugin_enable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_GET['plugin']) . '");');
   654         $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES(\'security\',\'plugin_enable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',"' . $db->escape($session->username) . '","' . $db->escape($_GET['plugin']) . '");');
   655         if ( !$q )
   655         if ( !$q )
   656           $db->_die();
   656           $db->_die();
   657         setConfig('plugin_'.$_GET['plugin'], '1');
   657         setConfig('plugin_'.$_GET['plugin'], '1');
   658         break;
   658         break;
   659       case "disable":
   659       case "disable":
   662           echo('<h3>Error disabling plugin</h3><p>The demo lockdown plugin cannot be disabled in demo mode.</p>');
   662           echo('<h3>Error disabling plugin</h3><p>The demo lockdown plugin cannot be disabled in demo mode.</p>');
   663           break;
   663           break;
   664         }
   664         }
   665         if ( !in_array($_GET['plugin'], $plugins->system_plugins) )
   665         if ( !in_array($_GET['plugin'], $plugins->system_plugins) )
   666         {
   666         {
   667           $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","plugin_disable",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_GET['plugin']) . '");');
   667           $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES(\'security\',\'plugin_disable\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',"' . $db->escape($session->username) . '","' . $db->escape($_GET['plugin']) . '");');
   668           if ( !$q )
   668           if ( !$q )
   669             $db->_die();
   669             $db->_die();
   670           setConfig('plugin_'.$_GET['plugin'], '0');
   670           setConfig('plugin_'.$_GET['plugin'], '0');
   671         }
   671         }
   672         else 
   672         else 
   903   {/if}
   903   {/if}
   904 {/slider}</pre>
   904 {/slider}</pre>
   905   <?php
   905   <?php
   906 }
   906 }
   907 
   907 
   908 /*
       
   909 function page_Admin_UserManager() {
       
   910   global $db, $session, $paths, $template, $plugins; // Common objects
       
   911   global $lang;
       
   912   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
       
   913   {
       
   914     $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
       
   915     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
       
   916     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
       
   917     return;
       
   918   }
       
   919   
       
   920   if ( isset($_GET['src']) && $_GET['src'] == 'get' && !empty($_GET['user']) )
       
   921   {
       
   922     $_POST['go'] = true;
       
   923     $_POST['username'] = $_GET['user'];
       
   924   }
       
   925   
       
   926   if(isset($_POST['go']))
       
   927   {
       
   928     // We need the user ID before we can do anything
       
   929     $q = $db->sql_query('SELECT user_id,username,email,real_name,style,user_level,account_active FROM '.table_prefix.'users WHERE username=\'' . $db->escape($_POST['username']) . '\'');
       
   930     if ( !$q )
       
   931     {
       
   932       die('Error selecting user ID: '.mysql_error());
       
   933     }
       
   934     if ( $db->numrows() < 1 )
       
   935     {
       
   936       echo('User does not exist, please enter another username.');
       
   937       return;
       
   938     }
       
   939     $r = $db->fetchrow();
       
   940     $db->free_result();
       
   941     if(isset($_POST['save']))
       
   942     {
       
   943       $_POST['level'] = intval($_POST['level']);
       
   944       
       
   945       $new_level = $_POST['level'];
       
   946       $old_level = intval($r['user_level']);
       
   947       
       
   948       if ( defined('ENANO_DEMO_MODE') )
       
   949       {
       
   950         echo '<div class="error-box">You cannot delete or modify user accounts in demo mode - they are cleaned up once every two hours.</div>';
       
   951         $re = Array('permission denied');
       
   952       }
       
   953       else
       
   954       {
       
   955         $re = $session->update_user((int)$r['user_id'], $_POST['new_username'], false, $_POST['new_pass'], $_POST['email'], $_POST['real_name'], false, $_POST['level']);
       
   956       }
       
   957       
       
   958       if($re == 'success')
       
   959       {
       
   960         
       
   961         if ( $new_level != $old_level )
       
   962         {
       
   963           $user_id = intval($r['user_id']);
       
   964           // We need to update group memberships
       
   965           if ( $old_level == USER_LEVEL_ADMIN ) 
       
   966           {
       
   967             $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_from_admin",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");');
       
   968             if ( !$q )
       
   969               $db->_die();
       
   970             $session->remove_user_from_group($user_id, GROUP_ID_ADMIN);
       
   971           }
       
   972           else if ( $old_level == USER_LEVEL_MOD ) 
       
   973           {
       
   974             $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_from_mod",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");');
       
   975             if ( !$q )
       
   976               $db->_die();
       
   977             $session->remove_user_from_group($user_id, GROUP_ID_MOD);
       
   978           }
       
   979           
       
   980           if ( $new_level == USER_LEVEL_ADMIN )
       
   981           {
       
   982             $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_to_admin",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");');
       
   983             if ( !$q )
       
   984               $db->_die();
       
   985             $session->add_user_to_group($user_id, GROUP_ID_ADMIN, false);
       
   986           }
       
   987           else if ( $new_level == USER_LEVEL_MOD )
       
   988           {
       
   989             $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_to_mod",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");');
       
   990             if ( !$q )
       
   991               $db->_die();
       
   992             $session->add_user_to_group($user_id, GROUP_ID_MOD, false);
       
   993           }
       
   994         }
       
   995         
       
   996         // update account activation
       
   997         if ( isset($_POST['account_active']) )
       
   998         {
       
   999           // activate account
       
  1000           $q = $db->sql_query('UPDATE '.table_prefix.'users SET account_active=1 WHERE user_id=' . intval($r['user_id']) . ';');
       
  1001           if ( !$q )
       
  1002             $db->_die();
       
  1003         }
       
  1004         else
       
  1005         {
       
  1006           // deactivate account and throw away the old key
       
  1007           $actkey = sha1 ( microtime() . mt_rand() );
       
  1008           $q = $db->sql_query('UPDATE '.table_prefix.'users SET account_active=0,activation_key=\'' . $actkey . '\' WHERE user_id=' . intval($r['user_id']) . ';');
       
  1009           if ( !$q )
       
  1010             $db->_die();
       
  1011         }
       
  1012         
       
  1013         echo('<div class="info-box">Your changes have been saved.</div>');
       
  1014       }
       
  1015       else
       
  1016       {
       
  1017         echo('<div class="error-box">Error saving changes: '.implode('<br />', $re).'</div>');
       
  1018       }
       
  1019       $q = $db->sql_query('SELECT user_id,username,email,real_name,style,user_level,account_active FROM '.table_prefix.'users WHERE username=\''.$db->escape($_POST['username']).'\'');
       
  1020       if ( !$q )
       
  1021       {
       
  1022         die('Error selecting user ID: '.mysql_error());
       
  1023       }
       
  1024       if($db->numrows($q) < 1)
       
  1025       {
       
  1026         die('User does not exist, please enter another username.');
       
  1027       }
       
  1028       $r = mysql_fetch_object($q);
       
  1029       $db->free_result();
       
  1030     }
       
  1031     elseif(isset($_POST['deleteme']) && isset($_POST['delete_conf']))
       
  1032     {
       
  1033       if ( defined('ENANO_DEMO_MODE') )
       
  1034       {
       
  1035         echo '<div class="error-box">You cannot delete or modify user accounts in demo mode - they are cleaned up once every two hours.</div>';
       
  1036       }
       
  1037       else
       
  1038       {
       
  1039         $q = $db->sql_query('DELETE FROM users WHERE user_id='.$r['user_id'].';');
       
  1040         if($q)
       
  1041         {
       
  1042           echo '<div class="error-box">The user account "'.$r['username'].'" was deleted.</div>';
       
  1043         }
       
  1044         else
       
  1045         {
       
  1046           echo '<div class="error-box">The user account "'.$r['username'].'" could not be deleted due to a database error.<br /><br />'.$db->get_error().'</div>';
       
  1047         }
       
  1048       }
       
  1049     }
       
  1050     else
       
  1051     {
       
  1052       $disabled = ( $r['user_id'] == $session->user_id ) ? ' disabled="disabled" ' : '';
       
  1053       $evt_get_score = ( getConfig('pw_strength_enable') == '1' ) ? 'onkeyup="password_score_field(this);" style="margin-right: 7px;" ' : '';
       
  1054       $meter         = ( getConfig('pw_strength_enable') == '1' ) ? '<tr><td></td><td><div id="pwmeter"></div><p><small>Password complexity requirements are not enforced here.</small></p></td></tr>' : '';
       
  1055       echo('
       
  1056       <h3>Edit User Info</h3>
       
  1057       <form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">
       
  1058         <table border="0" style="margin-left: 0.2in;">   
       
  1059           <tr><td>Username:</td><td><input type="text" name="new_username" value="'.$r['username'].'" /></td></tr>
       
  1060           <tr><td>New Password:</td><td><input ' . $disabled . ' type="password" name="new_pass" '.$evt_get_score.'/></td></tr>
       
  1061           '.$meter.'
       
  1062           <tr><td>E-mail:</td><td><input ' . $disabled . ' type="text" name="email" value="'.$r['email'].'" /></td></tr>
       
  1063           <tr><td>Real Name:</td><td><input ' . $disabled . ' type="text" name="real_name" value="'.$r['real_name'].'" /></td></tr>
       
  1064           ' . ( ( !empty($disabled) ) ? '<tr><td colspan="2"><small>To change your e-mail address, password, or real name, please use the user control panel.</small></td></tr>' : '' ) . '
       
  1065           <tr><td>User level:</td><td><select name="level"><option '); if($r['user_level']==USER_LEVEL_CHPREF) echo('SELECTED'); echo(' value="'.USER_LEVEL_CHPREF.'">Regular User</option><option '); if($r['user_level']==USER_LEVEL_MOD) echo('SELECTED'); echo(' value="'.USER_LEVEL_MOD.'">Moderator</option><option '); if($r['user_level']==USER_LEVEL_ADMIN) echo('SELECTED'); echo(' value="'.USER_LEVEL_ADMIN.'">Administrator</option></select></td></tr>
       
  1066           <tr><td></td><td><label><input type="checkbox" name="account_active"' . ( $r['account_active'] == '1' ? ' checked="checked"' : '' ) . ' /> Account is active</label><br /><small>If this is unchecked, the activation key will be reset, meaning that any activation e-mails sent will be invalidated.</small></td></tr>
       
  1067           <tr><td>Delete user:</td><td><input type="hidden" name="go" /><input type="hidden" name="username" value="'.$r['username'].'" /><input onclick="return confirm(\'This is your last warning.\n\nAre you sure you want to delete this user account? Even if you delete this user account, the username will be shown in page edit history, comments, and other areas of the site.\n\nDeleting a user account CANNOT BE UNDONE and should only be done in extreme circumstances.\n\nIf the user has violated the site policy, deleting the account will not prevent him from using the site, for that you need to add a new ban rule.\n\nContinue deleting this user account?\')" type="submit" name="deleteme" value="Delete this user" style="color: red;" /> <label><input type="checkbox" name="delete_conf" /> I\'m absolutely sure</label>
       
  1068           <tr><td align="center" colspan="2">
       
  1069           <input type="submit" name="save" value="Save Changes" /></td></tr>
       
  1070         </table>
       
  1071       </form>
       
  1072       ');
       
  1073     }
       
  1074   }
       
  1075   else if(isset($_POST['clearsessions'])) 
       
  1076   {
       
  1077     if ( defined('ENANO_DEMO_MODE') )
       
  1078     {
       
  1079       echo '<div class="error-box">Sorry Charlie, no can do. You might mess up other people logged into the demo site.</div>';
       
  1080     }
       
  1081     else
       
  1082     {
       
  1083       // Get the current session information so the user doesn't get logged out
       
  1084       $aes = new AESCrypt();
       
  1085       $sk = md5(strrev($session->sid_super));
       
  1086       $qb = $db->sql_query('SELECT session_key,salt,auth_level,source_ip,time FROM '.table_prefix.'session_keys WHERE session_key=\''.$sk.'\' AND user_id='.$session->user_id.' AND auth_level='.USER_LEVEL_ADMIN);
       
  1087       if ( !$qb )
       
  1088       {
       
  1089         die('Error selecting session key info block B: '.$db->get_error());
       
  1090       }
       
  1091       if ( $db->numrows($qb) < 1 )
       
  1092       {
       
  1093         die('Error: cannot read admin session info block B, aborting table clear process');
       
  1094       }
       
  1095       $qa = $db->sql_query('SELECT session_key,salt,auth_level,source_ip,time FROM '.table_prefix.'session_keys WHERE session_key=\''.md5($session->sid).'\' AND user_id='.$session->user_id.' AND auth_level='.USER_LEVEL_MEMBER);
       
  1096       if ( !$qa )
       
  1097       {
       
  1098         die('Error selecting session key info block A: '.$db->get_error());
       
  1099       }
       
  1100       if ( $db->numrows($qa) < 1 )
       
  1101       {
       
  1102         die('Error: cannot read user session info block A, aborting table clear process');
       
  1103       }
       
  1104       $ra = mysql_fetch_object($qa);
       
  1105       $rb = mysql_fetch_object($qb);
       
  1106       $db->free_result($qa);
       
  1107       $db->free_result($qb);
       
  1108       
       
  1109       $db->sql_query('DELETE FROM '.table_prefix.'session_keys;');
       
  1110       $db->sql_query('INSERT INTO '.table_prefix.'session_keys( session_key,salt,user_id,auth_level,source_ip,time ) VALUES( \''.$ra->session_key.'\', \''.$ra->salt.'\', \''.$session->user_id.'\', \''.$ra->auth_level.'\', \''.$ra->source_ip.'\', '.$ra->time.' ),( \''.$rb->session_key.'\', \''.$rb->salt.'\', \''.$session->user_id.'\', \''.$rb->auth_level.'\', \''.$rb->source_ip.'\', '.$rb->time.' )');
       
  1111       
       
  1112       echo('
       
  1113         <div class="info-box">The session key table has been cleared. Your database should be a little bit smaller now.</div>
       
  1114       ');
       
  1115     }
       
  1116   }   
       
  1117   echo('
       
  1118   <h3>User Management</h3>
       
  1119   <form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;">
       
  1120     <p>Username: '.$template->username_field('username').' <input type="submit" name="go" value="Go" /></p>
       
  1121     <h3>Clear session keys table</h3>
       
  1122      <p>It\'s a good idea to clean out your session keys table every once in a while, since this helps to reduce database size. During this process you will be logged off and (hopefully) logged back on automatically. The side effects of this include all users except you being logged off.</p>
       
  1123      <p><input type="submit" name="clearsessions" value="Clear session keys table" /></p>
       
  1124   </form>
       
  1125   ');
       
  1126   if(isset($_GET['action']) && isset($_GET['user']))
       
  1127   {
       
  1128     switch($_GET['action'])
       
  1129     {
       
  1130       case "activate":
       
  1131         $e = $db->sql_query('SELECT activation_key FROM '.table_prefix.'users WHERE username=\'' . $db->escape($_GET['user']) . '\'');
       
  1132         if($e)
       
  1133         {
       
  1134           $row = $db->fetchrow();
       
  1135           $db->free_result();
       
  1136           if($session->activate_account($_GET['user'], $row['activation_key'])) { echo '<div class="info-box">The user account "'.$_GET['user'].'" has been activated.</div>'; $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE time_id=' . $db->escape($_GET['logid'])); }
       
  1137           else echo '<div class="warning-box">The user account "'.$_GET['user'].'" has NOT been activated, possibly because the account is already active.</div>';
       
  1138         } else echo '<div class="error-box">Error activating account: '.mysql_error().'</div>';
       
  1139         break;
       
  1140       case "sendemail":
       
  1141         if($session->send_activation_mail($_GET['user'])) { echo '<div class="info-box">The user "'.$_GET['user'].'" has been sent an e-mail with an activation link.</div>'; $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE time_id=' . $db->escape($_GET['logid'])); }
       
  1142         else echo '<div class="error-box">The user account "'.$_GET['user'].'" has not been activated, probably because of a bad SMTP configuration.</div>';
       
  1143         break;
       
  1144       case "deny":
       
  1145         $e = $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE log_type=\'admin\' AND action=\'activ_req\' AND edit_summary=\'' . $db->escape($_GET['user']) . '\';');
       
  1146         if(!$e) echo '<div class="error-box">Error during row deletion: '.mysql_error().'</div>';
       
  1147         else echo '<div class="info-box">All activation requests for the user "'.$_GET['user'].'" have been deleted.</div>';
       
  1148         break;
       
  1149     }
       
  1150   }
       
  1151   $q = $db->sql_query('SELECT l.log_type, l.action, l.time_id, l.date_string, l.author, l.edit_summary, u.user_coppa FROM '.table_prefix.'logs AS l
       
  1152                          LEFT JOIN '.table_prefix.'users AS u
       
  1153                            ON ( u.username = l.edit_summary OR u.username IS NULL )
       
  1154                          WHERE log_type=\'admin\' AND action=\'activ_req\' ORDER BY time_id DESC;');
       
  1155   if($q)
       
  1156   {
       
  1157     if($db->numrows() > 0)
       
  1158     {
       
  1159       $n = $db->numrows();
       
  1160       if($n == 1) $s = $n . ' user is';
       
  1161       else $s = $n . ' users are';
       
  1162       echo '<h3>'.$s . ' awaiting account activation</h3>';
       
  1163       echo '<div class="tblholder">
       
  1164             <table border="0" cellspacing="1" cellpadding="4" width="100%">
       
  1165             <tr><th>Date of request</th><th>Requested by</th><th>Requested for</th><th>COPPA user</th><th colspan="3">Actions</th></tr>';
       
  1166       $cls = 'row2';
       
  1167       while($row = $db->fetchrow())
       
  1168       {
       
  1169         if($cls == 'row2') $cls = 'row1';
       
  1170         else $cls = 'row2';
       
  1171         $coppa = ( $row['user_coppa'] == '1' ) ? '<b>Yes</b>' : 'No';
       
  1172         echo '<tr><td class="'.$cls.'">'.date('F d, Y h:i a', $row['time_id']).'</td><td class="'.$cls.'">'.$row['author'].'</td><td class="'.$cls.'">'.$row['edit_summary'].'</td><td style="text-align: center;" class="' . $cls . '">' . $coppa . '</td><td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'UserManager&amp;action=activate&amp;user='.$row['edit_summary'].'&amp;logid='.$row['time_id']).'">Activate now</a></td><td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'UserManager&amp;action=sendemail&amp;user='.$row['edit_summary'].'&amp;logid='.$row['time_id']).'">Send activation e-mail</a></td><td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'UserManager&amp;action=deny&amp;user='.$row['edit_summary'].'&amp;logid='.$row['time_id']).'">Deny request</a></td></tr>';
       
  1173       }
       
  1174       echo '</table>';
       
  1175     }
       
  1176     $db->free_result();
       
  1177   }
       
  1178 }
       
  1179 */
       
  1180 
       
  1181 function page_Admin_GroupManager()
   908 function page_Admin_GroupManager()
  1182 {
   909 {
  1183   global $db, $session, $paths, $template, $plugins; // Common objects
   910   global $db, $session, $paths, $template, $plugins; // Common objects
  1184   global $lang;
   911   global $lang;
  1185   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
   912   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
  1874     {
  1601     {
  1875       $data = $content;
  1602       $data = $content;
  1876       $id = md5( microtime() . mt_rand() );
  1603       $id = md5( microtime() . mt_rand() );
  1877       
  1604       
  1878       $minor = isset($_POST['minor']) ? 'true' : 'false';
  1605       $minor = isset($_POST['minor']) ? 'true' : 'false';
  1879       $q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \'' . $db->escape($_POST['page_id']) . '\', \'' . $db->escape($_POST['namespace']) . '\', \''.$data.'\', \''.$id.'\', \''.$session->username.'\', \''.$db->escape(htmlspecialchars($_POST['summary'])).'\', '.$minor.');';
  1606       $q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \'' . $db->escape($_POST['page_id']) . '\', \'' . $db->escape($_POST['namespace']) . '\', \''.$db->escape($data).'\', \''.$id.'\', \''.$session->username.'\', \''.$db->escape(htmlspecialchars($_POST['summary'])).'\', '.$minor.');';
  1880       if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
  1607       if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
  1881       
  1608       
  1882       $query = 'UPDATE '.table_prefix.'page_text SET page_text=\''.$db->escape($data).'\',char_tag=\''.$id.'\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'' . $db->escape($_POST['namespace']) . '\';';
  1609       $query = 'UPDATE '.table_prefix.'page_text SET page_text=\''.$db->escape($data).'\',char_tag=\''.$id.'\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'' . $db->escape($_POST['namespace']) . '\';';
  1883       $e = $db->sql_query($query);
  1610       $e = $db->sql_query($query);
  1884       if(!$e) echo '<div class="warning-box">The page data could not be saved. MySQL said: '.mysql_error().'<br /><br />Query:<br /><pre>'.$query.'</pre></div>';
  1611       if(!$e) echo '<div class="warning-box">The page data could not be saved. MySQL said: '.mysql_error().'<br /><br />Query:<br /><pre>'.$query.'</pre></div>';
  1887       echo '<h3>Preview</h3><p><b>Reminder:</b> This is only a preview; your changes to this page have not yet been saved.</p><div style="margin: 1em; padding: 10px; border: 1px dashed #606060; background-color: #F8F8F8; max-height: 200px; overflow: auto;">'.RenderMan::render($content).'</div>';
  1614       echo '<h3>Preview</h3><p><b>Reminder:</b> This is only a preview; your changes to this page have not yet been saved.</p><div style="margin: 1em; padding: 10px; border: 1px dashed #606060; background-color: #F8F8F8; max-height: 200px; overflow: auto;">'.RenderMan::render($content).'</div>';
  1888     }
  1615     }
  1889     ?>
  1616     ?>
  1890     <p>
  1617     <p>
  1891     <textarea name="content" rows="20" cols="60" style="width: 100%;"><?php echo htmlspecialchars($content); ?></textarea><br />
  1618     <textarea name="content" rows="20" cols="60" style="width: 100%;"><?php echo htmlspecialchars($content); ?></textarea><br />
  1892     Edit summary: <input name="summary" value="<?php if(isset($_POST['summary'])) echo $_POST['summary']; ?>" size="40" /><br />
  1619     Edit summary: <input name="summary" value="<?php if(isset($_POST['summary'])) echo htmlspecialchars($_POST['summary']); ?>" size="40" /><br />
  1893     <label><input type="checkbox" name="minor" <?php if(isset($_POST['minor'])) echo 'checked="checked" '; ?>/>  This is a minor edit</label>
  1620     <label><input type="checkbox" name="minor" <?php if(isset($_POST['minor'])) echo 'checked="checked" '; ?>/>  This is a minor edit</label>
  1894     </p>
  1621     </p>
  1895     <p>
  1622     <p>
  1896     <input type="hidden" name="page_id" value="<?php echo $_POST['page_id']; ?>" />
  1623     <input type="hidden" name="page_id" value="<?php echo htmlspecialchars($_POST['page_id']); ?>" />
  1897     <input type="hidden" name="namespace" value="<?php echo $_POST['namespace']; ?>" />
  1624     <input type="hidden" name="namespace" value="<?php echo htmlspecialchars($_POST['namespace']); ?>" />
  1898     <input type="submit" name="save" value="Save changes" style="font-weight: bold;" />&nbsp;&nbsp;<input type="submit" name="preview" value="Show preview" />&nbsp;&nbsp;<input type="submit" name="revert" value="Revert changes" onclick="return confirm('Do you really want to revert your changes?');" />&nbsp;&nbsp;<input type="submit" name="cancel" value="Cancel" onclick="return confirm('Do you really want to cancel your changes?');" />
  1625     <input type="submit" name="save" value="Save changes" style="font-weight: bold;" />&nbsp;&nbsp;<input type="submit" name="preview" value="Show preview" />&nbsp;&nbsp;<input type="submit" name="revert" value="Revert changes" onclick="return confirm('Do you really want to revert your changes?');" />&nbsp;&nbsp;<input type="submit" name="cancel" value="Cancel" onclick="return confirm('Do you really want to cancel your changes?');" />
  1899     </p>
  1626     </p>
  1900     <?php
  1627     <?php
  1901     echo '</form>';
  1628     echo '</form>';
  1902   } else {
  1629   } else {
  2525     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
  2252     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
  2526     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
  2253     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
  2527     return;
  2254     return;
  2528   }
  2255   }
  2529   
  2256   
       
  2257   if ( ENANO_DBLAYER != 'MYSQL' )
       
  2258     die('<h3>Not supported</h3>
       
  2259           <p>This function is only supported under the MySQL database driver.</p>');
       
  2260   
  2530   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes' && defined('ENANO_DEMO_MODE') )
  2261   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes' && defined('ENANO_DEMO_MODE') )
  2531   {
  2262   {
  2532     redirect(makeUrlComplete('Special', 'Administration'), 'Access denied', 'You\'ve got to be kidding me. Forget it, kid.', 4 );
  2263     redirect(makeUrlComplete('Special', 'Administration'), 'Access denied', 'You\'ve got to be kidding me. Forget it, kid.', 4 );
  2533   }
  2264   }
  2534   
  2265   
  2536   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes')
  2267   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes')
  2537   {
  2268   {
  2538     
  2269     
  2539     if(defined('SQL_BACKUP_CRYPT'))
  2270     if(defined('SQL_BACKUP_CRYPT'))
  2540       // Try to increase our time limit
  2271       // Try to increase our time limit
  2541       @set_time_limit(300); // five minutes
  2272       @set_time_limit(0);
  2542     // Do the actual export
  2273     // Do the actual export
  2543     $aesext = ( defined('SQL_BACKUP_CRYPT') ) ? '.tea' : '';
  2274     $aesext = ( defined('SQL_BACKUP_CRYPT') ) ? '.tea' : '';
  2544     $filename = 'enano_backup_' . date('ymd') . '.sql' . $aesext;
  2275     $filename = 'enano_backup_' . date('ymd') . '.sql' . $aesext;
  2545     ob_start();
  2276     ob_start();
  2546     header('Content-disposition: attachment, filename="'.$filename.'";');
       
  2547     header('Content-type: application/transact-sql');
       
  2548     // Spew some headers
  2277     // Spew some headers
  2549     $headdate = date('F d, Y \a\t h:i a');
  2278     $headdate = date('F d, Y \a\t h:i a');
  2550     echo <<<HEADER
  2279     echo <<<HEADER
  2551 -- Enano CMS SQL backup
  2280 -- Enano CMS SQL backup
  2552 -- Generated on {$headdate} by {$session->username}
  2281 -- Generated on {$headdate} by {$session->username}
  2572     foreach($tables as $t)
  2301     foreach($tables as $t)
  2573     {
  2302     {
  2574       // THE FOLLOWING COMMENT DOES NOT APPLY AS OF 1.0.
  2303       // THE FOLLOWING COMMENT DOES NOT APPLY AS OF 1.0.
  2575       // Sorry folks - this script CAN'T backup enano_files and enano_search_index due to the sheer size of the tables.
  2304       // Sorry folks - this script CAN'T backup enano_files and enano_search_index due to the sheer size of the tables.
  2576       // If encryption is enabled the log data will be excluded too.
  2305       // If encryption is enabled the log data will be excluded too.
  2577       echo export_table(
  2306       $result = export_table(
  2578         $t,
  2307         $t,
  2579         isset($_POST['do_struct']),
  2308         isset($_POST['do_struct']),
  2580         ( isset($_POST['do_data']) ),
  2309         ( isset($_POST['do_data']) ),
  2581         false
  2310         false
  2582         ) . "\n";
  2311         ) . "\n";
       
  2312       if ( !$result )
       
  2313       {
       
  2314         $db->_die();
       
  2315       }
       
  2316       echo $result;
  2583     }
  2317     }
  2584     $data = ob_get_contents();
  2318     $data = ob_get_contents();
  2585     ob_end_clean();
  2319     ob_end_clean();
  2586     if(defined('SQL_BACKUP_CRYPT'))
  2320     if(defined('SQL_BACKUP_CRYPT'))
  2587     {
  2321     {
  2589       $db->close();
  2323       $db->close();
  2590       unset($paths, $db, $template, $plugins);
  2324       unset($paths, $db, $template, $plugins);
  2591       $tea = new TEACrypt();
  2325       $tea = new TEACrypt();
  2592       $data = $tea->encrypt($data, $session->private_key);
  2326       $data = $tea->encrypt($data, $session->private_key);
  2593     }
  2327     }
       
  2328     header('Content-disposition: attachment, filename="'.$filename.'";');
       
  2329     header('Content-type: application/transact-sql');
  2594     header('Content-length: '.strlen($data));
  2330     header('Content-length: '.strlen($data));
  2595     echo $data;
  2331     echo $data;
  2596     exit;
  2332     exit;
  2597   }
  2333   }
  2598   else
  2334   else
  2603     <p>This page allows you to back up your Enano database should something go miserably wrong.</p>
  2339     <p>This page allows you to back up your Enano database should something go miserably wrong.</p>
  2604     <p><label><input type="checkbox" name="do_system_tables" checked="checked" />  Export tables that are part of the Enano core</label><p>
  2340     <p><label><input type="checkbox" name="do_system_tables" checked="checked" />  Export tables that are part of the Enano core</label><p>
  2605     <p>Additional tables to export:</p>
  2341     <p>Additional tables to export:</p>
  2606     <p><select name="additional_tables[]" multiple="multiple">
  2342     <p><select name="additional_tables[]" multiple="multiple">
  2607        <?php
  2343        <?php
  2608          $q = $db->sql_query('SHOW TABLES;') or $db->_die('Somehow we were denied the request to get the list of tables.');
  2344          if ( ENANO_DBLAYER == 'MYSQL' )
       
  2345          {
       
  2346            $q = $db->sql_query('SHOW TABLES;') or $db->_die('Somehow we were denied the request to get the list of tables.');
       
  2347          }
       
  2348          else if ( ENANO_DBLAYER == 'PGSQL' )
       
  2349          {
       
  2350            $q = $db->sql_query('SELECT relname FROM pg_stat_user_tables ORDER BY relname;') or $db->_die('Somehow we were denied the request to get the list of tables.');
       
  2351          }
  2609          while($row = $db->fetchrow_num())
  2352          while($row = $db->fetchrow_num())
  2610          {
  2353          {
  2611            if(!in_array($row[0], $system_table_list)) echo '<option value="'.$row[0].'">'.$row[0].'</option>';
  2354            if(!in_array($row[0], $system_table_list)) echo '<option value="'.$row[0].'">'.$row[0].'</option>';
  2612          }
  2355          }
  2613        ?>
  2356        ?>