Gossamer Forum
Home : Products : DBMan : Customization :

Database selector

Quote Reply
Database selector
Here is a hack of the Database Manager which removes the create and delete functionality. It simply searches for .cfg files and displays a link to each database.

#!/usr/bin/perl
##########################################################################
# PROGRAM dbselect
##########################################################################
#This is a hack of the following program:
##########################################################################
# PROGRAM dbconfig
# VERSION 1.0
# DATE 24.07.99
# AUTHOR Patrick Erler
# EMAIL perler@dresden-online.com
# COMPANY
# PURPOSE database-manager for dbman. lists, creates deletes databases
# INCLUDED LIBRARY FILES
#use strict;
use CGI;
$dbconfig=new CGI;
$db_script_path = "./";
##########################################################################
# FUNCTION DECLARATIONS
# Todo: To provide proper modularity within this program, do everything
# in functions rather than globally, and declare all functions here.

sub Main;
sub ListDB;
##########################################################################
# PROGRAM ENTRANCE
Main;
##########################################################################
# FUNCTION DEFINITIONS
#-------------------------------------------------------------------------
# FUNCTION Main
# RECEIVES None
# RETURNS None
# EXPECTS None
# SETS None
# DOES This is the program's main function
sub Main {
#top of menu
print "Content-type: text/html\n\n";
print
qq!


<HTML><HEAD><TITLE>DBman: database-selector</TITLE></HEAD>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr>
<td colspan=1 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>DBman: database-selector</b>
</FONT>
</td>
</tr>
<tr>
<td>
<p>
<center>
<font face="verdana,arial,helvetica" size="4">
<b> Database Selector </b>
</font>
</center>

<center>
!;


ListDB;
print "</table>\n";
print "</center>\n";
print "</BODY></HTML>\n";

#-------------------------------------------------------------------------
# FUNCTION ListDB
# RECEIVES
# RETURNS
# EXPECTS
# SETS
# DOES upper part of menu, lists all Databases by searching the current
# directory for .cfg-files
sub ListDB
{
opendir(DIR, "$db_script_path");
@files = grep(/\.cfg$/,readdir(DIR));
closedir(DIR);

foreach $file (@files)
{
#don't show the template-database
unless ($file eq 'template.cfg')
{
#save the name of the.cfg file for the HREF
$cfgfile=$file;
$cfgfile=~s/\.cfg//g;
#reads in line by line, finds the line with the displayname and strips it out
#of the line for the menu
open (GETSTANDORT, "<$db_script_path/$file");
while (<GETSTANDORT>)
{if (/\$db_name/)
{
$_=~s/\$db_name\ = \'//g;
$_=~s/\'\;//g;
print qq!<A href="db.cgi?db=$cfgfile">$_</A>
!;
}
}
close (GETSTANDORT);
}
}

}

}