Skip to content
Snippets Groups Projects
Commit 9337feb7 authored by Robert Anderson's avatar Robert Anderson
Browse files

Added Realm Add/Delete & Realm attributes support

parent c936e8d7
No related branches found
No related tags found
No related merge requests found
...@@ -74,6 +74,7 @@ function printHeader($params = NULL) ...@@ -74,6 +74,7 @@ function printHeader($params = NULL)
<ul> <ul>
<li><a href="user-main.php">User List</a></li> <li><a href="user-main.php">User List</a></li>
<li><a href="group-main.php">Groups</a></li> <li><a href="group-main.php">Groups</a></li>
<li><a href="realms-main.php">Realms</a></li>
</ul> </ul>
<p>WiSP</p> <p>WiSP</p>
......
<?php
# Radius Realms Add
# Copyright (C) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
"Tabs" => array(
"Back to realms" => "realms-main.php",
),
));
if (isset($_POST['frmaction']) && $_POST['frmaction'] == "add") {
?>
<p class="pageheader">Add Realm</p>
<form method="post" action="realms-add.php">
<input type="hidden" name="frmaction" value="add2" />
<table class="entry">
<tr>
<td class="entrytitle">Name</td>
<td><input type="text" name="realms_name" /></td>
</tr>
<tr>
<td class="entrytitle">Disabled</td>
<td>
<select name="realms_disabled">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" />
</td>
</tr>
</table>
</form>
<?php
# Check we have all params
} elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "add2") {
?>
<p class="pageheader">Realm Add Results</p>
<?php
if (!empty($_POST['realms_name'])) {
$stmt = $db->prepare("INSERT INTO ${DB_TABLE_PREFIX}realms (Name,Disabled) VALUES (?,?)");
$res = $stmt->execute(array(
$_POST['realms_name'],
$_POST['realms_disabled']
));
if ($res !== FALSE) {
?>
<div class="notice">Realm added</div>
<?php
} else {
?>
<div class="warning">Failed to add realm</div>
<div class="warning"><?php print_r($stmt->errorInfo()) ?></div>
<?php
}
} else {
?>
<div class="warning">Need a realm name!</dv>
<?php
}
} else {
?>
<div class="warning">Invalid invocation</div>
<?php
}
printFooter();
# vim: ts=4
?>
<?php
# Radius Realms Attribute Add
# Copyright (C) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
"Tabs" => array(
"Back to realm list" => "realms-main.php"
),
));
if (isset($_POST['frmaction']) && $_POST['frmaction'] == "add") {
?>
<p class="pageheader">Add attribute</p>
<form method="post" action="realms-attribute-add.php">
<input type="hidden" name="frmaction" value="add2" />
<table class="entry">
<tr>
<td class="entrytitle">Attribute Name</td>
<td><input type="text" name="attr_name" /></td>
</tr>
<tr>
<td class="entrytitle">Operator</td>
<td>
<select name="attr_operator">
<option value="=">=</option>
<option value="==">==</option>
<option value=":=">:=</option>
<option value="+=">+=</option>
<option value="!=">!=</option>
<option value=">">&gt;</option>
<option value="<">&lt;</option>
<option value=">=">&gt;=</option>
<option value="<=">&lt;=</option>
<option value="=~">=~</option>
<option value="!~">!~</option>
<option value="=*">=*</option>
<option value="!*">!*</option>
<option value="||=">||=</option>
<option value="||==">||==</option>
</select>
</td>
</tr>
<tr>
<td class="entrytitle">Value</td>
<td><input type="text" name="attr_value" /></td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="realms_id" value="<?php echo $_POST['realms_id']; ?>" />
<input type="submit" />
</td>
</tr>
</table>
</form>
<?php
# Check we have all params
} elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "add2") {
?>
<p class="pageheader">Attribute Add Results</p>
<?php
# Check for empty values
if (empty($_POST['attr_name']) || empty($_POST['attr_operator']) || empty($_POST['attr_value'])) {
?>
<div class="warning">Submission cannot have empty value</div>
<?php
} else {
$stmt = $db->prepare("INSERT INTO ${DB_TABLE_PREFIX}realm_attributes (RealmID,Name,Operator,Value) VALUES (?,?,?,?)");
$res = $stmt->execute(array(
$_POST['realms_id'],
$_POST['attr_name'],
$_POST['attr_operator'],
$_POST['attr_value']
));
if ($res !== FALSE) {
?>
<div class="notice">Attribute added</div>
<?php
} else {
?>
<div class="warning">Failed to add attribute</div>
<div class="warning"><?php print_r($stmt->errorInfo()) ?></div>
<?php
}
}
} else {
?>
<div class="warning">Invalid invocation</div>
<?php
}
printFooter();
# vim: ts=4
?>
<?php
# Radius Realms Attribute Change
# Copyright (C) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
"Tabs" => array(
"Back to realm list" => "realms-main.php",
),
));
# Display change screen
if (isset($_POST['frmaction']) && $_POST['frmaction'] == "change") {
# Check an attribute was selected
if (isset($_POST['attr_id'])) {
# Prepare statement
$sql = "SELECT ID, Name, Operator, Value, Disabled FROM ${DB_TABLE_PREFIX}realm_attributes WHERE ID = ".$db->quote($_POST['attr_id']);
$res = $db->query($sql);
$row = $res->fetchObject();
?>
<p class="pageheader">Update Realm Attribute</p>
<form action="realms-attribute-change.php" method="post">
<input type="hidden" name="frmaction" value="change2" />
<input type="hidden" name="attr_id" value="<?php echo $_POST['attr_id']; ?>" />
<table class="entry" style="width: 75%;">
<tr>
<td></td>
<td class="entrytitle textcenter">Old Value</td>
<td class="entrytitle textcenter">New Value</td>
</tr>
<tr>
<td class="entrytitle texttop">
Name
</td>
<td class="oldval texttop"><?php echo $row->name; ?></td>
<td><textarea name="realm_attributes_name" cols="40" rows="1"></textarea></td>
</tr>
<tr>
<td class="entrytitle texttop">
Operator
</td>
<td class="oldval texttop"><?php echo $row->operator; ?></td>
<td>
<select name="realm_attributes_operator">
<option value="=">=</option>
<option value="==">==</option>
<option value=":=">:=</option>
<option value="+=">+=</option>
<option value="!=">!=</option>
<option value=">">&gt;</option>
<option value="<">&lt;</option>
<option value=">=">&gt;=</option>
<option value="<=">&lt;=</option>
<option value="=~">=~</option>
<option value="!~">!~</option>
<option value="=*">=*</option>
<option value="!*">!*</option>
<option value="||=">||=</option>
<option value="||==">||==</option>
</select>
</td>
</tr>
<tr>
<td class="entrytitle texttop">Value</td>
<td class="oldval texttop"><?php echo $row->value; ?></td>
<td><textarea name="realm_attributes_value" cols="40" rows="5"></textarea></td>
</tr>
<tr>
<td class="entrytitle">Disabled</td>
<td class="oldval"><?php echo $row->disabled ? 'yes' : 'no'; ?></td>
<td>
<select name="realm_attributes_disabled" />
<option value="">--</option>
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</td>
</tr>
</table>
<p />
<div class="textcenter">
<input type="submit" />
</div>
</form>
<?php
$res->closeCursor();
} else {
?>
<div class="warning">No attribute selected</div>
<?php
}
# SQL Updates
} elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "change2") {
?>
<p class="pageheader">Attribute Update Results</p>
<?php
# Check an attribute was selected
if (isset($_POST['attr_id'])) {
$updates = array();
if (!empty($_POST['realm_attributes_name'])) {
array_push($updates,"Name = ".$db->quote($_POST['realm_attributes_name']));
}
if (isset($_POST['realm_attributes_operator']) && $_POST['realm_attributes_operator'] != "") {
array_push($updates,"Operator = ".$db->quote($_POST['realm_attributes_operator']));
}
if (!empty($_POST['realm_attributes_value'])) {
array_push($updates,"Value = ".$db->quote($_POST['realm_attributes_value']));
}
if (isset($_POST['realm_attributes_disabled']) && $_POST['realm_attributes_disabled'] != "") {
array_push($updates ,"Disabled = ".$db->quote($_POST['realm_attributes_disabled']));
}
# Check if we have updates
if (sizeof($updates) > 0) {
$updateStr = implode(', ',$updates);
$res = $db->exec("
UPDATE
${DB_TABLE_PREFIX}realm_attributes
SET
$updateStr
WHERE
ID = ".$db->quote($_POST['attr_id']."
"));
if ($res !== FALSE) {
?>
<div class="notice">Attribute updated</div>
<?php
} else {
?>
<div class="warning">Error updating attribute</div>
<div class="warning"><?php print_r($db->errorInfo()) ?></div>
<?php
}
# Warn
} else {
?>
<div class="warning">No attribute updates</div>
<?php
}
# Warn
} else {
?>
<div class="error">No attribute data available</div>
<?php
}
} else {
?>
<div class="warning">Invalid invocation</div>
<?php
}
printFooter();
# vim: ts=4
?>
<?php
# Radius Realms Attribute Delete
# Copyright (C) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
"Tabs" => array(
"Back to realm list" => "realms-main.php",
),
));
# Display delete confirm screen
if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
# Check a user was selected
if (isset($_POST['attr_id'])) {
?>
<p class="pageheader">Delete Attribute</p>
<form action="realms-attribute-delete.php" method="post">
<div>
<input type="hidden" name="frmaction" value="delete2" />
<input type="hidden" name="attr_id" value="<?php echo $_POST['attr_id']; ?>" />
</div>
<div class="textcenter">
Are you very sure? <br />
<input type="submit" name="confirm" value="yes" />
<input type="submit" name="confirm" value="no" />
</div>
</form>
<?php
} else {
?>
<div class="warning">No attribute selected</div>
<?php
}
# SQL Updates
} elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete2") {
?>
<p class="pageheader">Attribute Delete Results</p>
<?php
# Make sure we have the attribute ID set
if (isset($_POST['attr_id'])) {
# And make sure user confirmed
if (isset($_POST['confirm']) && $_POST['confirm'] == "yes") {
$res = $db->exec("DELETE FROM ${DB_TABLE_PREFIX}realm_attributes WHERE ID = ".$db->quote($_POST['attr_id']));
if ($res !== FALSE) {
?>
<div class="notice">Attribute with ID: <?php print_r($_POST['attr_id']);?> deleted</div>
<?php
} else {
?>
<div class="warning">Error deleting attribute</div>
<div class="warning"><?php print_r($db->errorInfo()) ?></div>
<?php
}
# Warn
} else {
?>
<div class="warning">Delete attribute aborted</div>
<?php
}
} else {
?>
<div class="warning">Invocation error, no attribute ID selected</div>
<?php
}
}
printFooter();
# vim: ts=4
?>
<?php
# Radius Realm Attributes
# Copyright (C) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
"Tabs" => array(
"Back to realm list" => "realms-main.php"
),
));
?>
<p class="pageheader">Attribute List</p>
<form id="main_form" action="realms-attributes.php" method="post">
<div class="textcenter">
Action
<select id="main_form_action" name="frmaction"
onchange="
var myform = document.getElementById('main_form');
var myobj = document.getElementById('main_form_action');
if (myobj.selectedIndex == 2) {
myform.action = 'realms-attribute-add.php';
} else if (myobj.selectedIndex == 5) {
myform.action = 'realms-attribute-change.php';
} else if (myobj.selectedIndex == 3) {
myform.action = 'realms-attribute-delete.php';
}
myform.submit();
">
<option selected="selected">select action</option>
<option disabled="disabled"> - - - - - - - - - - - </option>
<option value="add">Add Attribute</option>
<option value="delete">Delete Attribute</option>
<option disabled="disabled"> - - - - - - - - - - - </option>
<option value="change">Change Attribute</option>
</select>
</div>
<p />
<table class="results" style="width: 75%;">
<tr class="resultstitle">
<td class="textcenter">ID</td>
<td class="textcenter">Name</td>
<td class="textcenter">Operator</td>
<td class="textcenter">Value</td>
<td class="textcenter">Disabled</td>
</tr>
<?php
if (isset($_POST['realms_id'])) {
$sql = "
SELECT
ID,
Name,
Operator,
Value,
Disabled
FROM
${DB_TABLE_PREFIX}realm_attributes
WHERE
RealmID = ".$db->quote($_POST['realms_id'])."
ORDER BY
Name
";
$res = $db->query($sql);
while ($row = $res->fetchObject()) {
?>
<tr class="resultsitem">
<td><input type="radio" name="attr_id" value="<?php echo $row->id; ?>"/><?php echo $row->id; ?></td>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->operator; ?></td>
<td><?php echo $row->value; ?></td>
<td class="textcenter"><?php echo $row->disabled ? 'yes' : 'no'; ?></td>
</tr>
<?php
}
$res->closeCursor();
if ($res->rowCount() == 0) {
?>
<p />
<tr>
<td colspan="5" class="textcenter">Realm attribute list is empty</td>
</tr>
<?php
}
?>
<input type="hidden" name="realms_id" value="<?php echo $_POST['realms_id']; ?>" />
<?php
} else {
?>
<tr class="resultitem">
<td colspan="5" class="textcenter">No realm ID selected</td>
</tr>
<?php
}
?>
</table>
</form>
<?php
printFooter();
# vim: ts=4
?>
<?php
# Radius Realms Delete
# Copyright (C) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
"Tabs" => array(
"Back to realms" => "realms-main.php",
),
));
# Display delete confirm screen
if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
# Check a policy group was selected
if (isset($_POST['realms_id'])) {
?>
<p class="pageheader">Delete Realm</p>
<form action="realms-delete.php" method="post">
<input type="hidden" name="frmaction" value="delete2" />
<input type="hidden" name="realms_id" value="<?php echo $_POST['realms_id']; ?>" />
<div class="textcenter">
Are you very sure? <br />
<input type="submit" name="confirm" value="yes" />
<input type="submit" name="confirm" value="no" />
</div>
</form>
<?php
} else {
?>
<div class="warning">No realm selected</div>
<?php
}
# SQL Updates
} elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete2") {
?>
<p class="pageheader">Realm Delete Results</p>
<?php
if (isset($_POST['realms_id'])) {
if (isset($_POST['confirm']) && $_POST['confirm'] == "yes") {
$db->beginTransaction();
$res = $db->exec("
DELETE FROM
${DB_TABLE_PREFIX}realm_attributes
WHERE
RealmID = ".$db->quote($_POST['realms_id'])."
");
if ($res !== FALSE) {
?>
<div class="notice">Realm attributes removed</div>
<?php
} else {
?>
<div class="warning">Error removing realm attributes</div>
<div class="warning"><?php print_r($db->errorInfo()) ?></div>
<?php
}
if ($res !== FALSE) {
$res = $db->exec("
DELETE FROM
${DB_TABLE_PREFIX}realms
WHERE
ID = ".$db->quote($_POST['realms_id'])."
");
if ($res !== FALSE) {
?>
<div class="notice">Realm removed</div>
<?php
} else {
?>
<div class="warning">Error removing realm attributes</div>
<div class="warning"><?php print_r($db->errorInfo()) ?></div>
<?php
}
}
# Check if all is ok, if so, we can commit, else must rollback
if ($res !== FALSE) {
$db->commit();
?>
<div class="notice">Changes comitted.</div>
<?php
} else {
$db->rollback();
?>
<div class="notice">Changes reverted.</div>
<?php
}
} else {
?>
<div class="notice">Realm not deleted, aborted by user</div>
<?php
}
# Warn
} else {
?>
<div class="warning">Invocation error, no realm ID</div>
<?php
}
} else {
?>
<div class="warning">Invalid invocation</div>
<?php
}
printFooter();
# vim: ts=4
?>
<?php
# Radius Realms Main
# Copyright (C) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
));
?>
<p class="pageheader">Realms</p>
<form id="main_form" action="realms-main.php" method="post">
<div class="textcenter">
Action
<select id="main_form_action" name="frmaction"
onchange="
var myform = document.getElementById('main_form');
var myobj = document.getElementById('main_form_action');
if (myobj.selectedIndex == 2) {
myform.action = 'realms-add.php';
} else if (myobj.selectedIndex == 3) {
myform.action = 'realms-delete.php';
} else if (myobj.selectedIndex == 5) {
myform.action = 'realms-attributes.php';
}
myform.submit();
">
<option selected="selected">select action</option>
<option disabled="disabled"> - - - - - - - - - - - </option>
<option value="add">Add Realm</option>
<option value="delete">Delete Realm</option>
<option disabled="disabled"> - - - - - - - - - - - </option>
<option value="members">Attributes</option>
</select>
</div>
<p />
<table class="results" style="width: 75%;">
<tr class="resultstitle">
<td class="textcenter">ID</td>
<td class="textcenter">Name</td>
<td class="textcenter">Disabled</td>
</tr>
<?php
$sql = "SELECT ID, Name, Disabled FROM ${DB_TABLE_PREFIX}realms ORDER BY ID";
$res = $db->query($sql);
if ($res->rowCount() > 0) {
while ($row = $res->fetchObject()) {
?>
<tr class="resultsitem">
<td><input type="radio" name="realms_id" value="<?php echo $row->id; ?>" /></td>
<td><?php echo $row->name; ?></td>
<td class="textcenter"><?php echo $row->disabled ? 'yes' : 'no'; ?></td>
</tr>
<?php
}
} else {
?>
<p />
<tr>
<td colspan="5" class="textcenter">Realms list is empty</td>
</tr>
<?php
}
$res->closeCursor();
?>
</table>
</form>
<?php
printFooter();
# vim: ts=4
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment