📄 exportconfig
字号:
## OpenCA - CA Command## (c) 2001 by Michael Bell and OpenCA Group#### File Name: exportConfig## Brief: exports complete configuration## Description: export the following data## * RBAC/## * extfiles/## * OpenSSL/## * openssl.cnf## * table RBAC from DB## Parameters: my $cmdName = "exportConfig";if ( $cmd !~ /$cmdName/i ) { configError( "Wrong Command Usage ($cmd over $cmdName)!" ); exit 1;}## 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.## Get required parameters from the configuration filemy $creat = getRequired( 'CreateArchive' );my $test = getRequired( 'TestArchive' );my $dest = getRequired( 'ExportDev' );my $cadir = getRequired( 'OpencaDir' );my $tmp = getRequired( 'TempDir' );my $openssl = getRequired ( 'sslconfig' );my $rbac_dir = getRequired ( 'RBAC_DIR' );my $openssl_dir = getRequired ( 'OPENSSL_DIR' );my $ext_dir = getRequired ( 'EXT_DIR' );my $config_dir = $rbac_dir;$config_dir =~ s/\/[^\/]*$//;$rbac_dir =~ s/^.*\///g;$openssl_dir =~ s/^.*\///g;$ext_dir =~ s/^.*\///g;my ( @lastExport );## Build the right $cmd with substitution of the $dest## with the 'ExportDest' and in 'TestArchive'my $arc = $query->subVar( $creat, '$dest', $dest );my $test = $query->subVar( $test, '$dest', $dest );print startLogPage("RBAC Exporting" );## create new tmp-dirprint addLogSection("Create Temporary Directory ... ");$tmpdir = $tmp."/RBAC_".$$;if( not mkdir( "$tmpdir", 0700 )) { print addErrorLog( "Failed creating dir $tmpdir" ); closePage(); exit 1;}if( not chdir( "$tmpdir" )) { print addErrorLog( "Failed changing dir to $tmpdir" ); closePage(); exit 1;}print addLogLine( "Ok." );print closeLogSection ();## bring acl into tmp-dirprint addLogSection("Exporting Roles to $tmpdir ... ");my @roles = $db->searchItems (DATATYPE => "RBAC");my $i = 0;my $role;my $tools = new OpenCA::Tools;foreach $role (@roles) { $tools->saveFile (FILENAME => "rbac_".$i.".txt", DATA => $role->getParsed()->{ITEM} ); $i++;}print addLogLine( "Ok." );print closeLogSection ();## bring openssl.cnf to tmp-dirprint addLogSection("Copying $openssl to $tmpdir ... ");$ret = `cp $openssl . 2>&1`;if( $? != 0 ) { print addErrorLog("Cannot copy $openssl to $tmpdir!"); print addLogLine( "cp $openssl ." ); closePage(); exit 1;}print addLogLine( "Ok." );print addPreLogLine( $ret );print closeLogSection ();## bring RBAC/ to tmp-dirprint addLogSection("Copying $rbac_dir to $tmpdir ... ");$ret = `cd $config_dir; tar -c $rbac_dir | tar -x -C $tmpdir 2>&1`;if( $? != 0 ) { print addErrorLog("Cannot copy $rbac_dir to $tmpdir!"); print addLogLine( "cd $config_dir; tar -c $rbac_dir | tar -x -C $tmpdir" ); closePage(); exit 1;}print addLogLine( "Ok." );print addPreLogLine( $ret );print closeLogSection ();## bring OpenSSL/ to tmp-dirprint addLogSection("Copying $openssl_dir to $tmpdir ... ");$ret = `cd $config_dir; tar -c $openssl_dir | tar -x -C $tmpdir 2>&1`;if( $? != 0 ) { print addErrorLog("Cannot copy $openssl_dir to $tmpdir!"); print addLogLine( "cd $config_dir; tar -c $openssl_dir | tar -x -C $tmpdir" ); closePage(); exit 1;}print addLogLine( "Ok." );print addPreLogLine( $ret );print closeLogSection ();## bring extfiles/ to tmp-dirprint addLogSection("Copying $ext_dir to $tmpdir ... ");$ret = `cd $config_dir; tar -c $ext_dir | tar -x -C $tmpdir 2>&1`;if( $? != 0 ) { print addErrorLog("Cannot copy $ext_dir to $tmpdir!"); print addLogLine( "cd $config_dir; tar -c $ext_dir | tar -x -C $tmpdir" ); closePage(); exit 1;}print addLogLine( "Ok." );print addPreLogLine( $ret );print closeLogSection ();print addLogSection("Creating archive ... ");$ret = `$arc * 2>&1`;if( $? != 0 ) { print addErrorLog("Archiving Failed to $dest!"); print addLogLine( "$arc" ); closePage(); exit 1;}print addLogLine( "Ok." );print addPreLogLine( $ret );print closeLogSection();print addLogSection("Testing Created Archive ... ");$ret = `$test 2>&1`;if( $? != 0 ) { print addErrorLog("Check Failed on $dest!"); closePage(); exit;}print addLogLine( "Ok." );print addPreLogLine( $ret );print closeLogSection();print addLogSection ("Removing Temporary Files ... ");if( not chdir( "$tmp" )) { print addErrorLog( "Failed changing dir to $tmp." ); closePage(); exit 1;}if ( length ($tmpdir) < 7 ) { print addErrorLog("Stopping removing because $tmpdir is shorter then 7 characters!"); closePage(); exit 1;}$ret = `rm -rf $tmpdir 2>&1`;if( $? != 0 ) { print addErrorLog("Removing Failed for $tmpdir!"); print addLogLine( "rm -rf $tmpdir" ); closePage(); exit 1;}print addLogLine( "Ok." );print addPreLogLine( $ret );print closeLogSection();closePage();1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -