<? if(!isset($PHP_AUTH_USER)) {
Header("WWW-authenticate: basic realm=\"$SID\"");
Header("HTTP/1.0 401 Unauthorized");
$title="Login Instructions";
echo "<blockquote> \n".
"You are not authorised to enter the site\n".
"</blockquote> \n";
exit;
} else {
putenv("ORACLE_SID=MAPSA"); /* Your default SID here */
putenv("ORACLE_HOME=/u01/app/oracle/product/8.0.5"); /* Your value! */
if (!($conn=ora_logon("$PHP_AUTH_USER@$SID",$PHP_AUTH_PW))) {
Header("WWW-authenticate: basic realm=\"$SID\"");
Header("HTTP/1.0 401 Unauthorized");
$title="Login Instructions";
echo "<blockquote> \n".
"You are not authorised to enter the site\n".
"</blockquote> \n";
exit;
}
}
/*
||
|| oraphp.php3 - v1.0
|| Author : Vattekkat Satheesh Babu
|| Date : Aug 03, 1999
|| License: GPL
||
|| Allows user to navigate an Oracle database. This is a quick script
|| put together in a very short time. So, code might not be formatted
|| to anyone's liking. Comments and code are always welcome
||
|| Customization needed will be changing the SID and ORACLE_HOME above
*/
if(!isset($schema))
$schema=strtoupper($PHP_AUTH_USER);
$title="Oracle Schema Browser [$schema@$SID]";
$header1=$title;
$ObjectDesc = array(
"TABLE" => "Tables"
,"VIEW" => "Views"
,"INDEX" => "Indexes"
,"TRIGGER" => "Triggers"
,"SYNONYM" => "Synonyms"
,"FUNCTION" => "Functions"
,"PROCEDURE" => "Procedures"
,"SEQUENCE" => "Sequences"
,"PACKAGE" => "Packages"
,"PACKAGE BODY" => "Package Bodies"
);
if(!isset($printqry))
$printqry="off";
$sidebar="<P CLASS=\"FOOTER\" ALIGN=CENTER><small>[ ";
if (isset($objecttype)){
$sidebar .= "<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&printqry=$printqry\">Top</A> ";
}else{
$sidebar .= "Top ";
}
$sidebar .= "| <A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&printqry=$printqry&changeschema=CHANGESCHEMA\">Schema</A> ";
while(list($key,$val)=each($ObjectDesc)) {
if ( $key == $objecttype )
$sidebar .= "| $val \n";
else
$sidebar .= "| <A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&printqry=$printqry&objecttype=$key\">$val</A> \n";
}
if (isset($objecttype))
$others="&objecttype=$objecttype";
if (isset($objectnm))
$others.="&objectnm=$objectnm";
if (isset($oper))
$others.="&oper=$oper";
$sidebar .= "]</small> </P>";
reset($ObjectDesc);
?>
<HTML>
<HEAD>
<TITLE>
<? echo "$title\n"; ?>
</TITLE>
</HEAD>
<BODY>
<? echo "$sidebar\n"; ?>
<H1>
<? echo "$header1\n"; ?>
</H1>
<?
function printoraerr($in_cur){
global $conn;
// function to check whether an oracle error occured
// if it did, print the error
// call this after every oracle call when a cursor is active
// If it encountered an error, we exit immediately
if(ora_errorcode($in_cur)) {
echo "Oracle code - ".ora_error($in_cur)."<br>\n";
ora_logoff($conn);
exit;
}
return;
}
function exequery($w_qry) {
global $conn,$printqry,$others,$SID,$PHP_SELF,$schema;
$cursor=ora_open($conn); printoraerr($cursor);
ora_parse($cursor,$w_qry,0); printoraerr($cursor);
ora_exec($cursor); printoraerr($cursor);
$numrows=0;
$w_numcols=ora_numcols($cursor);
// print headers
echo "
<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"2\">
<TR>\n";
for ($i=0;$i<$w_numcols;$i++) {
$align=(ora_columntype($cursor,$i)=="NUMBER")? "RIGHT":"LEFT";
echo "\t<TH VALIGN=TOP ALIGN=$align>".ora_columnname($cursor,$i). "</TH>\n";
}
echo "</TR>\n";
while(ora_fetch($cursor)){
echo "<TR>\n";
for ($i=0;$i<$w_numcols;$i++) {
$align=(ora_columntype($cursor,$i)=="NUMBER")? "RIGHT":"LEFT";
if(ora_columntype($cursor,$i)=="LONG")
echo "<TD VALIGN=TOP ALIGN=$align><PRE>".ora_getcolumn($cursor,$i). "</PRE></TD>\n";
else
echo "<TD VALIGN=TOP ALIGN=$align>".ora_getcolumn($cursor,$i). "</TD>\n";
printoraerr($cursor);
}
$numrows++;
echo "</TR>\n";
}
if ($numrows==0)
echo "<TR><TD COLSPAN=\"$w_numcols\"><B>Query returned no records</B></TD></TR>\n";
else {
echo "<TR>\n";
echo "<TH COLSPAN=\"".($w_numcols-1)."\" ALIGN=RIGHT>Count</TH>\n";
echo "<TH ALIGN=RIGHT>$numrows</TH>\n";
echo "</TR>\n";
}
echo "</TABLE>\n";
ora_close($cursor);
if ($printqry=="on") {
echo "<H4>Query</H4><P><pre>".htmlspecialchars($w_qry). "</pre></P>
<P ALIGN=CENTER><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&printqry=off$others\"><small><u><i>Hide Query</i></u></small></A></P>\n";
} else {
echo "<P ALIGN=CENTER><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&printqry=on$others\"><small><u><i>Show Query</i></u></small></A></P>\n";
}
return;
}
function change_schema(){
global $conn,$printqry,$others,$SID,$PHP_SELF,$schema;
$qry="SELECT username FROM all_users ORDER BY username";
$cursor=ora_open($conn); printoraerr($cursor);
ora_parse($cursor,$qry,0); printoraerr($cursor);
ora_exec($cursor); printoraerr($cursor);
echo "<form name=\"choseschema\" action=\"$PHP_SELF\">
<input type=\"hidden\" name=\"printqry\" value=\"$printqry\">
<input type=\"hidden\" name=\"SID\" value=\"$SID\">";
if(isset($objecttype))
echo "<input type=\"hidden\" name=\"objecttype\" value=\"$objecttype\">\n";
if(isset($oper))
echo "<input type=\"hidden\" name=\"oper\" value=\"$oper\">\n";
if(isset($objectnm))
echo "<input type=\"hidden\" name=\"objectnm\" value=\"$objectnm\">\n";
echo "<select name=\"schema\">\n";
while(ora_fetch($cursor)){
$option=ora_getcolumn($cursor,0);
if("$option" == "$schema")
echo "<option value=\"$option\" SELECTED>$option</option>\n";
else
echo "<option value=\"$option\">$option</option>\n";
}
echo "</select>\n<input type=\"submit\" value=\"Change Schema\">\n</form>\n";
ora_close($cursor);
echo "<P>Choose the schema you want and press the button. You will be
taken to the front page and then onwards you can see <B>only</B> the
objects owned by the new schema.</P>\n";
return;
}
function user_sources() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm, $SID, $printqry,$schema;
$qry="
SELECT
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=$objecttype&oper=srcdesc&printqry=$printqry&objectnm='||I.name||'\">'||I.name||'</A>' \"Name\",
COUNT(I.line) \"Lines\"
FROM
all_source I
WHERE I.type='$objecttype'
AND I.owner='$schema'
GROUP BY
I.name
ORDER BY
I.name";
$desc = $ObjectDesc[$objecttype];
exequery($qry);
}
function user_src_desc() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm, $SID,$schema;
$qry="
SELECT
'<PRE>'||NVL(I.text,' ')||'</PRE>' \"Code\"
FROM
all_source I
WHERE I.type='$objecttype'
AND I.name='$objectnm'
AND I.owner='$schema'
ORDER BY
I.line";
echo "<H3>$objectnm</H3>\n";
exequery($qry);
}
function user_views() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm, $SID,$printqry,$schema;
$qry="
SELECT ";
if ( isset($objectnm) )
$qry .= " I.view_name \"Name\",\n I.text \"Code\" ";
else
$qry .= " '<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=$objecttype&printqry=$printqry&oper=srcdesc&objectnm='||I.view_name||'\">'||I.view_name||'</A>' \"Name\",\n I.text_length \"Code Size\" ";
$qry .= "
FROM
all_views I ";
if ( isset($objectnm) )
$qry .= " WHERE I.view_name = '$objectnm' AND I.owner='$schema'";
else
$qry .= " WHERE I.owner='$schema'";
$qry .= "ORDER BY I.view_name";
$desc = $ObjectDesc[$objecttype];
exequery($qry);
}
function user_synonyms() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm, $SID, $printqry,$schema;
$qry="
SELECT
I.synonym_name \"Synonym\",
O.status \"Status\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm='||I.TABLE_NAME||'\">'||
I.table_name||'</A>' \"Table\",
NVL(I.db_link,' ') \"DB Link\"
FROM
all_objects O, all_synonyms I
WHERE
O.object_name = I.synonym_name
AND
O.object_type = 'SYNONYM'
AND
O.OWNER='$schema'
AND
I.OWNER='$schema'
ORDER BY
I.synonym_name";
$desc = $ObjectDesc[$objecttype];
exequery($qry);
}
function user_sequences() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm, $SID, $printqry,$schema;
$qry="
SELECT
I.sequence_name \"Sequence\",
I.last_number \"Current\",
O.status \"Status\",
NVL(I.min_value,0) \"Min\",
NVL(I.max_value,0) \"Max\",
I.increment_by \"Incr.\",
DECODE(I.cycle_flag,'Y','Yes','No') \"Cycle\",
DECODE(I.order_flag,'Y','Yes','No') \"Order\",
I.cache_size \"Cache\"
FROM
all_objects O, all_sequences I
WHERE
O.object_name = I.sequence_name
AND
O.object_type = 'SEQUENCE'
AND
O.owner='$schema'
AND
I.sequence_owner='$schema'
ORDER BY
I.sequence_name";
$desc = $ObjectDesc[$objecttype];
exequery($qry);
}
function user_triggers() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm, $SID, $printqry,$schema;
$qry="
SELECT
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=$objecttype&printqry=$printqry&oper=srcdesc&objectnm='||I.trigger_name||'\">'||I.trigger_name||'</A>' \"Name\",
I.trigger_type \"Type\",
O.status \"Status\",
I.status \"Enabled\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm='||I.TABLE_NAME||'\">'||
I.table_name||'</A>' \"Table\",
I.triggering_event \"Trig Event\",
'<PRE>'||NVL(I.description,' ')||'</PRE>' \"Description\"
FROM
all_objects O, all_triggers I
WHERE
O.object_name = I.trigger_name
AND
O.object_type = 'TRIGGER'
AND
O.owner = '$schema'
AND
I.owner = '$schema'
ORDER BY
I.trigger_name";
$desc = $ObjectDesc[$objecttype];
exequery($qry);
}
function user_trig_desc() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm, $SID, $printqry,$schema;
$qry="
SELECT
I.trigger_body \"Code\"
FROM
user_triggers I
WHERE
I.trigger_name = '$objectnm'";
echo "<H3>$objectnm</H3>\n";
exequery($qry);
}
function user_indexes() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
if ( $objecttype == "INDEX" && isset($objectnm))
$qry ="SELECT * FROM user_indexes WHERE index_name='$objectnm' ";
else
$qry="
SELECT
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=INDEX&printqry=$printqry&objectnm='||index_name||'\">'||index_name||'</A>'
\"Name\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm='||table_name||'\">'||
table_name||'</A>' \"Table\",
column_name \"Column\",
column_length \"Column length\"
FROM
all_ind_columns
WHERE
index_owner = '$schema'
ORDER BY
column_position";
if ( $objecttype == "INDEX" && isset($objectnm)) {
echo "<H4>$objectnm</H4>\n";
}
exequery($qry);
}
function user_tables() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
$qry="
SELECT
table_name \"Name\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&oper=tabdesc&printqry=$printqry&objectnm='||TABLE_NAME||'\">X</A>' \"Desc\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&oper=tabidx&printqry=$printqry&objectnm='||TABLE_NAME||'\">X</A>' \"Indexes\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&oper=tabcons&printqry=$printqry&objectnm='||TABLE_NAME||'\">X</A>' \"Constraints\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&oper=tabtrig&printqry=$printqry&objectnm='||TABLE_NAME||'\">X</A>' \"Triggers\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&oper=tabgrant&printqry=$printqry&objectnm='||TABLE_NAME||'\">X</A>' \"Grants\",
'<A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&oper=tabstat&printqry=$printqry&objectnm='||TABLE_NAME||'\">X</A>' \"Stats\"
FROM all_tables ";
if ( $objectnm )
$qry .= " WHERE table_name = '$objectnm' AND owner='$schema'";
else
$qry .= " WHERE owner='$schema'";
$qry .= " ORDER BY 1";
exequery($qry);
}
function user_tab_desc() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
$qry = "
SELECT
I.column_name \"Column\",
I.data_type||'('||
decode(I.data_type,
'NUMBER',I.data_precision||','||I.data_scale
,I.data_length)||')' \"Data Type\",
I.nullable \"Null?\",
I.data_default \"Default\",
nvl(C.comments,' ') \"Comments\"
FROM
all_col_comments C, all_tab_columns I
WHERE
I.table_name='$objectnm'
AND
C.owner = '$schema'
AND
I.owner = '$schema'
AND
C.table_name=I.table_name
AND
C.column_name=I.column_name";
echo "<H3><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm=$objectnm\">$objectnm</A></H3>\n";
echo "<H4>Description</H4>\n";
exequery($qry);
}
function user_tab_idx() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
$qry="
SELECT
C.index_name \"Index\",
I.uniqueness \"Unique\",
C.column_name \"Column\",
C.column_position \"Position\"
FROM
all_ind_columns C, all_indexes I
WHERE
I.table_name='$objectnm'
AND
I.table_owner='$schema'
AND
I.index_owner='$schema'
AND
C.index_name = I.index_name
ORDER BY
C.index_name,
C.column_position";
echo "<H3><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm=$objectnm\">$objectnm</A></H3>\n";
echo "<H4>Indexes</H4>\n";
exequery($qry);
}
function user_tab_cons() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
$qry="
SELECT
C.constraint_name \"Constraint\",
decode(I.constraint_type,'C','Not Null',
'P', 'Primary Key',
'R', 'Referential',
'Unknown')
\"Type\",
C.column_name \"Column\",
C.position \"Position\",
I.status \"Status\"
FROM
all_cons_columns C, all_constraints I
WHERE
I.table_name='$objectnm'
AND
C.owner = '$schema'
AND
I.owner = '$schema'
AND
C.constraint_name = I.constraint_name
ORDER BY
C.constraint_name";
echo "<H3><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm=$objectnm\">$objectnm</A></H3>\n";
echo "<H4>Constraints</H4>\n";
exequery($qry);
}
function user_tab_stat() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
$qry="
SELECT *
FROM
all_tables I
WHERE
I.table_name='$objectnm'
AND I.owner='$schema'
ORDER BY 1";
echo "<H3><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm=$objectnm\">$objectnm</A></H3>\n";
echo "<H4>Stats</H4>\n";
exequery($qry);
}
function user_tab_grant() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
$qry="
SELECT
I.grantee \"Granted To\",
decode(I.select_priv,'Y','Yes', 'No') \"Select\",
decode(I.insert_priv,'Y','Yes', 'No') \"Insert\",
decode(I.delete_priv,'Y','Yes', 'No') \"Update\",
decode(I.update_priv,'Y','Yes', 'No') \"Delete\",
decode(I.references_priv,'Y','Yes', 'No') \"Refer.\",
decode(I.alter_priv,'Y','Yes', 'No') \"Alter\",
decode(I.index_priv,'Y','Yes', 'No') \"Index\",
I.grantor \"Granted By\"
FROM
all_tab_grants I
WHERE
I.table_name='$objectnm'
AND
I.owner='$schema'
ORDER BY 1";
echo "<H3><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm=$objectnm\">$objectnm</A></H3>\n";
echo "<H4>Grants</H4>\n";
exequery($qry);
}
function user_tab_trig() {
global $ObjectDesc,$objecttype,$PHP_SELF,$objectnm,$SID,$printqry,$schema;
$qry="
SELECT
I.trigger_name \"Trigger\",
I.trigger_type \"Type\",
O.status \"Status\",
I.status \"Enabled\",
I.triggering_event \"Trig Event\"
FROM
all_objects O, all_triggers I
WHERE
I.table_name='$objectnm'
AND
O.object_name = I.trigger_name
AND
O.owner = '$schema'
AND
I.owner = '$schema'
AND
O.object_type = 'TRIGGER'
ORDER BY
I.trigger_name";
echo "<H3><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&objecttype=TABLE&printqry=$printqry&objectnm=$objectnm\">$objectnm</A></H3>\n";
echo "<H4>Triggers</H4>\n";
exequery($qry);
}
/*
||
|| Main
||
*/
if ( $changeschema == "CHANGESCHEMA" ) {
change_schema() ;
} elseif (isset($objecttype)){
echo "<H2><A HREF=\"$PHP_SELF?schema=$schema&SID=$SID&printqry=$printqry&objecttype=$objecttype\">$ObjectDesc[$objecttype]</A></H2>\n";
} else {
echo "<H2>Instance Parameters</H2>\n";
$qry="SELECT name \"Parameter\", nvl(value,' ') \"Value\" from v\$parameter";
exequery($qry);
/*
echo "<H2>Memory(SGA) Parameters</H2>\n";
$qry="SELECT * from s_v\$sgastat";
exequery($qry);
*/
echo "<H2>Credits</H2>
<H3>Author</H3>
<P><A HREF=\"http://www.csoft.net/~vsbabu/\">Vattekkat Satheesh Babu</A> - <I>Released under <A HREf=\"http://www.gnu.org/copyleft/gpl.html\">GNU Public License</A></I></P>
<H3>Version History</H3>
<OL>
<LI><B>Aug 01, 1999</B> - Basic Browsing </LI>
<LI><B>Aug 03, 1999</B> - Sequence, Packages and Views </LI>
<LI><B>Nov 01, 1999</B> - Change schema </LI>
</OL>
<H3>Requirements</H3>
<OL>
<LI><A HREF=\"http://www.oracle.com\">Oracle</A> - with a logon with SELECT privileges on all_* tables</LI>
<LI><A HREF=\"http://www.php.net\">PHP</A> - with Oracle (ora_*) functions' support</LI>
<LI><A HREF=\"http://www.apache.org\">Apache</A> - wth PHP support :-)</LI>
</OL>\n";
}
if (!isset($orderby)) {
$orderby=1;
}
if ( $objecttype == "INDEX" ) user_indexes();
if ( $objecttype == "TRIGGER" ) {
if($oper=="srcdesc")
user_trig_desc();
else
user_triggers();
}
if ( $objecttype == "SYNONYM" ) user_synonyms();
if ( $objecttype == "SEQUENCE" ) user_sequences();
if ( ($objecttype == "PROCEDURE") ||
($objecttype == "FUNCTION" ) ||
($objecttype == "PACKAGE" ) ||
($objecttype == "PACKAGE BODY" )) {
if($oper=="srcdesc")
user_src_desc();
else
user_sources();
}
if ( $objecttype == "TABLE" ){
if ( !$objectnm )
user_tables();
else
if($oper=="tabdesc") user_tab_desc();
else if($oper=="tabidx") user_tab_idx();
else if($oper=="tabcons") user_tab_cons();
else if($oper=="tabtrig") user_tab_trig();
else if($oper=="tabgrant") user_tab_grant();
else if($oper=="tabstat") user_tab_stat();
else user_tables();
}
if ( $objecttype == "VIEW" ) {
user_views();
}
ora_logoff($conn);
?>
</TD>
</TR>
</TABLE>
<HR>
<? echo $sidebar; ?>
Since you are seeing this, it means that your browser does not support cascading style sheets. Please download and use one of the many browsers that support web standards.