⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbs

📁 Perl写的CA认证程序
💻
字号:
#!/usr/bin/perl## dbManager - (c) 1999 by Massimiliano Pala and OpenCA Group## All Rights Reserved#### Project Information:#### 	Current Version ..................... $VER##      Project Started on .................. 30/04/2000##      Last Modified on .................... 30 04/2000##      Project Closed on ................... n/a#### Program currently tested with Perl5 Linux, Solaris and Apache.#### DISC CLAIMER: THIS SOFTWARE IS GIVEN AS IS WITHOUT ANY WARRANTIES## ABOUT ANY DAMAGE DERIVED BY THE USE ( CORRECT OR NOT ) OF THIS## SOFTWARE. THE AUTHOR IS THEREFORE NOT RESPONSABLE IN ANY WAY OF## DAMAGES RELATED IN ANY WAY TO THIS OR SUPPORTED SOFTWARE AS WELL.#### If you want to contact me (the author) please use the e-mail## addresses listed below. Do not esitate in reporting bugs, enhancement## or anything seems useful in developing this software:####	madwolf@comune.modena.it##	madwolf@openca.org#### Thank you for using this software, and remember that Open Projects## are the future of mankind. Do not sleep, partecipate to world wide## efforts to make life easier for all!## Base requirementsrequire 5.001;## Version Release$VER = '0.0.31';$PRG = 'dBs Manager';@INC = ( @INC, "lib/" );## Modules to be installed to have this program to work properlyuse OpenCA::Configuration;use OpenCA::TRIStateCGI;## New OpenCA modulesuse OpenCA::OpenSSL;use OpenCA::X509;use OpenCA::CRL;use OpenCA::CRR;use OpenCA::Tools;use OpenCA::REQ;use OpenCA::PKCS7;## Functions Requirements## ======================require "crypto-utils.lib";require "misc-utils.lib";## require "solaris-utils.lib";## Now it's time to get the parameters passed over the weblocal $query  = new OpenCA::TRIStateCGI;## Generate a new reference to Configuration ( instance )local $config = new OpenCA::Configuration;local $dbiconfig = new OpenCA::Configuration;## Let's load our default configurationlocal $CONFIG = 'dBs.conf';local $DBICONFIG = 'DBI.conf';if( ($ret = $config->loadCfg( "$CONFIG" )) == undef ) {	print "Content-type: text/html\n\n";	configError( "Error while Loading Configuration ($CONFIG)!" );	exit 100;}## Flush the output$|=1;## Print the Content Type for Browserprint "Content-type: text/html\n\n";## Let's get the base Directorylocal ( $basedir ) = ( $ENV{'SCRIPT_FILENAME'} =~ /(.*)\/.*/ );local $self = $query->url(-query=>0,-full=>0); ## Init Section## ============local $shellPath = getRequired( 'openssl' );local $tmpdir    = getRequired( 'TempDir' );local $dbDir     = getRequired( 'dbDir' );local $sslcnf    = getRequired( 'sslconfig' );local $verify    = getRequired( 'VerifyPath' );local $sign      = getRequired( 'SignPath' );local $cryptoShell = new OpenCA::OpenSSL( SHELL => "$shellPath" );if ( not $cryptoShell ) {        configError( "Cannot initialize Crypto Shell ($shellPath)!" );        exit 1;}$cryptoShell->setParams( CONFIG=>"$sslcnf",			 TMPDIR=>"$tmpdir", 			 VERIFY=>"$verify",			 SIGN  =>"$sign", );			 ## STDERR=>"/dev/null" );local $tools = new OpenCA::Tools();if ( not $tools ) {        configError( "Cannot initialize OpenCA::Tools class!" );        exit 1;}####### inserted by michael bell for switch DBmodule #########local $db;if ( uc getRequired ('DBmodule') eq "DBI") {  ## use RDBMS  use OpenCA::DBI;  if( ($ret = $config->loadCfg( "$DBICONFIG" )) == undef ) {    print "Content-type: text/html\n\n";    configError( "Error while Loading Configuration ($DBICONFIG)!" );    exit 100;  }  $db = new OpenCA::DBI (                         SHELL          => $cryptoShell,                         mode           => $dbiconfig->getParam ('mode'),                         failsafe       => $dbiconfig->getParam ('failsafe'),                         second_chance  => $dbiconfig->getParam ('second_chance'),                         logsecurity    => $dbiconfig->getParam ('logsecurity'),                         logperformance => $dbiconfig->getParam ('logperformance'),                         SignLog        => $dbiconfig->getParam ('SignLog'),                         MESSAGEKEY     => $dbiconfig->getParam ('MESSAGEKEY'),                         MESSAGELENGTH  => $dbiconfig->getParam ('MESSAGELENGTH'),                         CERT_FILE      => $dbiconfig->getParam ('CERT_FILE'),                         KEY_FILE       => $dbiconfig->getParam ('KEY_FILE'),                         PASSWD         => $dbiconfig->getParam ('PASSWD'),                         DEBUG          => $dbiconfig->getParam ('DEBUG'),                         remoteType     => $dbiconfig->getParam ('remoteType'),                         remoteName     => $dbiconfig->getParam ('remoteName'),                         remoteHost     => $dbiconfig->getParam ('remoteHost'),                         remotePort     => $dbiconfig->getParam ('remotePort'),                         remoteUser     => $dbiconfig->getParam ('remoteUser'),                         remotePasswd   => $dbiconfig->getParam ('remotePasswd'),                         localType      => $dbiconfig->getParam ('localType'),                         localName      => $dbiconfig->getParam ('localName'),                         localHost      => $dbiconfig->getParam ('localHost'),                         localPort      => $dbiconfig->getParam ('localPort'),                         localUser      => $dbiconfig->getParam ('localUser'),                         localPasswd    => $dbiconfig->getParam ('localPasswd')                         );  if ( not $db ) {    configError( "Cannot initialize OpenCA::DBI class! ($dbDir)" );    exit 1;  }  $versions->{DB} 		= OpenCA::DBI->VERSION;} else {  ## use DBM-files - this is the default  use OpenCA::DB;  $db = new OpenCA::DB( SHELL=>$cryptoShell, DB_DIR=>"$dbDir" );  if ( not $db ) {    configError( "Cannot initialize OpenCA::DB class! ($dbDir)" );    exit 1;  }  $versions->{DB} 		= OpenCA::DB->VERSION;}## end of different parts of OpenCA::DB and DBI the rest shoud be compatible## Main Section## ============local $cmd = $query->param('cmd');if ( "$cmd" eq "" ) {	configError("Command Error (Command Missing)");	exit 101;}if( $cmd =~ /dbStatus/ ) {		## Try to report status of dB.	my $dataType = $query->param('dataType');	configError( "Missing dB selection!") if ( not $dataType );	print startLogPage( "OpenCA dB Status Report" );	my @cols;        push( @cols, "Variable" );        push( @cols, "Value" );        print $query->startTable( COLS=>[ @cols ],                                     WIDTH=>"80%",				     TABLE_BGCOLOR=>"#000000",                                     TITLE_BGCOLOR=>"#DDCCFF" );	my $date     = $tools->getDate();	my $stimated = ( $db->elements( DATATYPE=>$dataType ) or "0" );	my $realElem = $db->rows( DATATYPE=>$dataType );	my $status   = $db->getItem( DATATYPE=>$dataType, KEY=>STATUS );	my $modified = $db->getItem( DATATYPE=>$dataType, KEY=>MODIFIED );	my $init     = $db->getItem( DATATYPE=>$dataType, KEY=>INIT );	my $nextItem = $db->getItem( DATATYPE=>$dataType, KEY=>SERIAL );	my $lastItem = $db->getItem( DATATYPE=>$dataType, KEY=>LAST );	my $deleted  = $db->getItem( DATATYPE=>$dataType, KEY=>DELETED );	if( $realElem ne $stimated ) {		$stimated = "<FONT color=\"Red\">$stimated</FONT>";	}	print $query->addTableLine( DATA=>[			"Stimated Elements:", $stimated ],			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Real Elements Number:", $realElem ], 			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Last Item:", ( $lastItem or "n/a" ) ], 			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Deleted Items:", ( $deleted or "n/a" ) ], 			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Datatype of contained elements:", $dataType ],			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Initiated:", ( $init or "n/a" ) ],			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Last Modified:", ( $modified or "n/a" ) ],			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Current Status:", ( "$status" or "n/a" ) ],			COLOR=>"#000000" );	print $query->addTableLine( DATA=>[			"Next Item ID:", ( $nextItem or "n/a" ) ],			COLOR=>"#000000" );	print $query->endTable();	print closeLogPage();	exit;}if( $cmd =~ /importReqs|importCerts|importCRLs|importCRRs/ ) {	## GNU Tar required for importing Certification Request	## to the CA. We use the GNU tar because of its availability	## for all the platforms and its stability.	print $query->start_html(-title=>"Requests Exporting Page",                                 -BGCOLOR=>"#FFFFFF",				 -TEXT=>"#445599" );	## Get required parameters from the configuration file	my $cmd  = getRequired( 'UnpackArchive' );	my $orig = getRequired( 'ImportDev' );	my $dir  = getRequired( 'NewReqsDir' );	$cmd = $query->subVar( $cmd, '$orig', $orig );	$cmd = $query->subVar( $cmd, '$dest', $dir );		configError( "Configuration error (check UnpackArchive " .		     "ImportDev and NewReqsDir keywords).")		if( (not $cmd) or (not $orig) or (not $dir) );	print startLogTable("Importing Data");        print "</CENTER>";        print "<FONT SIZE=+1><UL><OL><FONT FACE=\"Arial, Helvetica\">\n";	print closeLogPage();	exit;	print "Importing Requests Files .... ";	my $ret = `$cmd 2>&1`;	if( $? != 0 ) {		print "<BR><BR>Importing Requests Failed from $orig!<BR><BR>\n";		print "<UL><TT><FONT SIZE=-1 COLOR=red>";		print "<PRE>$ret</PRE></FONT></TT></UL>\n";		print "</OL></UL>\n";		closePage();		exit;	} 	print "Ok.<BR>\n";	print "<UL><TT><FONT SIZE=-1>";	print "<PRE>$ret</PRE></FONT></TT></UL>\n";	print "</OL></UL>\n";	print "</PRE></FONT></TT></UL>\n";        print "<FONT SIZE=+1><UL><OL><FONT FACE=\"Arial, Helvetica\">\n";	print "Importing Requests to dB .... ";	opendir( REQS, "$dir" );		my @reqsList = grep( /^[a-f0-9]+.req/i, readdir( REQS ) );	closedir( REQS );	$ret = "";	foreach $tmpReq (@reqsList) {		my $fileName = "$dir/$tmpReq";		my $data = new OpenCA::REQ( SHELL=>$cryptoShell,					    INFILE=>"$fileName" );		if ( not $db->storeItem( DATATYPE=>PENDING_REQUEST,					 DATA=>$data->{req} ) ) {			print "<BR><BR><FONT SIZE=-1 COLOR=red>";			print "Failed adding request to dB!</FONT><BR><BR>\n";                	print "</OL></UL>\n";                	closePage();                	exit;		} else {			unlink( "$fileName" );		}		$ret .= "Added <I>" . $data->getParsed()->{CN} .		        " (" . $data->getParsed->{EMAIL} . ")</I><BR>\n";	}	print "Ok.<BR>";	print "<UL><FONT SIZE=-1><BR>";	print "$ret</FONT></UL>\n";	print "</OL></UL>\n";	print "</PRE></FONT></TT></UL>\n";	print "</OL></UL></FONT>\n";	closePage();	exit 0;}if( $cmd =~ /^exportDB/i ) {        ## GNU Tar suggested for exporting Issued Certificates        ## to the CA. We use the GNU tar because of its availability        ## for all the platforms and its stability.        print $query->start_html(-title=>"Certificates Exporting Page",                                 -BGCOLOR=>"#FFFFFF");        ## Get required parameters from the configuration file        my $cmd  = getRequired( 'CreateArchive' );        my $test = getRequired( 'TestArchive' );        my $dest = getRequired( 'ExportDev' );        my $dir  = getRequired( 'CertsDir' );	## Build the right $cmd with substitution of the $dest	## with the 'ExportDest' and in 'TestArchive'	$cmd  = $query->subVar( $cmd, '$dest', $dest );	$test = $query->subVar( $test, '$dest', $dest );        print "<FONT SIZE=+3><CENTER>";        print "Please wait while processing dbExporting.<BR>\n";        print "(Fully detailed LOG following)<BR>\n";        print "<HR WIDTH=80%>";        print "</CENTER></FONT>";        print "<FONT SIZE=+1><UL><OL><FONT FACE=\"Arial, Helvetica\">\n";	## Exit now!	exit 0;        print "Certificate Exporting .... ";        $ret = `cd $dir; $cmd *.pem 2>&1`;        if( $? != 0 ) {                print "<BR><BR>Archiving Failed on $dest!<BR><BR>\n";                print "<UL><TT><FONT SIZE=-1 COLOR=red>";                print "<PRE>$ret</PRE></FONT></TT></UL>\n";                print "</OL></UL>\n";                closePage();                exit;        }        print "Ok.<BR>\n";        print "<UL><TT><FONT SIZE=-1 COLOR=#445567>";        print "<PRE>$ret</PRE></FONT></TT></UL>\n";        print "Testing Created Archive ... ";        $ret = `$test 2>&1`;        if( $? != 0 ) {                print "<BR><BR>Check Failed on $dest!<BR><BR>\n";                closepage();                exit;        } else {                print "Ok.<BR>";        }        print "<UL><TT><FONT SIZE=-1 COLOR=#445567><PRE>";        print "$ret</PRE></FONT></TT></UL>\n";        print "Removing Temporary Files .... ";        ## Now Let's Open the Directory        opendir ( CERTS , "$dir" ) || die "Directory NOT found $dir!\n";                @certsList = grep(/pem/, readdir( CERTS ) );        closedir( CERTS );        print "<UL><TT><FONT SIZE=-1 COLOR=#445567><PRE>";        foreach $file ( @certsList ) {		$cmd=`/bin/cp $dir/$file $cdir 2>&1`;                unlink( "$dir/$file" );                print "Deleted $dir/$file\n";        }        print "</PRE></FONT></TT></UL>\n";        print "</OL></UL>\n";        closePage();        exit 0;}if ( $cmd =~ /^emptyDB/i ) {	my $dataType = $query->param('dataType');	my ( $item, @itemList );	if( not $dataType ) {		generalError ( "Data Type not provided!" );		exit 0;	}	@itemList = $db->searchItem( DATATYPE=>$dataType );	foreach $item (@itemList) {		if ( not $db->deleteItem( DATATYPE=>$dataType,				  KEY=>$item->{KEY} ) ) {			generalError ("Error while removing Item from $dataType dB!");		}	}	success("Items Removed", "Deleted Request dB is now Empty");	exit;}	## No Valid Command has been given if you reach this pointprint $query->start_html(-title=>"Administration Error",		-BGCOLOR=>"#FFFFFF");print "<CENTER><BR><HR WIDTH=80%><BR></CENTER>";print "<OL><OL><H1><FONT COLOR=red>Error 700 </FONT></H1>";print "<OL>Command $cmd Not Supported ( yet ?!? ).</OL></OL></OL>";closePage();exit 0;## Subroutines Section : main subroutines are the createTable wich ## creates the base Table with the main row ( with Descriptions ),## the addFile wich adds a Row with the File description and date of## creations and so on, and the subVars ehich substitutes the variables## name contained in the $page var with their correct values.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -