Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //THIS CODE IS INTENDED FOR USE AS A VBULLETIN 4 CRON SCRIPT, IT REQUIRES THE VBULLETIN GLOBAL VAR PROVIDED BY CRONMANAGER.PHP - YOU MAY EMULATE THIS FUNCTIONALITY BY INCLUDING THE VBULLETIN GLOBAL.PHP
- //RECCOMENDED SCHEDULE IS EVERY 30 MINUTES TO 1 HOUR
- // ############################# VARIABLES ################################forgo
- mysql_pconnect("127.0.0.1", "lala", "lala"); //MYSQL information for the SourceBans/Vbulletin Database
- $db_sourcebans = "nationg1_sourcebans"; //Database name for SourceBans
- $db_vbulletin = "nationg1_vb4"; //Database name for vBulletin
- define("DB_PREFIX", "sb"); //Table Prefix for SourceBans
- $groups_with_admin= array(16,14,13,12,11,10,17); // Comma delimited list of groups with admin.
- // ######################## SET PHP ENVIRONMENT ###########################
- mysql_select_db($db_sourcebans);
- mysql_set_charset('utf8');
- require "CServerRcon.php"; //This file can be found in Sourcebans_web/includes/ and must be located in the same folder as this script.
- error_reporting(E_ALL & ~E_NOTICE); //Prevents "Notices" From showing up
- if (!is_object($vbulletin->db)) // Checks if the vbulletin database is accessiable, otherwise exit the script.
- {
- exit;
- }
- $vbulletin->db->hide_errors(); // Hide Database errors from Vbulletin
- // ############################ FUNCTIONS ################################
- function encrypt_password($password, $salt='SourceBans') // If you use a different salt for your sourcebans installation, Change this.
- {
- return sha1(sha1($salt . $password));
- }
- function getRandomPassword($length = "") //Returns a random alphanumeric string of the specified length, 32 chars if unspecified
- {
- $code = md5(uniqid(rand(), true));
- if ($length != "") return substr($code, 0, $length);
- else return $code;
- }
- function AddAdmin($sourcebans_group_web, $sourcebans_group_server, $sourcebans_group_server_name, $sourcebans_group_server_access, $username, $email, $steamid, $userid)
- {
- $password = getRandomPassword(8); // Generate a password for the user
- $res2 = mysql_query("SELECT `aid`, `group_id` FROM ".DB_PREFIX."_admins LEFT JOIN ".DB_PREFIX."_admins_servers_groups ON ".DB_PREFIX."_admins.aid=".DB_PREFIX."_admins_servers_groups.admin_id WHERE user='".$username."'") or die(mysql_error()); //A quick query so we can check to see if the admin is already an admin and whether they've been promoted or not
- $row2 = mysql_fetch_assoc($res2); // Fetch the result from the previous query
- mysql_query("INSERT INTO ".DB_PREFIX."_admins(user, authid, password, gid, email, srv_group)
- VALUES ('".$username."','".$steamid."','".encrypt_password($password)."',".$sourcebans_group_web.",'".$email."','".$sourcebans_group_server_name."') ON DUPLICATE KEY UPDATE srv_group='".$sourcebans_group_server_name."', gid='".$sourcebans_group_web."'") or die(mysql_error()); // Add the admin to the SourceBans database or, if they already exist, update their group data.
- if(mysql_affected_rows() > 0) //Check if the last query affected any rows, did it change anything or add a new admin? If no, skip.
- {
- $res3 = mysql_query("SELECT `aid` FROM ".DB_PREFIX."_admins WHERE user='".$username."'") or die(mysql_error()); // Select the users AdminID
- $row3 = mysql_fetch_assoc($res3);// Fetch the result from the previous query
- mysql_query("DELETE FROM ".DB_PREFIX."_admins_servers_groups WHERE admin_id='".$row3['aid']."'") or die(mysql_error());//Delete the users admin group data from the table
- mysql_query("INSERT IGNORE INTO ".DB_PREFIX."_admins_servers_groups(admin_id, group_id, srv_group_id, server_id) VALUES (".$row3['aid'].",".$sourcebans_group_server.",".$sourcebans_group_server_access.", -1)") or die(mysql_error()); //Add back their new data.
- //This next bit handles the PMs, the promotion/demotion will only work if your "highest power" admin group is the first id and the "lowest power" is the last id. i.e - Managers = GID1, Council = GID2, Admins = GID3, Members = GID4, Recruits = GID5
- if(mysql_num_rows($res2) == 0)
- {
- SendPM($userid, $username, $sourcebans_group_server_name, $password, 0); //Send the user a message with their password and username telling them that they've been added to the system.
- }
- elseif ($sourcebans_group_server > $row2['group_id'])
- {
- SendPM($userid, $username, $sourcebans_group_server_name, $password, 1); //Tell the user that they have been promoted in sourcebans.
- }
- elseif ($sourcebans_group_server < $row2['group_id'])
- {
- SendPM($userid, $username, $sourcebans_group_server_name, $password, 2); //Tell the user that they have been demoted in sourcebans.
- }
- }
- }
- function SendPM($pm_userid, $pm_username, $pm_group_name, $pm_password, $text) // Send a PM to the user, there is an actual datamanager API in vB for this, but it wasn't working reliable so I fell back on this method
- {
- $pm_from_userid=1; //The Vbulletin UserID to send the PM from
- $pm_from_user_text="Bouncer"; //The Vbulletin UserName to send the PM from
- switch($text) //The messages, pretty self explanatory which is which.
- {
- case 0:
- $pm_text_title="Added to Sourcebans";
- $pm_text="[CENTER][IMG]http://nationgaming.org/bans/images/logos/sb-large.png[/IMG]
- [/CENTER]
- [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.",
- You have been added as a ".$pm_group_name." to the Nation Gaming admin system. Please find below the details required to login to the admin web panel, you will be able to access in-game admin automatically.
- Username: [B]".$pm_username."[/B]
- Password: [B]".$pm_password."[/B]
- You can use this information to login into your new account at: http://nationgaming.org/bans/index.php?p=login
- It is HIGHLY recommended for security reasons that you change your password to something memorable once you login. If you have any questions please contact me or any other Manager with your query.
- Many thanks,
- ".$pm_from_user_text."
- [/SIZE][/FONT][/LEFT]";
- break;
- case 1:
- $pm_text_title="Promoted in Sourcebans";
- $pm_text="[CENTER][IMG]http://Nationgaming.org/bans/images/logos/sb-large.png[/IMG]
- [/CENTER]
- [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.",
- Congratulations! Your to a ".$pm_group_name." on the Nation Gaming admin system. Your login details are the same as before.
- You can use this information to login into your account at: http://nationgaming.org/bans/index.php?p=login
- If you have any questions please contact me or any other Manager with your query.
- Many thanks,
- ".$pm_from_user_text."
- [/SIZE][/FONT][/LEFT]";
- break;
- case 2:
- $pm_text_title="Demoted in Sourcebans";
- $pm_text="[CENTER][IMG]http://nationgaming.org/bans/images/logos/sb-large.png[/IMG]
- [/CENTER]
- [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.",
- We are afraid that you have been demoted to a ".$pm_group_name." on the Nation Gaming's admin system. Your login details are the same as before.
- You can use this information to login into your account at: http://nationgaming.org/bans/index.php?p=login
- If you have any questions please contact me or any other Manager with your query.
- Many thanks,
- ".$pm_from_user_text."
- [/SIZE][/FONT][/LEFT]";
- break;
- case 3:
- $pm_text_title="Removed from Sourcebans";
- $pm_text="[CENTER][IMG]http://nationgaming.org/bans/images/logos/sb-large.png[/IMG]
- [/CENTER]
- [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.",
- We are afraid that you have been removed from the Brotherhood of Gamers admin system.
- If you have any questions please contact me or any other Manager with your query.
- Many thanks,
- ".$pm_from_user_text."
- [/SIZE][/FONT][/LEFT]";
- break;
- }
- mysql_select_db($db_vbulletin); //Switch to vB Database
- mysql_query("INSERT INTO ". TABLE_PREFIX ."pmtext (`fromuserid`, `fromusername`, `title`, `message`, `touserarray`, `dateline`, `showsignature`) VALUES (".$pm_from_userid.", '".$pm_from_user_text."', '".$pm_text_title."', '".$pm_text."', '".serialize(array('cc' => array($pm_userid => $pm_username)))."', ".time().",1)") or die(mysql_error()); //Add the PM details to the pmtext table
- mysql_query("INSERT INTO ". TABLE_PREFIX ."pm (`pmtextid`, `userid`) VALUES (".mysql_insert_id().", ".$pm_userid.")") or die(mysql_error()); //Add the PM to the PM relational table
- mysql_query("UPDATE ". TABLE_PREFIX ."user SET pmunread=pmunread+1, pmtotal=pmtotal+1 WHERE `userid`=".$pm_userid) or die(mysql_error()); //Add to the user's unread and total PM count
- mysql_select_db($db_sourcebans); //Switch Back to SourceBans database
- }
- // ########################################################################
- // ######################### START MAIN SCRIPT ############################
- // ########################################################################
- $res = $vbulletin->db->query_read("SELECT `username`, `user`.`userid` as userid, `usergroupid`, `membergroupids`, `email`, `field5` FROM ". TABLE_PREFIX ."user LEFT JOIN `". TABLE_PREFIX ."userfield` ON `user`.`userid`=`userfield`.`userid`"); //Select all users from the Vbulletin Database
- while($row = mysql_fetch_assoc($res))
- {
- // CLEANUP OLD/INVALID ADMINS
- $res2 = mysql_query("SELECT `aid` FROM ".DB_PREFIX."_admins WHERE user='".$row['username']."'") or die(mysql_error()); //Check if the user has a sourcebans account
- $row2 = mysql_fetch_assoc($res2);
- if (mysql_num_rows($res2)>0 && !in_array($row['usergroupid'], $groups_with_admin)) //If yes, and they are not in one of the admin groups defined above then...
- {
- $additionaluser=false;
- for($i = 0; $i < count($user_additional_groups); $i ++) //Check if they are marked as an additional user to any of the admin groups defined above
- {
- if (in_array($user_additional_groups[$i], $groups_with_admin))
- {
- $additionaluser=true;
- break;
- }
- }
- if($additionaluser == false) // If they aren't remove them from SourceBans.
- {
- mysql_query("DELETE FROM ".DB_PREFIX."_admins_servers_group WHERE admin_id='".$row2['aid']."'");
- mysql_query("DELETE FROM ".DB_PREFIX."_admins WHERE aid='".$row2['aid']."'");
- SendPM($row['userid'], $row['username'], "None", "None", 3); //Send a PM telling them that they've been removed from sourcebans
- }
- }
- // PRIMARY USERGROUP ADMIN CONTROL
- if (in_array($row['usergroupid'], $groups_with_admin)) //If the user is in a primary group defined as an admin, then add/edit them as such.
- {
- switch($row['usergroupid'])
- {
- case 16: //Group ID from vBulletin
- //AddAdmin(Sourcebans Web GroupID, Sourcebans Admin GroupID, Sourcebans Admin Group Name (Must be EXACT), Sourcebans Server GroupID, $row['username'], $row['email'], $row['field5'], $row['userid'])
- AddAdmin(3, 9, "Managers", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 14:
- AddAdmin(9, 8, "Council", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 13:
- AddAdmin(4, 7, "Division Leaders", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 12:
- AddAdmin(5, 6, "Advisors", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 11:
- AddAdmin(6, 4, "Honor Members", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 10:
- AddAdmin(7, 3, "Members", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 17:
- AddAdmin(8, 2, "Recruits", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- }
- continue;
- }
- // ADDITIONAL USERGROUP ADMIN CONTROL
- if (strlen ($row['membergroupids']) > 0){
- $user_additional_groups=explode(",", $row['membergroupids']);
- }
- for($i = 0; $i < count($user_additional_groups); $i ++) //If the user is in a secondary group defined as an admin, then add/edit them as such, same format as above.
- {
- if (in_array($user_additional_groups[$i], $groups_with_admin))
- {
- switch($user_additional_groups[$i])
- {
- case 16:
- AddAdmin(3, 9, "Managers", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 14:
- AddAdmin(9, 8, "Council Members", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 13:
- AddAdmin(4, 7, "Division Leaders", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 12:
- AddAdmin(5, 6, "Advisors", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 11:
- AddAdmin(6, 4, "Honor Members", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 10:
- AddAdmin(7, 3, "Members", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- case 17:
- AddAdmin(8, 2, "Recruits", 1, $row['username'], $row['email'], $row['field5'], $row['userid']);
- break;
- }
- continue;
- }
- }
- }
- //REHASH SERVERS, DOES NOT REQUIRE EDITING
- $res = mysql_query("SELECT ip, port, rcon FROM ".DB_PREFIX."_servers WHERE enabled=1") or die(mysql_error());
- while($row = mysql_fetch_assoc($res))
- {
- $rcon = new CServerRcon($row['ip'], $row['port'], $row['rcon']);
- $rcon->rconCommand("sm_rehash");
- unset($rcon);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement