DBIforms is a set of perl scripts that provides a fast and easy mechanism to generate HTML forms to manipulate database information. These scripts are based on the Perl DBI module and can be implemented using any database backend for which there is a corresponding Perl DBD module.
The concept behind DBIforms is to provide 5 basic database functions:
The generation of reports from the data in the database is considered outside the scope of this effort and is not addressed by these functions. However, the search function assumes a custom reporting script has been created by the implementor of DBIforms and is used to display the results of the search request. More about that later in this document.
DBIforms stores it's own configuration information in the database and must be added before other implementations can be generated. To create an implementation of DBIforms, perform the following steps:
$ENV{LD_LIBRARY_PATH} = "/usr/i486-linux-libc5/lib:\ /usr/local/openlink/lib:\ /usr/local/lib"; $ENV{DBI_DSN} = "DBI:Sybase:CMDBDEVL"; # DSN $ENV{DBI_USER} = "cmdbadm"; # Database user name $ENV{DBI_PASS} = "configadm"; # Database user password $ENV{LD_LIBRARY_PATH} = "/usr/local/lib:/usr/i486-linux-libc5/lib"; $ENV{DD_CGIBIN} = "/usr/local/httpd/cgi-bin/CMDB02"; # Full path dir $ENV{DD_HTDOCS} = "/usr/local/httpd/htdocs/CMDB02"; # Full path dir
./mkinputpages.pl ./mkinputlines.pl
Error messages may be displayed the first time each script is executed because the script first drops, then creates the tables it uses. Since the first time the script is executed, the tables don't exist, an error is reported when dropping the tables. On any subsequent execution of the script no errors should be reported.
#!/usr/bin/perl -X ################################################################ # Program: mkSERVERlines.pl # Copyright (c) 2003 by Dana French # All Rights Reserved # # Description: Creates example form with input lines # # Author: Dana French (dfrench@mtxia.com) # # Date: 02/15/2003 # ################################################################ sub mkrecord() { print "Working on ${LINENAME}\n"; $sth = $dbh->do("delete from INPUTLINES4 WHERE LINENAME = '${LINENAME}'"); $sql = "insert into INPUTLINES4 ( LINENAME, INPUTNAME, INPUTPROMPT, INPUTTYPECGI, INPUTVALUE, INPUTHELP, TABLENAME, FIELDNAME, INPUTTYPESQL, HEIGHT, WIDTH, SELECTED, MULTIPLE, REQUIRED ) VALUES ( '${LINENAME}', '${INPUTNAME}', '${INPUTPROMPT} ', '${INPUTTYPECGI}', '${INPUTVALUE} ', '${INPUTHELP} ', '${TABLENAME}', '${FIELDNAME}', '${INPUTTYPESQL}', '${HEIGHT} ', '${WIDTH} ', '${SELECTED} ', '${MULTIPLE} ', '${REQUIRED} ' )"; $sth = $dbh->do($sql); } ################################################################ sub mkformline() { $sth = $dbh->do("delete from FORMLINES4 WHERE LINENAME = '${LINENAME}'"); $sql = "insert into FORMLINES4 ( FORMNAME, LINENAME, POSITIONID ) VALUES ( '${FORMNAME}', '${LINENAME}', '${POSITIONID}' )"; $sth = $dbh->do($sql); } ################################################################ use DBI; $|=1; do 'DS_DBIforms.pl'; # my ($sth); # my ($sth2); # my ($sth3); # my ($sql); $dbh = DBI->connect() ; $sth = $dbh->do("delete from INPUTPAGE4 WHERE FORMNAME = 'SERVER02'"); $sth = $dbh->do("insert into INPUTPAGE4 ( FORMNAME, PAGE_TITLE, CONTACT_NAME, CONTACT_EMAIL, CLR_PAGEBG, CLR_LINK, CLR_ALINK, CLR_VLINK, CLR_TDBG, CLR_THBG, CLR_BASEFONT, CLR_THFONT, CLR_TDFONT, SIZ_BASEFONT, SIZ_THFONT, SIZ_TDFONT, CELLSPACING, CELLPADDING, PRETABLE_SCRIPT, POSTTABLE_SCRIPT, FORM_ACTION, FORM_METHOD ) VALUES ( 'SERVER02', 'Servers', 'Dana French', 'dfrench\@mtxia.com', 'white', 'blue', 'yellow', 'red', '#62BCC6', '#211F5C', 'black', 'red', 'black', '4', '4', '3', '0', '5', 'SERVER02_pretable.pl', 'SERVER02_posttable.pl', '', 'POST' )"); ################################################################ # Input lines for form server02 ################################################################ ${LINENAME} = 'server02_frameid'; ${INPUTNAME} = 'SERVER02_FRAMEID'; ${INPUTPROMPT} = 'FRAME ID Number'; ${INPUTTYPECGI} = 'dynamicReference:Frame02:name:id'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the associated FRAME ID Number for this server'; ${TABLENAME} = 'KEY'; ${FIELDNAME} = 'frame_id'; ${INPUTTYPESQL} = 'int'; ${HEIGHT} = '8'; ${WIDTH} = '8'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '0'; &mkrecord; ${LINENAME} = 'server02_name'; ${INPUTNAME} = 'SERVER02_NAME'; ${INPUTPROMPT} = 'Server Name'; ${INPUTTYPECGI} = 'text'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the name of this server'; ${TABLENAME} = 'KEY'; ${FIELDNAME} = 'name'; ${INPUTTYPESQL} = 'varchar(64)'; ${HEIGHT} = '32'; ${WIDTH} = '64'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '1'; &mkrecord; ${LINENAME} = 'server02_hostname'; ${INPUTNAME} = 'SERVER02_HOSTNAME'; ${INPUTPROMPT} = 'Host Name'; ${INPUTTYPECGI} = 'text'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the host name of this server'; ${TABLENAME} = 'Server02'; ${FIELDNAME} = 'hostname'; ${INPUTTYPESQL} = 'varchar(64)'; ${HEIGHT} = '32'; ${WIDTH} = '64'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '1'; &mkrecord; ${LINENAME} = 'server02_managename'; ${INPUTNAME} = 'SERVER02_MANAGENAME'; ${INPUTPROMPT} = 'Management Name'; ${INPUTTYPECGI} = 'text'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the systems management name of this server'; ${TABLENAME} = 'Server02'; ${FIELDNAME} = 'managename'; ${INPUTTYPESQL} = 'varchar(64)'; ${HEIGHT} = '32'; ${WIDTH} = '64'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '1'; &mkrecord; ${LINENAME} = 'server02_osname'; ${INPUTNAME} = 'SERVER02_OSNAME'; ${INPUTPROMPT} = 'Server OS Name'; ${INPUTTYPECGI} = 'text'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the name of the Operating System running on this server'; ${TABLENAME} = 'Server02'; ${FIELDNAME} = 'osname'; ${INPUTTYPESQL} = 'varchar(64)'; ${HEIGHT} = '32'; ${WIDTH} = '64'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '0'; &mkrecord; ${LINENAME} = 'server02_osversion'; ${INPUTNAME} = 'SERVER02_OSVERSION'; ${INPUTPROMPT} = 'Server OS Version'; ${INPUTTYPECGI} = 'text'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the version of the Operating System running on this server'; ${TABLENAME} = 'Server02'; ${FIELDNAME} = 'osversion'; ${INPUTTYPESQL} = 'varchar(32)'; ${HEIGHT} = '32'; ${WIDTH} = '32'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '0'; &mkrecord; ${LINENAME} = 'server02_oslevel'; ${INPUTNAME} = 'SERVER02_OSLEVEL'; ${INPUTPROMPT} = 'Server OS Level'; ${INPUTTYPECGI} = 'text'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the maintenance level of the Operating System running on this server'; ${TABLENAME} = 'Server02'; ${FIELDNAME} = 'oslevel'; ${INPUTTYPESQL} = 'varchar(32)'; ${HEIGHT} = '32'; ${WIDTH} = '64'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '0'; &mkrecord; ${LINENAME} = 'server02_foserver'; ${INPUTNAME} = 'SERVER02_FOSERVER'; ${INPUTPROMPT} = 'FailOver Server'; ${INPUTTYPECGI} = 'text'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the name of the failover server'; ${TABLENAME} = 'Server02'; ${FIELDNAME} = 'failoverserver'; ${INPUTTYPESQL} = 'varchar(64)'; ${HEIGHT} = '32'; ${WIDTH} = '64'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '0'; &mkrecord; ${LINENAME} = 'server02_servicedesk'; ${INPUTNAME} = 'SERVER02_SERVICEDESK'; ${INPUTPROMPT} = 'Service Desk Group'; ${INPUTTYPECGI} = 'dynamicSelect'; ${INPUTVALUE} = ''; ${INPUTHELP} = 'Enter the name of the service desk group'; ${TABLENAME} = 'Server02'; ${FIELDNAME} = 'servicedeskgroup'; ${INPUTTYPESQL} = 'varchar(30)'; ${HEIGHT} = '30'; ${WIDTH} = '30'; ${SELECTED} = '0'; ${MULTIPLE} = '0'; ${REQUIRED} = '0'; &mkrecord; ################################################################ # Associate input lines with a form ################################################################ ${FORMNAME} = 'SERVER02'; $sth = $dbh->do("delete from FORMLINES4 WHERE FORMNAME = '${FORMNAME}'"); ${LINENAME} = 'server02_frameid'; ${POSITIONID} = '1'; &mkformline; ${LINENAME} = 'server02_name'; ${POSITIONID} = '2'; &mkformline; ${LINENAME} = 'server02_hostname'; ${POSITIONID} = '3'; &mkformline; ${LINENAME} = 'server02_managename'; ${POSITIONID} = '4'; &mkformline; ${LINENAME} = 'server02_osname'; ${POSITIONID} = '5'; &mkformline; ${LINENAME} = 'server02_osversion'; ${POSITIONID} = '6'; &mkformline; ${LINENAME} = 'server02_oslevel'; ${POSITIONID} = '7'; &mkformline; ${LINENAME} = 'server02_foserver'; ${POSITIONID} = '8'; &mkformline; ${LINENAME} = 'server02_servicedesk'; ${POSITIONID} = '9'; &mkformline; $dbh->disconnect();
/usr/local/httpd/cgi-bin/CMDB02/mkSERVERlines.pl
#!/usr/bin/perl -X ################################################################ # Program: reportSERVER02.pl # Copyright (c) 2003 by Dana French # All Rights Reserved # # Description: Allows user to search records in database # # Author: Dana French (dfrench@mtxia.com) # # Date: 11/12/2003 # ################################################################ use DBI; $|=1; @script_file = split(/\//, $ENV{SCRIPT_NAME} ); do 'DS_DBIforms.pl'; do 'SUB_DBIforms.pl'; $dbh = DBI->connect() ; &cgiParse; &selectInputPage; ${FORMNAME}="SERVER02"; $titlebar1 = "Configuration Management"; $titlebar2 = "Server02 Report"; &header; &staticbar; &titlebar; $menuarray{0} = { "prompt" => "Insert ${FORMNAME}", "url" => "/cgi-bin/CMDB02/insert.pl?FORMNAME=${FORMNAME}" }; $menuarray{1} = { "prompt" => "Modify ${FORMNAME}", "url" => "/cgi-bin/CMDB02/update.pl?FORMNAME=${FORMNAME}" }; $menuarray{2} = { "prompt" => "Delete ${FORMNAME}", "url" => "/cgi-bin/CMDB02/delete.pl?FORMNAME=${FORMNAME}" }; $menuarray{3} = { "prompt" => "View ${FORMNAME}", "url" => "/cgi-bin/CMDB02/select.pl?FORMNAME=${FORMNAME}" }; print "<P><UL>\n"; ${WHERECLAUSE} = "WHERE"; if ( "_${SERVER02_FRAMEID}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND frame_id = '${SERVER02_FRAMEID}'"; } if ( "_${SERVER02_NAME}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND name LIKE '%${SERVER02_NAME}%'"; } if ( "_${SERVER02_HOSTNAME}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND hostname LIKE '%${SERVER02_HOSTNAME}%'"; } if ( "_${SERVER02_MANAGENAME}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND managename LIKE '%${SERVER02_MANAGENAME}%'"; } if ( "_${SERVER02_OSNAME}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND osname LIKE '%${SERVER02_OSNAME}%'"; } if ( "_${SERVER02_OSVERSION}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND osversion LIKE '%${SERVER02_OSVERSION}%'"; } if ( "_${SERVER02_OSLEVEL}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND oslevel LIKE '%${SERVER02_OSLEVEL}%'"; } if ( "_${SERVER02_BUSINESSUNIT}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND businessunit LIKE '%${SERVER02_BUSINESSUNIT}%'"; } if ( "_${SERVER02_FOSERVER}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND failoverserver LIKE '%${SERVER02_FOSERVER}%'"; } if ( "_${SERVER02_SERVICEDESK}" ne "_" ) { ${WHERECLAUSE} = "${WHERECLAUSE} AND servicedeskgroup LIKE '%${SERVER02_SERVICEDESK}%'"; } ${WHERECLAUSE} = "" if ( "_${WHERECLAUSE}" eq "_WHERE" ); ${WHERECLAUSE} =~ s/WHERE AND/WHERE/; ################################################################ ${sql_statement} = "SELECT COUNT(*) FROM Server02 ${WHERECLAUSE}"; $sth0 = $dbh->prepare($sql_statement); $sth0->execute; if ($DBI::err) { print STDOUT $DBI::errstr,"\n"; last; } my $count_name = $sth0->{NAME}; while (@countresults = $sth0->fetchrow_array) { if ($DBI::err) { print STDOUT $DBI::errstr,"\n"; last; } foreach $field_name (@$count_name) { ${servercount} = shift @countresults; } } print "Server Records found: ${servercount}<BR>\n"; ################################################################ if ( ${servercount} > 0 ) { ${sql_statement} = "SELECT DISTINCT id, name FROM Server02 ${WHERECLAUSE} ORDER BY name "; print "${sql_statement}<BR>\n"; $sth99 = $dbh->prepare($sql_statement); $sth99->execute; if ($DBI::err) { print STDOUT $DBI::errstr,"\n"; last; } my $emp_name = $sth99->{NAME}; ${rowcount} = 0; while (@results = $sth99->fetchrow_array) { if ($DBI::err) { print STDOUT $DBI::errstr,"\n"; last; } foreach $field_name (@$emp_name) { ${${field_name}} = shift @results; } ++${rowcount}; if ( ${CSV} != 1) { print "</UL></P><P><HR></P><P><UL>\n"; print "<P><LI> <STRONG>Server Name:</STRONG> ${name}\n"; print " <STRONG>Record ID:</STRONG> ${id}</LI></P>\n"; } ${sql_statement} = "SELECT * FROM Server02 WHERE id = '${id}' ORDER BY id, name"; $sth1 = $dbh->prepare($sql_statement); $sth1->execute; if ($DBI::err) { print STDOUT $DBI::errstr,"\n"; last; } my $emp_name = $sth1->{NAME}; if ( ${CSV} == 1 && ${rowcount} == 1 ) { print "<P><HR></P>\n"; foreach $field_name (@$emp_name) { print "${field_name}, "; } print "<BR>\n"; } while (@results = $sth1->fetchrow_array) { if ($DBI::err) { print STDOUT $DBI::errstr,"\n"; last; } foreach $field_name (@$emp_name) { ${${field_name}} = shift @results; if ( ${CSV} == 1) { print "${${field_name}}, "; } } if ( ${CSV} == 1 ) { print "<BR>\n"; next; } print "<UL>\n"; print "<LI>\n"; print " <STRONG>Frame ID:</STRONG> ${frame_id}<BR>\n"; print " <STRONG>Host Name</STRONG> ${hostname}<BR>\n"; print " <STRONG>Management Name</STRONG> ${managename}<BR>\n"; print " <STRONG>OS Name</STRONG> ${osname}<BR>\n"; print " <STRONG>OS Version:</STRONG> ${osversion}<BR>\n"; print " <STRONG>OS Level:</STRONG> ${oslevel}<BR>\n"; print " <STRONG>Business Unit:</STRONG> ${businessunit}<BR>\n"; print " <STRONG>Failover Server:</STRONG> ${failoverserver}<BR>\n"; print " <STRONG>Service Desk Group:</STRONG> ${servicedeskgroup}<BR>\n"; print "</LI>\n"; print "</UL>\n"; } } } print "</UL></P>\n"; &footer; $dbh->disconnect();
grant select,insert,update,delete,index,alter,create,drop,reload,shutdown,process,file on CMDBDEVL.* to wwwrun@eperf identified by 'password for wwwrun' with grant option; grant select,insert,update,delete,index,alter,create,drop,reload,shutdown,process,file on CMDBDEVL.* to wwwrun@eperf.tu.com identified by 'password for wwwrun' with grant option; grant select,insert,update,delete,index,alter,create,drop,reload,shutdown,process,file on CMDBDEVL.* to wwwrun@localhost identified by 'password for wwwrun' with grant option;