51

Re: [Release] User Management Plugin

I would if I could smile

Re: [Release] User Management Plugin

Where can i get version 1.4 who is installed on mypunbb?  I need the function to Syncronise post counts.

Re: [Release] User Management Plugin

the post counts bit is included in the forum cleanup plugin

54 (edited by Maedhros 2006-01-02 23:09)

Re: [Release] User Management Plugin

lament wrote:

connor..

is there a "preview" mode or when I hit "Go" will it automatically delete with my specifications?

i just kinda want to see how many people haven't logged in in x amount of days or have only posted once. but from your verbiage, i think that when i hit "Go" it will delete them without confirmation. true?

User61 wrote:

Wouldn't it be nice if before the actual pruning, a list of users that are going to be pruned will be presented first (along with their stats and stuffs)?

I thought so, too, so I've hacked it a bit, and added a preview mode. There are some cosmetic things that could probably be done better, and I've just borrowed most of the code for showing users from userlist.php, so you might want to add other things to display about the users, but it seems to work. smile

You can find a patch to the plugin here: http://www.cinematicsight.co.uk/misc/AP … ment.patch

55

Re: [Release] User Management Plugin

Just installed this, it looks promising smile thanks

56

Re: [Release] User Management Plugin

Posts deleted together with users?
As possible avoid this?

ERROR - MIRROR

57

Re: [Release] User Management Plugin

Hmmm...
Posts are not deleted with user but they not see.

ERROR - MIRROR

58

Re: [Release] User Management Plugin

Thanks this is simple to install and does exactly what I need :-)

Re: [Release] User Management Plugin

HitMan wrote:

Hmmm...
Posts are not deleted with user but they not see.

what do you mean. "but they not see"?

Re: [Release] User Management Plugin

That they don't show probably.

Re: [Release] User Management Plugin

OK, lets see if I can change this plugin so it acts "nicer" tongue

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

62 (edited by Smartys 2006-10-14 17:10)

Re: [Release] User Management Plugin

If anyone would like, they can test my new version and tell me if they find any bugs (or if it works at all tongue)
Basically, I took PunBB's code for deleting a user and generalized it for multiple users. Hopefully it should all work (but it probably won't) tongue

<?php
/***********************************************************************

  Copyright (C) 2005 Connor Dunn (Connorhd@mypunbb.com)
  Modified by Smartys (smartys@gmail.com)
  
  This software 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 software 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

************************************************************************/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
define('PLUGIN_VERSION', "1.3.1");

if (isset($_POST['prune']))
{
    // Make sure something something was entered
    if ((trim($_POST['days']) == '') || trim($_POST['posts']) == '')
        message('You need to set all settings!');
    if ($_POST['admods_delete']) {
        $admod_delete = 'group_id > 0';
    }
    else {
        $admod_delete = 'group_id > 3';
    }

    if ($_POST['verified'] == 1)
        $verified = '';
    elseif ($_POST['verified'] == 0)
        $verified = 'AND (group_id < 32000)';
    else
        $verified = 'AND (group_id = 32000)';

    $prune = ($_POST['prune_by'] == 1) ? 'registered' : 'last_visit';

    $user_time = time() - ($_POST['days'] * 86400);
    $result = $db->query('SELECT id, group_id, username from '.$db->prefix.'users WHERE id != '.$pun_user['id'].' AND (num_posts < '.intval($_POST['posts']).') AND ('.$prune.' < '.intval($user_time).') AND (id > 1) AND ('.$admod_delete.')'.$verified, true) or error('Unable to select users to delete', __FILE__, __LINE__, $db->error());
    $users_pruned = $db->num_rows($result);
    
    // We want a list of all user IDs and a list of data for any admins/mods
    $users = array();
    $admod_list = array();
    while ($data = $db->fetch_assoc($result))
    {
        $users[] = $data['id'];
        
        if ($data['group_id'] == PUN_ADMIN || $data['group_id'] == PUN_MOD)
            $admod_list[] = $data;
    }
    
    // Stuff we only do if we're pruning admins/mods
    if (count($admod_list) > 0)
    {
        $result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
        while ($cur_forum = $db->fetch_assoc($result))
        {
            $cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
            $changed = false;
                
            foreach ($admod_list as $key => $val)
            {
                if (in_array($val['id'], $cur_moderators))
                {
                    unset($cur_moderators[$val['username']]);
                    $changed = true;
                }
            }
            
            if ($changed)
            {
                $cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
                $db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
            }
        }
    }
    
    if (count($users) > 0)
    {
        // Delete any subscriptions
        $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE user_id IN ('.implode(',', $users).')') or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
    
        // Remove deleted users from the online list (if they happen to be logged in)
        $db->query('DELETE FROM '.$db->prefix.'online WHERE user_id IN ('.implode(',', $users).')') or error('Unable to remove user from online list', __FILE__, __LINE__, $db->error());
        
        // Set all deleted users' posts to guest
        $db->query('UPDATE '.$db->prefix.'posts SET poster_id=1 WHERE poster_id IN ('.implode(',', $users).')') or error('Unable to update posts', __FILE__, __LINE__, $db->error());
        
        // Delete the users
        $db->query('DELETE FROM '.$db->prefix.'users WHERE id IN ('.implode(',', $users).')') or error('Unable to delete user', __FILE__, __LINE__, $db->error());
    }
    
    message('Pruning complete. Users pruned: '.$users_pruned.'.');
}
elseif (isset($_POST['add_user']))
{
    require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
    require PUN_ROOT.'lang/'.$pun_user['language'].'/register.php';
    $username = pun_trim($_POST['username']);
    $email1 = strtolower(trim($_POST['email']));
    $email2 = strtolower(trim($_POST['email']));

    if ($_POST['random_pass'] == '1')
    {
        $password1 = random_pass(8);
        $password2 = $password1;
    }
    else
    {
        $password1 = trim($_POST['password']);
        $password2 = trim($_POST['password']);
    }

    // Convert multiple whitespace characters into one (to prevent people from registering with indistinguishable usernames)
    $username = preg_replace('#\s+#s', ' ', $username);

    // Validate username and passwords
    if (strlen($username) < 2)
        message($lang_prof_reg['Username too short']);
    else if (pun_strlen($username) > 25)    // This usually doesn't happen since the form element only accepts 25 characters
        message($lang_common['Bad request']);
    else if (strlen($password1) < 4)
        message($lang_prof_reg['Pass too short']);
    else if ($password1 != $password2)
        message($lang_prof_reg['Pass not match']);
    else if (!strcasecmp($username, 'Guest') || !strcasecmp($username, $lang_common['Guest']))
        message($lang_prof_reg['Username guest']);
    else if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $username))
        message($lang_prof_reg['Username IP']);
    else if ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false)
        message($lang_prof_reg['Username reserved chars']);
    else if (preg_match('#\[b\]|\[/b\]|\[u\]|\[/u\]|\[i\]|\[/i\]|\[color|\[/color\]|\[quote\]|\[quote=|\[/quote\]|\[code\]|\[/code\]|\[img\]|\[/img\]|\[url|\[/url\]|\[email|\[/email\]#i', $username))
        message($lang_prof_reg['Username BBCode']);

    // Check username for any censored words
    if ($pun_config['o_censoring'] == '1')
    {
        // If the censored username differs from the username
        if (censor_words($username) != $username)
            message($lang_register['Username censor']);
    }

    // Check that the username (or a too similar username) is not already registered
    $result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE username=\''.$db->escape($username).'\' OR username=\''.$db->escape(preg_replace('/[^\w]/', '', $username)).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());

    if ($db->num_rows($result))
    {
        $busy = $db->result($result);
        message($lang_register['Username dupe 1'].' '.pun_htmlspecialchars($busy).'. '.$lang_register['Username dupe 2']);
    }


    // Validate e-mail
    require PUN_ROOT.'include/email.php';

    if (!is_valid_email($email1))
        message($lang_common['Invalid e-mail']);

    // Check if someone else already has registered with that e-mail address
    $dupe_list = array();

    $result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE email=\''.$email1.'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))
    {
        while ($cur_dupe = $db->fetch_assoc($result))
            $dupe_list[] = $cur_dupe['username'];
    }

    $timezone = '0';
    $language = isset($_POST['language']) ? $_POST['language'] : $pun_config['o_default_lang'];
    $save_pass = (!isset($_POST['save_pass']) || $_POST['save_pass'] != '1') ? '0' : '1';

    $email_setting = intval(1);

    // Insert the new user into the database. We do this now to get the last inserted id for later use.
    $now = time();

    $intial_group_id = ($_POST['random_pass'] == '0') ? $pun_config['o_default_user_group'] : PUN_UNVERIFIED;
    $password_hash = pun_hash($password1);

    // Add the user
    $db->query('INSERT INTO '.$db->prefix.'users (username, group_id, password, email, email_setting, save_pass, timezone, language, style, registered, registration_ip, last_visit) VALUES(\''.$db->escape($username).'\', '.$intial_group_id.', \''.$password_hash.'\', \''.$email1.'\', '.$email_setting.', '.$save_pass.', '.$timezone.' , \''.$language.'\', \''.$pun_config['o_default_style'].'\', '.$now.', \''.get_remote_address().'\', '.$now.')') or error('Unable to create user', __FILE__, __LINE__, $db->error());
    $new_uid = $db->insert_id();

    // Should we alert people on the admin mailing list that a new user has registered?
    if ($pun_config['o_regs_report'] == '1')
    {
        $mail_subject = 'Alert - New registration';
        $mail_message = 'User \''.$username.'\' registered in the forums at '.$pun_config['o_base_url']."\n\n".'User profile: '.$pun_config['o_base_url'].'/profile.php?id='.$new_uid."\n\n".'-- '."\n".'Forum Mailer'."\n".'(Do not reply to this message)';

        pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
    }

    // Must the user verify the registration or do we log him/her in right now?
    if ($_POST['random_pass'] == '1')
    {
        // Load the "welcome" template
        $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/welcome.tpl'));

        // The first row contains the subject
        $first_crlf = strpos($mail_tpl, "\n");
        $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
        $mail_message = trim(substr($mail_tpl, $first_crlf));
        $mail_subject = str_replace('<board_title>', $pun_config['o_board_title'], $mail_subject);
        $mail_message = str_replace('<base_url>', $pun_config['o_base_url'].'/', $mail_message);
        $mail_message = str_replace('<username>', $username, $mail_message);
        $mail_message = str_replace('<password>', $password1, $mail_message);
        $mail_message = str_replace('<login_url>', $pun_config['o_base_url'].'/login.php', $mail_message);
        $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
        pun_mail($email1, $mail_subject, $mail_message);
    }

    message('User Created');
}
else
{
    // Display the admin navigation menu
    generate_admin_menu($plugin);

?>
    <div class="block">
        <h2><span>User management - v<?php echo PLUGIN_VERSION ?></span></h2>
        <div class="box">
            <div class="inbox">
                <p>This Plugin allows you to prune users a certain number of days old with less than a certain number of posts.</p>
                <p><strong>Warning: This has a permanent and instant effect use with extreme caution (it is recomended you make a backup before using this feature).</strong></p>
                <p>It also allows you to manually add users, this is useful for closed forum e.g. if you have disabled user registration in options.</p>
            </div>
        </div>
    </div>
    <div class="blockform">
        <h2 class="block2"><span>User Prune</span></h2>
        <div class="box">
            <form id="example" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <fieldset>
                        <legend>Settings</legend>
                        <div class="infldset">
                        <table class="aligntop" cellspacing="0">
                        <!--Thanks to wiseage for this function -->
                            <tr>
                                <th scope="row">Prune by</th>
                                <td>
                                    <input type="radio" name="prune_by" value="1" checked="checked" /> <strong>Registed date</strong>   <input type="radio" name="prune_by" value="0" /> <strong>Last Login</strong>
                                    <span>This decides if the minimum number of days is calculated since the last login or the registered date.</span>
                                </td>
                            </tr>
                        <!--/Thanks to wiseage for this function -->
                            <tr>
                                <th scope="row">Minimum days since registration/last login</th>
                                <td>
                                    <input type="text" name="days" value="28" size="25" tabindex="1" />
                                    <span>The minimum number of days before users are pruned by the setting specified above.</span>
                                </td>
                            </tr>
                            <tr>
                                <th scope="row">Maximum number of posts</th>
                                <td>
                                    <input type="text" name="posts" value="1"  size="25" tabindex="1" />
                                    <span>Users with more posts than this won't be pruned. e.g. a value of 1 will remove users with no posts.</span>
                                </td>
                            </tr>
                            <tr>
                                <th scope="row">Delete admins and mods?</th>
                                <td>
                                    <input type="radio" name="admods_delete" value="1" /> <strong>Yes</strong>   <input type="radio" name="admods_delete" value="0" checked="checked" /> <strong>No</strong>
                                    <span>If Yes, any affected Moderators and Admins will also be pruned.</span>
                                </td>
                            </tr>
                            <tr>
                                <th scope="row">User status</th>
                                <td>
                                    <input type="radio" name="verified" value="1" /> <strong>Delete any</strong>   <input type="radio" name="verified" value="0" checked="checked" /> <strong>Delete only verified</strong>   <input type="radio" name="verified" value="2" /> <strong>Delete only unverified</strong>
                                    <span>Decideds if (un)verified users should be deleted.</span>
                                </td>
                            </tr>
                        </table>
                        </div>
                    </fieldset>
                </div>
            <p class="submitend"><input type="submit" name="prune" value="Go!" tabindex="2" /></p>
            </form>
        </div>

        <h2 class="block2"><span>Add user</span></h2>
        <div class="box">
            <form id="example" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <fieldset>
                        <legend>Settings</legend>
                        <div class="infldset">
                        <table class="aligntop" cellspacing="0">
                            <tr>
                                <th scope="row">Username</th>
                                <td>
                                    <input type="text" name="username" size="25" tabindex="3" />
                                </td>
                            </tr>
                            <tr>
                                <th scope="row">Email</th>
                                <td>
                                    <input type="text" name="email" size="50" tabindex="3" />
                                </td>
                            </tr>
                            <tr>
                                <th scope="row">Generate random password?</th>
                                <td>
                                    <input type="radio" name="random_pass" value="1" /> <strong>Yes</strong>   <input type="radio" name="random_pass" value="0" checked="checked" /> <strong>No</strong>
                                    <span>If Yes a random password will be generated and emailed to the above address.</span>
                                </td>
                            </tr>
                            <tr>
                                <th scope="row">Password</th>
                                <td>
                                    <input type="text" name="password" size="25" tabindex="3" />
                                    <span>If you don't want a random password.</span>
                                </td>
                            </tr>
                        </table>
                        </div>
                    </fieldset>
                </div>
                <p class="submitend"><input type="submit" name="add_user" value="Go!" tabindex="4" /></p>
            </form>
        </div>
    </div>

<?php
}
?>

Edit 1: It now loads without PHP parse errors! tongue
Edit 2: It now properly displays the number of users pruned (and it also doesn't give errors if no users matched the criteria)

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

63

Re: [Release] User Management Plugin

Smarty can you do thjis:

I need the plug in can do this:


delete the user and update the posts who had been deleted  to guest posts.

Re: [Release] User Management Plugin

That is the most dangerously powerful addition to punBB I have ever seen. I did embrace the add user feature -- great for testing if tweaking the new user process! Sory I couldn't help by tryign out the latest version two posts above -- it's just such a scary feature o.o

Re: [Release] User Management Plugin

yi3artist wrote:

That is the most dangerously powerful addition to punBB I have ever seen. I did embrace the add user feature -- great for testing if tweaking the new user process! Sory I couldn't help by tryign out the latest version two posts above -- it's just such a scary feature o.o

sorry, why is it dangerous or scary?

66

Re: [Release] User Management Plugin

Thanks! I'll give it a go.

Valda

67 (edited by the godote 2007-03-04 12:30)

Re: [Release] User Management Plugin

pedrotuga wrote:
HitMan wrote:

Hmmm...
Posts are not deleted with user but they not see.

what do you mean. "but they not see"?

elbekko wrote:

That they don't show probably.

how to fix this?

Re: [Release] User Management Plugin

http://punbb.org/forums/viewtopic.php?pid=79347#p79347

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

Re: [Release] User Management Plugin

yes, but i allready delete only the user, with the original UMP.

Re: [Release] User Management Plugin

Hi, this is a great plug-in.

Is it easy to have the option for "Generate random password" to be the default option? Could someone point out where in the code I could change this option so it's always selected?

Also, it seems that all of my test emails sent to new users are going straight into their Spam folders. Any ideas on how to avoid this?

TIA!

71 (edited by s0me0ne 2007-05-11 04:38)

Re: [Release] User Management Plugin

http://punbb.org/forums/viewtopic.php?pid=79347#p79347

is the newest, one with the most options and most stable version

that plugin works, but it gives the wrong # of pruned users, it told me 0 but it cleaned up several

good plugin though wink

72

Re: [Release] User Management Plugin

Rickard wrote:

Great stuff. Another thing I can remove from the todo list smile

This feature is quite nice. Maybe it should be added to the standard version, not as plugin. Anyone's opinion?