Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Config
- define("S1_PERMFILE", "/dir/to/permissions/file.yml");
- define("S2_PERMFILE", "/dir/to/other/server/file.yml");
- define("S1_HOST", "localhost");
- define("S2_HOST", "localhost");
- define("S1_PORT", "8765");
- define("S2_PORT", "8764");
- define("SOCK_TIMEOUT", "1000");
- define("TELNET_USER","username");
- define("TELNET_PASS","Password");
- /*
- * This function simply changes the users rank. No confirmation or checks are provided.
- * The function shouldn't be run unless the user running it has permission anyway.
- */
- function changeGroup($input, $group, $server = 0) {
- //First we check if the input is a single username, or a list of usernames. (CVS only!!!)
- if (strstr($input, ',')) {
- $input_array = $explode(',', $input);
- }
- else {
- $input_array[0] = $input;
- }
- //We read the correct permissions file to $p for processing
- if ($server == 1) {
- $file = S1_PERMFILE;
- $host = S1_HOST;
- $port = S1_PORT;
- $p = file_get_contents(S1_PERMFILE);
- }
- if ($server == 2) {
- $file = S2_PERMFILE;
- $host = S2_HOST;
- $port = S2_PORT;
- $p = file_get_contents(S2_PERMFILE);
- }
- //Lets parse the YAML to an array!
- $spyc = new Spyc();
- $p = $spyc->YAMLLoad($p);
- //We should check to make sure the group we're trying to move to actually exists.
- if (!array_key_exists($group, $p['groups']))
- throw new Exception("Group $group doesn't exist!", 100);
- //We're only interested in the users, not groups so we can ignore them
- $users = $p['users'];
- //Loop through each user that's input.
- foreach ($input_array as $input) {
- //Now setting the users new rank is as simple as changing the array's value
- $users[$input]["group"] = $group;
- }
- //We now update our $p array with the new user data
- $p['users'] = $users;
- //And generate yml from that array
- $yml = $spyc->dump($p, 4);
- /*
- * Fix for permissions :(
- */
- $x = 0;
- while ($x < 100) {
- $x = strval($x);
- $yml = str_replace(' ' . $x . ':', ' -', $yml);
- $x++;
- }
- $handle = fopen($file, "w");
- if (!$handle)
- throw new Exception("Could not open permissions file for writing", 101);
- if (!fwrite($handle, $yml)) {
- throw new Exception("Could not write to permissions file", 102);
- }
- $user = TELNET_USER;
- $pass = TELNET_PASS;
- $fp = fsockopen($host, $port, $errno, $errstr, 10);
- if (!$fp) {
- echo "Error $errno: $errstr";
- fclose($fp);
- }
- else {
- fputs($fp, $user . "\r\n");
- waste_time();
- fputs($fp, $pass . "\r\n");
- waste_time();
- fputs($fp, "broadcast $input has been moved to $group" . "\r\n");
- waste_time();
- fputs($fp, "permissions -reload all" . "\r\n");
- waste_time();
- fputs($fp, "exit\r\n");
- }
- return true;
- }
- function getServerStatus($server) {
- if ($server == 1) {
- $host = S1_HOST;
- $port = S1_PORT;
- }
- if ($server == 2) {
- $host = S2_HOST;
- $port = S2_PORT;
- }
- $s = fsockopen($host, $port, $errornum, $errorstr, SOCK_TIMEOUT);
- if (!$s)
- return false;
- else
- return true;
- }
- function waste_time() {
- $x = 1;
- while ($x < 5000) {
- $x++;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement