Skip to content

Commit

Permalink
A very meh rewrite of PHPserv service.
Browse files Browse the repository at this point in the history
  • Loading branch information
grawity committed Jul 7, 2010
1 parent 480c625 commit 31c8746
Showing 1 changed file with 207 additions and 100 deletions.
307 changes: 207 additions & 100 deletions modules/services/phpserv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,43 @@ function event_msg ($from,$to,$message) {
if ((strtolower($to) == 'phpserv') or (strtolower($to) == 'phpserv@'.strtolower($mysql->getsetting('server')))) {
$to = explode('@', $to, 2);
$to = $to[0];
$d = explode(' ', $message);
$args = explode(' ', $message);
$cmd = strtolower(array_shift($args));

// global $mysql;
// global $modules;
$ircd = &ircd();

if ($mysql->getaccess($from) > 0) {
if ($mysql->getaccess($from) > 900) {
if (strtolower($d[0]) == 'aml') {
$ircd->smo('o', '*** Services -- from '.$from.': Loading modules for AutoModuleLoad level ' . $d[1]);
aml($d[1]);

} elseif (strtolower($d[0]) == 'modload') {
load(implode(' ', array_slice($d, 1)));

} elseif (strtolower($d[0]) == 'modunload') {
unload(implode(' ', array_slice($d, 1)));

} elseif (strtolower($d[0]) == 'modreload') {
reload(implode(' ', array_slice($d, 1)));
$access = $mysql->getaccess($from);
switch ($cmd) {
case "aml":
if ($access > 900) {
$ircd->smo('o', "*** Services -- from {$from}: Loading modules for AutoModuleLoad level {$args[0]}");
aml($args[0]);
}
else $self->reply_noaccess($from);
break;
case "modload":
if ($access > 900) {
load(implode(' ', $args));
}
else $self->reply_noaccess($from);
break;
case "modunload":
if ($access > 900) {
unload(implode(' ', $args));
}
else $self->reply_noaccess($from);
break;
case "modreload":
if ($access > 900) {
reload(implode(' ', $args));
}
else $self->reply_noaccess($from);
break;

} elseif (strtolower($d[0]) == 'svnup') {
case "svnup":
if ($access > 900) {
if (pcntl_fork() == 0) {
$svn = popen('svn up 2>&1', 'r');
while (!feof($svn)) {
Expand All @@ -36,103 +51,195 @@ function event_msg ($from,$to,$message) {
die();
}
}
}
if ($mysql->getaccess($from) > 600) {
if (strtolower($d[0]) == 'kill') {
$ircd->svskill($d[1],'PHPServ Kill by '.$from.' ('.implode(' ', array_slice($d, 2)).')');

} elseif (strtolower($d[0]) == 'nick') {
$ircd->svsnick($d[1],$d[2]);
$ircd->smo('o', "\002Abuse: ".$from."\002 used SVSNICK ".$d[1].' '.$d[2]);

} elseif (strtolower($d[0]) == 'mode') {
$ircd->mode('PHPServ',$d[1],implode(' ', array_slice($d, 2)));
$ircd->notice($mysql->getsetting('server'),$d[1],$from.' used PHPServ Mode '.$d[1].' '.implode(' ', array_slice($d, 2)));
$ircd->notice('PHPServ',$from,'Success.');
$ircd->smo('o', "\002Abuse: ".$from."\002 used MODE ".$d[1].' '.implode(' ', array_slice($d, 2)));
} elseif (strtolower($d[0]) == 'global') {
$ircd->notice('PHPServ','$*','*** Network Announcement: '.implode(' ',array_slice($d,1)));
else $self->reply_noaccess($from);
break;

case "kill":
if ($access > 600) {
$victim = array_shift($args);
$reason = implode(" ", $args);
$ircd->svskill($victim, "PHPServ kill by {$from} ({$reason})");
}
}
if ($mysql->getaccess($from) > 100) {
if (strtolower($d[0]) == 'userops') {
$ircd->smo('w', '$'.$from.'$ '.implode(' ', array_slice($d, 1)));
else $self->reply_noaccess($from);
break;

case "nick":
if ($access > 600) {
$old = array_shift($args);
$new = array_shift($args);
$ircd->svsnick($old, $new);
$ircd->smo("o", "\002Abuse: {$from}\002 used SVSNICK {$old} {$new}");
}
}
if (strtolower($d[0]) == 'abuseops') {
$ircd->smo('o', '*** AbuseOPs -- from '.$from.': '.implode(' ', array_slice($d, 1)));

}
if (strtolower($d[0]) == 'setlevel') {
if ($x = $mysql->get($mysql->sql('SELECT * FROM `access` WHERE `user` = '.$mysql->escape($d[1])))) {
$clvl = $x['level'];
$tlvl = $d[2];
$ulvl = $mysql->getaccess($from);
if ($ulvl > $clvl) {
if ($tlvl < $ulvl) {
$mysql->setaccess($x['id'],$tlvl);
$ircd->notice('PHPServ',$from,'Success.');
} else {
$ircd->notice('PHPServ',$from,'Failed. You may not set a user higher than yourself.');
else $self->reply_noaccess($from);
break;

case "mode":
if ($access > 600) {
$target = array_shift($args);
$modes = implode(" ", $args);
$ircd->mode("PHPServ", $target, $modes);
$ircd->notice($mysql->getsetting('server'), $target, "{$from} used PHPServ MODE {$target} {$modes}");
$ircd->smo("o", "\002Abuse: {$from}\002 used MODE {$target} {$modes}");
}
else $self->reply_noaccess($from);
break;

case "userops":
if ($access > 100) {
$text = implode(" ", $args);
$ircd->smo("w", "\${$from}\$ {$args}");
}
else $self->reply_noaccess($from);
break;

case "abuseops":
if ($access > 0) {
$text = implode(" ", $args);
$ircd->smo("o", "*** AbuseOps -- from {$from}: {$text}");
}
else $self->reply_noaccess($from);
break;

case "setlevel":
if ($access > 0) {
$target = array_shift($args);
$target_level = (int) array_shift($args);

if ($x = $mysql->get($mysql->sql('SELECT * FROM `access` WHERE `user` = '.$mysql->escape($target))) {
$current_level = $x['level'];
if ($access > $current_level) {
if ($access >= $target_level) {
$mysql->setaccess($x['id'], $target_level);
$ircd->notice("PHPServ", $from, "Success.");
}
else {
$ircd->notice("PHPServ", $from, "Failed: You may not set a user higher than yourself.");
}
}
else {
$ircd->notice("PHPServ", $from, "Failed: You may not modify a user with a higher level then yourself.");
}
} else {
$ircd->notice('PHPServ',$from,'Failed. You may not modify a user with a higher level then yourself.');
$ircd->notice("PHPServ", $from, "Failed: User does not exist.");
}
} else {
$ircd->notice('PHPServ',$from,'Failed. User does not exist.');
}
} elseif (strtolower($d[0]) == 'logout') {
if ($mysql->logoutaccess($from)) {
$ircd->notice('PHPServ',$from,'Successfully logged out of PHPserv account.');
$ircd->swhois($from);
} else {
$ircd->notice('PHPServ',$from,'Failure.');
}
} elseif (strtolower($d[0]) == 'setpass') {
if ($x = $mysql->get($mysql->sql('SELECT `loggedin` FROM `users` WHERE `nick` = '.$mysql->escape($from)))) {
$mysql->setaccesspassword($x['loggedin'],$d[1]);
$ircd->notice('PHPServ',$from,'Setpass processed successfully.');
} else {
$ircd->notice('PHPServ',$from,'Error while processing setpass: You don\'t exist, go away!');
}
}
else $self->reply_noaccess($from);
break;

} else {
if (strtolower($d[0]) == 'identify' || strtolower($d[0]) == 'id') {
if (isset($d[1]) and isset($d[2]) and $mysql->loginaccess($from,$d[1],$d[2])) {
$ircd->notice('PHPServ',$from,'Identify processed successfully.');
$user = $mysql->get($mysql->sql('SELECT `loggedin` FROM `users` WHERE `nick` = '.$mysql->escape($from)));
$ircd->swhois($from,'is identified to PHPServ as '.$d[1].' (uid='.$user['loggedin'].')');
} else { $ircd->notice('PHPServ',$from,'Error while processing identify.'); }
} elseif (strtolower($d[0]) == 'register') {
if ($mysql->get($mysql->sql('SELECT `user` FROM `access` WHERE `user` = '.$mysql->escape($d[1])))) {
$ircd->notice('PHPServ',$from,'Error while processing registration: User already exists.');
} else {
$mysql->addaccess($d[1],$d[2],1);
$ircd->notice('PHPServ',$from,'Registration processed successfully.');
case "logout":
if ($access > 0) {
if ($mysql->logoutaccess($from)) {
$ircd->swhois($from);
$ircd->notice("PHPServ", $from, "Logged out of PHPServ.");
}
else {
$ircd->notice("PHPServ", $from, "Failed.");
}
}
}
}
if (strtolower($d[0]) == 'help') {
$ircd->notice('PHPServ',$from,'---- Help ----');
$ircd->notice('PHPServ',$from,'REGISTER <user> <pass> - Registers a username with PHPServ.');
$ircd->notice('PHPServ',$from,'IDENTIFY <user> <pass> - Identifies you to a username in PHPServ.');
$ircd->notice('PHPServ',$from,'SETPASS <pass> - Changes your password if you are identified.');
$ircd->notice('PHPServ',$from,'LOGOUT - Does the reverse of IDENTIFY if you are identified.');
$ircd->notice('PHPServ',$from,'---- End Help ----');
} elseif (strtolower($d[0]) == 'svninfo') {
else {
$ircd->notice("PHPServ", $from, "Failed: You are not logged in!");
}
break;

case "setpass":
if ($access > 0) {
$newpass = array_shift($args);
if ($x = $mysql->get($mysql->sql('SELECT `loggedin` FROM `users` WHERE `nick` = '.$mysql->escape($from)))) {
$mysql->setaccesspassword($x['loggedin'], $newpass);
$ircd->notice("PHPServ", $from, "Password changed.");
} else {
$ircd->notice("PHPServ", $from, "You don't exist, go away!");
}
}
else $self->reply_noaccess($from);
break;

case "identify":
case "id":
if ($access <= 0) {
$username = array_shift($args);
$password = array_shift($args);
if (strlen($username) and strlen($password)) {
if ($mysql->loginaccess($from, $username, $password)) {
$userinfo = $mysql->get($mysql->sql('SELECT `loggedin` FROM `users` WHERE `nick` = '.$mysql->escape($from)));
$ircd->swhois($from, "is identified to PHPServ as {$username} (uid={$user['loggedin']})");
$ircd->notice("PHPServ", $from, "Successfully logged in as {$username}");
}
else $self->reply_noaccess($from);
break;
}
else $ircd->notice("PHPServ", $from, "Usage: IDENTIFY username password");
}
else $ircd->notice("PHPServ", $from, "You are already logged in.");
break;

case "register":
if ($access <= 0) {
$username = array_shift($args);
$password = array_shift($args);
if (strlen($username) and strlen($password)) {
if ($mysql->get($mysql->sql('SELECT `user` FROM `access` WHERE `user` = '.$mysql->escape($username)))) {
$ircd->notice("PHPServ", $from, "Error: User already exists.");
}
else {
$mysql->addaccess($username, $password, 1);
$ircd->notice("PHPServ", $from, "Registration successful. Welcome to ClueNet!");
}
}
}
else $ircd->notice("PHPServ", $from, "You are already logged in.");
break;

case "help":
$ircd->notice("PHPServ", $from, "\002---- PHPServ commands ----\002");
if ($access > 900) {
$ircd->notice("PHPServ", $from, "MODLOAD <module> - Load PHPServ module");
$ircd->notice("PHPServ", $from, "MODUNLOAD <module>");
$ircd->notice("PHPServ", $from, "MODRELOAD <module>");
$ircd->notice("PHPServ", $from, "SVNUP");
}
if ($access > 600) {
$ircd->notice("PHPServ", $from, "KILL <victim> <reason> - SVSKILL");
$ircd->notice("PHPServ", $from, "NICK <victim> <newnick> - SVSNICK");
$ircd->notice("PHPServ", $from, "MODE <target> <modestring> - SVSMODE");
}
if ($access > 100) {
$ircd->notice("PHPServ", $from, "USEROPS <text>");
}
if ($access > 0) {
$ircd->notice("PHPServ", $from, "SETPASS <newpass> - Change yourpassword");
$ircd->notice("PHPServ", $from, "LOGOUT - Log out of PHPServ");
}
if ($access < 0) {
$ircd->notice("PHPServ", $from, "IDENTIFY <user> <pwd> - Log in to PHPServ");
$ircd->notice("PHPServ", $from, "REGISTER <user> <pwd> - Create a new PHPServ account");
}
break;

case "svninfo":
if (pcntl_fork() == 0) {
$svn = popen('svn info 2>&1', 'r');
while (!feof($svn)) {
$ircd->notice('PHPServ',$from,fgets($svn,512));
$ircd->notice('PHPServ', $from, fgets($svn, 512));
}
pclose($svn);
die();
}
break;

case "xyzzy":
$ircd->notice("PHPServ", $from, "Nothing happens.");
$ircd->swhois($from, "is awesome");
break;
}
}
}

function reply_noaccess($nick) {
$ircd = &ircd();
$ircd->notice("PHPServ", $nick, "Access denied.");
}

function event_eos ($a) {
// global $settings;
// global $modules;
Expand All @@ -146,14 +253,14 @@ function event_eos ($a) {
function event_signal_term () {
global $mysql;
$ircd = &ircd();
$ircd->smo('o', '*** SERVICES *** HELP! (sigterm)');
$ircd->smo('o', '*** SERVICES *** Received SIGTERM, dieing in a fire.');
$ircd->squit($mysql->getsetting('server'), 'SIGTERM');
}

function event_signal_hup () {
global $mysql;
$ircd = &ircd();
$ircd->smo('o', '*** SERVICES *** RESTARTING! (sighup)');
$ircd->smo('o', '*** SERVICES *** Received SIGHUP, restarting.');
$ircd->squit($mysql->getsetting('server'), 'RESTARTING');
// die('SIGHUP');
}
Expand All @@ -172,10 +279,10 @@ function event_kill ($from,$to,$reason) {
}

// class modinit {
function registerm () {
// global $modules;
$class = new phpserv;
register($class, __FILE__, 'PHPServ Module', 'phpserv');
function registerm () {
// global $modules;
$class = new phpserv;
register($class, __FILE__, 'PHPServ Module', 'phpserv');
}
// }
?>

0 comments on commit 31c8746

Please sign in to comment.