* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres72.php,v 1.23 2003/01/16 14:45:30 chriskl Exp $
+ * $Id: Postgres72.php,v 1.24 2003/01/17 23:10:10 xzilla Exp $
*/
/**
* Grabs a list of privileges for an object
* @param $object The object whose privileges are to be retrived
- * @return A recordset
+ * @return array containing username and privileges
*/
function getPrivileges($object = '') {
$this->clean($object);
$sql = "SELECT relacl FROM pg_class WHERE relname = '$object'";
-
- return $this->selectSet($sql);
- }
-
-/*
- function get_privilege ($table) {
- global $link, $strYes, $strNo, $arrPrivileges, $arrAcl;
- $sql_get_privilege = "SELECT relacl FROM pg_class WHERE relname = '$table'";
-
- if (!$res = @pg_exec($link, $sql_get_privilege)) {
- pg_die(pg_errormessage($link), $sql_get_privilege, __FILE__, __LINE__);
- } else {
- // query must return exactly one row (check this ?)
- if (!($row = @pg_fetch_array($res, 0))) {
- echo "Error: unable to retrieve ACL for view: $table";
- }
- $priv = trim(ereg_replace("[\{\"]", "", $row[relacl]));
- $users = explode(",", $priv);
- for ($iUsers = 0; $iUsers < count($users); $iUsers++) {
- $aryUser = explode("=", $users[$iUsers]);
- $privilege = $aryUser[1];
-
- for ($i = 0; $i < 7; $i++) {
- // $result[$username][$arrPrivileges[$i]] = strchr($privilege, $arrAcl[$i]) ? $strYes : $strNo;
- $aryUser[0] = $aryUser[0] ? $aryUser[0] : "public";
- // echo $aryUser[0], ": ", $arrAcl[$i], ":", $privilege, "<br>";
- $result[trim($aryUser[0])][$arrPrivileges[$i]] = strchr($privilege, $arrAcl[$i]) ? $strYes : $strNo;
+ $acl = $this->selectField($sql, 'relacl');
+
+ $acldata = trim(ereg_replace("[\{\"]", "", $acl));
+
+ $users = explode(',',$acldata);
+ $numusers = count($users);
+
+ // Hardcode in the field names we intend to use in our displays
+ // this needs to be converted to strings really
+ $privileges[0] = 'user/group@!@select@!@insert@!@update@!@delete@!@rule@!@references@!@trigger';
+
+ for ($i=0; $i<$numusers; $i++)
+ {
+ $userarray = explode("=", $users[$i]);
+ $username = $userarray[0] ? $userarray[0] : "public";
+ $privlist = $userarray[1];
+
+ $privileges[$i+1] = $username;
+
+ $pgAcl = array('r','a','w','d','R','x','t');
+ for ($n = 0; $n < 7; $n++)
+ {
+ $privileges[$i+1] .= strchr($privlist, $pgAcl[$n]) ? '@!@Yes' : '@!@No';
}
+
}
+
+ return $privileges;
}
- return $result;
- }
-*/
}
/**
* Manage views in a database
*
- * $Id: privileges.php,v 1.3 2003/01/04 07:08:03 chriskl Exp $
+ * $Id: privileges.php,v 1.4 2003/01/17 23:10:11 xzilla Exp $
*/
// Include application functions
global $PHP_SELF, $strPrivileges, $strGrant, $strRevoke;
global $strUser,$strGroup,$strSelect,$strInsert,$strUpdate,$strDelete,$strRule;
global $strReferences,$strTrigger,$strAction,$strYes,$strNo;
-
- $object = $_REQUEST['object'];
+
+
+ // the intention here is to look for an 'object' in the request array, and if found
+ // use it, if not found, use table. unfortunatly this throws an error (though it works)
+
+ $object = $_REQUEST['object'] ? $_REQUEST['object'] : $_REQUEST['table'];
echo "<h2>", htmlspecialchars($_REQUEST['database']), ": $strPrivileges : $object</h2>\n";
$misc->printMsg($msg);
- $privs = &$localData->getPrivileges($object);
+ $privileges = &$localData->getPrivileges($object);
// We must return only one row from the above query
- if ($privs->recordCount() == 1) {
- echo "<table border=1>\n";
- echo "<tr>\n";
- echo "<th>$strUser/$strGroup</th><th>$strSelect</th><th>$strInsert</th><th>$strUpdate</th><th>$strDelete</th><th>$strRule</th><th>$strReferences</th><th>$strTrigger</th><th colspan=\"2\">$strAction</th>\n";
- echo "</tr>\n";
-
- $priv = trim(ereg_replace("[\{\"]", "", $privs->f[$data->privFields['privarr']]));
-
- $users = explode(",", $priv);
-
- for ($iUsers = 0; $iUsers < count($users); $iUsers++) {
- $aryUser = explode("=", $users[$iUsers]);
- $username = $aryUser[0] ? $aryUser[0] : "public";
- $privilege = $aryUser[1];
-
- echo "<tr>\n";
- echo "<td>$username</td>\n";
-
- $arrAcl = array('r','a','w','d','R','x','t');
- for ($i = 0; $i < 7; $i++) {
-
- echo '<td>';
- echo strchr($privilege, $arrAcl[$i]) ? $strYes : $strNo;
- echo '</td>';
- }
+ echo '<table border="1">';
+
+ for ($y=0;$y<count($privileges);$y++)
+ {
+ $thisuser = explode('@!@',$privileges[$y]);
- echo "<td><a href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "&object=", urlencode($object), "&action=grant&user=", urlencode($username), "\">$strGrant</a></td>";
+ $otf = '<td>'; $ctf = '</td>';
- echo "<td><a href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "&object=", urlencode($object), "&action=revoke&user=", urlencode($username), "\">$strRevoke</a></td>";
+ if ($y==0) {
+ $otf = '<th>'; $ctf = '</th>';
+ }
- echo "</tr>\n";
-
+ echo '<tr>';
+
+ for ($x=0;$x<count($thisuser);$x++)
+ {
+
+ echo "$otf". $thisuser[$x] ."$ctf";
+ }
+
+ // $endcap = "<td><a href=#>$strGrant</a></td><td><a href=#>$strRevoke</a>";
+ $endcap = "<td><a href=\"$PHP_SELF?database=". urlencode($_REQUEST['database']) ."&object=". urlencode($object) ."&action=grant&user=". urlencode($thisuser[0]) ."\">$strGrant</a></td><td><a href=\"$PHP_SELF?database=". urlencode($_REQUEST['database']) ."&object=". urlencode($object) ."&action=revoke&user=". urlencode($thisuser[0]) ."\">$strRevoke</a></td>";
+
+ if ($y==0) {
+ $endcap = "<th colspan=2>$strAction</td>";
}
- echo "</table>\n";
+ echo $endcap;
+ echo '</tr>';
- } else {
- echo "Could Not Retrieve ACL for Object $object";
}
+ echo '</table>';
+
+
+ //} else {
+ // echo "Could Not Retrieve ACL for Object $object";
+ //}
+
}
$misc->printHeader($strPrivileges);