Show subroutines.php syntax highlighted
<?php
/**
* Linux Service Interface
*/
interface LinuxServiceInterface {
const RUNNING = 1;
const STOPPED = 0;
const UNKNOWN = 2;
function getStatus();
function setStatus($status);
function getVersion();
function setVersion($version);
function getName();
function setName($name);
function getID();
function getRuntimeInfo();
function saveRuntimeInfo($stdObject);
}
abstract class LinuxService {
protected $status;
protected $name;
protected $version;
public function __construct() {
$this->status = LinuxService :: RUNNING;
}
public function getStatus() {
return $this->status;
}
public function setStatus($status) {
$this->status = $status;
}
public function getVersion() {
return $this->version;
}
public function setVersion($version) {
$this->version = $version;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getID() {
$this->id = new ReflectionClass($this);
}
public function getRuntimeInfo() {
// NOT IMPLEMENTED BY DEFAULT
return array ();
}
public function saveRuntimeInfo($stdObject) {
// NOT IMPLEMENTED BY DEFAULT
return false;
}
}
class RuntimeInfoData {
const TEXT = 0;
const BOOL = 1;
protected $type = 0;
protected $css_style = 'runtimeInfo';
protected $name;
protected $value;
public function __construct($name = '', $value = '', $type = 0) {
$this->name = $name;
$this->value = $value;
$this->type = $type;
}
public function getName() {
return $this->name;
}
public function getValue() {
if ($this->getType() == RuntimeInfoData :: BOOL) {
if ($this->value == true) {
return 'On';
} else {
return 'Off';
}
}
return $this->value;
}
public function getType() {
return $this->type;
}
public function getCSSStyle() {
return $this->css_style;
}
public function setCSSStyle($newStyle) {
$this->css_style = $newStyle;
}
}
class RuntimeInfoClass {
protected $data = array ();
public function insertData($name, $value = '', $category = '') {
if ($name instanceof RuntimeInfoData) {
$RuntimeInfoObject = $name;
if (empty ($category)) {
$category = $value;
}
$this->data[$category][$RuntimeInfoObject->getName()] = $RuntimeInfoObject;
} else {
$this->data[$category][$name] = $value;
}
}
public function removeData($name, $category = '') {
unset ($this->data[$category][$name]);
}
public function getData() {
return $this->data;
}
}
/**
* Linux Admin module subroutines
*
* ECP MODULE 2.0
*
* @author Luke Satin
* @package linuxadmin
* @version 1.0
*/
class LinuxAdminModule extends Module {
private $services;
/**
* Show Controls
*
* Shows a control panel.
*/
function onShowControls() {
$this->addContent('controls.php');
}
function onShowService() {
try {
$service = $this->getServiceByName($_GET['service']);
$this->addContent('service.php');
$this->registerVariable($service, 'service');
} catch (Exception $e) {
exit ('No service found.');
}
}
function onUsersAdmin() {
try {
$this->addContent('users.php');
$XHTML = $this->getContent();
$XHTML = str_replace("\n", "", $XHTML); // javascript fix
$code = 'var XHTML="' . String :: Escape($XHTML) . '";';
$code .= 'setUsersWindow(net.elitemedia.Windows.Create({width:730,content:XHTML,wiredDrag:true}));';
Ajax :: Action(TabEval :: getBehavior($code));
Renderer :: FlushAjax();
} catch (NoAjaxException $e) {
}
}
function onAddUser($formData) {
if ($formData['user'] == 'root' || empty ($formData['user']))
exit;
if ($formData['pass'] != $formData['pass_'])
exit;
$this->execAsRoot('/usr/sbin/useradd -p ' . escapeshellarg($formData['pass']) . ' ' . escapeshellarg($formData['user']));
Ajax :: Action(TabCallFunction :: getBehavior('Dialog.closeInfo'));
$this->onUsersAdmin();
}
function onSystemUpdate() {
try {
$this->addContent('systemupdate.php');
$XHTML = $this->getContent();
$XHTML = str_replace("\n", "", $XHTML); // javascript fix
$code = 'var XHTML="' . String :: Escape($XHTML) . '";';
$code .= 'net.elitemedia.Windows.Create({width:730,content:XHTML,wiredDrag:true});';
Ajax :: Action(TabEval :: getBehavior($code));
Renderer :: FlushAjax();
} catch (NoAjaxException $e) {
}
}
/**
* Console Command
*
* Remote handling of console commands.
*/
function onConsoleCommand($command) {
$output = shell_exec($command);
try {
$output = trim($output);
$output = str_replace("\n", "#n#", $output);
$output = str_replace("|", "-", $output);
exit ("+:TabEval|net.elitemedia.Terminal._serverData=\"" . String :: Escape($output) . "\";net.elitemedia.Terminal.serverOutput();");
} catch (NoAjaxException $e) {
return $output;
}
}
/**
* Login
*
* Executed when user clicks on the LOGIN button.
*/
function onLogin($access) {
$verified = self :: VerifyUser($access['user'], $access['pass']);
if ($verified) {
// VERIFIED
Storage :: Save('linuxadmin_verified', $verified);
Storage :: Write();
try {
Ajax :: Action(TabCallFunction :: getBehavior('userVerified'));
Renderer :: FlushAjax();
} catch (NoAjaxException $e) {
Location :: Redirect(Location :: Rewrite('index.php')); // redirect to main page of current module
}
} else {
// NOT VERIFIED
try {
Ajax :: Action(TabAlert :: getBehavior('YOU HAVE NOT BEEN VERIFIED!'));
Renderer :: FlushAjax();
} catch (NoAjaxException $e) {
Location :: Redirect(Location :: Rewrite('index.php')); // redirect to main page of current module
}
}
}
/**
* Log Out
*
* Executed when user clicks on the Log Out button.
*/
function onLogOut() {
Storage :: Delete('linuxadmin_verified');
Location :: Redirect(Location :: Rewrite('index.php')); // redirect to main page of current module
}
/**
* Verify User
*
* Verifies linux user against /etc/shadow file.
*/
function VerifyUser($user, $password) {
$passwd = & File_Passwd :: factory('Unix');
return $passwd->staticAuth('/etc/shadow', $user, $password, 'des');
}
/**
* Default
*
* Used when there are no parameters.
*/
function onDefault($params = false) {
if (isset ($_GET['service']) && isset ($_GET['action'])) {
try {
$service = $this->getServiceByName($_GET['service']);
if (is_callable(array (
$service,
$_GET['action']
))) {
$service-> {
$_GET['action'] }
($params);
}
} catch (Exception $e) {
}
} else {
$this->LookForServices();
$this->addContent('services.php');
}
}
function getServices() {
return $this->services;
}
function lookForServices() {
if (sizeof($this->services))
return;
$Browser = ModulesManager :: LoadModule('FileBrowser');
$Browser->setPath('modules/linuxadmin/services');
$dirs = $Browser->getDirs();
$this->services = array ();
foreach ($dirs as $dir) {
$serviceFile = 'modules/linuxadmin/services/' . $dir . '/' . $dir . '.php';
if ($dir != '.svn' && @ file_exists($serviceFile)) {
require_once ($serviceFile);
$class = $dir;
if (!class_exists($class)) {
exit ("Class: " . $class . " does not exist!");
}
$c = new ReflectionClass($class);
$this->services[$class] = $c->newInstance();
}
}
}
function getServiceByName($name) {
$this->lookForServices();
foreach ($this->services as $service) {
if ($service->getName() == $name) {
return $service;
}
}
throw new Exception;
}
function onRuntimeInfoSave($data) {
try {
$service = $this->getServiceByName($_GET['service']);
$service->saveRuntimeInfo(json_decode($data));
} catch (Exception $e) {
}
Ajax :: Action(TabCallFunction :: getBehavior('runtimeInfoSaved'));
Renderer :: FlushAjax();
}
/**
* Handle different application views
*/
function onSetView() {
if (!User :: hasSession()) {
Location :: Redirect('index.php'); // redirect to main page
}
try {
$verified = Storage :: Load('linuxadmin_verified');
if (!$verified) {
throw new StorageException;
}
// linux user has successfuly logged in
Renderer :: setView('index');
} catch (StorageException $e) {
// linux user not logged in
Renderer :: setView('login');
}
}
function execAsRoot($cmd) {
if (strpos($cmd,'>') !== false || strpos($cmd,'| tee') !== false) {
$cmd = 'sudo ' . $cmd;
} else {
$cmd = 'sudo ' . $cmd . ' 2>&1';
}
$output = '';
$exitCode = '';
exec($cmd, $output, $exitCode);
if ($exitCode != 0) {
trigger_error("Command \"$cmd\" failed with exit code $exitCode: " .
join("\n", $output), E_USER_ERROR);
}
return array (
$exitCode,
$output
);
}
function onDeleteUser($user) {
if ($user == 'CyberLuke' || $user == 'root' || empty ($user))
exit;
$this->execAsRoot('/usr/sbin/userdel ' . escapeshellarg($user));
Ajax :: Action(TabCallFunction :: getBehavior('Dialog.closeInfo'));
$this->onUsersAdmin();
}
function onActivateUser($user) {
if ($user == 'CyberLuke' || $user == 'root' || empty ($user))
exit;
$this->execAsRoot('/usr/sbin/usermod -U ' . escapeshellarg($user));
Ajax :: Action(TabCallFunction :: getBehavior('Dialog.closeInfo'));
$this->onUsersAdmin();
}
function onDeactivateUser($user) {
if ($user == 'CyberLuke' || $user == 'root' || empty ($user))
exit;
$this->execAsRoot('/usr/sbin/usermod -L ' . escapeshellarg($user));
Ajax :: Action(TabCallFunction :: getBehavior('Dialog.closeInfo'));
$this->onUsersAdmin();
}
}
?>
See more files for this project here