Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Never released, thought I should. It makes me look good.
  • Loading branch information
acrois committed Jul 2, 2013
1 parent 7428ba7 commit 0e7e1b8
Show file tree
Hide file tree
Showing 18 changed files with 1,712 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ netcontrol
==========

An in-browser interface for popular tools like RCON, Quake Server queries, Minecraft server queries, etc.

All credits for jquery.ba-hashchange.min.js go to https://github.com/cowboy/jquery-hashchange
84 changes: 84 additions & 0 deletions commands/crcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
require_once('includes/command.php');

class CRCON extends Command
{
function run($parameters)
{
global $terminal;
$requestParameters = array('-h', '-p', '-r');
$parameters = $this->parseFlaggedParameters($requestParameters, $parameters);
$missing = $this->missingKeys($parameters, $requestParameters);

if ($missing === false)
{
$this->help();
return;
}

$parsedURL = parse_url($parameters['h']);
$ip = '127.0.0.1';
$port = 28960;

if (array_key_exists('host', $parsedURL))
{
if (array_key_exists('port', $parsedURL))
{
$port = $parsedURL['port'];
}

$ip = $parsedURL['host'];
}
else
{
$ip = $parsedURL['path'];
}

if ($result = $this->color($this->query($ip, $port, $parameters['p'], $parameters['r'])))
{
$terminal->writeLine($result);
return;
}

$terminal->writeLine('Failed to connect to server.');
}

function help()
{
global $terminal;
$terminal->writeLine('Call of Duty RCON Utility');
$terminal->writeLine('Example: crcon -h 127.0.0.1:28960 -p password -r serverinfo');
}

function color($string)
{
global $settings;
return $this->nonClosingColor($string, $settings['colors']['cod4'], '^');
}

function query($ip, $port, $rcon_pass, $command)
{
$socket = fsockopen('udp://'.$ip, $port, $errno, $errstr, 5);
socket_set_timeout($socket, 5);

if (!$socket)
{
return false;
}

$query = "\xFF\xFF\xFF\xFFrcon \"".$rcon_pass."\" ".$command;
fwrite($socket, $query);

$data = '';

while ($d = fread ($socket, 10000))
{
$data .= $d;
}

fclose($socket);
$data = preg_replace("/....print\n/", '', $data);
return $data;
}
}
?>
78 changes: 78 additions & 0 deletions commands/mping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
require_once('includes/command.php');

class MPing extends Command
{
function run($parameters)
{
global $terminal;

if (count($parameters) != 1)
{
$this->help();
return;
}

$parsedURL = parse_url($parameters[0]);
$result = false;

if (array_key_exists('host', $parsedURL))
{
if (array_key_exists('port', $parsedURL))
{
$result = $this->ping($parsedURL['host'], $parsedURL['port']);
}
else
{
$result = $this->ping($parsedURL['host']);
}
}
else
{
$result = $this->ping($parsedURL['path']);
}

if ($result !== false)
{
$terminal->writeLine($result['motd']);
$terminal->writeLine($result['players'].'/'.$result['max_players'].' players');
return;
}

$terminal->writeLine('The server could not be reached.');
}

function help()
{
global $terminal;
$terminal->writeLine('Minecraft Ping Utility');
$terminal->writeLine('Example: mping 127.0.0.1:25565');
}

function ping($host, $port = 25565, $timeout = 5)
{
$server = @fsockopen($host, $port, $errno, $errstr, $timeout);

if (!$server)
{
return false;
}

fwrite($server, "\xFE");
$result = fread($server, 256);

if ($result[0] != "\xFF")
{
return false;
}

$result = substr($result, 3);
$result = mb_convert_encoding($result, 'auto', 'UCS-2');
$result = explode("\xA7", $result);
fclose($server);
return array('motd' => $result[0],
'players' => intval($result[1]),
'max_players' => intval($result[2]));
}
}
?>
71 changes: 71 additions & 0 deletions commands/qquery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
require_once('includes/command.php');
require_once('includes/class_quake3.php');

class QQuery extends Command
{
function run($parameters)
{
global $terminal;

if (count($parameters) != 1)
{
$this->help();
return;
}

$parsedURL = parse_url($parameters[0]);
$quake = new Quake3();
$result = false;

if (array_key_exists('host', $parsedURL))
{
if (array_key_exists('port', $parsedURL))
{
$result = $quake->queryServerInfo($parsedURL['host'], $parsedURL['port']);
}
else
{
$result = $quake->queryServerInfo($parsedURL['host'], 28960);
}
}
else
{
$result = $quake->queryServerInfo($parsedURL['path'], 28960);
}

if ($result !== false)
{
$terminal->writeLine($this->color($this->arr2String(': ', $result)));
return;
}

$terminal->writeLine('The server could not be reached.');
}

function arr2String($glue, $array)
{
$toReturn = '';

foreach ($array as $key => $value)
{
$toReturn .= $key.$glue.$value."\n";
}

return $toReturn;
}

function help()
{
global $terminal;
$terminal->writeLine('Quake 3 Server Query Utility');
$terminal->writeLine('Example: qquery 127.0.0.1:28960');
}

function color($string)
{
global $settings;
return $this->nonClosingColor($string, $settings['colors']['cod4'], '^');
}
}
?>
83 changes: 83 additions & 0 deletions commands/rcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
require_once('includes/command.php');
require_once('includes/class_rcon.php');

class RCON extends Command
{
function run($parameters)
{
global $terminal;
$requestParameters = array('-h', '-p', '-r');
$parameters = $this->parseFlaggedParameters($requestParameters, $parameters);
$missing = $this->missingKeys($parameters, $requestParameters);

if ($missing === false)
{
$this->help();
return;
}

$parsedURL = parse_url($parameters['h']);
$rcon = null;

if (array_key_exists('host', $parsedURL))
{
if (array_key_exists('port', $parsedURL))
{
$rcon = new RCONSocket($parsedURL['host'], $parsedURL['port']);
}
else
{
$rcon = new RCONSocket($parsedURL['host']);
}
}
else
{
$rcon = new RCONSocket($parsedURL['path']);
}

//$rcon = new RCONSocket($parsedURL['host'], $parsedURL['port']);

if (!$rcon->connect())
{
$terminal->writeLine('Failed to connect. '.$rcon->getErrorString());
return;
}

if ($rcon->login($parameters['p']))
{
$result = $rcon->commandGetResponse($parameters['r']);

if ($result === false)
{
$terminal->writeLine('Failed to communicate. '.$rcon->getErrorString());
return;
}

$terminal->writeLine($this->color($result['s1']));
}
else
{
$terminal->writeLine('Failed to communicate with server or wrong password.');
}

$rcon->disconnect();
}

function help()
{
global $terminal;
$terminal->writeLine('Valve RCON Utility (Minecraft, Counter-Strike, Half-Life, etc.)');
$terminal->writeLine('Example: rcon -h 127.0.0.1:25565 -p password -r help');
}

function color($string)
{
global $settings;
return $this->nonClosingColor($string, $settings['rcon']['colors'], '§');
}

const RCON_AUTH = 3;
const RCON_ECOMMAND = 2;
}
?>
35 changes: 35 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
set_time_limit(15);
$settings = array();

/* TERMINAL SETTINGS */
$settings['terminal']['enabled'] = true; // commands allowed?
$settings['terminal']['commands'] = array('RCON' => 'commands/rcon.php',
'MPing' => 'commands/mping.php',
'CRCON' => 'commands/crcon.php',
'QQuery' => 'commands/qquery.php');

/* COLOR SETTINGS */
$settings['colors']['minecraft'] = array('0' => '000000', '1' => '0000aa', '2' => '00aa00', '3' => '00aaaa',
'4' => 'aa0000', '5' => 'aa00aa', '6' => 'ffaa00', '7' => 'aaaaaa',
'8' => '555550', '9' => '5555ff', 'a' => '55ff55', 'b' => '55ffff',
'c' => 'ff5555', 'd' => 'ff55ff', 'e' => 'ffff55', 'f' => 'ffffff');
$settings['colors']['cod4'] = array('1' => 'f15757', '2' => '00fb00', '3' => 'e8e803', '4' => '0000fe',
'5' => '02e5e5', '6' => 'ff5cff', '7' => 'aaaaaa', '8' => '000000',
'9' => '000000', '0' => '000000');

/* RCON SETTINGS */
$settings['rcon']['quirks'] = false; // quirks mode off by default, turn on if you get errors.
$settings['rcon']['colors'] = $settings['colors']['minecraft']; // reference to the color array
$settings['rcon']['timeout'] = 3; // in seconds, the timeout for an rcon connection

/* MASTER SERVERS */
$settings['masters']['cod4'] = array('cod4master.activision.com', 'cod4authorize.activision.com',
'cod4master.infinityward.com', 'cod4update.activision.com',
'master.gamespy.com:28960', 'master0.gamespy.com',
'master1.gamespy.com', 'clanservers.net');
$settings['masters']['cod5'] = array('cod5master.activision.com', 'cod5authorize.activision.com',
'cod5master.infinityward.com', 'cod5update.activision.com',
'master.gamespy.com:28960', 'master0.gamespy.com',
'master1.gamespy.com', 'clanservers.net');
?>
Binary file added images/application-terminal-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0e7e1b8

Please sign in to comment.