diff --git a/webui/wisp-locations-add.php b/webui/wisp-locations-add.php index e52d48cd1dee07d2311afac3622d84196354283f..0565618fc5934f268aea51ba29fa7d7c8cc1ae7c 100644 --- a/webui/wisp-locations-add.php +++ b/webui/wisp-locations-add.php @@ -29,7 +29,6 @@ printHeader(array( )); if (isset($_POST['frmaction']) && $_POST['frmaction'] == "add") { - ?> <p class="pageheader">Add location</p> @@ -54,56 +53,41 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "add") { # Check we have all params } elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "add2") { - ?> - <p class="pageheader">Location Add Results</p> - <?php # Check name if (empty($_POST['location'])) { - ?> - <div class="warning">Location cannot be empty</div> - <?php # Add to database } else { $stmt = $db->prepare("INSERT INTO ${DB_TABLE_PREFIX}wisp_locations (Location) VALUES (?)"); $res = $stmt->execute(array( - $_POST['location'], - )); - # Was it successful? - if ($res) { + $_POST['location'], + )); + # Was it successful? + if ($res !== FALSE) { ?> - <div class="notice">Location added</div> - <?php - } else { - ?> - <div class="warning">Failed to add location</div> <div class="warning"><?php print_r($stmt->errorInfo()) ?></div> - <?php } } -} else { +} else { ?> - <div class="warning">Invalid invocation</div> - <?php - } printFooter(); diff --git a/webui/wisp-locations-delete.php b/webui/wisp-locations-delete.php index 581bbfac2133bc1948ed84b1113a9ddece74f7e7..daf798fd944bfedad8857876f5671c8169238766 100644 --- a/webui/wisp-locations-delete.php +++ b/webui/wisp-locations-delete.php @@ -38,11 +38,10 @@ printHeader(array( # Display delete confirm screen if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") { + # Check a user was selected if (isset($_POST['location_id'])) { - ?> - <p class="pageheader">Delete Location</p> <form action="wisp-locations-delete.php" method="post"> @@ -54,82 +53,101 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") { <input type="submit" name="confirm" value="no" /> </div> </form> - <?php } else { - ?> - <div class="warning">No location selected</div> - <?php - } + # SQL Updates } elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete2") { - ?> - <p class="pageheader">Location Delete Results</p> - <?php if (isset($_POST['location_id'])) { + if (isset($_POST['confirm']) && $_POST['confirm'] == "yes") { + $db->beginTransaction(); - $res = $db->exec("UPDATE ${DB_TABLE_PREFIX}wisp_userdata SET LocationID = NULL WHERE LocationID = ".$db->quote($_POST['location_id'])); + $res = $db->exec(" + UPDATE + ${DB_TABLE_PREFIX}wisp_userdata + SET + LocationID = NULL + WHERE + LocationID = ".$db->quote($_POST['location_id'])." + "); + if ($res !== FALSE) { ?> <div class="notice">Location members unlinked</div> <?php } else { ?> - <div class="warning">Error unlinking members from location</div> + <div class="warning">Error removing users from location</div> <div class="warning"><?php print_r($db->errorInfo()); ?></div> <?php $db->rollback(); } if ($res !== FALSE) { - $res = $db->exec("DELETE FROM ${DB_TABLE_PREFIX}wisp_locations WHERE ID = ".$db->quote($_POST['location_id'])); + + $res = $db->exec(" + DELETE FROM + ${DB_TABLE_PREFIX}wisp_locations + WHERE + ID = ".$db->quote($_POST['location_id'])." + "); + if ($res !== FALSE) { ?> <div class="notice">Location deleted</div> <?php } else { ?> - <div class="warning">Error deleting location</div> + <div class="warning">Error removing location</div> <div class="warning"><?php print_r($db->errorInfo()); ?></div> <?php $db->rollback(); } + } - if ($res) { + + # Check if all is ok, if so, we can commit, else must rollback + if ($res !== FALSE) { + $db->commit(); ?> - <div class="notice">Location with ID: <?php echo $_POST['location_id']; ?> deleted</div> + <div class="notice">Changes comitted.</div> +<?php + } else { + $db->rollback(); +?> + <div class="notice">Changes reverted.</div> <?php - $db->commit(); } + } else { ?> <div class="warning">Delete location aborted</div> <?php } + } else { ?> - <div class="warning">Invocation error, no location ID selected</div> - <?php - } + } else { ?> <div class="warning">Invocation error</div> <?php } + printFooter(); diff --git a/webui/wisp-locations-manage.php b/webui/wisp-locations-manage.php index 7d035614067daf6ef91e9486bb3d40bfa1bc8b60..82e2002ef47e4d149e91300609334ce91c20d24d 100644 --- a/webui/wisp-locations-manage.php +++ b/webui/wisp-locations-manage.php @@ -27,8 +27,7 @@ printHeader(array( )); # If we have no action, display list -if (!isset($_POST['frmaction'])) -{ +if (!isset($_POST['frmaction'])) { ?> <p class="pageheader">Location List</p> @@ -66,23 +65,20 @@ if (!isset($_POST['frmaction'])) <td class="textcenter">ID</td> <td class="textcenter">Location</td> </tr> - <?php - $sql = "SELECT Name FROM ${DB_TABLE_PREFIX}wisp_locations ORDER BY Name ASC"; $res = $db->query($sql); # List users while ($row = $res->fetchObject()) { - ?> - - <tr class="resultsitem"> - <td><input type="radio" name="location_id" value="<?php echo $row->id; ?>"/></td> - <td><?php echo $row->name; ?></td> - </tr> + <tr class="resultsitem"> + <td><input type="radio" name="location_id" value="<?php echo $row->id; ?>"/></td> + <td><?php echo $row->name; ?></td> + </tr> <?php } + if ($res->rowCount() == 0) { ?> <p /> @@ -91,12 +87,14 @@ if (!isset($_POST['frmaction'])) </tr> <?php } + $res->closeCursor(); ?> </table> </form> <?php } + printFooter(); # vim: ts=4 diff --git a/webui/wisp-multiuser-add.php b/webui/wisp-multiuser-add.php index d1b1b54523ee5cb13c511418915bf40b7b8ae5e4..72b354b52585efd720d47ec75eab7589f97cd4fc 100644 --- a/webui/wisp-multiuser-add.php +++ b/webui/wisp-multiuser-add.php @@ -30,9 +30,7 @@ printHeader(array( if (!isset($_POST['frmaction'])) { - ?> - <p class="pageheader">Add WiSP Users</p> <!-- Add user input fields --> @@ -74,19 +72,17 @@ if (!isset($_POST['frmaction'])) { </form> <?php - } if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { - ?> - <p class="pageheader">Add WiSP Users</p> - <?php #FIXME # Perform checks on input - if (!empty($_POST['num_users']) && !empty($_POST['session_timeout']) && !empty($_POST['data_limit']) && !empty($_POST['time_limit'])) { + if (!empty($_POST['num_users']) && !empty($_POST['session_timeout']) && !empty($_POST['data_limit']) + && !empty($_POST['time_limit'])) { + $db->beginTransaction(); $numberOfUsers = (int)$_POST['num_users']; @@ -96,7 +92,6 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { $loginNamePrefix = $_POST['login_prefix']; for ($counter = 0; $counter <= $numberOfUsers; $counter += 1) { - # Check if user already exists $checkUsernameDuplicates = 0; @@ -137,17 +132,21 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { $checkUsernameDuplicates = 0; } } + } while ($checkUsernameDuplicates > 0); #Insert user into users table - $userInsert = $db->prepare("INSERT INTO - ${DB_TABLE_PREFIX}users (Username) - VALUES - (?) - "); + $userInsert = $db->prepare(" + INSERT INTO + ${DB_TABLE_PREFIX}users (Username) + VALUES + (?) + "); + $userInsertExec = $userInsert->execute(array($userName)); $failed = 0; + # After a user add is successful, continue with inserting the other data if ($userInsertExec) { @@ -224,25 +223,27 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { break; } } - if ($failed == 0) { - $db->commit(); - + # Check if all is ok, if so, we can commit, else must rollback + if ($res !== FALSE) { + $db->commit(); ?> - - <div class="notice">Users added</div> - + <div class="notice">Changes comitted.</div> <?php - + } else { + $db->rollback(); +?> + <div class="notice">Changes reverted.</div> +<?php + } } + } else { ?> - <div class="warning">One or more fields have been left empty</div> - <?php - } + } printFooter(); diff --git a/webui/wisp-user-add.php b/webui/wisp-user-add.php index 1c098f136c096bf2597e19fa6a9f406681ba13cb..e6d612e04d344c9683b0b69343cdb2d3773f2b66 100644 --- a/webui/wisp-user-add.php +++ b/webui/wisp-user-add.php @@ -30,9 +30,7 @@ printHeader(array( if (!isset($_POST['frmaction'])) { - ?> - <p class="pageheader">Add WiSP User</p> <!-- Add user input fields --> @@ -168,11 +166,8 @@ if (!isset($_POST['frmaction'])) { } if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { - ?> - <p class="pageheader">Add user</p> - <?php $db->beginTransaction(); @@ -181,12 +176,10 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { $stmt = $db->prepare("INSERT INTO ${DB_TABLE_PREFIX}users (Username) VALUES (?)"); $res = $stmt->execute(array($_POST['user_name'])); - if ($res !== FALSE) { ?> <div class="notice">User added</div> <?php - # Grab inserted ID $userID = $db->lastInsertId(); @@ -258,7 +251,6 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { } } - if ($res !== FALSE) { # Insert IP Address $stmt = $db->prepare(" @@ -347,7 +339,6 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { } } - if ($res !== FALSE) { # Insert user data $stmt = $db->prepare(" @@ -377,11 +368,17 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "insert") { } } - + # 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 } } diff --git a/webui/wisp-user-delete.php b/webui/wisp-user-delete.php index 6370e161a0bc03165222e338deed8576466dbf8a..86d9036e3c57cb5cc75d82b43798c8208341b77f 100644 --- a/webui/wisp-user-delete.php +++ b/webui/wisp-user-delete.php @@ -37,11 +37,10 @@ printHeader(array( # Display delete confirm screen if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") { + # Check a user was selected if (isset($_POST['user_id'])) { - ?> - <p class="pageheader">Remove User</p> <form action="wisp-user-delete.php" method="post"> @@ -55,24 +54,23 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") { <input type="submit" name="confirm" value="no" /> </div> </form> - <?php } else { - ?> - <div class="warning">No user selected</div> - <?php } + # SQL Updates } elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete2") { ?> <p class="pageheader">User Remove Results</p> <?php if (isset($_POST['user_id'])) { + if (isset($_POST['confirm']) && $_POST['confirm'] == "yes") { + $db->beginTransaction(); # Delete user data $res = $db->exec("DELETE FROM wisp_userdata WHERE UserID = ".$db->quote($_POST['user_id'])); @@ -118,16 +116,32 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") { <?php $db->rollback(); } + + # 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="warning">Delete user aborted</div> <?php } + } else { ?> <div class="warning">No user selected</div> <?php } + } else { ?> @@ -139,4 +153,3 @@ printFooter(); # vim: ts=4 ?> - diff --git a/webui/wisp-user-list.php b/webui/wisp-user-list.php index 45a346b0f6a6fc783c4adf4eaf22623c9e722fae..9ca75b88fff55c214e876f4e29c9e3134a125444 100644 --- a/webui/wisp-user-list.php +++ b/webui/wisp-user-list.php @@ -67,8 +67,9 @@ if (!isset($_POST['frmaction'])) { </table> </form> <?php -} -if (isset($_POST['frmaction']) && $_POST['frmaction'] == "dofilter") { + + +} elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "dofilter") { ?> <form id="main_form" action="wisp-user-list.php" method="post"> @@ -114,14 +115,15 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "dofilter") { <td class="textcenter">IP Address</td> </tr> <?php - $sql = "SELECT - ID, Name - FROM - ${DB_TABLE_PREFIX}wisp_locations - ORDER BY + $sql = " + SELECT + ID, Name + FROM + ${DB_TABLE_PREFIX}wisp_locations + ORDER BY Name ASC - "; + "; $res = $db->query($sql); $locationsIDtoName = array(); @@ -192,39 +194,38 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "dofilter") { # Query based on user input $sql = " SELECT - users.ID, - users.Username, - wisp_userdata.UserID, - wisp_userdata.FirstName, - wisp_userdata.LastName, - wisp_userdata.Email, - wisp_userdata.Phone, - wisp_userdata.LocationID + users.ID, + users.Username, + wisp_userdata.UserID, + wisp_userdata.FirstName, + wisp_userdata.LastName, + wisp_userdata.Email, + wisp_userdata.Phone, + wisp_userdata.LocationID FROM - users, wisp_userdata $extraTables + users, wisp_userdata $extraTables WHERE - users.ID = wisp_userdata.UserID - $extraSQL - $sortSQL - "; + users.ID = wisp_userdata.UserID + $extraSQL + $sortSQL + "; $res = $db->prepare($sql); $res->execute($extraSQLVals); # List users while ($row = $res->fetchObject()) { - # Second dirty query to get user's attributes $tempUserID = $row->id; $attrQuery = " - SELECT - Name, - Value - FROM - user_attributes - WHERE - UserID = $tempUserID - "; + SELECT + Name, + Value + FROM + user_attributes + WHERE + UserID = $tempUserID + "; $dataCap = NULL; $timeCap = NULL; @@ -264,13 +265,11 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "dofilter") { <td><?php echo $timeCap; ?> Min</td> <td><?php echo $userIP; ?></td> </tr> - <?php } # If there were no rows, complain if ($res->rowCount() == 0) { - ?> <p /> <tr> @@ -284,6 +283,7 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "dofilter") { </form> <?php } + printFooter(); # vim: ts=4 diff --git a/webui/wisp-user-logs.php b/webui/wisp-user-logs.php index 55c16c7bdfbba7cbbf0bfb8f09769394093a1739..e1994f79d1779aea61fc961b6acee51275588343 100644 --- a/webui/wisp-user-logs.php +++ b/webui/wisp-user-logs.php @@ -38,7 +38,6 @@ printHeader(array( <p class="pageheader">WiSP User Log</p> <?php - if (isset($_POST['user_id'])) { # Which user in the accounting table should we look for? @@ -47,9 +46,7 @@ if (isset($_POST['user_id'])) { $row = $stmt->fetchObject(); $stmt->closeCursor(); $getuser = $row->username; - ?> - <form id="main_form" action="wisp-user-logs.php" method="post"> <!-- User input from and to dates --> <div> @@ -126,37 +123,37 @@ if (isset($_POST['user_id'])) { # Query to get all default data $sql = " SELECT - EventTimestamp, - ServiceType, - FramedProtocol, - NASPort, - NASPortType, - CallingStationID, - CalledStationID, - NASPortID, - AcctSessionID, - FramedIPAddress, - AcctAuthentic, - NASIdentifier, - NASIPAddress, - AcctDelayTime, - AcctSessionTime, - AcctInputOctets, - AcctInputGigawords, - AcctOutputOctets, - AcctOutputGigawords, - AcctStatusType, - AcctTerminateCause + EventTimestamp, + ServiceType, + FramedProtocol, + NASPort, + NASPortType, + CallingStationID, + CalledStationID, + NASPortID, + AcctSessionID, + FramedIPAddress, + AcctAuthentic, + NASIdentifier, + NASIPAddress, + AcctDelayTime, + AcctSessionTime, + AcctInputOctets, + AcctInputGigawords, + AcctOutputOctets, + AcctOutputGigawords, + AcctStatusType, + AcctTerminateCause FROM - ${DB_TABLE_PREFIX}accounting + ${DB_TABLE_PREFIX}accounting WHERE - Username = '$getuser' - $extraSQL + Username = '$getuser' + $extraSQL ORDER BY - EventTimestamp + EventTimestamp DESC - $limitSQL - "; + $limitSQL + "; $res = $db->prepare($sql); $res->execute($extraSQLVals); @@ -166,7 +163,6 @@ if (isset($_POST['user_id'])) { $totalSessionTime = 0; while ($row = $res->fetchObject()) { - # Input $inputDataItem = 0; @@ -199,9 +195,7 @@ if (isset($_POST['user_id'])) { } $totalSessionTime += $sessionTimeItem; - ?> - <tr class="resultsitem"> <td class="textcenter"><?php echo $row->eventtimestamp; ?></td> <td class="textcenter"><?php echo $row->servicetype; ?></td> @@ -223,69 +217,43 @@ if (isset($_POST['user_id'])) { <td class="textcenter"><?php echo $row->acctstatustype; ?></td> <td class="textcenter"><?php echo strRadiusTermCode($row->acctterminatecause); ?></td> </tr> - <?php - } - if ($res->rowCount() == 0) { + if ($res->rowCount() == 0) { ?> - <tr> <td colspan="23" class="textcenter">No logs found for user: <?php echo $getuser; ?></td> </tr> - <?php - } else { - ?> <tr class="resultsitem"> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> - <td class="textcenter"></td> + <td colspan="13"</td> <td class="textcenter" style="font-weight: bold;"><? printf('%.2f',$totalSessionTime); ?> Min</td> <td class="textcenter" style="font-weight: bold;"><? printf('%.2f',$totalInputData); ?> MB</td> <td class="textcenter" style="font-weight: bold;"><? printf('%.2f',$totalOutputData); ?> MB</td> - <td class="textcenter"></td> - <td class="textcenter"></td> </tr> - <?php - } + $res->closeCursor(); ?> </table> + <?php } else { - ?> <div class="warning">No user selected</div> <?php - } ?> - - <?php printFooter(); - # vim: ts=4 ?>