aboutsummaryrefslogtreecommitdiff
path: root/php/admin
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2018-01-29 16:04:13 -0500
committerBrian Evans <grknight@gentoo.org>2018-01-29 16:05:35 -0500
commit3c56284f7fe1926f6bf6ebd97ec72805d94df1e4 (patch)
tree805a3fb4cfb14519c0bebc3f1863f4759e916a82 /php/admin
downloadbouncer-3c56284f7fe1926f6bf6ebd97ec72805d94df1e4.tar.gz
bouncer-3c56284f7fe1926f6bf6ebd97ec72805d94df1e4.tar.bz2
bouncer-3c56284f7fe1926f6bf6ebd97ec72805d94df1e4.zip
Import existing bouncer.g.o into gitv1.0-20181208-IMPORT
Diffstat (limited to 'php/admin')
-rw-r--r--php/admin/index.php111
-rw-r--r--php/admin/locations.php100
-rw-r--r--php/admin/login.php42
-rw-r--r--php/admin/logout.php12
-rw-r--r--php/admin/lstats.php59
-rw-r--r--php/admin/mirror-list.php74
-rw-r--r--php/admin/mstats.php32
-rw-r--r--php/admin/os.php100
-rw-r--r--php/admin/products.php101
-rw-r--r--php/admin/pstats.php29
-rw-r--r--php/admin/regions.php101
-rw-r--r--php/admin/users.php104
12 files changed, 865 insertions, 0 deletions
diff --git a/php/admin/index.php b/php/admin/index.php
new file mode 100644
index 0000000..8c3db5c
--- /dev/null
+++ b/php/admin/index.php
@@ -0,0 +1,111 @@
+<?php
+/**
+ * Regions.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+// add mirror
+if (!empty($_POST['add-submit'])) {
+ if (mirror_insert_mirror($_POST['mirror_name'],$_POST['region_id'],$_POST['mirror_baseurl'],$_POST['mirror_rating'])) {
+ set_msg('Mirror added successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
+ exit;
+ } else {
+ set_error('Mirror could not be added because of an unknown error.');
+ }
+}
+
+// process actions
+if (!empty($_POST['submit'])) {
+ if (!empty($_POST['mirror_id'])) {
+ switch($_POST['action']) {
+ case 'edit':
+ if (!empty($_POST['doit'])) {
+ if (mirror_update_mirror($_POST['mirror_id'],$_POST['mirror_name'],$_POST['region_id'],$_POST['mirror_baseurl'],$_POST['mirror_rating'])) {
+ set_msg('Mirror updated successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
+ exit;
+ } else {
+ set_error('Mirror update failed.');
+ }
+ } else {
+ $title = 'Edit Mirror';
+ $nav = INC.'/admin_nav.php';
+ require_once(HEADER);
+ echo '<h2>Edit Mirror</h2>';
+ $posts = mirror_get_one_mirror($_POST['mirror_id']);
+ form_start();
+ include_once(INC.'/forms/mirror.php');
+ form_hidden('doit','1');
+ form_hidden('action','edit');
+ form_hidden('mirror_id',$_POST['mirror_id']);
+ form_submit('submit','','button1','Update');
+ form_end();
+ require_once(FOOTER);
+ exit;
+ }
+ break;
+ case 'delete':
+ if (mirror_delete_mirror($_POST['mirror_id'])) {
+ set_msg('Mirror deleted successfully.');
+ } else {
+ set_error('Mirror could not be deleted.');
+ }
+ break;
+ case 'toggle':
+ if (mirror_toggle($_POST['mirror_id'])) {
+ set_msg('Mirror enabled/disabled.');
+ } else {
+ set_error('Mirror could not be enabled/disabled.');
+ }
+ }
+ } else {
+ set_error('You must select a mirror to continue.');
+ }
+}
+
+$title = 'Mirrors';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Mirrors</h2>';
+
+show_error();
+show_msg();
+
+$mirrors = mirror_get_mirrors();
+
+$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'mirror_active';
+$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'ASC';
+$mirrors=array_order_by($mirrors,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'mirror_id'=>'',
+ 'mirror_active'=>'Status',
+ 'mirror_rating'=>'Rating',
+ 'mirror_name'=>'Host Name',
+ 'mirror_baseurl'=>'Address',
+ 'region_name'=>'Region',
+ 'mirror_count'=>'Hits'
+);
+
+$actions = array(
+ 'toggle'=>'Enable/Disable',
+ 'edit'=>'Edit',
+ 'delete'=>'Delete'
+);
+
+form_start();
+show_list($mirrors,$headers,'radio',$actions);
+form_end();
+
+echo '<h2>Add a Mirror</h2>';
+form_start();
+include_once(INC.'/forms/mirror.php');
+form_submit('add-submit','','button1','Add Mirror');
+form_end();
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/locations.php b/php/admin/locations.php
new file mode 100644
index 0000000..f1bb456
--- /dev/null
+++ b/php/admin/locations.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * File locations.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+// add mirror
+if (!empty($_POST['add-submit'])&&!empty($_POST['location_path'])) {
+ if (mirror_insert_location($_POST['product_id'],$_POST['os_id'],$_POST['location_path'])) {
+ set_msg('Location added successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/locations.php');
+ exit;
+ } else {
+ set_error('Location could not be added because of an unknown error.');
+ }
+}
+
+// process actions
+if (!empty($_POST['submit'])) {
+ if (!empty($_POST['location_id'])) {
+ switch($_POST['action']) {
+ case 'edit':
+ if (!empty($_POST['doit'])) {
+ if (mirror_update_location($_POST['location_id'],$_POST['product_id'],$_POST['os_id'],$_POST['location_path'])) {
+ set_msg('Location updated successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/locations.php');
+ exit;
+ } else {
+ set_error('Location update failed.');
+ }
+ } else {
+ $title = 'Edit Location';
+ $nav = INC.'/admin_nav.php';
+ require_once(HEADER);
+ echo '<h2>Edit Location</h2>';
+ $posts = mirror_get_one_location($_POST['location_id']);
+ form_start();
+ include_once(INC.'/forms/location.php');
+ form_hidden('doit','1');
+ form_hidden('action','edit');
+ form_hidden('location_id',$_POST['location_id']);
+ form_submit('submit','','button1','Update');
+ form_end();
+ require_once(FOOTER);
+ exit;
+ }
+ break;
+ case 'delete':
+ if (mirror_delete_location($_POST['location_id'])) {
+ set_msg('Location deleted successfully.');
+ } else {
+ set_error('Location could not be deleted.');
+ }
+ break;
+ }
+ } else {
+ set_error('You must select a mirror to continue.');
+ }
+}
+
+$title = 'Locations';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Locations</h2>';
+show_error();
+show_msg();
+
+$locations = mirror_get_locations();
+
+$_GET['sort'] = (!empty($_GET['sort']))?$_GET['sort']:'product_name';
+$_GET['order'] = (!empty($_GET['order']))?$_GET['order']:'ASC';
+$locations = array_order_by($locations,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'location_id'=>'',
+ 'product_name'=>'Product',
+ 'os_name'=>'OS',
+ 'location_path'=>'Path'
+);
+
+$actions = array(
+ 'edit'=>'Edit',
+ 'delete'=>'Delete'
+);
+
+form_start();
+show_list($locations,$headers,'radio',$actions);
+form_end();
+
+echo '<h2>Add a Location</h2>';
+form_start();
+include_once(INC.'/forms/location.php');
+form_submit('add-submit','','button1','Add Location');
+form_end();
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/login.php b/php/admin/login.php
new file mode 100644
index 0000000..5e9d4c3
--- /dev/null
+++ b/php/admin/login.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Admin login.
+ * @package mirror
+ * @subpackage admin
+ */
+require_once('../cfg/init.php');
+require_once(LIB.'/auth.php');
+
+// authenticate
+if (!empty($_POST['submit'])) {
+ if ($auth = auth_mysql($_POST['username'],$_POST['password'])) {
+ auth_create_session($auth);
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
+ exit;
+ } else {
+ $msg = 'Authentication failed. Please check username and password and try again.';
+ }
+}
+
+$title='Gentoo Mirror Manager Login';
+$body_tags=' onload="document.getElementById(\'username\').focus();" ';
+require_once(HEADER);
+?>
+<h1>Gentoo Mirror Manager Login</h1>
+<?php echo (!empty($msg))?'<pre>'.$msg.'</pre>':null; ?>
+<form name="form" id="form" method="post" action="./login.php" >
+<div>
+ <label for="username">Username:</label>
+ <input type="text" name="username" id="username" size="30" maxlength="100" />
+</div>
+<br />
+<div>
+ <label for="password">Password:</label>
+ <input type="password" name="password" id="password" size="30" maxlength="100" />
+</div>
+<br />
+<input type="submit" name="submit" id="submit" class="button" value="Log In" />
+</form>
+<?php
+require_once(FOOTER);
+?>
diff --git a/php/admin/logout.php b/php/admin/logout.php
new file mode 100644
index 0000000..d980d9d
--- /dev/null
+++ b/php/admin/logout.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Admin logout.
+ * @package mirror
+ * @subpackage admin
+ */
+require_once('../cfg/init.php');
+require_once(LIB.'/auth.php');
+auth_logout();
+header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/login.php');
+exit;
+?>
diff --git a/php/admin/lstats.php b/php/admin/lstats.php
new file mode 100644
index 0000000..f7f1900
--- /dev/null
+++ b/php/admin/lstats.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Location Statistics.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+$stats = db_get("
+ SELECT
+ IF(mirror_location_mirror_map.location_active='0','DISABLED','ok') as location_active,
+ mirror_name,
+ mirror_baseurl,
+ location_path
+ FROM
+ mirror_mirrors,
+ mirror_location_mirror_map,
+ mirror_locations
+ WHERE
+ mirror_mirrors.mirror_id = mirror_location_mirror_map.mirror_id AND
+ mirror_locations.location_id = mirror_location_mirror_map.location_id
+",MYSQL_ASSOC);
+
+$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'location_active';
+$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'ASC';
+$stats=array_order_by($stats,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'location_active'=>'Status',
+ 'mirror_name'=>'Host Name',
+ 'mirror_baseurl'=>'Address',
+ 'location_path'=>'Path'
+);
+
+// should we export to csv?
+if (!empty($_GET['csv'])) {
+ $csv = array();
+ $csv[] = $headers;
+ foreach ($stats as $row) {
+ $csv[] = $row;
+ }
+ csv_send_csv($csv);
+ exit;
+}
+
+$title = 'Location Statistics';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Location Statistics</h2>';
+
+echo '<p>This shows whether or not a server is serving up a certain file.</p>';
+
+show_list($stats,$headers,'simple');
+
+echo '<p><a href="./lstats.php?csv=1&amp;sort='.$_GET['sort'].'&amp;order='.$_GET['order'].'">Save this page as CSV &raquo;</a></p>';
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/mirror-list.php b/php/admin/mirror-list.php
new file mode 100644
index 0000000..c161efd
--- /dev/null
+++ b/php/admin/mirror-list.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Regions.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+if (!empty($_GET['os'])&&!empty($_GET['product'])) {
+ // clean in os and product strings
+ $os_name = mysql_real_escape_string(trim(strtolower($_GET['os'])));
+ $product_name = mysql_real_escape_string(trim(strtolower($_GET['product'])));
+ // get os and product IDs
+ $os_id = db_name_to_id('mirror_os','os_id','os_name',$os_name);
+ $product_id = db_name_to_id('mirror_products','product_id','product_name',$product_name);
+}
+
+if (!empty($_GET['os_id'])&&!empty($_GET['product_id'])) {
+
+ $os_id = intval($_GET['os_id']);
+ $product_id = intval($_GET['product_id']);
+
+
+ $mirrors = db_get("
+ SELECT DISTINCT
+ mirror_baseurl
+ FROM
+ mirror_mirrors
+ INNER JOIN
+ mirror_location_mirror_map
+ ON
+ mirror_location_mirror_map.mirror_id = mirror_mirrors.mirror_id
+ INNER JOIN
+ mirror_locations
+ ON
+ mirror_location_mirror_map.location_id = mirror_locations.location_id
+ WHERE
+ mirror_locations.os_id = {$os_id} AND
+ mirror_locations.product_id = {$product_id} AND
+ mirror_location_mirror_map.location_active = '1' AND
+ mirror_mirrors.mirror_active = '1'
+ ");
+
+ header("Content-type: text/plain;");
+ foreach ($mirrors as $mirror) {
+ echo $mirror['mirror_baseurl']."\n";
+ }
+ exit;
+
+} else {
+
+ $title = 'Mirror Listing';
+ require_once(HEADER);
+ echo '<h1>Mirror List</h1>';
+ echo '<p>Use this form to get a list of all mirrors serving up active files
+ for the selected Product/OS.</p>';
+ form_start('list','list','get','./mirror-list.php');
+ echo '<div>';
+ form_label('Product', 'product','label-small');
+ form_select('product_id','product','',mirror_get_products_select(),$posts['product_id']);
+ echo ' [<a href="./products.php">edit products</a>]';
+ echo '</div><br />';
+
+ echo '<div>';
+ form_label('OS', 'os','label-small');
+ form_select('os_id','os','',mirror_get_oss_select(),$posts['os_id']);
+ echo ' [<a href="./os.php">edit operating systems</a>]';
+ echo '</div><br />';
+ form_submit('submit','','button1','Update');
+ form_end();
+ require_once(FOOTER);
+}
+?>
diff --git a/php/admin/mstats.php b/php/admin/mstats.php
new file mode 100644
index 0000000..5778d16
--- /dev/null
+++ b/php/admin/mstats.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Mirror Statistics.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+$title = 'Mirror Statistics';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Mirror Statistics</h2>';
+
+$stats = mirror_get_mirror_stats();
+
+$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'count';
+$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'DESC';
+$stats=array_order_by($stats,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'count'=>'Hits',
+ 'mirror_rating'=>'Rating',
+ 'mirror_name'=>'Host Name',
+ 'mirror_baseurl'=>'Address',
+ 'region_name'=>'Region'
+);
+
+show_list($stats,$headers,'simple');
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/os.php b/php/admin/os.php
new file mode 100644
index 0000000..b150245
--- /dev/null
+++ b/php/admin/os.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Operating Systems.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+// add os
+if (!empty($_POST['add-submit'])&&!empty($_POST['os_name'])) {
+ if (mirror_insert_os($_POST['os_name'],$_POST['os_priority'])) {
+ set_msg('OS added successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
+ exit;
+ } else {
+ set_error('OS could not be added because of an unknown error.');
+ }
+}
+
+// process actions
+if (!empty($_POST['submit'])) {
+ if (!empty($_POST['os_id'])) {
+ switch($_POST['action']) {
+ case 'edit':
+ if (!empty($_POST['doit'])) {
+ if (mirror_update_os($_POST['os_id'],$_POST['os_name'],$_POST['os_priority'])) {
+ set_msg('OS updated successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
+ exit;
+ } else {
+ set_error('OS update failed.');
+ }
+ } else {
+ $title = 'Edit OS';
+ $nav = INC.'/admin_nav.php';
+ require_once(HEADER);
+ echo '<h2>Edit OS</h2>';
+ $posts = mirror_get_one_os($_POST['os_id']);
+ form_start();
+ include_once(INC.'/forms/os.php');
+ form_hidden('doit','1');
+ form_hidden('action','edit');
+ form_hidden('os_id',$_POST['os_id']);
+ form_submit('submit','','button1','Update');
+ form_end();
+ require_once(FOOTER);
+ exit;
+ }
+ break;
+ case 'delete':
+ if (!record_exists('mirror_locations','os_id',$_POST['os_id'])&&mirror_delete_os($_POST['os_id'])) {
+ set_msg('OS deleted successfully.');
+ } else {
+ set_error('OS cannot be deleted because it is being used by a file location.');
+ }
+ break;
+ }
+ } else {
+ set_error('You must select a os to continue.');
+ }
+}
+
+$title = 'Operating Systems';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Operating Systems</h1>';
+
+show_error();
+show_msg();
+
+$oss = mirror_get_oss();
+
+$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'os_name';
+$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'ASC';
+$oss=array_order_by($oss,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'os_id'=>'',
+ 'os_name'=>'OS Name',
+ 'os_priority'=>'Priority'
+);
+
+$actions = array(
+ 'edit'=>'Edit',
+ 'delete'=>'Delete'
+);
+
+form_start();
+show_list($oss,$headers,'radio',$actions);
+form_end();
+
+echo '<h2>Add a OS</h2>';
+form_start();
+include_once(INC.'/forms/os.php');
+form_submit('add-submit','','button1','Add OS');
+form_end();
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/products.php b/php/admin/products.php
new file mode 100644
index 0000000..e93686f
--- /dev/null
+++ b/php/admin/products.php
@@ -0,0 +1,101 @@
+<?php
+/**
+ * Products.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+// add product
+if (!empty($_POST['add-submit'])&&!empty($_POST['product_name'])) {
+ if (mirror_insert_product($_POST['product_name'],$_POST['product_priority'])) {
+ set_msg('Product added successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/products.php');
+ exit;
+ } else {
+ set_error('Product could not be added because of an unknown error.');
+ }
+}
+
+// process actions
+if (!empty($_POST['submit'])) {
+ if (!empty($_POST['product_id'])) {
+ switch($_POST['action']) {
+ case 'edit':
+ if (!empty($_POST['doit'])) {
+ if (mirror_update_product($_POST['product_id'],$_POST['product_name'],$_POST['product_priority'])) {
+ set_msg('Product updated successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/products.php');
+ exit;
+ } else {
+ set_error('Product update failed.');
+ }
+ } else {
+ $title = 'Edit Product';
+ $nav = INC.'/admin_nav.php';
+ require_once(HEADER);
+ echo '<h2>Edit Product</h2>';
+ $posts = mirror_get_one_product($_POST['product_id']);
+ form_start();
+ include_once(INC.'/forms/product.php');
+ form_hidden('doit','1');
+ form_hidden('action','edit');
+ form_hidden('product_id',$_POST['product_id']);
+ form_submit('submit','','button1','Update');
+ form_end();
+ require_once(FOOTER);
+ exit;
+ }
+ break;
+ case 'delete':
+ if (!record_exists('mirror_locations','product_id',$_POST['product_id'])&&mirror_delete_product($_POST['product_id'])) {
+ set_msg('Product deleted successfully.');
+ } else {
+ set_error('Product cannot be deleted because it is being used by a file location.');
+ }
+ break;
+ }
+ } else {
+ set_error('You must select a product to continue.');
+ }
+}
+
+$title = 'Products';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Products</h1>';
+
+show_error();
+show_msg();
+
+$products = mirror_get_products();
+
+$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'product_name';
+$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'ASC';
+$products=array_order_by($products,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'product_id'=>'',
+ 'product_name'=>'Product Name',
+ 'product_priority'=>'Priority',
+ 'product_count'=>'Downloads'
+);
+
+$actions = array(
+ 'edit'=>'Edit',
+ 'delete'=>'Delete'
+);
+
+form_start();
+show_list($products,$headers,'radio',$actions);
+form_end();
+
+echo '<h2>Add a Product</h2>';
+form_start();
+include_once(INC.'/forms/product.php');
+form_submit('add-submit','','button1','Add Product');
+form_end();
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/pstats.php b/php/admin/pstats.php
new file mode 100644
index 0000000..e0b4aff
--- /dev/null
+++ b/php/admin/pstats.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Product Statistics.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+$title = 'Product Statistics';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Product Statistics</h2>';
+
+$stats = mirror_get_product_stats();
+
+$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'count';
+$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'DESC';
+$stats=array_order_by($stats,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'count'=>'Hits',
+ 'product_name'=>'Product'
+);
+
+show_list($stats,$headers,'simple');
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/regions.php b/php/admin/regions.php
new file mode 100644
index 0000000..f42c0da
--- /dev/null
+++ b/php/admin/regions.php
@@ -0,0 +1,101 @@
+<?php
+/**
+ * Regions.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+// add region
+if (!empty($_POST['add-submit'])&&!empty($_POST['region_name'])) {
+ if (mirror_insert_region($_POST['region_name'],$_POST['region_priority'])) {
+ set_msg('Region added successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/regions.php');
+ exit;
+ } else {
+ set_error('Region could not be added because of an unknown error.');
+ }
+}
+
+// process actions
+if (!empty($_POST['submit'])) {
+ if (!empty($_POST['region_id'])) {
+ switch($_POST['action']) {
+ case 'edit':
+ if (!empty($_POST['doit'])) {
+ if (mirror_update_region($_POST['region_id'],$_POST['region_name'],$_POST['region_priority'])) {
+ set_msg('Region updated successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/regions.php');
+ exit;
+ } else {
+ set_error('Region update failed.');
+ }
+ } else {
+ $title = 'Edit Region';
+ $nav = INC.'/admin_nav.php';
+ require_once(HEADER);
+ echo '<h2>Edit Region</h2>';
+ $posts = mirror_get_one_region($_POST['region_id']);
+ form_start();
+ include_once(INC.'/forms/region.php');
+ form_hidden('doit','1');
+ form_hidden('action','edit');
+ form_hidden('region_id',$_POST['region_id']);
+ form_submit('submit','','button1','Update');
+ form_end();
+ require_once(FOOTER);
+ exit;
+ }
+ break;
+ case 'delete':
+ if (!record_exists('mirror_mirror_region_map','region_id',$_POST['region_id'])&&mirror_delete_region($_POST['region_id'])) {
+ set_msg('Region deleted successfully.');
+ } else {
+ set_error('Region cannot be deleted because it is linked to a mirror.');
+ }
+ break;
+ }
+ } else {
+ set_error('You must select a region to continue.');
+ }
+}
+
+$title = 'Regions';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Regions</h2>';
+
+show_error();
+show_msg();
+
+$regions = mirror_get_regions();
+
+$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'region_name';
+$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'ASC';
+$regions=array_order_by($regions,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'region_id'=>'',
+ 'region_name'=>'Region Name',
+ 'mirrors'=>'Mirrors',
+ 'region_priority'=>'Priority'
+);
+
+$actions = array(
+ 'edit'=>'Edit',
+ 'delete'=>'Delete'
+);
+
+form_start();
+show_list($regions,$headers,'radio',$actions);
+form_end();
+
+echo '<h2>Add a Region</h2>';
+form_start();
+include_once(INC.'/forms/region.php');
+form_submit('add-submit','','button1','Add Region');
+form_end();
+
+require_once(FOOTER);
+?>
diff --git a/php/admin/users.php b/php/admin/users.php
new file mode 100644
index 0000000..3017c49
--- /dev/null
+++ b/php/admin/users.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * Users.
+ * @package mirror
+ * @subpackage admin
+ */
+$protect=1; // protect this page
+require_once('../cfg/init.php');
+
+// add user
+if (!empty($_POST['add-submit'])&&!empty($_POST['username'])&&!empty($_POST['password'])&&!empty($_POST['rpassword'])) {
+ if (mirror_insert_user($_POST['username'],$_POST['password'],$_POST['rpassword'],$_POST['user_firstname'],$_POST['user_lastname'],$_POST['user_email'])) {
+ set_msg('User added successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/users.php');
+ exit;
+ } else {
+ set_error('User could not be added because of an unknown error.');
+ }
+}
+
+// process actions
+if (!empty($_POST['submit'])) {
+ if (!empty($_POST['user_id'])) {
+ switch($_POST['action']) {
+ case 'edit':
+ if (!empty($_POST['doit'])) {
+ if (mirror_update_user($_POST['user_id'],$_POST['username'],$_POST['password'],$_POST['rpassword'],$_POST['user_firstname'],$_POST['user_lastname'],$_POST['user_email'])) {
+ set_msg('User updated successfully.');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/users.php');
+ exit;
+ } else {
+ set_error('User update failed.');
+ }
+ } else {
+ $title = 'Edit User';
+ $nav = INC.'/admin_nav.php';
+ require_once(HEADER);
+ echo '<h2>Edit User</h2>';
+ $posts = mirror_get_one_user($_POST['user_id']);
+ form_start();
+ include_once(INC.'/forms/user.php');
+ form_hidden('doit','1');
+ form_hidden('action','edit');
+ form_hidden('user_id',$_POST['user_id']);
+ form_submit('submit','','button1','Update');
+ form_end();
+ require_once(FOOTER);
+ exit;
+ }
+ break;
+ case 'delete':
+ if ($_POST['user_id']==$_SESSION['user']['user_id']) {
+ set_error('You cannot delete yourself.');
+ } elseif (mirror_delete_user($_POST['user_id'])) {
+ set_msg('User deleted successfully.');
+ } else {
+ set_error('User could not be deleted because of an error.');
+ }
+ break;
+ }
+ } else {
+ set_error('You must select a user to continue.');
+ }
+}
+
+$title = 'Users';
+$nav = INC.'/admin_nav.php';
+require_once(HEADER);
+echo '<h2>Users</h2>';
+
+show_error();
+show_msg();
+
+$users = mirror_get_users();
+
+$_GET['sort'] = (!empty($_GET['sort']))?$_GET['sort']:'user_lastname';
+$_GET['order'] = (!empty($_GET['order']))?$_GET['order']:'ASC';
+$users = array_order_by($users,$_GET['sort'],$_GET['order']);
+
+$headers = array(
+ 'user_id'=>'',
+ 'user_lastname'=>'Last',
+ 'user_firstname'=>'First',
+ 'user_email'=>'Email',
+ 'username'=>'Username'
+);
+
+$actions = array(
+ 'edit'=>'Edit',
+ 'delete'=>'Delete'
+);
+
+form_start();
+show_list($users,$headers,'radio',$actions);
+form_end();
+
+echo '<h2>Add a User</h2>';
+form_start();
+include_once(INC.'/forms/user.php');
+form_submit('add-submit','','button1','Add User');
+form_end();
+
+require_once(FOOTER);
+?>