From 65c6095d9500c01412507b5bf9598cdb2fb6e72e Mon Sep 17 00:00:00 2001
From: "Leigh B. Stoller" <stoller@flux.utah.edu>
Date: Tue, 26 Oct 2004 16:06:30 +0000
Subject: [PATCH] Add argument to let you look for your own images/osids. For
 example:

	https://www.emulab.net/showosid_list.php3?creator=stoller
	https://www.emulab.net/showimageid_list.php3?creator=stoller

A quickie; it can be worked in better if we want.
---
 www/showimageid_list.php3 | 24 +++++++++++++++++++++---
 www/showosid_list.php3    | 21 +++++++++++++++++++--
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/www/showimageid_list.php3 b/www/showimageid_list.php3
index c74bef2a07..4f6a0a6d4b 100644
--- a/www/showimageid_list.php3
+++ b/www/showimageid_list.php3
@@ -1,7 +1,7 @@
 <?php
 #
 # EMULAB-COPYRIGHT
-# Copyright (c) 2000-2003 University of Utah and the Flux Group.
+# Copyright (c) 2000-2004 University of Utah and the Flux Group.
 # All rights reserved.
 #
 include("defs.php3");
@@ -36,12 +36,28 @@ elseif (! strcmp($sortby, "desc"))
     $order = "i.description";
 else 
     $order = "i.imagename";
+$extraclause = "";
+
+#
+# Allow for creator restriction
+#
+if (isset($creator) && $creator != "") {
+    if (! TBvalid_uid($creator)) {
+	PAGEARGERROR("Invalid characters in creator");
+    }
+    if ($isadmin) 
+	$extraclause = "where i.creator='$creator' ";
+    else
+	$extraclause = "and i.creator='$creator' ";
+}
 
 #
 # Get the list.
 #
 if ($isadmin) {
-    $query_result = DBQueryFatal("SELECT * FROM images as i order by $order");
+    $query_result = DBQueryFatal("SELECT * FROM images as i ".
+				 "$extraclause ".
+				 "order by $order");
 }
 else {
     #
@@ -55,7 +71,9 @@ else {
     $query_result =
 	DBQueryFatal("select distinct i.* from images as i ".
 		     "left join group_membership as g on g.pid=i.pid ".
-		     "where g.uid='$uid' or i.global order by $order");
+		     "where (g.uid='$uid' or i.global) ".
+		     "$extraclause ".
+		     "order by $order");
 }
 
 SUBPAGESTART();
diff --git a/www/showosid_list.php3 b/www/showosid_list.php3
index 77b754b73f..7ab753a38a 100644
--- a/www/showosid_list.php3
+++ b/www/showosid_list.php3
@@ -37,18 +37,35 @@ elseif (! strcmp($sortby, "desc"))
 else 
     $order = "o.osname";
 
+#
+# Allow for creator restriction
+#
+$extraclause = "";
+if (isset($creator) && $creator != "") {
+    if (! TBvalid_uid($creator)) {
+	PAGEARGERROR("Invalid characters in creator");
+    }
+    if ($isadmin) 
+	$extraclause = "where o.creator='$creator' ";
+    else
+	$extraclause = "and o.creator='$creator' ";
+}
+
 #
 # Get the project list.
 #
 if ($isadmin) {
     $query_result =
-	DBQueryFatal("SELECT * FROM os_info as o order by $order");
+	DBQueryFatal("SELECT * FROM os_info as o ".
+		     "$extraclause ".
+		     "order by $order");
 }
 else {
     $query_result =
 	DBQueryFatal("select distinct o.* from os_info as o ".
 		     "left join group_membership as g on g.pid=o.pid ".
-		     "where g.uid='$uid' or o.shared=1 ".
+		     "where (g.uid='$uid' or o.shared=1) ".
+		     "$extraclause ".
 		     "order by $order");
 }
 
-- 
GitLab