diff -Nru haci-0.97c/bin/checkPerlDependencies.bash haci-0.98c/bin/checkPerlDependencies.bash --- haci-0.97c/bin/checkPerlDependencies.bash 2010-02-24 03:29:58.000000000 +0000 +++ haci-0.98c/bin/checkPerlDependencies.bash 2015-03-04 01:47:48.000000000 +0000 @@ -3,8 +3,9 @@ # Checking for Perl module dependencies # It can try to install them automatically on Demand -modules="CGI CGI::Ajax CGI::Carp CGI::Cookie CGI::Session Class::Accessor Class::MakeMethods Config::General DBD::mysql Digest::MD5 Digest::SHA Encode Encode::Guess File::Temp HTML::Entities Locale::gettext Log::LogLite Math::BigInt#1.87 Net::CIDR Net::IPv6Addr Net::SNMP Storable Template Time::Local" +modules="CGI CGI::Ajax CGI::Carp CGI::Cookie CGI::Session Class::Accessor Class::MakeMethods Config::General Digest::MD5 Digest::SHA Encode Encode::Guess File::Temp HTML::Entities Locale::gettext Log::LogLite Math::BigInt#1.87 Net::CIDR Net::IPv6Addr Net::SNMP Storable Template::Toolkit%Template Time::Local Text::CSV" aptget=`which apt-get 2>/dev/null` +yum=`which yum 2>/dev/null` yast2=`which yast2 2>/dev/null` zypper=`which zypper 2>/dev/null` cpan=`which cpan 2>/dev/null` @@ -12,25 +13,34 @@ checkModules() { index=0 echo "Checking if all Perl Dependencies are available..." - for modt in $modules + for mod in $modules do - if echo $modt | grep -q '#'; then - mod=`echo $modt|cut -d '#' -f 1`; - ver=`echo $modt|cut -d '#' -f 2`; - else - mod=$modt - ver='' + modOrig=$mod + package='' + ver='' + + if echo $mod | grep -q '%'; then + package=`echo $mod|cut -d '%' -f 2`; + mod=`echo $mod|cut -d '%' -f 1`; + fi + + if echo $mod | grep -q '#'; then + ver=`echo $mod|cut -d '#' -f 2`; + mod=`echo $mod|cut -d '#' -f 1`; fi + echo -n "$mod" - if echo $modt | grep -q '#'; then echo -n " v$ver"; fi + test -z $ver || echo -n " v$ver" echo -n ': ' - if perl -e "use $mod $ver" 2>/dev/null; + test -z $package && package=$mod + + if perl -e "use $package $ver" 2>/dev/null; then echo "OK"; else echo "NO"; - failed[$index]=$mod + failed[$index]=$modOrig ((index++)) fi done @@ -47,7 +57,11 @@ modIndex=0 while [ ${modIndex} -lt ${#failed[@]} ] do - echo "${failed[$modIndex]}" + mod="${failed[$modIndex]}" + if echo $mod | grep -q '%'; then + mod=`echo $mod|cut -d '%' -f 1`; + fi + echo $mod modIndex=$((${modIndex}+1)) done } @@ -61,8 +75,9 @@ if ( [ "$cpan" != "" ] && test -x $cpan); then bCpan=1; else bCpan=0; fi if ( [ "$yast2" != "" ] && test -x $yast2); then bYast2=1; else bYast2=0; fi if ( [ "$zypper" != "" ] && test -x $zypper); then bZypper=1; else bZypper=0; fi +if ( [ "$yum" != "" ] && test -x $yum); then bYum=1; else bYum=0; fi -if [ "$bDebian" -eq 0 ] && [ "$bCpan" -eq 0 ] +if [ "$bDebian" -eq 0 ] && [ "$bCpan" -eq 0 ] && [ "$bYast2" -eq 0 ] && [ "$bYum" -eq 0 ] then echo; echo "Don't know how to install these modules. Please do it by hand" exit 0; @@ -82,18 +97,26 @@ modIndex=0 while [ ${modIndex} -lt ${#failed[@]} ] do - echo "${failed[$modIndex]}" + mod=${failed[$modIndex]} + + if echo "$mod" | grep -q '%'; then + mod=`echo "$mod" | cut -d '%' -f 1`; + fi + + echo "$mod" + if [ "$bCpan" -eq 1 ]; then - $cpan ${failed[$modIndex]} + $cpan $mod elif [ "$bDebian" -eq 1 ]; then - debPack=${failed[$modIndex]} - $aptget -y install lib${debPack//::/-}-perl + $aptget -y install lib${mod//::/-}-perl elif [ "$bYast2" -eq 1 ]; then - yastPack=${failed[$modIndex]} - $yast2 -i perl-${yastPack//::/-} + $yast2 -i perl-${mod//::/-} + elif [ "$bYum" -eq 1 ]; + then + $yum install -y perl-${mod//::/-} else echo "Sorry, don't know how to get this module..." fi @@ -109,3 +132,5 @@ echo; echo "Everything fine. All Dependencies are installed." fi exit 0 + +# vim:ts=2:sts=2:sw=2 diff -Nru haci-0.97c/bin/checkPerlOptionals.bash haci-0.98c/bin/checkPerlOptionals.bash --- haci-0.97c/bin/checkPerlOptionals.bash 2010-03-08 17:22:58.000000000 +0000 +++ haci-0.98c/bin/checkPerlOptionals.bash 2015-03-04 01:47:50.000000000 +0000 @@ -3,34 +3,44 @@ # Checking for optional Perl module dependencies # It can try to install them automatically on demand -modules="Cache::FastMmap Cache::FileCache DNS::ZoneParse IO::Socket::INET6 Math::BigInt::GMP Net::DNS Net::Ping Pod::WSDL SOAP::Transport::HTTP SQL::Translator#0.09000 SQL::Translator::Diff Text::CSV_XS Apache::DBI" +modules="Cache::FastMmap Cache::FileCache DNS::ZoneParse IO::Socket::INET6 Math::BigInt::GMP Net::DNS Net::Ping Pod::WSDL SOAP::Transport::HTTP SQL::Translator#0.09000 Apache::DBI DBD::Pg DBD::mysql Frontier-RPC%Frontier::Client LDAP%Net::LDAP Frontier::RPC2 File::Basename Time::HiRes JSON URI::Query Text::CSV_XS" aptget=`which apt-get 2>/dev/null` yast2=`which yast2 2>/dev/null` +yum=`which yum 2>/dev/null` zypper=`which zypper 2>/dev/null` cpan=`which cpan 2>/dev/null` checkModules() { index=0 echo "Checking if all optional Perl dependencies are available..." - for modt in $modules + for mod in $modules do - if echo $modt | grep -q '#'; then - mod=`echo $modt|cut -d '#' -f 1`; - ver=`echo $modt|cut -d '#' -f 2`; - else - mod=$modt - ver='' + modOrig=$mod + package='' + ver='' + + if echo $mod | grep -q '%'; then + package=`echo $mod|cut -d '%' -f 2`; + mod=`echo $mod|cut -d '%' -f 1`; + fi + + if echo $mod | grep -q '#'; then + ver=`echo $mod|cut -d '#' -f 2`; + mod=`echo $mod|cut -d '#' -f 1`; fi + echo -n "$mod" - if echo $modt | grep -q '#'; then echo -n " v$ver"; fi + test -z $ver || echo -n " v$ver" echo -n ': ' - if perl -e "use $mod $ver" 2>/dev/null; + test -z $package && package=$mod + + if perl -e "use $package $ver" 2>/dev/null; then echo "OK"; else echo "NO"; - failed[$index]=$mod + failed[$index]=$modOrig ((index++)) fi done @@ -47,7 +57,12 @@ modIndex=0 while [ ${modIndex} -lt ${#failed[@]} ] do - echo "${failed[$modIndex]}" + mod=${failed[$modIndex]} + if echo $mod | grep -q '%'; then + mod=`echo $mod|cut -d '%' -f 1`; + fi + + echo $mod modIndex=$((${modIndex}+1)) done } @@ -60,9 +75,10 @@ if ( test -f /etc/debian_version && [ "$aptget" != "" ] && test -x $aptget); then bDebian=1; else bDebian=0; fi if ( [ "$cpan" != "" ] && test -x $cpan); then bCpan=1; else bCpan=0; fi if ( [ "$yast2" != "" ] && test -x $yast2); then bYast2=1; else bYast2=0; fi +if ( [ "$yum" != "" ] && test -x $yum); then bYum=1; else bYum=0; fi if ( [ "$zypper" != "" ] && test -x $zypper); then bZypper=1; else bZypper=0; fi -if [ "$bDebian" -eq 0 ] && [ "$bCpan" -eq 0 ] +if [ "$bDebian" -eq 0 ] && [ "$bCpan" -eq 0 ] && [ "$bYast2" -eq 0 ] && [ "$bYum" -eq 0 ] then echo; echo "Don't know how to install these modules. Please do it by hand" exit 0; @@ -82,18 +98,29 @@ modIndex=0 while [ ${modIndex} -lt ${#failed[@]} ] do - echo "${failed[$modIndex]}" + mod=${failed[$modIndex]} + if echo $mod | grep -q '%'; then + mod=`echo $mod|cut -d '%' -f 1`; + fi + + if echo $mod | grep -q '#'; then + mod=`echo $mod|cut -d '#' -f 1`; + fi + + echo $mod + if [ "$bCpan" -eq 1 ]; then - $cpan ${failed[$modIndex]} + $cpan $mod elif [ "$bDebian" -eq 1 ]; then - debPack=${failed[$modIndex]} - $aptget -y install lib${debPack//::/-}-perl + $aptget -y install lib${mod//::/-}-perl + elif [ "$bYum" -eq 1 ]; + then + $yum install -y perl-${mod//::/-} elif [ "$bYast2" -eq 1 ]; then - yastPack=${failed[$modIndex]} - $yast2 -i perl-${yastPack//::/-} + $yast2 -i perl-${mod//::/-} else echo "Sorry, don't know how to get this module..." fi @@ -109,3 +136,5 @@ echo; echo "Everything fine. All Dependencies are installed." fi exit 0 + +# vim:ts=2:sts=2:sw=2 diff -Nru haci-0.97c/bin/cleanupDatabase.pl haci-0.98c/bin/cleanupDatabase.pl --- haci-0.97c/bin/cleanupDatabase.pl 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/bin/cleanupDatabase.pl 2014-08-28 22:12:23.000000000 +0000 @@ -1,4 +1,6 @@ #!/usr/bin/perl +# +# Check database for inconsistent entries and remove them package HaCi::HaCi; @@ -16,7 +18,7 @@ use Getopt::Std; use Data::Dumper qw/Dumper/; -use HaCi::Conf; +use HaCi::Conf qw/getConfigValue/; use HaCi::Utils qw/getConfig getPlugins getTable initTables finalizeTables initCache/; $Getopt::Std::STANDARD_HELP_VERSION = 1; @@ -24,6 +26,11 @@ our $opts = {}; getopts('cd', $opts); +my $mysqlDumpBin = 'mysqldump'; +my $mysqlDumpArgs = q{-u'' -p'' -h'' ''}; +my $postgresqlDumpBin = 'pg_dump'; +my $postgresqlDumpArgs = q{-U'' -h'' ''}; + my $debug = (exists $opts->{d}) ? $opts->{d} : 0; my @busy = ('|', '/', '-', '\\', '-'); my ($bc, $ec, $sc) = (0, 0, 0); @@ -113,8 +120,20 @@ if ($opts->{c}) { print "\nPlease make sure to make a database backup before cleaning it up.\n"; - if (system("which mysqldump >/dev/null") == 0) { - my $md = qx/which mysqldump/; + my $dbType = &getConfigValue('db', 'dbtype'); + my $dumpBin = ''; + my $dumpArgs = ''; + if ($dbType eq 'mysql') { + $dumpBin = $mysqlDumpBin; + $dumpArgs = $mysqlDumpArgs; + } + elsif ($dbType eq 'postgresql') { + $dumpBin = $postgresqlDumpBin; + $dumpArgs = $postgresqlDumpArgs; + } + + if ($dumpBin && system("which $dumpBin >/dev/null") == 0) { + my $md = qx/which $dumpBin/; chomp($md); my $dbConf = $conf->{user}->{db}; my $pwd = qx/pwd/; @@ -125,12 +144,23 @@ while ( -f $dbname ) { $dbname = $dbnameO . '.' . $cnter++; } - my $backupT = $md . " -u'$dbConf->{dbuser}' -p'XXX' -h'$dbConf->{dbhost}' '$dbConf->{dbname}' > $dbname"; - print "Found 'mysqldump':\n\t$backupT\nShould I run this dump? [y|N]: "; + #my $backupT = $md . " -u'$dbConf->{dbuser}' -p'XXX' -h'$dbConf->{dbhost}' '$dbConf->{dbname}' > $dbname"; + my $backupT = $md . ' ' . $dumpArgs . "> $dbname"; + $backupT =~ s//$dbConf->{dbuser}/g; + $backupT =~ s//XXX/g; + $backupT =~ s//$dbConf->{dbhost}/g; + $backupT =~ s//$dbConf->{dbname}/g; + + print "Found '$dumpBin':\n\t$backupT\nShould I run this dump? [y|N]: "; my $bb = ; chomp($bb); if (lc($bb) eq 'y') { - my $backupStr = $md . " -u'$dbConf->{dbuser}' -p'$dbConf->{dbpass}' -h'$dbConf->{dbhost}' '$dbConf->{dbname}' > $dbname"; + #my $backupStr = $md . " -u'$dbConf->{dbuser}' -p'$dbConf->{dbpass}' -h'$dbConf->{dbhost}' '$dbConf->{dbname}' > $dbname"; + my $backupStr = $md . ' ' . $dumpArgs . "> $dbname"; + $backupStr =~ s//$dbConf->{dbuser}/g; + $backupStr =~ s//$dbConf->{dbpass}/g; + $backupStr =~ s//$dbConf->{dbhost}/g; + $backupStr =~ s//$dbConf->{dbname}/g; print qx($backupStr); if ($?) { print "... Dump was NOT successful!!!\n"; @@ -139,6 +169,7 @@ } } } + print "Continue cleaning up database? [y|N]: "; my $con = ; print "\n"; @@ -196,7 +227,8 @@ } # Get stale V4 - my @networksNR = $networkTable->search(['ID', 'network', 'description', 'rootID', 'ipv6ID'], {}, 0, "WHERE rootID NOT IN ($roots)"); + my $nriCol = $networkTable->meth2Col('rootID'); + my @networksNR = $networkTable->search(['ID', 'network', 'description', 'rootID', 'ipv6ID'], {}, 0, "WHERE $nriCol NOT IN ($roots)"); foreach (@networksNR) { my $ip = $_; print "\r" . $busy[$bc++%5]; @@ -206,7 +238,8 @@ print "\r " . ($#networksNR + 1) . " stale V4 network entrys found without matching root\n"; # Get stale V6 - my @networkV6sNR = $networkV6Table->search(['ID', 'rootID'], {}, 0, "WHERE rootID NOT IN ($roots)"); + my $nriV6Col = $networkV6Table->meth2Col('rootID'); + my @networkV6sNR = $networkV6Table->search(['ID', 'rootID'], {}, 0, "WHERE $nriV6Col NOT IN ($roots)"); foreach (@networkV6sNR) { my $ip = $_; print "\r" . $busy[$bc++%5]; @@ -215,18 +248,9 @@ } print "\r " . ($#networkV6sNR + 1) . " stale V6 network entrys found without matching root\n"; - # Get stale networkAC - my @networkACsNR = $networkACTable->search(['ID', 'rootID'], {}, 0, "WHERE rootID NOT IN ($roots)"); - foreach (@networkACsNR) { - my $ac = $_; - print "\r" . $busy[$bc++%5]; - print "\r $ac->{ID} : $ac->{rootID}: Stale network ACL entry (root doesn't exists)\n" if $debug; - &delEntry($networkACTable, $ac->{ID}); - } - print "\r " . ($#networkACsNR + 1) . " stale network ACL entrys found without matching root\n"; - # Get stale rootAC - my @rootACsNR = $rootACTable->search(['ID', 'rootID'], {}, 0, "WHERE rootID NOT IN ($roots)"); + my $rriCol = $rootACTable->meth2Col('rootID'); + my @rootACsNR = $rootACTable->search(['ID', 'rootID'], {}, 0, "WHERE $rriCol NOT IN ($roots)"); foreach (@rootACsNR) { my $ac = $_; print "\r" . $busy[$bc++%5]; diff -Nru haci-0.97c/bin/HaCid.pl haci-0.98c/bin/HaCid.pl --- haci-0.97c/bin/HaCid.pl 2010-06-22 13:21:06.000000000 +0000 +++ haci-0.98c/bin/HaCid.pl 2011-07-11 18:16:25.000000000 +0000 @@ -53,7 +53,7 @@ our $conf; *conf = \$HaCi::Conf::conf; &HaCi::Conf::init($workDir); -warn "WORKDIR: $workDir\n"; + &getConfig(); $maxMemCon = $conf->{user}->{misc}->{maxmemconsumption} if exists $conf->{user}->{misc}->{maxmemconsumption} && $conf->{user}->{misc}->{maxmemconsumption}; @@ -86,6 +86,7 @@ sleep 1; } } else { + &loadPlugins(); &main(); } @@ -392,7 +393,7 @@ sub getPID { unless (open PID, $conf->{static}->{path}->{hacidpid}) { - &log("Cannot open Pidfile '$conf->{static}->{path}->{hacidpid}' for reading: $!", 2); + &log("Cannot open Pidfile '$conf->{static}->{path}->{hacidpid}' for reading: $!", 3); return; } my $pid = ; diff -Nru haci-0.97c/bin/testXMLRPCAPI.pl haci-0.98c/bin/testXMLRPCAPI.pl --- haci-0.97c/bin/testXMLRPCAPI.pl 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/bin/testXMLRPCAPI.pl 2015-03-04 01:48:27.000000000 +0000 @@ -0,0 +1,403 @@ +#!/usr/bin/perl + +# Test all available XMLRPC-API-Calls + +use strict; +use warnings; +use Data::Dumper; +use Frontier::Client; + +my $server = 'demo.haci.larsux.de'; +my $user = 'admin'; +my $pass = 'admin'; +my $debug = 1; +my $v6 = $ARGV[0] || 0; + +my $api = new Frontier::Client(url => "http://$server/RPC2"); +my $session = $api->call('login', [$user, $pass]); +die 'Login failed!' unless $session; + +unless ($v6) { + &test('addRoot', + ['_apiTestRoot', 0], + 0 + ); + + &test('listRoots', + [], + {name => '_apiTestRoot', ipv6 => 0}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('addNet', + ['_apiTestRoot', '192.168.0.0/24', '1. test network', 'IN USE', 30], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('addNet', + ['_apiTestRoot', '192.168.0.8/29', '2. test network', 'IN USE', 32], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('addNet', + ['_apiTestRoot', '192.168.0.10/32', '3. test network', 'IN USE'], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('addNet', + ['_apiTestRoot', '192.168.0.100/32', '30. test network', 'IN USE'], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('getFreeSubnets', + ['_apiTestRoot', '192.168.0.0/24', 29, 2], + ['192.168.0.0/29', '192.168.0.16/29'], + [['delRoot', ['_apiTestRoot']]] + ); + + &test('getFreeSubnetsFromSearch', + ['1. test network', '', '', '', '', '_apiTestRoot', 28, 1], + {network => '192.168.0.16/28', rootName => '_apiTestRoot'}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('getFreeSubnets', + ['_apiTestRoot', '192.168.0.8/29', 32, 2], + ['192.168.0.9/32', '192.168.0.11/32'], + [['delRoot', ['_apiTestRoot']]] + ); + + &test('search', + ['192.168.0.0/24', '', 1, '', '', '_apiTestRoot'], + {network => '192.168.0.0/24', description => '1. test network', rootName => '_apiTestRoot', state => 'IN USE'}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('search', + ['1. test network', '', 1, '', '', '_apiTestRoot'], + {network => '192.168.0.0/24', description => '1. test network', rootName => '_apiTestRoot', state => 'IN USE'}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('editNet', + ['_apiTestRoot', '192.168.0.10/32', {description => '4. test network', state => 'FREE'}], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('search', + ['4. test network', 'FREE', 1, '', '', '_apiTestRoot'], + {network => '192.168.0.10/32', description => '4. test network', rootName => '_apiTestRoot', state => 'FREE'}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('delNet', + ['_apiTestRoot', '192.168.0.100/32'], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('search', + ['4. test network', 'FREE', 1, '', '', '_apiTestRoot'], + {network => '192.168.0.100/32', description => '30. test network', rootName => '_apiTestRoot', state => 'FREE'}, + [['delRoot', ['_apiTestRoot']]], + 1 + ); + + &test('addNet', + ['_apiTestRoot', '192.168.0.0/28', '6. test network', 'IN USE'], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('delNet', + ['_apiTestRoot', '192.168.0.0/28', 0, 1], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('search', + ['4. test network', 'FREE', 1, '', '', '_apiTestRoot'], + {network => '192.168.0.10/32', description => '4. test network', rootName => '_apiTestRoot', state => 'FREE'}, + [['delRoot', ['_apiTestRoot']]], + 1 + ); + + &test('addNet', + ['_apiTestRoot', '192.168.0.4/30', '7. test network'], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('assignFreeSubnet', + ['_apiTestRoot', '192.168.0.4/30', 32, 'assigned net'], + {network => '192.168.0.5/32', description => 'assigned net', state => 'UNSPECIFIED'}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('getFreeSubnets', + ['_apiTestRoot', '192.168.0.4/30', 32, 2], + ['192.168.0.6/32'], + [['delRoot', ['_apiTestRoot']]] + ); + + &test('getSubnets', + ['_apiTestRoot', '192.168.0.4/30'], + {network => '192.168.0.5/32', description => 'assigned net', state => 'UNSPECIFIED'}, + [['delRoot', ['_apiTestRoot']]] + ); + + for (1..50) { + &test('assignFreeSubnet', + ['_apiTestRoot', '192.168.0.0/24', 32, 'assigned net ' . $_], + {description => 'assigned net ' . $_, state => 'UNSPECIFIED'}, + [['delRoot', ['_apiTestRoot']]] + ); + + if ($_ == 25) { + &test('delNet', + ['_apiTestRoot', '192.168.0.25/32'], + 0, + [['delRoot', ['_apiTestRoot']]] + ); + } + } + + &test('getSubnets', + ['_apiTestRoot', '192.168.0.0/24'], + {network => '192.168.0.51/32', description => 'assigned net 50', state => 'UNSPECIFIED'}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('getSubnets', + ['_apiTestRoot', '192.168.0.0/24'], + {network => '192.168.0.25/32', description => 'assigned net 26', state => 'UNSPECIFIED'}, + [['delRoot', ['_apiTestRoot']]] + ); + + &test('delRoot', + ['_apiTestRoot'], + 0 + ); +} else { + + &test('addRoot', + ['_apiTestRootv6', 1, 1], + 0 + ); + + &test('listRoots', + [], + {name => '_apiTestRootv6', ipv6 => 1}, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('addNet', + ['_apiTestRootv6', 'dead:beaf::/64', '1. test network', 'IN USE', 120], + 0, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('addNet', + ['_apiTestRootv6', 'dead:beaf::100/120', '2. test network', 'IN USE', 128], + 0, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('addNet', + ['_apiTestRootv6', 'dead:beaf::102/128', '3. test network', 'IN USE'], + 0, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('addNet', + ['_apiTestRootv6', 'dead:beaf::1000/128', '30. test network', 'IN USE'], + 0, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('getFreeSubnets', + ['_apiTestRootv6', 'dead:beaf::/64', 120, 2], + ['dead:beaf:0000:0000:0000:0000:0000:0000/120', 'dead:beaf:0000:0000:0000:0000:0000:0200/120'], + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('getFreeSubnetsFromSearch', + ['1. test network', '', '', '', '', '_apiTestRootv6', 124, 1], + {network => 'dead:beaf:0000:0000:0000:0000:0000:0000/124', rootName => '_apiTestRootv6'}, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('getFreeSubnets', + ['_apiTestRootv6', 'dead:beaf::100/120', 128, 2], + ['dead:beaf:0000:0000:0000:0000:0000:0100/128', 'dead:beaf:0000:0000:0000:0000:0000:0101/128'], + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('search', + ['dead:beaf:0:0:0:0:0:0/64', '', 1, '', '', '_apiTestRootv6'], + {network => 'dead:beaf::/64', description => '1. test network', rootName => '_apiTestRootv6', state => 'IN USE'}, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('search', + ['1. test network', '', 1, '', '', '_apiTestRootv6'], + {network => 'dead:beaf::/64', description => '1. test network', rootName => '_apiTestRootv6', state => 'IN USE'}, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('editNet', + ['_apiTestRootv6', 'dead:beaf:0000:0000:0000:0000:0000:0102/128', {description => '4. test network', state => 'FREE'}], + 0, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('search', + ['4. test network', 'FREE', 1, '', '', '_apiTestRootv6'], + {network => 'dead:beaf::102/128', description => '4. test network', rootName => '_apiTestRootv6', state => 'FREE'}, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('delNet', + ['_apiTestRootv6', 'dead:beaf:0000:0000:0000:0000:0000:0102/128'], + 0, + [['delRoot', ['_apiTestRootv6']]] + ); + + &test('search', + ['4. test network', 'FREE', 1, '', '', '_apiTestRootv6'], + {network => 'dead:beaf::102/128', description => '30. test network', rootName => '_apiTestRootv6', state => 'FREE'}, + [['delRoot', ['_apiTestRootv6']]], + 1 + ); + + &test('delRoot', + ['_apiTestRootv6'], + 0 + ); +} + + +print "Successfully passed all tests\n"; +exit 0; +#------------------------------------ +sub test { + my $method = shift; + my $args = shift; + my $expectedResult = shift; + my $rollBackMethods = shift; + my $notExpect = shift || 0; + my $errorStr = "Error while testing '$method': "; + + my $result = undef; + eval { + $result = $api->call($method, $session, @{$args}); + }; + &rollBack($errorStr . $@, $rollBackMethods) if $@; + + return unless defined $expectedResult; + + my $bOK = 0; + if (ref($expectedResult) eq 'HASH') { + if (ref($result) eq 'ARRAY') { + foreach (@{$result}) { + my $resultItem = $_; + my $nrOfOK = 0; + if (ref($resultItem) eq 'HASH') { + foreach (keys %{$expectedResult}) { + my $key = $_; + my $value = $expectedResult->{$key}; + $nrOfOK++ if exists $resultItem->{$key} && $value eq $resultItem->{$key}; + if ($nrOfOK == scalar keys %{$expectedResult}) { + $bOK = 1; + last; + } + } + last if $bOK; + } + } + $bOK = abs($bOK - 1) if $notExpect; + unless ($bOK) { + my $error = $errorStr . (($notExpect) ? 'Not expected result found' : 'Expected result cannot be found'); + $error .= Dumper($result) if $debug; + &rollBack($error, $rollBackMethods); + } else { + print "Successfully tested '$method'\n"; + } + } + elsif (ref($result) eq 'HASH') { + my $nrOfOK = 0; + foreach (keys %{$expectedResult}) { + my $key = $_; + my $value = $expectedResult->{$key}; + $nrOfOK++ if exists $result->{$key} && $value eq $result->{$key}; + if ($nrOfOK == scalar keys %{$expectedResult}) { + $bOK = 1; + last; + } + } + unless ($bOK) { + my $error = $errorStr . (($notExpect) ? 'Not expected result found' : 'Expected result cannot be found'); + $error .= Dumper($result) if $debug; + &rollBack($error, $rollBackMethods); + } else { + print "Successfully tested '$method'\n"; + } + + } else { + &rollBack($errorStr . 'Result is not an array nor a hash: ' . $result, $rollBackMethods); + } + } + elsif (ref($expectedResult) eq 'ARRAY') { + if (ref($result) eq 'ARRAY') { + my $nrOfOK = 0; + foreach (@{$expectedResult}) { + my $expectedResultItem = $_; + foreach (@{$result}) { + my $resultItem = $_; + $nrOfOK++ if $resultItem eq $expectedResultItem; + if ($nrOfOK == scalar @{$expectedResult}) { + $bOK = 1; + last; + } + } + last if $bOK; + } + } + unless ($bOK) { + my $error = $errorStr . 'Expected result cannot be found'; + $error .= Dumper($result) if $debug; + &rollBack($error, $rollBackMethods); + } else { + print "Successfully tested '$method'\n"; + } + } + elsif ($result ne $expectedResult) { + &rollBack($errorStr . $result, $rollBackMethods); + } else { + print "Successfully tested '$method'\n"; + } +} + +sub rollBack { + my $result = shift; + my $rollBackMethods = shift; + + warn Dumper($result); + + if (defined $rollBackMethods) { + print "Rollbacking with " . join(', ', map {${$_}[0]} @{$rollBackMethods}) . "\n"; + foreach (@{$rollBackMethods}) { + my $meth = $$_[0]; + my $args = $$_[1]; + &test($meth, $args); + } + } + exit 1; +} + +# vim:ts=2:sts=2:sw=2 diff -Nru haci-0.97c/cgi-bin/HaCiAPI.cgi haci-0.98c/cgi-bin/HaCiAPI.cgi --- haci-0.97c/cgi-bin/HaCiAPI.cgi 2010-01-10 01:55:06.000000000 +0000 +++ haci-0.98c/cgi-bin/HaCiAPI.cgi 2015-02-15 16:47:26.000000000 +0000 @@ -2,7 +2,7 @@ ############################################################################### ## HaCi - IP Address Administration # -## Copyright (C) 2006-2010 by Lars Wildemann # +## Copyright (C) 2006-2015 by Lars Wildemann # ## Author: Lars Wildemann # ## # ## HaCi is an IP Address / Network Administration Tool with IPv6 Support. # diff -Nru haci-0.97c/cgi-bin/HaCi.cgi haci-0.98c/cgi-bin/HaCi.cgi --- haci-0.97c/cgi-bin/HaCi.cgi 2010-01-10 01:55:06.000000000 +0000 +++ haci-0.98c/cgi-bin/HaCi.cgi 2015-02-15 16:47:26.000000000 +0000 @@ -2,7 +2,7 @@ ############################################################################### ## HaCi - IP Address Administration # -## Copyright (C) 2006-2010 by Lars Wildemann # +## Copyright (C) 2006-2015 by Lars Wildemann # ## Author: Lars Wildemann # ## # ## HaCi is an IP Address / Network Administration Tool with IPv6 Support. # diff -Nru haci-0.97c/cgi-bin/test.cgi haci-0.98c/cgi-bin/test.cgi --- haci-0.97c/cgi-bin/test.cgi 2010-03-08 17:22:58.000000000 +0000 +++ haci-0.98c/cgi-bin/test.cgi 2015-03-04 02:22:17.000000000 +0000 @@ -3,6 +3,8 @@ use strict; use warnings; use CGI; +use Data::Dumper; + sub getWorkDir { my $currDir = `pwd`; @@ -29,13 +31,17 @@ $ENV{workdir} = $workDir; unshift @INC, $ENV{workdir} . '/modules'; +our $conf; *conf = \$HaCi::Conf::conf; +eval { + require HaCi::Conf; + &HaCi::Conf::init($workDir); +}; + my $q = new CGI(@_); my $title = 'HaCi - IP Address Administration'; -my $ver = '0.9.7a'; -my -@mands = qw/CGI CGI::Ajax CGI::Carp CGI::Cookie CGI::Session Class::Accessor Class::MakeMethods Config::General DBD::mysql Digest::MD5 Digest::SHA Encode Encode::Guess File::Temp HTML::Entities Locale::gettext Log::LogLite Math::Base85 Math::BigInt#1.87 Net::CIDR Net::IMAP::Simple Net::IPv6Addr Net::SNMP Storable Template Time::Local/; -my -@opts = qw/Cache::FastMmap Cache::FileCache DNS::ZoneParse IO::Socket::INET6 Math::BigInt::GMP Net::DNS Net::Nslookup Net::Ping Pod::WSDL SOAP::Transport::HTTP SQL::Translator#0.09000 SQL::Translator::Diff Text::CSV_XS Apache::DBI/; +my $ver = $conf->{static}->{gui}->{version} || '[unknown]'; +my @mands = qw/CGI CGI::Ajax CGI::Carp CGI::Cookie CGI::Session Class::Accessor Class::MakeMethods Config::General DBD::mysql Digest::MD5 Digest::SHA Encode Encode::Guess File::Temp HTML::Entities Locale::gettext Log::LogLite Math::Base85 Math::BigInt%1.87 Net::CIDR Net::IMAP::Simple Net::IPv6Addr Net::SNMP Storable Template Time::Local Text::CSV/; +my @opts = qw/Cache::FastMmap Cache::FileCache DNS::ZoneParse IO::Socket::INET6 Math::BigInt::GMP Net::DNS Net::Nslookup Net::Ping Pod::WSDL SOAP::Transport::HTTP SQL::Translator%0.09000 SQL::Translator::Diff Text::CSV_XS Apache::DBI DBD::Pg DBD::mysql Frontier::RPC2 File::Basename Time::HiRes JSON URI::Query Text::CSV_XS/; print $q->header(-charset=>'UTF-8'); @@ -47,10 +53,22 @@ print $q->h2("Version: " . $ver . (($ENV{MOD_PERL}) ? ' (running under mod-perl)' : '')); print $q->h6($ENV{SERVER_SOFTWARE}); +eval { + require HaCi::Utils; + &HaCi::Utils::getConfig(); + my $dbError = &checkDB(); + my $dbHost = $conf->{user}->{db}->{dbhost} || ''; + my $dbName = $conf->{user}->{db}->{dbname} || ''; + my $dbUser = $conf->{user}->{db}->{dbuser} || ''; + print $q->br, $q->h3("Database connection ($dbUser\@$dbHost:$dbName): $dbError"); +}; +print $q->br, $q->h5("Canot test database connection:
$@
"); + + print $q->br, $q->h3("Mandatory Modules:"); print $q->start_table({cellpadding=>3, rules=>'all'}); foreach (sort @mands) { - s/#/ /g; + s/%/ /g; eval "use $_"; warn $@ if $@; print $q->Tr($q->th({align=>'left'}, $_), $q->td({bgcolor=>(($@) ? '#FFAAAA' : '#AAFFAA')}, (($@) ? 'NOT' : '') . ' available')); @@ -60,12 +78,34 @@ print $q->start_table({cellpadding=>3, rules=>'all'}); print $q->br, $q->h3("Recommended Modules:"); foreach (sort @opts) { - s/#/ /g; + s/%/ /g; eval "use $_"; warn $@ if $@; print $q->Tr($q->th({align=>'left'}, $_), $q->td({bgcolor=>(($@) ? '#FFAAAA' : '#AAFFAA')}, (($@) ? 'NOT' : '') . ' available')); } exit 0; +#----------------------------------- +sub checkDB { + my $dbType = &HaCi::Utils::getConfigValue('db', 'dbtype'); + eval { + require "HaCi/Tables/$dbType/network.pm"; + }; + return "Error while loading Table 'network': $@\n" if $@; + + + $DBIEasy::lastError = ''; + my $tableRef = "HaCi::Tables::${dbType}::network"->new($conf->{user}->{db}); + return $DBIEasy::lastError if $DBIEasy::lastError; + + my $dbh = $tableRef->dbh(); + if (ref($dbh) && $dbh->can('ping') && $dbh->ping()) { + return 'OK'; + } else { + return $dbh->errstr; + } + + return 'OK'; +} # vim:ts=4:sw=4 diff -Nru haci-0.97c/ChangeLog haci-0.98c/ChangeLog --- haci-0.97c/ChangeLog 2010-06-23 22:09:49.000000000 +0000 +++ haci-0.98c/ChangeLog 2015-03-04 01:46:38.000000000 +0000 @@ -1,3 +1,111 @@ +2015-03-04 + * CSV-Import bugfix in order to allow import networks with non-asccii characters + * enhance (database) documentation and test cases + +2015-02-16 + * add test suite for XMLRPC-API + * add root methods (add, edit, delete) to XMLRPC-API + +2015-02-15 + * add simple REST wrapper + * add config option showNetBorders + * add config option removeCIDRFromIPs + * minor Bugfixes + +2015-02-13 + * Add multiple authentication methods for login at once + +2015-02-07 + * add some flushes to the session object + * add timeout to 'showStatus'-Ajax-call, in order to circumvent a race condition (expanded net don't stay expanded) + * when you define a minimal network cidr, you can expand that net even if it has no childs + +2015-01-03 + * Add tag support for networks + +2014-12-31 + * remove potential XSS attack vectors + +2014-10-27 + * fix import status issue + * limit height of warning window + +2014-10-18 + * add export subnets for supernets and roots + * add wrapper for accessing CGI params + +2014-09-14 + * added simple 'exportSubnet' method + added new config variable 'gui/showNrOfFreeSubnetsWithMinCIDR' + +2014-09-09 + * Bugfix (calculation of free subnets) + * add 'editNet' function to XMLRPC-API + * add functionality to search for networks (with wildcards) + +2014-09-04 + * add new XMLRPC-API method: editNet + +2014-08-28 + * add DB-Docu + * add mysql support for networkLock + * some Bugfixes + * add default network lock configuration item + +2014-08-27 + * add locking for network deletion + * add new API method: XMLRPC + * improve rights delegation while editing networks + * add new button 'Search and assign free networks' + * add possibility to configure multiple server to ldap authentication + * inherit ACS from super net / root + * sort user and group field + * improve robustness against concurrent requests + +2012-09-26 + * added search for free network in GUI + * several Bugfixes + +2012-07-23 + * added audit functionality + +2012-06-20 + * added possibility to show amount of free subnets in search view + * added possibility to change a template name + * added yum support for checkPerlDependencies + * enhance ldap authentication support (authenticate a DN after searching for it in LDAP) + * Expanded entries field in templateEntry to 1024 chars + +2012-01-31 + * enhanced generic database support + * added postgresql support + * some speedup enhancements + +2012-01-17 + * start enhancing database abstraction in order to implement other database accessors + +2012-01-13 + * several Bugfixes + +2011-07-11 + * added recurrent mode for plugin 'GenZonefile' in order to create zonefiles automatically + +2011-07-09 + * added parameter for onDemand execution of plugins + * added genZonefile plugin + +2011-07-07 + * added ldap authentication module + +2011-06-12 + * force string type in SOAP-API (Patch-ID:3314242) + +2011-02-15 + * Bugfix 3168045, 3111556 + +2010-09-24 + * add support for 32 bit as numbers + 2010-06-23 * Bugfixes (editRoot, copyNets, moveNets) * Enhancements (showStatus, importASN, importCSV) diff -Nru haci-0.97c/debian/changelog haci-0.98c/debian/changelog --- haci-0.97c/debian/changelog 2013-06-19 05:57:43.000000000 +0000 +++ haci-0.98c/debian/changelog 2017-07-11 13:11:39.000000000 +0000 @@ -1,3 +1,16 @@ +haci (0.98c-1) unstable; urgency=medium + + * New upstream version 0.98c + * debian/watch: Update the file location. + * debian/example: Removed + * Bump Standards-Version to 4.0.0 (without changes) + * debian/patches: Refresh patches. + * debian/compat: Bump to 10 + * Remove changelog duplicated install. + * Update Vcs-* + + -- TANIGUCHI Takaki Tue, 11 Jul 2017 22:11:39 +0900 + haci (0.97c-3) unstable; urgency=low * debian/control: Bump Standards-Version to 3.9.4 (with no changes). diff -Nru haci-0.97c/debian/compat haci-0.98c/debian/compat --- haci-0.97c/debian/compat 2013-06-19 05:57:43.000000000 +0000 +++ haci-0.98c/debian/compat 2017-07-11 13:11:39.000000000 +0000 @@ -1 +1 @@ -7 +10 diff -Nru haci-0.97c/debian/control haci-0.98c/debian/control --- haci-0.97c/debian/control 2013-06-19 05:57:43.000000000 +0000 +++ haci-0.98c/debian/control 2017-07-11 13:11:39.000000000 +0000 @@ -2,11 +2,11 @@ Section: admin Priority: extra Maintainer: TANIGUCHI Takaki -Build-Depends: debhelper (>= 7.0.50~) -Standards-Version: 3.9.4 +Build-Depends: debhelper (>= 10) +Standards-Version: 4.0.0 Homepage: http://haci.larsux.de/ -Vcs-Git: git://git.debian.org/collab-maint/haci.git -Vcs-Browser: http://git.debian.org/?p=collab-maint/haci.git;a=summary +Vcs-Git: https://anonscm.debian.org/git/collab-maint/haci.git +Vcs-Browser: https://anonscm.debian.org/cgit/collab-maint/haci.git Package: haci Architecture: all diff -Nru haci-0.97c/debian/docs haci-0.98c/debian/docs --- haci-0.97c/debian/docs 2013-06-19 05:57:43.000000000 +0000 +++ haci-0.98c/debian/docs 2017-07-11 13:11:39.000000000 +0000 @@ -1,2 +1 @@ README -ChangeLog diff -Nru haci-0.97c/debian/examples haci-0.98c/debian/examples --- haci-0.97c/debian/examples 2013-06-19 05:57:43.000000000 +0000 +++ haci-0.98c/debian/examples 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -etc/*.samples diff -Nru haci-0.97c/debian/patches/webapp-policy haci-0.98c/debian/patches/webapp-policy --- haci-0.97c/debian/patches/webapp-policy 2013-06-19 05:57:43.000000000 +0000 +++ haci-0.98c/debian/patches/webapp-policy 2017-07-11 13:11:39.000000000 +0000 @@ -24,8 +24,10 @@ Reviewed-By: Last-Update: ---- haci-0.97c.orig/html/index.html -+++ haci-0.97c/html/index.html +Index: haci/html/index.html +=================================================================== +--- haci.orig/html/index.html 2017-07-11 21:34:53.538210458 +0900 ++++ haci/html/index.html 2017-07-11 21:34:53.522210681 +0900 @@ -1,6 +1,6 @@ @@ -34,21 +36,23 @@ ---- haci-0.97c.orig/etc/internal.conf -+++ haci-0.97c/etc/internal.conf -@@ -5,7 +5,7 @@ +Index: haci/etc/internal.conf +=================================================================== +--- haci.orig/etc/internal.conf 2017-07-11 21:34:53.538210458 +0900 ++++ haci/etc/internal.conf 2017-07-11 21:38:35.335124234 +0900 +@@ -9,7 +9,7 @@ workdir = $workdir templateIncludePath = $workdir/Template -- templateCompilePath = $workdir/spool -+ templateCompilePath = /var/cache/haci/Template - spoolPath = $workdir/spool +- spoolPath = $workdir/spool ++ spoolPath = /var/cache/haci/Template + templateCompilePath = ${spoolPath} authModules = $workdir/modules/HaCi/Authentication plugins = $workdir/modules/HaCi/Plugins -@@ -26,9 +26,9 @@ +@@ -31,9 +31,9 @@ titleShort = HaCi titleLong = HaCi - IP Address Administration - version = 0.97c + version = 0.98c - jsSrcDir = / - jsSrc = /HaCi.js - imagePathRel = /Images @@ -58,7 +62,7 @@ logo = ${imagePathRel}/logo.png style = bright maxSubnetSize = 8 -@@ -52,13 +52,13 @@ +@@ -57,13 +57,13 @@ ID = bright name = bright @@ -74,8 +78,10 @@ descr = Black Layout ---- haci-0.97c.orig/Template/HaCiShowAbout.tmpl -+++ haci-0.97c/Template/HaCiShowAbout.tmpl +Index: haci/Template/HaCiShowAbout.tmpl +=================================================================== +--- haci.orig/Template/HaCiShowAbout.tmpl 2017-07-11 21:34:53.538210458 +0900 ++++ haci/Template/HaCiShowAbout.tmpl 2017-07-11 21:34:53.522210681 +0900 @@ -1,7 +1,7 @@
- @@ -86,8 +92,10 @@
Version: [% version %]

---- haci-0.97c.orig/Template/HaCiMenu.tmpl -+++ haci-0.97c/Template/HaCiMenu.tmpl +Index: haci/Template/HaCiMenu.tmpl +=================================================================== +--- haci.orig/Template/HaCiMenu.tmpl 2017-07-11 21:34:53.538210458 +0900 ++++ haci/Template/HaCiMenu.tmpl 2017-07-11 21:34:53.522210681 +0900 @@ -1,4 +1,4 @@ - + @@ -103,19 +111,10 @@ [% UNLESS entry.disabled %] [% ELSE %] ---- haci-0.97c.orig/Template/HaCiShowSubnets.tmpl -+++ haci-0.97c/Template/HaCiShowSubnets.tmpl -@@ -35,7 +35,7 @@ - - - - ---- haci-0.97c.orig/Template/HaCiLogin.tmpl -+++ haci-0.97c/Template/HaCiLogin.tmpl +Index: haci/Template/HaCiLogin.tmpl +=================================================================== +--- haci.orig/Template/HaCiLogin.tmpl 2017-07-11 21:34:53.538210458 +0900 ++++ haci/Template/HaCiLogin.tmpl 2017-07-11 21:34:53.522210681 +0900 @@ -1,9 +1,9 @@
@@ -128,3 +127,16 @@
+Index: haci/Template/HaCiShowSubnets.tmpl +=================================================================== +--- haci.orig/Template/HaCiShowSubnets.tmpl 2017-07-11 21:34:53.538210458 +0900 ++++ haci/Template/HaCiShowSubnets.tmpl 2017-07-11 21:39:16.126556852 +0900 +@@ -42,7 +42,7 @@ + + + + diff -Nru haci-0.97c/debian/watch haci-0.98c/debian/watch --- haci-0.97c/debian/watch 2013-06-19 05:57:43.000000000 +0000 +++ haci-0.98c/debian/watch 2017-07-11 13:11:39.000000000 +0000 @@ -1,23 +1,3 @@ -# Example watch control file for uscan -# Rename this file to "watch" and then you can run the "uscan" command -# to check for upstream updates and more. -# See uscan(1) for format +version=4 +http://sf.net/haci/ HaCi_(.*)\.tar\.gz debian uupdate -# Compulsory line, this is a version 3 file -version=3 - -# Uncomment to examine a Webpage -# -#http://www.example.com/downloads.php haci-(.*)\.tar\.gz - -# Uncomment to examine a Webserver directory -#http://www.example.com/pub/haci-(.*)\.tar\.gz - -# Uncommment to examine a FTP server -#ftp://ftp.example.com/pub/haci-(.*)\.tar\.gz debian uupdate - -# Uncomment to find new files on sourceforge, for devscripts >= 2.9 -# http://sf.net/haci/haci-(.*)\.tar\.gz - -# Uncomment to find new files on GooglePages -# http://example.googlepages.com/foo.html haci-(.*)\.tar\.gz diff -Nru haci-0.97c/docs/HaCiAPI.txt haci-0.98c/docs/HaCiAPI.txt --- haci-0.97c/docs/HaCiAPI.txt 2010-01-10 01:55:06.000000000 +0000 +++ haci-0.98c/docs/HaCiAPI.txt 2015-01-03 05:11:10.000000000 +0000 @@ -1,4 +1,4 @@ -__HaCiAPI__ +__HaCi_SOAP_API__ Available methods and their parameters, return values and a short description search : @@ -10,6 +10,8 @@ _IN fuzzy $boolean (optional) Fuzzy search? _IN template $string (optional) isolate your Search by defining a Template _IN templateQueries $string (optional) Define special Queries for the specified Template. spererated by semicolon. E.g.: value1=foo;value2=bar + _IN root $string (optional) Define special root to search in + _IN tags $string (optional) return only networks with this tags, seperate with spaces (i.e.: 'OR foo bar', 'AND foo bar') _RETURN @HaCi::SOAP::Type::network _DOC This is a search function @@ -47,6 +49,7 @@ _IN state $string (optional) The State of the Network (One of: UNSPECIFIED, ALLOCATED PA, ALLOCATED PI, ALLOCATED UNSPECIFIED, SUB-ALLOCATED PA, LIR-PARTITIONED PA, LIR-PARTITIONED PI, EARLY-REGISTRATION, NOT-SET, ASSIGNED PA, ASSIGNED PI, ASSIGNED ANYCAST, ALLOCATED-BY-RIR, ALLOCATED-BY-LIR, ASSIGNED, RESERVED, LOCKED, FREE) _IN defSubnetSize $int (optional) Default CIDR for Subnets _IN templateName $string (optional) Template, which should be linked to the Network + _IN tags $string (optional) Tags (seperate by comma) _RETURN $string Prints if addition has failed or was successfull _DOC This function adds a Network diff -Nru haci-0.97c/docs/HaCiRESTWrapper.txt haci-0.98c/docs/HaCiRESTWrapper.txt --- haci-0.97c/docs/HaCiRESTWrapper.txt 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCiRESTWrapper.txt 2015-02-15 16:47:26.000000000 +0000 @@ -0,0 +1,21 @@ +REST wrapper for HaCi XML-RPC-API + +The methods and parameters are equal to the XML-RPC-API. +The parameters have to be URL encoded (i.e: '/' => '%2f') + +Authentication: + * via HTTP basic authentication + * via username and password parameter + +USAGE: + * http(s):///RESTWrapper/[API-METHOD]?username=&password=&[API-PARAMETER] + * http(s)://@@/RESTWrapper/[API-METHOD]?[API-PARAMETER] + +Examples: + * http(s)://foo:bar@/RESTWrapper/search?search=test?rootName=bigRoot + * http(s):///RESTWrapper/getFreeSubnets?username=foo&password=bar&rootName=bigRoot&supernet=192.168.0.0%2f24&cidr=32&amount=3 + + $ curl 'http://demo.haci.larsux.de/RESTWrapper/getFreeSubnets?username=admin&password=admin&rootName=testRoot&supernet=192.168.0.0%2f24&cidr=32&amount=3' + ["192.168.0.1/32","192.168.0.2/32","192.168.0.3/32"] + +Return: JSON-Object diff -Nru haci-0.97c/docs/HaCiSoapClient.pl haci-0.98c/docs/HaCiSoapClient.pl --- haci-0.97c/docs/HaCiSoapClient.pl 2009-11-01 03:46:19.000000000 +0000 +++ haci-0.98c/docs/HaCiSoapClient.pl 2014-08-28 22:12:23.000000000 +0000 @@ -12,9 +12,11 @@ die (defined $res && ref $res ? $res->faultstring : $soap->transport->status), "\n"; }; -my $haciApiUrl = 'http://demo.haci.larsux.de/cgi-bin/HaCiAPI.cgi?getWSDL'; -my $user = 'admin'; -my $pass = 'admin'; +my $haciApiUrl = 'http://hacidev.larsux.de/cgi-bin/HaCiAPI.cgi?getWSDL'; +#my $user = 'admin'; +#my $pass = 'admin'; +my $user = 'test'; +my $pass = '1'; my $a = $ARGV[0] || 0; my $soap = SOAP::Lite->service($haciApiUrl); diff -Nru haci-0.97c/docs/HaCi_v0.98b.mysql haci-0.98c/docs/HaCi_v0.98b.mysql --- haci-0.97c/docs/HaCi_v0.98b.mysql 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCi_v0.98b.mysql 2015-03-04 00:15:52.000000000 +0000 @@ -0,0 +1,334 @@ +-- +-- Table structure for table `audit` +-- + +DROP TABLE IF EXISTS `audit`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `audit` ( + `ID` int(11) NOT NULL auto_increment, + `ts` datetime NOT NULL default '0000-00-00 00:00:00', + `username` varchar(255) NOT NULL default '', + `accessGroups` varchar(255) NOT NULL default '', + `action` varchar(255) NOT NULL default '', + `object` varchar(255) NOT NULL default '', + `value` text NOT NULL, + `error` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`) +) ENGINE=InnoDB AUTO_INCREMENT=676 DEFAULT CHARSET=latin1; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `network` +-- + +DROP TABLE IF EXISTS `network`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `network` ( + `ID` int(11) NOT NULL auto_increment, + `rootID` int(11) NOT NULL default '0', + `network` bigint(40) NOT NULL default '0', + `description` varchar(255) NOT NULL default '', + `state` smallint(6) NOT NULL default '0', + `defSubnetSize` tinyint(4) unsigned NOT NULL default '0', + `tmplID` int(11) NOT NULL default '0', + `ipv6ID` varbinary(22) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `rootID` (`rootID`,`ipv6ID`,`network`), + KEY `network` (`network`) +) ENGINE=InnoDB AUTO_INCREMENT=35184 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkAC` +-- + +DROP TABLE IF EXISTS `networkAC`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkAC` ( + `ID` int(11) NOT NULL auto_increment, + `rootID` int(11) NOT NULL default '0', + `network` bigint(40) NOT NULL default '0', + `netID` int(11) NOT NULL default '0', + `groupID` int(11) NOT NULL default '0', + `ACL` int(11) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`groupID`) +) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkPlugin` +-- + +DROP TABLE IF EXISTS `networkPlugin`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkPlugin` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL default '0', + `pluginID` int(11) NOT NULL default '0', + `sequence` int(11) NOT NULL default '0', + `newLine` tinyint(4) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`pluginID`) +) ENGINE=InnoDB AUTO_INCREMENT=83 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkV6` +-- + +DROP TABLE IF EXISTS `networkV6`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkV6` ( + `ID` varbinary(22) NOT NULL default '', + `rootID` int(11) NOT NULL default '0', + `networkPrefix` bigint(20) unsigned NOT NULL default '0', + `hostPart` bigint(20) unsigned NOT NULL default '0', + `cidr` smallint(6) NOT NULL default '0', + PRIMARY KEY (`ID`,`rootID`), + UNIQUE KEY `rootID` (`rootID`,`networkPrefix`,`hostPart`,`cidr`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `plugin` +-- + +DROP TABLE IF EXISTS `plugin`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `plugin` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `filename` varchar(255) NOT NULL default '', + `active` tinyint(4) NOT NULL default '0', + `lastRun` datetime NOT NULL default '0000-00-00 00:00:00', + `runTime` int(11) NOT NULL default '0', + `lastError` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `pluginConf` +-- + +DROP TABLE IF EXISTS `pluginConf`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `pluginConf` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL, + `pluginID` int(11) NOT NULL, + `name` varchar(255) NOT NULL, + `value` text NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`pluginID`,`name`) +) ENGINE=InnoDB AUTO_INCREMENT=76 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `pluginValue` +-- + +DROP TABLE IF EXISTS `pluginValue`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `pluginValue` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL, + `pluginID` int(11) NOT NULL, + `origin` int(11) NOT NULL, + `name` varchar(255) NOT NULL, + `value` text NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`pluginID`,`name`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `root` +-- + +DROP TABLE IF EXISTS `root`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `root` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `ipv6` tinyint(1) NOT NULL default '0', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=98 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `rootAC` +-- + +DROP TABLE IF EXISTS `rootAC`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `rootAC` ( + `ID` int(11) NOT NULL auto_increment, + `rootID` int(11) NOT NULL default '0', + `groupID` int(11) NOT NULL default '0', + `ACL` int(11) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `rootID` (`rootID`,`groupID`) +) ENGINE=InnoDB AUTO_INCREMENT=139 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `setting` +-- + +DROP TABLE IF EXISTS `setting`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `setting` ( + `ID` int(11) NOT NULL auto_increment, + `userID` int(11) NOT NULL default '0', + `param` varchar(255) NOT NULL default '', + `value` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY `userID` (`userID`,`param`,`value`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `squad` +-- + +DROP TABLE IF EXISTS `squad`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `squad` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `permissions` int(11) NOT NULL default '0', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `template` +-- + +DROP TABLE IF EXISTS `template`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `template` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `type` varchar(64) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `templateEntry` +-- + +DROP TABLE IF EXISTS `templateEntry`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `templateEntry` ( + `ID` int(11) NOT NULL auto_increment, + `tmplID` int(11) NOT NULL default '0', + `type` int(11) NOT NULL default '0', + `position` int(11) NOT NULL default '0', + `description` varchar(255) NOT NULL default '', + `size` int(11) NOT NULL default '1', + `entries` text NOT NULL, + `rows` int(11) NOT NULL default '1', + `cols` int(11) NOT NULL default '1', + PRIMARY KEY (`ID`) +) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `templateValue` +-- + +DROP TABLE IF EXISTS `templateValue`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `templateValue` ( + `ID` int(11) NOT NULL auto_increment, + `tmplID` int(11) NOT NULL default '0', + `tmplEntryID` int(11) NOT NULL default '0', + `netID` int(11) NOT NULL default '0', + `value` blob NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`tmplID`,`tmplEntryID`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `user` ( + `ID` int(11) NOT NULL auto_increment, + `username` varchar(100) NOT NULL default '', + `password` varchar(255) NOT NULL default '', + `groupIDs` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `username` (`username`) +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `networkLock` +-- + +DROP TABLE IF EXISTS `networkLock`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkLock` ( + `ID` int(11) NOT NULL auto_increment, + `ts` datetime NOT NULL default '0000-00-00 00:00:00', + `duration` int(11) NOT NULL default '0', + `rootID` int(11) NOT NULL default '0', + `networkPrefix` bigint(20) unsigned NOT NULL default '0', + `hostPart` bigint(20) unsigned NOT NULL default '0', + `cidr` smallint(6) NOT NULL default '0', + `ipv6` smallint(6) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `rootID` (`rootID`,`networkPrefix`,`hostPart`,`cidr`,`ipv6`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; diff -Nru haci-0.97c/docs/HaCi_v0.98b.pgsql haci-0.98c/docs/HaCi_v0.98b.pgsql --- haci-0.97c/docs/HaCi_v0.98b.pgsql 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCi_v0.98b.pgsql 2015-03-04 01:21:47.000000000 +0000 @@ -0,0 +1,815 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = off; +SET check_function_bodies = false; +SET client_min_messages = warning; +SET escape_string_warning = off; + +-- +-- Name: HaCi2; Type: COMMENT; Schema: -; Owner: postgres +-- + +COMMENT ON DATABASE "HaCi2" IS 'HaCi2'; + + +SET search_path = public, pg_catalog; + +-- +-- Name: network_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE network_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_id_seq OWNER TO "HaCi2"; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: network; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network ( + id integer DEFAULT nextval('network_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network bigint DEFAULT (0)::bigint NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + state smallint DEFAULT (0)::smallint NOT NULL, + def_subnet_size smallint DEFAULT (0)::smallint NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + ipv6_id bytea DEFAULT ''::bytea NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + CONSTRAINT network_def_subnet_size_check CHECK ((def_subnet_size >= 0)) +); + + +ALTER TABLE public.network OWNER TO "HaCi2"; + +-- +-- Name: network_ac_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE network_ac_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_ac_id_seq OWNER TO "HaCi2"; + +-- +-- Name: network_ac; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network_ac ( + id integer DEFAULT nextval('network_ac_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network bigint DEFAULT (0)::bigint NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + group_id integer DEFAULT 0 NOT NULL, + acl integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.network_ac OWNER TO "HaCi2"; + +-- +-- Name: network_plugin_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE network_plugin_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_plugin_id_seq OWNER TO "HaCi2"; + +-- +-- Name: network_plugin; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network_plugin ( + id integer DEFAULT nextval('network_plugin_id_seq'::regclass) NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + plugin_id integer DEFAULT 0 NOT NULL, + sequence integer DEFAULT 0 NOT NULL, + new_line smallint DEFAULT (0)::smallint NOT NULL +); + + +ALTER TABLE public.network_plugin OWNER TO "HaCi2"; + +-- +-- Name: network_v6; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network_v6 ( + id bytea DEFAULT ''::bytea NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network_prefix numeric(20,0) DEFAULT (0)::numeric NOT NULL, + host_part numeric(20,0) DEFAULT (0)::numeric NOT NULL, + cidr smallint DEFAULT (0)::smallint NOT NULL, + CONSTRAINT network_v6_host_part_check CHECK ((host_part >= (0)::numeric)), + CONSTRAINT network_v6_network_prefix_check CHECK ((network_prefix >= (0)::numeric)) +); + + +ALTER TABLE public.network_v6 OWNER TO "HaCi2"; + +-- +-- Name: plugin_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE plugin_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.plugin_id_seq OWNER TO "HaCi2"; + +-- +-- Name: plugin; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE plugin ( + id integer DEFAULT nextval('plugin_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + filename character varying(255) DEFAULT ''::character varying NOT NULL, + active smallint DEFAULT (0)::smallint NOT NULL, + last_run timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + run_time integer DEFAULT 0 NOT NULL, + last_error character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.plugin OWNER TO "HaCi2"; + +-- +-- Name: plugin_conf_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE plugin_conf_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.plugin_conf_id_seq OWNER TO "HaCi2"; + +-- +-- Name: plugin_conf; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE plugin_conf ( + id integer DEFAULT nextval('plugin_conf_id_seq'::regclass) NOT NULL, + net_id integer NOT NULL, + plugin_id integer NOT NULL, + name character varying(255) NOT NULL, + value text NOT NULL +); + + +ALTER TABLE public.plugin_conf OWNER TO "HaCi2"; + +-- +-- Name: plugin_value_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE plugin_value_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.plugin_value_id_seq OWNER TO "HaCi2"; + +-- +-- Name: plugin_value; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE plugin_value ( + id integer DEFAULT nextval('plugin_value_id_seq'::regclass) NOT NULL, + net_id integer NOT NULL, + plugin_id integer NOT NULL, + origin integer NOT NULL, + name character varying(255) NOT NULL, + value text NOT NULL +); + + +ALTER TABLE public.plugin_value OWNER TO "HaCi2"; + +-- +-- Name: root_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE root_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.root_id_seq OWNER TO "HaCi2"; + +-- +-- Name: root; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE root ( + id integer DEFAULT nextval('root_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + ipv6 smallint DEFAULT (0)::smallint NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.root OWNER TO "HaCi2"; + +-- +-- Name: root_ac_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE root_ac_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.root_ac_id_seq OWNER TO "HaCi2"; + +-- +-- Name: root_ac; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE root_ac ( + id integer DEFAULT nextval('root_ac_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + group_id integer DEFAULT 0 NOT NULL, + acl integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.root_ac OWNER TO "HaCi2"; + +-- +-- Name: setting_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE setting_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.setting_id_seq OWNER TO "HaCi2"; + +-- +-- Name: setting; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE setting ( + id integer DEFAULT nextval('setting_id_seq'::regclass) NOT NULL, + user_id integer DEFAULT 0 NOT NULL, + param character varying(255) DEFAULT ''::character varying NOT NULL, + value character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.setting OWNER TO "HaCi2"; + +-- +-- Name: squad_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE squad_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.squad_id_seq OWNER TO "HaCi2"; + +-- +-- Name: squad; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE squad ( + id integer DEFAULT nextval('squad_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + permissions integer DEFAULT 0 NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.squad OWNER TO "HaCi2"; + +-- +-- Name: template_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE template_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.template_id_seq OWNER TO "HaCi2"; + +-- +-- Name: template; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE template ( + id integer DEFAULT nextval('template_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + type character varying(64) DEFAULT ''::character varying NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.template OWNER TO "HaCi2"; + +-- +-- Name: template_entry_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE template_entry_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.template_entry_id_seq OWNER TO "HaCi2"; + +-- +-- Name: template_entry; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE template_entry ( + id integer DEFAULT nextval('template_entry_id_seq'::regclass) NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + type integer DEFAULT 0 NOT NULL, + "position" integer DEFAULT 0 NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + size integer DEFAULT 1 NOT NULL, + entries character varying(1023) DEFAULT ''::character varying NOT NULL, + rows integer DEFAULT 1 NOT NULL, + cols integer DEFAULT 1 NOT NULL +); + + +ALTER TABLE public.template_entry OWNER TO "HaCi2"; + +-- +-- Name: template_value_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE template_value_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.template_value_id_seq OWNER TO "HaCi2"; + +-- +-- Name: template_value; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE template_value ( + id integer DEFAULT nextval('template_value_id_seq'::regclass) NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + tmpl_entry_id integer DEFAULT 0 NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + value bytea NOT NULL +); + + +ALTER TABLE public.template_value OWNER TO "HaCi2"; + +-- +-- Name: audit_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE audit_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.audit_id_seq OWNER TO "HaCi2"; + +-- +-- Name: audit; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE audit ( + id integer DEFAULT nextval('audit_id_seq'::regclass) NOT NULL, + ts timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + username character varying(100) DEFAULT ''::character varying NOT NULL, + access_groups character varying(255) DEFAULT ''::character varying NOT NULL, + action character varying(255) DEFAULT ''::character varying NOT NULL, + object character varying(255) DEFAULT ''::character varying NOT NULL, + value character varying(1024) DEFAULT ''::character varying NOT NULL, + error character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.audit OWNER TO "HaCi2"; + +-- +-- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE user_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.user_id_seq OWNER TO "HaCi2"; + +-- +-- Name: user; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE "user" ( + id integer DEFAULT nextval('user_id_seq'::regclass) NOT NULL, + username character varying(100) DEFAULT ''::character varying NOT NULL, + password character varying(255) DEFAULT ''::character varying NOT NULL, + group_ids character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public."user" OWNER TO "HaCi2"; + + +-- +-- Name: network_ac_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_ac + ADD CONSTRAINT network_ac_net_id_key UNIQUE (net_id, group_id); + + +-- +-- Name: network_ac_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_ac + ADD CONSTRAINT network_ac_pkey PRIMARY KEY (id); + + +-- +-- Name: network_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network + ADD CONSTRAINT network_pkey PRIMARY KEY (id); + + +-- +-- Name: network_plugin_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_plugin + ADD CONSTRAINT network_plugin_net_id_key UNIQUE (net_id, plugin_id); + + +-- +-- Name: network_plugin_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_plugin + ADD CONSTRAINT network_plugin_pkey PRIMARY KEY (id); + + +-- +-- Name: network_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network + ADD CONSTRAINT network_root_id_key UNIQUE (root_id, ipv6_id, network); + + +-- +-- Name: network_v6_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_v6 + ADD CONSTRAINT network_v6_pkey PRIMARY KEY (id, root_id); + + +-- +-- Name: network_v6_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_v6 + ADD CONSTRAINT network_v6_root_id_key UNIQUE (root_id, network_prefix, host_part, cidr); + + +-- +-- Name: plugin_conf_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_conf + ADD CONSTRAINT plugin_conf_net_id_key UNIQUE (net_id, plugin_id, name); + + +-- +-- Name: plugin_conf_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_conf + ADD CONSTRAINT plugin_conf_pkey PRIMARY KEY (id); + + +-- +-- Name: plugin_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin + ADD CONSTRAINT plugin_name_key UNIQUE (name); + + +-- +-- Name: plugin_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin + ADD CONSTRAINT plugin_pkey PRIMARY KEY (id); + + +-- +-- Name: plugin_value_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_value + ADD CONSTRAINT plugin_value_net_id_key UNIQUE (net_id, plugin_id, name); + + +-- +-- Name: plugin_value_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_value + ADD CONSTRAINT plugin_value_pkey PRIMARY KEY (id); + + +-- +-- Name: root_ac_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root_ac + ADD CONSTRAINT root_ac_pkey PRIMARY KEY (id); + + +-- +-- Name: root_ac_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root_ac + ADD CONSTRAINT root_ac_root_id_key UNIQUE (root_id, group_id); + + +-- +-- Name: root_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root + ADD CONSTRAINT root_name_key UNIQUE (name); + + +-- +-- Name: root_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root + ADD CONSTRAINT root_pkey PRIMARY KEY (id); + + +-- +-- Name: setting_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY setting + ADD CONSTRAINT setting_pkey PRIMARY KEY (id); + + +-- +-- Name: setting_user_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY setting + ADD CONSTRAINT setting_user_id_key UNIQUE (user_id, param, value); + + +-- +-- Name: squad_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY squad + ADD CONSTRAINT squad_name_key UNIQUE (name); + + +-- +-- Name: squad_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY squad + ADD CONSTRAINT squad_pkey PRIMARY KEY (id); + + +-- +-- Name: template_entry_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template_entry + ADD CONSTRAINT template_entry_pkey PRIMARY KEY (id); + + +-- +-- Name: template_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template + ADD CONSTRAINT template_name_key UNIQUE (name); + + +-- +-- Name: template_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template + ADD CONSTRAINT template_pkey PRIMARY KEY (id); + + +-- +-- Name: template_value_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template_value + ADD CONSTRAINT template_value_net_id_key UNIQUE (net_id, tmpl_id, tmpl_entry_id); + + +-- +-- Name: template_value_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template_value + ADD CONSTRAINT template_value_pkey PRIMARY KEY (id); + + +-- +-- Name: audit_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY audit + ADD CONSTRAINT audit_pkey PRIMARY KEY (id); + + +-- +-- Name: user_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY "user" + ADD CONSTRAINT user_pkey PRIMARY KEY (id); + + +-- +-- Name: user_username_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY "user" + ADD CONSTRAINT user_username_key UNIQUE (username); + + +-- +-- Name: network_network_idx; Type: INDEX; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE INDEX network_network_idx ON network USING btree (network); + + +-- +-- Name: public; Type: ACL; Schema: -; Owner: postgres +-- + +-- +-- Name: network_lock_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE network_lock_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_lock_id_seq OWNER TO "HaCi2"; + +-- +-- Name: network_lock; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network_lock ( + id integer DEFAULT nextval('network_lock_id_seq'::regclass) NOT NULL, + ts timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + duration integer DEFAULT 0 NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network_prefix numeric(20,0) DEFAULT (0)::numeric NOT NULL, + host_part numeric(20,0) DEFAULT (0)::numeric NOT NULL, + cidr smallint DEFAULT (0)::smallint NOT NULL, + ipv6 smallint DEFAULT (0)::smallint NOT NULL +); + + +ALTER TABLE public.network_lock OWNER TO "HaCi2"; + +-- +-- Name: network_lock_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_lock + ADD CONSTRAINT network_lock_pkey PRIMARY KEY (id); + + +-- +-- Name: network_lock_uniq_network; Type: INDEX; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE UNIQUE INDEX network_lock_uniq_network ON network_lock USING btree (root_id, network_prefix, host_part, cidr, ipv6); + + + +REVOKE ALL ON SCHEMA public FROM PUBLIC; +REVOKE ALL ON SCHEMA public FROM postgres; +GRANT ALL ON SCHEMA public TO postgres; +GRANT ALL ON SCHEMA public TO PUBLIC; + + +-- +-- PostgreSQL database dump complete +-- + diff -Nru haci-0.97c/docs/HaCi_v0.98b-v0.98c.pgsql haci-0.98c/docs/HaCi_v0.98b-v0.98c.pgsql --- haci-0.97c/docs/HaCi_v0.98b-v0.98c.pgsql 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCi_v0.98b-v0.98c.pgsql 2015-03-04 01:19:37.000000000 +0000 @@ -0,0 +1,28 @@ +ALTER TABLE network + ADD COLUMN search_str character varying(255) DEFAULT ''::character varying; + +CREATE INDEX network_description_idx ON network USING btree (description); +CREATE INDEX network_search_str_idx ON network USING btree (search_str); +CREATE SEQUENCE network_tag_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_tag_id_seq OWNER TO "HaCi2"; + +CREATE TABLE network_tag ( + id integer DEFAULT nextval('network_tag_id_seq'::regclass) NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + tag character varying(255) DEFAULT ''::character varying NOT NULL +); + +ALTER TABLE public.network_tag OWNER TO "HaCi2"; + +ALTER TABLE ONLY network_tag + ADD CONSTRAINT network_tag_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY network_tag + ADD CONSTRAINT network_tag_net_id_tag_key UNIQUE (net_id, tag); diff -Nru haci-0.97c/docs/HaCi_v0.98c.mysql haci-0.98c/docs/HaCi_v0.98c.mysql --- haci-0.97c/docs/HaCi_v0.98c.mysql 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCi_v0.98c.mysql 2015-03-04 00:15:52.000000000 +0000 @@ -0,0 +1,396 @@ +-- MySQL dump 10.11 +-- +-- Host: localhost Database: HaCi +-- ------------------------------------------------------ +-- Server version 5.0.51a-24+lenny5 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `CIDRmagic` +-- + +DROP TABLE IF EXISTS `CIDRmagic`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `CIDRmagic` ( + `cidr` int(11) NOT NULL, + `adder` int(10) unsigned NOT NULL, + PRIMARY KEY (`cidr`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `audit` +-- + +DROP TABLE IF EXISTS `audit`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `audit` ( + `ID` int(11) NOT NULL auto_increment, + `ts` datetime NOT NULL default '0000-00-00 00:00:00', + `username` varchar(255) NOT NULL default '', + `accessGroups` varchar(255) NOT NULL default '', + `action` varchar(255) NOT NULL default '', + `object` varchar(255) NOT NULL default '', + `value` text NOT NULL, + `error` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`) +) ENGINE=InnoDB AUTO_INCREMENT=1920 DEFAULT CHARSET=latin1; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `network` +-- + +DROP TABLE IF EXISTS `network`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `network` ( + `ID` int(11) NOT NULL auto_increment, + `rootID` int(11) NOT NULL default '0', + `network` bigint(20) unsigned NOT NULL default '0', + `description` varchar(255) NOT NULL default '', + `state` smallint(6) NOT NULL default '0', + `defSubnetSize` tinyint(4) unsigned NOT NULL default '0', + `tmplID` int(11) NOT NULL default '0', + `ipv6ID` varbinary(22) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + `searchStr` varchar(255) default '', + PRIMARY KEY (`ID`), + UNIQUE KEY `rootID` (`rootID`,`ipv6ID`,`network`), + KEY `network` (`network`), + KEY `description` (`description`), + KEY `searchStr` (`searchStr`) +) ENGINE=InnoDB AUTO_INCREMENT=36230 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkAC` +-- + +DROP TABLE IF EXISTS `networkAC`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkAC` ( + `ID` int(11) NOT NULL auto_increment, + `rootID` int(11) NOT NULL default '0', + `network` bigint(40) NOT NULL default '0', + `netID` int(11) NOT NULL default '0', + `groupID` int(11) NOT NULL default '0', + `ACL` int(11) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`groupID`) +) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkLock` +-- + +DROP TABLE IF EXISTS `networkLock`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkLock` ( + `ID` int(11) NOT NULL auto_increment, + `ts` datetime NOT NULL default '0000-00-00 00:00:00', + `duration` int(11) NOT NULL default '0', + `rootID` int(11) NOT NULL default '0', + `networkPrefix` bigint(20) unsigned NOT NULL default '0', + `hostPart` bigint(20) unsigned NOT NULL default '0', + `cidr` smallint(6) NOT NULL default '0', + `ipv6` smallint(6) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `rootID` (`rootID`,`networkPrefix`,`hostPart`,`cidr`,`ipv6`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkPlugin` +-- + +DROP TABLE IF EXISTS `networkPlugin`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkPlugin` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL default '0', + `pluginID` int(11) NOT NULL default '0', + `sequence` int(11) NOT NULL default '0', + `newLine` tinyint(4) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`pluginID`) +) ENGINE=InnoDB AUTO_INCREMENT=115 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkTag` +-- + +DROP TABLE IF EXISTS `networkTag`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkTag` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL default '0', + `tag` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`tag`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `networkV6` +-- + +DROP TABLE IF EXISTS `networkV6`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `networkV6` ( + `ID` varbinary(22) NOT NULL default '', + `rootID` int(11) NOT NULL default '0', + `networkPrefix` bigint(20) unsigned NOT NULL default '0', + `hostPart` bigint(20) unsigned NOT NULL default '0', + `cidr` smallint(6) NOT NULL default '0', + PRIMARY KEY (`ID`,`rootID`), + UNIQUE KEY `rootID` (`rootID`,`networkPrefix`,`hostPart`,`cidr`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `plugin` +-- + +DROP TABLE IF EXISTS `plugin`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `plugin` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `filename` varchar(255) NOT NULL default '', + `active` tinyint(4) NOT NULL default '0', + `lastRun` datetime NOT NULL default '0000-00-00 00:00:00', + `runTime` int(11) NOT NULL default '0', + `lastError` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `pluginConf` +-- + +DROP TABLE IF EXISTS `pluginConf`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `pluginConf` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL, + `pluginID` int(11) NOT NULL, + `name` varchar(255) NOT NULL, + `value` text NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`pluginID`,`name`) +) ENGINE=InnoDB AUTO_INCREMENT=76 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `pluginValue` +-- + +DROP TABLE IF EXISTS `pluginValue`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `pluginValue` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL, + `pluginID` int(11) NOT NULL, + `origin` int(11) NOT NULL, + `name` varchar(255) NOT NULL, + `value` text NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`pluginID`,`name`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `root` +-- + +DROP TABLE IF EXISTS `root`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `root` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `ipv6` tinyint(1) NOT NULL default '0', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=109 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `rootAC` +-- + +DROP TABLE IF EXISTS `rootAC`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `rootAC` ( + `ID` int(11) NOT NULL auto_increment, + `rootID` int(11) NOT NULL default '0', + `groupID` int(11) NOT NULL default '0', + `ACL` int(11) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `rootID` (`rootID`,`groupID`) +) ENGINE=InnoDB AUTO_INCREMENT=156 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `setting` +-- + +DROP TABLE IF EXISTS `setting`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `setting` ( + `ID` int(11) NOT NULL auto_increment, + `userID` int(11) NOT NULL default '0', + `param` varchar(255) NOT NULL default '', + `value` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY `userID` (`userID`,`param`,`value`) +) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `squad` +-- + +DROP TABLE IF EXISTS `squad`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `squad` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `permissions` int(11) NOT NULL default '0', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `template` +-- + +DROP TABLE IF EXISTS `template`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `template` ( + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `type` varchar(64) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `templateEntry` +-- + +DROP TABLE IF EXISTS `templateEntry`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `templateEntry` ( + `ID` int(11) NOT NULL auto_increment, + `tmplID` int(11) NOT NULL default '0', + `type` int(11) NOT NULL default '0', + `position` int(11) NOT NULL default '0', + `description` varchar(255) NOT NULL default '', + `size` int(11) NOT NULL default '1', + `entries` text NOT NULL, + `rows` int(11) NOT NULL default '1', + `cols` int(11) NOT NULL default '1', + PRIMARY KEY (`ID`) +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `templateValue` +-- + +DROP TABLE IF EXISTS `templateValue`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `templateValue` ( + `ID` int(11) NOT NULL auto_increment, + `tmplID` int(11) NOT NULL default '0', + `tmplEntryID` int(11) NOT NULL default '0', + `netID` int(11) NOT NULL default '0', + `value` blob NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`tmplID`,`tmplEntryID`) +) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `user` ( + `ID` int(11) NOT NULL auto_increment, + `username` varchar(100) NOT NULL default '', + `password` varchar(255) NOT NULL default '', + `groupIDs` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY `username` (`username`) +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2015-01-03 5:02:35 diff -Nru haci-0.97c/docs/HaCi_v0.98c.pgsql haci-0.98c/docs/HaCi_v0.98c.pgsql --- haci-0.97c/docs/HaCi_v0.98c.pgsql 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCi_v0.98c.pgsql 2015-03-04 00:15:52.000000000 +0000 @@ -0,0 +1,863 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; + +SET search_path = public, pg_catalog; + +-- +-- Name: audit_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE audit_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.audit_id_seq OWNER TO "HaCi"; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: audit; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE audit ( + id integer DEFAULT nextval('audit_id_seq'::regclass) NOT NULL, + ts timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + username character varying(100) DEFAULT ''::character varying NOT NULL, + access_groups character varying(255) DEFAULT ''::character varying NOT NULL, + action character varying(255) DEFAULT ''::character varying NOT NULL, + object character varying(255) DEFAULT ''::character varying NOT NULL, + value character varying(1024) DEFAULT ''::character varying NOT NULL, + error character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.audit OWNER TO "HaCi"; + +-- +-- Name: network_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE network_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.network_id_seq OWNER TO "HaCi"; + +-- +-- Name: network; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE network ( + id integer DEFAULT nextval('network_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network bigint DEFAULT (0)::bigint NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + state smallint DEFAULT (0)::smallint NOT NULL, + def_subnet_size smallint DEFAULT (0)::smallint NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + ipv6_id bytea DEFAULT '\x'::bytea NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + search_str character varying(255), + CONSTRAINT network_def_subnet_size_check CHECK ((def_subnet_size >= 0)) +); + + +ALTER TABLE public.network OWNER TO "HaCi"; + +-- +-- Name: network_ac_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE network_ac_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.network_ac_id_seq OWNER TO "HaCi"; + +-- +-- Name: network_ac; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE network_ac ( + id integer DEFAULT nextval('network_ac_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network bigint DEFAULT (0)::bigint NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + group_id integer DEFAULT 0 NOT NULL, + acl integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.network_ac OWNER TO "HaCi"; + +-- +-- Name: network_lock_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE network_lock_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.network_lock_id_seq OWNER TO "HaCi"; + +-- +-- Name: network_lock; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE network_lock ( + id integer DEFAULT nextval('network_lock_id_seq'::regclass) NOT NULL, + ts timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + duration integer DEFAULT 0 NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network_prefix numeric(20,0) DEFAULT (0)::numeric NOT NULL, + host_part numeric(20,0) DEFAULT (0)::numeric NOT NULL, + cidr smallint DEFAULT (0)::smallint NOT NULL, + ipv6 smallint DEFAULT (0)::smallint NOT NULL +); + + +ALTER TABLE public.network_lock OWNER TO "HaCi"; + +-- +-- Name: network_plugin_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE network_plugin_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.network_plugin_id_seq OWNER TO "HaCi"; + +-- +-- Name: network_plugin; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE network_plugin ( + id integer DEFAULT nextval('network_plugin_id_seq'::regclass) NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + plugin_id integer DEFAULT 0 NOT NULL, + sequence integer DEFAULT 0 NOT NULL, + new_line smallint DEFAULT (0)::smallint NOT NULL +); + + +ALTER TABLE public.network_plugin OWNER TO "HaCi"; + +-- +-- Name: network_tag_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE network_tag_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.network_tag_id_seq OWNER TO "HaCi"; + +-- +-- Name: network_tag; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE network_tag ( + id integer DEFAULT nextval('network_tag_id_seq'::regclass) NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + tag character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.network_tag OWNER TO "HaCi"; + +-- +-- Name: network_v6; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE network_v6 ( + id bytea DEFAULT '\x'::bytea NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network_prefix numeric(20,0) DEFAULT (0)::numeric NOT NULL, + host_part numeric(20,0) DEFAULT (0)::numeric NOT NULL, + cidr smallint DEFAULT (0)::smallint NOT NULL, + CONSTRAINT network_v6_host_part_check CHECK ((host_part >= (0)::numeric)), + CONSTRAINT network_v6_network_prefix_check CHECK ((network_prefix >= (0)::numeric)) +); + + +ALTER TABLE public.network_v6 OWNER TO "HaCi"; + +-- +-- Name: plugin_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE plugin_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.plugin_id_seq OWNER TO "HaCi"; + +-- +-- Name: plugin; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE plugin ( + id integer DEFAULT nextval('plugin_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + filename character varying(255) DEFAULT ''::character varying NOT NULL, + active smallint DEFAULT (0)::smallint NOT NULL, + last_run timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + run_time integer DEFAULT 0 NOT NULL, + last_error character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.plugin OWNER TO "HaCi"; + +-- +-- Name: plugin_conf_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE plugin_conf_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.plugin_conf_id_seq OWNER TO "HaCi"; + +-- +-- Name: plugin_conf; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE plugin_conf ( + id integer DEFAULT nextval('plugin_conf_id_seq'::regclass) NOT NULL, + net_id integer NOT NULL, + plugin_id integer NOT NULL, + name character varying(255) NOT NULL, + value text NOT NULL +); + + +ALTER TABLE public.plugin_conf OWNER TO "HaCi"; + +-- +-- Name: plugin_value_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE plugin_value_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.plugin_value_id_seq OWNER TO "HaCi"; + +-- +-- Name: plugin_value; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE plugin_value ( + id integer DEFAULT nextval('plugin_value_id_seq'::regclass) NOT NULL, + net_id integer NOT NULL, + plugin_id integer NOT NULL, + origin integer NOT NULL, + name character varying(255) NOT NULL, + value text NOT NULL +); + + +ALTER TABLE public.plugin_value OWNER TO "HaCi"; + +-- +-- Name: root_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE root_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.root_id_seq OWNER TO "HaCi"; + +-- +-- Name: root; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE root ( + id integer DEFAULT nextval('root_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + ipv6 smallint DEFAULT (0)::smallint NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.root OWNER TO "HaCi"; + +-- +-- Name: root_ac_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE root_ac_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.root_ac_id_seq OWNER TO "HaCi"; + +-- +-- Name: root_ac; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE root_ac ( + id integer DEFAULT nextval('root_ac_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + group_id integer DEFAULT 0 NOT NULL, + acl integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.root_ac OWNER TO "HaCi"; + +-- +-- Name: setting_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE setting_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.setting_id_seq OWNER TO "HaCi"; + +-- +-- Name: setting; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE setting ( + id integer DEFAULT nextval('setting_id_seq'::regclass) NOT NULL, + user_id integer DEFAULT 0 NOT NULL, + param character varying(255) DEFAULT ''::character varying NOT NULL, + value character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.setting OWNER TO "HaCi"; + +-- +-- Name: squad_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE squad_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.squad_id_seq OWNER TO "HaCi"; + +-- +-- Name: squad; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE squad ( + id integer DEFAULT nextval('squad_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + permissions integer DEFAULT 0 NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.squad OWNER TO "HaCi"; + +-- +-- Name: template_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE template_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.template_id_seq OWNER TO "HaCi"; + +-- +-- Name: template; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE template ( + id integer DEFAULT nextval('template_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + type character varying(64) DEFAULT ''::character varying NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.template OWNER TO "HaCi"; + +-- +-- Name: template_entry_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE template_entry_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.template_entry_id_seq OWNER TO "HaCi"; + +-- +-- Name: template_entry; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE template_entry ( + id integer DEFAULT nextval('template_entry_id_seq'::regclass) NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + type integer DEFAULT 0 NOT NULL, + "position" integer DEFAULT 0 NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + size integer DEFAULT 1 NOT NULL, + entries character varying(1023) DEFAULT ''::character varying NOT NULL, + rows integer DEFAULT 1 NOT NULL, + cols integer DEFAULT 1 NOT NULL +); + + +ALTER TABLE public.template_entry OWNER TO "HaCi"; + +-- +-- Name: template_value_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE template_value_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.template_value_id_seq OWNER TO "HaCi"; + +-- +-- Name: template_value; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE template_value ( + id integer DEFAULT nextval('template_value_id_seq'::regclass) NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + tmpl_entry_id integer DEFAULT 0 NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + value bytea NOT NULL +); + + +ALTER TABLE public.template_value OWNER TO "HaCi"; + +-- +-- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi +-- + +CREATE SEQUENCE user_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.user_id_seq OWNER TO "HaCi"; + +-- +-- Name: user; Type: TABLE; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE TABLE "user" ( + id integer DEFAULT nextval('user_id_seq'::regclass) NOT NULL, + username character varying(100) DEFAULT ''::character varying NOT NULL, + password character varying(255) DEFAULT ''::character varying NOT NULL, + group_ids character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public."user" OWNER TO "HaCi"; + +-- +-- Name: audit_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY audit + ADD CONSTRAINT audit_pkey PRIMARY KEY (id); + + +-- +-- Name: network_ac_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_ac + ADD CONSTRAINT network_ac_net_id_key UNIQUE (net_id, group_id); + + +-- +-- Name: network_ac_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_ac + ADD CONSTRAINT network_ac_pkey PRIMARY KEY (id); + + +-- +-- Name: network_lock_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_lock + ADD CONSTRAINT network_lock_pkey PRIMARY KEY (id); + + +-- +-- Name: network_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network + ADD CONSTRAINT network_pkey PRIMARY KEY (id); + + +-- +-- Name: network_plugin_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_plugin + ADD CONSTRAINT network_plugin_net_id_key UNIQUE (net_id, plugin_id); + + +-- +-- Name: network_plugin_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_plugin + ADD CONSTRAINT network_plugin_pkey PRIMARY KEY (id); + + +-- +-- Name: network_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network + ADD CONSTRAINT network_root_id_key UNIQUE (root_id, ipv6_id, network); + + +-- +-- Name: network_tag_net_id_tag_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_tag + ADD CONSTRAINT network_tag_net_id_tag_key UNIQUE (net_id, tag); + + +-- +-- Name: network_tag_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_tag + ADD CONSTRAINT network_tag_pkey PRIMARY KEY (id); + + +-- +-- Name: network_v6_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_v6 + ADD CONSTRAINT network_v6_pkey PRIMARY KEY (id, root_id); + + +-- +-- Name: network_v6_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY network_v6 + ADD CONSTRAINT network_v6_root_id_key UNIQUE (root_id, network_prefix, host_part, cidr); + + +-- +-- Name: plugin_conf_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY plugin_conf + ADD CONSTRAINT plugin_conf_net_id_key UNIQUE (net_id, plugin_id, name); + + +-- +-- Name: plugin_conf_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY plugin_conf + ADD CONSTRAINT plugin_conf_pkey PRIMARY KEY (id); + + +-- +-- Name: plugin_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY plugin + ADD CONSTRAINT plugin_name_key UNIQUE (name); + + +-- +-- Name: plugin_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY plugin + ADD CONSTRAINT plugin_pkey PRIMARY KEY (id); + + +-- +-- Name: plugin_value_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY plugin_value + ADD CONSTRAINT plugin_value_net_id_key UNIQUE (net_id, plugin_id, name); + + +-- +-- Name: plugin_value_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY plugin_value + ADD CONSTRAINT plugin_value_pkey PRIMARY KEY (id); + + +-- +-- Name: root_ac_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY root_ac + ADD CONSTRAINT root_ac_pkey PRIMARY KEY (id); + + +-- +-- Name: root_ac_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY root_ac + ADD CONSTRAINT root_ac_root_id_key UNIQUE (root_id, group_id); + + +-- +-- Name: root_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY root + ADD CONSTRAINT root_name_key UNIQUE (name); + + +-- +-- Name: root_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY root + ADD CONSTRAINT root_pkey PRIMARY KEY (id); + + +-- +-- Name: setting_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY setting + ADD CONSTRAINT setting_pkey PRIMARY KEY (id); + + +-- +-- Name: setting_user_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY setting + ADD CONSTRAINT setting_user_id_key UNIQUE (user_id, param, value); + + +-- +-- Name: squad_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY squad + ADD CONSTRAINT squad_name_key UNIQUE (name); + + +-- +-- Name: squad_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY squad + ADD CONSTRAINT squad_pkey PRIMARY KEY (id); + + +-- +-- Name: template_entry_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY template_entry + ADD CONSTRAINT template_entry_pkey PRIMARY KEY (id); + + +-- +-- Name: template_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY template + ADD CONSTRAINT template_name_key UNIQUE (name); + + +-- +-- Name: template_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY template + ADD CONSTRAINT template_pkey PRIMARY KEY (id); + + +-- +-- Name: template_value_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY template_value + ADD CONSTRAINT template_value_net_id_key UNIQUE (net_id, tmpl_id, tmpl_entry_id); + + +-- +-- Name: template_value_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY template_value + ADD CONSTRAINT template_value_pkey PRIMARY KEY (id); + + +-- +-- Name: user_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY "user" + ADD CONSTRAINT user_pkey PRIMARY KEY (id); + + +-- +-- Name: user_username_key; Type: CONSTRAINT; Schema: public; Owner: HaCi; Tablespace: +-- + +ALTER TABLE ONLY "user" + ADD CONSTRAINT user_username_key UNIQUE (username); + + +-- +-- Name: network_description_idx; Type: INDEX; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE INDEX network_description_idx ON network USING btree (description); + + +-- +-- Name: network_lock_uniq_network; Type: INDEX; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE UNIQUE INDEX network_lock_uniq_network ON network_lock USING btree (root_id, network_prefix, host_part, cidr, ipv6); + + +-- +-- Name: network_network_idx; Type: INDEX; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE INDEX network_network_idx ON network USING btree (network); + + +-- +-- Name: network_search_str_idx; Type: INDEX; Schema: public; Owner: HaCi; Tablespace: +-- + +CREATE INDEX network_search_str_idx ON network USING btree (search_str); + + +-- +-- Name: public; Type: ACL; Schema: -; Owner: postgres +-- + +REVOKE ALL ON SCHEMA public FROM PUBLIC; +REVOKE ALL ON SCHEMA public FROM postgres; +GRANT ALL ON SCHEMA public TO postgres; +GRANT ALL ON SCHEMA public TO PUBLIC; + + +-- +-- PostgreSQL database dump complete +-- + diff -Nru haci-0.97c/docs/HaCi_v0.98.psql haci-0.98c/docs/HaCi_v0.98.psql --- haci-0.97c/docs/HaCi_v0.98.psql 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCi_v0.98.psql 2015-03-04 01:19:31.000000000 +0000 @@ -0,0 +1,711 @@ +-- +-- PostgreSQL database dump +-- + +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = off; +SET check_function_bodies = false; +SET client_min_messages = warning; +SET escape_string_warning = off; + +-- +-- Name: HaCi2; Type: COMMENT; Schema: -; Owner: postgres +-- + +COMMENT ON DATABASE "HaCi2" IS 'HaCi2'; + + +SET search_path = public, pg_catalog; + +-- +-- Name: network_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE network_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_id_seq OWNER TO "HaCi2"; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: network; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network ( + id integer DEFAULT nextval('network_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network bigint DEFAULT 0::bigint NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + state smallint DEFAULT 0::smallint NOT NULL, + def_subnet_size smallint DEFAULT 0::smallint NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + ipv6_id bytea DEFAULT ''::bytea NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + CONSTRAINT network_def_subnet_size_check CHECK ((def_subnet_size >= 0)) +); + + +ALTER TABLE public.network OWNER TO "HaCi2"; + +-- +-- Name: network_ac_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE network_ac_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_ac_id_seq OWNER TO "HaCi2"; + +-- +-- Name: network_ac; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network_ac ( + id integer DEFAULT nextval('network_ac_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network bigint DEFAULT 0::bigint NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + group_id integer DEFAULT 0 NOT NULL, + acl integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.network_ac OWNER TO "HaCi2"; + +-- +-- Name: network_plugin_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE network_plugin_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_plugin_id_seq OWNER TO "HaCi2"; + +-- +-- Name: network_plugin; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network_plugin ( + id integer DEFAULT nextval('network_plugin_id_seq'::regclass) NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + plugin_id integer DEFAULT 0 NOT NULL, + sequence integer DEFAULT 0 NOT NULL, + new_line smallint DEFAULT 0::smallint NOT NULL +); + + +ALTER TABLE public.network_plugin OWNER TO "HaCi2"; + +-- +-- Name: network_v6; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE network_v6 ( + id bytea DEFAULT ''::bytea NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network_prefix numeric(20,0) DEFAULT (0)::numeric NOT NULL, + host_part numeric(20,0) DEFAULT (0)::numeric NOT NULL, + cidr smallint DEFAULT 0::smallint NOT NULL, + CONSTRAINT network_v6_host_part_check CHECK ((host_part >= (0)::numeric)), + CONSTRAINT network_v6_network_prefix_check CHECK ((network_prefix >= (0)::numeric)) +); + + +ALTER TABLE public.network_v6 OWNER TO "HaCi2"; + +-- +-- Name: plugin_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE plugin_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.plugin_id_seq OWNER TO "HaCi2"; + +-- +-- Name: plugin; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE plugin ( + id integer DEFAULT nextval('plugin_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + filename character varying(255) DEFAULT ''::character varying NOT NULL, + active smallint DEFAULT 0::smallint NOT NULL, + last_run timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + run_time integer DEFAULT 0 NOT NULL, + last_error character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.plugin OWNER TO "HaCi2"; + +-- +-- Name: plugin_conf_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE plugin_conf_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.plugin_conf_id_seq OWNER TO "HaCi2"; + +-- +-- Name: plugin_conf; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE plugin_conf ( + id integer DEFAULT nextval('plugin_conf_id_seq'::regclass) NOT NULL, + net_id integer NOT NULL, + plugin_id integer NOT NULL, + name character varying(255) NOT NULL, + value text NOT NULL +); + + +ALTER TABLE public.plugin_conf OWNER TO "HaCi2"; + +-- +-- Name: plugin_value_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE plugin_value_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.plugin_value_id_seq OWNER TO "HaCi2"; + +-- +-- Name: plugin_value; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE plugin_value ( + id integer DEFAULT nextval('plugin_value_id_seq'::regclass) NOT NULL, + net_id integer NOT NULL, + plugin_id integer NOT NULL, + origin integer NOT NULL, + name character varying(255) NOT NULL, + value text NOT NULL +); + + +ALTER TABLE public.plugin_value OWNER TO "HaCi2"; + +-- +-- Name: root_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE root_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.root_id_seq OWNER TO "HaCi2"; + +-- +-- Name: root; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE root ( + id integer DEFAULT nextval('root_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + ipv6 smallint DEFAULT 0::smallint NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.root OWNER TO "HaCi2"; + +-- +-- Name: root_ac_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE root_ac_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.root_ac_id_seq OWNER TO "HaCi2"; + +-- +-- Name: root_ac; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE root_ac ( + id integer DEFAULT nextval('root_ac_id_seq'::regclass) NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + group_id integer DEFAULT 0 NOT NULL, + acl integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.root_ac OWNER TO "HaCi2"; + +-- +-- Name: setting_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE setting_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.setting_id_seq OWNER TO "HaCi2"; + +-- +-- Name: setting; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE setting ( + id integer DEFAULT nextval('setting_id_seq'::regclass) NOT NULL, + user_id integer DEFAULT 0 NOT NULL, + param character varying(255) DEFAULT ''::character varying NOT NULL, + value character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.setting OWNER TO "HaCi2"; + +-- +-- Name: squad_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE squad_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.squad_id_seq OWNER TO "HaCi2"; + +-- +-- Name: squad; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE squad ( + id integer DEFAULT nextval('squad_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + permissions integer DEFAULT 0 NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.squad OWNER TO "HaCi2"; + +-- +-- Name: template_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE template_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.template_id_seq OWNER TO "HaCi2"; + +-- +-- Name: template; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE template ( + id integer DEFAULT nextval('template_id_seq'::regclass) NOT NULL, + name character varying(255) DEFAULT ''::character varying NOT NULL, + type character varying(64) DEFAULT ''::character varying NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public.template OWNER TO "HaCi2"; + +-- +-- Name: template_entry_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE template_entry_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.template_entry_id_seq OWNER TO "HaCi2"; + +-- +-- Name: template_entry; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE template_entry ( + id integer DEFAULT nextval('template_entry_id_seq'::regclass) NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + type integer DEFAULT 0 NOT NULL, + "position" integer DEFAULT 0 NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + size integer DEFAULT 1 NOT NULL, + entries character varying(255) DEFAULT ''::character varying NOT NULL, + rows integer DEFAULT 1 NOT NULL, + cols integer DEFAULT 1 NOT NULL +); + + +ALTER TABLE public.template_entry OWNER TO "HaCi2"; + +-- +-- Name: template_value_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE template_value_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.template_value_id_seq OWNER TO "HaCi2"; + +-- +-- Name: template_value; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE template_value ( + id integer DEFAULT nextval('template_value_id_seq'::regclass) NOT NULL, + tmpl_id integer DEFAULT 0 NOT NULL, + tmpl_entry_id integer DEFAULT 0 NOT NULL, + net_id integer DEFAULT 0 NOT NULL, + value bytea NOT NULL +); + + +ALTER TABLE public.template_value OWNER TO "HaCi2"; + +-- +-- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: HaCi2 +-- + +CREATE SEQUENCE user_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.user_id_seq OWNER TO "HaCi2"; + +-- +-- Name: user; Type: TABLE; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE TABLE "user" ( + id integer DEFAULT nextval('user_id_seq'::regclass) NOT NULL, + username character varying(100) DEFAULT ''::character varying NOT NULL, + password character varying(255) DEFAULT ''::character varying NOT NULL, + group_ids character varying(255) DEFAULT ''::character varying NOT NULL, + description character varying(255) DEFAULT ''::character varying NOT NULL, + create_from character varying(255) DEFAULT ''::character varying NOT NULL, + create_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + modify_from character varying(255) DEFAULT ''::character varying NOT NULL, + modify_date timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL +); + + +ALTER TABLE public."user" OWNER TO "HaCi2"; + +-- +-- Name: network_ac_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_ac + ADD CONSTRAINT network_ac_net_id_key UNIQUE (net_id, group_id); + + +-- +-- Name: network_ac_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_ac + ADD CONSTRAINT network_ac_pkey PRIMARY KEY (id); + + +-- +-- Name: network_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network + ADD CONSTRAINT network_pkey PRIMARY KEY (id); + + +-- +-- Name: network_plugin_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_plugin + ADD CONSTRAINT network_plugin_net_id_key UNIQUE (net_id, plugin_id); + + +-- +-- Name: network_plugin_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_plugin + ADD CONSTRAINT network_plugin_pkey PRIMARY KEY (id); + + +-- +-- Name: network_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network + ADD CONSTRAINT network_root_id_key UNIQUE (root_id, ipv6_id, network); + + +-- +-- Name: network_v6_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_v6 + ADD CONSTRAINT network_v6_pkey PRIMARY KEY (id, root_id); + + +-- +-- Name: network_v6_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY network_v6 + ADD CONSTRAINT network_v6_root_id_key UNIQUE (root_id, network_prefix, host_part, cidr); + + +-- +-- Name: plugin_conf_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_conf + ADD CONSTRAINT plugin_conf_net_id_key UNIQUE (net_id, plugin_id, name); + + +-- +-- Name: plugin_conf_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_conf + ADD CONSTRAINT plugin_conf_pkey PRIMARY KEY (id); + + +-- +-- Name: plugin_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin + ADD CONSTRAINT plugin_name_key UNIQUE (name); + + +-- +-- Name: plugin_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin + ADD CONSTRAINT plugin_pkey PRIMARY KEY (id); + + +-- +-- Name: plugin_value_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_value + ADD CONSTRAINT plugin_value_net_id_key UNIQUE (net_id, plugin_id, name); + + +-- +-- Name: plugin_value_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY plugin_value + ADD CONSTRAINT plugin_value_pkey PRIMARY KEY (id); + + +-- +-- Name: root_ac_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root_ac + ADD CONSTRAINT root_ac_pkey PRIMARY KEY (id); + + +-- +-- Name: root_ac_root_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root_ac + ADD CONSTRAINT root_ac_root_id_key UNIQUE (root_id, group_id); + + +-- +-- Name: root_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root + ADD CONSTRAINT root_name_key UNIQUE (name); + + +-- +-- Name: root_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY root + ADD CONSTRAINT root_pkey PRIMARY KEY (id); + + +-- +-- Name: setting_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY setting + ADD CONSTRAINT setting_pkey PRIMARY KEY (id); + + +-- +-- Name: setting_user_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY setting + ADD CONSTRAINT setting_user_id_key UNIQUE (user_id, param, value); + + +-- +-- Name: squad_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY squad + ADD CONSTRAINT squad_name_key UNIQUE (name); + + +-- +-- Name: squad_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY squad + ADD CONSTRAINT squad_pkey PRIMARY KEY (id); + + +-- +-- Name: template_entry_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template_entry + ADD CONSTRAINT template_entry_pkey PRIMARY KEY (id); + + +-- +-- Name: template_name_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template + ADD CONSTRAINT template_name_key UNIQUE (name); + + +-- +-- Name: template_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template + ADD CONSTRAINT template_pkey PRIMARY KEY (id); + + +-- +-- Name: template_value_net_id_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template_value + ADD CONSTRAINT template_value_net_id_key UNIQUE (net_id, tmpl_id, tmpl_entry_id); + + +-- +-- Name: template_value_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY template_value + ADD CONSTRAINT template_value_pkey PRIMARY KEY (id); + + +-- +-- Name: user_pkey; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY "user" + ADD CONSTRAINT user_pkey PRIMARY KEY (id); + + +-- +-- Name: user_username_key; Type: CONSTRAINT; Schema: public; Owner: HaCi2; Tablespace: +-- + +ALTER TABLE ONLY "user" + ADD CONSTRAINT user_username_key UNIQUE (username); + + +-- +-- Name: network_network_idx; Type: INDEX; Schema: public; Owner: HaCi2; Tablespace: +-- + +CREATE INDEX network_network_idx ON network USING btree (network); + + +-- +-- Name: public; Type: ACL; Schema: -; Owner: postgres +-- + +REVOKE ALL ON SCHEMA public FROM PUBLIC; +REVOKE ALL ON SCHEMA public FROM postgres; +GRANT ALL ON SCHEMA public TO postgres; +GRANT ALL ON SCHEMA public TO PUBLIC; + + +-- +-- PostgreSQL database dump complete +-- + diff -Nru haci-0.97c/docs/HaCi_v0.98-v0.98b.pgsql haci-0.98c/docs/HaCi_v0.98-v0.98b.pgsql --- haci-0.97c/docs/HaCi_v0.98-v0.98b.pgsql 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCi_v0.98-v0.98b.pgsql 2015-03-04 00:15:52.000000000 +0000 @@ -0,0 +1,55 @@ + +ALTER TABLE template_entry + ALTER COLUMN entries TYPE character varying(1023) /* TYPE change - table: template_entry original: character varying(255) new: character varying(1023) */; + +CREATE SEQUENCE audit_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + +ALTER TABLE public.audit_id_seq OWNER TO "HaCi"; + +CREATE TABLE audit ( + id integer DEFAULT nextval('audit_id_seq'::regclass) NOT NULL, + ts timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + username character varying(100) DEFAULT ''::character varying NOT NULL, + access_groups character varying(255) DEFAULT ''::character varying NOT NULL, + action character varying(255) DEFAULT ''::character varying NOT NULL, + object character varying(255) DEFAULT ''::character varying NOT NULL, + value character varying(1024) DEFAULT ''::character varying NOT NULL, + error character varying(255) DEFAULT ''::character varying NOT NULL +); + +ALTER TABLE audit + ADD CONSTRAINT audit_pkey PRIMARY KEY (id); + +ALTER TABLE public."audit" OWNER TO "HaCi"; +CREATE SEQUENCE network_lock_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.network_lock_id_seq OWNER TO "HaCi"; + +CREATE TABLE network_lock ( + id integer DEFAULT nextval('network_lock_id_seq'::regclass) NOT NULL, + ts timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, + duration integer DEFAULT 0 NOT NULL, + root_id integer DEFAULT 0 NOT NULL, + network_prefix numeric(20,0) DEFAULT (0)::numeric NOT NULL, + host_part numeric(20,0) DEFAULT (0)::numeric NOT NULL, + cidr smallint DEFAULT (0)::smallint NOT NULL, + ipv6 smallint DEFAULT (0)::smallint NOT NULL +); + +ALTER TABLE public.network_lock OWNER TO "HaCi"; + +ALTER TABLE ONLY network_lock + ADD CONSTRAINT network_lock_pkey PRIMARY KEY (id); + +CREATE UNIQUE INDEX network_lock_uniq_network ON network_lock USING btree (root_id, network_prefix, host_part, cidr, ipv6); + diff -Nru haci-0.97c/docs/HaCiXMLRPC-API.txt haci-0.98c/docs/HaCiXMLRPC-API.txt --- haci-0.97c/docs/HaCiXMLRPC-API.txt 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCiXMLRPC-API.txt 2015-02-16 00:46:27.000000000 +0000 @@ -0,0 +1,234 @@ +Class XMLRPC + This class provides a XML-RPC API for HaCi. + + Basic usage: + + my $api = new Frontier::Client(url => "http://$server/RPC2"); + my $session = $api->call('login', [$user, $pass]); + die 'Login failed!' unless $session; + + print Dumper($api->call($method, $session, @args)); + + $api->call('logout', $session); + + exit 0; + + login() + Login and return your session + + Params + + Returns + - session [string] session token you can use for authentication + + logout() + Logout + + Params + + Returns + + search() + Search networks + + Params + - search [string] string to search for + - state [string] filter the result by that network state (ALLOCATED PA, ASSIGNED, ...) + - exact [string] don't do a substring search + - template name [string] filter the result by that template name + - template query [hash] filter the result by defining special values for template entries (i.e.: {name => 'POOL1'}) + - root name [string] limit the search in that root + - nrOfFreeSubs [boolean] compute the number of free subnets in each found network + - withDetails [boolean] show details for found networks + - tags [string] return only networks with this tags, seperate with spaces (i.e.: 'OR foo bar', 'AND foo bar') + Returns + - networks [array] array of found network blocks (hash) + - netID + - network + - rootName + - description + - state + - nrOfFreeSubs + Example + my $networks = search('Test', 'ASSIGNED', 0, 'DSL-POOL', {name => 'Pool1'}, 'DSL-Test-Pool-Root', 0); + + getFreeSubnets() + Find free subnets in a specified root and supernet and return the + wanted amount of subnets + + Params + - root name [string] search free subnets in that root + - supernet [network] search free subnets in that supernet (e.g. 192.168.0.0/24, 2001::/120) + - cidr [integer] specify the target cidr of your subnets (e.g. 30) + - amount [integer] how many subnets you want to get + Returns + - networks [array] array of free subnets found (hash) + - network + Example + my $freeSubnets = getFreeSubnets('Test root', '10.184.120.0/23', 32, 1); + + getFreeSubnetsFromSearch() + Search networks and return free subnets from them + + Params + - search [string] string to search for + - state [string] filter the result by that network state (ALLOCATED PA, ASSIGNED, ...) + - exact [string] don't do a substring search + - template name [string] filter the result by that template name + - template query [hash] filter the result by defining special values for template entries (i.e.: {name => 'POOL1'}) + - root name [string] limit the search in that root + - cidr [integer] specify the target cidr of your subnets (e.g. 30) + - amount [integer] how many subnets you want to get + Returns + - networks [array] array of free subnets found (hash) + - network + - root name + Example + my $freeSubnets = getFreeSubnetsFromSearch('search me', '', 1, '', {}, 'Test-Root', 29, 3); + + listRoots() + Add a root to HaCi + + Params + Returns + - roots [array] array of found roots (hash) + - ID + - name + - ipv6 (boolean) + + addRoot() + Add a root to HaCi + + Params + - root name [string] add a root with this name + - description [string] description of the root + - ipv6 [boolean] this root contains IPv6 networks + Returns + - success [string] 0 on success, error-String at error + + editRoot() + Edit an existing root + + Params + - root name [string] edit this root + - new root name [string] change root name + - description [string] new description of the root + Returns + - success [string] 0 on success, error-String at error + + delRoot() + Delete a root from HaCi + + Params + - root name [string] remove the root + Returns + - success [string] 0 on success, error-String at error + + addNet() + Add a network to HaCi + + Params + - root name [string] add the network to this root + - network [network] add this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + - description [string] description of the network + - state [string] state of the network (e.g. ALLOCATED PA, ASSIGNED, ...) + - def subnet Size [integer] define a default subnet cidr size (e.g. 30) + - template name [string] assign a template to the network + - template values [hash] pass template values (e.g. {hostname => 'abc.de', os => 'redhat'}) + - tags [string] add tags (seperate by comma) + Returns + - success [string] 0 on success, error-String at error + + editNet() + Edit an existing network + + Params + - root name [string] edit the network in this root + - network [network] edit this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + - changes [hash] changes (valid attributes are: network description state rootName defSubnetSize tmplName tmplValues) + e.g.: + {description => 'test_8'} + {network => '192.168.0.8/29', defSubnetSize=>30, state=>'FREE', rootName=>'larsux.de'} + Returns + - success [string] 0 on success, error-String at error + + delNet() + Delete a network from HaCi + + Params + - root name [string] remove the netork from this root + - network [network] remove this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + - network lock [integer] lock network for X seconds + - withSubnets [boolean] also remve subnets + Returns + - success [string] 0 on success, error-String at error + + assignFreeSubnet() + Find the next free subnet and assign it in one step + + Params + - root name [string] search free subnets in that root + - supernet [network] search free subnets in that supernet (e.g. 192.168.0.0/24, 2001::/120) + - cidr [integer] specify the target cidr of your subnets (e.g. 30) + - description [string] description of the network + - state [string] state of the network (e.g. ALLOCATED PA, ASSIGNED, ...) + - def subnet Size [integer] define a default subnet cidr size (e.g. 30) + - template name [string] assign a template to the network + - template values [hash] pass template values (e.g. {hostname => 'abc.de', os => 'redhat'}) + Returns + - network details [hash] new network assigned: + - netID + - network + - modify date + - ipv6 (boolean) + - description + - state + - create from + - create date + - default subnet cidr size + - template name + - modify from + + getNetworkDetails() + Get details from a network in HaCi + + Params + - root name [string] get details of a network in this root + - network [network] get details of this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + Returns + - network [hash] network details: + - netID + - network + - modify date + - ipv6 (boolean) + - description + - state + - create from + - create date + - default subnet cidr size + - template name + - modify from + + getSubnets() + Get subnets from a root and optional from a supernet + + Params + - root name [string] get subnets from this root + - supernet [network] get subnets from this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + Returns + - networks [array] array of found networks (hash) + - netID + - network + - modify date + - ipv6 (boolean) + - description + - state + - create from + - create date + - default subnet cidr size + - template name + - modify from + Example + my $subnets = getSubnets('Test'); + my $subnets = getSubnets('Test', '192.168.0.0/24'); + diff -Nru haci-0.97c/docs/HaCiXMLRPCClient.pl haci-0.98c/docs/HaCiXMLRPCClient.pl --- haci-0.97c/docs/HaCiXMLRPCClient.pl 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/HaCiXMLRPCClient.pl 2015-02-16 00:46:27.000000000 +0000 @@ -0,0 +1,88 @@ +#!/usr/bin/perl + +# Demo script using all available functions of the HaCi XMPRPC-API + +use strict; +use warnings; +use Data::Dumper; +use Frontier::Client; + +#my $server = 'demo.haci.larsux.de'; +my $server = 'hacidev.larsux.de'; +my $user = 'admin'; +my $pass = 'admin'; +my $a = $ARGV[0] || 0; + +my $api = new Frontier::Client(url => "http://$server/RPC2"); +my $session = $api->call('login', [$user, $pass]); +die 'Login failed!' unless $session; + +$a = 999 if $a && $a !~ /^\d+$/; + +if (!$a) { + print "USAGE $0 Number + +Options: + Number: + 1: search + 2: getFreeSubnets + 3: getFreeSubnetsFromSearch + 4: listRoots + 5: addRoot + 6: editRoot + 7: delRoot + 8: addNet + 9: editNet + 10: delNet + 11: assignFreeSubnet + 12: getNetworkDetails + 13: getSubnets + + +"; + exit 0; +} +elsif ($a == 1) { + print Dumper($api->call('search', $session, 'test', 0, 0, 'Pool', {'Pool-Typ' => 'DSL'}, 'testRoot', 1, 1)); +} +elsif ($a == 2) { + print Dumper($api->call('getFreeSubnets', $session, 'testRoot', '192.168.0.0/24', 29, 10)); +} +elsif ($a == 3) { + print Dumper($api->call('getFreeSubnetsFromSearch', $session, 'HaCiAPI', 0, 0, 'Pool', {'Pool-Typ' => 'DSL'}, 'testRoot', 29, 10)); +} +elsif ($a == 4) { + print Dumper($api->call('listRoots', $session)); +} +elsif ($a == 5) { + print Dumper($api->call('addRoot', $session, 'testRoot', 'Test Root', 0)); +} +elsif ($a == 6) { + print Dumper($api->call('editRoot', $session, 'testRoot', 'Testroot', 'tEST rOOT')); +} +elsif ($a == 7) { + print Dumper($api->call('delRoot', $session, 'Testroot')); +} +elsif ($a == 8) { + print Dumper($api->call('addNet', $session, 'testRoot', '192.168.0.128/25', 'HaCiAPI Test Network', 'ASSIGNED PI', 29, 'Pool', {'Pool-Typ' => 'DSL', Name => 'TEST'})); +} +elsif ($a == 9) { + print Dumper($api->call('editNet', $session, 'testRoot', '192.168.0.128/25', {description => 'HaCiAPI Test Network modified', state => 'FREE', defSubnetSize => 27})); +} +elsif ($a == 10) { + print Dumper($api->call('delNet', $session, 'testRoot', '192.168.0.128/25')); +} +elsif ($a == 11) { + print Dumper($api->call('assignFreeSubnet', $session, 'testRoot', '192.168.0.128/25', 29, 'test29er under testRoot', '', 32, 'Pool', {'Pool-Typ' => 'DSL', Name => 'TEST'})); +} +elsif ($a == 12) { + print Dumper($api->call('getNetworkDetails', $session, 'testRoot', '192.168.0.128/25')); +} +elsif ($a == 13) { + print Dumper($api->call('getSubnets', $session, 'testRoot', '192.168.0.128/25')); +} else { + my $method = shift @ARGV; + print Dumper($api->call($method, $session, @ARGV)); +} + +exit 0; diff -Nru haci-0.97c/docs/manualDatabaseUpgrades_mysql.txt haci-0.98c/docs/manualDatabaseUpgrades_mysql.txt --- haci-0.97c/docs/manualDatabaseUpgrades_mysql.txt 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/docs/manualDatabaseUpgrades_mysql.txt 2015-03-04 00:15:52.000000000 +0000 @@ -0,0 +1,82 @@ +# These are the database scheme changes between different HaCi versions. New tables were created by HaCi automatically. +# Also those changes where automatically performed by HaCi. +# Since version 0.97 there's a config option 'autoUpgradeDatabase', which gives you the opportunity to enable resp. disable the automatic upgrade function. + + +0.75 -> 0.8: +ALTER TABLE network DROP INDEX network; +ALTER TABLE network ADD COLUMN ipv6ID varchar(22) NOT NULL DEFAULT ''; +ALTER TABLE network ADD UNIQUE (network, rootID, ipv6ID); + +ALTER TABLE root ADD COLUMN ipv6 tinyint(1) NOT NULL DEFAULT '0'; + +ALTER TABLE networkAC DROP INDEX rootID; +ALTER TABLE networkAC ADD COLUMN netID integer(11) NOT NULL DEFAULT '0'; +ALTER TABLE networkAC ADD UNIQUE (netID, groupID); + + +0.8 -> 0.91 +ALTER TABLE plugin DROP COLUMN date; +ALTER TABLE plugin ADD COLUMN runTime integer(11) NOT NULL DEFAULT '0'; +ALTER TABLE plugin ADD COLUMN lastError varchar(255) NOT NULL DEFAULT ''; + +ALTER TABLE networkPlugin ADD COLUMN sequence integer(11) NOT NULL DEFAULT '0'; +ALTER TABLE networkPlugin ADD COLUMN newLine tinyint(4) NOT NULL DEFAULT '0'; + + +0.91 -> 0.95 +ALTER TABLE plugin ADD COLUMN filename varchar(255) NOT NULL DEFAULT ''; + +ALTER TABLE network ADD COLUMN defSubnetSize TINYINT(4) unsigned NOT NULL DEFAULT '0'; +ALTER TABLE network ADD INDEX (network); + + +0.95 -> 0.96 +ALTER TABLE network CHANGE COLUMN ipv6ID ipv6ID varbinary(22) NOT NULL DEFAULT ''; + +ALTER TABLE networkV6 CHANGE COLUMN ID ID varbinary(22) NOT NULL DEFAULT ''; + +0.96 -> 0.97 +ALTER TABLE networkV6 CHANGE COLUMN networkPrefix networkPrefix bigint(20) unsigned NOT NULL DEFAULT '0'; +ALTER TABLE networkV6 CHANGE COLUMN hostPart hostPart bigint(20) unsigned NOT NULL DEFAULT '0'; + +0.97 -> 0.98 +ALTER TABLE templateEntry CHANGE COLUMN entries entries text NOT NULL; +CREATE TABLE `audit` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `ts` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `username` varchar(255) NOT NULL DEFAULT '', + `accessGroups` varchar(255) NOT NULL DEFAULT '', + `action` varchar(255) NOT NULL DEFAULT '', + `object` varchar(255) NOT NULL DEFAULT '', + `value` text NOT NULL, + `error` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +0.98 -> 0.98b +CREATE TABLE `networkLock` ( + `ID` int(11) NOT NULL auto_increment, + `ts` datetime NOT NULL default '0000-00-00 00:00:00', + `duration` int(11) NOT NULL default '0', + `rootID` int(11) NOT NULL default '0', + `networkPrefix` bigint(20) unsigned NOT NULL default '0', + `hostPart` bigint(20) unsigned NOT NULL default '0', + `cidr` smallint(6) NOT NULL default '0', + `ipv6` smallint(6) NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `rootID` (`rootID`,`networkPrefix`,`hostPart`,`cidr`,`ipv6`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; + +0.98b -> 0.98c +ALTER TABLE network ADD COLUMN searchStr varchar(255) DEFAULT ''; +ALTER TABLE network CHANGE COLUMN network network bigint(20) unsigned NOT NULL DEFAULT 0; +ALTER TABLE network ADD INDEX (description); +ALTER TABLE network ADD INDEX (searchStr); +CREATE TABLE `networkTag` ( + `ID` int(11) NOT NULL auto_increment, + `netID` int(11) NOT NULL default '0', + `tag` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY `netID` (`netID`,`tag`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; diff -Nru haci-0.97c/docs/manualDatabaseUpgrades.txt haci-0.98c/docs/manualDatabaseUpgrades.txt --- haci-0.97c/docs/manualDatabaseUpgrades.txt 2010-02-24 01:57:43.000000000 +0000 +++ haci-0.98c/docs/manualDatabaseUpgrades.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,41 +0,0 @@ -# These are the database scheme changes between different HaCi versions. New tables were created by HaCi automatically. -# Also those changes where automatically performed by HaCi. -# Since version 0.9.7 there's a config option 'autoUpgradeDatabase', which gives you the opportunity to enable resp. disable the automatic upgrade function. - - -0.7.5 -> 0.8: -ALTER TABLE network DROP INDEX network; -ALTER TABLE network ADD COLUMN ipv6ID varchar(22) NOT NULL DEFAULT ''; -ALTER TABLE network ADD UNIQUE (network, rootID, ipv6ID); - -ALTER TABLE root ADD COLUMN ipv6 tinyint(1) NOT NULL DEFAULT '0'; - -ALTER TABLE networkAC DROP INDEX rootID; -ALTER TABLE networkAC ADD COLUMN netID integer(11) NOT NULL DEFAULT '0'; -ALTER TABLE networkAC ADD UNIQUE (netID, groupID); - - -0.8 -> 0.9.1 -ALTER TABLE plugin DROP COLUMN date; -ALTER TABLE plugin ADD COLUMN runTime integer(11) NOT NULL DEFAULT '0'; -ALTER TABLE plugin ADD COLUMN lastError varchar(255) NOT NULL DEFAULT ''; - -ALTER TABLE networkPlugin ADD COLUMN sequence integer(11) NOT NULL DEFAULT '0'; -ALTER TABLE networkPlugin ADD COLUMN newLine tinyint(4) NOT NULL DEFAULT '0'; - - -0.9.1 -> 0.9.5 -ALTER TABLE plugin ADD COLUMN filename varchar(255) NOT NULL DEFAULT ''; - -ALTER TABLE network ADD COLUMN defSubnetSize TINYINT(4) unsigned NOT NULL DEFAULT '0'; -ALTER TABLE network ADD INDEX (network); - - -0.9.5 -> 0.9.6 -ALTER TABLE network CHANGE COLUMN ipv6ID ipv6ID varbinary(22) NOT NULL DEFAULT ''; - -ALTER TABLE networkV6 CHANGE COLUMN ID ID varbinary(22) NOT NULL DEFAULT ''; - -0.9.6 -> 0.9.7 -ALTER TABLE networkV6 CHANGE COLUMN networkPrefix networkPrefix bigint(20) unsigned NOT NULL DEFAULT '0'; -ALTER TABLE networkV6 CHANGE COLUMN hostPart hostPart bigint(20) unsigned NOT NULL DEFAULT '0'; diff -Nru haci-0.97c/etc/HaCi.conf.sample haci-0.98c/etc/HaCi.conf.sample --- haci-0.97c/etc/HaCi.conf.sample 2010-03-08 17:22:58.000000000 +0000 +++ haci-0.98c/etc/HaCi.conf.sample 2015-03-04 00:15:52.000000000 +0000 @@ -3,6 +3,9 @@ dbName = HaCi dbUser = HaCi dbPass = geheim! + + # database type (mysql [default], postgresql) + dbType = mysql # GUI parameters @@ -12,7 +15,7 @@ new = 777777 reserved = FF00F0 - locked = AAAAAA + locked = 555555 free = 00AA00 assigned = 000000 invisible = FFFFFF @@ -43,6 +46,15 @@ # enable locales support (default 1) enableLocaleSupport = 1 + + # show number of free subnets with CIDR 'min' + showNrOfFreeSubnetsWithMinCIDR = 1 + + # show first and last address as 'netaddress' respectively 'broadcast' + showNetBorders = 1 + + # remove CIDR (/32 respectively /128) from IP addresses + removeCIDRFromIPs = 1 @@ -57,19 +69,43 @@ # suppress database upgrade error messages if you are sure that everything is okay ignoreUpgradeFailures = 0 + + # enable debugging + debug = 0 + + # set default network lock time (in seconds) when deleting networks + dftNetworkLock = 0 # authentication parameters ## authentication modules # internal: internal auth # imap : IMAP auth - authModule = internal + # ldap : LDAP auth + # + # you can specify multiple authentication modules which will be used one after another + authModule = ldap, internal # authenticationmodule parameters # host = imap.server.tld # authtype = login + + + # authenticate with bindDN + # host = ldap1.server.tld + # host = ldap2.server.tld + # bindDN = cn=,ou=linux-users,dc=example,dc=com # the variable will be replaced with the authenticating username + + # search for user and authenticate against that dn (necessary, if the cn isn't equal with the authenticating username) + # host = ldap1.server.tld + # host = ldap2.server.tld + # bindDN = cn=ldapread,ou=User,dc=example,dc=com + # bindPW = + # baseDN = ou=organisation,dc=example,dc=com + # filter = attr= # the variable will be replaced with the authenticating username + diff -Nru haci-0.97c/etc/internal.conf haci-0.98c/etc/internal.conf --- haci-0.97c/etc/internal.conf 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/etc/internal.conf 2015-03-04 01:07:44.000000000 +0000 @@ -2,17 +2,21 @@ # Only touch if you know what you are doing! + + dbType = mysql + + workdir = $workdir templateIncludePath = $workdir/Template - templateCompilePath = $workdir/spool spoolPath = $workdir/spool + templateCompilePath = ${spoolPath} authModules = $workdir/modules/HaCi/Authentication plugins = $workdir/modules/HaCi/Plugins localePath = $workdir/locale - statusFile = $workdir/spool/status - cacheFile = $workdir/spool/cache - tableHashFile = $workdir/spool/tableHash + statusFile = ${spoolPath}/status + cacheFile = ${spoolPath}/cache + tableHashFile = ${spoolPath}/tableHash HaCid = $workdir/bin/HaCid.pl templateInit = HaCi.tmpl imagePathRel = /Images @@ -20,12 +24,13 @@ whois = /usr/bin/whois imagePath = ${workdir}${imagePathRel} HaCidPID = ${spoolPath}/HaCid.pid + lockPath = ${spoolPath} titleShort = HaCi titleLong = HaCi - IP Address Administration - version = 0.97c + version = 0.98c jsSrcDir = / jsSrc = /HaCi.js imagePathRel = /Images @@ -65,11 +70,12 @@ debug = 0 + dbiTrace = 0 ripeDB = 193.0.6.135 - sessionTimeout = +1h + sessionTimeout = +4h maxMemConsumption = 100000 disableCache = 0 - searchLimit = 1000 + searchLimit = 2000 name = UNSPECIFIED @@ -160,7 +166,7 @@ name = IN USE - parents = 1, 2, 16, 14 + # parents = 1, 2, 16, 14 ID = 18 @@ -263,6 +269,11 @@ short = pluginMgmt order = 3 + <17> + long = Show audit logs + short = showAuditLogs + order = 17 + diff -Nru haci-0.97c/etc/startup.pl haci-0.98c/etc/startup.pl --- haci-0.97c/etc/startup.pl 2010-03-08 17:22:58.000000000 +0000 +++ haci-0.98c/etc/startup.pl 2013-03-04 20:30:07.000000000 +0000 @@ -3,6 +3,7 @@ $ENV{MOD_PERL} or die "not running under mod_perl!"; +use lib qw(/var/www/HaCi/modules); use ModPerl::Registry; use Apache::DBI; use CGI (); diff -Nru haci-0.97c/html/HaCi_black.css haci-0.98c/html/HaCi_black.css --- haci-0.97c/html/HaCi_black.css 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/html/HaCi_black.css 2015-01-03 05:11:10.000000000 +0000 @@ -15,7 +15,7 @@ } a:link{ - color:#5555cc; + color:#5555cc; } a:visited{ color:#5555cc; @@ -207,7 +207,7 @@ } #box select{ font-size:1em; - height:1.6em; + /*height:1.6em;*/ } #box table{ font-size:0.8em; @@ -259,7 +259,7 @@ vertical-align:middle; } #menuBoxLink a{ - color:#FFFF00; + color:#0000FF; text-decoration:none; } #menuBoxEntry{ @@ -527,6 +527,11 @@ left:350px; } +#warnlContent { + max-height: 300px !important; + overflow:auto !important; +} + #warnl:hover{ cursor:move; } @@ -563,3 +568,6 @@ #floatingPopupContent{ } + +#boxBody { +} diff -Nru haci-0.97c/html/HaCi.css haci-0.98c/html/HaCi.css --- haci-0.97c/html/HaCi.css 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/html/HaCi.css 2015-01-03 05:11:10.000000000 +0000 @@ -14,10 +14,10 @@ height: 96% } -a:link{ - color:#5555cc; +a:link { + color:#5555cc; } -a:visited{ +a:visited { color:#5555cc; } @@ -210,7 +210,7 @@ } #box select{ font-size:1em; - height:1.6em; + /*height:1.6em;*/ } #box table{ font-size:0.8em; @@ -262,7 +262,7 @@ vertical-align:middle; } #menuBoxLink a{ - color:#FFFF00; + color:#0000FF; text-decoration:none; } #menuBoxEntry{ @@ -531,6 +531,11 @@ left:350px; } +#warnlContent { + max-height: 300px !important; + overflow:auto !important; +} + #warnl:hover{ cursor:move; } @@ -567,3 +572,6 @@ #floatingPopupContent{ } + +#boxBody { +} diff -Nru haci-0.97c/html/HaCi.js haci-0.98c/html/HaCi.js --- haci-0.97c/html/HaCi.js 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/html/HaCi.js 2015-02-15 16:47:26.000000000 +0000 @@ -86,6 +86,7 @@ netmaskBlock.style.display = 'none'; } else { document.getElementById('netmask').disabled = true; + document.getElementById('netmask').value = ''; } document.getElementsByName('netaddress')[0].size = 43; document.getElementsByName('netaddress')[0].maxLength = 43; @@ -201,6 +202,16 @@ function setnetmask_cidr (network, target_netmask, target_cidr, target_netaddress) { var splits = network.split('/'); + + if (splits[1] == null || splits[1] == '') { + if (ipv6 == 1) { + splits[1] = 128 + } else { + splits[1] = 32 + } + } +console.log(splits); + if (ipv6 == 1) { splits[0] = adjustIPv6(splits[0]); if (splits[1]) { @@ -434,15 +445,22 @@ break; case 3: var optionStr = ''; - for (i = 0; i < document.getElementsByTagName("option").length; i++) { - var tagTitle = document.getElementsByTagName("option")[i].title; - if (tagTitle == 'tmplEntryID_' + ID) { - var tagValue = document.getElementsByTagName("option")[i].value; - if (optionStr != '') - optionStr += ';'; - optionStr += tagValue; + for (i = 0; i < document.getElementsByTagName("select").length; i++) { + var selectName = document.getElementsByTagName("select")[i].name; + if (selectName == 'tmplEntryID_' + ID) { + var options = document.getElementsByTagName("select")[i].options; + for (u = 0; u < options.length; u++) { + if (options[u] != undefined) { + var optionValue = options[u].value; + if (optionStr != '') + optionStr += ';'; + optionStr += optionValue; + } + } + break; } } + document.getElementById('TmplEntryParamDescr').value = document.getElementById('tmplEntryDescrID_' + ID).value; document.getElementById('TmplEntryParamEntries').disabled = ''; document.getElementById('TmplEntryParamEntries').value = optionStr; @@ -492,6 +510,34 @@ } } +function setAllACLs (source, acl) { + + var sourceChecked = document.getElementById(source).checked; + var regex = new RegExp('^accGroup_' + acl + '_'); + var i = 0; + var inputs = document.getElementsByTagName('input'); + for (i = 0; i < inputs.length; ++i) { + if (!inputs[i].name.match(regex)) + continue; + var index = inputs[i].name.replace(regex, ''); + inputs[i].checked = sourceChecked; + setACLs(index, acl); + } + + switch (acl) { + case 'r': + if (!sourceChecked) { + document.getElementById('checkAll_write').checked = false; + } + break; + case 'w': + if (sourceChecked) { + document.getElementById('checkAll_read').checked = true; + } + break; + } +} + function chkTmplPosition (max) { if (max != undefined) { maxTmplPositions = max; @@ -723,3 +769,66 @@ jumpto.value = ''; jumpto.style.color = '#000000' } + +function changeACLFromParent() { + var aclFromParentCB = document.getElementsByName("aclsFromParent")[0]; + document.getElementsByName("checkAll_read")[0].disabled = aclFromParentCB.checked; + document.getElementsByName("checkAll_write")[0].disabled = aclFromParentCB.checked; + + var regex = new RegExp('^accGroup_'); + var i = 0; + var inputs = document.getElementsByTagName('input'); + for (i = 0; i < inputs.length; ++i) { + if (!inputs[i].name.match(regex)) + continue; + inputs[i].disabled = aclFromParentCB.checked; + } +} + +function enableACLs() { + var regex = new RegExp('^accGroup_'); + var i = 0; + var inputs = document.getElementsByTagName('input'); + for (i = 0; i < inputs.length; ++i) { + if (!inputs[i].name.match(regex)) + continue; + inputs[i].disabled = 0 + } +} + +function addAvailTag() { + var tags = document.getElementById("tags"); + var availTags = document.getElementById("availTags"); + var newTag = availTags.selectedOptions[0].text; + + var exists = 0; + tags.value.split(/\s+/).forEach(function(tag) { + if (tag == newTag) { + window.alert("Tag '" + tag + "' is already set"); + exists = 1; + } + }); + + if (exists) + return; + + if (tags.value != '') + tags.value += " "; + + tags.value += newTag; +} + +function toggleEnableIntAcc() { + var checkBox = document.getElementsByName("enableInternalAccount")[0]; + var pass1 = document.getElementsByName("password1")[0]; + var pass2 = document.getElementsByName("password2")[0]; + if (checkBox.checked) { + pass1.disabled = false; + pass2.disabled = false; + } else { + pass1.disabled = true; + pass1.value = ''; + pass2.disabled = true; + pass2.value = ''; + } +} diff -Nru haci-0.97c/html/HaCiXMLRPC-API.html haci-0.98c/html/HaCiXMLRPC-API.html --- haci-0.97c/html/HaCiXMLRPC-API.html 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/html/HaCiXMLRPC-API.html 2015-02-16 00:46:27.000000000 +0000 @@ -0,0 +1,294 @@ + + + + +modules/HaCi/XMLRPC.pm + + + + + + + + +
+

+ + + +
+
+ + +

+

+

Class XMLRPC

+

This class provides a XML-RPC API for HaCi.

+

Basic usage:

+
+        my $api         = new Frontier::Client(url => "http://$server/RPC2");
+        my $session     = $api->call('login', [$user, $pass]);
+        die 'Login failed!' unless $session;
+
+        print Dumper($api->call($method, $session, @args));
+
+        $api->call('logout', $session);
+
+        exit 0;
+
+
login()
+ +
+

Login and return your session

+
+ Params
+
+ Returns
+    - session        [string]    session token you can use for authentication
+
+
logout()
+ +
+

Logout

+
+ Params
+
+ Returns
+
+
search()
+ +
+

Search networks

+
+ Params
+    - search          [string]  string to search for
+    - state           [string]  filter the result by that network state (ALLOCATED PA, ASSIGNED, ...)
+    - exact           [string]  don't do a substring search
+    - template name   [string]  filter the result by that template name
+    - template query  [hash]    filter the result by defining special values for template entries (i.e.: {name => 'POOL1'})
+    - root name       [string]  limit the search in that root
+    - nrOfFreeSubs    [boolean] compute the number of free subnets in each found network
+    - withDetails     [boolean] show details for found networks
+    - tags            [string]  return only networks with this tags, seperate with spaces (i.e.: 'OR foo bar', 'AND foo bar')
+ Returns
+    - networks        [array]    array of found network blocks (hash)
+                                 - netID
+                                 - network
+                                 - rootName
+                                 - description
+                                 - state
+                                 - nrOfFreeSubs
+ Example
+    my $networks = search('Test', 'ASSIGNED', 0, 'DSL-POOL', {name => 'Pool1'}, 'DSL-Test-Pool-Root', 0);
+
+
getFreeSubnets()
+ +
+

Find free subnets in a specified root and supernet and return the wanted amount of subnets

+
+ Params
+    - root name       [string]  search free subnets in that root
+    - supernet        [network] search free subnets in that supernet (e.g. 192.168.0.0/24, 2001::/120)
+    - cidr            [integer] specify the target cidr of your subnets (e.g. 30)
+    - amount          [integer] how many subnets you want to get
+ Returns
+    - networks        [array]   array of free subnets found (hash)
+                                - network
+ Example
+    my $freeSubnets = getFreeSubnets('Test root', '10.184.120.0/23', 32, 1);
+
+
getFreeSubnetsFromSearch()
+ +
+

Search networks and return free subnets from them

+
+ Params
+    - search          [string]  string to search for
+    - state           [string]  filter the result by that network state (ALLOCATED PA, ASSIGNED, ...)
+    - exact           [string]  don't do a substring search
+    - template name   [string]  filter the result by that template name
+    - template query  [hash]    filter the result by defining special values for template entries (i.e.: {name => 'POOL1'})
+    - root name       [string]  limit the search in that root
+    - cidr            [integer] specify the target cidr of your subnets (e.g. 30)
+    - amount          [integer] how many subnets you want to get
+ Returns
+    - networks        [array]   array of free subnets found (hash)
+                                - network
+                                - root name
+ Example
+    my $freeSubnets = getFreeSubnetsFromSearch('search me', '', 1, '', {}, 'Test-Root', 29, 3);
+
+
listRoots()
+ +
+

Add a root to HaCi

+
+ Params
+ Returns
+    - roots        [array]    array of found roots (hash)
+                                 - ID
+                                 - name
+                                 - ipv6 (boolean)
+
+
addRoot()
+ +
+

Add a root to HaCi

+
+ Params
+    - root name       [string]  add a root with this name
+    - description     [string]  description of the root
+    - ipv6            [boolean] this root contains IPv6 networks
+ Returns
+    - success         [string] 0 on success, error-String at error
+
+
editRoot()
+ +
+

Edit an existing root

+
+ Params
+    - root name      [string]  edit this root
+    - new root name  [string]  change root name
+    - description    [string]  new description of the root
+ Returns
+    - success         [string] 0 on success, error-String at error
+
+
delRoot()
+ +
+

Delete a root from HaCi

+
+ Params
+    - root name       [string]  remove the root
+ Returns
+    - success         [string] 0 on success, error-String at error
+
+
addNet()
+ +
+

Add a network to HaCi

+
+ Params
+    - root name       [string]  add the network to this root
+    - network         [network] add this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125)
+    - description     [string]  description of the network
+    - state           [string]  state of the network (e.g. ALLOCATED PA, ASSIGNED, ...)
+    - def subnet Size [integer] define a default subnet cidr size (e.g. 30)
+    - template name   [string]  assign a template to the network
+    - template values [hash]    pass template values (e.g. {hostname => 'abc.de', os => 'redhat'})
+    - tags                                              [string]  add tags (seperate by comma)
+ Returns
+    - success         [string] 0 on success, error-String at error
+
+
editNet()
+ +
+

Edit an existing network

+
+ Params
+    - root name   [string]  edit the network in this root
+    - network     [network] edit this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125)
+    - changes     [hash]    changes (valid attributes are: network description state rootName defSubnetSize tmplName tmplValues)
+                            e.g.:
+                             {description => 'test_8'}
+                             {network => '192.168.0.8/29', defSubnetSize=>30, state=>'FREE', rootName=>'larsux.de'}
+ Returns
+    - success         [string] 0 on success, error-String at error
+
+
delNet()
+ +
+

Delete a network from HaCi

+
+ Params
+    - root name       [string]  remove the netork from this root
+    - network         [network] remove this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125)
+    - network lock    [integer] lock network for X seconds
+    - withSubnets     [boolean] also remve subnets
+ Returns
+    - success         [string] 0 on success, error-String at error
+
+
assignFreeSubnet()
+ +
+

Find the next free subnet and assign it in one step

+
+ Params
+    - root name       [string]  search free subnets in that root
+    - supernet        [network] search free subnets in that supernet (e.g. 192.168.0.0/24, 2001::/120)
+    - cidr            [integer] specify the target cidr of your subnets (e.g. 30)
+    - description     [string]  description of the network
+    - state           [string]  state of the network (e.g. ALLOCATED PA, ASSIGNED, ...)
+    - def subnet Size [integer] define a default subnet cidr size (e.g. 30)
+    - template name   [string]  assign a template to the network
+    - template values [hash]    pass template values (e.g. {hostname => 'abc.de', os => 'redhat'})
+ Returns
+    - network details [hash]    new network assigned:
+                                - netID
+                                - network
+                                - modify date
+                                - ipv6 (boolean)
+                                - description
+                                - state
+                                - create from
+                                - create date
+                                - default subnet cidr size
+                                - template name
+                                - modify from
+
+
getNetworkDetails()
+ +
+

Get details from a network in HaCi

+
+ Params
+    - root name       [string]  get details of a network in this root
+    - network         [network] get details of this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125)
+ Returns
+    - network         [hash]    network details:
+                                - netID
+                                - network
+                                - modify date
+                                - ipv6 (boolean)
+                                - description
+                                - state
+                                - create from
+                                - create date
+                                - default subnet cidr size
+                                - template name
+                                - modify from
+
+
getSubnets()
+ +
+

Get subnets from a root and optional from a supernet

+
+ Params
+    - root name       [string]  get subnets from this root
+    - supernet        [network] get subnets from this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125)
+ Returns
+    - networks        [array]    array of found networks (hash)
+                                 - netID
+                                 - network
+                                 - modify date
+                                 - ipv6 (boolean)
+                                 - description
+                                 - state
+                                 - create from
+                                 - create date
+                                 - default subnet cidr size
+                                 - template name
+                                 - modify from
+ Example
+    my $subnets = getSubnets('Test');
+    my $subnets = getSubnets('Test', '192.168.0.0/24');
+
+
+ + + + Binary files /tmp/tmpulZGPg/VHhJDdrVp_/haci-0.97c/html/Images/exportSubnets_small.png and /tmp/tmpulZGPg/PvHC8nPaSV/haci-0.98c/html/Images/exportSubnets_small.png differ Binary files /tmp/tmpulZGPg/VHhJDdrVp_/haci-0.97c/html/Images/left.png and /tmp/tmpulZGPg/PvHC8nPaSV/haci-0.98c/html/Images/left.png differ Binary files /tmp/tmpulZGPg/VHhJDdrVp_/haci-0.97c/html/Images/right.png and /tmp/tmpulZGPg/PvHC8nPaSV/haci-0.98c/html/Images/right.png differ Binary files /tmp/tmpulZGPg/VHhJDdrVp_/haci-0.97c/html/Images/searchAndAddNet.png and /tmp/tmpulZGPg/PvHC8nPaSV/haci-0.98c/html/Images/searchAndAddNet.png differ Binary files /tmp/tmpulZGPg/VHhJDdrVp_/haci-0.97c/html/Images/showAuditLogs.png and /tmp/tmpulZGPg/PvHC8nPaSV/haci-0.98c/html/Images/showAuditLogs.png differ Binary files /tmp/tmpulZGPg/VHhJDdrVp_/haci-0.97c/locale/de/LC_MESSAGES/HaCi.mo and /tmp/tmpulZGPg/PvHC8nPaSV/haci-0.98c/locale/de/LC_MESSAGES/HaCi.mo differ diff -Nru haci-0.97c/locale/de/LC_MESSAGES/HaCi.po haci-0.98c/locale/de/LC_MESSAGES/HaCi.po --- haci-0.97c/locale/de/LC_MESSAGES/HaCi.po 2010-02-24 03:29:58.000000000 +0000 +++ haci-0.98c/locale/de/LC_MESSAGES/HaCi.po 2015-02-16 00:46:27.000000000 +0000 @@ -74,10 +74,10 @@ msgid "Search,Compare" msgstr "Suchen, Vergleichen" -msgid "Import ASN Routes" +msgid "Import ASN routes" msgstr "ASN Routen importieren" -msgid "Import DNS Zonefile" +msgid "Import DNS zonefile" msgstr "DNS Zonefile importieren" msgid "No IP Addresses found for Origin '%s'." @@ -161,6 +161,9 @@ msgid "Successfully deleted '%s' from '%s' (%i Networks deleted)" msgstr "Erfolgreich '%s' von '%s' gelöscht (%i Netze gelöscht)" +msgid "Successfully deleted '%s' from '%s' (%i Networks deleted) and locked for %i seconds." +msgstr "Erfolgreich '%s' von '%s' gelöscht (%i Netze gelöscht) und für %i Sekunden gesperrt" + msgid "None" msgstr "Keine" @@ -228,19 +231,25 @@ msgid "Add Root" msgstr "Startpunkt hinzufügen" +msgid "Add root" +msgstr "Startpunkt hinzufügen" + msgid "Add Network" msgstr "Netz hinzufügen" +msgid "Add network" +msgstr "Netz hinzufügen" + msgid "Import" msgstr "Importieren" -msgid "ASN Routes" +msgid "ASN routes" msgstr "ASN Routen" -msgid "Add Network %s" +msgid "Add network %s" msgstr "Netz %s hinzufügen" -msgid "Edit Network %s" +msgid "Edit network %s" msgstr "Netz %s bearbeiten" msgid "Separator" @@ -255,19 +264,25 @@ msgid "Exact" msgstr "Exakt" +msgid "Show number of free subnets" +msgstr "Zeige Anzahl freier Subnetze an" + msgid "Fuzzy Search" msgstr "Unscharfe Suche" +msgid "# of free subnets" +msgstr "# freier Subnetze" + msgid "Wildcard" msgstr "Platzhalter" msgid "Maintenance" msgstr "Verwaltung" -msgid "User Management" +msgid "User management" msgstr "Benutzerverwaltung" -msgid "Group Management" +msgid "Group management" msgstr "Gruppenverwaltung" msgid "Logged in as %s" @@ -279,17 +294,20 @@ msgid "Random Tree" msgstr "Zufälliger Baum" -msgid "Template Management" +msgid "Template management" msgstr "Vorlagenverwaltung" -msgid "Flush Cache" +msgid "Flush cache" msgstr "Cache leeren" msgid "About HaCi" msgstr "Über HaCi" +msgid "Search free networks" +msgstr "Suche freie Netze" + #: Import -msgid "Import from DNS Zonefiles" +msgid "Import from DNS zonefiles" msgstr "von DNS Zonefiles importieren" msgid "Local Zonefile" @@ -345,6 +363,9 @@ msgid "Available Variables from the Plugins" msgstr "Verfügbare Variablen der Plugins" +msgid "Available Variables" +msgstr "Verfügbare Variablen" + msgid "Description Helper" msgstr "Hilfe für die Beschreibung" @@ -485,6 +506,9 @@ msgid "Details of Network %s" msgstr "Details des Netzes %s" +msgid "Details of IP %s" +msgstr "Details der IP %s" + msgid "Functions" msgstr "Funktionen" @@ -494,9 +518,12 @@ msgid "Type" msgstr "Typ" -msgid "Type Infos of Network %s" +msgid "Type info of Network %s" msgstr "Typ Informationen des Netzes %s" +msgid "Type info of IP %s" +msgstr "Typ Informationen der IP %s" + msgid "Split" msgstr "Aufteilen" @@ -637,6 +664,9 @@ msgid "Structure" msgstr "Struktur" +msgid "Template name" +msgstr "Vorlagen Name" + #: ShowGroups msgid "Groups" msgstr "Gruppen" @@ -654,6 +684,9 @@ msgid "No Group deleted. Nothing found!" msgstr "Keine Gruppe gelöscht. Nix gefunden!" +msgid "You cannot delete the administrator group!" +msgstr "Die Administratorgruppe kann nicht gelöscht werden!" + msgid "Successfully deleted Group '%s'" msgstr "Erfolgreich Gruppe '%s' gelöscht" @@ -722,7 +755,7 @@ msgstr "Dieses Netz existiert schon!" #: pluginMgmt -msgid "Plugin Management" +msgid "Plugin management" msgstr "Pluginverwaltung" msgid "Configure Plugin '%s'" @@ -932,3 +965,103 @@ msgid "Errors while updating Setting for '%s': %s" msgstr "Wärend die Einstellungen für '%s' aktualisiert wurden, sind Fehler aufgetreten: %s" + +#: audit +msgid "Show audit logs" +msgstr "Zeige Auditaufzeichnungen" + +msgid "Audit logs" +msgstr "Auditaufzeichnungen" + +msgid "Sort by" +msgstr "Sortieren nach" + +msgid "Reverse" +msgstr "Umgekehrt" + +msgid "Timestamp" +msgstr "Datum" + +msgid "Action" +msgstr "Aktion" + +msgid "Object" +msgstr "Objekt" + +msgid "Value" +msgstr "Wert" + +msgid "Number of entries" +msgstr "Anzahl der Einträge" + +msgid "Page (%d .. %d)" +msgstr "Seite (%d .. %d)" + +msgid "Overwrite existing" +msgstr "Überschreibe existierende" + +msgid "Add free network" +msgstr "Freies Netz hinzufügen" + +msgid "Search for free networks" +msgstr "Suche nach freien Netzen" + +msgid "Amount" +msgstr "Anzahl" + +msgid "Result" +msgstr "Ergebnis" + +msgid "No free networks found" +msgstr "Keine freien Netze gefunden" + +msgid "Never" +msgstr "Nie" + +msgid "No changes" +msgstr "Keine Änderungen" + +msgid "Sorry, the network '%s' is still locked for '%i' seconds till '%s'!" +msgstr "Das Netzwerk '%s' ist noch für '%i' Sekunden gesperrt bis '%s'!" + +msgid "Error while deleting network lock '%i': %s" +msgstr "Fehler beim Entfernen der Netzwerk-Sperre '%i': %s" + +msgid "Lock network for X seconds" +msgstr "Sperre Netzwerk für X Sekunden" + +msgid "Network lock time must be provided in seconds not '%s'" +msgstr "Netzwerksperre muss in Sekunden angegeben werden, nicht '%s'" + +msgid "All" +msgstr "Alle" + +msgid "Inherit from supernet" +msgstr "Vom Supernetz erben" + +msgid "Export Subnets" +msgstr "Subnetze exportieren" + +msgid "# of assigned subnets" +msgstr "# vergebener Subnetze" + +msgid "%s: Status (%s) not known" +msgstr "%s: Status (%s) nicht bekannt" + +msgid "seperate
by space" +msgstr "trennen mit
Leerzeichen" + +msgid "AND" +msgstr "UND" + +msgid "OR" +msgstr "ODER" + +msgid "marked: NOT inherited" +msgstr "markiert: NICHT vererbt" + +msgid "Enable internal account" +msgstr "internes Konto aktivieren" + +msgid "Internal account is disabled." +msgstr "Internes Konto is deaktiviert" Binary files /tmp/tmpulZGPg/VHhJDdrVp_/haci-0.97c/locale/it/LC_MESSAGES/HaCi.mo and /tmp/tmpulZGPg/PvHC8nPaSV/haci-0.98c/locale/it/LC_MESSAGES/HaCi.mo differ diff -Nru haci-0.97c/locale/it/LC_MESSAGES/HaCi.po haci-0.98c/locale/it/LC_MESSAGES/HaCi.po --- haci-0.97c/locale/it/LC_MESSAGES/HaCi.po 2010-01-12 18:16:38.000000000 +0000 +++ haci-0.98c/locale/it/LC_MESSAGES/HaCi.po 2012-07-09 21:20:21.000000000 +0000 @@ -213,22 +213,22 @@ msgid "Show all Nets" msgstr "Mostra tutte le Reti" -msgid "Add Root" +msgid "Add root" msgstr "Aggiungi una Radice" -msgid "Add Network" +msgid "Add network" msgstr "Aggiungi una Rete" msgid "Import" msgstr "Importa" -msgid "ASN Routes" +msgid "ASN routes" msgstr "ASN Routes" -msgid "Add Network %s" +msgid "Add network %s" msgstr "Aggiungu la Rete %s" -msgid "Edit Network %s" +msgid "Edit network %s" msgstr "Modifica la Rete %s" msgid "Separator" @@ -252,10 +252,10 @@ msgid "Maintenance" msgstr "Manutenzione" -msgid "User Management" +msgid "User management" msgstr "Gestione Utenti" -msgid "Group Management" +msgid "Group management" msgstr "Gestione Gruppi" msgid "Logged in as %s" @@ -267,10 +267,10 @@ msgid "Random Tree" msgstr "Albero Casuale" -msgid "Template Management" +msgid "Template management" msgstr "Gestione Template" -msgid "Flush Cache" +msgid "Flush cache" msgstr "Svuota la Cache" msgid "About HaCi" @@ -710,7 +710,7 @@ msgstr "Questa Rete esiste gia`!" #: pluginMgmt -msgid "Plugin Management" +msgid "Plugin management" msgstr "Gestione Plugin" msgid "Configure Plugin '%s'" diff -Nru haci-0.97c/modules/DBIEasy/mysql.pm haci-0.98c/modules/DBIEasy/mysql.pm --- haci-0.97c/modules/DBIEasy/mysql.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/DBIEasy/mysql.pm 2012-06-27 23:02:32.000000000 +0000 @@ -0,0 +1,155 @@ +package DBIEasy::mysql; + +use strict; +use warnings; + +use base 'DBIEasy'; + +my $queryTimeout = 300; + +sub getDSN { + my $self = shift; + + return ( + 'DBI:mysql:' . + 'database=' . $self->dbname . + ';host=' . $self->dbhost, + $self->dbuser, $self->dbpass + ); +} + +sub checkIfTableExists { + my $self = shift; + my $dbh = $self->dbh; + my $table = $self->TABLE; + + my @tables = $dbh->tables(undef, undef, $table); + unless (grep {/^(`?$self->{dbname}`?.)?`?$table`?$/} @tables) { + if ($self->SETUPTABLE) { + $self->_carp("Table '$table' doesn't exist, try to create it...\n"); + my $createStmt = "CREATE TABLE `$table` (" . $self->CREATETABLE . ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; + $dbh->do($createStmt) or $self->_croak($dbh->errstr); + + my @tables = $dbh->tables(undef, undef, $table); + unless (grep {/^(`?$self->{dbname}`?.)?`?$table`?$/} @tables) { + $self->_croak("Sorry, after creating the Table '$table', it isn't there?"); + return 0; + } + } else { + $self->_croak("Table '$table' doesn't exist!"); + return 0; + } + } + return 1; +} + +sub getPK { + my $self = shift; + my $dbh = $self->dbh; + my $table = $self->TABLE; + my @PKs = (); + + my $sth = $dbh->prepare("SHOW INDEX FROM $table"); + $sth->execute; + $self->_croak($dbh->errstr) if $dbh->errstr; + if ($sth) { + my $hashRef = $sth->fetchall_hashref(['Key_name', 'Seq_in_index']); + foreach (keys %{$hashRef}) { + my $key = $_; + foreach (keys %{$hashRef->{$key}}) { + if ($key eq 'PRIMARY') { + push @PKs, $hashRef->{$key}->{$_}->{Column_name}; + } + } + } + } + if ($#PKs == -1) { + $self->_croak("No Primary Keys in Table '$table'!"); + } else { + return \@PKs; + } +} + +sub getShowCreate { + my $self = shift; + my $dbh = $self->dbh; + my $table = $self->TABLE; + + my $sth = $dbh->prepare("SHOW CREATE TABLE `$table`"); + $sth->execute; + $self->_croak($dbh->errstr) if $dbh->errstr; + + if ($sth) { + my $showCreatet = $sth->fetchall_arrayref([1]); + if (defined $showCreatet) { + my $showCreate = $$showCreatet[0]; + return $$showCreate[0]; + } else { + $self->_carp("Sorry, Show Create Table '$table' doesn't work!"); + return ''; + } + } +} + + +sub getColoumns { + my $self = shift; + my $dbh = $self->dbh; + my $table = $self->TABLE; + + my $sth = $dbh->prepare("DESCRIBE `$table`"); + $sth->execute; + $self->_croak($dbh->errstr) if $dbh->errstr; + + if ($sth) { + my $hashRef = $sth->fetchall_hashref('Field'); + return ((defined $hashRef && ref $hashRef eq 'HASH') ? keys %{$hashRef} : ()); + } else { + $self->_carp("Sorry, no Columns found!"); + return (); + } +} + +sub checkForOldHandles { + my $self = shift; + my $dbh = shift; + + my $sth_sh_proc = $dbh->prepare("show full processlist"); + my $sth_kill = $dbh->prepare("kill ?"); + + unless ($sth_sh_proc->execute()) { + _carp("Unable to execute show procs [" . $dbh->errstr() . "]"); + return 0; + } + while (my $row = $sth_sh_proc->fetchrow_hashref()) { + if ($row->{Command} eq 'Sleep' && $row->{Time} > $queryTimeout) { + my $id = $row->{Id}; + $sth_kill->execute($id); + } + } + + return 1; +} + +sub mkCaseSensitive { + my $self = shift; + my @whereStr = @_; + + return map {$_ = 'binary ' . $_} @whereStr; +} + +sub _log { + DBIEasy::_log(@_); +} + +sub _carp { + DBIEasy::_carp(@_); +} + +sub _croak { + DBIEasy::_croak(@_); +} + +1; + +# vim:ts=2:sts=2:sw=2 diff -Nru haci-0.97c/modules/DBIEasy/postgresql.pm haci-0.98c/modules/DBIEasy/postgresql.pm --- haci-0.97c/modules/DBIEasy/postgresql.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/DBIEasy/postgresql.pm 2012-06-27 23:02:32.000000000 +0000 @@ -0,0 +1,172 @@ +package DBIEasy::postgresql; + +use strict; +use warnings; +use Data::Dumper; + +use base 'DBIEasy'; + +my $queryTimeout = 300; + +sub getDSN { + my $self = shift; + + return ( + 'DBI:Pg:' . + 'database=' . $self->dbname . + ';host=' . $self->dbhost, + $self->dbuser, $self->dbpass + ); +} + +sub checkIfTableExists { + my $self = shift; + my $dbh = $self->dbh; + my $table = lc($self->TABLE); + + my @tables = $dbh->tables(undef, undef, $table); + unless (grep {/^("?[^\.\s]+"?.)?"?$table"?$/} @tables) { + if ($self->SETUPTABLE) { + $self->_carp("Table '$table' doesn't exist, try to create it...\n"); + my $createStmt = "CREATE TABLE `$table` (" . $self->CREATETABLE . ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; + $dbh->do($createStmt) or $self->_croak($dbh->errstr); + + my @tables = $dbh->tables(undef, undef, $table); + unless (grep {/^(`?$self->{dbname}`?.)?`?$table`?$/} @tables) { + $self->_croak("Sorry, after creating the Table '$table', it isn't there?"); + return 0; + } + } else { + $self->_croak("Table '$table' doesn't exist!"); + return 0; + } + } + return 1; +} + +sub getPK { + my $self = shift; + my $dbh = $self->dbh; + my $table = lc($self->TABLE); + my @PKs = (); + + my $sth = $dbh->prepare(qq{ +SELECT + f.attname AS pk +FROM + pg_attribute f + JOIN pg_class c ON c.oid = f.attrelid + LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY ( p.conkey ) +WHERE + c.relkind = 'r'::char + AND p.contype = 'p' + AND c.relname = ? + AND f.attnum > 0 + }); + $sth->execute($table); + $self->_croak($dbh->errstr) if $dbh->errstr; + if ($sth) { + my $primKeys = $sth->fetchall_arrayref({}); + foreach (@{$primKeys}) { + push @PKs, $_->{pk}; + } + } + if ($#PKs == -1) { + $self->_croak("No Primary Keys in Table '$table'!"); + } else { + return \@PKs; + } +} + +sub getColoumns { + my $self = shift; + my $dbh = $self->dbh; + my $table = lc($self->TABLE); + + my $sth = $dbh->prepare(qq{ +SELECT + f.attname AS name +FROM + pg_attribute f + JOIN pg_class c ON c.oid = f.attrelid +WHERE + c.relkind = 'r'::char + AND c.relname = ? + AND f.attnum > 0 + }); + $sth->execute($table); + $self->_croak($dbh->errstr) if $dbh->errstr; + + my $cols = $sth->fetchall_arrayref({}); + if ($#{$cols} > -1) { + return map {$_->{name}} @{$cols}; + } else { + $self->_carp("Sorry, no Columns found!"); + return (); + } +} + +sub checkForOldHandles { + my $self = shift; + my $dbh = shift; + + my $superUser = ${$dbh->selectall_arrayref(qq{ + SELECT usesuper + FROM pg_user + WHERE usename=? + }, { Slice => {} }, $self->dbuser)}[0]; + + # Killing old queries only makes sense if database user has superuser rights + return unless defined $superUser && $superUser->{usesuper}; + + my $sth_sh_proc = $dbh->prepare(q{ + SELECT + EXTRACT(EPOCH FROM query_start)::integer as query_start, + procpid + FROM + pg_stat_activity + WHERE + current_query='idle in transaction' + }); + my $sth_kill = $dbh->prepare("SELECT pg_cancel_backend(?)"); + + unless ($sth_sh_proc->execute()) { + _carp("Unable to execute show procs [" . $dbh->errstr() . "]"); + return 0; + } + + while (my $row = $sth_sh_proc->fetchrow_hashref()) { + my $queryAge = time - $row->{query_start}; + if ($queryAge > $queryTimeout) { + my $id = $row->{procpid}; + $sth_kill->execute($id); + } + } + + return 1; +} + +sub mkCaseSensitive { + my $self = shift; + my @whereStr = @_; + + # postgresql is case sensitive by default + + return @whereStr; +} + +sub _log { + DBIEasy::_log(@_); +} + +sub _carp { + DBIEasy::_carp(@_); +} + +sub _croak { + DBIEasy::_croak(@_); +} + +1; + +# vim:ts=2:sts=2:sw=2 diff -Nru haci-0.97c/modules/DBIEasy.pm haci-0.98c/modules/DBIEasy.pm --- haci-0.97c/modules/DBIEasy.pm 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/modules/DBIEasy.pm 2012-07-09 21:20:21.000000000 +0000 @@ -3,15 +3,17 @@ use strict; use Carp qw/carp croak/; use DBI; +use Data::Dumper; + +use HaCi::Conf qw/getConfigValue/; my $dbHandles = {}; my $initConf = {}; -my $timeout = 300; our $lastError = ''; BEGIN { no strict 'refs'; - foreach my $attr (qw/error errorStrs dbhost dbname dbuser dbpass PK dbh/) { + foreach my $attr (qw/error errorStrs dbhost dbname dbuser dbpass dbtype PK dbh cols2Meths meths2Cols/) { *{$attr} = sub { my $proto = shift; my $value = shift; @@ -56,26 +58,54 @@ $self->{CONFIG} = $config; } - return undef unless &init($self); + return undef unless $self->init(); - my $dbh = &getDBConn($self); + my $dbh = $self->getDBConn(); if ($dbh) { + DBI->trace(&getConfigValue('misc', 'dbitrace')); $self->dbh($dbh); - if (&initChecks($self)) { - $self->PK(&getPK($self)); - &initSubRefs($self); + if ($self->initChecks()) { + $self->PK($self->getPK()); + $self->initSubRefs(); return $self; } } return undef; } +sub getDBConn { + my $self = shift; + my $dbh = undef; + + if ($dbHandles->{$$}->{$self->dbhost}->{$self->dbname}) { + $dbh = $dbHandles->{$$}->{$self->dbhost}->{$self->dbname}; + $self->_carp("Taking allready connected database handle: $dbh ($$: " . $self->TABLE() . ")") if 0; + $self->dbh($dbh); + unless ($dbh->ping) { + $self->_carp("Mhh, that old handle doesn't smell well. Better taking a new one!"); + $dbh = undef; + } + } + unless (defined $dbh) { + $dbh = DBI->connect($self->getDSN(), { + PrintError => 0, + AutoCommit => 1 + }); + $self->_croak($DBI::errstr) unless $dbh; + $self->checkForOldHandles($dbh) if defined $dbh; + } + $dbHandles->{$$}->{$self->dbhost}->{$self->dbname} = $dbh; + $self->dbh($dbh); + return $dbh; +} + sub init { my $self = shift; - foreach ('dbhost', 'dbname', 'dbuser', 'dbpass') { + foreach ('dbhost', 'dbname', 'dbuser', 'dbpass', 'dbtype') { my $key = $_; + $self->{CONFIG}->{$key} = 'mysql' if $key eq 'dbtype' && !defined $self->{CONFIG}->{$key}; unless ($self->{$key}) { if ($self->{CONFIG}->{$key}) { $self->$key($self->{CONFIG}->{$key}); @@ -88,14 +118,55 @@ return 1; } +sub mapColNames { + my $self = shift; + my @columns = @_; + my @mappedColumns = (); + my $col2Meth = $self->col2Meth(); + + return @columns unless $self->can('columnMapping'); + + my $columnMapping = $self->columnMapping(); + die "columnMapping in " . ref($self) . " is not a valid hash!" unless ref($columnMapping) eq 'HASH'; + + foreach (keys %{$columnMapping}) { + $col2Meth->{$columnMapping->{$_}} = $_; + } + + map { + $_ = $col2Meth->{$_} if exists $col2Meth->{$_} && $col2Meth->{$_}; + } @columns; + + $self->cols2Meths($col2Meth); + $self->meths2Cols($columnMapping); + + return @columns; +} + +sub meth2Col { + my $self = shift; + my $meth = shift; + my $meths2Cols = $self->meths2Cols(); + + return (exists $meths2Cols->{$meth}) ? $meths2Cols->{$meth} : $meth; +} + +sub col2Meth { + my $self = shift; + my $col = shift; + my $cols2Meths = $self->cols2Meths(); + + return (exists $cols2Meths->{$col}) ? $cols2Meths->{$col} : $col; +} + sub initSubRefs { my $self = shift; - + no strict 'refs'; - foreach (&getColoumns($self)) { + foreach ($self->mapColNames($self->getColoumns())) { my $col = $_; - next unless $col; + unless ($self->can($col)) { *{(ref $self) . "::$col"} = sub { my $self = shift; @@ -110,149 +181,33 @@ } } -sub getDBConn { - my $self = shift; - my $dbh = undef; - - if ($dbHandles->{$$}->{$self->dbhost}->{$self->dbname}) { - $dbh = $dbHandles->{$$}->{$self->dbhost}->{$self->dbname}; - $self->_carp("Taking allready connected Database Handle: $dbh ($$: " . $self->TABLE() . ")") if 0; - $self->dbh($dbh); - unless ($dbh->ping) { -# unless (&checkIfTableExists($self)) { - $self->_carp("Mhh, that old Handle doesn't smell well. Better taking a new one!"); - $dbh = undef; - } - } - unless (defined $dbh) { - my @DSN = ( - 'DBI:mysql:' . - 'database=' . $self->dbname . - ';host=' . $self->dbhost, - $self->dbuser, $self->dbpass - ); - - $dbh = DBI->connect(@DSN, { - PrintError => 0, - AutoCommit => 1 - }); - $self->_croak($DBI::errstr) unless $dbh; - &checkForOldHandles($dbh) if defined $dbh; - } - $dbHandles->{$$}->{$self->dbhost}->{$self->dbname} = $dbh; - $self->dbh($dbh); - return $dbh; -} - sub initChecks { my $self = shift; my $dbh = $self->dbh; my $error = 0; - $error = 1 unless &checkIfTableExists($self); + $error = 1 unless $self->checkIfTableExists(); return ($error == 0) ? 1 : 0; } sub clear { my $self = shift; - foreach (&getColoumns($self)) { + foreach (keys %{$self->{COLOUMNS}}) { $self->$_(undef); } $self->error(0); $self->errorStrs(''); } -sub checkIfTableExists { - my $self = shift; - my $dbh = $self->dbh; - my $table = $self->TABLE; - - my @tables = $dbh->tables(undef, undef, $table); - unless (grep {/^(`?$self->{dbname}`?.)?`?$table`?$/} @tables) { - if ($self->SETUPTABLE) { - $self->_carp("Table '$table' doesn't exist, try to create it...\n"); - my $createStmt = "CREATE TABLE `$table` (" . $self->CREATETABLE . ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; - $dbh->do($createStmt) or $self->_croak($dbh->errstr); - - my @tables = $dbh->tables(undef, undef, $table); - unless (grep {/^(`?$self->{dbname}`?.)?`?$table`?$/} @tables) { - $self->_croak("Sorry, after creating the Table '$table', it isn't there?"); - return 0; - } - } else { - $self->_croak("Table '$table' doesn't exist!"); - return 0; - } - } - return 1; -} - -sub getPK { - my $self = shift; - my $dbh = $self->dbh; - my $table = $self->TABLE; - my @PKs = (); - - my $sth = $dbh->prepare("SHOW INDEX FROM $table"); - $sth->execute; - $self->_croak($dbh->errstr) if $dbh->errstr; - if ($sth) { - my $hashRef = $sth->fetchall_hashref(['Key_name', 'Seq_in_index']); - foreach (keys %{$hashRef}) { - my $key = $_; - foreach (keys %{$hashRef->{$key}}) { - if ($key eq 'PRIMARY') { - push @PKs, $hashRef->{$key}->{$_}->{Column_name}; - } - } - } - } - if ($#PKs == -1) { - $self->_croak("No Primary Keys in Table '$table'!"); - } else { - return \@PKs; - } -} +sub count { + my $self = shift; + my $qryRestr = shift || 0; + my $bLike = shift || 0; + my $appStr = shift || 0; + my $distinct = shift || 0; -sub getShowCreate { - my $self = shift; - my $dbh = $self->dbh; - my $table = $self->TABLE; - - my $sth = $dbh->prepare("SHOW CREATE TABLE `$table`"); - $sth->execute; - $self->_croak($dbh->errstr) if $dbh->errstr; - - if ($sth) { - my $showCreatet = $sth->fetchall_arrayref([1]); - if (defined $showCreatet) { - my $showCreate = $$showCreatet[0]; - return $$showCreate[0]; - } else { - $self->_carp("Sorry, Show Create Table '$table' doesn't work!"); - return ''; - } - } -} - - -sub getColoumns { - my $self = shift; - my $dbh = $self->dbh; - my $table = $self->TABLE; - - my $sth = $dbh->prepare("DESCRIBE `$table`"); - $sth->execute; - $self->_croak($dbh->errstr) if $dbh->errstr; - - if ($sth) { - my $hashRef = $sth->fetchall_hashref('Field'); - return ((defined $hashRef && ref $hashRef eq 'HASH') ? keys %{$hashRef} : ()); - } else { - $self->_carp("Sorry, no Columns found!"); - return (); - } + return $self->search('%COUNT%', $qryRestr, $bLike, $appStr, $distinct); } sub search { @@ -264,14 +219,29 @@ my $distinct = shift || 0; my $pk = $self->PK; my $dbh = $self->dbh; + my $table = $self->TABLE; my @rows = (); my @whereStr = (); + my @whereVals = (); my $con = 'AND'; my $cs = ''; + my $count = 0; - foreach (@$pk) { - my $pkt = $_; - push @$qryCols, $pkt unless grep {/^$pkt$/} @$qryCols; + if (ref($qryCols) eq '' && $qryCols eq '%COUNT%') { + $qryCols = []; + $count = 1; + } + + # map db method to db column + foreach (@{$qryCols}) { + $_ = $self->meth2Col($_) + } + + unless ($count) { + foreach (@$pk) { + my $pkt = $_; + push @$qryCols, $pkt unless grep {/^$pkt$/} @$qryCols; + } } if ($qryRestr) { @@ -283,7 +253,8 @@ elsif ($_ eq '%CS%') { $cs = $qryRestr->{$_}; } else { - push @whereStr, $_ . (($bLike) ? ' LIKE ' : ' = ') . "'" . $qryRestr->{$_} . "'"; + push @whereStr, $self->meth2Col($_) . (($bLike) ? ' LIKE ' : ' = ') . '?'; + push @whereVals, $qryRestr->{$_}; } } } @@ -291,25 +262,42 @@ $whereStr[0] = $qryRestr; } } - map {$_ = 'binary ' . $_;} @whereStr if $cs; - - my $prStr = "SELECT " . (($distinct) ? 'DISTINCT ' : '') . join(',', @$qryCols) . ' FROM ' . $self->TABLE . (($#whereStr > -1) ? ' WHERE ' . join(" $con ", @whereStr) : ''); + @whereStr = $self->mkCaseSensitive(@whereStr) if $cs; + + my $prStr = + "SELECT " . + (($count) ? 'COUNT(*) as cnt' : '') . + (($distinct) ? 'DISTINCT ' : '') . + join(',', @$qryCols) . + ' FROM ' . $dbh->quote_identifier($table) . + (($#whereStr > -1) ? + ' WHERE ' . join(" $con ", @whereStr) : + '' + ); $prStr .= ' ' . $appStr if $appStr; - warn "STRING: " . join('', split(/\n/, $prStr)) . "\n" if 0; + warn "SEARCH: " . join('', split(/\n/, $prStr)) . " < @whereVals" if 0; my $sth = $dbh->prepare($prStr); $self->_carp($dbh->errstr()) if $dbh->errstr(); - $sth->execute; + $sth->trace('SQL') if 0; + $sth->execute(@whereVals); $self->_carp($dbh->errstr()) if $dbh->errstr(); + if ($count) { + my $cnter = $sth->fetchall_arrayref(); + return ${${$cnter}[0]}[0]; + } + my $hashRef = $sth->fetchall_hashref($pk); $self->_carp($dbh->errstr()) if $dbh->errstr(); my $pkCnter = 1; - push @rows, &getRows($self, $hashRef, $pkCnter); + push @rows, $self->getRows($hashRef, $pkCnter); + warn "RETURN: " . Dumper(@rows) if 0; + return @rows; } @@ -322,10 +310,16 @@ return @rows unless ref $hashRef eq 'HASH'; foreach (keys %{$hashRef}) { + my $cPK = $_; if ($pkCnter < ($#{$self->{PK}} + 1)) { - push @rows, &getRows($self, $hashRef->{$_}, ($pkCnter + 1)); + push @rows, $self->getRows($hashRef->{$cPK}, ($pkCnter + 1)); } else { - push @rows, $hashRef->{$_}; + my $mappedHash = {}; + foreach (keys %{$hashRef->{$cPK}}) { + my $col = $_; + $mappedHash->{$self->col2Meth($col)} = $hashRef->{$cPK}->{$col}; + } + push @rows, $mappedHash; } } @@ -335,13 +329,7 @@ sub insert { my $self = shift; - return &modify($self, 'INSERT'); -} - -sub replace { - my $self = shift; - - return &modify($self, 'REPLACE'); + return $self->modify('INSERT'); } sub update { @@ -350,7 +338,7 @@ my $bLike = shift; my $appStr = shift || 0; - return &modify($self, 'UPDATE', $rowRestr, $bLike, $appStr); + return $self->modify('UPDATE', $rowRestr, $bLike, $appStr); } sub delete { @@ -359,7 +347,7 @@ my $bLike = shift; my $appStr = shift || 0; - return &modify($self, 'DELETE', $rowRestr, $bLike, $appStr); + return $self->modify('DELETE', $rowRestr, $bLike, $appStr); } sub modify { @@ -370,14 +358,15 @@ my $appStr = shift || 0; my $dbh = $self->dbh; my $table = $self->TABLE; - my @adds = (); + my $col2Meth = $self->col2Meth(); my @whereStr = (); + my @whereVals = (); my $modStr = $type; my $con = 'AND'; - $modStr .= ' INTO' if $type eq 'INSERT' || $type eq 'REPLACE'; + $modStr .= ' INTO' if $type eq 'INSERT'; $modStr .= ' FROM' if $type eq 'DELETE'; - $modStr .= ' ' . $table; - $modStr .= ' SET ' if $type eq 'INSERT' || $type eq 'REPLACE' || $type eq 'UPDATE'; + $modStr .= ' ' . $dbh->quote_identifier($table); + $modStr .= ' SET' if $type eq 'UPDATE'; if ($rowRestr) { if (ref $rowRestr eq 'HASH') { @@ -386,7 +375,8 @@ if ($row eq 'CON') { $con = $rowRestr->{CON}; } else { - push @whereStr, $row . (($bLike) ? ' LIKE ' : ' = ') . "'" . $rowRestr->{$row} . "'"; + push @whereStr, $self->meth2Col($row) . (($bLike) ? ' LIKE ' : ' = ') . '?'; + push @whereVals, $rowRestr->{$row}; } } } @@ -397,21 +387,38 @@ $self->_log("$type in $table") if 0; + my @cols = (); + my @vals = (); foreach (keys %{$self->{COLOUMNS}}) { my $value = $self->{COLOUMNS}->{$_}; if (defined $value) { - $value = $dbh->quote($value); - push @adds, "$_=$value"; + my $col = $self->meth2Col($_); + if ($type eq 'UPDATE') { + $modStr .= ',' if $modStr !~ / SET$/; + $modStr .= " $col = ?"; + } + unless ($type eq 'DELETE') { + push @cols, $col; + push @vals, $value; + } } } - $modStr .= join(', ', @adds) if $type eq 'INSERT' || $type eq 'REPLACE' || $type eq 'UPDATE'; + if ($type eq 'INSERT') { + $modStr .= ' (' . join(', ', @cols) . ') VALUES (' . join(', ', map {'?'} (1 .. scalar @vals)) . ')' + } + $modStr .= ' WHERE ' . join(" $con ", @whereStr) if $#whereStr > -1; $modStr .= ' ' . $appStr if $appStr; - warn $modStr if 0; - my $rows = $dbh->do($modStr); + warn "DB-UPDATE: $modStr (" . join(', ', @vals) . '; ', join(', ', @whereVals) if 0; + my $sth = $dbh->prepare($modStr); $self->_carp($dbh->errstr()) if $dbh->errstr(); + + $sth->trace('SQL') if 0; + my $rows = $sth->execute(@vals, @whereVals); + $self->_carp($dbh->errstr()) if $dbh->errstr(); + return $rows; } @@ -427,7 +434,10 @@ } sub _log { - _carp(@_); + my $self = shift, + my @msg = @_; + + $self->_carp(@_); } sub _carp { @@ -437,7 +447,13 @@ $self->error(1); $self->errorStrs($message); $lastError .= $message; - warn "DB " . (ref $self) . ' [' . (caller(4))[3] . '->' . (caller(3))[3] . '->' . (caller(2))[3] . "]: $message"; + warn "DB " . + (ref $self) . + ' [' . (caller(4))[3] . + '->' . (caller(3))[3] . + '->' . (caller(2))[3] . ':' . (caller(1))[2] . + '->' . (caller(1))[3] . ':' . (caller(0))[2] . + "]: $message"; } else { Carp::carp($message || $self); } @@ -459,26 +475,6 @@ return; } -sub checkForOldHandles { - my $dbh = shift; - - my $sth_sh_proc = $dbh->prepare("show full processlist"); - my $sth_kill = $dbh->prepare("kill ?"); - - unless ($sth_sh_proc->execute()) { - _carp("Unable to execute show procs [" . $dbh->errstr() . "]"); - return 0; - } - while (my $row = $sth_sh_proc->fetchrow_hashref()) { - if ($row->{Command} eq 'Sleep' && $row->{Time} > $timeout) { - my $id = $row->{Id}; - $sth_kill->execute($id); - } - } - - return 1; -} - END { foreach (keys %{$dbHandles}) { my $host = $_; diff -Nru haci-0.97c/modules/HaCi/Authentication/imap.pm haci-0.98c/modules/HaCi/Authentication/imap.pm --- haci-0.97c/modules/HaCi/Authentication/imap.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/Authentication/imap.pm 2011-07-07 20:45:57.000000000 +0000 @@ -7,7 +7,6 @@ require Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(getCryptPassword); our $conf; *conf = \$HaCi::Conf::conf; diff -Nru haci-0.97c/modules/HaCi/Authentication/internal.pm haci-0.98c/modules/HaCi/Authentication/internal.pm --- haci-0.97c/modules/HaCi/Authentication/internal.pm 2010-03-08 17:22:58.000000000 +0000 +++ haci-0.98c/modules/HaCi/Authentication/internal.pm 2015-02-13 23:32:19.000000000 +0000 @@ -1,6 +1,7 @@ package HaCi::Authentication::internal; use strict; +use Data::Dumper; use HaCi::Log qw/warnl debug/; use HaCi::GUI::gettext qw/_gettext/; use POSIX qw(strftime); @@ -59,13 +60,14 @@ my $userTable = $conf->{var}->{TABLES}->{user}; unless (defined $userTable) { - $conf->{var}->{authenticationError} = HaCi::Utils::_gettext("Authentication failed: Database Error!"); + $conf->{var}->{authenticationError} = HaCi::Utils::_gettext("Authentication failed: Database error!"); return 0; } my $user = ($userTable->search(['*'], {username => $self->user()}))[0]; unless (defined $user) { + warn "User '" . $self->user() . "' not found in database!\n"; $conf->{var}->{authenticationError} = HaCi::Utils::_gettext("Authentication failed!"); return 0; } else { @@ -74,6 +76,11 @@ my $password = $user->{password}; + if ($password eq '') { + $conf->{var}->{authenticationError} = HaCi::Utils::_gettext("Internal account is disabled."); + return 0; + } + my $newPass = &getCryptPassword($self->pass()); if ($password eq $newPass) { @@ -105,9 +112,11 @@ } if (defined $self->{sess}->param('username')) { - my $user = ($userTable->search(['ID'], {username => $self->{sess}->param('username')}))[0]; - + my $userParam = $self->{sess}->param('username'); + my $user = ($userTable->search(['ID'], {username => $userParam}))[0]; + if (!defined $user || !exists $user->{ID}) { + warn "User '$userParam' not found in database!\n"; $conf->{var}->{authenticationError} = HaCi::Utils::_gettext("Authentication failed!"); $self->{sess}->clear('authenticated'); $self->{sess}->param('authenticated', 0); @@ -136,12 +145,12 @@ my @users = $userTable->search(['ID']); if ($#users == -1) { - &HaCi::Utils::warnl("No Users available! Generating new Admin User with no Password! Please change it right after you logged in!"); + &HaCi::Utils::warnl("No users available! Generating new admin user with empty password! Please change it right after you logged in!"); my $pass = &getCryptPassword(''); my $groupTable = $conf->{var}->{TABLES}->{group}; unless (defined $groupTable) { - warn "Cannot init Authentication! DB Error (group)\n"; + warn "Cannot init authentication! DB Error (group)\n"; return 0; } my $adminGroup = ($groupTable->search(['ID'], {name => 'Administrator'}))[0]; @@ -151,16 +160,23 @@ $userTable->groupIDs(' ' . $adminGroup->{ID} . ','); my $DB = ($userTable->search(['ID'], {username => 'admin'}))[0]; if ($DB) { - $userTable->ID($DB->{'ID'}); $userTable->modifyFrom($session->param('username')); $userTable->modifyDate(&HaCi::Utils::currDate('datetime')); &HaCi::Utils::debug("Change User 'admin'\n"); - return $userTable->replace(); + unless ($userTable->update({ID => $DB->{ID}})) { + &warnl("Cannot update admin user: " . $groupTable->errorStrs); + return 0; + } + return 1; } else { $userTable->ID(undef); $userTable->createFrom($session->param('username')); $userTable->createDate(&HaCi::Utils::currDate('datetime')); - return $userTable->insert(); + unless ($userTable->insert()) { + &warnl("Cannot create admin user: " . $groupTable->errorStrs); + return 0; + } + return 1; } } } @@ -188,16 +204,23 @@ $groupTable->permissions('1' . $rightsStr); my $DB = ($groupTable->search(['ID'], {name => 'Administrator'}))[0]; if ($DB) { - $groupTable->ID($DB->{'ID'}); $groupTable->modifyFrom($session->param('username')); $groupTable->modifyDate(&HaCi::Utils::currDate('datetime')); &HaCi::Utils::debug("Change Group 'Administrator'\n"); - return $groupTable->replace(); + unless ($groupTable->update({ID => $DB->{ID}})) { + &warnl("Cannot update admin group: " . $groupTable->errorStrs); + return 0; + } + return 1; } else { $groupTable->ID(undef); $groupTable->createFrom($session->param('username')); $groupTable->createDate(&HaCi::Utils::currDate('datetime')); - return $groupTable->insert(); + unless ($groupTable->insert()) { + &warnl("Cannot create admin group: " . $groupTable->errorStrs); + return 0; + } + return 1; } } return 1; @@ -231,13 +254,8 @@ sub bin2dec { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $bin = shift; - my $dec = 0; - my $cnter = 0; - foreach (split//, reverse $bin) { - $dec += 2 ** $cnter if $_; - $cnter++; - } + my $dec = oct("0b" . $bin); return $dec; } diff -Nru haci-0.97c/modules/HaCi/Authentication/ldap.pm haci-0.98c/modules/HaCi/Authentication/ldap.pm --- haci-0.97c/modules/HaCi/Authentication/ldap.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Authentication/ldap.pm 2014-08-28 22:12:24.000000000 +0000 @@ -0,0 +1,154 @@ +package HaCi::Authentication::ldap; + +use strict; +use HaCi::Log qw/warnl debug/; +use HaCi::GUI::gettext qw/_gettext/; +use Net::LDAP; +use Data::Dumper; + +require Exporter; +our @ISA = qw(Exporter); + +our $conf; *conf = \$HaCi::Conf::conf; + +sub new { + my $class = shift; + my $self = {}; + + bless $self, $class; + return $self; +} + +sub user { + my $self = shift; + my $user = shift; + + if (defined $user) { + $self->{user} = $user; + } else { + return $self->{user}; + } +} + +sub pass { + my $self = shift; + my $pass = shift; + + if (defined $pass) { + $self->{pass} = $pass; + } else { + return $self->{pass}; + } +} + +sub session { + my $self = shift; + my $sess = shift; + + if (defined $sess) { + $self->{sess} = $sess; + } else { + return $self->{sess}; + } +} + +sub authenticate { + my $self = shift; + my $user = $self->user(); + + $self->{sess}->param('authenticated', 0); + + my $ldap = undef; + my $host = $conf->{user}->{auth}->{authparams}->{ldap}->{host} || ['localhost']; + + my $bOK = 0; + foreach (@{$host}) { + my $host = $_; + unless ($ldap = Net::LDAP->new($host)) { + my $error = "Authentication failed: Cannot connect to LDAP Server '$host': " . $@; + $conf->{var}->{authenticationError} .= $error . '
'; + warn $error; + } else { + $bOK = 1; + last; + } + } + return 0 unless $bOK; + + + my $bindDN = $conf->{user}->{auth}->{authparams}->{ldap}->{binddn} || ''; + my $bindPW = $conf->{user}->{auth}->{authparams}->{ldap}->{bindpw} || ''; + my $baseDN = $conf->{user}->{auth}->{authparams}->{ldap}->{basedn} || ''; + my $filter = $conf->{user}->{auth}->{authparams}->{ldap}->{filter} || ''; + if ($filter) { + unless ($bindPW) { + $conf->{var}->{authenticationError} = "Authentication failed: No passsword configured for binding"; + return 0; + } + + my $msg = $ldap->bind($bindDN, password => $bindPW); + if ($msg->code()) { + $conf->{var}->{authenticationError} = "Authentication failed: Cannot bind to LDAP server"; + return 0; + } + + $filter =~ s//$user/g; + my $search = $ldap->search( + base => $baseDN, + filter => $filter, + scope => 'sub', + attrs => ['cn'] + ); + my @results = $search->entries; + if ($#results < 0) { + $conf->{var}->{authenticationError} = "Authentication failed: User not known"; + return 0; + } + $bindDN = $results[0]->dn(); + + } else { + $bindDN =~ s//$user/g; + } + + &HaCi::Utils::debug("Authenticate [ldap] with: $bindDN\n"); + + my $login = $ldap->bind ($bindDN, password => $self->pass()); + if ($login->code) { + &HaCi::Utils::debug("Authentication Failed: " . $login->error() . "\n"); + $conf->{var}->{authenticationError} = _gettext("Authentication failed!"); + } else { + $self->{sess}->param('authenticated', 1); + $self->{sess}->param('username', $self->user()); + &HaCi::Utils::debug("Sucessfully logged in!"); + } + + return &isAutenticated($self); +} + +sub isAutenticated { + my $self = shift; + + my $username = $self->{sess}->param('username') || $self->user(); + + if ($username) { + my $userTable = $conf->{var}->{TABLES}->{user}; + unless (defined $userTable) { + warn "Cannot authenticate! DB Error (user)\n"; + return 0; + } + + my $user = ($userTable->search(['ID'], {'%CS%' => 1, username => $username}))[0]; + + if (!defined $user || !exists $user->{ID}) { + &debug("Authentication failed: User '$username' not in Database!"); + $conf->{var}->{authenticationError} = _gettext("Authentication failed!"); + $self->{sess}->clear('authenticated'); + $self->{sess}->param('authenticated', 0); + return 0; + } + } + + return (defined $self->{sess}->param('authenticated')) ? $self->{sess}->param('authenticated') : 0; +} + +1; diff -Nru haci-0.97c/modules/HaCi/GUI/authentication.pm haci-0.98c/modules/HaCi/GUI/authentication.pm --- haci-0.97c/modules/HaCi/GUI/authentication.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/GUI/authentication.pm 2014-12-31 04:51:33.000000000 +0000 @@ -3,8 +3,8 @@ use strict; use HaCi::Conf qw/getConfigValue/; +use HaCi::Utils qw/getParam/; use HaCi::GUI::init; - use HaCi::GUI::gettext qw/_gettext/; our $conf; *conf = \$HaCi::Conf::conf; @@ -31,7 +31,7 @@ { target => 'value', type => 'textfield', - value => (defined $q->param('username')) ? $q->param('username') : '', + value => &getParam(1, '', 'username', 1), name => 'username', size => 13, maxlength => 255, diff -Nru haci-0.97c/modules/HaCi/GUI/gettext.pm haci-0.98c/modules/HaCi/GUI/gettext.pm --- haci-0.97c/modules/HaCi/GUI/gettext.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/GUI/gettext.pm 2012-07-15 00:56:50.000000000 +0000 @@ -27,7 +27,7 @@ } sub initLocale { - my $locale = shift; + my $locale = shift || 'C'; setlocale(LC_ALL, $locale); $conf->{var}->{GETTEXT} = Locale::gettext->domain_raw('HaCi'); diff -Nru haci-0.97c/modules/HaCi/GUI/init.pm haci-0.98c/modules/HaCi/GUI/init.pm --- haci-0.97c/modules/HaCi/GUI/init.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/GUI/init.pm 2014-08-28 22:12:24.000000000 +0000 @@ -31,7 +31,7 @@ $locale = 'C' unless defined $locale && $locale; &initLocale($locale); - $s->param('locale', $locale); + $s->param('locale', $locale) if defined $s; } $t->{T} = Template->new( @@ -48,9 +48,11 @@ sub setUserVars { my $s = $HaCi::HaCi::session; - $t->{V}->{showTreeStructure} = (defined $s->param('settings') && exists $s->param('settings')->{bShowTreeStruct}) ? ${$s->param('settings')->{bShowTreeStruct}}[0] : $conf->{user}->{gui}->{showtreestructure}; + $t->{V}->{showTreeStructure} = (defined $s && defined $s->param('settings') && exists $s->param('settings')->{bShowTreeStruct}) ? + ${$s->param('settings')->{bShowTreeStruct}}[0] : + $conf->{user}->{gui}->{showtreestructure}; $t->{V}->{directaccess} = $conf->{user}->{gui}->{directaccess}; - my $style = (defined $s->param('settings') && exists $s->param('settings')->{layout}) ? ${$s->param('settings')->{layout}}[0] : $conf->{user}->{gui}->{style} || $conf->{static}->{gui}->{style}; + my $style = (defined $s && defined $s->param('settings') && exists $s->param('settings')->{layout}) ? ${$s->param('settings')->{layout}}[0] : $conf->{user}->{gui}->{style} || $conf->{static}->{gui}->{style}; foreach (@{$conf->{static}->{gui}->{layouts}}) { my $layout = $_; diff -Nru haci-0.97c/modules/HaCi/GUI/main.pm haci-0.98c/modules/HaCi/GUI/main.pm --- haci-0.97c/modules/HaCi/GUI/main.pm 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/modules/HaCi/GUI/main.pm 2015-03-04 00:44:02.000000000 +0000 @@ -2,6 +2,7 @@ use warnings; use strict; +use Data::Dumper; use HaCi::Utils qw/ getRoots getNextDBNetwork getWHOISData getNSData checkSpelling_Net getNrOfChilds rootID2Name getMaintInfosFromRoot getPluginValue @@ -9,10 +10,11 @@ getGroups getGroup groupID2Name getUsers getUser userID2Name dec2bin lwd checkRight netID2Stuff getNetworkParentFromDB nd dn parseCSVConfigfile getID getStatus removeStatus expand getDBNetworkBefore getNetID getPlugins getPluginsForNet pluginID2Name updatePluginLastRun rootID2ipv6 checkRootACL checkNetACL netv6Dec2ipv6ID getPluginInfos setStatus getPluginConfMenu pluginName2ID - getFreeSubnets pluginID2File getSettings userName2ID quoteHTML getConfigValue _gettext + getFreeSubnets pluginID2File getSettings userName2ID quoteHTML getConfigValue _gettext getPluginConfValues getAuditLogs getRights + getParam getAvailTags tmplName2ID /; use HaCi::Mathematics qw/ - dec2net net2dec getBroadcastFromNet dec2ip getIPFromDec getNetmaskFromCidr getNetaddress getV6BroadcastNet ipv62dec + dec2net net2dec getBroadcastFromNet dec2ip getIPFromDec getNetmaskFromCidr getNetaddress getV6BroadcastNet ipv62dec ipv6Sort netv6Dec2net getV6BroadcastIP ipv6Dec2ip netv62Dec netv6Dec2IpCidr ipv6DecCidr2NetaddressV6Dec ipv6DecCidr2netv6Dec /; use HaCi::Log qw/warnl debug/; @@ -33,7 +35,7 @@ my $q = $HaCi::HaCi::q; my $s = $HaCi::HaCi::session; - if (my $func = $q->param('func')) { + if (my $func = &getParam(1, undef, 'func')) { if ($func eq 'addRoot' && &checkRight('addRoot')) { $t->{V}->{mainPage} = 'addRoot'; &mkAddRoot(); @@ -81,7 +83,7 @@ } elsif ($func eq 'importConfig' && &checkRight('impConfig')) { $t->{V}->{mainPage} = 'importConfig'; - if (defined $q->param('source') && $q->param('source') eq 'csv') { + if (&getParam(1, 0, 'source') && &getParam(1, '', 'source') eq 'csv') { &mkImportCSV(); } else { &mkImportConfig(); @@ -89,7 +91,7 @@ } elsif ($func eq 'showNet' && &checkRight('showNetDet')) { $t->{V}->{mainPage} = 'showNet'; - my ($rootID, $networkDec) = &netID2Stuff($q->param('netID')); + my ($rootID, $networkDec) = &netID2Stuff(&getParam(1, 0, 'netID')); $s->param('currNet', $networkDec); $s->param('currRootID', $rootID); &mkShowNet(); @@ -102,6 +104,10 @@ $t->{V}->{mainPage} = 'search'; &mkSearch(); } + elsif ($func eq 'getFreeSubnetsFromSearch' && &checkRight('search') && &checkRight('addNet')) { + $t->{V}->{mainPage} = 'getFreeSubnetsFromSearch'; + &mkSearch(); + } elsif ($func eq 'compare' && &checkRight('search')) { $t->{V}->{mainPage} = 'compare'; &mkCompare(); @@ -173,6 +179,10 @@ $t->{V}->{mainPage} = 'showSettings'; &mkShowSettings(); } + elsif ($func eq 'showAuditLogs') { + $t->{V}->{mainPage} = 'showAuditLogs'; + &mkShowAuditLogs(); + } } else { $t->{V}->{mainPage} = 'showAllNets'; &mkTree(); @@ -186,8 +196,8 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $bEditTree = $q->param('editTree'); - my $roots = &getRoots(); + my $bEditTree = &getParam(1, 0, 'editTree'); + my $roots = &getRoots(1); map {my $h=$_;$h->{name} = "eHTML($h->{name}); $_ = $h;} @{$roots}; $t->{V}->{rootID2Ver} = $roots; @@ -210,7 +220,7 @@ name => 'rootIDJump', size => 1, values => $roots, - selected => (($q->param('rootID')) ? [$q->param('rootID')] : []), + selected => (defined (&getParam(1, undef, 'rootID')) ? [&getParam(1, 0, 'rootID')] : []), onChange => 'javascript:checkIfIPv6(this.value, "TREE")', }, { @@ -219,9 +229,9 @@ name => 'jumpTo', size => 25, maxlength => 39, - value => ((defined $q->param('jumpTo') && $q->param('jumpTo') ne '') ? $q->param('jumpTo') : '<' . _gettext('IP address') . '>'), - style => ((defined $q->param('jumpTo')) ? '' : 'color:#AAAAAA'), - onClick => ((defined $q->param('jumpTo')) ? '' : "clearTextfield('jumpTo')"), + value => ((&getParam(1, 0, 'jumpTo') && &getParam(1, '', 'jumpTo') ne '') ? &getParam(1, 0, 'jumpTo', 1) : '<' . _gettext('IP address') . '>'), + style => ((defined &getParam(1, undef, 'jumpTo')) ? '' : 'color:#AAAAAA'), + onClick => ((defined &getParam(1, undef, 'jumpTo')) ? '' : "clearTextfield('jumpTo')"), onKeyDown => "submitOnEnter(event, 'jumpToButton')", }, { @@ -348,7 +358,7 @@ name => 'copyToRootID', size => 1, values => $roots, - selected => (($q->param('rootID')) ? [$q->param('rootID')] : []), + selected => ((&getParam(1, 0, 'rootID')) ? [&getParam(1, undef, 'rootID')] : []), }, ] } @@ -366,7 +376,6 @@ my $rootTable = $conf->{var}->{TABLES}->{root}; my $networkTable = $conf->{var}->{TABLES}->{network}; my $expands = $s->param('expands') || {}; - my $expandAll = (defined $q->param('expandAll') && $q->param('expandAll')) ? 1 : 0; unless (defined $rootTable || defined $networkTable) { warn "Cannot generate Tree. DB Error\n"; return 0; @@ -384,7 +393,7 @@ &mkTreeNetwork(\$tree, $rootID, $ipv6, (($ipv6) ? Math::BigInt->new(0) : 0), 0, 0); } $t->{V}->{tree} = $tree->print_html(); - $t->{V}->{editTree} = (defined $q->param('editTree')) ? $q->param('editTree') : 0; + $t->{V}->{editTree} = &getParam(1, 0, 'editTree'); } sub mkTreeNetwork { @@ -400,7 +409,7 @@ my $s = $HaCi::HaCi::session; my $q = $HaCi::HaCi::q; my $expands = $s->param('expands') || {}; - my $expandAll = (defined $q->param('expandAll') && $q->param('expandAll')) ? 1 : 0; + my $expandAll = (&getParam(1, 0, 'expandAll')) ? 1 : 0; my $networkDecOrig = ($ipv6) ? $networkDec->copy() : $networkDec; if ($bAddParent) { @@ -453,7 +462,7 @@ $tree->setRootName($rootID, $rootName); $tree->setRootDescr($rootID, $rootDescr); $tree->setRootExpanded($rootID, (($expandAll || $expands->{root}->{$rootID}) ? 1 : 0)); - $tree->setRootParent($rootID, ((defined &getNextDBNetwork($rootID, $ipv6, 0)) ? 1 : 0)); + $tree->setRootParent($rootID, ((defined &getNextDBNetwork($rootID, $ipv6, (($ipv6) ? Math::BigInt->new(0) : 0))) ? 1 : 0)); $tree->setRootV6($rootID, $ipv6); } @@ -480,6 +489,22 @@ } } + while ($description =~ /\%\*(.*?)\*\%/) { + my ($tmpl, $name) = split/\%/, $1; + if ($tmpl && $name) { + my $tmplID = &tmplName2ID($tmpl); + if ($tmplID ne '') { + my $values = &getTemplateData($netID, $tmplID, 1); + my $value = $values->{$name} || ''; + $description =~ s/\%\*.*?\*\%/$value/; + } else { + last; + } + } else { + last; + } + } + return $description; } @@ -502,13 +527,14 @@ my $status = $networkT->{state}; my $defSubnetSize = $networkT->{defSubnetSize}; my $bACL = 0; - $description = &subDescription($description, $netID) if $description =~ /\%{2}/; + $description = &subDescription($description, $netID) if $description =~ /\%(\%|\*)/; if (&checkSpelling_Net($network, $ipv6)) { + my $bChilds = (defined &getNextDBNetwork($rootID, $ipv6, $networkDec, 1)) ? 1 : 0; $bACL = &checkNetACL($netID, 'r'); $tree->addNet($netID, $rootID, $ipv6, $networkDec, $description, ($status || 0), $networkDecOrig, 0, $defSubnetSize); - $tree->setNetExpanded($rootID, $ipv6, $networkDec, ((($expandAll || $expands->{network}->{$rootID}->{$networkDec}) && $bACL) ? 1 : 0)); - $tree->setNetParent($rootID, $ipv6, $networkDec, ((defined &getNextDBNetwork($rootID, $ipv6, $networkDec, 1)) ? 1 : 0)); + $tree->setNetExpanded($rootID, $ipv6, $networkDec, ((($expandAll || (exists $expands->{network}->{$rootID}->{$networkDec} && $expands->{network}->{$rootID}->{$networkDec})) && $bACL) ? 1 : 0)); + $tree->setNetParent($rootID, $ipv6, $networkDec, (($bChilds || $defSubnetSize) ? 1 : 0)); $tree->setInvisible($rootID, $ipv6, $networkDec, ($bACL == 0) ? 1 : 0); } return $bACL; @@ -521,7 +547,7 @@ my $thisScript = $conf->{var}->{thisscript}; my $menu = [ { - title => sprintf(_gettext("Logged in as %s"), $s->param('username')), + title => sprintf(_gettext("Logged in as %s"), "eHTML($s->param('username'))), entries => [ { title => _gettext("Logout"), @@ -539,13 +565,13 @@ img => '/Images/showAll.png', }, { - title => _gettext("Add Root"), + title => _gettext("Add root"), link => "$thisScript?func=addRoot", img => '/Images/addRoot.png', disabled => (&checkRight('addRoot')) ? 0 : 1, }, { - title => _gettext("Add Network"), + title => _gettext("Add network"), link => "$thisScript?func=addNet", img => '/Images/addNet.png', disabled => (&checkRight('addNet')) ? 0 : 1, @@ -556,13 +582,13 @@ title => _gettext("Import"), entries => [ { - title => _gettext("ASN Routes"), + title => _gettext("ASN routes"), link => "$thisScript?func=importASNRoutes", img => '/Images/impASNRoutes.png', disabled => (&checkRight('impASNRoutes')) ? 0 : 1, }, { - title => _gettext("DNS Zonefile"), + title => _gettext("DNS zonefile"), link => "$thisScript?func=importDNS", img => '/Images/impDNSZoneFile.png', disabled => (&checkRight('impDNS')) ? 0 : 1, @@ -585,13 +611,19 @@ disabled => (&checkRight('search')) ? 0 : 1, }, { + title => _gettext("Search free networks"), + link => "$thisScript?func=getFreeSubnetsFromSearch", + img => '/Images/searchAndAddNet.png', + disabled => (&checkRight('search') && &checkRight('addNet')) ? 0 : 1, + }, + { title => _gettext("Compare"), link => "$thisScript?func=compare", img => '/Images/compare.png', disabled => (&checkRight('search')) ? 0 : 1, }, { - title => _gettext("Flush Cache"), + title => _gettext("Flush cache"), link => "$thisScript?func=flushCache", img => '/Images/flushACL.png', }, @@ -601,30 +633,36 @@ title => _gettext("Maintenance"), entries => [ { - title => _gettext("User Management"), + title => _gettext("User management"), link => "$thisScript?func=showUsers", img => '/Images/userMgmt.png', disabled => (&checkRight('userMgmt')) ? 0 : 1, }, { - title => _gettext("Group Management"), + title => _gettext("Group management"), link => "$thisScript?func=showGroups", img => '/Images/groupMgmt.png', disabled => (&checkRight('groupMgmt')) ? 0 : 1, }, { - title => _gettext("Template Management"), + title => _gettext("Template management"), link => "$thisScript?func=showTemplates", img => '/Images/tmplMgmt.png', disabled => (&checkRight('tmplMgmt')) ? 0 : 1, }, { - title => _gettext("Plugin Management"), + title => _gettext("Plugin management"), link => "$thisScript?func=showPlugins", img => '/Images/pluginMgmt.png', disabled => (&checkRight('pluginMgmt')) ? 0 : 1, }, { + title => _gettext("Audit logs"), + link => "$thisScript?func=showAuditLogs", + img => '/Images/showAuditLogs.png', + disabled => (&checkRight('showAuditLogs')) ? 0 : 1, + }, + { title => _gettext("Settings"), link => "$thisScript?func=showSettings", img => '/Images/configure.png', @@ -647,7 +685,8 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $rootID = $q->param('rootID'); + my $rootID = &getParam(1, undef, 'rootID'); + $rootID =~ s/\D//g; my $root = &getMaintInfosFromRoot($rootID); my $rootACTable = $conf->{var}->{TABLES}->{rootAC}; @@ -693,16 +732,17 @@ my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; my $s = $HaCi::HaCi::session; - my $name = ((defined $q->param('name')) ? "eHTML($q->param('name')) : ''); - my $descr = ((defined $q->param('descr')) ? "eHTML($q->param('descr')) : ''); - my $ipv6 = ((defined $q->param('ipv6')) ? $q->param('ipv6') : 0); - my $bEditRoot = (defined $q->param('editRoot')) ? 1 : 0; - my $nrOfNetworks = ((defined $q->param('rootID')) ? &getNrOfChilds(0, $q->param('rootID')) : 0); + my $name = ((defined &getParam(1, undef, 'name')) ? &getParam(1, '', 'name', 1) : ''); + my $descr = ((defined &getParam(1, undef, 'descr')) ? &getParam(1, '', 'descr', 1) : ''); + my $ipv6 = &getParam(1, 0, 'ipv6'); + $ipv6 = 1 if $ipv6; + my $bEditRoot = (&getParam(1, 0, 'editRoot')) ? 1 : 0; + my $nrOfNetworks = ((defined &getParam(1, undef, 'rootID')) ? &getNrOfChilds(0, &getParam(1, undef, 'rootID')) : 0); if ($bEditRoot) { $t->{V}->{addRootHeader} = sprintf(_gettext("Edit Root %s"), $name); } else { - $t->{V}->{addRootHeader} = _gettext("Add Root"); + $t->{V}->{addRootHeader} = _gettext("Add root"); } $t->{V}->{addRootFormName} = 'addRoot'; $t->{V}->{addRootMenu} = [ @@ -765,7 +805,14 @@ my $groups = {}; foreach (@{&getGroups()}) { - $groups->{$_->{ID}} = $_->{name} unless $_->{name} eq 'Administrator' || $s->param('groupIDs') =~ / $_->{ID},/; + my $groupID = $_->{ID}; + my $groupName = $_->{name}; + next if $groupName eq 'Administrator' || $s->param('groupIDs') =~ / $_->{ID},/; + + my $rights = &getRights($groupID); + next unless $rights->{showRoots} || $rights->{addRoot} || $rights->{editRoot}; + + $groups->{$groupID} = $groupName; } $t->{V}->{rootGroupRightsHeader} = _gettext("Access Rights"); @@ -802,6 +849,41 @@ }, ]; + push @{$t->{V}->{rootGroupRightsMenu}}, ( + { + elements => [ + { + target => 'single', + type => 'checkbox', + name => 'checkAll_read', + value => 1, + descr => '', + checked => 0, + align => 'center', + width => '3em', + onChange => "javascript:setAllACLs(\"checkAll_read\", \"r\")", + }, + { + target => 'single', + type => 'checkbox', + name => 'checkAll_write', + value => 1, + descr => '', + checked => 0, + width => '5em', + align => 'center', + onChange => "javascript:setAllACLs(\"checkAll_write\", \"w\")", + }, + { + target => 'single', + type => 'label', + value => '[' . _gettext("All") . ']', + width => '8em', + } + ] + }, + ); + foreach (sort {$a<=>$b} keys %{$groups}) { push @{$t->{V}->{rootGroupRightsMenu}}, ( { @@ -812,7 +894,7 @@ name => 'accGroup_r_' . $_, value => 1, descr => '', - checked => (defined $q->param('accGroup_r_' . $_)) ? $q->param('accGroup_r_' . $_) : 0, + checked => &getParam(1, 0, 'accGroup_r_' . $_), align => 'center', width => '3em', onChange => "javascript:setACLs(\"$_\",\"r\")", @@ -823,7 +905,7 @@ name => 'accGroup_w_' . $_, value => 1, descr => '', - checked => (defined $q->param('accGroup_w_' . $_)) ? $q->param('accGroup_w_' . $_) : 0, + checked => &getParam(1, 0, 'accGroup_w_' . $_), width => '5em', align => 'center', onChange => "javascript:setACLs(\"$_\",\"w\")", @@ -831,7 +913,7 @@ { target => 'single', type => 'label', - value => $groups->{$_}, + value => "eHTML($groups->{$_}), width => '8em', } ] @@ -888,9 +970,9 @@ my $pluginOrders = {}; my $ipv6 = 0; my $maxSubnetSize = &getConfigValue('gui', 'maxsubnetsize'); - my $roots = &getRoots(); - map {my $h=$_;$h->{name} = "eHTML($h->{name}); $_ = $h;} @{$roots}; - + my $roots = &getRoots(1); + map {my $h = $_; $h->{name} = "eHTML($h->{name}); $_ = $h;} @{$roots}; + map {$_->{name} = "eHTML($_->{name})} @{$types}; my $defSubnetSizes = [{ID => "0", name => "min"}]; my $defSubnetSizesV6 = [{ID => "0", name => "min"}]; map {$_->{ID} = $_->{id}} @{$stats}; @@ -906,35 +988,42 @@ # get Variables.... - my $editNet = (defined $q->param('editNet')) ? $q->param('editNet') : 0; - my $fillNet = (defined $q->param('fillNet')) ? $q->param('fillNet') : 0; - my $checktAddNet = (defined $q->param('checktAddNet')) ? $q->param('checktAddNet') : 0; - my $chTmplID = (defined $q->param('chTmplID')) ? $q->param('chTmplID') : 0; - my $submitAddNet = (defined $q->param('submitAddNet')) ? $q->param('submitAddNet') : 0; - my $forceState = (defined $q->param('forceState')) ? $q->param('forceState') : 0; + my $editNet = &getParam(1, 0, 'editNet'); + my $fillNet = &getParam(1, 0, 'fillNet'); + my $checktAddNet = &getParam(1, 0, 'checktAddNet'); + my $chTmplID = &getParam(1, 0, 'chTmplID'); + my $submitAddNet = &getParam(1, 0, 'submitAddNet'); + my $forceState = &getParam(1, 0, 'forceState'); + my $aclsFromParent = &getParam(1, 0, 'aclsFromParent'); # Init variables... my $netaddress = ''; my $netmask = ''; my $cidr = ''; my $descr = ''; + my $tags = ''; my $state = 0; my $defSubnetSize = 'min'; my $rootID = 0; my $tmplID = 0; + my $availTagsT = &getAvailTags(); + my $availTags = []; + foreach (sort @{$availTagsT}) { + push @{$availTags}, {ID => $_, name => $_}; + } # If Fillnet if ($fillNet) { - if (defined $q->param('rootID') && defined $q->param('networkDec')) { - $rootID = $q->param('rootID'); - my $networkDec = $q->param('networkDec'); + if (defined &getParam(1, undef, 'rootID') && defined &getParam(1, undef, 'networkDec')) { + $rootID = &getParam(1, 0, 'rootID'); + my $networkDec = &getParam(1, 0, 'networkDec'); $ipv6 = &rootID2ipv6($rootID); $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); (my $ipaddress, $cidr) = split/\//, $network; $netmask = ($ipv6) ? 0 : &getNetmaskFromCidr($cidr); $netaddress = ($ipv6) ? $ipaddress : &dec2ip(&getNetaddress($ipaddress, $netmask)); - $t->{V}->{addNetHeader} = sprintf(_gettext("Add Network %s"), $network); + $t->{V}->{addNetHeader} = sprintf(_gettext("Add network %s"), $network); my $newRoots = []; foreach (@$roots) { @@ -949,7 +1038,7 @@ # If editNet get Values from DB if ($editNet) { $t->{V}->{editNet} = 1; - my $netID = $q->param('netID'); + my $netID = &getParam(1, 0, 'netID'); if (defined $netID) { my $maintenanceInfos = &getMaintInfosFromNet($netID); @@ -960,11 +1049,13 @@ $descr = $maintenanceInfos->{description} || ''; $state = $maintenanceInfos->{state} || 0; $defSubnetSize = $maintenanceInfos->{defSubnetSize} || 0; + $tags = $maintenanceInfos->{tags} || []; + $tags = join(' ', @{$tags}); my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); (my $ipaddress, $cidr) = split/\//, $network; $netmask = ($ipv6) ? 0 : &getNetmaskFromCidr($cidr); $netaddress = ($ipv6) ? $ipaddress : &dec2ip(&getNetaddress($ipaddress, $netmask)); - $t->{V}->{addNetHeader} = sprintf(_gettext("Edit Network %s"), $network); + $t->{V}->{addNetHeader} = sprintf(_gettext("Edit network %s"), $network); my $newRoots = []; foreach (@$roots) { @@ -1005,15 +1096,17 @@ # If checktAddNet or chTmplID or return because of bad values => get values from before if ($checktAddNet || $chTmplID || $submitAddNet) { - $netaddress = $q->param('netaddress'); - $netmask = $q->param('netmask'); - $cidr = $q->param('cidr'); - $descr = $q->param('descr'); - $state = $q->param('state'); - $defSubnetSize = $q->param('defSubnetSize'); - $rootID = $q->param('rootID'); - $tmplID = $q->param('tmplID'); + $netaddress = &getParam(1, undef, 'netaddress', 1); + $netmask = &getParam(1, undef, 'netmask', 1); + $cidr = &getParam(1, undef, 'cidr', 1); + $descr = &getParam(1, undef, 'descr', 1); + $state = &getParam(1, undef, 'state', 1); + $defSubnetSize = &getParam(1, undef, 'defSubnetSize', 1); + $rootID = &getParam(1, undef, 'rootID', 1); + $tmplID = &getParam(1, undef, 'tmplID', 1); $t->{V}->{addNetHeader} = sprintf(_gettext((($editNet) ? 'Edit' : 'Add') . " Network %s"), $netaddress . '/' . $cidr); + } else { + $aclsFromParent = 1 unless $editNet; } # Generate default Subnet Cidr Menu @@ -1031,7 +1124,7 @@ $descr = "eHTML($descr); $t->{V}->{rootID2Ver} = $roots; - $t->{V}->{addNetHeader} ||= _gettext("Add Network"); + $t->{V}->{addNetHeader} ||= _gettext("Add network"); $t->{V}->{addNetFormName} = 'addNet'; $t->{V}->{addNetMenu} = [ { @@ -1134,13 +1227,13 @@ align => 'center', buttons => [ { - name => 'showDescrHelper', + name => 'showDescrHelperBtn', type => '', onClick => "showDescrHelper()", value => '1', img => 'info_small.png', picOnly => 1, - title => _gettext("Available Variables from the Plugins"), + title => _gettext("Available variables"), }, ], }, @@ -1151,6 +1244,38 @@ { target => 'key', type => 'label', + value => _gettext("Tags"), + }, + { + target => 'single', + type => 'textfield', + name => 'tags', + size => 20, + maxlength => 255, + value => $tags, + colspan => 1, + }, + { + target => 'single', + type => 'popupMenu', + name => 'availTags', + size => 1, + onClick => 'javascript:addAvailTag();', + values => $availTags, + }, + { + target => 'single', + type => 'label', + align => 'center', + value => _gettext("seperate
by space"), + }, + ] + }, + { + elements => [ + { + target => 'key', + type => 'label', value => _gettext("Status"), }, { @@ -1176,7 +1301,7 @@ align => 'center', buttons => [ { - name => 'showStatusHelper', + name => 'showStatusHelperBtn', type => '', onClick => "showStatusHelper()", value => '1', @@ -1220,14 +1345,14 @@ size => 1, values => $types, selected => [$tmplID], - onChange => 'javascript:document.getElementById("chTmplID").value=1;submit()', + onChange => 'javascript:document.getElementById("chTmplID").value=1;enableACLs();submit()', colspan => 3, } ] }, ]; - $t->{V}->{helpDescrHeader} = _gettext("Available Variables from the Plugins"); + $t->{V}->{helpDescrHeader} = _gettext("Available variables"); $t->{V}->{helpDescrMenu} = [ { elements => [ @@ -1269,16 +1394,86 @@ ]; if ($tmplID) { + my $tmplName = &tmplID2Name($tmplID); + push @{$t->{V}->{addNetMenu}}, ( { value => { type => 'hline', - colspan => 2, + colspan => 4, } }, ); (my $menu, undef) = &getTemplateEntries($tmplID, 1, 0, 0, 0, 1); push @{$t->{V}->{addNetMenu}}, @{$menu}; + + my $elements = []; + foreach (@{$menu}) { + my $row = $_; + next unless exists $row->{elements}; + + foreach (@{$row->{elements}}) { + my $element = $_; + if ($element->{target} eq 'key') { + my $name = $element->{value}; + + push @{$elements}, ( + {elements => [ + { + target => 'single', + type => 'label', + value => '', + width => '0.1em', + }, + { + target => 'single', + type => 'label', + value => '', + }, + { + target => 'single', + type => 'label', + value => $name, + width => '3em', + align => 'center', + }, + { + target => 'single', + type => 'buttons', + align => 'center', + width => '1em', + buttons => [ + { + name => 'insertPluginVar', + type => '', + onClick => "insertPluginVar('descr','\%\*$tmplName\%$name\*\%')", + value => '1', + img => 'insert_small.png', + picOnly => 1, + title => sprintf(_gettext("Insert '%s' from Type '%s'"), $name, $tmplName), + }, + ], + }, + ]} + ); + } + } + } + + push @{$t->{V}->{helpDescrMenu}}, ( + { + elements => [ + { + target => 'single', + type => 'label', + value => sprintf(_gettext("Type '%s'"), $tmplName), + bold => 1, + colspan => 4, + }, + ], + }, + @{$elements} + ) if $#{$menu} != -1; } my $groups = {}; @@ -1287,34 +1482,39 @@ my $rootID = 0; my $networkDec = 0; my $netID = 0; - if ($fillNet && defined $q->param('rootID') && defined $q->param('networkDec')) { + if ($fillNet && defined &getParam(1, undef, 'rootID') && defined &getParam(1, undef, 'networkDec')) { $knowNet = 1; - $rootID = $q->param('rootID'); - $networkDec = $q->param('networkDec'); + $rootID = &getParam(1, 0, 'rootID'); + $networkDec = &getParam(1, 0, 'networkDec'); $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $parent = &getNetworkParentFromDB($rootID, $networkDec, $ipv6); $netID = $parent->{ID}; } - elsif ($editNet && defined $q->param('netID')) { + elsif ($editNet && defined &getParam(1, undef, 'netID')) { $knowNet = 1; - $netID = $q->param('netID'); + $netID = &getParam(1, 0, 'netID'); } foreach (@{&getGroups()}) { my $groupID = $_->{ID}; next if $_->{name} eq 'Administrator' || $s->param('groupIDs') =~ / $_->{ID},/; + + my $rights = &getRights($groupID); + next unless $rights->{showNets} || $rights->{addNet} || $rights->{editNet}; $groups->{$_->{ID}}->{NAME} = $_->{name}; # If checktAddNet or chTmplID or return because of bad values => get values from before if ($checktAddNet || $chTmplID || $submitAddNet) { - $groups->{$_->{ID}}->{R} = (defined $q->param('accGroup_r_' . $groupID)) ? $q->param('accGroup_r_' . $groupID) : 0; - $groups->{$_->{ID}}->{W} = (defined $q->param('accGroup_w_' . $groupID)) ? $q->param('accGroup_r_' . $groupID) : 0; + $groups->{$_->{ID}}->{R} = &getParam(1, 0, 'accGroup_r_' . $groupID); + $groups->{$_->{ID}}->{W} = &getParam(1, 0, 'accGroup_w_' . $groupID); + $groups->{$_->{ID}}->{I} = &getParam(1, 0, 'accGroup_i_' . $groupID); } else { # If you know the network (fillnet, editNet) get ACLs if ($knowNet) { - my $acl = &checkNetACL($netID, 'ACL', $groupID); - $groups->{$_->{ID}}->{R} = ($acl == 1 || $acl == 3) ? 1 : 0; - $groups->{$_->{ID}}->{W} = ($acl == 2 || $acl == 3) ? 1 : 0; + my $acl = &checkNetACL($netID, 'ACL', $groupID, 1); + $groups->{$_->{ID}}->{R} = ($acl % 4 == 1 || $acl % 4 == 3) ? 1 : 0; + $groups->{$_->{ID}}->{W} = ($acl % 4 == 2 || $acl % 4 == 3) ? 1 : 0; + $groups->{$_->{ID}}->{I} = ($acl > 3) ? 1 : 0; # inherited? } } } @@ -1353,6 +1553,43 @@ } }, ]; + + push @{$t->{V}->{netGroupRightsMenu}}, ( + { + elements => [ + { + target => 'single', + type => 'checkbox', + name => 'checkAll_read', + value => 1, + descr => '', + checked => 0, + align => 'center', + disabled => ($aclsFromParent) ? 1 : 0, + width => '3em', + onChange => "javascript:setAllACLs(\"checkAll_read\", \"r\")", + }, + { + target => 'single', + type => 'checkbox', + name => 'checkAll_write', + value => 1, + descr => '', + checked => 0, + width => '5em', + align => 'center', + disabled => ($aclsFromParent) ? 1 : 0, + onChange => "javascript:setAllACLs(\"checkAll_write\", \"w\")", + }, + { + target => 'single', + type => 'label', + value => '[' . _gettext("All") . ']', + width => '8em', + } + ] + }, + ); foreach (sort {$a<=>$b} keys %{$groups}) { push @{$t->{V}->{netGroupRightsMenu}}, ( @@ -1366,6 +1603,7 @@ descr => '', checked => $groups->{$_}->{R}, align => 'center', + disabled => ($aclsFromParent) ? 1 : 0, width => '3em', onChange => "javascript:setACLs(\"$_\",\"r\")", }, @@ -1378,12 +1616,14 @@ checked => $groups->{$_}->{W}, width => '5em', align => 'center', + disabled => ($aclsFromParent) ? 1 : 0, onChange => "javascript:setACLs(\"$_\",\"w\")", }, { target => 'single', type => 'label', - value => $groups->{$_}->{NAME}, + value => "eHTML($groups->{$_}->{NAME}), + bgColor => ((($groups->{$_}->{I} || 0) || !$editNet) ? 0 : 'FFAAAA'), width => '8em', } ] @@ -1394,9 +1634,51 @@ name => 'accGroup', value => $_ }, + { + name => 'accGroup_i_' . $_, + value => $groups->{$_}->{I} + }, ); }; + push @{$t->{V}->{netGroupRightsMenu}}, ( + { + value => { + type => 'hline', + colspan => 3, + } + }, + { + elements => [ + { + target => 'single', + type => 'label', + align => 'right', + colspan => 3, + value => '(' . _gettext("marked: NOT inherited") . ')', + }, + ], + }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Inherit from supernet"), + }, + { + target => 'value', + type => 'checkbox', + name => 'aclsFromParent', + value => 1, + descr => '', + checked => ($aclsFromParent) ? 1 : 0, + onChange => "javascript:changeACLFromParent()", + }, + ], + }, + ); + $t->{V}->{pluginInfoBoxHeader} = _gettext("Plugin Info"); push @{$t->{V}->{pluginInfoBoxMenu}}, ( { @@ -1602,9 +1884,9 @@ @{$elements} ) if $#{$api} != -1; - my $pluginDescr = "eHTML($availPlugins->{$ID}->{DESCR}); + my $pluginDescr = "eHTML($availPlugins->{$ID}->{DESCR} || ''); $pluginDescr =~ s/'/\\'/g; - my $pluginName = "eHTML($availPlugins->{$ID}->{NAME}); + my $pluginName = "eHTML($availPlugins->{$ID}->{NAME} || ''); $pluginName =~ s/'/\\'/g; push @{$t->{V}->{netPluginsMenu}}, ( { @@ -1859,18 +2141,18 @@ push @{$t->{V}->{addNetHiddens}}, ( { name => 'networkDec', - value => $q->param('networkDec') + value => &getParam(1, undef, 'networkDec', 1) }, - ) if defined $q->param('networkDec'); + ) if defined &getParam(1, undef, 'networkDec'); } if ($editNet) { push @{$t->{V}->{addNetHiddens}}, ( { name => 'netID', - value => $q->param('netID') + value => &getParam(1, undef, 'netID', 1) } - ) if defined $q->param('netID'); + ) if defined &getParam(1, undef, 'netID'); } } @@ -1880,7 +2162,7 @@ my $q = $HaCi::HaCi::q; &removeStatus(); - $t->{V}->{importASNRoutesHeader} = _gettext("Import ASN Routes"); + $t->{V}->{importASNRoutesHeader} = _gettext("Import ASN routes"); $t->{V}->{importASNRoutesFormName} = 'importASNRoutes'; $t->{V}->{importASNRoutesMenu} = [ { @@ -1888,15 +2170,15 @@ { target => 'key', type => 'label', - value => _gettext("AS Number"), + value => _gettext("AS Number") . " (asplain)", }, { target => 'value', type => 'textfield', name => 'asn', - size => 5, - maxlength => 5, - value => ((defined $q->param('asn')) ? $q->param('asn') : ''), + size => 6, + maxlength => 10, + value => &getParam(1, '', 'asn', 1), focus => 1, onKeyDown => "submitOnEnter(event, 'submitImportASNRoutes')", } @@ -2023,7 +2305,7 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; my $t = $HaCi::GUI::init::t; - my $netID = $q->param('netID'); + my $netID = &getParam(1, undef, 'netID'); return unless defined $netID; my ($rootID, $networkDec, $ipv6) = &netID2Stuff($netID); @@ -2035,15 +2317,37 @@ my $descr = $maintenanceInfos->{description} || ''; my $state = $maintenanceInfos->{state} || 0; my $defSubnetSize = $maintenanceInfos->{defSubnetSize} || 0; + my $tags = $maintenanceInfos->{tags} || []; + $tags = join(' ', @{$tags}); my ($ipaddress, $cidr) = split(/\//, $network); my $netmask = ($ipv6) ? 0 : &getNetmaskFromCidr($cidr); my $netaddress = ($ipv6) ? $ipaddress : &dec2ip(&getNetaddress($ipaddress, $netmask)); my $broadcastDec = ($ipv6) ? &getV6BroadcastIP($networkDec) : &getBroadcastFromNet($networkDec); my $broadcast = ($ipv6) ? &ipv6Dec2ip($broadcastDec) : &dec2ip($broadcastDec); my $nrOfAddresses = Math::BigInt->new(2); - my $nrOfFreeSubnets = &getFreeSubnets($netID, 1); + my $nrOfFreeSubnets = 0; + my $nrOfChilds = &getNrOfChilds($networkDec, $rootID, $ipv6); $state = &networkStateID2Name($state); + if ($defSubnetSize) { + my $freeSubnets = &getFreeSubnets($netID, 1, $defSubnetSize); + $nrOfFreeSubnets = $freeSubnets; + } else { + # We don't wan't to count all free subnets with minimal cidr size + if (&getConfigValue('gui', 'shownroffreesubnetswithmincidr')) { + my $cntBox; + foreach (&getFreeSubnets($netID)) { + (undef, my $cidr) = split(/\//); + $cntBox->{$cidr}++; + } + $nrOfFreeSubnets = '' if scalar keys %{$cntBox} > 0; + foreach (sort keys %{$cntBox}) { + $nrOfFreeSubnets .= ', ' if $nrOfFreeSubnets; + $nrOfFreeSubnets .= $cntBox->{$_} . ' /' . $_; + } + } + } + $nrOfAddresses->bpow((($ipv6) ? 128 : 32) - (($ipv6) ? (($cidr < 64) ? 64 : $cidr) : $cidr)); my ($routPref, $subnet, $hostID) = (($ipv6) ? ($ipaddress =~ /(.{14}):(.{4}):(.*)/) : ()); $descr = &subDescription($descr, $netID) if $descr =~ /\%{2}/; @@ -2069,7 +2373,8 @@ } } - $t->{V}->{netBasicInfoHeader} = sprintf(_gettext("Details of Network %s"), $network); + $network =~ s/\/\d+// if &getConfigValue('gui', 'removecidrfromips') && $cidr == (($ipv6) ? 128 : 32); + $t->{V}->{netBasicInfoHeader} = sprintf(_gettext("Details of " . (($cidr == (($ipv6) ? 128 : 32)) ? 'IP' : 'Network') . " %s"), $network); $t->{V}->{netBasicInfo} = [ { elements => [ @@ -2128,7 +2433,9 @@ } ] }, - { + ($ipv6) ? + () : + ({ elements => [ { target => 'key', @@ -2141,7 +2448,7 @@ value => $broadcast } ] - }, + }), ($ipv6) ? ( { elements => [ @@ -2199,6 +2506,7 @@ } ] }, + ($defSubnetSize || &getConfigValue('gui', 'shownroffreesubnetswithmincidr')) ? ( { elements => [ { @@ -2212,6 +2520,20 @@ value => $nrOfFreeSubnets, } ] + }) : (), + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("# of assigned subnets"), + }, + { + target => 'value', + type => 'label', + value => $nrOfChilds, + } + ] }, { value => { @@ -2238,6 +2560,20 @@ { target => 'key', type => 'label', + value => _gettext("Tags"), + }, + { + target => 'value', + type => 'label', + value => "eHTML($tags), + } + ] + }, + { + elements => [ + { + target => 'key', + type => 'label', value => _gettext("Status"), }, { @@ -2263,7 +2599,7 @@ { target => 'value', type => 'label', - value => $maintenanceInfos->{createFrom}, + value => "eHTML($maintenanceInfos->{createFrom}), } ] }, @@ -2281,6 +2617,7 @@ } ] }, + ($maintenanceInfos->{modifyDate} =~ /^1970/) ? () : ( { elements => [ { @@ -2291,7 +2628,7 @@ { target => 'value', type => 'label', - value => $maintenanceInfos->{modifyFrom}, + value => "eHTML($maintenanceInfos->{modifyFrom}), } ] }, @@ -2308,7 +2645,7 @@ value => $maintenanceInfos->{modifyDate}, } ] - }, + }), ]; $t->{V}->{netFunctionsHeader} = _gettext("Menu"); @@ -2360,6 +2697,19 @@ type => 'buttons', buttons => [ { + name => 'exportSubnets', + type => 'submit', + value => _gettext("Export Subnets"), + disabled => ($nrOfChilds > 0) && ((($ipv6 && $cidr != 128) || (!$ipv6 && $cidr != 32)) && (&checkRight('showNetDet'))) ? 0 : 1, + img => 'exportSubnets_small.png', + }, + ], + }, + { + target => 'single', + type => 'buttons', + buttons => [ + { name => 'delNet', type => 'submit', value => _gettext("Delete"), @@ -2395,14 +2745,14 @@ } ]; - $t->{V}->{netInfoHeader} = sprintf(_gettext("Type Infos of Network %s"), $network); + $t->{V}->{netInfoHeader} = sprintf(_gettext("Type info of " . (($cidr == (($ipv6) ? 128 : 32)) ? 'IP' : 'Network') . " %s"), $network); $t->{V}->{netInfo} = &getTemplateData($netID, $tmplID); } sub mkDelNet { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - my $netID = $q->param('netID'); + my $netID = &getParam(1, undef, 'netID', 1); return unless defined $netID; my ($rootID, $networkDec, $ipv6) = &netID2Stuff($netID); @@ -2432,6 +2782,23 @@ ], }, { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Lock network for X seconds"), + }, + { + target => 'value', + type => 'textfield', + name => 'networkLock', + value => 0, + size => 5, + maxlength => 10, + }, + ], + }, + { value => { type => 'hline', colspan => 2, @@ -2479,7 +2846,7 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; my $t = $HaCi::GUI::init::t; - my $rootID = $q->param('rootID'); + my $rootID = &getParam(1, undef, 'rootID'); my $rootName = &rootID2Name($rootID); my $maintenanceInfos = &getMaintInfosFromRoot($rootID); my $nrOfNetworks = &getNrOfChilds(0, $rootID); @@ -2548,7 +2915,7 @@ { target => 'value', type => 'label', - value => $maintenanceInfos->{createFrom}, + value => "eHTML($maintenanceInfos->{createFrom}), } ] }, @@ -2566,6 +2933,7 @@ } ] }, + ($maintenanceInfos->{modifyFrom}) ? ( { elements => [ { @@ -2576,7 +2944,7 @@ { target => 'value', type => 'label', - value => $maintenanceInfos->{modifyFrom}, + value => "eHTML($maintenanceInfos->{modifyFrom}), } ] }, @@ -2593,7 +2961,7 @@ value => $maintenanceInfos->{modifyDate}, } ] - }, + }) : (), ]; $t->{V}->{rootFunctionsHeader} = _gettext("Menu"); @@ -2632,6 +3000,19 @@ { target => 'single', type => 'buttons', + buttons => [ + { + name => 'exportSubnets', + type => 'submit', + value => _gettext("Export Subnets"), + disabled => ($nrOfNetworks > 0) && (&checkRight('showNetDet')) ? 0 : 1, + img => 'exportSubnets_small.png', + }, + ], + }, + { + target => 'single', + type => 'buttons', align => 'center', buttons => [ { @@ -2658,7 +3039,7 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $rootID = $q->param('rootID'); + my $rootID = &getParam(1, undef, 'rootID'); my $rootName = "eHTML(&rootID2Name($rootID)); my $nrOfChilds = &getNrOfChilds(0, $rootID); @@ -2719,27 +3100,47 @@ sub mkSearch { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $t = $HaCi::GUI::init::t; - my $q = $HaCi::HaCi::q; - my $searchValue = ((defined $q->param('search')) ? $q->param('search') : ''); - my $stats = $conf->{static}->{misc}->{networkstates}; - my $state = (defined $q->param('state')) ? $q->param('state') : -1; - my $tmplID = (defined $q->param('tmplID')) ? $q->param('tmplID') : -1; - my $types = &getNetworkTypes(1); - $searchValue =~ s/"/"/g; + my $t = $HaCi::GUI::init::t; + my $q = $HaCi::HaCi::q; + my $func = &getParam(1, '', 'func'); + my $bSearchForFree = ($func eq 'getFreeSubnetsFromSearch') ? 1 : 0; + my $searchValue = &getParam(1, '', 'search'); + my $tags = &getParam(0, [], 'tags'); + my $tagOp = &getParam(1, 0, 'tagOp'); + my $stats = $conf->{static}->{misc}->{networkstates}; + my $state = &getParam(1, -1, 'state'); + my $tmplID = &getParam(1, -1, 'tmplID'); + my $types = &getNetworkTypes(1); + map {$_->{name} = "eHTML($_->{name})} @{$types}; + my $dbType = &getConfigValue('db', 'dbtype'); + $searchValue =~ s/"/"/g; unshift @{$types}, {ID => -1, name => '[ALL]'}; + my $availTagsT = &getAvailTags(); + my $availTags = []; + foreach (sort @{$availTagsT}) { + push @{$availTags}, {ID => $_, name => $_}; + } + + my $roots = &getRoots(1); + unshift @{$roots}, {ID => -1, name => '[' . _gettext('ALL') . ']'}; + map {my $h=$_;$h->{name} = "eHTML($h->{name}); $_ = $h;} @{$roots}; + map {$_->{ID} = $_->{id}} @{$stats}; unshift @{$stats}, {ID => -1, name => '[ALL]'}; - $t->{V}->{searchHeader} = _gettext("Search"); - $t->{V}->{searchResultHeader} = _gettext("Result"); - $t->{V}->{gettext_network} = _gettext("Network"); - $t->{V}->{gettext_description} = _gettext("Description"); - $t->{V}->{gettext_state} = _gettext("Status"); - $t->{V}->{searchFormName} = 'search'; - $t->{V}->{buttonFocus} = 'searchButton'; - $t->{V}->{searchMenu} = [ + $t->{V}->{searchHeader} = ($func eq 'getFreeSubnetsFromSearch') ? _gettext("Search and get free network") : _gettext("Search"); + $t->{V}->{searchResultHeader} = _gettext("Result"); + $t->{V}->{gettext_network} = _gettext("Network"); + $t->{V}->{gettext_description} = _gettext("Description"); + $t->{V}->{gettext_state} = _gettext("Status"); + $t->{V}->{gettext_tags} = _gettext("Tags"); + $t->{V}->{gettext_nrOfFreeSubnets} = _gettext("# of free subnets"); + $t->{V}->{searchFormName} = 'search'; + $t->{V}->{buttonFocus} = 'searchButton'; + $t->{V}->{bShowNrOfFreeSubs} = ((defined &getParam(1, undef, 'shNrOfFreeSubs')) ? 1 : 0); + $t->{V}->{bSearchForFree} = $bSearchForFree; + $t->{V}->{searchMenu} = [ { elements => [ { @@ -2751,7 +3152,7 @@ value => $searchValue, focus => 1, onKeyDown => "submitOnEnter(event, 'searchButton')", - colspan => 2, + colspan => 3, align => 'center', }, ], @@ -2768,6 +3169,7 @@ type => 'label', value => '*', bold => 1, + colspan => 2, }, ], }, @@ -2784,11 +3186,12 @@ name => 'exact', value => 1, descr => '', - checked => ((defined $q->param('exact')) ? 1 : 0), + checked => ((defined &getParam(1, undef, 'exact')) ? 1 : 0), + colspan => 2, }, ], }, - { + ((lc($dbType) eq 'mysql') ? { elements => [ { target => 'key', @@ -2801,10 +3204,64 @@ name => 'fuzzy', value => 1, descr => '', - checked => ((defined $q->param('fuzzy')) ? 1 : 0), + checked => ((defined &getParam(1, undef, 'fuzzy')) ? 1 : 0), + colspan => 2, } ] - }, + } : ()), + ($bSearchForFree) ? ({ + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("CIDR"), + }, + { + target => 'single', + type => 'textfield', + name => 'size', + value => &getParam(1, 30, 'size'), + size => 3, + maxlength => 3, + colspan => 2, + }, + ], + }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Amount"), + }, + { + target => 'single', + type => 'textfield', + name => 'amount', + value => &getParam(1, 3, 'amount'), + size => 3, + maxlength => 4, + colspan => 2, + }, + ], + }) : ({ + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Show number of free subnets"), + }, + { + target => 'value', + type => 'checkbox', + name => 'shNrOfFreeSubs', + value => 1, + descr => '', + checked => ((defined &getParam(1, undef, 'shNrOfFreeSubs')) ? 1 : 0), + colspan => 2, + }, + ], + }), { elements => [ { @@ -2819,6 +3276,7 @@ size => 1, values => $stats, selected => [$state], + colspan => 2, } ] }, @@ -2841,6 +3299,52 @@ } ] }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Root"), + }, + { + target => 'value', + type => 'popupMenu', + name => 'rootID', + size => 1, + values => $roots, + selected => [], + colspan => 2, + }, + ] + }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Tags"), + }, + { + target => 'single', + type => 'popupMenu', + name => 'tags', + size => 3, + values => $availTags, + selected => $tags, + multiple => 1, + }, + { + target => 'single', + type => 'radio', + name => 'tagOp', + values => [{value=>'AND',label=>_gettext('AND')}, {value=>'OR',label=>_gettext('OR')}], + cr => 1, + selected => ($tagOp) ? $tagOp : 'AND', + colspan => 1, + align => 'left', + } + ] + } ]; if ($tmplID) { @@ -2848,7 +3352,7 @@ { value => { type => 'hline', - colspan => 2, + colspan => 3, } }, ); @@ -2860,7 +3364,7 @@ { value => { type => 'hline', - colspan => 2, + colspan => 3, } }, { @@ -2869,12 +3373,12 @@ target => 'single', type => 'buttons', align => 'center', - colspan => 2, + colspan => 3, buttons => [ { name => 'searchButton', type => 'submit', - value => _gettext("Search"), + value => _gettext(($bSearchForFree) ? 'Search for free networks' : "Search"), img => 'search_small.png', }, ] @@ -2886,7 +3390,7 @@ push @{$t->{V}->{searchHiddens}}, ( { name => 'func', - value => 'search' + value => $func }, { name => 'chTmplID', @@ -2901,6 +3405,10 @@ my $q = $HaCi::HaCi::q; my $netTypes = &getNetworkTypes(); + foreach (@{$netTypes}) { + $_->{name} = "eHTML($_->{name}); + } + $t->{V}->{newTemplateHeader} = _gettext("New Template"); $t->{V}->{newTemplateFormName} = 'newTemplate'; $t->{V}->{newTemplateMenu} = [ @@ -2917,6 +3425,7 @@ name => 'tmplName', size => 20, maxlength => 255, + onKeyDown => "submitOnEnter(event, 'newTmpl')", }, { target => 'single', @@ -3001,8 +3510,8 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $tmplID = (defined $q->param('tmplID')) ? $q->param('tmplID') : undef; - my $tmplName = (defined $q->param('tmplName') && $q->param('tmplName')) ? $q->param('tmplName') : &tmplID2Name($tmplID); + my $tmplID = &getParam(1, undef, 'tmplID'); + my $tmplName = (defined &getParam(1, undef, 'tmplName') && &getParam(1, '', 'tmplName') ne '') ? &getParam(1, '', 'tmplName') : &tmplID2Name($tmplID); my $tmpl = &getTemplate($tmplID); my $types = [ {ID => 0, name => _gettext('HLine')}, @@ -3013,7 +3522,7 @@ ]; $t->{V}->{maxPositions} = $tmpl->{MaxPosition}; - $t->{V}->{templateHeader} = ((defined $q->param('newTmpl')) ? (_gettext("New")) : '') . sprintf(_gettext("Template '%s' for '%s'"), $tmplName, _gettext($q->param('tmplType') || '')); + $t->{V}->{templateHeader} = ((defined &getParam(1, undef, 'newTmpl')) ? (_gettext("New")) : '') . sprintf(_gettext("Template '%s' for '%s'"), "eHTML($tmplName), _gettext(&getParam(1, '', 'tmplType') || '')); $t->{V}->{templateMenu} = [ { elements => [ @@ -3025,7 +3534,7 @@ { target => 'value', type => 'label', - value => $tmpl->{createFrom}, + value => "eHTML($tmpl->{createFrom}), } ] }, @@ -3053,7 +3562,7 @@ { target => 'value', type => 'label', - value => $tmpl->{modifyFrom}, + value => "eHTML($tmpl->{modifyFrom}), } ] }, @@ -3073,10 +3582,56 @@ }, ]; + $t->{V}->{editTemplateNameFormName} = 'editTmpl'; + $t->{V}->{editTemplateNameHeader} = _gettext("Template name"); + $t->{V}->{editTemplateNameMenu} = [ + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Name"), + }, + { + target => 'value', + type => 'textfield', + name => 'tmplName', + size => 20, + maxlength => 255, + value => "eHTML($tmplName) + }, + ] + }, + { + value => { + type => 'hline', + colspan => 2, + } + }, + { + elements => [ + { + target => 'single', + type => 'buttons', + align => 'center', + colspan => 2, + buttons => [ + { + name => 'editTemplName', + type => 'submit', + value => _gettext("Change"), + img => 'change_small.png', + }, + ] + } + ] + } + ]; + $t->{V}->{editTemplateFormName} = 'editTmpl'; $t->{V}->{gettext_Templates} = _gettext("Templates"); $t->{V}->{editTemplateHeader} = _gettext("Structure"); - $t->{V}->{editTemplateMenu} = [ + $t->{V}->{editTemplateMenu} = [ { elements => [ { @@ -3157,12 +3712,8 @@ $t->{V}->{editTemplateHiddens} = [ { - name => 'tmplName', - value => $q->param('tmplName') || '', - }, - { name => 'tmplType', - value => $q->param('tmplType') || '', + value => &getParam(1, '', 'tmplType') || '', }, { name => 'tmplEntryID', @@ -3173,7 +3724,7 @@ push @{$t->{V}->{editTemplateHiddens}}, ( { name => 'tmplID', - value => $q->param('tmplID') + value => &getParam(1, undef, 'tmplID') }, ) if defined $tmplID; @@ -3223,7 +3774,7 @@ type => 'textfield', name => 'TmplEntryParamEntries', size => 20, - maxlength => 255, + maxlength => 1024, }, ], }, @@ -3262,14 +3813,14 @@ ]; $t->{V}->{templatePreviewHeader} = _gettext("Preview"); - ($t->{V}->{templatePreviewMenu}, $t->{V}->{templatePreviewHiddens}) = &getTemplateEntries($q->param('tmplID'), 0, 1, 0, 0, 1); + ($t->{V}->{templatePreviewMenu}, $t->{V}->{templatePreviewHiddens}) = &getTemplateEntries(&getParam(1, undef, 'tmplID'), 0, 1, 0, 0, 1); } sub mkDelTmpl { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $tmplID = $q->param('tmplID'); + my $tmplID = &getParam(1, undef, 'tmplID'); my $tmplName = &tmplID2Name($tmplID); $t->{V}->{delTmplHeader} = sprintf(_gettext("Do you really want to delete the Template %s?"), $tmplName); @@ -3315,6 +3866,9 @@ my $q = $HaCi::HaCi::q; my $groups = &getGroups(); + foreach (@{$groups}) { + $_->{name} = "eHTML($_->{name}); + } $t->{V}->{newGroupHeader} = _gettext("New Group"); $t->{V}->{newGroupFormName} = 'showGroup'; $t->{V}->{newGroupMenu} = [ @@ -3331,6 +3885,7 @@ name => 'groupName', size => 20, maxlength => 255, + onKeyDown => "submitOnEnter(event, 'newGroup')", }, { target => 'single', @@ -3403,12 +3958,12 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $groupID = (defined $q->param('groupID')) ? $q->param('groupID') : undef; - my $groupName = (defined $q->param('groupName') && $q->param('groupName')) ? $q->param('groupName') : &groupID2Name($groupID); + my $groupID = &getParam(1, undef, 'groupID'); + my $groupName = (defined &getParam(1, undef, 'groupName') && &getParam(1, '', 'groupName') ne '') ? &getParam(1, '', 'groupName') : &groupID2Name($groupID); my $group = &getGroup($groupID); my $bAdmin = 1 if $groupName eq 'Administrator'; - if (defined $q->param('editGroup')) { + if (&getParam(1, 0, 'editGroup')) { if (defined $groupID) { my $groupTable = $conf->{var}->{TABLES}->{group}; unless (defined $groupTable) { @@ -3417,21 +3972,28 @@ } my $group = ($groupTable->search(['*'], {ID => $groupID}))[0]; $q->delete('groupDescr'); $q->param('groupDescr', $group->{description}); - my $cnter = 0; - my $cryptStr = substr($group->{permissions}, 1, length($group->{permissions}) - 1); - my $permStr = &dec2bin(&lwd($cryptStr)); - foreach (split//, substr($permStr, 1, length($permStr) - 1)) { - if ($_ || $bAdmin) { - $q->delete('groupPerm_' . $cnter); $q->param('groupPerm_' . $cnter, 1); + + if ($bAdmin) { + foreach (keys %{$conf->{static}->{rights}}) { + $q->delete('groupPerm_' . $_); $q->param('groupPerm_' . $_, 1); + } + } else { + my $cnter = 0; + my $cryptStr = substr($group->{permissions}, 1, length($group->{permissions}) - 1); + my $permStr = &dec2bin(&lwd($cryptStr)); + foreach (split//, substr($permStr, 1, length($permStr) - 1)) { + if ($_) { + $q->delete('groupPerm_' . $cnter); $q->param('groupPerm_' . $cnter, 1); + } + $cnter++; } - $cnter++; } } } - my $groupDescr = ((defined $q->param('groupDescr')) ? $q->param('groupDescr') : ''); + my $groupDescr = &getParam(1, '', 'groupDescr'); $groupDescr =~ s/"/"/g; - $t->{V}->{editGroupHeader} = ((defined $q->param('newGroup')) ? (_gettext("New ")) : '') . sprintf(_gettext("Group '%s'"), $groupName); + $t->{V}->{editGroupHeader} = ((defined &getParam(1, undef, 'newGroup')) ? (_gettext("New ")) : '') . sprintf(_gettext("Group '%s'"), "eHTML($groupName)); $t->{V}->{editGroupMenu} = [ { elements => [ @@ -3443,7 +4005,7 @@ { target => 'value', type => 'label', - value => $groupName + value => "eHTML($groupName) } ] }, @@ -3460,7 +4022,7 @@ name => 'groupDescr', size => 25, maxlength => 255, - value => $groupDescr, + value => "eHTML($groupDescr), }, ], }, @@ -3480,7 +4042,7 @@ { target => 'value', type => 'label', - value => $group->{createFrom}, + value => "eHTML($group->{createFrom}), } ] }, @@ -3508,7 +4070,7 @@ { target => 'value', type => 'label', - value => $group->{modifyFrom}, + value => "eHTML($group->{modifyFrom}), } ] }, @@ -3544,7 +4106,7 @@ name => 'groupPerm_' . $cnter, value => 1, descr => ' ' . _gettext($conf->{static}->{rights}->{$cnter}->{long}), - checked => (defined $q->param('groupPerm_' . $cnter)) ? $q->param('groupPerm_' . $cnter) : 0, + checked => &getParam(1, 0, 'groupPerm_' . $cnter), disabled => ($bAdmin) ? 1 : 0, } ] @@ -3586,7 +4148,7 @@ push @{$t->{V}->{editGroupHiddens}}, ( { name => 'groupID', - value => $q->param('groupID') + value => &getParam(1, undef, 'groupID') }, ) if defined $groupID; } @@ -3595,7 +4157,7 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $groupID = $q->param('groupID'); + my $groupID = &getParam(1, undef, 'groupID'); my $groupName = &groupID2Name($groupID); $t->{V}->{delGroupHeader} = sprintf(_gettext("Do you really want to delete the Group %s?"), $groupName); @@ -3641,7 +4203,7 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $userID = $q->param('userID'); + my $userID = &getParam(1, undef, 'userID'); my $userName = &userID2Name($userID); $t->{V}->{delUserHeader} = sprintf(_gettext("Do you really want to delete the User %s?"), $userName); @@ -3689,6 +4251,9 @@ my $q = $HaCi::HaCi::q; my $users = &getUsers(); + foreach (@{$users}) { + $_->{name} = "eHTML($_->{name}); + } $t->{V}->{newUserHeader} = _gettext("New User"); $t->{V}->{newUserFormName} = 'newUser'; @@ -3706,6 +4271,7 @@ name => 'userName', size => 20, maxlength => 255, + onKeyDown => "submitOnEnter(event, 'newUser')", }, { target => 'single', @@ -3774,21 +4340,15 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $userID = (defined $q->param('userID')) ? $q->param('userID') : undef; - my $userName = (defined $q->param('userName') && $q->param('userName')) ? $q->param('userName') : &userID2Name($userID); + my $userID = &getParam(1, 0, 'userID'); + my $userName = (defined &getParam(1, undef, 'userName') && &getParam(1, '', 'userName') ne '') ? &getParam(1, '', 'userName') : &userID2Name($userID); my $user = &getUser($userID); my $groups = {}; foreach (@{&getGroups()}) { $groups->{$_->{ID}} = $_->{name}; } - if (defined $q->param('editUser')) { - my $userTable = $conf->{var}->{TABLES}->{user}; - unless (defined $userTable) { - warn "Cannot Edit User. DB Error\n"; - return 0; - } - my $user = ($userTable->search(['*'], {ID => $userID}))[0]; + if (&getParam(1, 0, 'editUser')) { $q->delete('userDescr'); $q->param('userDescr', $user->{description}); foreach (split(/, /, $user->{groupIDs})) { s/\D//g; @@ -3796,10 +4356,10 @@ } } - my $userDescr = ((defined $q->param('userDescr')) ? $q->param('userDescr') : ''); + my $userDescr = &getParam(1, '', 'userDescr'); $userDescr =~ s/"/"/g; $t->{V}->{gettext_userpassword} = _gettext("Password is only for buildin 'HaCi' authentication!"); - $t->{V}->{editUserHeader} = ((defined $q->param('newUser')) ? (_gettext("New ")) : '') . sprintf(_gettext("User '%s'"), $userName); + $t->{V}->{editUserHeader} = ((defined &getParam(1, undef, 'newUser')) ? (_gettext("New ")) : '') . sprintf(_gettext("User '%s'"), "eHTML($userName)); $t->{V}->{editUserMenu} = [ { elements => [ @@ -3811,7 +4371,7 @@ { target => 'value', type => 'label', - value => $userName + value => "eHTML($userName) } ] }, @@ -3820,30 +4380,51 @@ { target => 'key', type => 'label', - value => _gettext("Password"), + value => _gettext("Description"), }, { target => 'value', - type => 'passwordfield', - name => 'password1', + type => 'textfield', + name => 'userDescr', size => 25, maxlength => 255, + value => "eHTML($userDescr) }, ], }, + ($userName eq 'admin') ? () : ( { elements => [ { target => 'key', type => 'label', - value => _gettext("Password Validation"), + value => _gettext("Enable internal account"), + }, + { + target => 'value', + type => 'checkbox', + name => 'enableInternalAccount', + value => 1, + descr => '', + checked => &getParam(1, (($user->{password} // '') eq '') ? 0 : 1, 'enableInternalAccount'), + onChange => 'toggleEnableIntAcc();', + } + ] + }), + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Password"), }, { target => 'value', type => 'passwordfield', - name => 'password2', + name => 'password1', size => 25, maxlength => 255, + disabled => ($userName eq 'admin') ? 0 : (&getParam(1, (($user->{password} // '') eq '') ? 0 : 1, 'enableInternalAccount')) ? 0 : 1, }, ], }, @@ -3852,15 +4433,15 @@ { target => 'key', type => 'label', - value => _gettext("Description"), + value => _gettext("Password Validation"), }, { target => 'value', - type => 'textfield', - name => 'userDescr', + type => 'passwordfield', + name => 'password2', size => 25, maxlength => 255, - value => $userDescr + disabled => ($userName eq 'admin') ? 0 : (&getParam(1, (($user->{password} // '') eq '') ? 0 : 1, 'enableInternalAccount')) ? 0 : 1, }, ], }, @@ -3880,7 +4461,7 @@ { target => 'value', type => 'label', - value => $user->{createFrom}, + value => "eHTML($user->{createFrom}), } ] }, @@ -3908,7 +4489,7 @@ { target => 'value', type => 'label', - value => $user->{modifyFrom}, + value => "eHTML($user->{modifyFrom}), } ] }, @@ -3938,8 +4519,8 @@ type => 'checkbox', name => 'userGroup_' . $_, value => 1, - descr => ' ' . $groups->{$_}, - checked => (defined $q->param('userGroup_' . $_)) ? $q->param('userGroup_' . $_) : 0, + descr => ' ' . "eHTML($groups->{$_}), + checked => &getParam(1, 0, 'userGroup_' . $_), } ] }, @@ -3981,9 +4562,16 @@ push @{$t->{V}->{editUserHiddens}}, ( { name => 'userID', - value => $q->param('userID') + value => &getParam(1, undef, 'userID') }, ) if defined $userID; + + push @{$t->{V}->{editUserHiddens}}, ( + { + name => 'enableInternalAccount', + value => 1 + }, + ) if $userName eq 'admin' } sub mkImportDNS { @@ -3991,13 +4579,13 @@ my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; my $stats = $conf->{static}->{misc}->{networkstates}; - my $roots = &getRoots(); + my $roots = &getRoots(1); unshift @{$roots}, {ID => -1, name => '[' . _gettext('NEW') . ']'}; - map {my $h=$_;$h->{name} = "eHTML($h->{name}); $_ = $h;} @{$roots}; + map {$_->{name} = "eHTML($_->{name})} @{$roots}; map {$_->{ID} = $_->{id}} @{$stats}; - $t->{V}->{importDNSHeader} = _gettext("Import from DNS Zonefiles"); + $t->{V}->{importDNSHeader} = _gettext("Import from DNS zonefiles"); $t->{V}->{importDNSTransHeader} = _gettext("Zonefile Transfer"); $t->{V}->{importDNSTransFormName} = 'importDNSTrans'; $t->{V}->{importDNSTransMenu} = [ @@ -4014,7 +4602,7 @@ name => 'nameserver', size => 15, maxlength => 256, - value => ((defined $q->param('nameserver')) ? $q->param('nameserver') : ''), + value => &getParam(1, '', 'nameserver'), focus => 1, } ] @@ -4032,7 +4620,7 @@ name => 'domain', size => 10, maxlength => 256, - value => ((defined $q->param('domain')) ? $q->param('domain') : ''), + value => &getParam(1, '', 'domain'), focus => 1, } ] @@ -4050,7 +4638,7 @@ name => 'targetRoot', size => 1, values => $roots, - selected => ((defined $q->param('targetRoot')) ? [$q->param('targetRoot')] : []), + selected => ((defined &getParam(1, undef, 'targetRoot')) ? [&getParam(1, 0, 'targetRoot')] : []), }, ] }, @@ -4067,7 +4655,7 @@ name => 'state', size => 1, values => $stats, - selected => ((defined $q->param('state')) ? [$q->param('state')] : []), + selected => ((defined &getParam(1, undef, 'state')) ? [&getParam(1, 0, 'state')] : []), } ] }, @@ -4123,7 +4711,7 @@ name => 'zonefile', size => 25, maxlength => 64000, - value => ((defined $q->param('domain')) ? $q->param('domain') : ''), + value => &getParam(1, 0, 'domain'), focus => 1, } ] @@ -4141,7 +4729,7 @@ name => 'origin', size => 25, maxlength => 255, - value => ((defined $q->param('origin')) ? $q->param('origin') : ''), + value => &getParam(1, '', 'origin'), }, ] }, @@ -4158,7 +4746,7 @@ name => 'targetRoot', size => 1, values => $roots, - selected => ((defined $q->param('targetRoot')) ? [$q->param('targetRoot')] : []), + selected => ((defined &getParam(1, undef, 'targetRoot')) ? [&getParam(1, 0, 'targetRoot')] : []), }, ] }, @@ -4175,7 +4763,7 @@ name => 'state', size => 1, values => $stats, - selected => ((defined $q->param('state')) ? [$q->param('state')] : []), + selected => ((defined &getParam(1, undef, 'state')) ? [&getParam(1, 0, 'state')] : []), } ] }, @@ -4219,7 +4807,8 @@ my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; my $stats = $conf->{static}->{misc}->{networkstates}; - my $roots = &getRoots(); + my $roots = &getRoots(1); + map {$_->{name} = "eHTML($_->{name})} @{$roots}; unshift @{$roots}, {ID => -1, name => '[' . _gettext('NEW') . ']'}; my $sources = [ {ID => 'cisco', name => 'cisco'}, @@ -4247,7 +4836,7 @@ name => 'config', size => 25, maxlength => 64000, - value => ((defined $q->param('config')) ? $q->param('config') : ''), + value => &getParam(1, '', 'config'), focus => 1, } ] @@ -4265,7 +4854,7 @@ name => 'source', size => 1, values => $sources, - selected => ((defined $q->param('source')) ? [$q->param('source')] : []), + selected => ((defined &getParam(1, undef, 'source')) ? [&getParam(1, 0, 'source')] : []), } ] }, @@ -4282,7 +4871,7 @@ name => 'state', size => 1, values => $stats, - selected => ((defined $q->param('state')) ? [$q->param('state')] : []), + selected => ((defined &getParam(1, undef, 'state')) ? [&getParam(1, 0, 'state')] : []), } ] }, @@ -4299,10 +4888,27 @@ name => 'targetRoot', size => 1, values => $roots, - selected => ((defined $q->param('targetRoot')) ? [$q->param('targetRoot')] : []), + selected => ((defined &getParam(1, undef, 'targetRoot')) ? [&getParam(1, 0, 'targetRoot')] : []), }, ] }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Overwrite existing"), + }, + { + target => 'value', + type => 'checkbox', + name => 'overwrite', + value => 1, + descr => '', + checked => 0, + }, + ], + }, ]; $t->{V}->{importConfigButtons} = [ @@ -4344,18 +4950,21 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $id = (defined $q->param('configFileID')) ? $q->param('configFileID') : $conf->{var}->{exportID}; + my $id = (defined &getParam(1, undef, 'configFileID')) ? &getParam(1, 0, 'configFileID') : $conf->{var}->{exportID}; my @data = &parseCSVConfigfile($id, 1); $conf->{var}->{STATUS}->{STATUS} = 'FINISH'; $conf->{var}->{STATUS}->{PERCENT} = 100; &setStatus(); my $nrOfCols = $conf->{var}->{nrOfCols}; my $netTypes = &getNetworkTypes(1); - my $descrs = (defined $q->param('tmplID') && $q->param('tmplID')) ? &getTemplateEntries($q->param('tmplID'), 0, 0, 1, 0, 1) : {}; + map {$_->{name} = "eHTML($_->{name})} @{$netTypes}; + my $descrs = (defined &getParam(1, undef, 'tmplID') && &getParam(1, 0, 'tmplID')) ? &getTemplateEntries(&getParam(1, 0, 'tmplID'), 0, 0, 1, 0, 1) : {}; my @cols = ( {ID => 0, name => ''}, - {ID => -1, name => 'network'}, - {ID => -2, name => 'status'}, - {ID => -3, name => 'description'}, + {ID => -1, name => _gettext('Network')}, + {ID => -2, name => _gettext('Status')}, + {ID => -3, name => _gettext('Description')}, + {ID => -4, name => _gettext('Tags')}, + {ID => -5, name => _gettext('Def. Subnet CIDR')}, ); foreach (keys %{$descrs}) { push @cols, {ID => $_, name => $descrs->{$_}} @@ -4379,7 +4988,7 @@ name => 'sep', size => 1, maxlength => 1, - value => ((defined $q->param('sep')) ? $q->param('sep') : ''), + value => &getParam(1, '', 'sep'), }, { type => 'buttons', @@ -4406,7 +5015,7 @@ name => 'tmplID', size => 1, values => $netTypes, - selected => ((defined $q->param('tmplID')) ? [$q->param('tmplID')] : []), + selected => ((defined &getParam(1, undef, 'tmplID')) ? [&getParam(1, 0, 'tmplID')] : []), }, { type => 'buttons', @@ -4451,19 +5060,23 @@ push @{$t->{V}->{importCSVHiddens}}, ( { name => 'config', - value => $q->param('config') + value => &getParam(1, undef, 'config') }, { name => 'source', - value => $q->param('source') + value => &getParam(1, undef, 'source') }, { name => 'state', - value => $q->param('state') + value => &getParam(1, undef, 'state') }, { name => 'targetRoot', - value => $q->param('targetRoot') + value => &getParam(1, undef, 'targetRoot') + }, + { + name => 'overwrite', + value => &getParam(1, 0, 'overwrite') }, { name => 'configFileID', @@ -4476,8 +5089,8 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - my $roots = &getRoots(); - map {my $h=$_;$h->{name} = "eHTML($h->{name}); $_ = $h;} @{$roots}; + my $roots = &getRoots(1); + map {$_->{name} = "eHTML($_->{name})} @{$roots}; &removeStatus(); $t->{V}->{compareHeader} = _gettext("Compare"); @@ -4496,7 +5109,7 @@ name => 'leftRootID', size => 1, values => $roots, - selected => ((defined $q->param('leftRootID')) ? [$q->param('leftRootID')] : []), + selected => ((defined &getParam(1, undef, 'leftRootID')) ? [&getParam(1, 0, 'leftRootID')] : []), }, { target => 'key', @@ -4509,7 +5122,7 @@ name => 'rightRootID', size => 1, values => $roots, - selected => ((defined $q->param('rightRootID')) ? [$q->param('rightRootID')] : []), + selected => ((defined &getParam(1, undef, 'rightRootID')) ? [&getParam(1, 0, 'rightRootID')] : []), }, { target => 'key', @@ -4522,7 +5135,7 @@ name => 'resultName', size => 10, maxlength => 256, - value => ((defined $q->param('resultName')) ? $q->param('resultName') : ''), + value => &getParam(1, '', 'resultName'), focus => 1, }, ] @@ -4671,7 +5284,7 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; my $t = $HaCi::GUI::init::t; - my $netID = $q->param('netID'); + my $netID = &getParam(1, undef, 'netID'); return unless defined $netID; my $types = &getNetworkTypes(1); @@ -4679,7 +5292,7 @@ my ($rootID, $networkDec, $ipv6) = &netID2Stuff($netID); my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); return unless &checkSpelling_Net($network, $ipv6); - + map {$_->{name} = "eHTML($_->{name})} @{$types}; map {$_->{ID} = $_->{id}} @{$stats}; my $maintenanceInfos = &getMaintInfosFromNet($netID); @@ -4788,7 +5401,7 @@ { target => 'value', type => 'label', - value => $descr, + value => "eHTML($descr), } ] }, @@ -4822,7 +5435,7 @@ { target => 'value', type => 'label', - value => $maintenanceInfos->{createFrom}, + value => "eHTML($maintenanceInfos->{createFrom}), } ] }, @@ -4850,7 +5463,7 @@ { target => 'value', type => 'label', - value => $maintenanceInfos->{modifyFrom}, + value => "eHTML($maintenanceInfos->{modifyFrom}), } ] }, @@ -4946,7 +5559,7 @@ name => 'descrTemplate', size => 20, maxlength => 255, - value => $descr . ' %d', + value => "eHTML($descr) . ' %d', }, { target => 'value', @@ -4954,13 +5567,13 @@ align => 'left', buttons => [ { - name => 'showDescrHelper', + name => 'showDescrHelperBtn', type => '', onClick => "showDescrHelper()", value => '1', img => 'info_small.png', picOnly => 1, - title => _gettext("Available Variables from the Plugins"), + title => _gettext("Available variables"), }, ], }, @@ -5028,7 +5641,7 @@ }, ); - $t->{V}->{helpDescrHeader} = _gettext("Available Variables from the Plugins"); + $t->{V}->{helpDescrHeader} = _gettext("Available variables"); $t->{V}->{helpDescrMenu} = [ { elements => [ @@ -5210,19 +5823,20 @@ my $stats = $conf->{static}->{misc}->{networkstates}; my $oneOK = 0; + map {$_->{name} = "eHTML($_->{name})} @{$types}; map {$_->{ID} = $_->{id}} @{$stats}; $t->{V}->{combineNetsHeader} = _gettext("Combine Networks"); $t->{V}->{combineNetsFormName} = 'combineNetsMenu'; - my $box = {}; - foreach ($q->param('selectedNetworks')) { + my $box = {}; + my $selectedNets = &getParam(0, [], 'selectedNetworks'); + foreach (@{$selectedNets}) { my ($network, $rootID) = split/_/, $_, 2; my $ipv6 = &rootID2ipv6($rootID); my $networkDec = ($ipv6) ? &netv62Dec($network) : &net2dec($network); my $parent = &getNetworkParentFromDB($rootID, $networkDec, $ipv6); my $parentDec = (defined $parent) ? $parent->{network} : 0; -# warn "COMBINE $network -> " . &dec2net($parentDec) . "\n"; $box->{$rootID}->{IPV6} = $ipv6; push @{$box->{$rootID}->{PARENTS}->{$parentDec}}, $networkDec; } @@ -5235,7 +5849,7 @@ my $ipv6 = $box->{$rootID}->{IPV6}; my @parents = (); if ($ipv6) { - @parents = sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} keys %{$box->{$rootID}->{PARENTS}}; + @parents = &ipv6Sort(keys %{$box->{$rootID}->{PARENTS}}); } else { @parents = sort {$a<=>$b} keys %{$box->{$rootID}->{PARENTS}}; } @@ -5243,12 +5857,13 @@ my $parent = $_; my @nets = (); if ($ipv6) { - @nets = sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} @{$box->{$rootID}->{PARENTS}->{$parent}}; + @nets = &ipv6Sort(@{$box->{$rootID}->{PARENTS}->{$parent}}); } else { @nets = sort {$a<=>$b} @{$box->{$rootID}->{PARENTS}->{$parent}}; } foreach (@nets) { my $currNet = $_; + $currNet = Math::BigInt->new($currNet) if $ipv6; if (defined $lastNet) { my $netBefore = &getDBNetworkBefore($rootID, $currNet, $ipv6, 1); $cnter++ if $lastNet != $netBefore; @@ -5280,7 +5895,6 @@ my $currIPT = ($ipv6) ? Math::BigInt->new($firstNetaddress) : $firstNetaddress; my $currNetaddress = ($ipv6) ? &ipv6DecCidr2NetaddressV6Dec($currIPT, $cidr) : &getNetaddress($currIPT, &getNetmaskFromCidr($cidr)); my $currIP = ($ipv6) ? $currNetaddress->copy()->badd($base->copy()->bpow(128 - $cidr)) : $currNetaddress + (2**(32 - $cidr)); -# warn "First: " . &dec2ip($firstNetaddress) . " - " . &dec2net($last) ." (currIP: " . &dec2ip($currIP) . ") < (LASTBROADCAST: " . &dec2ip($lastBroadcast) . ")\n"; while ($currIP <= $lastBroadcast) { last if $cidr < 1; @@ -5293,7 +5907,6 @@ my $newNetRevisedNetDec = ($ipv6) ? &ipv6DecCidr2netv6Dec($newNetRevisedIPDec, $cidr) : &net2dec(&dec2ip($newNetRevisedIPDec) . '/' . $cidr); my $newNetRevised = ($ipv6) ? &netv6Dec2net(&ipv6DecCidr2netv6Dec($newNetRevisedIPDec, $cidr)) : &dec2ip($newNetRevisedIPDec) . '/' . $cidr; my $newNetBroadcast = ($ipv6) ? &getV6BroadcastNet(&ipv6DecCidr2netv6Dec($newNetRevisedIPDec, $cidr), 128) : &net2dec(&dec2ip(&getBroadcastFromNet(&net2dec($newNetRevised))) . '/' . 32); -# warn "NEW: " . &dec2net($newNetRevisedNetDec) . "\n"; if ($transCnter) { push @{$t->{V}->{combineNetsMenu}}, ( @@ -5324,12 +5937,13 @@ my $cnter1 = 0; my @nets = (); if ($ipv6) { - @nets = sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} @{$box1->{$rootID}->{NETS}->{$cnter}}; + @nets = &ipv6Sort(@{$box1->{$rootID}->{NETS}->{$cnter}}); } else { @nets = sort {$a<=>$b} @{$box1->{$rootID}->{NETS}->{$cnter}}; } foreach (@nets) { my $networkDec = $_; + $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $ipv6ID = ($ipv6) ? &netv6Dec2ipv6ID($networkDec) : ''; my $netID = &getNetID($rootID, $networkDec, $ipv6ID); my $maintenanceInfos = &getMaintInfosFromNet($netID); @@ -5351,7 +5965,7 @@ { target => 'value', type => 'label', - value => (($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec)) . ' (' . $maintenanceInfos->{description} . ')', + value => (($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec)) . ' (' . "eHTML($maintenanceInfos->{description}) . ')', } ] }, @@ -5459,7 +6073,7 @@ name => 'combineNets_' . $transCnter . '_descr', size => 20, maxlength => 255, - value => $descr, + value => "eHTML($descr), } ] }, @@ -6150,6 +6764,7 @@ my $plugin = &pluginID2Name($pluginID); my $pluginFilename = &pluginID2File($pluginID); my $pluginInfos = (&getPluginInfos($pluginFilename))[1]; + my $pluginConfValues = &getPluginConfValues($pluginID, $netID); my $error = $pluginInfos->{ERROR} || ''; return if !$pluginInfos->{ACTIVE} && !$pluginInfos->{ERROR}; @@ -6180,7 +6795,7 @@ if ($pluginInfos->{ONDEMAND}) { my $lastRun = time; eval { - $plug->run_onDemand($maintenanceInfos); + $plug->run_onDemand($maintenanceInfos, $pluginConfValues); }; if ($@) { $error = "Error while running Module: $@"; @@ -6256,8 +6871,8 @@ my $global = shift || 0; my $q = $HaCi::HaCi::q; my $t = $HaCi::GUI::init::t; - my $pluginID = $q->param('pluginID'); - my $netID = $q->param('netID'); + my $pluginID = &getParam(1, undef, 'pluginID'); + my $netID = &getParam(1, undef, 'netID'); my $plugin = &pluginID2Name($pluginID); $netID = -1 unless defined $netID; my ($rootID, $networkDec, $ipv6); @@ -6290,10 +6905,10 @@ my $t = $HaCi::GUI::init::t; my $thisScript = $conf->{var}->{thisscript}; my $maxSubnetSize = &getConfigValue('gui', 'maxsubnetsize'); - my $netID = $q->param('netID'); + my $netID = &getParam(1, undef, 'netID'); my $net = &getMaintInfosFromNet($netID); my $ipv6 = ($net->{ipv6ID}) ? 1 : 0; - my $subnetSize = (defined $q->param('subnetSize')) ? $q->param('subnetSize') : $net->{defSubnetSize}; + my $subnetSize = &getParam(1, $net->{defSubnetSize}, 'subnetSize'); my $network = ($ipv6) ? &netv6Dec2net($net->{network}) : &dec2net($net->{network}); my $cidr = (split/\//, $network, 2)[1]; my @freeSubnetst = &getFreeSubnets($netID, 0, $subnetSize); @@ -6323,6 +6938,7 @@ $t->{V}->{freeSubnetsHeader} = _gettext("Free Subnets"); $t->{V}->{showSubnetsFormName} = 'showSubnets'; $t->{V}->{buttonFocus} = 'showSubnets'; + $t->{V}->{bAddNet} = &checkRight('addNet'); $t->{V}->{freeSubnets} = $freeSubnets; $t->{V}->{noResults} = ($#freeSubnetst == -1) ? 1 : 0; $t->{V}->{gettext_subnet} = _gettext('Subnet'); @@ -6396,11 +7012,11 @@ my $t = $HaCi::GUI::init::t; my $subMenu = ''; - if ($q->param('changeOwnPW')) { + if (&getParam(1, 0, 'changeOwnPW')) { $subMenu = 'chOwnPW'; &mkChOwnPW(); } - elsif ($q->param('showViewSettings')) { + elsif (&getParam(1, 0, 'showViewSettings')) { $subMenu = 'showViewSettings'; &mkShowViewSettings(); } @@ -6647,6 +7263,184 @@ ]; } +sub mkShowAuditLogs { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + my $t = $HaCi::GUI::init::t; + my $q = $HaCi::HaCi::q; + my $pageSize = &getParam(1, 100, 'pageSize'); + my $page = &getParam(1, 1, 'page'); + my $sortBy = &getParam(1, 'ts', 'sortBy'); + my $bReverse = &getParam(1, 0, 'reverse'); + my $searchFor = &getParam(1, '', 'searchFor'); + $pageSize =~ s/\D//g; + $page =~ s/\D//g; + $pageSize ||= 100; + $page ||= 1; + + $page++ if &getParam(1, 0, 'showAuditLogsRight'); + $page-- if &getParam(1, 0, 'showAuditLogsLeft'); + + my ($auditLogs, $totalAuditLogs) = &getAuditLogs($pageSize, ($page - 1), $sortBy, $bReverse, $searchFor, 1); + $auditLogs ||= []; + $totalAuditLogs ||= 0; + my $totalNrOfPages = int(($totalAuditLogs / $pageSize) + (($totalAuditLogs % $pageSize) ? 1 : 0)); + $totalNrOfPages ||= 1; + if ($page > $totalNrOfPages) { + $page = $totalNrOfPages; + ($auditLogs, $totalAuditLogs) = &getAuditLogs($pageSize, ($page - 1)); + } + + my $pageValues = []; + map {push @{$pageValues}, {ID => $_, name => $_}} (10, 50, 100, 500, 1000); + + my $sortByValues = [ + {ID => 'ts', name => _gettext('Timestamp')}, + {ID => 'username', name => _gettext('Username')}, + {ID => 'action', name => _gettext('Action')}, + {ID => 'object', name => _gettext('Object')}, + ]; + + $t->{V}->{auditLogs} = $auditLogs; + $t->{V}->{showAuditLogs} = _gettext("Audit logs"); + $t->{V}->{gettext_noContent} = _gettext("No audit logs available"); + $t->{V}->{gettext_timestamp} = _gettext("Timestamp"); + $t->{V}->{gettext_username} = _gettext("Username"); + $t->{V}->{gettext_action} = _gettext("Action"); + $t->{V}->{gettext_object} = _gettext("Object"); + $t->{V}->{gettext_value} = _gettext("Value"); + $t->{V}->{gettext_error} = _gettext("Error"); + $t->{V}->{showAuditLogsFormName} = 'showAuditLogsMenu'; + $t->{V}->{showAuditLogsHeader} = _gettext("Show audit logs"); + $t->{V}->{showAuditLogsMenu} = [ + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Number of entries"), + }, + { + target => 'value', + type => 'popupMenu', + name => 'pageSize', + size => 1, + values => $pageValues, + selected => [$pageSize], + }, + ], + }, + { + elements => [ + { + target => 'key', + type => 'label', + value => sprintf(_gettext("Page (%d .. %d)"), 1, $totalNrOfPages) + }, + { + target => 'value', + type => 'textfield', + name => 'page', + size => 3, + maxlength => 7, + value => $page, + onKeyDown => "submitOnEnter(event, 'commitShowAuditLogs')", + } + ], + }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Search") + }, + { + target => 'value', + type => 'textfield', + name => 'searchFor', + size => 10, + maxlength => 64, + value => $searchFor, + onKeyDown => "submitOnEnter(event, 'commitShowAuditLogs')", + } + ], + }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Sort by"), + }, + { + target => 'value', + type => 'popupMenu', + name => 'sortBy', + size => 1, + values => $sortByValues, + selected => [$sortBy] + }, + ], + }, + { + elements => [ + { + target => 'key', + type => 'label', + value => _gettext("Reverse"), + }, + { + target => 'value', + type => 'checkbox', + name => 'reverse', + value => 1, + descr => '', + checked => $bReverse, + disabled => 0, + }, + ], + }, + { + value => { + type => 'hline', + colspan => 2, + } + }, + { + elements => [ + { + target => 'single', + type => 'buttons', + align => 'center', + colspan => 5, + buttons => [ + (($page == 1) ? () : + { + name => 'showAuditLogsLeft', + type => 'submit', + value => ' ', + img => 'left.png', + }), + { + name => 'commitShowAuditLogs', + type => 'submit', + value => _gettext("Show"), + img => 'search_small.png', + }, + (($page == $totalNrOfPages) ? () : + { + name => 'showAuditLogsRight', + type => 'submit', + value => ' ', + img => 'right.png', + }), + ], + }, + ], + } + ]; +} + 1; # vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/HaCiAPI.pm haci-0.98c/modules/HaCi/HaCiAPI.pm --- haci-0.97c/modules/HaCi/HaCiAPI.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/HaCiAPI.pm 2015-01-03 05:11:10.000000000 +0000 @@ -2,13 +2,14 @@ use strict; use warnings; +use File::Basename; use vars qw/$workDir/; # Polluting Environment for Config::General $ENV{script_name} = $ENV{SCRIPT_NAME}; -$workDir = &getWorkDir(); +($workDir = dirname( __FILE__ )) =~ s#/modules/HaCi##; $ENV{workdir} = $workDir; unshift @INC, $ENV{workdir} . '/modules'; @@ -21,20 +22,6 @@ our $conf; *conf = \$HaCi::Conf::conf; -sub getWorkDir { - my $currDir = `pwd`; - chomp($currDir); - my $scriptFile = $0; - $scriptFile = $ENV{SCRIPT_FILENAME} if exists $ENV{SCRIPT_FILENAME}; - (my $scriptDir = $scriptFile) =~ s/\/[^\/]+$//; - my $destDir = ($scriptDir =~ /^\//) ? $scriptDir : $currDir . '/' . $scriptDir; - chdir "$destDir/../" or die "Cannot change into workdir '$destDir/../': $!\n"; - my $workDir = `pwd`; - chomp($workDir); - - return $workDir; -} - sub init { my @args = @_; @@ -56,7 +43,11 @@ my $value = $params->{$key}; if (defined $value) { $q->delete($key); - $q->param($key, $value); + if (ref($value) eq 'ARRAY') { + $q->param($key, @{$value}); + } else { + $q->param($key, $value); + } warn "\$q->param($key, $value);\n" if $conf->{static}->{misc}->{debug}; } } @@ -72,6 +63,8 @@ _IN fuzzy $boolean (optional) Fuzzy search? _IN template $string (optional) isolate your Search by defining a Template _IN templateQueries $string (optional) Define special Queries for the specified Template. spererated by semicolon. E.g.: value1=foo;value2=bar +_IN root $string (optional) Define special root to search in +_IN tags $string (optional) return only networks with this tags, seperate with spaces (i.e.: 'OR foo bar', 'AND foo bar') _RETURN @HaCi::SOAP::Type::network _DOC This is a search function @@ -79,7 +72,17 @@ sub search { my ($class, $user, $pass, @funcArgs) = @_; &init(); - &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&search_pre, \&search_post); + + my $result = ''; + eval { + $result = &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&search_pre, \&search_post); + }; + if ($@) { + warn "Error: $@"; + return $@; + } + + return $result; } sub search_pre { @@ -94,11 +97,27 @@ my $fuzzy = $$funcArgs[3] || ''; my $tmplName = $$funcArgs[4] || ''; my $tmplQuery = $$funcArgs[5] || ''; - my $tmplID = ($tmplName ne '') ? &tmplName2ID($tmplName) : 0; + my $rootName = $$funcArgs[6] || ''; + my $tagsT = $$funcArgs[7] || ''; + $tagsT =~ s/^\s+//; + $tagsT =~ s/\s+$//; + my @tags = split(/\s+/, $tagsT); + my $tagOp = ($tagsT ne '') ? shift @tags : 0; + if ($tagsT ne '' && scalar @tags == 0) { + @tags = ($tagOp); + $tagOp = 'OR'; + } + + my $tmplID = ($tmplName ne '') ? &tmplName2ID($tmplName) : -1; + my $rootID = ($rootName ne '') ? &rootName2ID($rootName) : 0; unless (defined $tmplID) { &warnl("No such Template found! ($tmplName)"); $tmplID = -1; } + unless (defined $rootID) { + &warnl("No such root found! ($rootName)"); + $rootID = -1; + } foreach (split(/;/, $tmplQuery)) { my $query = $_; @@ -112,7 +131,7 @@ my $tmplEntry = 'tmplEntryID_' . $tmplEntryID; &fillParams($q, { $tmplDescr => $key, - $tmplEntry => $value, + $tmplEntry => $value, }); } @@ -123,6 +142,9 @@ exact => $exact || undef, fuzzy => $fuzzy || undef, tmplID => $tmplID, + rootID => $rootID, + tags => (scalar @tags > 0) ? \@tags : undef, + tagOp => $tagOp, }); } @@ -138,7 +160,7 @@ if (defined $result && ref($result) eq 'ARRAY') { my $networks = []; foreach (@{$result}) { - push @{$networks}, new HaCi::SOAP::Type::network($_->{rootName}, $_->{network}, $_->{description}, $_->{state}); + push @{$networks}, new HaCi::SOAP::Type::network($_->{rootName}, $_->{network}, $_->{description}, $_->{state}, $_->{tags}); } return $networks; } else { @@ -162,7 +184,17 @@ sub getFreeSubnets { my ($class, $user, $pass, @funcArgs) = @_; &init(@funcArgs); - &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&getFreeSubnets_pre, \&getFreeSubnets_post); + + my $result = ''; + eval { + $result = &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&getFreeSubnets_pre, \&getFreeSubnets_post); + }; + if ($@) { + warn "Error: $@"; + return $@; + } + + return $result; } sub getFreeSubnets_pre { @@ -196,7 +228,7 @@ } &fillParams($q, { - showSubnets => 1, + getFreeSubnets => 1, netID => $netID, subnetSize => $cidr, amount => $amount, @@ -209,14 +241,17 @@ my $t = shift; my $warnings = shift; my $result = $t->{V}->{freeSubnets}; - my $amount = $q->param('amount') || 0; + my $amount = &getParam($q, 1, 0, 'amount'); + my $rootName = $$funcArgs[0] || 0; &dieWarnings($warnings) if $warnings ne ''; if (defined $result && ref($result) eq 'ARRAY') { my $networks = []; my $cnter = 0; foreach (@{$result}) { - push @{$networks}, new HaCi::SOAP::Type::network('', $_->{net}); + my $cRootName = ($_->{rootName}) ? $_->{rootName} : $rootName; + my $cNetwork = ($_->{network}) ? $_->{network} : $_->{net}; + push @{$networks}, new HaCi::SOAP::Type::network($cRootName, $cNetwork); return $networks if $amount && ++$cnter == $amount; } return $networks; @@ -228,9 +263,7 @@ sub dieWarnings { my $warnings = shift; -warn "die " . SOAP::Fault->faultcode('HaCiAPI')->faultstring($warnings) . "\n"; -# die SOAP::Fault->faultcode('HaCiAPI')->faultstring($warnings); - die $warnings; + die SOAP::Fault->faultcode('HaCiAPI')->faultstring($warnings); } =begin WSDL @@ -252,7 +285,17 @@ sub getFreeSubnetsFromSearch { my ($class, $user, $pass, @funcArgs) = @_; &init(); - &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&getFreeSubnetsFromSearch_pre, \&getFreeSubnets_post); + + my $result = ''; + eval { + $result = &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&getFreeSubnetsFromSearch_pre, \&getFreeSubnets_post); + }; + if ($@) { + warn "Error: $@"; + return $@; + } + + return $result; } sub getFreeSubnetsFromSearch_pre { @@ -313,6 +356,7 @@ _IN state $string (optional) The State of the Network. (One of: UNSPECIFIED, ALLOCATED PA, ALLOCATED PI, ALLOCATED UNSPECIFIED, SUB-ALLOCATED PA, LIR-PARTITIONED PA, LIR-PARTITIONED PI, EARLY-REGISTRATION, NOT-SET, ASSIGNED PA, ASSIGNED PI, ASSIGNED ANYCAST, ALLOCATED-BY-RIR, ALLOCATED-BY-LIR, ASSIGNED, RESERVED, LOCKED, FREE) _IN defSubnetSize $int (optional) Default CIDR for Subnets _IN templateName $string (optional) Template, which should be linked to the Network +_IN tags $string (optional) Tags (seperate by comma) _RETURN $string Prints if addition has failed or was successfull _DOC This function adds a Network @@ -320,7 +364,17 @@ sub addNet { my ($class, $user, $pass, @funcArgs) = @_; &init(@funcArgs); - &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&addNet_pre, \&addNet_post); + + my $result = ''; + eval { + $result = &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&addNet_pre, \&addNet_post); + }; + if ($@) { + warn "Error: $@"; + return $@; + } + + return $result; } sub addNet_pre { @@ -336,6 +390,7 @@ my $state = (($$funcArgs[1] eq '') ? -1 : &networkStateName2ID($$funcArgs[1]) || 0), my $defss = $$funcArgs[5] || 0; my $tmplName = $$funcArgs[6] || ''; + my $tags = $$funcArgs[7] || ''; $cidr = (($ip =~ /:/) ? 128 : 32) if !defined $cidr || !$cidr; my $rootID = &rootName2ID($rootName); @@ -360,7 +415,8 @@ state => $state, defSubnetSize => $defss, tmplID => $tmplID, - forceState => 1 + tags => $tags, + forceState => 1 }); } @@ -376,7 +432,9 @@ $cidr = (($ip =~ /:/) ? 128 : 32) if !defined $cidr || !$cidr; my $network = $ip . '/' . $cidr; - if (defined $q->param('func') && $q->param('func') eq 'showAllNets') { + my $func = &getParam($q, 1, undef, 'func'); + warn "FUNC: $func\n"; + if (defined $func && $func eq 'showAllNets') { return "Sucessfully added Network '$network' to Root '$rootName'" . (($warnings) ? " ($warnings)" : ''); } else { return "Error while adding Network '$network' to Root '$rootName': $warnings"; @@ -397,7 +455,17 @@ sub delNet { my ($class, $user, $pass, @funcArgs) = @_; &init(@funcArgs); - &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&delNet_pre, \&delNet_post); + + my $result = ''; + eval { + $result = &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&delNet_pre, \&delNet_post); + }; + if ($@) { + warn "Error: $@"; + return $@; + } + + return $result; } sub delNet_pre { @@ -445,7 +513,8 @@ my $rootName = $$funcArgs[0] || ''; my $network = $$funcArgs[1] || '0/0'; - if (defined $q->param('func') && $q->param('func') eq 'showAllNets') { + my $func = &getParam($q, 1, undef, 'func'); + if (defined $func && $func eq 'showAllNets') { return "Sucessfully deleted Network '$network' from Root '$rootName'" . (($warnings) ? " ($warnings)" : ''); } else { return "Error while deleting Network '$network' from Root '$rootName': $warnings"; @@ -464,7 +533,17 @@ sub template { my ($class, $user, $pass, @funcArgs) = @_; &init(@funcArgs); - &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&template_pre, \&template_post); + + my $result = ''; + eval { + $result = &HaCi::HaCi::run(1, [$user, $pass, @funcArgs], \&template_pre, \&template_post); + }; + if ($@) { + warn "Error: $@"; + return $@; + } + + return $result; } sub template_pre { @@ -487,4 +566,28 @@ my $warnings = shift; } +sub getParam { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $q = shift; + my $onlyScalar = shift; + my $ifUndef = shift; + my $paramName = shift; + return $ifUndef unless defined $paramName; + + my @values = $q->param($paramName); + unless (defined $values[0]) { + return $ifUndef if $onlyScalar; + return () if $ifUndef == 0; # return empty list if onlyScalar != 1 && ifUndef == 0 + return $ifUndef; + } + + if ($onlyScalar) { + &debug("called function 'getParam' with option 'onlyScalar' AND more than one value! (" . (caller(0))[0] . '->' . (caller(0))[2] . ')') if $#values > 0; + return $values[0]; + } + + return @values; +} + 1; diff -Nru haci-0.97c/modules/HaCi/HaCi.pm haci-0.98c/modules/HaCi/HaCi.pm --- haci-0.97c/modules/HaCi/HaCi.pm 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/modules/HaCi/HaCi.pm 2015-02-13 23:32:19.000000000 +0000 @@ -26,13 +26,13 @@ netv6Dec2net /; use HaCi::Utils qw/ - prWarnl delUser getRights importCSV compare checkDB newWindow prNewWindows setStatus removeStatus + prWarnl delUser getRights importCSV compare checkDB newWindow prNewWindows setStatus removeStatus netv6Dec2ipv6ID addRoot addNet importASNRoutes getConfig checkSpelling_Net rootID2Name rootName2ID delNet genRandBranch editRoot delRoot copyNetsTo delNets search checkSpelling_IP checkSpelling_CIDR saveTmpl delTmpl saveGroup delGroup saveUser lwd dec2bin groupID2Name checkRight importDNSTrans importDNSLocal getNetworkParentFromDB importConfig rootID2ipv6 - expand splitNet combineNets updatePluginDB getTable checkTables checkNetworkACTable checkNetACL getRoots - mkPluginConfig initTables initCache chOwnPW updSettings updateSettingsInSession flushACLCache flushNetCache - searchAndGetFreeSubnets getParam + expand splitNet combineNets updatePluginDB getTable checkTables checkNetworkTable checkNetworkACTable checkNetACL getRoots + mkPluginConfig initTables initCache chOwnPW updSettings updateSettingsInSession flushACLCache flushNetCache exportSubnets + searchAndGetFreeSubnets getParam changeTmplName checkNetworkLock getFreeSubnets getNetID getDBNetworkBefore /; local our $q = undef; @@ -63,15 +63,16 @@ use Data::Dumper qw/Dumper/; # Loading Dumper for Debugging... foreach ($q->param) { my $k = $_; + next if $k eq 'password'; foreach ($q->param($k)) { warn " $k => $_ \n"; } } } # Dump - if ($q->param('func')) { - if ($q->param('func') eq 'logout') { - if ($session->param('authenticated')) { + if (&getParam(1, 0, 'func')) { + if (&getParam(1, '', 'func') eq 'logout') { + if (defined $session && $session->param('authenticated')) { &debug("logging out"); &removeStatus(); $session->delete(); @@ -89,21 +90,31 @@ my $t = $HaCi::GUI::init::t; - if (!$conf->{var}->{relogin} && &authentication()) { + if ( + !$conf->{var}->{relogin} && + &authentication( + &getParam(1, undef, 'username', 0, 1), + &getParam(1, undef, 'password'), + &getParam(1, undef, 'login'), + $session->param('username') + ) + ) { &getRights(); &$soapPreRun($soapArgs, $q) if $soap && defined $soapPreRun; &checkRights(); &main(); } else { &checkTables(); + &checkNetworkTable(); &checkNetworkACTable(); &HaCi::GUI::authentication::login(); $t->{V}->{page} = 'login'; } my $warnings = ''; + my $localQ = $q; $warnings = &finalize(); - return &$soapPostRun($soapArgs, $q, $t, $warnings) if $soap && defined $soapPostRun; + return &$soapPostRun($soapArgs, $localQ, $t, $warnings) if $soap && defined $soapPostRun; } sub main { @@ -111,70 +122,73 @@ &HaCi::GUI::init::setUserVars(); - if ($q->param('fname')) { # AJAX call + if (&getParam(1, 0, 'fname')) { # AJAX call return; } my $t = $HaCi::GUI::init::t; my $q = $HaCi::HaCi::q; - if ($q->param('submitAddRoot')) { + if (&getParam(1, 0, 'submitAddRoot')) { if (&addRoot( - &getParam(1, undef, $q->param('name')), - &getParam(1, undef, $q->param('descr')), - &getParam(1, 0, $q->param('ipv6')), - &getParam(1, undef, $q->param('rootID')), + &getParam(1, undef, 'name'), + &getParam(1, undef, 'descr'), + &getParam(1, 0, 'ipv6'), + &getParam(1, undef, 'rootID'), )) { $q->delete('func'); $q->param('func', 'showAllNets'); } else { $q->delete('func'); $q->param( 'func', - ((&getParam(1, 0, $q->param('editRoot'))) ? 'editRoot' : 'addRoot') + ((&getParam(1, 0, 'editRoot')) ? 'editRoot' : 'addRoot') ); } } - elsif ($q->param('submitAddNet')) { + elsif (&getParam(1, 0, 'submitAddNet')) { if (&addNet( - &getParam(1, 0, $q->param('netID')), - &getParam(1, undef, $q->param('rootID')), - &getParam(1, undef, $q->param('netaddress')), - &getParam(1, undef, $q->param('cidr')), - &getParam(1, '', $q->param('descr')), - &getParam(1, 0, $q->param('state')), - &getParam(1, 0, $q->param('tmplID')), - &getParam(1, 0, $q->param('defSubnetSize')), - &getParam(1, 0, $q->param('forceState')), + &getParam(1, 0, 'netID'), + &getParam(1, undef, 'rootID'), + &getParam(1, undef, 'netaddress'), + &getParam(1, undef, 'cidr'), + &getParam(1, '', 'descr'), + &getParam(1, 0, 'state'), + &getParam(1, 0, 'tmplID'), + &getParam(1, 0, 'defSubnetSize'), + &getParam(1, 0, 'forceState'), + 0, + 0, + &getParam(1, '', 'tags'), )) { $q->delete('func'); $q->param('func', 'showAllNets'); } else { $q->delete('func'); $q->param('func', 'addNet'); } } - elsif ($q->param('abortAddRoot')) { + elsif (&getParam(1, 0, 'abortAddRoot')) { $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('abortAddNet')) { - if ($q->param('editNet')) { + elsif (&getParam(1, 0, 'abortAddNet')) { + if (&getParam(1, 0, 'editNet')) { $q->delete('func'); $q->param('func', 'showNet'); } else { $q->delete('func'); $q->param('func', 'showAllNets'); } } - elsif ($q->param('checktAddNet')) { + elsif (&getParam(1, 0, 'checktAddNet')) { &checkNet( - &getParam(1, undef, $q->param('netaddress')), - &getParam(1, undef, $q->param('cidr')), + &getParam(1, undef, 'netaddress'), + &getParam(1, undef, 'cidr'), ); - if ($q->param('editNet')) { + if (&getParam(1, 0, 'editNet')) { $q->delete('func'); $q->param('func', 'editNet'); } else { $q->delete('func'); $q->param('func', 'addNet'); } } - elsif ($q->param('submitImportASNRoutes')) { + elsif (&getParam(1, 0, 'submitImportASNRoutes')) { if ( &importASNRoutes( - &getParam(1, undef, $q->param('asn')) + &getParam(1, undef, 'asn') ) ) { $q->delete('func'); $q->param('func', 'showAllNets'); @@ -182,213 +196,233 @@ $q->delete('func'); $q->param('func', 'importASNRoutes'); } } - elsif ($q->param('submitImpDNSTrans')) { + elsif (&getParam(1, 0, 'submitImpDNSTrans')) { if (&importDNSTrans()) { $q->delete('func'); $q->param('func', 'showAllNets'); } else { $q->delete('func'); $q->param('func', 'importDNS'); } } - elsif ($q->param('submitImpDNSLocal')) { + elsif (&getParam(1, 0, 'submitImpDNSLocal')) { if (&importDNSLocal()) { $q->delete('func'); $q->param('func', 'showAllNets'); } else { $q->delete('func'); $q->param('func', 'importDNS'); } } - elsif ($q->param('submitImpConfig')) { + elsif (&getParam(1, 0, 'submitImpConfig')) { if (&importConfig()) { $q->delete('func'); $q->param('func', 'showAllNets'); } else { $q->delete('func'); $q->param('func', 'importConfig'); } } - elsif ($q->param('impCSVChangeSep')) { + elsif (&getParam(1, 0, 'impCSVChangeSep')) { $q->delete('func'); $q->param('func', 'importConfig'); } - elsif ($q->param('impCSVChangeType')) { + elsif (&getParam(1, 0, 'impCSVChangeType')) { $q->delete('func'); $q->param('func', 'importConfig'); } - elsif ($q->param('abortImpCSV')) { + elsif (&getParam(1, 0, 'abortImpCSV')) { $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('submitImpCSV')) { + elsif (&getParam(1, 0, 'submitImpCSV')) { if (&importCSV()) { $q->delete('func'); $q->param('func', 'showAllNets'); } else { $q->delete('func'); $q->param('func', 'importConfig'); } } - elsif ($q->param('editPluginConf')) { + elsif (&getParam(1, 0, 'editPluginConf')) { $q->delete('func'); $q->param('func', 'showPluginConf'); } - elsif ($q->param('editNet')) { + elsif (&getParam(1, 0, 'editNet')) { $q->delete('func'); $q->param('func', 'editNet'); } - elsif ($q->param('splitNet')) { + elsif (&getParam(1, 0, 'splitNet')) { $q->delete('func'); $q->param('func', 'splitNet'); } - elsif ($q->param('submitSplitNet')) { + elsif (&getParam(1, 0, 'submitSplitNet')) { &splitNet( - &getParam(1, undef, $q->param('netID')), - &getParam(1, undef, $q->param('splitCidr')), - &getParam(1, '', $q->param('descrTemplate')), - &getParam(1, 0, $q->param('state')), - &getParam(1, 0, $q->param('tmplID')), - &getParam(1, 0, $q->param('delParentNet')), + &getParam(1, undef, 'netID'), + &getParam(1, undef, 'splitCidr'), + &getParam(1, '', 'descrTemplate'), + &getParam(1, 0, 'state'), + &getParam(1, 0, 'tmplID'), + &getParam(1, 0, 'delParentNet'), ); $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('submitCombineNets')) { + elsif (&getParam(1, 0, 'submitCombineNets')) { &combineNets(); $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('abortCombineNets')) { + elsif (&getParam(1, 0, 'abortCombineNets')) { $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('abortSplitNet')) { + elsif (&getParam(1, 0, 'abortSplitNet')) { $q->delete('func'); $q->param('func', 'showNet'); } - elsif ($q->param('combineNets')) { - my @nets = $q->param('selectedNetworks'); - if ($#nets > 0) { + elsif (&getParam(1, 0, 'combineNets')) { + my $nets = &getParam(0, [], 'selectedNetworks'); + if ($#{$nets} > 0) { $q->delete('func'); $q->param('func', 'combineNets'); } } - elsif ($q->param('abortEditRoot')) { + elsif (&getParam(1, 0, 'abortEditRoot')) { $q->delete('func'); $q->param('func', 'showRoot'); } - elsif ($q->param('editRoot')) { + elsif (&getParam(1, 0, 'editRoot')) { $q->delete('func'); $q->param('func', 'editRoot'); } - elsif ($q->param('abortDelRoot')) { + elsif (&getParam(1, 0, 'abortDelRoot')) { $q->delete('func'); $q->param('func', 'showRoot'); } - elsif ($q->param('abortDelNet')) { + elsif (&getParam(1, 0, 'abortDelNet')) { $q->delete('func'); $q->param('func', 'showNet'); } - elsif ($q->param('delRoot')) { - if ($q->param('commitDelRoot')) { + elsif (&getParam(1, 0, 'delRoot')) { + if (&getParam(1, 0, 'commitDelRoot')) { &delRoot( - &getParam(1, undef, $q->param('rootID')) + &getParam(1, undef, 'rootID') ); $q->delete('func'); $q->param('func', 'showAllNets'); } else { $q->delete('func'); $q->param('func', 'delRoot'); } } - elsif ($q->param('delNet')) { - if ($q->param('commitDelNet')) { - &delNet( - &getParam(1, undef, $q->param('netID')), - ((defined $q->param('withSubnets')) ? 1 : 0) - ); - $q->delete('func'); $q->param('func', 'showAllNets'); + elsif (&getParam(1, 0, 'delNet')) { + if (&getParam(1, 0, 'commitDelNet')) { + my $networkLock = &getParam(1, 0, 'networkLock'); + if (defined $networkLock && int($networkLock) ne $networkLock) { + &warnl(sprintf(_gettext("Network lock time must be provided in seconds not '%s'"), $networkLock)); + $q->delete('func'); $q->param('func', 'delNet'); + } else { + &delNet( + &getParam(1, undef, 'netID'), + ((&getParam(1, 0, 'withSubnets')) ? 1 : 0), + 0, + &getParam(1, 0, 'networkLock') + ); + $q->delete('func'); $q->param('func', 'showAllNets'); + } } else { $q->delete('func'); $q->param('func', 'delNet'); } } - elsif ($q->param('reduceRoot')) { + elsif (&getParam(1, 0, 'reduceRoot')) { &expand( '-', 'root', - &getParam(1, undef, $q->param('reduceRoot')) + &getParam(1, undef, 'reduceRoot') ); $session->param('currNet', ''); $session->param( 'currRootID', - &getParam(1, undef, $q->param('reduceRoot')) + &getParam(1, undef, 'reduceRoot') ); } - elsif ($q->param('expandRoot')) { + elsif (&getParam(1, 0, 'expandRoot')) { &expand( '+', 'root', - &getParam(1, undef, $q->param('expandRoot')) + &getParam(1, undef, 'expandRoot') ); $session->param('currNet', ''); $session->param( 'currRootID', - &getParam(1, undef, $q->param('expandRoot')) + &getParam(1, undef, 'expandRoot') ); } - elsif ($q->param('reduceNetwork')) { + elsif (&getParam(1, 0, 'reduceNetwork')) { &expand( '-', 'network', - &getParam(1, undef, $q->param('reduceNetwork')), - &getParam(1, undef, $q->param('rootID')) + &getParam(1, undef, 'reduceNetwork'), + &getParam(1, undef, 'rootID') ); $session->param( 'currNet', - &getParam(1, undef, $q->param('reduceNetwork')) + &getParam(1, undef, 'reduceNetwork') ); $session->param( 'currRootID', - &getParam(1, undef, $q->param('rootID')) + &getParam(1, undef, 'rootID') ); } - elsif ($q->param('expandNetwork')) { + elsif (&getParam(1, 0, 'expandNetwork')) { &expand( '+', 'network', - &getParam(1, undef, $q->param('expandNetwork')), - &getParam(1, undef, $q->param('rootID')) + &getParam(1, undef, 'expandNetwork'), + &getParam(1, undef, 'rootID') ); $session->param( 'currNet', - &getParam(1, undef, $q->param('expandNetwork')) + &getParam(1, undef, 'expandNetwork') ); $session->param( 'currRootID', - &getParam(1, undef, $q->param('rootID')) + &getParam(1, undef, 'rootID') ); } - elsif ($q->param('closeTree')) { + elsif (&getParam(1, 0, 'closeTree')) { &expand('-', 'ALL', 'ALL'); } - elsif ($q->param('jumpToButton')) { + elsif (&getParam(1, 0, 'jumpToButton')) { &expandTo( - &getParam(1, undef, $q->param('rootIDJump')), - &getParam(1, undef, $q->param('jumpTo')) + &getParam(1, undef, 'rootIDJump'), + &getParam(1, undef, 'jumpTo') ); } - elsif ($q->param('genRandBranch')) { + elsif (&getParam(1, 0, 'genRandBranch')) { &genRandBranch(); $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('finishEditTree')) { + elsif (&getParam(1, 0, 'finishEditTree')) { $q->delete('editTree'); } - elsif ($q->param('copyNetsTo')) { + elsif (&getParam(1, 0, 'copyNetsTo')) { ©NetsTo( - &getParam(1, undef, $q->param('copyToRootID')), - [$q->param('selectedNetworks')], + &getParam(1, undef, 'copyToRootID'), + &getParam(0, [], 'selectedNetworks'), 0 ); } - elsif ($q->param('moveNetsTo')) { + elsif (&getParam(1, 0, 'moveNetsTo')) { ©NetsTo( - &getParam(1, undef, $q->param('copyToRootID')), - [$q->param('selectedNetworks')], + &getParam(1, undef, 'copyToRootID'), + &getParam(0, [], 'selectedNetworks'), 1 ); } - elsif ($q->param('deleteNets')) { - &delNets([$q->param('selectedNetworks')]); + elsif (&getParam(1, 0, 'deleteNets')) { + &delNets(&getParam(0, [], 'selectedNetworks')); } - elsif ($q->param('searchButton')) { - &search(); - $q->delete('func'); $q->param('func', 'search'); + elsif (&getParam(1, 0, 'searchButton')) { + if ((&getParam(1, '', 'func') eq 'getFreeSubnetsFromSearch')) { + &searchAndGetFreeSubnets(); + $t->{V}->{searchResult} = $t->{V}->{freeSubnets}; + } else { + &search(); + } } - elsif ($q->param('compareButton')) { + elsif (&getParam(1, 0, 'compareButton')) { &compare(); $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('newTmpl')) { - if ($q->param('tmplName')) { + elsif (&getParam(1, 0, 'newTmpl')) { + my $tmplName = &getParam(1, '', 'tmplName'); + + my $exists = 0; + if ($tmplName) { + $exists = &checkIfExistsInDB('template', 'name', $tmplName); + &warnl("Template '$tmplName' already exists!") if $exists; + } + + if ($tmplName && !$exists) { $q->delete('tmplID'); - my $tmplName = &getParam(1, '', $q->param('tmplName')); + my $tmplName = &getParam(1, '', 'tmplName'); $tmplName =~ s/[<>&"']//g; $q->delete('tmplName'), $q->param('tmplName', $tmplName); $q->delete('func'); $q->param('func', 'editTmpl'); @@ -397,65 +431,76 @@ $q->delete('func'); $q->param('func', 'showTemplates'); } } - elsif ($q->param('editNetTypeTmpl')) { - unless (defined $q->param('tmplID')) { + elsif (&getParam(1, 0, 'editNetTypeTmpl')) { + unless (defined &getParam(1, undef, 'tmplID')) { $q->delete('func'); $q->param('func', 'showTemplates'); } else { $q->delete('func'); $q->param('func', 'editTmpl'); } } - elsif ($q->param('abortEditTmpl')) { + elsif (&getParam(1, 0, 'editTemplName')) { + &changeTmplName(&getParam(1, undef, 'tmplID', 1), &getParam(1, 0, 'tmplName')); + $q->delete('func'); $q->param('func', 'editTmpl'); + } + elsif (&getParam(1, 0, 'abortEditTmpl')) { $q->delete('func'); $q->param('func', 'showTemplates'); } - elsif ($q->param('submitAddTmplEntry')) { + elsif (&getParam(1, 0, 'submitAddTmplEntry')) { my $tmplID = &saveTmpl(); $q->delete('tmplID'); $q->param('tmplID', $tmplID); $q->delete('func'); $q->param('func', 'editTmpl'); } - elsif ($q->param('submitEditTmplEntry')) { + elsif (&getParam(1, 0, 'submitEditTmplEntry')) { my $tmplID = &saveTmpl(1); $q->delete('tmplID'); $q->param('tmplID', $tmplID); $q->delete('func'); $q->param('func', 'editTmpl'); } - elsif ($q->param('submitDeleteTmplEntry')) { + elsif (&getParam(1, 0, 'submitDeleteTmplEntry')) { my $tmplID = &saveTmpl(2); $q->delete('tmplID'); $q->param('tmplID', $tmplID); $q->delete('func'); $q->param('func', 'editTmpl'); } - elsif ($q->param('delTmpl')) { - if ($q->param('commitDelTmpl')) { - &delTmpl(&getParam(1, undef, $q->param('tmplID'))); + elsif (&getParam(1, 0, 'delTmpl')) { + if (&getParam(1, 0, 'commitDelTmpl')) { + &delTmpl(&getParam(1, undef, 'tmplID')); $q->delete('func'); $q->param('func', 'showTemplates'); } - elsif ($q->param('abortDelTmpl')) { + elsif (&getParam(1, 0, 'abortDelTmpl')) { $q->delete('func'); $q->param('func', 'showTemplates'); } else { - if ($q->param('tmplID')) { + if (&getParam(1, 0, 'tmplID')) { $q->delete('func'); $q->param('func', 'delTmpl'); } else { $q->delete('func'); $q->param('func', 'showTemplates'); } } } - elsif ($q->param('newGroup')) { - if ($q->param('groupName')) { + elsif (&getParam(1, 0, 'newGroup')) { + my $groupName = &getParam(1, '', 'groupName'); + #$groupName =~ s/[<>&"']//g; + + my $exists = 0; + if ($groupName) { + $exists = &checkIfExistsInDB('group', 'name', $groupName); + &warnl("Group '$groupName' already exists!") if $exists; + } + + if ($groupName && !$exists) { $q->delete('groupID'); - my $groupName = &getParam(1, '', $q->param('groupName')); - $groupName =~ s/[<>&"']//g; $q->delete('groupName'), $q->param('groupName', $groupName); $q->delete('func'); $q->param('func', 'editGroup'); } else { $q->delete('func'); $q->param('func', 'showGroups'); } } - elsif ($q->param('editGroup')) { - unless (defined $q->param('groupID')) { + elsif (&getParam(1, 0, 'editGroup')) { + unless (defined &getParam(1, undef, 'groupID')) { $q->delete('func'); $q->param('func', 'showGroups'); } else { $q->delete('func'); $q->param('func', 'editGroup'); } } - elsif ($q->param('submitEditGroup')) { + elsif (&getParam(1, 0, 'submitEditGroup')) { my $groupID = &saveGroup(); if (defined $groupID) { $q->delete('groupID'); $q->param('groupID', $groupID); @@ -464,20 +509,21 @@ $q->delete('func'); $q->param('func', 'editGroup'); } } - elsif ($q->param('abortEditGroup')) { + elsif (&getParam(1, 0, 'abortEditGroup')) { $q->delete('func'); $q->param('func', 'showGroups'); } - elsif ($q->param('delGroup')) { - if ($q->param('commitDelGroup')) { - &delGroup(&getParam(1, undef, $q->param('groupID'))); + elsif (&getParam(1, 0, 'delGroup')) { + if (&getParam(1, 0, 'commitDelGroup')) { + &delGroup(&getParam(1, undef, 'groupID')); $q->delete('func'); $q->param('func', 'showGroups'); } - elsif ($q->param('abortDelGroup')) { + elsif (&getParam(1, 0, 'abortDelGroup')) { $q->delete('func'); $q->param('func', 'showGroups'); } else { - if ($q->param('groupID')) { - my $groupName = &groupID2Name(&getParam(1, undef, $q->param('groupID'))); + if (&getParam(1, 0, 'groupID')) { + my $groupName = &groupID2Name(&getParam(1, undef, 'groupID')); if ($groupName eq 'Administrator') { + &warnl(_gettext("You cannot delete the administrator group!")); $q->delete('func'); $q->param('func', 'showGroups'); } else { $q->delete('func'); $q->param('func', 'delGroup'); @@ -487,25 +533,32 @@ } } } - elsif ($q->param('newUser')) { - if ($q->param('userName')) { + elsif (&getParam(1, 0, 'newUser')) { + my $userName = &getParam(1, '', 'userName'); + #$userName =~ s/[<>&"']//g; + + my $exists = 0; + if ($userName) { + $exists = &checkIfExistsInDB('user', 'username', $userName); + &warnl("User '$userName' already exists!") if $exists; + } + + if ($userName && !$exists) { $q->delete('userID'); - my $userName = &getParam(1, '', $q->param('userName')); - $userName =~ s/[<>&"']//g; $q->delete('userName'), $q->param('userName', $userName); $q->delete('func'); $q->param('func', 'editUser'); } else { $q->delete('func'); $q->param('func', 'showUsers'); } } - elsif ($q->param('editUser')) { - unless (defined $q->param('userID')) { + elsif (&getParam(1, 0, 'editUser')) { + unless (defined &getParam(1, undef, 'userID')) { $q->delete('func'); $q->param('func', 'showUsers'); } else { $q->delete('func'); $q->param('func', 'editUser'); } } - elsif ($q->param('submitEditUser')) { + elsif (&getParam(1, 0, 'submitEditUser')) { my $userID = &saveUser(); if (defined $userID) { $q->delete('userID'); $q->param('userID', $userID); @@ -514,42 +567,42 @@ $q->delete('func'); $q->param('func', 'editUser'); } } - elsif ($q->param('abortEditUser')) { + elsif (&getParam(1, 0, 'abortEditUser')) { $q->delete('func'); $q->param('func', 'showUsers'); } - elsif ($q->param('delUser')) { - if ($q->param('commitDelUser')) { - &delUser(&getParam(1, undef, $q->param('userID'))); + elsif (&getParam(1, 0, 'delUser')) { + if (&getParam(1, 0, 'commitDelUser')) { + &delUser(&getParam(1, undef, 'userID')); $q->delete('func'); $q->param('func', 'showUsers'); } - elsif ($q->param('abortDelUser')) { + elsif (&getParam(1, 0, 'abortDelUser')) { $q->delete('func'); $q->param('func', 'showUsers'); } else { - if ($q->param('userID')) { + if (&getParam(1, 0, 'userID')) { $q->delete('func'); $q->param('func', 'delUser'); } else { $q->delete('func'); $q->param('func', 'showUsers'); } } } - elsif ($q->param('showSubnets')) { + elsif (&getParam(1, 0, 'showSubnets')) { $q->delete('func'); $q->param('func', 'showSubnets'); } - elsif ($q->param('abortShowSubnets')) { + elsif (&getParam(1, 0, 'abortShowSubnets')) { $q->delete('func'); $q->param('func', 'showNet'); } - elsif ($q->param('checkDB')) { + elsif (&getParam(1, 0, 'checkDB')) { &checkDB(); } - elsif ($q->param('submitshowPlugins')) { + elsif (&getParam(1, 0, 'submitshowPlugins')) { &updatePluginDB(); $q->delete('func'); $q->param('func', 'showPlugins'); } - elsif ($q->param('editPluginGlobConf')) { + elsif (&getParam(1, 0, 'editPluginGlobConf')) { $q->delete('func'); $q->param('func', 'showPluginGlobConf'); } - elsif ($q->param('submitPluginConfig')) { - my $global = &getParam(1, 0, $q->param('global')); + elsif (&getParam(1, 0, 'submitPluginConfig')) { + my $global = &getParam(1, 0, 'global'); &mkPluginConfig($global); if ($global) { $q->delete('func'); $q->param('func', 'showPlugins'); @@ -557,8 +610,8 @@ $q->delete('func'); $q->param('editNet', 'Bearbeiten'); $q->param('func', 'editNet'); } } - elsif ($q->param('abortPluginConfig')) { - my $global = &getParam(1, 0, $q->param('global')); + elsif (&getParam(1, 0, 'abortPluginConfig')) { + my $global = &getParam(1, 0, 'global'); if ($global) { $q->delete('func'); $q->param('func', 'showPlugins'); } else { @@ -566,35 +619,56 @@ $q->delete('editNet'); $q->param('editNet', 1); } } - elsif ($q->param('abortShowSettings')) { + elsif (&getParam(1, 0, 'abortShowSettings')) { $q->delete('func'); $q->param('func', 'showAllNets'); } - elsif ($q->param('commitChOwnPW')) { + elsif (&getParam(1, 0, 'commitChOwnPW')) { unless (&chOwnPW()) { $q->param('changeOwnPW', 1); } } - elsif ($q->param('commitViewSettings')) { + elsif (&getParam(1, 0, 'commitShowAuditLogs')) { + $q->delete('func'); $q->param('func', 'showAuditLogs'); + } + elsif (&getParam(1, 0, 'showAuditLogsLeft')) { + $q->delete('func'); $q->param('func', 'showAuditLogs'); + } + elsif (&getParam(1, 0, 'showAuditLogsRight')) { + $q->delete('func'); $q->param('func', 'showAuditLogs'); + } + elsif (&getParam(1, 0, 'commitViewSettings')) { unless (&updSettings()) { $q->param('showViewSettings', 1); } &HaCi::GUI::init::setUserVars(); } - elsif ($q->param('searchAndGetFreeSubnets')) { + elsif (&getParam(1, 0, 'searchAndGetFreeSubnets')) { &searchAndGetFreeSubnets(); } + elsif (&getParam(1, 0, 'getFreeSubnets')) { + my $netID = &getParam(1, undef, 'netID'); + my $subnetSize = &getParam(1, undef, 'subnetSize'); + my $amount = &getParam(1, undef, 'amount'); + &getFreeSubnets($netID, 0, $subnetSize, $amount); + } + elsif (&getParam(1, 0, 'exportSubnets')) { + my $rootID = &getParam(1, undef, 'rootID'); + my $netID = &getParam(1, undef, 'netID'); + my $ID = (defined $rootID) ? $rootID : $netID; + &exportSubnets($ID, (defined $rootID) ? 1 : 0); + } - if (defined $q->param('func')) { - if ($q->param('func') eq 'addNet') { - my $roots = &getRoots(); + if (defined &getParam(1, 0, 'func')) { + if (&getParam(1, '', 'func') eq 'addNet') { + my $roots = &getRoots(0); if ($#{$roots} == -1) { &warnl("Cannot find any Root! Please create some before you create networks\n"); $q->delete('func'); $q->param('func', 'addRoot'); } } - elsif ($q->param('func') eq 'addNet' && $q->param('networkDec') && $q->param('rootID') && !($q->param('editNet'))) { - my $rootID = &getParam(1, undef, $q->param('rootID')); - my $networkDec = &getParam(1, undef, $q->param('networkDec')); + if (&getParam(1, '', 'func') eq 'addNet' && &getParam(1, 0, 'networkDec') && &getParam(1, 0, 'rootID') && !(&getParam(1, 0, 'editNet'))) { + my $rootID = &getParam(1, undef, 'rootID'); + my $networkDec = &getParam(1, undef, 'networkDec'); my $ipv6 = &rootID2ipv6($rootID); $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $parent = &getNetworkParentFromDB($rootID, $networkDec, $ipv6); @@ -611,8 +685,12 @@ $q->delete('func'); $q->param('func', 'showAllNets'); } } + + unless (&checkNetworkLock($rootID, $networkDec, $ipv6)) { + $q->delete('func'); $q->param('func', 'showAllNets'); + } } - elsif ($q->param('func') eq 'flushCache') { + elsif (&getParam(1, '', 'func') eq 'flushCache') { &flushACLCache(); &flushNetCache(); $q->delete('func'); $q->param('func', 'showAllNets'); @@ -620,9 +698,9 @@ } $HaCi::GUI::init::t->{V}->{jumpTo} = $session->param('currRootID') . '-' . $session->param('currNet') if $session->param('currRootID') && $session->param('currNet'); - &HaCi::GUI::main::start(); + &HaCi::GUI::main::start() unless $conf->{var}->{soap} || &getParam(1, 0, 'exportSubnet'); - if ($q->param('newWindow') && $q->param('newWindow') eq 'showStatus') { + if (&getParam(1, 0, 'newWindow') && &getParam(1, '', 'newWindow') eq 'showStatus') { $t->{V}->{page} = 'showStatus'; } else { $t->{V}->{page} = 'main'; @@ -631,36 +709,44 @@ sub expandTo { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $rootID = shift; - my $ipaddress = shift || ''; - my $ipv6 = &rootID2ipv6($rootID); - $ipaddress =~ s/[^\w\.\:]//g; + my $rootID = shift; + my $network = shift || ''; + my $ipv6 = &rootID2ipv6($rootID); + $network =~ s/[^\w\.\:\/]//g; - return 0 unless $ipaddress; + return 0 unless $network; - unless (&checkSpelling_IP($ipaddress, $ipv6)) { - warn "Cannot jump to. No IP Address: '$ipaddress'\n"; + unless (&checkSpelling_Net($network, $ipv6) || &checkSpelling_IP($network, $ipv6)) { + warn "Cannot jump to. No IP Address / network: '$network'\n"; return 0; } - my $networkDec = ($ipv6) ? &netv62Dec($ipaddress . '/128') : &net2dec($ipaddress . '/32'); + $network .= ($ipv6) ? '/128' : '/32' unless $network =~ /\/\d+$/; + my $networkDec = ($ipv6) ? &netv62Dec($network) : &net2dec($network); my $s = $HaCi::HaCi::session; my $expands = $s->param('expands') || {}; - my $networkTable = $conf->{var}->{TABLES}->{network}; unless (defined $networkTable) { warn "Cannot jump to network. DB Error\n"; return 0; } - my $bestMatch = 0; + my $ipv6ID = ($ipv6) ? &netv6Dec2ipv6ID($networkDec) : ''; + my $netID = &getNetID($rootID, $networkDec, $ipv6ID); + my $bestMatch = (defined $netID) ? $networkDec : 0; + unless ($bestMatch) { + $networkDec = &getDBNetworkBefore($rootID, $networkDec, $ipv6); + $netID = &getNetID($rootID, $networkDec, $ipv6ID); + $bestMatch = (defined $netID) ? $networkDec : 0; + } + while (my $parent = &getNetworkParentFromDB($rootID, $networkDec, $ipv6)) { my $parentDec = $parent->{network}; &expand('+', 'network', $parentDec, $rootID) unless $expands->{network}->{$rootID}->{$parentDec}; $bestMatch = $parentDec unless $bestMatch; $networkDec = $parentDec; } - + if ($bestMatch) { &expand('+', 'root', $rootID); $session->param('jumpTo', 1); @@ -693,6 +779,38 @@ }; } +sub getSession { + my $sessID = shift; + + eval { + $session = CGI::Session->load($sessID); + }; + if ($@ || !defined $session) { + warn $@ . ' ' . CGI::Session->errstr; + $conf->{var}->{authenticationError} = _gettext("Session is broken"); + $conf->{var}->{relogin} = 1; + #Do not return 0 if sessID is undef, but force to gen new session, so that an API call didn't fail + return 0 if defined $sessID && $sessID; + } + + if ( defined $session && $session->is_expired ) { + $conf->{var}->{authenticationError} = _gettext("Session is expired"); + $conf->{var}->{relogin} = 1; + return 0; + } + if ( !defined $session || $session->is_empty ) { + if (defined $session) { + &debug("Session " . $session->id() . " is empty. Generating new..."); + } else { + &debug("Session cannot be loaded! Generating new..."); + } + &genNewSession(); + } + $session->expire($conf->{static}->{misc}->{sessiontimeout}); + + return $session; +} + sub init { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; $q = CGI->new(\&hook, $ENV{CONTENT_LENGTH}); @@ -707,27 +825,9 @@ $pjx->DEBUG(0); my %cookies = fetch CGI::Cookie; - my $sid = &getParam(1, undef, $q->param('sid')); my $sessID = (exists $cookies{CGISESSID}) ? $cookies{CGISESSID}->value : undef; - eval { - $session = CGI::Session->load($sessID) or die CGI::Session->errstr; - }; - if ($@) { - warn $@; - $conf->{var}->{authenticationError} = _gettext("Session is broken"); - $conf->{var}->{relogin} = 1; - return; - } - if ( $session->is_expired ) { - $conf->{var}->{authenticationError} = _gettext("Session is expired"); - $conf->{var}->{relogin} = 1; - } - my @params = $q->param; - if ( $session->is_empty && $#params != -1) { - $session = $session->new($sid); - } - $session->expire($conf->{static}->{misc}->{sessiontimeout}); + return unless &getSession($sessID); ($aclCacheHandle, $netCacheHandle) = &initCache(); if (defined $netCacheHandle) { @@ -743,10 +843,10 @@ &initTables(); - if ($q->param('locale')) { - $session->param('locale', $q->param('locale')); + if (&getParam(1, 0, 'locale')) { + $session->param('locale', &getParam(1, '', 'locale')); } - $q->delete('jumpTo') if defined $q->param('jumpTo') && $q->param('jumpTo') eq ''; + $q->delete('jumpTo') if &getParam(1, 0, 'jumpTo') && &getParam(1, '', 'jumpTo') eq ''; } sub soapInit { @@ -761,63 +861,70 @@ sub genNewSession { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $sid = &getParam(1, undef, $q->param('sid')); - $session = CGI::Session->new($sid) or die CGI::Session->errstr; + $session = CGI::Session->new() or die CGI::Session->errstr; $session->expire($conf->{static}->{misc}->{sessiontimeout}); - if ($q->param('locale')) { - $session->param('locale', $q->param('locale')); + if (ref($q) && &getParam(1, 0, 'locale')) { + $session->param('locale', &getParam(1, '', 'locale')); } } sub authentication { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - use HaCi::Authentication::internal; - my $authAdmin = new HaCi::Authentication::internal; - $authAdmin->session($session); - $authAdmin->init(); - - my $auth; - if (($q->param('login') && $q->param('username') eq 'admin') || ($session->param('username') && $session->param('username') eq 'admin') ) { - $auth = $authAdmin; - } else { - my $temp = (exists $conf->{user}->{auth}->{authmodule} && $conf->{user}->{auth}->{authmodule}) ? $conf->{user}->{auth}->{authmodule} : 'internal'; - $temp = 'internal' if $temp eq 'HaCi'; # fix to be backward compatible - my $authModule = "HaCi::Authentication::$temp"; - my $authModuleFile = $conf->{static}->{path}->{authmodules} . '/' . $temp . '.pm'; - eval { - require $authModuleFile; - }; - if ($@) { - $conf->{var}->{authenticationError} = _gettext("Authentication Error"); - &warnl($@); - return 0; - } - $auth = $authModule->new(); - } - $auth->session($session); - - if ($q->param('login')) { - my $user = &getParam(1, undef, $q->param('username')); - my $pass = &getParam(1, undef, $q->param('password')); + my $user = shift; + my $pass = shift; + my $bLogin = shift; + my $sessionUser = shift; + + if ($bLogin) { unless (defined $user) { $conf->{var}->{authenticationError} = _gettext("No User given"); return 0; } - - $auth->user($user); - $auth->pass($pass); - - if ($auth->authenticate()) { - $conf->{var}->{authenticated} = 1; - &updateSettingsInSession(); - return 1; - } else { - return 0; + + my @authModules = (($bLogin && $user eq 'admin') || ($sessionUser eq 'admin')) + ? 'internal' + : (exists $conf->{user}->{auth}->{authmodule} && $conf->{user}->{auth}->{authmodule} ne '') ? split(/\s*,\s*/, $conf->{user}->{auth}->{authmodule}) : ('internal'); + + my $authErrors = []; + foreach (@authModules) { + my $authModule = $_; + $authModule = 'internal' if $authModule eq 'HaCi'; # fix to be backward compatible + + my $authModuleFile = $conf->{static}->{path}->{authmodules} . '/' . $authModule . '.pm'; + eval { + require $authModuleFile; + }; + if ($@) { + $conf->{var}->{authenticationError} = _gettext("Authentication Error"); + &warnl($@); + return 0; + } + + my $auth = "HaCi::Authentication::$authModule"->new(); + $auth->session($session); + $auth->init() if $authModule eq 'internal'; + + $auth->user($user); + $auth->pass($pass); + + if ($auth->authenticate()) { + $conf->{var}->{authenticated} = 1; + &updateSettingsInSession(); + &debug("Successfully authenticated by '$authModule'") if 1; + return 1; + } else { + push @{$authErrors}, $conf->{var}->{authenticationError}; + $conf->{var}->{authenticationError} = ''; + &debug("Not authenticated by '$authModule'") if 1; + } } + + $conf->{var}->{authenticationError} = join('
', @{$authErrors}); + return 0; } else { - if ($auth->isAutenticated()) { + if (defined $session->param('authenticated') && $session->param('authenticated')) { &debug("Allready authenticated") if 0; $conf->{var}->{authenticated} = 1; return 1; @@ -831,10 +938,19 @@ sub finalize { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $template = $HaCi::GUI::init::t; - my $cookie = $q->cookie( - -name => $session->name, - -value => $session->id - ); + my $cookie; + if (defined $session) { + $cookie = $q->cookie( + -name => $session->name, + -value => $session->id + ); + } else { + &debug("No session available while finalizing. Setting session-id to 0"); + $cookie = $q->cookie( + -name => 'CGISESSID', + -value => 0 + ); + } unless ($conf->{var}->{soap}) { my $html_output = ''; @@ -859,11 +975,12 @@ } print $q->Dump() if 0; - if (0) { map { warn " $_ -> " . $q->param($_); } $q->param; } # Dump + if (0) { map { warn " $_ -> " . &getParam(1, '', $_); } $q->param; } # Dump print '' if $conf->{var}->{reloadPage}; print '' if $conf->{var}->{closePage}; } + undef $HaCi::HaCi::q; # Cache Statistics if (0) { @@ -882,10 +999,12 @@ warn "Cannot set Cache (aclCache!)\n" unless $aclCacheHandle->set('HASH', $aclCache); } - $session->clear('jumpTo'); - $session->clear('jumpToNet'); - $session->clear('jumpToRoot'); - $session->flush(); + if (defined $session) { + $session->clear('jumpTo'); + $session->clear('jumpToNet'); + $session->clear('jumpToRoot'); + $session->flush(); + } &warnl($conf->{var}->{authenticationError}) if $conf->{var}->{authenticationError} && $conf->{var}->{soap}; return &prWarnl(1) if $conf->{var}->{soap}; @@ -973,6 +1092,12 @@ /^compare$/ ) && !&checkRight('search') || ( + /^getFreeSubnetsFromSearch$/ + ) && (!&checkRight('search') || !&checkRight('addNet')) || + ( + /^getFreeSubnets$/ + ) && (!&checkRight('search')) || + ( /^submitImportASNRoutes$/ ) && !&checkRight('impASNRoutes') || ( @@ -986,7 +1111,13 @@ /^submitImpConfig$/ || /^impCSVChangeSep$/ || /^submitImpCSV$/ - ) && !&checkRight('impConfig') + ) && !&checkRight('impConfig') || + ( + /^showAditLogs$/ || + /^showAditLogsLeft$/ || + /^showAditLogsRight$/ || + /^commitShowAuditLogs$/ + ) && !&checkRight('showAuditLogs') } } @@ -999,6 +1130,23 @@ $q->delete($param); } +sub checkIfExistsInDB { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $table = shift; + my $col = shift; + my $val = shift; + + my $table = $conf->{var}->{TABLES}->{$table}; + unless (defined $table) { + &warn("Cannot check. DB Error ($table)"); + return 1; + } + my $DB = ($table->search(['ID'], {$col => $val}))[0]; + + return (defined $DB) ? 1 : 0; +} + 1; # vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Mathematics.pm haci-0.98c/modules/HaCi/Mathematics.pm --- haci-0.97c/modules/HaCi/Mathematics.pm 2010-06-22 16:59:38.000000000 +0000 +++ haci-0.98c/modules/HaCi/Mathematics.pm 2014-08-28 22:12:24.000000000 +0000 @@ -12,7 +12,7 @@ getCidrFromNetmask getNetmaskFromCidr getCidrFrom2IPs netv6Dec2net getV6BroadcastIP netv6Dec2ip ipv62Dec2 ipv6Dec2ip getV6BroadcastNet netv6Dec2NextNetDec ipv6DecCidr2netv6Dec netv62Dec ipv6DecCidr2NetaddressV6Dec - getCidrFromNetv6Dec getCidrFromDec + getCidrFromNetv6Dec getCidrFromDec ipv6Sort ); our $conf; *conf = \$HaCi::Conf::conf; @@ -420,7 +420,7 @@ my $netv6Dect = shift; unless (ref $netv6Dect) { - warn "Calling 'netv6Dec2net' without Math::Bigint Reference!\n"; + warn "Calling 'netv6Dec2net' without Math::Bigint Reference! (" . (caller(0))[0] . '->' . (caller(0))[2] . ")\n"; return 0; } @@ -485,6 +485,11 @@ return $ipv6Dec; } +sub ipv6Sort { + # Because sorting with Math::BigInt objects is too expensive, we use a trick to sort those big numbers numerically with strings + sort {substr('0'x 44 .$a, -44) cmp substr('0'x 44 .$b, -44)} @_; +} + 1; # vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Plugins/CrossRootNetTrace.pm haci-0.98c/modules/HaCi/Plugins/CrossRootNetTrace.pm --- haci-0.97c/modules/HaCi/Plugins/CrossRootNetTrace.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Plugins/CrossRootNetTrace.pm 2015-02-15 16:47:29.000000000 +0000 @@ -0,0 +1,306 @@ +package HaCi::Plugins::CrossRootNetTrace; + +# Cross root tracing plugin for HaCi +# +# Based on code written by +# Andreas Lewitzki +# Pär Karlsson + +use strict; +use warnings; +use base qw/HaCi::Plugin/; + +use HaCi::Mathematics qw(dec2net net2dec netv6Dec2net ipv62dec); +use HaCi::Utils qw(getNetworkParentFromDB getNetworkChilds getMaintInfosFromNet getTemplateData rootID2Name); +use HaCi::GUI::gettext qw(_gettext); + +use Carp; +use Encode; +use English qw(-no_match_vars); +use Net::DNS; +use Data::Dumper; + +our $conf; +*conf = \$HaCi::Conf::conf; +our $session; +*session = \$HaCi::HaCi::session; +our $INFO = { + name => 'CrossRootNetTrace', + version => '3.0', + onDemand => 1, + description => _gettext('This plugin tracks overlaying networks across all roots'), + menuOnDemand => [ + { + NAME => 'dnsResolver', + DESCR => _gettext('Special DNS Resolver for this network'), + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => '8.8.8.8,8.8.4.4' + }, + ], + globMenuOnDemand => [ + { + NAME => 'dnsResolver', + DESCR => _gettext('DNS Resolver'), + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => '8.8.8.8,8.8.4.4' + }, + ] +}; + +my $RE_IPV4_NETWORK = qr{ (?:\d+[.]){3}\d+\/\d+ }msx; +my $RE_IPV6_NETWORK = qr{ (?:\w+[:])+\w+\/\d+ }msx; +my $RE_NETWORK = qr{ \A (?: $RE_IPV4_NETWORK|$RE_IPV6_NETWORK) \z }imsx; + +sub makeKeyVal { + my $self = shift; + my $key = shift; + my $val = shift, + my $url = shift; + $key = encode( 'latin1', decode( 'utf8', $key ) ); + + return { + elements => [ + { + colspan => 2, + target => 'key', + type => 'label', + value => $url ? "" . _gettext($key) . '' : _gettext($key) + }, + { + target => 'value', + type => 'label', + color => '#0000ff', + value => $url ? "" . $val . '' : _gettext($val) + }, + ] + }; +} + +sub ipSort { + if ( $a =~ $RE_NETWORK && $b =~ $RE_NETWORK ) { + my ( $a_ip, $a_cidr ) = split m{/}msx, $a; + my ( $b_ip, $b_cidr ) = split m{/}msx, $b; + my ( $a_addr, $b_addr ); + if ( $a =~ $RE_IPV4_NETWORK && $b =~ $RE_IPV4_NETWORK ) { + $a_addr = net2dec($a); + $b_addr = net2dec($b); + } + elsif ( $a =~ $RE_IPV6_NETWORK && $b =~ $RE_IPV6_NETWORK ) { + $a_addr = ipv62dec($a_ip); + $b_addr = ipv62dec($b_ip); + } + else { + carp "Cannot compare mixed IPv4 and IPv6 addresses: $a <=> $b"; + return -1; + } + if ( $a_addr > $b_addr ) { + return 1; + } + if ( $a_addr == $b_addr ) { + if ( $a_cidr > $b_cidr ) { + return 1; + } + else { + return -1; + } + } + } + return -1; +} + +sub run_onDemand { + my $self = shift; + my $networkRef = shift; + my $config = shift; + + my $netID = $networkRef->{ID}; + my $networkDec = $networkRef->{network}; + my $ipv6 = $networkRef->{ipv6}; + my $network = ($ipv6) ? netv6Dec2net($networkDec) : dec2net($networkDec); + $self->{networkRef} = $networkRef; + $self->{inetnum} = $network; + $self->{username} = $session->param('username'); + + if ( $network !~ $RE_NETWORK ) { + $self->warnl("'$network' does not look like a network!"); + return; + } + + my $supernets = &getNetworkParentFromDB(-1, $networkDec, $ipv6, 0); + my @subnets = &getNetworkChilds($netID, 0, 1, 1); + + if (ref($supernets) eq 'ARRAY' && $#{$supernets} > -1) { + foreach (@{$supernets}) { + my $sNetRef = $_; + my $sNetID = $sNetRef->{ID}; + my $sNetDec = $sNetRef->{network}; + my $sNetInfo = &getMaintInfosFromNet($sNetID); + my $sNetIPv6 = $sNetInfo->{ipv6}; + my $sNet = ($sNetIPv6) ? netv6Dec2net($sNetDec) : dec2net($sNetDec); + + if (0) { # do we need template data for output? + my $templateData = &getTemplateData($sNetID, $sNetInfo->{tmplID}, 1); + $sNetInfo->{tmplData} = $templateData; + } + + push @{$self->{data}->{up}->{$sNet}}, $sNetInfo; + } + } + + if ($#subnets > -1) { + foreach (@subnets) { + my $sNetRef = $_; + my $sNetID = $sNetRef->{ID}; + my $sNetDec = $sNetRef->{network}; + my $sNetInfo = &getMaintInfosFromNet($sNetID); + my $sNetIPv6 = $sNetInfo->{ipv6}; + my $sNet = ($sNetIPv6) ? netv6Dec2net($sNetDec) : dec2net($sNetDec); + my $cidr = $sNetDec % 256; + + if (0) { # do we need template data for output? + my $templateData = &getTemplateData($sNetID, $sNetInfo->{tmplID}, 1); + $sNetInfo->{tmplData} = $templateData; + } + + push @{$self->{data}->{cidr}->{$cidr}->{$sNet}}, $sNetInfo; + push @{$self->{data}->{down}->{$sNet}}, $sNetInfo; + } + } + + if (($network =~ /\/32$/ || $network =~ /\/128$/) && exists $config->{dnsResolver} && $config->{dnsResolver}) { + my $resolver = Net::DNS::Resolver->new(nameservers => [split(/\s*,\s*/, $config->{dnsResolver})]); + my $ip = (split(/\//, $network, 2))[0]; + my $reply = $resolver->query($ip, 'PTR'); + my $hostname = ''; + if ($reply) { + foreach ($reply->answer()) { + my $rr = $_; + next unless $rr->type() eq 'PTR'; + $hostname = $rr->ptrdname(); + } + } + if ($hostname) { + push @{$self->{data}->{down}->{$network}}, { + rootID => -2, + description => $hostname + }; + } + } + + return 1; +} + +sub show { + my $self = shift; + my $show = + { HEADER => + sprintf( _gettext("Cross Root Net Trace for %s"), $self->{inetnum} ), + }; + my $ipnet = $self->{inetnum}; + my $result = $self->{data}; + my @sorted = sort { ipSort($_) } keys %{ $result->{up} }; + for my $net (@sorted) { + my $ndata = $self->{data}->{up}->{$net}; + my ( $ipaddress, $cidr ) = split m{/}msx, $net; + push @{ $show->{BODY} }, + { + elements => [ + { + align => 'center', + colspan => 3, + target => 'value', + type => 'vline', + }, + ] + }; + push @{ $show->{BODY} }, + { + elements => [ + { + bold => 1, + underline => 1, + align => 'center', + colspan => 3, + color => ( $net eq $ipnet ? 'blue' : 'black' ), + target => 'value', + type => 'label', + value => _gettext( ( $net eq $ipnet ? ">> $net <<" : $net ) ) + } + ] + }; + for my $data ( sort { $a->{rootID} cmp $b->{rootID} } @{$ndata} ) { + my $rootID = $data->{rootID}; + my $rootName = ($rootID == -2) ? 'DNS' : &rootID2Name($rootID); + push @{ $show->{BODY} }, + $self->makeKeyVal( $rootName, $data->{description}, + "?jumpToButton=1&rootIDJump=$rootID&jumpTo=$ipaddress" ); + } + } + + @sorted = sort { ipSort($_) } keys %{ $result->{down} }; + for my $cidr ( sort { $a <=> $b } keys %{ $result->{cidr} } ) { + if ( scalar keys %{ $result->{cidr}->{$cidr} } == 1 ) { + my $net = [ keys %{ $result->{cidr}->{$cidr} } ]->[0]; + my $ndata = $result->{down}->{$net}; + my ( $ipaddress, $cidr ) = split m{/}msx, $net; + push @{ $show->{BODY} }, + { + elements => [ + { + bold => 1, + underline => 1, + align => 'center', + colspan => 3, + target => 'value', + type => 'label', + color => ( $net eq $ipnet ? 'blue' : 'black' ), + value => _gettext( ( $net eq $ipnet ? ">> $net <<" : $net ) ) + } + ] + }; + for my $data ( sort { $a->{rootID} cmp $b->{rootID} } @{$ndata} ) { + my $rootID = $data->{rootID}; + my $rootName = ($rootID == -2) ? 'DNS' : &rootID2Name($rootID); + push @{ $show->{BODY} }, + $self->makeKeyVal( $rootName, $data->{description}, + "?jumpToButton=1&rootIDJump=$rootID&jumpTo=$ipaddress" ); + } + } + else { + my $netCount = {}; + for my $net ( keys %{ $result->{cidr}->{$cidr} } ) { + for my $d ( @{ $result->{cidr}->{$cidr}->{$net} } ) { + my $rootID = $d->{rootID}; + my $root = &rootID2Name($rootID); + $netCount->{$root}++; + } + } + push @{ $show->{BODY} }, + { + elements => [ + { + bold => 1, + underline => 1, + align => 'center', + colspan => 3, + target => 'value', + type => 'label', + value => _gettext("/$cidr") + } + ] + }; + for my $root ( keys %{$netCount} ) { + push @{ $show->{BODY} }, + $self->makeKeyVal( $root, $netCount->{$root} ); + } + } + } + + return $show; +} + +1; diff -Nru haci-0.97c/modules/HaCi/Plugins/DNSInfoForNetworks.pm haci-0.98c/modules/HaCi/Plugins/DNSInfoForNetworks.pm --- haci-0.97c/modules/HaCi/Plugins/DNSInfoForNetworks.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/Plugins/DNSInfoForNetworks.pm 2014-08-28 22:12:24.000000000 +0000 @@ -41,10 +41,13 @@ my $origin = $_->{origin}; my $ipv6 = (exists $_->{ipv6} && $_->{ipv6}) ? 1 : 0; my $networkDec = $_->{network}; + my $descr = $_->{description}; my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); my $ip = (split(/\//, $network, 2))[0]; $self->saveValue($netID, $origin, 'NAME', $network); + $self->saveValue($netID, $origin, 'DESCR', $descr); + $self->saveValue($netID, $origin, 'ID', $networkDec); $self->saveValue(-1, $origin, 'lastUpdated', scalar localtime) unless exists $lastUpdatedCheck->{$origin}; my $ptr = ''; @@ -74,9 +77,20 @@ ] }; + my $unsorted = {}; foreach (sort {$a<=>$b} keys %{$values}) { my $netID = $_; + my $id = $values->{$netID}->{ID}; + $unsorted->{$id} = $netID; + } + + my @sorted = sort {$a<=>$b} keys %{$unsorted}; + + foreach (@sorted) { + my $id = $_; + my $netID = $unsorted->{$id}; my $name = $values->{$netID}->{NAME} || ''; + my $descr = $values->{$netID}->{DESCR} || ''; my $ptr = $values->{$netID}->{PTR} || ''; push @{$show->{BODY}}, ( @@ -85,7 +99,7 @@ { target => 'key', type => 'label', - value => $name, + value => $name . ' (' . $descr . ')', }, { target => 'value', diff -Nru haci-0.97c/modules/HaCi/Plugins/GenZonefile.pm haci-0.98c/modules/HaCi/Plugins/GenZonefile.pm --- haci-0.97c/modules/HaCi/Plugins/GenZonefile.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Plugins/GenZonefile.pm 2011-07-11 18:16:25.000000000 +0000 @@ -0,0 +1,350 @@ +package HaCi::Plugins::GenZonefile; + +use strict; +use warnings; + +use base qw/HaCi::Plugin/; +use HaCi::Mathematics qw/dec2net netv6Dec2net/; +use HaCi::Utils qw/netID2Stuff getNetworkChilds getMaintInfosFromNet/; +use HaCi::GUI::gettext qw/_gettext/; +use Net::Ping; + +our $conf; *conf = \$HaCi::Conf::conf; + +our $INFO = { + name => 'GenZonefile', + version => '0.1', + recurrent => 1, + onDemand => 1, + description => _gettext('This Plugin generates a zonefile which contains all ip addresses of this network.'), + api => [ + { + name => 'STATUS', + descr => _gettext('Generated zonefile'), + }, + ], + menuOnDemand => [ + { + NAME => 'origin', + DESCR => 'Origin', + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => 'example.com' + }, + { + NAME => 'primaryns', + DESCR => 'Primary Nameserver', + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => 'ns1.example.com' + }, + { + NAME => 'secondaryns', + DESCR => 'Secondary Nameserver', + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => 'ns2.example.com' + }, + { + NAME => 'primarymx', + DESCR => 'Primary Mailexchanger with priority', + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => '10 mx1.example.com' + }, + { + NAME => 'secondarymx', + DESCR => 'Secondary Mailexchanger with priority', + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => '20 mx2.example.com' + }, + { + NAME => 'mailaddress', + DESCR => 'Email address', + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 128, + VALUE => 'hostmaster.example.com' + }, + { + NAME => 'ttl', + DESCR => 'Default TTL', + TYPE => 'textbox', + SIZE => 4, + MAXLENGTH => 10, + VALUE => '3600' + }, + { + NAME => 'refresh', + DESCR => 'Refresh', + TYPE => 'textbox', + SIZE => 5, + MAXLENGTH => 10, + VALUE => '86400' + }, + { + NAME => 'retry', + DESCR => 'Retry', + TYPE => 'textbox', + SIZE => 4, + MAXLENGTH => 10, + VALUE => '7200' + }, + { + NAME => 'expire', + DESCR => 'Expire', + TYPE => 'textbox', + SIZE => 7, + MAXLENGTH => 10, + VALUE => '3600000' + }, + { + NAME => 'minimum', + DESCR => 'Minimum', + TYPE => 'textbox', + SIZE => 6, + MAXLENGTH => 10, + VALUE => '172800' + }, + { + NAME => 'arr', + DESCR => 'A-RR', + TYPE => 'checkbox', + CHECKED => '1' + }, + { + NAME => 'ptrrr', + DESCR => 'PTR-RR', + TYPE => 'checkbox', + CHECKED => '0' + }, + ], + globMenuRecurrent => [ + { + NAME => 'targetDir', + DESCR => 'Target directory', + TYPE => 'textbox', + SIZE => 25, + MAXLENGTH => 255, + VALUE => $conf->{static}->{path}->{workdir} . '/spool/GenZonefile' + }, + ] +}; + +sub run_onDemand { + my $self = shift; + my $networkRef = shift; + my $confValues = shift; + + my $networkDec = $networkRef->{network}; + my $ipv6 = ($networkRef->{ipv6ID}) ? 1 : 0; + my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); + my $zonefiles = $self->genZonefile($networkRef, $confValues); + + my $zonefile = ''; + my $origins = ''; + foreach (@{$zonefiles}) { + my $origin = $_->{ORIGIN}; + my $content = $_->{ZONEFILE}; + + $zonefile .= "\n" . ' ' x 80 . "\n" if $zonefile ne ''; + $origins .= ' and ' if $origins ne ''; + $zonefile .= $content; + $origins .= $origin; + } + + $self->{zonefile} = $zonefile; + $self->{origin} = $origins; + $self->{network} = $network; + + return 1; +} + +sub run_recurrent { + my $self = shift; + my $networks = shift; + my $config = shift; + + my $destDir = $config->{-1}->{targetDir}; + + unless (-d $destDir || mkdir $destDir) { + $self->warnl("Cannot create Directory '$destDir': $!", 1); + }; + + foreach (@$networks) { + my $netID = $_->{ID}; + my $zonefiles = $self->genZonefile($_, $config->{$netID}, 1); + + foreach (@{$zonefiles}) { + my $origin = $_->{ORIGIN}; + my $content = $_->{ZONEFILE}; + my $zoneFile = $destDir . '/' . $origin; + + unless (open ZONE, '>' . $zoneFile) { + $self->warnl("Cannot open Zonefile '$zoneFile' for writing: $!", 1); + } + print ZONE $content; + close ZONE; + } + } +} + +sub genZonefile { + my $self = shift; + my $networkRef = shift; + my $confValues = shift; + my $recurrent = shift || 0; + + my $networkDec = $networkRef->{network}; + my $netID = $networkRef->{ID}; + my $ipv6ID = $networkRef->{ipv6ID}; + + my $origin = $confValues->{origin} || 'example.com'; + my $primNS = $confValues->{primaryns} || 'ns1.example.com'; + my $secNS = $confValues->{secondaryns} || 'ns2.example.com'; + my $primMX = $confValues->{primarymx} || '10 mx1.example.com'; + my $secMX = $confValues->{secondarymx} || '20 mx2.example.com'; + my $mail = $confValues->{mailaddress} || 'hostmaster.example.com'; + my $ttl = $confValues->{ttl} || '3600'; + my $refresh = $confValues->{refresh} || '86400'; + my $retry = $confValues->{retry} || '7200'; + my $expire = $confValues->{expire} || '3600000'; + my $minimum = $confValues->{minimum} || '172800'; + my $arr = $confValues->{arr}; + my $ptrrr = $confValues->{ptrrr}; + my $ipv6 = ($ipv6ID) ? 1 : 0; + my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); + my @networks = &getNetworkChilds($netID); + my @time = localtime(); + my $serial = sprintf("%04i%02i%02i%02i", $time[5] + 1900, $time[4] + 1, $time[3], 1); + my ($ip, $cidr) = split(/\//, $network, 2); + my $zonefiles = []; + + my $zonefileA = qq{ +\$TTL 3600 +$origin.\tIN SOA $primNS. $mail. ( +\t$serial ; serial +\t$refresh ; refresh +\t$retry ; retry +\t$expire ; expire +\t$minimum ; minimum +\t) +; +\tIN NS $primNS. +\tIN NS $secNS. +; +\tIN MX $primMX. +\tIN MX $secMX. +; +}; + + my $nets = (); + foreach (@networks) { + $nets->{$_->{network}} = $_; + } + + my @as = (); + my @ptrs = (); + foreach (sort {$a<=>$b} keys %{$nets}) { + my $net = $nets->{$_}; + my $netID = $net->{ID}; + my $networkDec = $net->{network}; + my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); + my ($ip, $cidr) = split(/\//, $network, 2); + next if ($ipv6 && $cidr != 128) || (!$ipv6 && $cidr != 32); + + my $netInfos = &getMaintInfosFromNet($netID); + my $descr = $netInfos->{description}; + $descr =~ s/\s/_/g; + $descr =~ s/\W//g; + $descr =~ s/_/-/g; + $descr =~ s/$origin$//; + + push @as, "$descr\tIN " . (($ipv6) ? 'AAAA' : 'A') . " $ip\n" if $arr; + $ip =~ s/.*[\.:](\w+)/$1/; + $ip = join('.', reverse split//, $ip) if $ipv6; + push @ptrs, "$ip\tIN PTR $descr.$origin.\n" + } + + $zonefileA .= join('', @as); + push @{$zonefiles}, { + ORIGIN => $origin, + ZONEFILE => $zonefileA + }; + + my $originPTR = ''; + if ($ptrrr) { + if ($cidr == (($ipv6) ? 112 : 24)) { + $ip =~ s/[\.:]\w+$//; + $ip =~ s/://g; + my $ipRef = join('.', reverse (($ipv6) ? split//, $ip : split/\./, $ip)); + $originPTR = $ipRef . '.' . (($ipv6) ? 'ip6' : 'in-addr') . '.arpa'; + + my $zonefilePTR .= qq{ +\$TTL 3600 +$originPTR.\tIN SOA $primNS. $mail. ( +\t$serial ; serial +\t$refresh ; refresh +\t$retry ; retry +\t$expire ; expire +\t$minimum ; minimum +\t) +; +\tIN NS $primNS. +\tIN NS $secNS. +; +\tIN MX $primMX. +\tIN MX $secMX. +; +}; + $zonefilePTR .= join('', @ptrs); + push @{$zonefiles}, { + ORIGIN => $originPTR, + ZONEFILE => $zonefilePTR + }; + } else { + if ($recurrent) { + $self->warnl("Reverse zonefile can only be generated for /24 (IPv4) and /112 (IPv6) networks! ($network)\n", 2); + } else { + push @{$zonefiles}, { + ORIGIN => $originPTR, + ZONEFILE => "Reverse zonefile can only be generated for /24 (IPv4) and /112 (IPv6) networks!" + }; + } + } + } + + my @origins = (); + push @origins, $origin if $arr; + push @origins, $originPTR if $ptrrr && $cidr == (($ipv6) ? 112 : 24); + + return $zonefiles; +} + +sub show { + my $self = shift; + my $show = { + HEADER => sprintf("Generated zonefile for '%s'", $self->{origin}), + BODY => [ + { + elements => [ + { + target => 'single', + type => 'label', + value => '
' . $self->{zonefile} . '
' + }, + ] + }, + ] + }; + + return $show; +} + +1; diff -Nru haci-0.97c/modules/HaCi/Plugins/PingInfo.pm haci-0.98c/modules/HaCi/Plugins/PingInfo.pm --- haci-0.97c/modules/HaCi/Plugins/PingInfo.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/Plugins/PingInfo.pm 2012-07-15 00:56:51.000000000 +0000 @@ -3,7 +3,9 @@ use strict; use warnings; -use HaCi::Mathematics qw/dec2net/; +use base qw/HaCi::Plugin/; + +use HaCi::Mathematics qw/dec2net netv6Dec2net/; use HaCi::GUI::gettext qw/_gettext/; require Exporter; diff -Nru haci-0.97c/modules/HaCi/Plugins/PingNetworks.pm haci-0.98c/modules/HaCi/Plugins/PingNetworks.pm --- haci-0.97c/modules/HaCi/Plugins/PingNetworks.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/Plugins/PingNetworks.pm 2014-08-28 22:12:24.000000000 +0000 @@ -86,6 +86,7 @@ my $ip = (split(/\//, $network, 2))[0]; $self->saveValue($netID, $origin, 'NAME', $network); + $self->saveValue($netID, $origin, 'ID', $networkDec); $self->saveValue(-1, $origin, 'lastUpdated', scalar localtime) unless exists $lastUpdatedCheck->{$origin}; eval { if ($p->ping($ip)) { @@ -115,8 +116,18 @@ ] }; + my $unsorted = {}; foreach (sort {$a<=>$b} keys %{$values}) { my $netID = $_; + my $id = $values->{$netID}->{ID}; + $unsorted->{$id} = $netID; + } + + my @sorted = sort {$a<=>$b} keys %{$unsorted}; + + foreach (@sorted) { + my $id = $_; + my $netID = $unsorted->{$id}; my $name = $values->{$netID}->{NAME}; my $status = $values->{$netID}->{STATUS}; diff -Nru haci-0.97c/modules/HaCi/Plugins/SearchAgent.pm haci-0.98c/modules/HaCi/Plugins/SearchAgent.pm --- haci-0.97c/modules/HaCi/Plugins/SearchAgent.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/Plugins/SearchAgent.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -package HaCi::Plugins::SearchAgent; - -use strict; -use warnings; - -use base qw/HaCi::Plugin/; -use HaCi::Mathematics qw/dec2net netv6Dec2net/; -use HaCi::Utils qw/netID2Stuff/; -use HaCi::GUI::gettext qw/_gettext/; - -our $INFO = { - name => 'Search Agent', - version => '0.1', - recurrent => 1, - onDemand => 0, - description => _gettext('This Plugin fills the Search-Database'), - globMenuRecurrent => [], - globMenuOnDemand => [], - menuRecurrent => [], - menuOnDemand => [], -}; - -sub run_recurrent { - my $self = shift; - my $networks = shift; - my $config = shift; - - warn "SearchAgent: I'm running...\n"; - - return 1; -} - -sub show { - my $self = shift; - my $netID = shift; - my $values = $self->getValues($netID); - my $results = {}; - my $lastUpdated = $self->getValue(-1, 'lastUpdated'); - - my $show = { - HEADER => "TEMPLATE", - BODY => [ - { - elements => [ - { - target => 'single', - type => 'label', - value => 'TEMPLATE', - }, - ] - }, - ] - }; - - return $show; -} - -1; diff -Nru haci-0.97c/modules/HaCi/Plugins/WhoisInfo.pm haci-0.98c/modules/HaCi/Plugins/WhoisInfo.pm --- haci-0.97c/modules/HaCi/Plugins/WhoisInfo.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/Plugins/WhoisInfo.pm 2012-02-06 23:01:09.000000000 +0000 @@ -39,6 +39,8 @@ last if $self->{inetnum} && /^\s*$/; } + $self->{inetnum} ||= $network; + return 1; } diff -Nru haci-0.97c/modules/HaCi/RESTWrapper.pm haci-0.98c/modules/HaCi/RESTWrapper.pm --- haci-0.97c/modules/HaCi/RESTWrapper.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/RESTWrapper.pm 2015-02-15 16:47:28.000000000 +0000 @@ -0,0 +1,133 @@ +package HaCi::RESTWrapper; + +# REST wrapper for HaCi XML-RPC-API +# +# The methods and parameters are equal to the XML-RPC-API +# +# Authentication: +# * via HTTP basic authentication +# * via username and password parameter +# +# USAGE: +# * http(s)://$hostname/RESTWrapper/[API-METHOD]?username=&password=&[API-PARAMETER] +# * http(s)://@\@$hostname/RESTWrapper/[API-METHOD]?[API-PARAMETER] +# +# Examples: +# * http(s)://foo:bar\@$hostname/RESTWrapper/search?search=test?rootName=bigRoot +# * http(s)://$hostname/RESTWrapper/getFreeSubnets?username=foo&password=bar&rootName=bigRoot&supernet=192.168.0.0%2f24&cidr=32&amount=3\n"; +# +# Return: JSON-Object + +use strict; +use warnings; + +use Data::Dumper; +use Apache2::RequestRec (); +use Apache2::RequestIO (); +use Apache2::Access (); +use Apache2::Const -compile => qw(OK SERVER_ERROR HTTP_BAD_REQUEST); +use JSON (); +use URI::Query (); +use Frontier::Client (); +use Switch; + +my $r; +$SIG{__DIE__} = sub { + my $msg = join('', @_); + $r->content_type('text/html'); + warn $msg; + print $msg; + $r->status(Apache2::Const::SERVER_ERROR); +}; + +sub handler { + $r = shift; + + $r->allow_methods(1, qw(GET)); + + my $pathInfo = $r->path_info(); + my $hostname = $r->hostname(); + my $uq = URI::Query->new($r->args()); + my %params = $uq->hash(); + + unless ($pathInfo =~ /^\/(\w+)$/) { + print " +USAGE: + * http(s)://$hostname/RESTWrapper/[API-METHOD]?username=&password=&[API-PARAMETER] + * http(s)://@\@$hostname/RESTWrapper/[API-METHOD]?[API-PARAMETER] + +Examples: + * http(s)://foo:bar\@$hostname/RESTWrapper/search?search=test?rootName=bigRoot + * http(s)://$hostname/RESTWrapper/getFreeSubnets?username=foo&password=bar&rootName=bigRoot&supernet=192.168.0.0%2f24&cidr=32&amount=3\n"; + + return Apache2::Const::HTTP_BAD_REQUEST; + } + my $method = $1; + + my $user = $r->user(); + (undef, my $pass) = $r->get_basic_auth_pw(); + $user ||= $params{username}; + $pass ||= $params{password}; + + my $result = &wrapper($hostname, $method, $user, $pass, \%params); + $r->content_type('application/json'); + print JSON->new->allow_nonref->encode($result) unless ref($result) eq 'HASH' && $result->{omitOutput}; + + return Apache2::Const::OK; +} + +sub wrapper { + my $server = shift; + my $method = shift; + my $user = shift; + my $pass = shift; + my $params = shift; + + my $api = new Frontier::Client(url => "http://$server/RPC2"); + my $session = $api->call('login', [$user, $pass]); + die 'Login failed!' unless $session; + + # warn "Params: " . Dumper($params); + + my @methParams = (); + switch ($method) { + case "search" { + @methParams = qw(search state exact templateName templateQuery rootName nrOfFreeSubs withDetails); + } + case "getFreeSubnets" { + @methParams = qw(rootName supernet cidr amount); + } + case "getFreeSubnetsFromSearch" { + @methParams = qw(search state exact templateName templateQuery rootName cidr amount); + } + case "addNet" { + @methParams = qw(rootName network description state defSubnetSize templateName templateValues); + } + case "delNet" { + @methParams = qw(rootName network); + } + case "assignFreeSubnet" { + @methParams = qw(rootName supernet cidr description state defSubnetSize templateName templateValues); + } + case "getNetworkDetails" { + @methParams = qw(rootName network); + } + case "getSubnets" { + @methParams = qw(rootName supernet); + } + else { + die "Unkown method '$method'\n"; + } + } + + my @args = (); + foreach (@methParams) { + push @args, $params->{$_} // ''; + } + # warn "Calling $method with: " . join(', ', @args) . "\n"; + return $api->call($method, $session, @args); +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/SOAP/Type/network.pm haci-0.98c/modules/HaCi/SOAP/Type/network.pm --- haci-0.97c/modules/HaCi/SOAP/Type/network.pm 2008-09-17 16:34:08.000000000 +0000 +++ haci-0.98c/modules/HaCi/SOAP/Type/network.pm 2015-01-03 05:11:11.000000000 +0000 @@ -6,6 +6,7 @@ _ATTR network $string Network _ATTR description $string Description _ATTR state $string State + _ATTR tags $string Tags =cut @@ -14,13 +15,15 @@ my $rootName = shift || ''; my $network = shift || ''; my $description = shift || ''; - my $state = shift || 0; + my $state = SOAP::Data->type(string => (shift || 0)); + my $tags = shift || ''; bless { rootName => $rootName, network => $network, description => $description, state => $state, + tags => $tags, }, $class; } diff -Nru haci-0.97c/modules/HaCi/Tables/group.pm haci-0.98c/modules/HaCi/Tables/group.pm --- haci-0.97c/modules/HaCi/Tables/group.pm 2006-11-15 18:31:11.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/group.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -package HaCi::Tables::group; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'squad' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` int(11) NOT NULL auto_increment, - `name` varchar(255) NOT NULL default '', - `description` varchar(255) NOT NULL default '', - `permissions` integer NOT NULL default '0', - `createFrom` varchar(255) NOT NULL default '', - `createDate` datetime NOT NULL default '0000-00-00 00:00:00', - `modifyFrom` varchar(255) NOT NULL default '', - `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', - PRIMARY KEY (`ID`), - UNIQUE KEY (`name`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/audit.pm haci-0.98c/modules/HaCi/Tables/mysql/audit.pm --- haci-0.97c/modules/HaCi/Tables/mysql/audit.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/audit.pm 2012-06-25 23:23:00.000000000 +0000 @@ -0,0 +1,46 @@ +package HaCi::Tables::mysql::audit; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'audit' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int(11) NOT NULL auto_increment, + `ts` datetime NOT NULL default '0000-00-00 00:00:00', + `username` varchar(255) NOT NULL default '', + `accessGroups` varchar(255) NOT NULL default '', + `action` varchar(255) NOT NULL default '', + `object` varchar(255) NOT NULL default '', + `value` text NOT NULL, + `error` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/group.pm haci-0.98c/modules/HaCi/Tables/mysql/group.pm --- haci-0.97c/modules/HaCi/Tables/mysql/group.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/group.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,48 @@ +package HaCi::Tables::mysql::group; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'squad' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `permissions` integer NOT NULL default '0', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY (`name`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/networkAC.pm haci-0.98c/modules/HaCi/Tables/mysql/networkAC.pm --- haci-0.97c/modules/HaCi/Tables/mysql/networkAC.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/networkAC.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,46 @@ +package HaCi::Tables::mysql::networkAC; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'networkAC' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` integer NOT NULL auto_increment, + `rootID` integer NOT NULL default '0', + `network` bigint(40) NOT NULL default '0', + `netID` integer NOT NULL default '0', + `groupID` integer NOT NULL default '0', + `ACL` integer NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY (`netID`, `groupID`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/networkLock.pm haci-0.98c/modules/HaCi/Tables/mysql/networkLock.pm --- haci-0.97c/modules/HaCi/Tables/mysql/networkLock.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/networkLock.pm 2014-08-28 23:35:40.000000000 +0000 @@ -0,0 +1,50 @@ +package HaCi::Tables::mysql::networkLock; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'networkLock' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` integer NOT NULL auto_increment, + `ts` datetime NOT NULL default '0000-00-00 00:00:00', + `duration` integer NOT NULL default '0', + `rootID` int NOT NULL default 0, + `networkPrefix` bigint UNSIGNED NOT NULL default 0, + `hostPart` bigint UNSIGNED NOT NULL default 0, + `cidr` smallint NOT NULL default 0, + `ipv6` smallint NOT NULL default 0, + PRIMARY KEY (`ID`), + UNIQUE KEY (`rootID`, `networkPrefix`,`hostPart`,`cidr`, `ipv6`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/networkPlugin.pm haci-0.98c/modules/HaCi/Tables/mysql/networkPlugin.pm --- haci-0.97c/modules/HaCi/Tables/mysql/networkPlugin.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/networkPlugin.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,45 @@ +package HaCi::Tables::mysql::networkPlugin; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'networkPlugin' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` integer NOT NULL auto_increment, + `netID` integer NOT NULL default '0', + `pluginID` integer NOT NULL default '0', + `sequence` integer NOT NULL default '0', + `newLine` tinyint NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY (`netID`, `pluginID`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/network.pm haci-0.98c/modules/HaCi/Tables/mysql/network.pm --- haci-0.97c/modules/HaCi/Tables/mysql/network.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/network.pm 2014-10-18 03:20:08.000000000 +0000 @@ -0,0 +1,58 @@ +package HaCi::Tables::mysql::network; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'network' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int(11) NOT NULL auto_increment, + `rootID` int (11) NOT NULL default '0', + `network` bigint(20) UNSIGNED NOT NULL default '0', + `description` varchar(255) NOT NULL default '', + `state` smallint(6) NOT NULL default '0', + `defSubnetSize` TINYINT(4) UNSIGNED NOT NULL default '0', + `tmplID` integer NOT NULL default '0', + `ipv6ID` varbinary(22) NOT NULL default '', + `searchStr` varchar(255) default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + INDEX (`network`), + INDEX (`description`), + INDEX (`searchStr`), + UNIQUE KEY (`rootID`,`ipv6ID`, `network`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/networkTag.pm haci-0.98c/modules/HaCi/Tables/mysql/networkTag.pm --- haci-0.97c/modules/HaCi/Tables/mysql/networkTag.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/networkTag.pm 2015-01-03 05:11:11.000000000 +0000 @@ -0,0 +1,43 @@ +package HaCi::Tables::mysql::networkTag; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'networkTag' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` integer NOT NULL auto_increment, + `netID` integer NOT NULL default '0', + `tag` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY (`netID`, `tag`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/networkV6.pm haci-0.98c/modules/HaCi/Tables/mysql/networkV6.pm --- haci-0.97c/modules/HaCi/Tables/mysql/networkV6.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/networkV6.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,45 @@ +package HaCi::Tables::mysql::networkV6; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'networkV6' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` varbinary(22) NOT NULL default '', + `rootID` int NOT NULL default 0, + `networkPrefix` bigint UNSIGNED NOT NULL default 0, + `hostPart` bigint UNSIGNED NOT NULL default 0, + `cidr` smallint NOT NULL default 0, + PRIMARY KEY (`ID`, `rootID`), + UNIQUE KEY (`rootID`, `networkPrefix`,`hostPart`,`cidr`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/pluginConf.pm haci-0.98c/modules/HaCi/Tables/mysql/pluginConf.pm --- haci-0.97c/modules/HaCi/Tables/mysql/pluginConf.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/pluginConf.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,45 @@ +package HaCi::Tables::mysql::pluginConf; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'pluginConf' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` INT NOT NULL AUTO_INCREMENT, + `netID` INT NOT NULL , + `pluginID` INT NOT NULL , + `name` VARCHAR( 255 ) NOT NULL , + `value` TEXT NOT NULL , + PRIMARY KEY (`ID`), + UNIQUE KEY (`netID`,`pluginID`,`name`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/plugin.pm haci-0.98c/modules/HaCi/Tables/mysql/plugin.pm --- haci-0.97c/modules/HaCi/Tables/mysql/plugin.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/plugin.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,47 @@ +package HaCi::Tables::mysql::plugin; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'plugin' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `filename` varchar(255) NOT NULL default '', + `active` tinyint NOT NULL default 0, + `lastRun` datetime NOT NULL default '0000-00-00 00:00:00', + `runTime` int NOT NULL default 0, + `lastError` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY (`name`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/pluginValue.pm haci-0.98c/modules/HaCi/Tables/mysql/pluginValue.pm --- haci-0.97c/modules/HaCi/Tables/mysql/pluginValue.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/pluginValue.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,46 @@ +package HaCi::Tables::mysql::pluginValue; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'pluginValue' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` INT NOT NULL AUTO_INCREMENT, + `netID` INT NOT NULL , + `pluginID` INT NOT NULL , + `origin` INT NOT NULL , + `name` VARCHAR( 255 ) NOT NULL , + `value` TEXT NOT NULL , + PRIMARY KEY (`ID`), + UNIQUE KEY (`netID`,`pluginID`,`name`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/rootAC.pm haci-0.98c/modules/HaCi/Tables/mysql/rootAC.pm --- haci-0.97c/modules/HaCi/Tables/mysql/rootAC.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/rootAC.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,44 @@ +package HaCi::Tables::mysql::rootAC; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'rootAC' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` integer NOT NULL auto_increment, + `rootID` integer NOT NULL default 0, + `groupID` integer NOT NULL default '0', + `ACL` integer NOT NULL default '0', + PRIMARY KEY (`ID`), + UNIQUE KEY (`rootID`, `groupID`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/root.pm haci-0.98c/modules/HaCi/Tables/mysql/root.pm --- haci-0.97c/modules/HaCi/Tables/mysql/root.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/root.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,48 @@ +package HaCi::Tables::mysql::root; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'root' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `ipv6` tinyint(1) NOT NULL default 0, + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY (`name`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/setting.pm haci-0.98c/modules/HaCi/Tables/mysql/setting.pm --- haci-0.97c/modules/HaCi/Tables/mysql/setting.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/setting.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,44 @@ +package HaCi::Tables::mysql::setting; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'setting' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` integer NOT NULL auto_increment, + `userID` integer NOT NULL default 0, + `param` varchar(255) NOT NULL default '', + `value` varchar(255) NOT NULL default '', + PRIMARY KEY (`ID`), + UNIQUE KEY (`userID`, `param`, `value`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/templateEntry.pm haci-0.98c/modules/HaCi/Tables/mysql/templateEntry.pm --- haci-0.97c/modules/HaCi/Tables/mysql/templateEntry.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/templateEntry.pm 2012-06-19 22:37:12.000000000 +0000 @@ -0,0 +1,48 @@ +package HaCi::Tables::mysql::templateEntry; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'templateEntry' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int(11) NOT NULL auto_increment, + `tmplID` int(11) NOT NULL default '0', + `type` integer NOT NULL default '0', + `position` integer NOT NULL default '0', + `description` varchar(255) NOT NULL default '', + `size` integer NOT NULL default '1', + `entries` text NOT NULL, + `rows` integer NOT NULL default '1', + `cols` integer NOT NULL default '1', + PRIMARY KEY (`ID`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/template.pm haci-0.98c/modules/HaCi/Tables/mysql/template.pm --- haci-0.97c/modules/HaCi/Tables/mysql/template.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/template.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,47 @@ +package HaCi::Tables::mysql::template; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'template' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int(11) NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `type` varchar(64) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY (`name`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/templateValue.pm haci-0.98c/modules/HaCi/Tables/mysql/templateValue.pm --- haci-0.97c/modules/HaCi/Tables/mysql/templateValue.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/templateValue.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,45 @@ +package HaCi::Tables::mysql::templateValue; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'templateValue' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` integer NOT NULL auto_increment, + `tmplID` integer NOT NULL default '0', + `tmplEntryID` integer NOT NULL default '0', + `netID` integer NOT NULL default '0', + `value` blob NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY (`netID`,`tmplID`,`tmplEntryID`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} + +1; diff -Nru haci-0.97c/modules/HaCi/Tables/mysql/user.pm haci-0.98c/modules/HaCi/Tables/mysql/user.pm --- haci-0.97c/modules/HaCi/Tables/mysql/user.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/mysql/user.pm 2012-01-17 00:28:56.000000000 +0000 @@ -0,0 +1,48 @@ +package HaCi::Tables::mysql::user; +use base 'DBIEasy::mysql'; + +sub TABLE { #Table Name + 'user' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 1 +} + +sub CREATETABLE { # Table Create Definition + q{ + `ID` int(11) NOT NULL auto_increment, + `username` varchar(100) NOT NULL default '', + `password` varchar(255) NOT NULL default '', + `groupIDs` varchar(255) NOT NULL default '', + `description` varchar(255) NOT NULL default '', + `createFrom` varchar(255) NOT NULL default '', + `createDate` datetime NOT NULL default '0000-00-00 00:00:00', + `modifyFrom` varchar(255) NOT NULL default '', + `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + UNIQUE KEY (`username`) + } +} + +sub _log { + my $self = shift; + my @msg = @_; + + DBIEasy::mysql::_log($self, @msg); +} + +sub _carp { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_carp($self, $message, %info); +} + +sub _croak { + my $self = shift; + my ($message, %info) = @_; + + DBIEasy::mysql::_croak($self, $message, %info); +} +1; diff -Nru haci-0.97c/modules/HaCi/Tables/networkAC.pm haci-0.98c/modules/HaCi/Tables/networkAC.pm --- haci-0.97c/modules/HaCi/Tables/networkAC.pm 2007-09-21 06:12:23.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/networkAC.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ -package HaCi::Tables::networkAC; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'networkAC' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` integer NOT NULL auto_increment, - `rootID` integer NOT NULL default '0', - `network` bigint(40) NOT NULL default '0', - `netID` integer NOT NULL default '0', - `groupID` integer NOT NULL default '0', - `ACL` integer NOT NULL default '0', - PRIMARY KEY (`ID`), - UNIQUE KEY (`netID`, `groupID`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/networkPlugin.pm haci-0.98c/modules/HaCi/Tables/networkPlugin.pm --- haci-0.97c/modules/HaCi/Tables/networkPlugin.pm 2008-02-28 03:02:23.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/networkPlugin.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -package HaCi::Tables::networkPlugin; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'networkPlugin' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` integer NOT NULL auto_increment, - `netID` integer NOT NULL default '0', - `pluginID` integer NOT NULL default '0', - `sequence` integer NOT NULL default '0', - `newLine` tinyint NOT NULL default '0', - PRIMARY KEY (`ID`), - UNIQUE KEY (`netID`, `pluginID`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/network.pm haci-0.98c/modules/HaCi/Tables/network.pm --- haci-0.97c/modules/HaCi/Tables/network.pm 2010-02-24 03:29:58.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/network.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -package HaCi::Tables::network; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'network' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` int(11) NOT NULL auto_increment, - `rootID` int (11) NOT NULL default '0', - `network` bigint(40) NOT NULL default '0', - `description` varchar(255) NOT NULL default '', - `state` smallint(6) NOT NULL default '0', - `defSubnetSize` TINYINT(4) UNSIGNED NOT NULL default '0', - `tmplID` integer NOT NULL default '0', - `ipv6ID` varbinary(22) NOT NULL default '', - `createFrom` varchar(255) NOT NULL default '', - `createDate` datetime NOT NULL default '0000-00-00 00:00:00', - `modifyFrom` varchar(255) NOT NULL default '', - `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', - PRIMARY KEY (`ID`), - INDEX (`network`), - UNIQUE KEY (`rootID`,`ipv6ID`, `network`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; - -# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/networkV6.pm haci-0.98c/modules/HaCi/Tables/networkV6.pm --- haci-0.97c/modules/HaCi/Tables/networkV6.pm 2010-02-24 03:29:58.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/networkV6.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -package HaCi::Tables::networkV6; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'networkV6' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` varbinary(22) NOT NULL default '', - `rootID` int NOT NULL default 0, - `networkPrefix` bigint UNSIGNED NOT NULL default 0, - `hostPart` bigint UNSIGNED NOT NULL default 0, - `cidr` smallint NOT NULL default 0, - PRIMARY KEY (`ID`, `rootID`), - UNIQUE KEY (`rootID`, `networkPrefix`,`hostPart`,`cidr`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/pluginConf.pm haci-0.98c/modules/HaCi/Tables/pluginConf.pm --- haci-0.97c/modules/HaCi/Tables/pluginConf.pm 2007-12-20 15:46:56.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/pluginConf.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -package HaCi::Tables::pluginConf; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'pluginConf' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` INT NOT NULL AUTO_INCREMENT, - `netID` INT NOT NULL , - `pluginID` INT NOT NULL , - `name` VARCHAR( 255 ) NOT NULL , - `value` TEXT NOT NULL , - PRIMARY KEY (`ID`), - UNIQUE KEY (`netID`,`pluginID`,`name`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/plugin.pm haci-0.98c/modules/HaCi/Tables/plugin.pm --- haci-0.97c/modules/HaCi/Tables/plugin.pm 2010-02-24 03:29:58.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/plugin.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -package HaCi::Tables::plugin; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'plugin' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` int NOT NULL auto_increment, - `name` varchar(255) NOT NULL default '', - `filename` varchar(255) NOT NULL default '', - `active` tinyint NOT NULL default 0, - `lastRun` datetime NOT NULL default '0000-00-00 00:00:00', - `runTime` int NOT NULL default 0, - `lastError` varchar(255) NOT NULL default '', - PRIMARY KEY (`ID`), - UNIQUE KEY (`name`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/pluginValue.pm haci-0.98c/modules/HaCi/Tables/pluginValue.pm --- haci-0.97c/modules/HaCi/Tables/pluginValue.pm 2008-02-07 01:36:03.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/pluginValue.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ -package HaCi::Tables::pluginValue; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'pluginValue' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` INT NOT NULL AUTO_INCREMENT, - `netID` INT NOT NULL , - `pluginID` INT NOT NULL , - `origin` INT NOT NULL , - `name` VARCHAR( 255 ) NOT NULL , - `value` TEXT NOT NULL , - PRIMARY KEY (`ID`), - UNIQUE KEY (`netID`,`pluginID`,`name`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/audit.pm haci-0.98c/modules/HaCi/Tables/postgresql/audit.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/audit.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/audit.pm 2012-06-25 23:23:00.000000000 +0000 @@ -0,0 +1,30 @@ +package HaCi::Tables::postgresql::audit; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'audit' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + ts => 'ts', + username => 'username', + accessGroups => 'access_groups', + action => 'action', + object => 'object', + value => 'value', + error => 'error', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/group.pm haci-0.98c/modules/HaCi/Tables/postgresql/group.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/group.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/group.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,30 @@ +package HaCi::Tables::postgresql::group; +use base 'DBIEasy::postgresql'; + +sub TABLE { #table name + 'squad' +} + +sub SETUPTABLE { # create table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # table create definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + name => 'name', + description => 'description', + permissions => 'permissions', + createFrom => 'create_from', + createDate => 'create_date', + modifyFrom => 'modify_from', + modifyDate => 'modify_date', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/networkAC.pm haci-0.98c/modules/HaCi/Tables/postgresql/networkAC.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/networkAC.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/networkAC.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,28 @@ +package HaCi::Tables::postgresql::networkAC; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'network_ac' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + rootID => 'root_id', + network => 'network', + netID => 'net_id', + groupID => 'group_id', + ACL => 'acl' + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/networkLock.pm haci-0.98c/modules/HaCi/Tables/postgresql/networkLock.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/networkLock.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/networkLock.pm 2014-08-28 22:12:24.000000000 +0000 @@ -0,0 +1,30 @@ +package HaCi::Tables::postgresql::networkLock; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'network_lock' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + ts => 'ts', + duration => 'duration', + rootID => 'root_id', + networkPrefix => 'network_prefix', + hostPart => 'host_part', + cidr => 'cidr', + ipv6 => 'ipv6', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/networkPlugin.pm haci-0.98c/modules/HaCi/Tables/postgresql/networkPlugin.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/networkPlugin.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/networkPlugin.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,27 @@ +package HaCi::Tables::postgresql::networkPlugin; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'network_plugin' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + netID => 'net_id', + pluginID => 'plugin_id', + sequence => 'sequence', + newLine => 'new_line', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/network.pm haci-0.98c/modules/HaCi/Tables/postgresql/network.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/network.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/network.pm 2014-09-09 23:48:51.000000000 +0000 @@ -0,0 +1,35 @@ +package HaCi::Tables::postgresql::network; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'network' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + rootID => 'root_id', + network => 'network', + description => 'description', + state => 'state', + defSubnetSize => 'def_subnet_size', + tmplID => 'tmpl_id', + ipv6ID => 'ipv6_id', + searchStr => 'search_str', + createFrom => 'create_from', + createDate => 'create_date', + modifyFrom => 'modify_from', + modifyDate => 'modify_date', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/networkTag.pm haci-0.98c/modules/HaCi/Tables/postgresql/networkTag.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/networkTag.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/networkTag.pm 2015-01-03 05:11:11.000000000 +0000 @@ -0,0 +1,25 @@ +package HaCi::Tables::postgresql::networkTag; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'network_tag' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + netID => 'net_id', + tag => 'tag' + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/networkV6.pm haci-0.98c/modules/HaCi/Tables/postgresql/networkV6.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/networkV6.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/networkV6.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,27 @@ +package HaCi::Tables::postgresql::networkV6; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'network_v6' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + rootID => 'root_id', + networkPrefix => 'network_prefix', + hostPart => 'host_part', + cidr => 'cidr' + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/pluginConf.pm haci-0.98c/modules/HaCi/Tables/postgresql/pluginConf.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/pluginConf.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/pluginConf.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,27 @@ +package HaCi::Tables::postgresql::pluginConf; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'plugin_conf' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + netID => 'net_id', + pluginID => 'plugin_id', + name => 'name', + value => 'value', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/plugin.pm haci-0.98c/modules/HaCi/Tables/postgresql/plugin.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/plugin.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/plugin.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,29 @@ +package HaCi::Tables::postgresql::plugin; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'plugin' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + name => 'name', + filename => 'filename', + active => 'active', + lastRun => 'last_run', + runTime => 'run_time', + lastError => 'last_error', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/pluginValue.pm haci-0.98c/modules/HaCi/Tables/postgresql/pluginValue.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/pluginValue.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/pluginValue.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,28 @@ +package HaCi::Tables::postgresql::pluginValue; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'plugin_value' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + netID => 'net_id', + pluginID => 'plugin_id', + origin => 'origin', + name => 'name', + value => 'value', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/rootAC.pm haci-0.98c/modules/HaCi/Tables/postgresql/rootAC.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/rootAC.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/rootAC.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,26 @@ +package HaCi::Tables::postgresql::rootAC; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'root_ac' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + rootID => 'root_id', + groupID => 'group_id', + ACL => 'acl', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/root.pm haci-0.98c/modules/HaCi/Tables/postgresql/root.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/root.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/root.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,30 @@ +package HaCi::Tables::postgresql::root; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'root' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + name => 'name', + description => 'description', + ipv6 => 'ipv6', + createFrom => 'create_from', + createDate => 'create_date', + modifyFrom => 'modify_from', + modifyDate => 'modify_date', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/setting.pm haci-0.98c/modules/HaCi/Tables/postgresql/setting.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/setting.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/setting.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,26 @@ +package HaCi::Tables::postgresql::setting; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'setting' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + userID => 'user_id', + param => 'param', + value => 'value', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/templateEntry.pm haci-0.98c/modules/HaCi/Tables/postgresql/templateEntry.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/templateEntry.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/templateEntry.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,31 @@ +package HaCi::Tables::postgresql::templateEntry; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'template_entry' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + tmplID => 'tmpl_id', + type => 'type', + position => 'position', + description => 'description', + size => 'size', + entries => 'entries', + rows => 'rows', + cols => 'cols', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/template.pm haci-0.98c/modules/HaCi/Tables/postgresql/template.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/template.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/template.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,29 @@ +package HaCi::Tables::postgresql::template; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'template' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + name => 'name', + type => 'type', + createFrom => 'create_from', + createDate => 'create_date', + modifyFrom => 'modify_from', + modifyDate => 'modify_date', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/templateValue.pm haci-0.98c/modules/HaCi/Tables/postgresql/templateValue.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/templateValue.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/templateValue.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,27 @@ +package HaCi::Tables::postgresql::templateValue; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'template_value' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + tmplID => 'tmpl_id', + tmplEntryID => 'tmpl_entry_id', + netID => 'net_id', + value => 'value', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/postgresql/user.pm haci-0.98c/modules/HaCi/Tables/postgresql/user.pm --- haci-0.97c/modules/HaCi/Tables/postgresql/user.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/postgresql/user.pm 2012-01-19 23:49:18.000000000 +0000 @@ -0,0 +1,31 @@ +package HaCi::Tables::postgresql::user; +use base 'DBIEasy::postgresql'; + +sub TABLE { #Table Name + 'user' +} + +sub SETUPTABLE { # Create Table unless it doesn't exists? + 0 +} + +sub CREATETABLE { # Table Create Definition +} + +sub columnMapping { # map DBIEasy methods to table column names + { + ID => 'id', + username => 'username', + password => 'password', + groupIDs => 'group_ids', + description => 'description', + createFrom => 'create_from', + createDate => 'create_date', + modifyFrom => 'modify_from', + modifyDate => 'modify_date', + } +} + +1; + +# vim:ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Tables/rootAC.pm haci-0.98c/modules/HaCi/Tables/rootAC.pm --- haci-0.97c/modules/HaCi/Tables/rootAC.pm 2006-11-15 18:31:12.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/rootAC.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -package HaCi::Tables::rootAC; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'rootAC' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` integer NOT NULL auto_increment, - `rootID` integer NOT NULL default 0, - `groupID` integer NOT NULL default '0', - `ACL` integer NOT NULL default '0', - PRIMARY KEY (`ID`), - UNIQUE KEY (`rootID`, `groupID`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/root.pm haci-0.98c/modules/HaCi/Tables/root.pm --- haci-0.97c/modules/HaCi/Tables/root.pm 2007-09-13 05:43:15.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/root.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -package HaCi::Tables::root; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'root' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` int(11) NOT NULL auto_increment, - `name` varchar(255) NOT NULL default '', - `description` varchar(255) NOT NULL default '', - `ipv6` tinyint(1) NOT NULL default 0, - `createFrom` varchar(255) NOT NULL default '', - `createDate` datetime NOT NULL default '0000-00-00 00:00:00', - `modifyFrom` varchar(255) NOT NULL default '', - `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', - PRIMARY KEY (`ID`), - UNIQUE KEY (`name`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/setting.pm haci-0.98c/modules/HaCi/Tables/setting.pm --- haci-0.97c/modules/HaCi/Tables/setting.pm 2008-06-27 16:50:22.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/setting.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -package HaCi::Tables::setting; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'setting' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` integer NOT NULL auto_increment, - `userID` integer NOT NULL default 0, - `param` varchar(255) NOT NULL default '', - `value` varchar(255) NOT NULL default '', - PRIMARY KEY (`ID`), - UNIQUE KEY (`userID`, `param`, `value`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/templateEntry.pm haci-0.98c/modules/HaCi/Tables/templateEntry.pm --- haci-0.97c/modules/HaCi/Tables/templateEntry.pm 2006-11-15 18:31:12.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/templateEntry.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -package HaCi::Tables::templateEntry; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'templateEntry' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` int(11) NOT NULL auto_increment, - `tmplID` int(11) NOT NULL default '0', - `type` integer NOT NULL default '0', - `position` integer NOT NULL default '0', - `description` varchar(255) NOT NULL default '', - `size` integer NOT NULL default '1', - `entries` varchar(255) NOT NULL default '', - `rows` integer NOT NULL default '1', - `cols` integer NOT NULL default '1', - PRIMARY KEY (`ID`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/template.pm haci-0.98c/modules/HaCi/Tables/template.pm --- haci-0.97c/modules/HaCi/Tables/template.pm 2006-10-09 06:06:36.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/template.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -package HaCi::Tables::template; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'template' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` int(11) NOT NULL auto_increment, - `name` varchar(255) NOT NULL default '', - `type` varchar(64) NOT NULL default '', - `createFrom` varchar(255) NOT NULL default '', - `createDate` datetime NOT NULL default '0000-00-00 00:00:00', - `modifyFrom` varchar(255) NOT NULL default '', - `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', - PRIMARY KEY (`ID`), - UNIQUE KEY (`name`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/templateValue.pm haci-0.98c/modules/HaCi/Tables/templateValue.pm --- haci-0.97c/modules/HaCi/Tables/templateValue.pm 2010-02-15 17:27:12.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/templateValue.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -package HaCi::Tables::templateValue; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'templateValue' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` integer NOT NULL auto_increment, - `tmplID` integer NOT NULL default '0', - `tmplEntryID` integer NOT NULL default '0', - `netID` integer NOT NULL default '0', - `value` blob NOT NULL, - PRIMARY KEY (`ID`), - UNIQUE KEY (`netID`,`tmplID`,`tmplEntryID`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} - -1; diff -Nru haci-0.97c/modules/HaCi/Tables/user.pm haci-0.98c/modules/HaCi/Tables/user.pm --- haci-0.97c/modules/HaCi/Tables/user.pm 2008-12-05 10:29:59.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tables/user.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -package HaCi::Tables::user; -use base 'DBIEasy'; - -sub TABLE { #Table Name - 'user' -} - -sub SETUPTABLE { # Create Table unless it doesn't exists? - 1 -} - -sub CREATETABLE { # Table Create Definition - q{ - `ID` int(11) NOT NULL auto_increment, - `username` varchar(100) NOT NULL default '', - `password` varchar(255) NOT NULL default '', - `groupIDs` varchar(255) NOT NULL default '', - `description` varchar(255) NOT NULL default '', - `createFrom` varchar(255) NOT NULL default '', - `createDate` datetime NOT NULL default '0000-00-00 00:00:00', - `modifyFrom` varchar(255) NOT NULL default '', - `modifyDate` datetime NOT NULL default '0000-00-00 00:00:00', - PRIMARY KEY (`ID`), - UNIQUE KEY (`username`) - } -} - -sub _log { - my $self = shift; - my @msg = @_; - - DBIEasy::_log($self, @msg); -} - -sub _carp { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_carp($self, $message, %info); -} - -sub _croak { - my $self = shift; - my ($message, %info) = @_; - - DBIEasy::_croak($self, $message, %info); -} -1; diff -Nru haci-0.97c/modules/HaCi/Tree.pm haci-0.98c/modules/HaCi/Tree.pm --- haci-0.97c/modules/HaCi/Tree.pm 2010-02-26 00:41:48.000000000 +0000 +++ haci-0.98c/modules/HaCi/Tree.pm 2015-02-15 16:47:28.000000000 +0000 @@ -1,13 +1,13 @@ package HaCi::Tree; use strict; -use constant LOG2 => log(2); +use Data::Dumper; use HaCi::Mathematics qw/ - dec2net net2dec getBroadcastFromNet getIPFromDec dec2ip ip2dec netv6Dec2net + dec2net net2dec getBroadcastFromNet getIPFromDec dec2ip ip2dec netv6Dec2net ipv6Sort netv6Dec2NextNetDec netv6Dec2ip netv6Dec2IpCidr ipv6DecCidr2netv6Dec getV6BroadcastIP /; -use HaCi::Utils qw/checkSpelling_Net debug checkRight networkStateID2Name fillHoles nd dn quoteHTML/; +use HaCi::Utils qw/checkSpelling_Net debug checkRight networkStateID2Name fillHoles nd dn quoteHTML checkNetACL getConfigValue/; use HaCi::GUI::gettext qw/_gettext/; our $conf; *conf = \$HaCi::Conf::conf; @@ -206,10 +206,12 @@ my $lastNetDec = ($ipv6) ? $networkDecStart->copy() : $networkDecStart; my @netst = keys %{$self->{TREE}->{$rootID}->{NETWORKS}}; my @nets = (); - my $defSubnetSize = 0; + my $defSubnetSize = ($lastNetDec == $networkDecStart) ? + ((exists $self->{TREE}->{$rootID}->{NETWORKS}->{$lastNetDec}) ? $self->{TREE}->{$rootID}->{NETWORKS}->{$lastNetDec}->{DEFSUBNETSIZE} : 0) : + ((exists $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDecStart}) ? $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDecStart}->{DEFSUBNETSIZE} : 0); if ($ipv6) { - @nets = sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} @netst; + @nets = &ipv6Sort(@netst); } else { @nets = sort {$a<=>$b} @netst; } @@ -220,10 +222,6 @@ last if $networkDec > $broadcastEnd; next if $networkDecStart != $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{NETPARENT}; - $defSubnetSize = ($lastNetDec == $networkDecStart) ? - ((exists $self->{TREE}->{$rootID}->{NETWORKS}->{$lastNetDec}) ? $self->{TREE}->{$rootID}->{NETWORKS}->{$lastNetDec}->{DEFSUBNETSIZE} : 0) : - ((exists $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDecStart}) ? $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDecStart}->{DEFSUBNETSIZE} : 0); - foreach (&fillHoles($lastNetDec, $networkDec, $ipv6, $defSubnetSize)) { &addNet($self, -1, $rootID, $ipv6, $_, '', 0, 1, $networkDecStart, 0); } @@ -242,14 +240,12 @@ my $session = $HaCi::HaCi::session; my $sortBox = {}; - foreach (keys %{$self->{TREE}}) { - my $rootID = $_; + foreach my $rootID (keys %{$self->{TREE}}) { my $rootName = $self->{TREE}->{$rootID}->{NAME} || ''; $sortBox->{$rootName} = $rootID; } - foreach (sort keys %{$sortBox}) { - my $rootName = $_; + foreach my $rootName (sort keys %{$sortBox}) { my $rootID = $sortBox->{$rootName}; my $tmp = &print_html_root($self, $rootID); my $networks = &print_html_networks($self, $rootID); @@ -262,11 +258,12 @@ sub print_html_root { my $self = shift; my $rootID = shift; - my $rootName = "eHTML($self->{TREE}->{$rootID}->{NAME}) || '???'; - my $rootDescr = "eHTML($self->{TREE}->{$rootID}->{DESCR}) || ''; - my $rootExpanded = $self->{TREE}->{$rootID}->{EXPANDED}; - my $rootParent = $self->{TREE}->{$rootID}->{PARENT}; - my $ipv6 = $self->{TREE}->{$rootID}->{V6}; + my $root = $self->{TREE}->{$rootID}; + my $rootName = "eHTML($root->{NAME}) || '???'; + my $rootDescr = "eHTML($root->{DESCR}) || ''; + my $rootExpanded = $root->{EXPANDED}; + my $rootParent = $root->{PARENT}; + my $ipv6 = $root->{V6}; my $rootColor = $self->{user}->{gui}->{colors}->{root}; my $bEditTree = (defined $HaCi::HaCi::q->param('editTree') && $HaCi::HaCi::q->param('editTree')) ? 1 : 0; my $bShowRoot = &checkRight('showRootDet'); @@ -298,7 +295,8 @@ my $newLevel = shift || 0; my $origNetworkDec = shift || 0; my $networks = []; - my $ipv6 = $self->{TREE}->{$rootID}->{V6}; + my $root = $self->{TREE}->{$rootID}; + my $ipv6 = $root->{V6}; $origNetworkDec = Math::BigInt->new($origNetworkDec) if $ipv6; my $thisScript = $conf->{var}->{thisscript} || ''; @@ -315,10 +313,10 @@ my @broadcasts = (); my @parentCidrs = (); my $bNoDiv = 0; - my @netst = keys %{$self->{TREE}->{$rootID}->{NETWORKS}}; + my @netst = keys %{$root->{NETWORKS}}; my @nets = (); if ($ipv6) { - @nets = sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} @netst; + @nets = &ipv6Sort(@netst); } else { @nets = sort {$a<=>$b} @netst; } @@ -328,16 +326,17 @@ my $parentMarker = {}; foreach (@nets) { my $networkDec = $_; - my $network = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{NETWORK}; - my $netID = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{NETID}; - my $descr = "eHTML($self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{DESCR}); - my $expanded = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{EXPANDED}; - my $parent = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{PARENT}; - my $fillNet = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{FILLNET} || 0; - my $status = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{STATUS} || 'assigned'; - my $invisible = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{INVISIBLE} || 0; - my $defSubnetSize = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{DEFSUBNETSIZE} || 0; - $ipv6 = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}->{IPV6}; + my $net = $self->{TREE}->{$rootID}->{NETWORKS}->{$networkDec}; + my $network = $net->{NETWORK}; + my $netID = $net->{NETID}; + my $descr = "eHTML($net->{DESCR}); + my $expanded = $net->{EXPANDED}; + my $parent = $net->{PARENT}; + my $fillNet = $net->{FILLNET} || 0; + my $status = $net->{STATUS} || 'assigned'; + my $invisible = $net->{INVISIBLE} || 0; + my $defSubnetSize = $net->{DEFSUBNETSIZE} || 0; + $ipv6 = $net->{IPV6}; my $bJumpTo = (defined $session->param('jumpTo') && $session->param('jumpToNet') == $networkDec && $session->param('jumpToRoot') == $rootID) ? 1 : 0; $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $broadcast = ($ipv6) ? &getV6BroadcastIP($networkDec) : &getBroadcastFromNet($networkDec); @@ -366,41 +365,46 @@ $parentCidr = $lastCidr; } else { foreach (reverse @broadcasts) { - if ($_ < $ipaddressDec) { - $level--; - $parentBroadcast = pop @broadcasts; - $parentCidr = pop @parentCidrs; - my $net = pop @{$networks}; - $net->{parentBroadcast} = 1; - push @{$networks}, $net; - } + next unless $_ < $ipaddressDec; + + $level--; + pop @broadcasts; + $parentBroadcast = $broadcasts[-1]; + pop @parentCidrs; + $parentCidr = $parentCidrs[-1]; + my $cNet = pop @{$networks}; + $cNet->{parentBroadcast} = 1; + push @{$networks}, $cNet; } } - if ($fillNet && $cidr == (($ipv6) ? 128 : 32)) { - if (!($ipaddressDec % (2 ** ((($ipv6) ? 128 : 32) - $parentCidr)))) { - $descr = '[netaddress]'; - $netColor = '#' . $conf->{user}->{gui}->{colors}->{network}->{netborder}; - } - elsif ($parentBroadcast == $ipaddressDec) { - $descr = '[broadcast]'; - $netColor = '#' . $conf->{user}->{gui}->{colors}->{network}->{netborder}; + if (!$ipv6 && &getConfigValue('gui', 'shownetborders')) { + if ($fillNet && $cidr == (($ipv6) ? 128 : 32)) { + if (!($ipaddressDec % (2 ** ((($ipv6) ? 128 : 32) - $parentCidr)))) { + $descr = '[netaddress]'; + $netColor = '#' . $conf->{user}->{gui}->{colors}->{network}->{netborder}; + } + elsif ($parentBroadcast == $ipaddressDec) { + $descr = '[broadcast]'; + $netColor = '#' . $conf->{user}->{gui}->{colors}->{network}->{netborder}; + } } } - my $picUrl = ($invisible) ? '' : (($expanded) ? 'reduceNetwork' : 'expandNetwork') . "(['args__$rootID', 'args__$networkDec', 'args__" . ($level - 1) . "', 'args__$bEditTree', 'NO_CACHE'], ['${rootID}.$networkDec'], 'POST');showStatus(1);"; + my $picUrl = ($invisible) ? '' : (($expanded) ? 'reduceNetwork' : 'expandNetwork') . "(['args__$rootID', 'args__$networkDec', 'args__" . ($level - 1) . "', 'args__$bEditTree', 'NO_CACHE'], ['${rootID}.$networkDec'], 'POST');setTimeout('showStatus(1)', 1000);"; $bNoDiv = 1 if $networkDec == $origNetworkDec; my $statePic = 0; my $stateAlt = ''; - if (uc($status) eq 'LOCKED') { + my $ucStatus = uc($status); + if ($ucStatus eq 'LOCKED') { $statePic = 'key_small.png'; $stateAlt = _gettext("This Network is locked"); } - elsif (uc($status) eq 'RESERVED') { + elsif ($ucStatus eq 'RESERVED') { $statePic = 'reserved_small.png'; $stateAlt = _gettext("This Network is reserved"); } - elsif (uc($status) eq 'FREE') { + elsif ($ucStatus eq 'FREE') { $statePic = 'free_small.png'; $stateAlt = _gettext("This Network is free"); } @@ -409,10 +413,13 @@ $parentMarker->{$netCnter} = $level if $parent && $level > ($newLevel + 1); my $lastParent = 0; if ($origNetworkDec == $networkDec) { -# don't set lastParent, because it doesn't work probably + # don't set lastParent, because it doesn't work probably $lastParent = 0; #($HaCi::HaCi::netcache->{GUI}->{$rootID}->{$origNetworkDec}->{LASTPARENT}) ? $level : 0; } + # remove CIDR from IP if wanted + $network =~ s/\/\d+// if &getConfigValue('gui', 'removecidrfromips') && $cidr == (($ipv6) ? 128 : 32); + push @{$networks}, { rootID => $rootID, space => $level * $offset, @@ -436,9 +443,11 @@ stateAlt => $stateAlt, invisible => $invisible, ipv6 => $ipv6, + bEditNet => &checkRight('editNet') && &checkNetACL($netID, 'w'), editPic => 'edit_small.png', editAlt => _gettext('Edit'), editNetUrl => "a('editNet', '$netID',0,0,0);", + bDelNet => &checkRight('editNet') && &checkNetACL($netID, 'w'), delPic => 'del_small.png', delAlt => _gettext('Delete'), delNetUrl => "a('delNet', '$netID',0,0,0);", @@ -452,12 +461,11 @@ $lastCidr = $cidr; } - foreach (sort {$a<=>$b} keys %{$parentMarker}) { - my $netCnter = $_; - my $level = $parentMarker->{$netCnter}; - my $net = ${$networks}[($netCnter - 1)]; + foreach my $netCnter (sort {$a<=>$b} keys %{$parentMarker}) { + my $level = $parentMarker->{$netCnter}; + my $net = ${$networks}[($netCnter - 1)]; if ($lastParents->{$level} == $netCnter) { -# don't set lastParent, because it doesn't work probably + # don't set lastParent, because it doesn't work probably $net->{lastParent} = 0; #$level; ${$networks}[($netCnter - 1)] = $net; $HaCi::HaCi::netcache->{GUI}->{$rootID}->{$net->{networkDec}}->{LASTPARENT} = 1; @@ -476,3 +484,5 @@ } 1; + +# vi: ts=2:sw=2:sws=2 diff -Nru haci-0.97c/modules/HaCi/Utils.pm haci-0.98c/modules/HaCi/Utils.pm --- haci-0.97c/modules/HaCi/Utils.pm 2010-06-23 22:03:30.000000000 +0000 +++ haci-0.98c/modules/HaCi/Utils.pm 2015-03-04 02:25:50.000000000 +0000 @@ -13,6 +13,7 @@ use HTML::Entities; use POSIX qw(strftime); use Data::Dumper qw/Dumper/; +use Text::CSV; #use Time::HiRes qw/gettimeofday tv_interval/; #my $t0 = undef; @@ -23,6 +24,7 @@ getNetaddress getCidrFromNetmask getIPFromDec ipv62dec ipv6Parts2NetDec netv6Dec2PartsDec getV6BroadcastIP getV6BroadcastNet netv6Dec2ip ipv62Dec2 ipv6Dec2ip netv6Dec2net netv62Dec netv6Dec2IpCidr ipv6DecCidr2netv6Dec netv6Dec2NextNetDec ipv6DecCidr2NetaddressV6Dec + ipv6Sort /; use HaCi::Authentication::internal qw/getCryptPassword lwe bin2dec/; use HaCi::GUI::gettext qw/_gettext/; @@ -36,18 +38,18 @@ our @EXPORT_OK = qw( warnl debug importCSV compare checkDB newWindow prNewWindows getID getStatus setStatus addRoot addNet getRoots checkSpelling_Net importASNRoutes getNextDBNetwork getConfig - getWHOISData getNSData rootID2Name rootName2ID getNrOfChilds getMaintInfosFromRoot + getWHOISData getNSData rootID2Name rootName2ID getNrOfChilds getMaintInfosFromRoot checkNetworkLock getMaintInfosFromNet editRoot delNet genRandBranch delRoot copyNetsTo delNets search checkSpelling_IP checkSpelling_CIDR networkStateName2ID networkStateID2Name getNetworkTypes - getTemplate saveTmpl prWarnl getTemplateEntries tmplID2Name delTmpl getTemplateData + getTemplate saveTmpl prWarnl getTemplateEntries tmplID2Name delTmpl getTemplateData getAuditLogs getGroups getGroup saveGroup groupID2Name delGroup getUsers getUser userID2Name saveUser currDate lwd dec2bin checkRight importDNSTrans importDNSLocal fillHoles _gettext getParam - netID2Stuff getNetworkParentFromDB importConfig delUser getRights parseCSVConfigfile + netID2Stuff getNetworkParentFromDB importConfig delUser getRights parseCSVConfigfile exportSubnets removeStatus expand splitNet combineNets getDBNetworkBefore getNetID getPlugins updatePluginDB - getPluginsForNet pluginID2Name getTable checkTables updatePluginLastRun rootID2ipv6 - checkRootACL checkNetACL checkNetworkACTable netv6Dec2ipv6ID getPluginInfos getPluginConfMenu + getPluginsForNet pluginID2Name getTable checkTables updatePluginLastRun rootID2ipv6 changeTmplName + checkRootACL checkNetACL checkNetworkTable checkNetworkACTable netv6Dec2ipv6ID getPluginInfos getPluginConfMenu mkPluginConfig getNetworksForPlugin getPluginConfValues getNetworkChilds initTables initCache - finalizeTables getPluginLastRun pluginName2ID getPluginValue getHaCidInfo nd dn quoteHTML + finalizeTables getPluginLastRun pluginName2ID getPluginValue getHaCidInfo nd dn quoteHTML getAvailTags getFreeSubnets pluginID2File chOwnPW getSettings userName2ID updSettings updateSettingsInSession flushACLCache flushNetCache getConfigValue tmplName2ID tmplEntryDescr2EntryID searchAndGetFreeSubnets ); @@ -73,7 +75,7 @@ type => 'label', width => 500, align => 'left', - value => '
' . join("\n", @{$conf->{var}->{warnl}}) . '
' + value => '
' . join("\n", @{$conf->{var}->{warnl}}) . '
' }, ] }, @@ -177,15 +179,20 @@ my $name = shift; my $descr = shift; my $ipv6 = shift; - my $rootID = shift; + my $rootID = shift || 0; + my $editRoot = shift || 0; my $q = $HaCi::HaCi::q; my $session = $HaCi::HaCi::session; - my $editRoot = (defined $q->param('editRoot') && $q->param('editRoot')) ? 1 : 0; - my $bImp = (defined $q->param('submitImportASNRoutes') && $q->param('submitImportASNRoutes')) ? 1 : 0; - $bImp ||= (defined $q->param('submitImportDNS') && $q->param('submitImportDNS')) ? 1 : 0; $descr ||= ''; $ipv6 ||= 0; + my $bImp = 0; + if (ref($q)) { # NON-API access? + $editRoot = (&getParam(1, 0, 'editRoot')) ? 1 : 0; + $bImp = (&getParam(1, 0, 'submitImportASNRoutes')) ? 1 : 0; + $bImp ||= (&getParam(1, 0, 'submitImportDNS')) ? 1 : 0; + } + unless (defined $name && $name) { &warnl(sprintf(_gettext("Sorry, you have to give me a %s!"), 'name')); return 0; @@ -210,8 +217,12 @@ $rootTable->modifyFrom($session->param('username')); $rootTable->modifyDate(&currDate('datetime')); unless ($rootTable->update({ID => $rootID})) { - &warnl("Cannot update Root: " . $rootTable->errorStrs, $bImp); + my $errStr = "Cannot update Root: " . $rootTable->errorStrs; + &warnl($errStr); + &audit('root.update', $name, &tableContent2Str($rootTable), $errStr); return 0; + } else { + &audit('root.update', $name, &tableContent2Str($rootTable)); } } else { my $DBROOT = ($rootTable->search(['ID', 'name'], {name => $name}))[0]; @@ -224,16 +235,24 @@ $rootTable->modifyDate(&currDate('datetime')); &debug("Change Root-Entry for '$name'\n"); unless ($rootTable->update({ID => $DBROOT->{'ID'}})) { - &warnl("Cannot update Root: " . $rootTable->errorStrs, $bImp); + my $errStr = "Cannot update Root: " . $rootTable->errorStrs; + &warnl($errStr); + &audit('root.update', $name, &tableContent2Str($rootTable), $errStr); return 0; + } else { + &audit('root.update', $name, &tableContent2Str($rootTable)); } } else { $rootTable->ID(undef); $rootTable->createFrom($session->param('username')); $rootTable->createDate(&currDate('datetime')); unless ($rootTable->insert()) { - &warnl("Cannot insert new Root: " . $rootTable->errorStrs, $bImp); + my $errStr = "Cannot insert new Root: " . $rootTable->errorStrs; + &warnl($errStr); + &audit('root.add', $name, &tableContent2Str($rootTable), $errStr); return 0; + } else { + &audit('root.add', $name, &tableContent2Str($rootTable)); } } } @@ -247,7 +266,7 @@ foreach (@acls) { $rootACTable->clear(); unless ($rootACTable->delete({ID => $_->{ID}})) { - $errors .= $rootACTable->errorStrs() unless $bImp; + $errors .= $rootACTable->errorStrs(); } &removeACLEntry($rootID, 'root', $_->{groupID}); } @@ -259,34 +278,46 @@ $box->{$_} = 3; } - foreach ($q->param) { - if (/accGroup_([rwi])_(\d+)/) { - my $right = $1; - my $groupID = $2; - if ($right eq 'i') { - $box->{$groupID} = 0; - } else { - $box->{$groupID} += ($right eq 'r') ? 1 : ($right eq 'w') ? 2 : 0; + if (ref($q)) { # No API access? + foreach ($q->param) { + if (/accGroup_([rwi])_(\d+)/) { + my $right = $1; + my $groupID = $2; + if ($right eq 'i') { + $box->{$groupID} = 0; + } else { + $box->{$groupID} += ($right eq 'r') ? 1 : ($right eq 'w') ? 2 : 0; + } } } } $errors = ''; + my $auditData = ''; foreach (keys %{$box}) { + my $groupName = &groupID2Name($_); + unless ($groupName eq 'Administrator') { + my $acl = 'none'; + $acl = ($box->{$_} == 3) ? 'rw' : 'ro' if $box->{$_}; + $auditData .= ';' if $auditData; + $auditData .= $groupName . '=' . $acl; + } + $rootACTable->clear(); $rootACTable->rootID($rootID); $rootACTable->ID(undef); $rootACTable->groupID($_); $rootACTable->ACL($box->{$_}); unless ($rootACTable->insert()) { - $errors .= $rootACTable->errorStrs unless $bImp; + $errors .= $rootACTable->errorStrs; } &removeACLEntry($rootID, 'root', $_); } - &warnl("Errors while setting Root ACLs: " . $errors, $bImp) if $errors; + &warnl("Errors while setting Root ACLs: " . $errors) if $errors; + &audit('rootACL.update', $name, $auditData, $errors) if $auditData; } - warn "Successfully created Root $name"; + warn "Successfully " . (($editRoot) ? 'updated' : 'created') . " Root '$name'\n"; return 1; } @@ -313,28 +344,55 @@ my $tmplID = shift; my $defSubnetSize = shift || 0; my $forceState = shift || 0; - my $q = $HaCi::HaCi::q; + my $tmplDataBox = shift || 0; + my $editNet = shift || 0; + my $tags = shift || ''; + $tags =~ s/^\s+//; + $tags =~ s/\s+$//; + + my $dontChangeACL = 0; + my $dontChangePlugins = 0; + my $session = $HaCi::HaCi::session; - my $bImp = (defined $q->param('submitImportASNRoutes') && $q->param('submitImportASNRoutes')) ? 1 : 0; - $bImp ||= (defined $q->param('submitImpDNSTrans') && $q->param('submitImpDNSTrans')) ? 1 : 0; - $bImp ||= (defined $q->param('submitImpDNSLocal') && $q->param('submitImpDNSLocal')) ? 1 : 0; - $bImp ||= (defined $q->param('submitImpConfig') && $q->param('submitImpConfig')) ? 1 : 0; - $bImp ||= (defined $q->param('submitImpCSV') && $q->param('submitImpCSV')) ? 1 : 0; - my $onlyNew = (defined $q->param('onlyNew') && $q->param('onlyNew')) ? 1 : 0; - my $editNet = (defined $q->param('editNet') && $q->param('editNet')) ? 1 : 0; - my @netPluginActives = (defined $q->param('netPluginActives')) ? $q->param('netPluginActives') : (); - my @netPluginNewLines = (defined $q->param('netPluginNewLines')) ? $q->param('netPluginNewLines') : (); + my $q = $HaCi::HaCi::q; + + my $bImp = 0; + my $onlyNew = 0; + my $aclsFromParent = 0; + my $netPluginActives = []; + my $netPluginNewLines = []; + if (ref($q)) { + $bImp = (&getParam(1, 0, 'submitImportASNRoutes')) ? 1 : 0; + $bImp ||= (&getParam(1, 0, 'submitImpDNSTrans')) ? 1 : 0; + $bImp ||= (&getParam(1, 0, 'submitImpDNSLocal')) ? 1 : 0; + $bImp ||= (&getParam(1, 0, 'submitImpConfig')) ? 1 : 0; + $bImp ||= (&getParam(1, 0, 'submitImpCSV')) ? 1 : 0; + $onlyNew = (&getParam(1, 0, 'onlyNew')) ? 1 : 0; + $editNet = (&getParam(1, 0, 'editNet')) ? 1 : 0; + $netPluginActives = &getParam(0, [], 'netPluginActives'); + $netPluginNewLines = &getParam(0, [], 'netPluginNewLines'); + $aclsFromParent = (&getParam(1, 0, 'aclsFromParent')) ? 1 : 0; + $tmplDataBox = {}; + } else { + $dontChangeACL = 1; # you can't change ACLs by API, yet + $dontChangePlugins = 1; # you can't change Plugins by API, yet + } + my $rootInfos = &getMaintInfosFromRoot($rootID); my $ipv6 = $rootInfos->{ipv6}; my $ipv6ID = ''; eval { - $netaddress = Net::IPv6Addr::to_string_preferred($netaddress) if $ipv6 && $netaddress =~ /::/; + $netaddress = Net::IPv6Addr::to_string_preferred($netaddress) if $ipv6 && $netaddress =~ /::/; }; if ($@) { &warnl($@); return 0; } + if (ref($q) && !&getParam(1, 0, 'overwrite')) { + $onlyNew = (&getParam(1, 0, 'overwrite')) ? 0 : 1; + } + unless (&checkSpelling_IP($netaddress, $ipv6)) { &warnl("This Netaddress '$netaddress' is incorrect!"); return 0; @@ -345,6 +403,11 @@ return 0; } + if (($defSubnetSize != 0 && $defSubnetSize <= $cidr) || ($ipv6 && $defSubnetSize > 128) || (!$ipv6 && $defSubnetSize > 32)) { + &warnl("This default subnet size '$defSubnetSize' is incorrect!"); + return 0; + } + my $networkTable = $conf->{var}->{TABLES}->{network}; unless (defined $networkTable) { warn "Cannot add Network. DB Error (network)\n"; @@ -357,12 +420,12 @@ } unless (defined $rootID && $rootID) { - &warnl(sprintf(_gettext("Sorry, you have to give me a %s!"), 'rootID'), $bImp); + &warnl(sprintf(_gettext("Sorry, you have to give me a %s!"), 'rootID')); return 0; } unless (defined $netaddress && $netaddress) { - &warnl(sprintf(_gettext("Sorry, you have to give me a %s!"), 'netaddress'), $bImp); + &warnl(sprintf(_gettext("Sorry, you have to give me a %s!"), 'netaddress')); return 0; } @@ -381,19 +444,21 @@ } if (lc($netaddress) ne lc($netaddressT)) { - &warnl(sprintf(_gettext("Sorry, this is not a correct Network: %s!"), $netaddress . '/' . $cidr), $bImp); + &warnl(sprintf(_gettext("Sorry, this is not a correct Network: %s!"), $netaddress . '/' . $cidr)); return 0; } my $network = $netaddress . '/' . $cidr; - &debug((($editNet) ? 'Edit' : 'Add') . " Network $network on " . &rootID2Name($rootID)); + &debug((($editNet) ? 'Edit' : 'Add') . " Network $network on " . $rootInfos->{name}); unless (&checkSpelling_Net($network, $ipv6)) { - &warnl(sprintf(_gettext("Sorry, this doesn't look like a %s: '%s'!"), 'network', $network), $bImp); + &warnl(sprintf(_gettext("Sorry, this doesn't look like a %s: '%s'!"), 'network', $network)); return 0; } my $networkDec = ($ipv6) ? &netv62Dec($network) : &net2dec($network); + return 0 unless &checkNetworkLock($rootID, $networkDec, $ipv6); + if ($bImp) { $ipv6ID = Net::IPv6Addr::to_string_base85($netaddress) . sprintf("%x", $cidr) if $ipv6; my $DBNET = ($networkTable->search(['ID'], {rootID => $rootID, network => (($ipv6) ? 0 : $networkDec), ipv6ID => $ipv6ID}))[0]; @@ -413,15 +478,15 @@ my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); unless (&checkNetACL($netID, 'w')) { - &warnl(sprintf(_gettext("Not enough rights to edit this Network '%s'"), $network), $bImp); + &warnl(sprintf(_gettext("Not enough rights to edit this Network '%s'"), $network)); return 0; } - unless ($q->param('submitImpCSV')) { - &debug("Flushing Cache for: " . &rootID2Name($rootID)); + unless (ref($q) && &getParam(1, 0, 'submitImpCSV')) { + &debug("Flushing Cache for: " . $rootInfos->{name}); &removeFromNetcache($rootID); } } else { - &warnl("Without a netID I cannot edit this Net!", $bImp); + &warnl("Without a netID I cannot edit this Net!"); return 0; } } @@ -433,7 +498,7 @@ unless (($parentID && &checkNetACL($parentID, 'w')) || (!$parentID && &checkRootACL($rootID, 'w'))) { my $parent = ($ipv6) ? &netv6Dec2net($parentDec) : &dec2net($parentDec); - &warnl(sprintf(_gettext("Not enough rights to add this Network '%s' under '%s'"), $network, $parent), $bImp); + &warnl(sprintf(_gettext("Not enough rights to add this Network '%s' under '%s'"), $network, $parent)); return 0; } } @@ -464,39 +529,48 @@ $networkTable->tmplID($tmplID); $networkTable->ipv6ID($ipv6ID); $networkTable->defSubnetSize($defSubnetSize); + $networkTable->searchStr($network); + my $auditData = "root => $rootInfos->{name}, description => $descr, state => " . &networkStateID2Name($state) . ", template => " . &tmplID2Name($tmplID) . ", defSubnetSize => $defSubnetSize"; my $origTmplID = undef; if ($editNet) { - my $DBNET = ($networkTable->search(['ID', 'tmplID', 'ipv6ID'], {ID => $netID}))[0]; + my $DBNET = ($networkTable->search(['ID', 'rootID', 'tmplID', 'ipv6ID'], {ID => $netID}))[0]; unless (defined $DBNET) { - &warnl("Cannot update Net: No such Network exists ($netID)", $bImp); + &warnl("Cannot update Net: No such Network exists ($netID)"); return 0; } - $origTmplID = $DBNET->{'tmplID'}; + $origTmplID = $DBNET->{'tmplID'}; $networkTable->modifyFrom($session->param('username')); $networkTable->modifyDate(&currDate('datetime')); unless ($networkTable->update({ID => $netID})) { - &warnl("Cannot update Net: " . $networkTable->errorStrs, $bImp); + my $errStr = "Cannot update Net: " . $networkTable->errorStrs; + &warnl($errStr); + &audit('network.update', $network, $auditData, $errStr); return 0; + } else { + &audit('network.update', $network, $auditData); } + if ($ipv6) { unless (defined $DBNET) { - &warnl("Cannot update Net: No such Network exists ($netID)", $bImp); + &warnl("Cannot update Net: No such Network exists ($netID)"); return 0; } - unless ($networkV6Table->update({ID => $DBNET->{'ipv6ID'}, rootID => $rootID})) { - &warnl("Cannot update V6 Net: " . $networkV6Table->errorStrs, $bImp); + my $origRootID = $DBNET->{'rootID'}; + unless ($networkV6Table->update({ID => $DBNET->{'ipv6ID'}, rootID => $origRootID})) { + my $errStr = "Cannot update V6 Net: " . $networkV6Table->errorStrs; + &warnl($errStr); return 0; } } - unless ($q->param('submitImpCSV')) { - &debug("Flushing Cache for: " . &rootID2Name($rootID)); + unless (ref($q) && &getParam(1, 0, 'submitImpCSV')) { + &debug("Flushing Cache for: " . $rootInfos->{name}); &removeFromNetcache($rootID); } } else { - my $DBNET = ($networkTable->search(['ID'], {network => $networkDec, rootID => $rootID, ipv6ID => $ipv6ID}))[0]; + my $DBNET = ($networkTable->search(['ID'], {network => ($ipv6) ? 0 : $networkDec, rootID => $rootID, ipv6ID => $ipv6ID}))[0]; if (defined $DBNET) { - &warnl(sprintf(_gettext("This Network '%s' allready exists!"), $network), $bImp); + &warnl(sprintf(_gettext("This Network '%s' allready exists!"), $network)); return 0; } @@ -504,191 +578,272 @@ $networkTable->createFrom($session->param('username')); $networkTable->createDate(&currDate('datetime')); unless ($networkTable->insert()) { - &warnl("Cannot add Net: " . $networkTable->errorStrs, $bImp); + my $errStr = "Cannot add Net: " . $networkTable->errorStrs; + &warnl($errStr); + &audit('network.add', $network, $auditData, $errStr); return 0; + } else { + &audit('network.add', $network, $auditData); } if ($ipv6) { unless ($networkV6Table->insert()) { - &warnl("Cannot add V6 Net: " . $networkV6Table->errorStrs, $bImp); + my $errStr = "Cannot add V6 Net: " . $networkV6Table->errorStrs; + &warnl($errStr); return 0; } } - unless ($q->param('submitImpCSV')) { - &debug("Flushing Cache for: " . &rootID2Name($rootID)); + unless (ref($q) && &getParam(1, 0, 'submitImpCSV')) { + &debug("Flushing Cache for: " . $rootInfos->{name}); &removeFromNetcache($rootID); } } $netID = &getNetID($rootID, $networkDec, $ipv6ID) unless $editNet; - my $networkACTable = $conf->{var}->{TABLES}->{networkAC}; - unless (defined $networkACTable) { - warn "Cannot add Network ACL. DB Error (networkAC)\n"; - } else { - my @acls = $networkACTable->search(['ID', 'groupID'], {netID => $netID}); - my $errors = ''; - foreach (@acls) { - &debug("Deleting NetworkACL ID: " . $_->{ID} . "\n"); - my $groupID = $_->{groupID}; - - $networkACTable->clear(); - unless ($networkACTable->delete({ID => $_->{ID}})) { - $errors .= $networkACTable->errorStrs() unless $bImp; + my $networkTagTable = $conf->{var}->{TABLES}->{networkTag}; + unless (defined $networkTagTable) { + warn "Cannot add Network Tags. DB Error (networkTag)\n"; + } else { + my @tagsDB = $networkTagTable->search(['ID'], {netID => $netID}); + my $errors = ''; + foreach (@tagsDB) { + &debug("Deleting network tag ID: " . $_->{ID} . "\n"); + + $networkTagTable->clear(); + unless ($networkTagTable->delete({ID => $_->{ID}})) { + $errors .= $networkTagTable->errorStrs(); } - &removeACLEntry($netID, 'net', $groupID); } &warnl($errors) if $errors; + foreach (split(/\s+/, $tags)) { + my $tag = $_; + $networkTagTable->clear(); + $networkTagTable->netID($netID); + $networkTagTable->ID(undef); + $networkTagTable->tag($tag); + unless ($networkTagTable->insert()) { + $errors .= $networkTagTable->errorStrs; + } + } + &warnl("Errors while setting network tags: " . $errors) if $errors; + &audit('networkTag.update', $network, $tags, $errors); + } + + unless ($dontChangeACL) { + my $networkACTable = $conf->{var}->{TABLES}->{networkAC}; + unless (defined $networkACTable) { + warn "Cannot add Network ACL. DB Error (networkAC)\n"; + } else { + my @acls = $networkACTable->search(['ID', 'groupID'], {netID => $netID}); + my $errors = ''; + foreach (@acls) { + &debug("Deleting NetworkACL ID: " . $_->{ID} . "\n"); + my $groupID = $_->{groupID}; - my $box = {}; - foreach (split(/, /, $session->param('groupIDs'))) { - s/\D//g; - my $acl = &checkNetACL($netID, 'ACL', $_); - $box->{$_} = ($acl == 3) ? -1 : 3; - } + $networkACTable->clear(); + unless ($networkACTable->delete({ID => $_->{ID}})) { + $errors .= $networkACTable->errorStrs(); + } + &removeACLEntry($netID, 'net', $groupID); + } + &warnl($errors) if $errors; - foreach ($q->param('accGroup')) { - my $groupID = $_; - my $acl = &checkNetACL($netID, 'ACL', $groupID); - $box->{$groupID} = 0; - foreach ('r', 'w') { - my $right = $_; - if ($q->param('accGroup_' . $right . '_' . $groupID)) { - $box->{$groupID} += (($right eq 'r') ? 1 : (($right eq 'w') ? 2 : 0)); + my $box = {}; + unless ($aclsFromParent) { + foreach (split(/, /, $session->param('groupIDs'))) { + s/\D//g; + my $acl = &checkNetACL($netID, 'ACL', $_); + $box->{$_} = ($acl == 3) ? -1 : 3; + } + + if (ref($q)) { + my $accGroups = &getParam(0, [], 'accGroup'); + foreach (@{$accGroups}) { + my $groupID = $_; + my $acl = &checkNetACL($netID, 'ACL', $groupID); + $box->{$groupID} = 0; + foreach ('r', 'w') { + my $right = $_; + if (&getParam(1, 0, 'accGroup_' . $right . '_' . $groupID)) { + $box->{$groupID} += (($right eq 'r') ? 1 : (($right eq 'w') ? 2 : 0)); + } + } + $box->{$groupID} = -1 if $box->{$groupID} == $acl; + } } } - $box->{$groupID} = -1 if $box->{$groupID} == $acl; - } - $errors = ''; - foreach (keys %{$box}) { - my $groupID = $_; - next if $box->{$groupID} == -1; + $errors = ''; + my $auditData = ''; + foreach (keys %{$box}) { + my $groupID = $_; + next if $box->{$groupID} == -1; + + my $groupName = &groupID2Name($groupID); + unless ($groupName eq 'Administrator') { + my $acl = 'none'; + $acl = ($box->{$_} == 3) ? 'rw' : 'ro' if $box->{$_}; + $auditData .= ';' if $auditData; + $auditData .= $groupName . '=' . $acl; + } - $networkACTable->clear(); - $networkACTable->netID($netID); - $networkACTable->ID(undef); - $networkACTable->groupID($groupID); - $networkACTable->ACL($box->{$_}); - unless ($networkACTable->insert()) { - $errors .= $networkACTable->errorStrs unless $bImp; + $networkACTable->clear(); + $networkACTable->netID($netID); + $networkACTable->ID(undef); + $networkACTable->groupID($groupID); + $networkACTable->ACL($box->{$_}); + unless ($networkACTable->insert()) { + $errors .= $networkACTable->errorStrs; + } + &removeACLEntry($netID, 'net', $groupID); } - &removeACLEntry($netID, 'net', $groupID); + &warnl("Errors while setting Network ACLs: " . $errors) if $errors; + &audit('networkACL.update', $network, $auditData, $errors) if $auditData; } - &warnl("Errors while setting Network ACLs: " . $errors, $bImp) if $errors; } - if ($tmplID) { - my $tmplValueTable = $conf->{var}->{TABLES}->{templateValue}; - unless (defined $tmplValueTable) { - warn "Cannot add Template Value. DB Error (templateValue)\n"; - return 0; - } + if ($tmplDataBox && ref($tmplDataBox) eq 'HASH') { + if ($tmplID) { + my $tmplValueTable = $conf->{var}->{TABLES}->{templateValue}; + unless (defined $tmplValueTable) { + warn "Cannot add Template Value. DB Error (templateValue)\n"; + return 0; + } + + if (ref($q)) { + foreach ($q->param) { + if (/^tmplEntryID_(\d+)$/) { + my $tmplEntryID = $1; + next unless $tmplEntryID; + + my $value = &getParam(1, '', 'tmplEntryID_' . $tmplEntryID); + $tmplDataBox->{$tmplEntryID} = $value; + } + } + }; + + my $auditData = ''; + foreach (keys %{$tmplDataBox}) { + my $tmplEntryID = $_; + my $value = $tmplDataBox->{$tmplEntryID}; + if (ref($value)) { + &warnl("Only strings are allowed for template values! (not " . ref($value) . ")\n"); + &delNet($netID, 0, 0, 0) unless $editNet; + return 0; + } - foreach ($q->param) { - if (/^tmplEntryID_(\d+)$/) { - my $tmplEntryID = $1; - next unless $tmplEntryID; $tmplValueTable->clear(); $tmplValueTable->netID($netID); $tmplValueTable->tmplID($tmplID); $tmplValueTable->tmplEntryID($tmplEntryID); - $tmplValueTable->value(&getParam(1, '', $q->param('tmplEntryID_' . $tmplEntryID))); + $tmplValueTable->value($value); + + my $tmplEntryDescr = &tmplEntryID2Name($tmplEntryID); + $auditData .= "$tmplEntryDescr => $value "; my $DB = ($tmplValueTable->search(['ID'], {netID => $netID, tmplID => $tmplID, tmplEntryID => $tmplEntryID}))[0]; if ($DB) { &debug("Change Template-Value for '$rootID:$network $tmplID:$tmplEntryID'\n"); unless ($tmplValueTable->update({ID => $DB->{'ID'}})) { - &warnl("Cannot update Template Value: " . $tmplValueTable->errorStrs); + my $errStr = "Cannot update Template Value: " . $tmplValueTable->errorStrs; + &warnl($errStr); return 0; } } else { $tmplValueTable->ID(undef); unless ($tmplValueTable->insert()) { - &warnl("Cannot add Template Value: " . $tmplValueTable->errorStrs); + my $errStr = "Cannot add Template Value: " . $tmplValueTable->errorStrs; + &warnl($errStr); return 0; } } } + &audit('templateValue.update', $network, $auditData); } - } - if (defined $origTmplID && $origTmplID != $tmplID && $origTmplID) { - my $tmplValueTable = $conf->{var}->{TABLES}->{templateValue}; - unless (defined $tmplValueTable) { - warn "Cannot remove old Template Values. DB Error (templateValue)\n"; - return 1; - } - my @oldEntries = $tmplValueTable->search(['ID'], {netID => $netID, tmplID => $origTmplID}); - my $errors = ''; - foreach (@oldEntries) { - &debug("Deleting Template Value for ID: " . $_->{ID} . "\n"); - $tmplValueTable->errorStrs(''); - unless ($tmplValueTable->delete({ID => $_->{ID}})) { - $errors .= $tmplValueTable->errorStrs(); + if (defined $origTmplID && $origTmplID != $tmplID && $origTmplID) { + my $tmplValueTable = $conf->{var}->{TABLES}->{templateValue}; + unless (defined $tmplValueTable) { + warn "Cannot remove old Template Values. DB Error (templateValue)\n"; + return 1; + } + my @oldEntries = $tmplValueTable->search(['ID'], {netID => $netID, tmplID => $origTmplID}); + my $errors = ''; + foreach (@oldEntries) { + &debug("Deleting Template Value for ID: " . $_->{ID} . "\n"); + $tmplValueTable->errorStrs(''); + unless ($tmplValueTable->delete({ID => $_->{ID}})) { + $errors .= $tmplValueTable->errorStrs(); + } } + &warnl($errors) if $errors; } - &warnl($errors) if $errors; - } - - my $networkPluginTable = $conf->{var}->{TABLES}->{networkPlugin}; - unless (defined $networkPluginTable) { - warn "Cannot update PluginDB. DB Error (networkPlugin)\n"; - return 0; - } - $networkPluginTable->clear(); - - my $netPlugins = {}; - my $availPlugins = &getPlugins(); - my $pluginsForNet = &getPluginsForNet($netID); - foreach (keys %{$pluginsForNet}) { - $netPlugins->{$_}->{ACTIVE} = 1;# unless $availPlugins->{$_}->{DEFAULT}; } - my $errors = ''; - foreach (@netPluginActives) { - my $pluginID = $_; - my $pluginOrder = &getParam(1, 0, $q->param('pluginOrder_' . $pluginID)); - my $entry = ($networkPluginTable->search(['ID'], {netID => $netID, pluginID => $pluginID}))[0]; + unless ($dontChangePlugins) { + my $networkPluginTable = $conf->{var}->{TABLES}->{networkPlugin}; + unless (defined $networkPluginTable) { + warn "Cannot update PluginDB. DB Error (networkPlugin)\n"; + return 0; + } $networkPluginTable->clear(); - $networkPluginTable->netID($netID); - $networkPluginTable->pluginID($pluginID); - $networkPluginTable->sequence($pluginOrder); - $networkPluginTable->newLine(scalar grep {/^$pluginID$/} @netPluginNewLines); - unless (defined $entry) { - &debug("Adding Plugin '$availPlugins->{$pluginID}->{NAME}' for network '$network'\n"); - unless ($networkPluginTable->insert()) { - $errors .= "Cannot insert Network Plugin Entry for '$availPlugins->{$pluginID}->{NAME}': " . $networkPluginTable->errorStrs(); - } - } else { - my $ID = $entry->{ID}; - &debug("Updating Plugin '$availPlugins->{$pluginID}->{NAME}' for network '$network'\n"); - unless ($networkPluginTable->update({ID => $ID})) { - $errors .= "Cannot update Network Plugin Entry for '$availPlugins->{$pluginID}->{NAME}': " . $networkPluginTable->errorStrs(); - } - } - delete $netPlugins->{$pluginID}; - } - foreach (keys %{$netPlugins}) { - my $pluginID = $_; - my $entry = ($networkPluginTable->search(['ID'], {netID => $netID, pluginID => $pluginID}))[0]; - if (defined $entry) { - &debug("Deleting Plugin '$availPlugins->{$pluginID}->{NAME}' from network '$network'\n"); + my $netPlugins = {}; + my $availPlugins = &getPlugins(); + my $pluginsForNet = &getPluginsForNet($netID); + foreach (keys %{$pluginsForNet}) { + $netPlugins->{$_}->{ACTIVE} = 1;# unless $availPlugins->{$_}->{DEFAULT}; + } + my $errors = ''; + foreach (@{$netPluginActives}) { + my $pluginID = $_; + my $pluginOrder = 0; + my $entry = ($networkPluginTable->search(['ID'], {netID => $netID, pluginID => $pluginID}))[0]; + $pluginOrder = &getParam(1, 0, 'pluginOrder_' . $pluginID) if ref($q); + $networkPluginTable->clear(); - $networkPluginTable->delete({netID => $netID, pluginID => $pluginID}); - if ($networkPluginTable->error) { - $errors .= '\n' . sprintf(_gettext("Error while deleting '%s' from '%s': %s"), $availPlugins->{$pluginID}->{NAME}, $network, $networkPluginTable->errorStrs); + $networkPluginTable->netID($netID); + $networkPluginTable->pluginID($pluginID); + $networkPluginTable->sequence($pluginOrder); + $networkPluginTable->newLine(scalar grep {/^$pluginID$/} @{$netPluginNewLines}); + unless (defined $entry) { + &debug("Adding Plugin '$availPlugins->{$pluginID}->{NAME}' for network '$network'\n"); + unless ($networkPluginTable->insert()) { + $errors .= "Cannot insert Network Plugin Entry for '$availPlugins->{$pluginID}->{NAME}': " . $networkPluginTable->errorStrs(); + } + } else { + my $ID = $entry->{ID}; + &debug("Updating Plugin '$availPlugins->{$pluginID}->{NAME}' for network '$network'\n"); + unless ($networkPluginTable->update({ID => $ID})) { + $errors .= "Cannot update Network Plugin Entry for '$availPlugins->{$pluginID}->{NAME}': " . $networkPluginTable->errorStrs(); + } + } + delete $netPlugins->{$pluginID}; + } + foreach (keys %{$netPlugins}) { + my $pluginID = $_; + my $entry = ($networkPluginTable->search(['ID'], {netID => $netID, pluginID => $pluginID}))[0]; + + if (defined $entry) { + &debug("Deleting Plugin '$availPlugins->{$pluginID}->{NAME}' from network '$network'\n"); + $networkPluginTable->clear(); + $networkPluginTable->delete({netID => $netID, pluginID => $pluginID}); + if ($networkPluginTable->error) { + $errors .= '\n' . sprintf(_gettext("Error while deleting '%s' from '%s': %s"), $availPlugins->{$pluginID}->{NAME}, $network, $networkPluginTable->errorStrs); + } } } + &warnl($errors) if $errors; } - &warnl($errors) if $errors; return 1; } sub getRoots { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + my $checkACL = shift || 0; + my $rootTable = $conf->{var}->{TABLES}->{root}; unless (defined $rootTable) { warn "Cannot get Roots. DB Error (root)\n"; @@ -697,6 +852,9 @@ my @rootst = $rootTable->search(['ID', 'name', 'ipv6']); my $rootst = {}; foreach (@rootst) { + my $id = $_->{ID}; + next if $checkACL && !&checkRootACL($id, 'r'); + $rootst->{$_->{name}} = { ID => $_->{ID}, ipv6 => $_->{ipv6}, @@ -719,13 +877,13 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $asn = shift; my $q = $HaCi::HaCi::q; - my $delOld = (defined $q->param('delOld') && $q->param('delOld')) ? 1 : 0; + my $delOld = (&getParam(1, 0, 'delOld')) ? 1 : 0; $asn = 'AS' . $asn unless $asn =~ /^AS/; my $status = $conf->{var}->{STATUS}; $status->{TITLE} = "Importing Routes for '$asn'..."; $status->{STATUS} = 'Runnung...'; $status->{PERCENT} = 0; &setStatus(); - unless ($asn =~ /^AS\d{1,5}$/) { - &warnl(sprintf(_gettext("Sorry, this doesn't look like a %s: '%s'!"), 'AS Number', $asn)); + unless ($asn =~ /^AS\d{1,10}$/) { + &warnl(sprintf(_gettext("Sorry, this doesn't look like a %s: '%s'!"), 'AS Number in asplain notation', $asn)); return 0; } @@ -820,11 +978,11 @@ unless ($ipv4Used) { my $root = ($rootTable->search(['ID'], {name => $asn}))[0]; - $rootTable->delete({ID => $root->{ID}}) if defined $root && exists $root->{ID}; + &delRoot($root->{ID}) if defined $root && exists $root->{ID}; } unless ($ipv6Used) { my $rootV6 = ($rootTable->search(['ID'], {name => $asn . '_IPv6'}))[0]; - $rootTable->delete({ID => $rootV6->{ID}}) if defined $rootV6 && exists $rootV6->{ID}; + &delRoot($rootV6->{ID}) if defined $rootV6 && exists $rootV6->{ID}; } &warnl(sprintf(_gettext("%i Routes found. Saved %i new Inetnums of %i found"), $nrOfRoutes, $nrOfSaves, $nrOfINs)); @@ -915,11 +1073,11 @@ sub importDNSTrans { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - my $nsServer = &getParam(1, '', $q->param('nameserver')); - my $domain = &getParam(1, '', $q->param('domain')); - my $status = &getParam(1, 0, $q->param('state')); - my $origin = &getParam(1, '', $q->param('origin')); - my $targetRootID = &getParam(1, -1, $q->param('targetRoot')); + my $nsServer = &getParam(1, '', 'nameserver'); + my $domain = &getParam(1, '', 'domain'); + my $status = &getParam(1, 0, 'state'); + my $origin = &getParam(1, '', 'origin'); + my $targetRootID = &getParam(1, -1, 'targetRoot'); my $stat = $conf->{var}->{STATUS}; $stat->{TITLE} = "Importing DNS Zonefile from Server '$nsServer'";$stat->{STATUS} = 'Running...'; $stat->{PERCENT} = 0; &setStatus(); @@ -991,10 +1149,10 @@ sub importConfig { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - my $file = &getParam(1, undef, $q->param('config')); - my $source = &getParam(1, undef, $q->param('source')); - my $state = &getParam(1, 0, $q->param('state')); - my $targetRootID = &getParam(1, -1, $q->param('targetRoot')); + my $file = &getParam(1, undef, 'config'); + my $source = &getParam(1, undef, 'source'); + my $state = &getParam(1, 0, 'state'); + my $targetRootID = &getParam(1, -1, 'targetRoot'); my $configFile = ''; my $data = ''; my $session = $HaCi::HaCi::session; @@ -1067,33 +1225,52 @@ } $rootName = (($targetRootID == -1) ? $rootName : &rootID2Name($targetRootID)); - $rootName =~ s/_v6$//; $rootName ||= $file; my @cnter = (0, 0); if ($#$box > -1) { - my $rootID = -1; - my $rootIDv4 = &rootName2ID($rootName) || -1; - my $rootIDv6 = &rootName2ID($rootName . '_v6') || -1; + my $rootIDv4; + my $rootNamev4; + my $rootIDv6; + my $rootNamev6; + my $rootID = &rootName2ID($rootName) || -1; + if ($rootID != -1) { + my $bIPv6 = &rootID2ipv6($rootID); + if ($bIPv6) { + $rootNamev4 = $rootName . '_v4'; + $rootNamev6 = $rootName; + $rootIDv4 = &rootName2ID($rootNamev4) || -1; + $rootIDv6 = $rootID; + } else { + $rootNamev4 = $rootName; + $rootNamev6 = $rootName . '_v6'; + $rootIDv4 = $rootID; + $rootIDv6 = &rootName2ID($rootNamev6) || -1; + } + } else { + $rootNamev4 = $rootName . '_v4'; + $rootNamev6 = $rootName . '_v6'; + } my $v4 = 1; + foreach my $entry (@$box) { if ($entry->{ip} =~ /^[\d\.]+$/) { if ($rootIDv4 == -1) { - unless (&addRoot($rootName)) { + unless (&addRoot($rootNamev4)) { warn "AddRoot failed!\n"; return 0; } - $rootIDv4 = &rootName2ID($rootName); + $rootIDv4 = &rootName2ID($rootNamev4); } $rootID = $rootIDv4; $v4 = 1; } elsif ($entry->{ip} =~ /^[\w\:]+$/) { if ($rootIDv6 == -1) { - unless (&addRoot($rootName . '_v6', '', 1)) { + unless (&addRoot($rootNamev6, '', 1)) { warn "AddRoot failed!\n"; return 0; } - $rootIDv6 = &rootName2ID($rootName . '_v6'); + $rootIDv6 = &rootName2ID($rootNamev6); } $rootID = $rootIDv6; $v4 = 0; @@ -1101,7 +1278,7 @@ warn "Cannot add Network '" . $entry->{ip} . "' because it's malformed!\n"; next; } - if(&addNet(0, $rootID, $entry->{ip}, $entry->{cidr}, $entry->{descr}, $status, 0, 0, 1)) { + if(&addNet(0, $rootID, $entry->{ip}, $entry->{cidr}, $entry->{descr}, $state, 0, 0, 1)) { ($v4) ? $cnter[0]++ : $cnter[1]++; } } @@ -1115,11 +1292,11 @@ sub importCSV { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - my $configFileID = &getParam(1, undef, $q->param('configFileID')); - my $fileName = &getParam(1, undef, $q->param('config')); - my $status = &getParam(1, 0, $q->param('status')); - my $targetRootID = &getParam(1, -1, $q->param('targetRoot')); - my $tmplID = &getParam(1, 0, $q->param('tmplID')); + my $configFileID = &getParam(1, undef, 'configFileID'); + my $fileName = &getParam(1, undef, 'config'); + my $state = &getParam(1, 0, 'state'); + my $targetRootID = &getParam(1, -1, 'targetRoot'); + my $tmplID = &getParam(1, 0, 'tmplID'); my $stat = $conf->{var}->{STATUS}; $stat->{TITLE} = "Importing CSV '$fileName'";$stat->{STATUS} = 'Running...'; $stat->{PERCENT} = 0; &setStatus(); @@ -1151,7 +1328,7 @@ foreach ($q->param) { if (/^COL_(\d+)$/) { - $cnv->{$1} = $q->param($_); + $cnv->{$1} = &getParam(1, undef, $_); } } @@ -1159,56 +1336,85 @@ my @cnter = (0, 0); my $rootIDs = {}; foreach (@data) { - my $cnter = 0; - my @cols = @{$_}; - my $network = ''; - my $status = 0; - my $description = ''; - my $percent = int(($colCnter++ / ($#data + 1)) * 100); + my $cnter = 0; + my @cols = @{$_}; + my $network = ''; + my $status = ''; + my $description = ''; + my $tags = ''; + my $defSubnetSize = 0; + my $percent = int(($colCnter++ / (($#data + 1) || 1)) * 100); foreach (@cols) { $cnter++; - $network = $_ if $cnv->{$cnter} == -1; - $status = $_ if $cnv->{$cnter} == -2; - $description = $_ if $cnv->{$cnter} == -3; + $network = $_ if $cnv->{$cnter} == -1; + $status = $_ if $cnv->{$cnter} == -2; + $description = $_ if $cnv->{$cnter} == -3; + $tags = $_ if $cnv->{$cnter} == -4; + $defSubnetSize = $_ if $cnv->{$cnter} == -5; if ($cnv->{$cnter} > 0) { $q->delete('tmplEntryID_' . $cnv->{$cnter}); $q->param('tmplEntryID_' . $cnv->{$cnter}, $_); } } next unless $network; + if ($status ne '') { + my $origStatus = $status; + $status = &networkStateName2ID($status); + &warnl(sprintf(_gettext("%s: Status (%s) not known"), $network, $origStatus)) if (!$status && $origStatus ne 'UNSPECIFIED'); + } + $status ||= $state; + $stat->{DATA} = "Importing Network '$network' ($description)"; $stat->{PERCENT} = $percent; &setStatus(); my ($ip, $cidr) = split/\//, $network; my $rootName = (($targetRootID == -1) ? $fileName : &rootID2Name($targetRootID)); - $rootName =~ s/_v6$//; - my $rootID = -1; - my $rootIDv4 = &rootName2ID($rootName) || -1; - my $rootIDv6 = &rootName2ID($rootName . '_v6') || -1; + my $rootIDv4 = -1; + my $rootNamev4 = ''; + my $rootIDv6 = -1; + my $rootNamev6 = ''; + my $rootID = &rootName2ID($rootName) || -1; + if ($rootID != -1) { + my $bIPv6 = &rootID2ipv6($rootID); + if ($bIPv6) { + $rootNamev4 = $rootName . '_v4'; + $rootNamev6 = $rootName; + $rootIDv4 = &rootName2ID($rootNamev4) || -1; + $rootIDv6 = $rootID; + } else { + $rootNamev4 = $rootName; + $rootNamev6 = $rootName . '_v6'; + $rootIDv4 = $rootID; + $rootIDv6 = &rootName2ID($rootNamev6) || -1; + } + } else { + $rootNamev4 = $rootName . '_v4'; + $rootNamev6 = $rootName . '_v6'; + } my $v = 4; if (&checkSpelling_Net($network, 0)) { if ($rootIDv4 == -1) { - unless (&checkIfRootExists($rootName)) { - unless (&addRoot($rootName, '', 0)) { + unless (&checkIfRootExists($rootNamev4)) { + unless (&addRoot($rootNamev4, '', 0)) { warn "AddRoot failed!\n"; $stat->{STATUS} = 'ERROR'; $stat->{DATA} = ''; $stat->{PERCENT} = 100; &setStatus(); return 0; } } - $rootIDv4 = &rootName2ID($rootName); + $rootIDv4 = &rootName2ID($rootNamev4); } $rootID = $rootIDv4; $v = 4; } elsif (&checkSpelling_Net($network, 1)) { if ($rootIDv6 == -1) { - unless (&checkIfRootExists($rootName . '_v6')) { - unless (&addRoot($rootName . '_v6', '', 1)) { + unless (&checkIfRootExists($rootNamev6)) { + unless (&addRoot($rootNamev6, '', 1)) { warn "AddRoot failed!\n"; $stat->{STATUS} = 'ERROR'; $stat->{DATA} = ''; $stat->{PERCENT} = 100; &setStatus(); return 0; } } - $rootIDv6 = &rootName2ID($rootName . '_v6'); + $rootIDv6 = &rootName2ID($rootNamev6); } $rootID = $rootIDv6; $v = 6; @@ -1236,10 +1442,10 @@ $rootIDs->{$rootID} = 1; if ($ip eq $netaddress) { - $cnter[0 + (($v == 6) ? 1 : 0)]++ if &addNet(0, $rootID, $ip, $cidr, $description, $status, $tmplID, 0, 1); + $cnter[0 + (($v == 6) ? 1 : 0)]++ if &addNet(0, $rootID, $ip, $cidr, $description, $status, $tmplID, $defSubnetSize, 1, 0, 0, $tags); } else { $cnter[0 + (($v == 6) ? 1 : 0)]++ if &addNet(0, $rootID, $netaddress, $cidr, '', 0, $tmplID, 0, 1); - $cnter[0 + (($v == 6) ? 1 : 0)]++ if &addNet(0, $rootID, $ip, $stdCidr, $description, $status, $tmplID, 0, 1); + $cnter[0 + (($v == 6) ? 1 : 0)]++ if &addNet(0, $rootID, $ip, $stdCidr, $description, $status, $tmplID, $defSubnetSize, 1, 0, 0, $tags); } } foreach (keys %{$rootIDs}) { @@ -1258,7 +1464,7 @@ my $configFileID = shift; my $bPreview = shift || 0; my $q = $HaCi::HaCi::q; - my $sep = &getParam(1, undef, $q->param('sep')); + my $sep = &getParam(1, undef, 'sep'); my @box = []; my $nrOfCols = 0; my $stat = $conf->{var}->{STATUS}; @@ -1266,20 +1472,21 @@ $stat->{TITLE} = "Parsing CSV file."; $stat->{STATUS} = 'Runnung...'; $stat->{PERCENT} = 5; &setStatus(); unless (defined $sep) { - $sep = ';'; - $q->param('sep', ';'); + $sep = ','; + $q->param('sep', ','); } eval { - require Text::CSV_XS; + require Text::CSV; }; if ($@) { warn $@; return (); } - my $csv = Text::CSV_XS->new({ - 'sep_char' => $sep - }); + my $csv = Text::CSV->new({ + 'sep_char' => $sep, + binary => 1 + }) or die "Cannot use CSV: ".Text::CSV->error_diag (); unless (open EXPORT, $conf->{static}->{path}->{spoolpath} . '/' . "$configFileID.tmp") { &warnl("Cannot open Temp File '$conf->{static}->{path}->{spoolpath}/$configFileID.tmp' for reading: $!"); @@ -1306,7 +1513,9 @@ $error = 1; &warnl("CVS Error in line $line: " . $csv->error_diag()); } - unless ($line % ($maxLines / 4)) { + my $ml = ($maxLines / 4); + $ml = 1 if $ml < 1; + unless ($line % $ml) { $stat->{TITLE} = "Parsing CSV file." . '.' x (int($line * 4 / $maxLines)); $stat->{STATUS} = 'Runnung...'; $stat->{PERCENT} = (5 + (int($line * 4 / $maxLines))); &setStatus(); } $line++; @@ -1368,10 +1577,10 @@ sub importDNSLocal { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - my $file = &getParam(1, undef, $q->param('zonefile')); - my $status = &getParam(1, 0, $q->param('state')); - my $origin = &getParam(1, '', $q->param('origin')); - my $targetRootID = &getParam(1, -1, $q->param('targetRoot')); + my $file = &getParam(1, undef, 'zonefile'); + my $status = &getParam(1, 0, 'state'); + my $origin = &getParam(1, '', 'origin'); + my $targetRootID = &getParam(1, -1, 'targetRoot'); my $zoneFileT = ''; my $data = ''; my $stat = $conf->{var}->{STATUS}; @@ -1583,20 +1792,23 @@ return undef; } + my $npCol = $networkV6Table->meth2Col('networkPrefix'); + my $hpCol = $networkV6Table->meth2Col('hostPart'); + my $cidrCol = $networkV6Table->meth2Col('cidr'); if ($inNetwork) { my $broadcastNetDec = &getV6BroadcastNet($networkDec, 128); my ($bNet, $bHost, undef) = &netv6Dec2PartsDec($broadcastNetDec); - $broadcastStr = "AND (networkPrefix < $bNet || (networkPrefix = $bNet AND hostPart < $bHost) || (networkPrefix = $bNet AND hostPart = $bHost AND cidr <= 128))"; + $broadcastStr = "AND ($npCol < $bNet OR ($npCol = $bNet AND $hpCol < $bHost) OR ($npCol = $bNet AND $hpCol = $bHost AND $cidrCol <= 128))"; } - $networkT = ($networkV6Table->search( + $networkT = ($networkV6Table->search( ['ID', 'networkPrefix', 'hostPart', 'cidr'], {rootID => $rootID}, 0, "AND ( - (networkPrefix > $net) OR - (networkPrefix = $net AND hostPart > $host) OR - (networkPrefix = $net AND hostPart = $host AND cidr > $cidr) - ) $broadcastStr ORDER BY networkPrefix, hostPart, cidr LIMIT 1") + ($npCol > $net) OR + ($npCol = $net AND $hpCol > $host) OR + ($npCol = $net AND $hpCol = $host AND $cidrCol > $cidr) + ) $broadcastStr ORDER BY $npCol, $hpCol, $cidrCol LIMIT 1") )[0]; if (defined $networkT) { $networkT->{ipv6} = 1; @@ -1613,16 +1825,17 @@ } } else { my $broadcastStr = ''; + my $nwCol = $networkTable->meth2Col('network'); if ($inNetwork) { my $broadcast = &net2dec(&dec2ip(&getBroadcastFromNet($networkDec)) . '/32'); # <= damit /32er auch in einem /31er angezeigt werden - $broadcastStr = "AND network <= $broadcast"; + $broadcastStr = "AND $nwCol <= $broadcast"; } - $networkT = ($networkTable->search( + $networkT = ($networkTable->search( ['ID', 'network', 'description', 'state', 'defSubnetSize'], {rootID => $rootID, ipv6ID => ''}, 0, - "AND network > $networkDec $broadcastStr ORDER BY network LIMIT 1") + "AND $nwCol > $networkDec $broadcastStr ORDER BY $nwCol LIMIT 1") )[0]; $networkT->{ipv6} = 0 if defined $networkT; } @@ -1661,14 +1874,17 @@ return undef; } + my $npCol = $networkV6Table->meth2Col('networkPrefix'); + my $hpCol = $networkV6Table->meth2Col('hostPart'); + my $cidrCol = $networkV6Table->meth2Col('cidr'); $networkT = ($networkV6Table->search( ['ID', 'networkPrefix', 'hostPart', 'cidr'], {rootID => $rootID}, 0, "AND ( - (networkPrefix < $net) OR - (networkPrefix = $net AND hostPart < $host) OR - (networkPrefix = $net AND hostPart = $host AND cidr < $cidr) - ) ORDER BY networkPrefix DESC, hostPart DESC, cidr DESC LIMIT 1") + ($npCol < $net) OR + ($npCol = $net AND $hpCol < $host) OR + ($npCol = $net AND $hpCol = $host AND $cidrCol < $cidr) + ) ORDER BY $npCol DESC, $hpCol DESC, $cidrCol DESC LIMIT 1") )[0]; if (defined $networkT) { my $currNetworkDec = &ipv6Parts2NetDec($networkT->{networkPrefix}, $networkT->{hostPart}, $networkT->{cidr}); @@ -1691,10 +1907,11 @@ } } } else { - $networkT = ($networkTable->search( + my $nwCol = $networkTable->meth2Col('network'); + $networkT = ($networkTable->search( ['ID', 'network'], {rootID => $rootID, ipv6ID => ''}, 0, - "AND network < $networkDec ORDER BY network DESC LIMIT 1") + "AND $nwCol < $networkDec ORDER BY $nwCol DESC LIMIT 1") )[0]; if (defined $networkT && $inNetwork) { my $parent = &getNetworkParentFromDB($rootID, $networkDec, $ipv6); @@ -1734,7 +1951,10 @@ warn "Seems to be a development Branch. Extending '.dev' to the ConfigFile: '$configFile'\n"; $conf->{static}->{misc}->{debug} = 1; } - return unless $configFile; + unless ($configFile) { + &warnl("No config file found! (Looking at " . $conf->{static}->{path}->{workdir} . '/etc/' . $file . ", " . '/etc/' . $file . ")\n"); + return; + } my %config; eval { @@ -1990,10 +2210,11 @@ sub getNetworkChilds { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $netID = shift; - my $onlyRoot = shift; - my $withParent = shift; - $onlyRoot ||= 0; + my $netID = shift; + my $onlyRoot = shift; + my $withParent = shift; + my $ignoreRoot = shift || 0; + $onlyRoot ||= 0; my $networkTable = $conf->{var}->{TABLES}->{network}; unless (defined $networkTable) { @@ -2036,31 +2257,45 @@ my ($net, $host, $cidr) = &netv6Dec2PartsDec($networkDec); my ($netB, $hostB, $cidrB) = &netv6Dec2PartsDec($broadcast); - @childs = $networkV6Table->search( - ['ID', 'networkPrefix', 'hostPart', 'cidr'], - {rootID => $rootID}, 0, + my $npCol = $networkV6Table->meth2Col('networkPrefix'); + my $hpCol = $networkV6Table->meth2Col('hostPart'); + my $cidrCol = $networkV6Table->meth2Col('cidr'); + my $rootFilter = ($ignoreRoot) ? {1 => 1} : {rootID => $rootID}; + @childs = $networkV6Table->search( + ['ID', 'rootID', 'networkPrefix', 'hostPart', 'cidr'], + $rootFilter, 0, "AND ( - (networkPrefix > $net) OR - (networkPrefix = $net AND hostPart > $host) OR - (networkPrefix = $net AND hostPart = $host AND cidr >" . (($withParent) ? '=' : '') . " $cidr) + ($npCol > $net) OR + ($npCol = $net AND $hpCol > $host) OR + ($npCol = $net AND $hpCol = $host AND $cidrCol >" . (($withParent) ? '=' : '') . " $cidr) ) AND ( - (networkPrefix < $netB) OR - (networkPrefix = $netB AND hostPart < $hostB) OR - (networkPrefix = $netB AND hostPart = $hostB AND cidr <= $cidrB) - ) ORDER BY networkPrefix, hostPart, cidr"); + ($npCol < $netB) OR + ($npCol = $netB AND $hpCol < $hostB) OR + ($npCol = $netB AND $hpCol = $hostB AND $cidrCol <= $cidrB) + ) ORDER BY $npCol, $hpCol, $cidrCol"); if (@childs) { my @newChilds = (); foreach (@childs) { - my $child = $_; - my $net = ($networkTable->search(['ID', 'network', 'state'], {ipv6ID => $child->{ID}, network => 0, rootID => $rootID}))[0]; + my $child = $_; + my $rootID = $child->{rootID}; + my $searchFilter = {ipv6ID => $child->{ID}, network => 0, rootID => $rootID}; + + my $net = ($networkTable->search(['ID', 'network', 'state'], $searchFilter))[0]; $net->{network} = &ipv6Parts2NetDec($child->{networkPrefix}, $child->{hostPart}, $child->{cidr}); push @newChilds, $net; } @childs = @newChilds; } } else { - @childs = $networkTable->search(['ID', 'network', 'state'], {rootID => $rootID, ipv6ID => ''}, 0, "AND network >" . (($withParent) ? '=' : '') . " $networkDec AND network <= $broadcast"); + my $nwCol = $networkTable->meth2Col('network'); + my $searchFilter = {ipv6ID => ''}; + $searchFilter->{rootID} = $rootID unless $ignoreRoot; + @childs = $networkTable->search( + ['ID', 'network', 'state'], + $searchFilter, 0, + "AND $nwCol >" . (($withParent) ? '=' : '') . " $networkDec AND $nwCol <= $broadcast" + ); } } return (@childs) ? @childs : (); @@ -2072,6 +2307,7 @@ my $rootID = shift; my $ipv6 = shift; $ipv6 = &rootID2ipv6($rootID) unless defined $ipv6; + $networkDec = Math::BigInt->new(0) if $ipv6 && !$networkDec; my $broadcast = ($ipv6) ? &getV6BroadcastNet($networkDec, 128) : &net2dec(&dec2ip(&getBroadcastFromNet($networkDec)) . '/32'); my @nrs = (); @@ -2095,20 +2331,28 @@ return undef; } + my $npCol = $networkV6Table->meth2Col('networkPrefix'); + my $hpCol = $networkV6Table->meth2Col('hostPart'); + my $cidrCol = $networkV6Table->meth2Col('cidr'); @nrs = $networkV6Table->search( ['ID'], {rootID => $rootID}, 0, "AND ( - (networkPrefix > $net) OR - (networkPrefix = $net AND hostPart > $host) OR - (networkPrefix = $net AND hostPart = $host AND cidr > $cidr) + ($npCol > $net) OR + ($npCol = $net AND $hpCol > $host) OR + ($npCol = $net AND $hpCol = $host AND $cidrCol > $cidr) ) AND ( - (networkPrefix < $netB) OR - (networkPrefix = $netB AND hostPart < $hostB) OR - (networkPrefix = $netB AND hostPart = $hostB AND cidr <= $cidrB) - ) ORDER BY networkPrefix, hostPart, cidr"); - } else { - @nrs = $networkTable->search(['ID'], {rootID => $rootID, ipv6ID => ''}, 0, "AND network > $networkDec AND network <= $broadcast"); + ($npCol < $netB) OR + ($npCol = $netB AND $hpCol < $hostB) OR + ($npCol = $netB AND $hpCol = $hostB AND $cidrCol <= $cidrB) + ) ORDER BY $npCol, $hpCol, $cidrCol"); + } else { + my $nwCol = $networkTable->meth2Col('network'); + @nrs = $networkTable->search( + ['ID'], + {rootID => $rootID, ipv6ID => ''}, 0, + "AND $nwCol > $networkDec AND $nwCol <= $broadcast" + ); } return ($#nrs + 1) || 0; @@ -2116,8 +2360,9 @@ sub getMaintInfosFromNet { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $netID = shift; - my $networkTable = $conf->{var}->{TABLES}->{network}; + my $netID = shift; + my $networkTable = $conf->{var}->{TABLES}->{network}; + my $networkTagTable = $conf->{var}->{TABLES}->{networkTag}; return {} unless defined $netID; @@ -2146,6 +2391,17 @@ } } + unless (defined $networkTagTable) { + warn "Cannot get Tag infos for network. DB Error (networkTag)\n"; + return (defined $net) ? $net : {}; + } + my @tagsDB = $networkTagTable->search(['*'], {netID => $netID}); + my $tags = []; + foreach (@tagsDB) { + push @{$tags}, $_->{tag}; + } + $net->{tags} = $tags; + return (defined $net) ? $net : {}; } @@ -2182,8 +2438,11 @@ my $netID = shift; my $bWithSubnets = shift || 0; my $bLocal = shift || 0; + my $networkLock = shift || 0; my $errors = ''; my $ipv6 = 0; + my $s = $HaCi::HaCi::session; + my $expands = $s->param('expands'); return '' unless defined $netID; my ($rootID, $networkDec) = (); @@ -2209,6 +2468,12 @@ &warnl($err) unless $bLocal; return ($bLocal) ? $err : 0; } + my $networkTagTable = $conf->{var}->{TABLES}->{networkTag}; + unless (defined $networkTagTable) { + my $err = "Cannot delete network tags. DB Error (networkTag)\n"; + &warnl($err) unless $bLocal; + return ($bLocal) ? $err : 0; + } my $tmplValueTable = $conf->{var}->{TABLES}->{templateValue}; unless (defined $tmplValueTable) { my $err = "Cannot delete Network. DB Error (templateValue)"; @@ -2235,8 +2500,10 @@ my $networkDec = $$_[1]; $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); + my $parent = &getNetworkParentFromDB($rootID, $networkDec, $ipv6); + my $parentDec = (defined $parent) ? $parent->{network} : 0; - &debug("Delete Network " . (($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec)) . " from $rootName"); + &debug("Delete Network $network from $rootName"); unless (&checkNetACL($netID, 'w')) { $errors .= "\n" . (($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec)) . ": Not enouph permissions (write) to delete this Network"; @@ -2275,11 +2542,25 @@ warn sprintf("Error while deleting ACLs for '%s' from '%s': %s", $network, $rootName, $networkACTable->errorStrs); } + $networkTagTable->clear(); + $networkTagTable->delete({netID => $netID}); + if ($networkTagTable->error) { + warn sprintf("Error while deleting tags for '%s' from '%s': %s", $network, $rootName, $networkTagTable->errorStrs); + } + $tmplValueTable->clear(); $tmplValueTable->delete({netID => $netID}); if ($tmplValueTable->error) { warn sprintf("Error while deleting Templates for '%s' from '%s': %s", $network, $rootName, $tmplValueTable->errorStrs); } + &audit('network.delete', $network, "root => $rootName"); + + &addNetworkLock($rootID, $networkDec, $ipv6, $networkLock, $bLocal) if $networkLock; + + if (defined $parentDec && $expands->{network}->{$rootID}->{$parentDec}) { + my $nrOfChilds = &getNrOfChilds($parentDec, $rootID, $ipv6); + &expand('-', 'network', $parentDec, $rootID) unless $nrOfChilds; + } } &removeFromNetcache($rootID); @@ -2290,12 +2571,58 @@ $rows =~ s/0E0/0/; unless ($networkDec == -1) { my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); - &warnl(sprintf(_gettext("Successfully deleted '%s' from '%s' (%i Networks deleted)"), $network, $rootName, $rows)); + if ($networkLock) { + &warnl(sprintf(_gettext("Successfully deleted '%s' from '%s' (%i Networks deleted) and locked for %i seconds."), $network, $rootName, $rows, $networkLock)); + } else { + &warnl(sprintf(_gettext("Successfully deleted '%s' from '%s' (%i Networks deleted)"), $network, $rootName, $rows)); + } } return ($bLocal) ? $rows : 1; } } +sub addNetworkLock { + my $rootID = shift; + my $networkDec = shift; + my $ipv6 = shift; + my $networkLock = shift; + my $bLocal = shift; + my $networkPrefix = 0; + my $hostPart = 0; + my $cidr = 0; + + my $networkLockTable = $conf->{var}->{TABLES}->{networkLock}; + unless (defined $networkLockTable) { + my $err = "Cannot lock network. DB Error (networkLock)"; + &warnl($err) unless $bLocal; + return ($bLocal) ? $err : 0; + } + + if ($ipv6) { + ($networkPrefix, $hostPart, $cidr) = &HaCi::Mathematics::netv6Dec2PartsDec($networkDec); + } else { + ($networkPrefix, $cidr) = ($networkDec, &HaCi::Mathematics::getCidrFromDec($networkDec)); + } + my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); + + $networkLockTable->clear(); + $networkLockTable->ts(&currDate('datetime')); + $networkLockTable->duration($networkLock); + $networkLockTable->rootID($rootID); + $networkLockTable->networkPrefix($networkPrefix); + $networkLockTable->hostPart($hostPart); + $networkLockTable->cidr($cidr); + $networkLockTable->ipv6($ipv6); + unless ($networkLockTable->insert()) { + my $errStr = "Cannot lock network '$network' for $networkLock seconds: " . $networkLockTable->errorStrs(); + &warnl($errStr); + &audit('network.lock', $network, $networkLock, $errStr); + } else { + &debug("Successfully locked network '$network' for $networkLock seconds"); + &audit('network.lock', $network, $networkLock); + } +} + sub genRandBranch { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $rootName = ''; @@ -2342,7 +2669,7 @@ return 0; } - my $rows = &delNet($rootID, -1, 1); + my $rows = &delNet($rootID, -1, 1, 0); if ($rows !~ /^\d+$/) { &warnl(sprintf(_gettext("Error while deleting '%s': %s"), $rootName, $rows)); return 0; @@ -2362,6 +2689,7 @@ &debug("$rows netAC Entries removed"); } &warnl(sprintf(_gettext("Successfully deleted '%s' (%i Networks deleted)"), $rootName, $rows)); + &audit('root.delete', $rootName); } } @@ -2521,7 +2849,7 @@ $ipv6Error = 1; } if ($ipv6Error) { - &delNet($newNetID, 0, 1); + &delNet($newNetID, 0, 1, 0); next; } } @@ -2589,6 +2917,7 @@ sub delNets { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $networks = shift; + my $networkLock = shift || 0; my $s = $HaCi::HaCi::session; my $expands = $s->param('expands') || {}; my $networkTable = $conf->{var}->{TABLES}->{network}; @@ -2606,10 +2935,10 @@ my $netID = &getNetID($rootID, $networkDec, $ipv6ID); if ($expands->{network}->{$rootID}->{$networkDec}) { - my $rows = &delNet($netID, 0, 1); + my $rows = &delNet($netID, 0, 1, $networkLock); $error .= $rows if $rows !~ /^\d+$/; } else { - my $rows = &delNet($netID, 1, 1); + my $rows = &delNet($netID, 1, 1, $networkLock); $error .= $rows if $rows !~ /^\d+$/; } } @@ -2623,81 +2952,94 @@ sub search { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $q = $HaCi::HaCi::q; - my $search = &getParam(1, '', $q->param('search')); - my $bLike = (defined $q->param('exact') ? 0 : 1); - my $bFuzzy = (defined $q->param('fuzzy') ? 1 : 0); - my $state = &getParam(1, undef, $q->param('state')); - my $tmplID = &getParam(1, -1, $q->param('tmplID')); - my $searchLimit = $conf->{static}->{misc}->{searchlimit} || 1000; - $bLike = (defined $bLike) ? $bLike : 1; + + my $search = shift || ''; + my $bLike = shift || 0; + my $bFuzzy = shift || 0; + my $bshNrOfFreeSubs = shift || 0; + my $rootID = shift; + my $state = shift; + my $tmplID = shift; + my $tmplBox = shift || {}; + my $tags = shift || []; + my $tagOp = shift || 'OR'; + + my $q = $HaCi::HaCi::q; + if (ref($q)) { + $search = &getParam(1, '', 'search'); + $bLike = (&getParam(1, 0, 'exact')) ? 0 : 1; + $bFuzzy = (&getParam(1, 0, 'fuzzy')) ? 1 : 0; + $bshNrOfFreeSubs = (&getParam(1, 0, 'shNrOfFreeSubs')) ? 1 : 0; + $rootID = &getParam(1, '', 'rootID'); + $state = &getParam(1, undef, 'state'); + $tmplID = &getParam(1, -1, 'tmplID'); + $tagOp = &getParam(1, 'AND', 'tagOp'); + $tags = &getParam(0, [], 'tags'); + } + + my $searchLimit = $conf->{static}->{misc}->{searchlimit} || 1000; + my $dbType = &getConfigValue('db', 'dbtype'); + $bLike = (defined $bLike) ? $bLike : 1; + $search = '*' if !$search && $tmplID != -1; + $search = '*' if !$search && scalar @{$tags} > 0; + $rootID = '' if $rootID == -1; return unless $search; - my $tmplBox = {}; if ($tmplID > 0) { - foreach ($q->param) { - $tmplBox->{$1} = $q->param($_) if /^tmplEntryID_(\d+)$/ && $q->param($_) ne ''; + if (ref($q)) { + foreach ($q->param) { + $tmplBox->{$1} = &getParam(1, undef, $_) if /^tmplEntryID_(\d+)$/ && &getParam(1, '', $_) ne ''; + } } } my $tmplResultBox = {}; if ($tmplID ne -1) { - my $tmplSearch = '0'; + my $tmplValueTable = $conf->{var}->{TABLES}->{templateValue}; + unless (defined $tmplValueTable) { + &warnl("Cannot get Template Values. DB Error (templateValue)"); + return ''; + } + + my $tmplValIDCol = $tmplValueTable->meth2Col('tmplEntryID'); + my $tmplSearch = '0=1'; foreach (keys %{$tmplBox}) { my $search = $tmplBox->{$_}; $search =~ s/'/\\'/g; $search =~ s/"/\\"/g; $search =~ s/;/\\;/g; - $search =~ s/%/\\%/g; - $search =~ s/([^\\]|^)\*/%/g; - $tmplSearch .= " OR (tmplEntryID=$_ AND CONVERT(value USING latin1) " . (($bLike) ? "like '%$search%'" : "='$search'") . ')'; - } + if (lc($dbType) eq 'mysql') { + $search =~ s/%/\\%/g; + } else { + $search =~ s/%/\\\\%/g; + } + $search =~ s/([^\\]|^)\*/$1 . '%'/eg; - my $tmplValueTable = $conf->{var}->{TABLES}->{templateValue}; - unless (defined $tmplValueTable) { - &warnl("Cannot get Template Values. DB Error (templateValue)"); - return ''; + if ($dbType eq 'postgresql') { + $tmplSearch .= " OR ($tmplValIDCol=$_ AND value::text " . (($bLike) ? "ILIKE '%$search%'" : "='$search'") . ')'; + } else { + $tmplSearch .= " OR ($tmplValIDCol=$_ AND CONVERT(value USING latin1) " . (($bLike) ? "like '%$search%'" : "='$search'") . ')'; + } } + + &debug("TmplSearch: " . $tmplSearch); my @results = $tmplValueTable->search(['netID', 'tmplEntryID'], $tmplSearch); foreach (@results) { $tmplResultBox->{$_->{netID}}->{$_->{tmplEntryID}} = 1; } } - my $t = $HaCi::GUI::init::t; - my $bNet = 1 if &checkSpelling_Net($search, 0); - my $bIP = 1 if &checkSpelling_IP($search, 0); - my $ipv6 = 1 if $search =~ /\:/; - $search .= (($ipv6) ? '/128' : '/32') if $bIP; - $search = (($ipv6) ? &netv62Dec($search) : &net2dec($search)) if $bNet || $bIP; $search =~ s/'/\\'/g; $search =~ s/"/\\"/g; $search =~ s/;/\\;/g; - $search =~ s/%/\\%/g; - $search =~ s/([^\\]|^)\*/%/g; + if (lc($dbType) eq 'mysql') { + $search =~ s/%/\\%/g; + } else { + $search =~ s/%/\\\\%/g; + } + $search =~ s/([^\\]|^)\*/$1 . '%'/eg; $search = '%' . $search . '%' if $bLike && !$bFuzzy; $state = ($state eq '-1') ? undef : int($state); - my $fuzzySearch = - '(substring(soundex(description), 2) LIKE ' . - (($bLike) ? "concat('%', " : '') . - "substring(soundex('$search'), 2)" . - (($bLike) ? ", '%')" : '') . - (($bNet || $bIP) ? ( - ') OR (substring(soundex(network), 2) LIKE ' . - (($bLike) ? "concat('%', " : '') . - "substring(soundex('$search'), 2)" . - (($bLike) ? ", '%')" : '') . ')') : - ')'); - $fuzzySearch .= " AND state='$state'" if defined $state; - $fuzzySearch .= " AND tmplID='$tmplID'" unless $tmplID == -1; - - my $normSearch = "(description LIKE '$search'"; - $normSearch .= " OR network LIKE '$search'" if $bNet || $bIP; - $normSearch .= ')'; - $normSearch .= " AND state='$state'" if defined $state; - $normSearch .= " AND tmplID='$tmplID'" unless $tmplID == -1; - - $t->{V}->{'gettext_rootName'} = _gettext("Root Name"); my $networkTable = $conf->{var}->{TABLES}->{network}; unless (defined $networkTable) { @@ -2705,6 +3047,44 @@ return 0; } + my $nwCol = $networkTable->meth2Col('network'); + my $descrCol = $networkTable->meth2Col('description'); + my $stateCol = $networkTable->meth2Col('state'); + my $tmplIDCol = $networkTable->meth2Col('tmplID'); + my $rootIDCol = $networkTable->meth2Col('rootID'); + my $searchStrCol = $networkTable->meth2Col('searchStr'); + + my $fuzzySearch = ''; + if (lc($dbType) eq 'mysql') { + $fuzzySearch = + "((substring(soundex($descrCol), 2) LIKE " . + (($bLike) ? "concat('%', " : '') . + "substring(soundex('$search'), 2)" . + (($bLike) ? ", '%')" : '') . + ')'; + $fuzzySearch .= " OR $searchStrCol LIKE '$search')"; + $fuzzySearch .= " AND $stateCol='$state'" if defined $state; + $fuzzySearch .= " AND $tmplIDCol='$tmplID'" unless $tmplID == -1; + } + + my $normSearch = ''; + + if (lc($dbType) eq 'postgresql') { + $normSearch = "($descrCol ILIKE E'$search'"; + $normSearch .= " OR $searchStrCol ILIKE E'$search'"; + $normSearch .= ')'; + $normSearch .= " AND $stateCol='$state'" if defined $state; + $normSearch .= " AND $tmplIDCol='$tmplID'" unless $tmplID == -1; + $normSearch .= " AND $rootIDCol='$rootID'" if $rootID; + } else { + $normSearch = "($descrCol LIKE '$search'"; + $normSearch .= " OR $searchStrCol LIKE '$search'"; + $normSearch .= ')'; + $normSearch .= " AND $stateCol='$state'" if defined $state; + $normSearch .= " AND $tmplIDCol='$tmplID'" unless $tmplID == -1; + $normSearch .= " AND $rootIDCol='$rootID'" if $rootID; + } + my $networkV6Table = $conf->{var}->{TABLES}->{networkV6}; unless (defined $networkV6Table) { warn "Cannot search. DB Error (networkV6)\n"; @@ -2712,17 +3092,21 @@ } my $qryRef = ($bFuzzy) ? $fuzzySearch : $normSearch; - + &debug("Search: $qryRef"); + my @results = $networkTable->search( - ['ID', 'network', 'description', 'rootID', 'ipv6ID', 'state'], $qryRef, $bLike, "ORDER BY network LIMIT $searchLimit" + ['ID', 'network', 'description', 'rootID', 'ipv6ID', 'state', 'defSubnetSize'], $qryRef, $bLike, "ORDER BY $nwCol" ); my $tmp = {}; my $tmplInfos = {}; + foreach (@results) { - my $net = $_; - my $rootID = $net->{rootID}; - my $ipv6 = &rootID2ipv6($rootID); + my $net = $_; + my $rootID = $net->{rootID}; + my $netID = $net->{ID}; + $net->{tags} = &getTags($netID); + my $ipv6 = &rootID2ipv6($rootID); if ($tmplID ne -1) { my $tmplResult = 0; foreach (keys %{$tmplBox}) { @@ -2731,6 +3115,21 @@ next if $tmplResult; $tmplInfos->{$net->{ID}} = &getTemplateData($net->{ID}, $tmplID, 1); } + if (scalar @{$tags} > 0) { + my $tagsDB = $net->{tags}; + my $ok = 0; + foreach (@{$tagsDB}) { + my $tagDB = $_; + foreach (@{$tags}) { + my $tag = $_; + $ok++ if $tag eq $tagDB; + last if $tagOp eq 'OR' && $ok; + } + last if $tagOp eq 'OR' && $ok; + } + next unless $ok; + next if $tagOp eq 'AND' && $ok < scalar @{$tags}; + } if ($ipv6) { my $v6Net = ($networkV6Table->search(['ID', 'networkPrefix', 'hostPart', 'cidr'], {ID => $net->{ipv6ID}, rootID => $rootID}, 0))[0]; if (defined $v6Net) { @@ -2742,34 +3141,63 @@ $tmp->{A}->{$rootID}->{IPV6} = $ipv6; } + my $pushCnter = 0; foreach my $rootID (keys %{$tmp->{A}}) { my $ipv6 = $tmp->{A}->{$rootID}->{IPV6}; my @nets = (); if ($ipv6) { - @nets = sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} keys %{$tmp->{A}->{$rootID}->{NETS}}; + @nets = &ipv6Sort(keys %{$tmp->{A}->{$rootID}->{NETS}}); } else { @nets = sort {$a<=>$b} keys %{$tmp->{A}->{$rootID}->{NETS}}; } foreach (@nets) { next unless $tmp->{A}->{$rootID}->{NETS}->{$_}->{network}; next if !&checkRootACL($rootID, 'r') || !&checkNetACL($tmp->{A}->{$rootID}->{NETS}->{$_}->{ID}, 'r'); - - my $network = ($ipv6) ? &netv6Dec2net($tmp->{A}->{$rootID}->{NETS}->{$_}->{network}) : &dec2net($tmp->{A}->{$rootID}->{NETS}->{$_}->{network}); - my $ipaddress = (split/\//, $network)[0]; - my $rootName = &rootID2Name($rootID); + + my $network = ($ipv6) ? &netv6Dec2net($tmp->{A}->{$rootID}->{NETS}->{$_}->{network}) : &dec2net($tmp->{A}->{$rootID}->{NETS}->{$_}->{network}); + my ($ipaddress, $cidr) = split(/\//, $network); + $network = Net::IPv6Addr::to_string_compressed($ipaddress) . '/' . $cidr if $ipv6; + my $rootName = &rootID2Name($rootID); if ($rootName ne '') { + my $nrOfFreeSubsStr = 0; + if ($bshNrOfFreeSubs) { + if ($tmp->{A}->{$rootID}->{NETS}->{$_}->{defSubnetSize}) { + my $freeSubnets = &getFreeSubnets($tmp->{A}->{$rootID}->{NETS}->{$_}->{ID}, 1, $tmp->{A}->{$rootID}->{NETS}->{$_}->{defSubnetSize}); + $nrOfFreeSubsStr = $freeSubnets . ' /' . $tmp->{A}->{$rootID}->{NETS}->{$_}->{defSubnetSize}; + } else { + my $cntBox; + foreach (&getFreeSubnets($tmp->{A}->{$rootID}->{NETS}->{$_}->{ID})) { + (undef, my $cidr) = split(/\//); + $cntBox->{$cidr}++; + } + $nrOfFreeSubsStr = '' if scalar keys %{$cntBox} > 0; + foreach (sort keys %{$cntBox}) { + $nrOfFreeSubsStr .= ', ' if $nrOfFreeSubsStr; + $nrOfFreeSubsStr .= $cntBox->{$_} . ' /' . $_; + } + } + } + (my $cidr = $network) =~ s#.*/##; + my $defSubnetSize = $tmp->{A}->{$rootID}->{NETS}->{$_}->{defSubnetSize} || '?'; + last if $pushCnter++ > $searchLimit; push @{$tmp->{B}}, { - netID => $tmp->{A}->{$rootID}->{NETS}->{$_}->{ID}, - network => $network, - description => "eHTML($tmp->{A}->{$rootID}->{NETS}->{$_}->{description}), - url => "$conf->{var}->{thisscript}?jumpToButton=1&rootIDJump=$rootID&jumpTo=$ipaddress", - rootName => "eHTML($rootName), - state => &networkStateID2Name($tmp->{A}->{$rootID}->{NETS}->{$_}->{state}), + netID => $tmp->{A}->{$rootID}->{NETS}->{$_}->{ID}, + tags => "eHTML(join(' ', @{$tmp->{A}->{$rootID}->{NETS}->{$_}->{tags}})), + network => $network, + description => "eHTML($tmp->{A}->{$rootID}->{NETS}->{$_}->{description}), + url => "$conf->{var}->{thisscript}?jumpToButton=1&rootIDJump=$rootID&jumpTo=$network", + rootName => "eHTML($rootName), + state => &networkStateID2Name($tmp->{A}->{$rootID}->{NETS}->{$_}->{state}), + nrOfFreeSubs => $nrOfFreeSubsStr } } } + last if $pushCnter++ > $searchLimit; } + my $t = $HaCi::GUI::init::t; + $t->{V}->{'gettext_rootName'} = _gettext("Root Name"); + if ($#{$tmp->{B}} == -1) { $t->{V}->{searchResult} = {}; $t->{V}->{noSearchResult} = 1; @@ -2780,6 +3208,8 @@ $t->{V}->{searchResult} = $tmp->{B}; $t->{V}->{tmplInfos} = $tmplInfos if $tmplID ne -1; $t->{V}->{tmplDescr} = &getTemplateEntries($tmplID, 0, 0, 1, 0, 1) if $tmplID ne -1; + + return $tmp->{B}; } sub networkStateName2ID { @@ -2831,7 +3261,8 @@ return $types; } - my @netTypes = $tmplTable->search(['ID', 'name'], {type => 'Nettype'}, 0, "ORDER BY `name`"); + my $nameCol = $tmplTable->meth2Col('name'); + my @netTypes = $tmplTable->search(['ID', 'name'], {type => 'Nettype'}, 0, "ORDER BY $nameCol"); foreach (@netTypes) { push @{$types}, {ID => $_->{ID}, name => $_->{name}}; } @@ -2884,15 +3315,75 @@ return $return; } +sub tmplEntryID2Name { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + my $ID = shift; + $ID = -1 unless defined $ID; + + my $tmplEntryTable = $conf->{var}->{TABLES}->{templateEntry}; + unless (defined $tmplEntryTable) { + warn "Cannot get Template. DB Error (templateEntry)\n"; + return ''; + } + + my $DB = ($tmplEntryTable->search(['description'], {ID => $ID}))[0]; + + return ($DB) ? $DB->{description} : ''; +} + +sub changeTmplName { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + my $tmplID = shift; + my $tmplName = shift || ''; + my $q = $HaCi::HaCi::q; + my $s = $HaCi::HaCi::session; + my $tmplTable = $conf->{var}->{TABLES}->{template}; + $tmplID = -1 unless defined $tmplID; + + unless (defined $tmplTable) { + &warnl("Cannot update Template. DB Error (template)"); + } + + if ($tmplID < 0) { + &warnl(_gettext('Sorry, wrong tamplate ID passed!')); + return 0; + } + + unless ($tmplName) { + &warnl(_gettext('Sorry, you have to give me a name!')); + return 0; + } + + $tmplTable->clear(); + $tmplTable->name($tmplName); + + my $DB = ($tmplTable->search(['name'], {ID => $tmplID}))[0]; + if ($DB) { + $tmplTable->modifyFrom($s->param('username')); + $tmplTable->modifyDate(&currDate('datetime')); + &debug("Change Template-Name from '$DB->{name}' to '$tmplName'\n"); + unless ($tmplTable->update({ID => $tmplID})) { + my $errStr = "Cannot update Template-Name: " . $tmplTable->errorStrs(); + &warnl($errStr); + &audit('template.updateName', $DB->{name}, $tmplName, $errStr, 1); + } else { + &audit('template.updateName', $DB->{name}, $tmplName, '', 1); + } + } else { + &warnl(sprintf(_gettext("No such template found for id '%s'"), $tmplID)); + return 0; + } +} + sub saveTmpl { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $type = shift || 0; my $q = $HaCi::HaCi::q; my $s = $HaCi::HaCi::session; - my $tmplID = &getParam(1, -1, $q->param('tmplID')); - my $tmplType = &getParam(1, undef, $q->param('tmplType')); + my $tmplID = &getParam(1, -1, 'tmplID'); + my $tmplType = &getParam(1, undef, 'tmplType'); my $tmplTable = $conf->{var}->{TABLES}->{template}; - my $position = &getParam(1, 0, $q->param('position')); + my $position = &getParam(1, 0, 'position'); unless (defined $tmplTable) { &warnl("Cannot save Template. DB Error (template)"); } @@ -2904,13 +3395,14 @@ unless (defined $tmplType) { &warnl("Cannot save Template. No Template Type given!"); } + my $posCol = $tmplEntryTable->meth2Col('position'); if ($tmplID < 0) { - unless (defined $q->param('tmplName')) { + unless (defined &getParam(1, undef, 'tmplName')) { &warnl(_gettext('Sorry, you have to give me a Name!')); return 0; } - my $tmplName = &getParam(1, '', $q->param('tmplName')); + my $tmplName = &getParam(1, '', 'tmplName'); $tmplTable->clear(); $tmplTable->name($tmplName); @@ -2929,7 +3421,11 @@ $tmplTable->createFrom($s->param('username')); $tmplTable->createDate(&currDate('datetime')); unless ($tmplTable->insert()) { - &warnl("Cannot create Template-Entry '$tmplName': " . $tmplTable->errorStrs()); + my $errStr = "Cannot create Template-Entry '$tmplName': " . $tmplTable->errorStrs(); + &warnl($errStr); + &audit('template.add', $tmplName, &tableContent2Str($tmplTable), $errStr, 1); + } else { + &audit('template.add', $tmplName, &tableContent2Str($tmplTable), '', 1); } } my $newTmpl = ($tmplTable->search(['ID'], {name => $tmplName}))[0]; @@ -2937,7 +3433,7 @@ } if ($type == 2) { - my $tmplEntryID = &getParam(1, undef, $q->param('tmplEntryID')); + my $tmplEntryID = &getParam(1, undef, 'tmplEntryID'); if (!defined $tmplEntryID || $tmplEntryID eq '') { &warnl("No Template Entry ID!"); return $tmplID; @@ -2950,7 +3446,7 @@ } &debug("$nrs Entries from Template deleted!\n"); - my @entries = $tmplEntryTable->search(['ID', 'position'], {tmplID => $tmplID}, 0, "AND position > $position"); + my @entries = $tmplEntryTable->search(['ID', 'position'], {tmplID => $tmplID}, 0, "AND $posCol > $position"); foreach (@entries) { $tmplEntryTable->clear(); $tmplEntryTable->position(($_->{position} - 1)); @@ -2960,7 +3456,17 @@ } } else { unless ($type) { - my @entries = $tmplEntryTable->search(['ID', 'position'], {tmplID => $tmplID}, 0, "AND position >= $position"); + my $descrNew = &getParam(1, '', 'TmplEntryParamDescr'); + my $tmplEntries = &HaCi::Utils::getTemplateEntries($tmplID, 0, 0, 1, 0, 1); + foreach (keys %{$tmplEntries}) { + my $id = $_; + my $descr = $tmplEntries->{$id}; + if ($descr eq $descrNew) { + &warnl("Label '$descr' already exists!"); + return $tmplID; + } + } + my @entries = $tmplEntryTable->search(['ID', 'position'], {tmplID => $tmplID}, 0, "AND $posCol >= $position"); foreach (@entries) { $tmplEntryTable->clear(); $tmplEntryTable->position(($_->{position} + 1)); @@ -2973,30 +3479,38 @@ my $tmpl = ($tmplTable->search(['*'], {ID => $tmplID}))[0]; $tmplEntryTable->clear(); $tmplEntryTable->tmplID($tmplID); - $tmplEntryTable->type(&getParam(1, 0, $q->param('TmplEntryType'))); + $tmplEntryTable->type(&getParam(1, 0, 'TmplEntryType')); $tmplEntryTable->position($position); - $tmplEntryTable->description(&getParam(1, '', $q->param('TmplEntryParamDescr'))); - $tmplEntryTable->size(&getParam(1, 1, $q->param('TmplEntryParamSize'))); - $tmplEntryTable->entries(&getParam(1, '', $q->param('TmplEntryParamEntries'))); - $tmplEntryTable->rows(&getParam(1, 1, $q->param('TmplEntryParamRows'))); - $tmplEntryTable->cols(&getParam(1, 1, $q->param('TmplEntryParamCols'))); + $tmplEntryTable->description(&getParam(1, '', 'TmplEntryParamDescr')); + $tmplEntryTable->size(&getParam(1, 1, 'TmplEntryParamSize')); + $tmplEntryTable->entries(&getParam(1, '', 'TmplEntryParamEntries')); + $tmplEntryTable->rows(&getParam(1, 1, 'TmplEntryParamRows')); + $tmplEntryTable->cols(&getParam(1, 1, 'TmplEntryParamCols')); my $bError = 0; if ($type == 1) { - my $tmplEntryID = &getParam(1, undef, $q->param('tmplEntryID')); + my $tmplEntryID = &getParam(1, undef, 'tmplEntryID'); unless (defined $tmplEntryID) { &warnl("No Template Entry ID!"); return $tmplID; } unless ($tmplEntryTable->update({ID => $tmplEntryID})) { - &warnl("Cannot update Template-Entry for Template '$tmpl->{name}': " . $tmplEntryTable->errorStrs()); + my $errStr = "Cannot update Template-Entry for Template '$tmpl->{name}': " . $tmplEntryTable->errorStrs(); + &warnl($errStr); + &audit('templateEntry.update', $tmpl->{name}, &tableContent2Str($tmplEntryTable), $errStr, 1); $bError = 1; + } else { + &audit('templateEntry.update', $tmpl->{name}, &tableContent2Str($tmplEntryTable), '', 1); } } else { $tmplEntryTable->ID(undef); unless ($tmplEntryTable->insert()) { - &warnl("Cannot insert Template-Entry for Template '$tmpl->{name}': " . $tmplEntryTable->errorStrs()); + my $errStr = "Cannot add Template-Entry for Template '$tmpl->{name}': " . $tmplEntryTable->errorStrs(); + &warnl($errStr); + &audit('templateEntry.add', $tmpl->{name}, &tableContent2Str($tmplEntryTable), $errStr, 1); $bError = 1; + } else { + &audit('templateEntry.add', $tmpl->{name}, &tableContent2Str($tmplEntryTable), '', 1); } } unless ($bError) { @@ -3075,7 +3589,7 @@ }; } elsif ($type == 1) { - my $value = (($bWithValues && defined $q->param('tmplEntryID_' . $ID)) ? $q->param('tmplEntryID_' . $ID) : ''); + my $value = (($bWithValues && defined &getParam(1, undef, 'tmplEntryID_' . $ID)) ? &getParam(1, undef, 'tmplEntryID_' . $ID) : ''); $value =~ s/"/"/g; push @{$tmplEntries}, { onClick => ($bWithChecks) ? "javascript:updTmplParamsFromPreview($ID, 1, $pos)" : '', @@ -3099,7 +3613,7 @@ }; } elsif ($type == 2) { - my $value = (($bWithValues && defined $q->param('tmplEntryID_' . $ID)) ? $q->param('tmplEntryID_' . $ID) : ''); + my $value = (($bWithValues && defined &getParam(1, undef, 'tmplEntryID_' . $ID)) ? &getParam(1, undef, 'tmplEntryID_' . $ID) : ''); $value =~ s/"/"/g; push @{$tmplEntries}, { onClick => ($bWithChecks) ? "javascript:updTmplParamsFromPreview($ID, 2, $pos)" : '', @@ -3140,7 +3654,7 @@ name => 'tmplEntryID_' . $ID, size => $size, values => $popupValues, - selected => (($bWithValues && defined $q->param('tmplEntryID_' . $ID)) ? [$q->param('tmplEntryID_' . $ID)] : []), + selected => (($bWithValues && defined &getParam(1, undef, 'tmplEntryID_' . $ID)) ? [&getParam(1, 0, 'tmplEntryID_' . $ID)] : []), title => $title, } ] @@ -3187,7 +3701,7 @@ my @array = (); if ($num) { if ($ipv6) { - map {push @array, $hash->{$_}} sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} keys %{$hash}; + map {push @array, $hash->{$_}} &ipv6Sort(keys %{$hash}); } else { map {push @array, $hash->{$_}} sort {$a<=>$b} keys %{$hash}; } @@ -3221,8 +3735,9 @@ return ''; } - my @values = $tmplValueTable->search(['ID', 'netID'], {tmplID => $tmplID}, 0, "Group by tmplID"); - my $nets = ''; + my $tmplIDCol = $tmplValueTable->meth2Col('tmplID'); + my @values = $tmplValueTable->search(['ID', 'netID'], {tmplID => $tmplID}, 0, "Group by $tmplIDCol"); + my $nets = ''; foreach (@values) { my ($rootID, $network, $ipv6) = &netID2Stuff($_->{netID}); $nets .= ', ' . &rootID2Name($rootID) . ':' . (($ipv6) ? &netv62Dec($network) : &dec2net($network)); @@ -3261,6 +3776,7 @@ &warnl(_gettext("No Templates deleted. Nothing found!")) } else { &warnl(sprintf(_gettext("Successfully deleted Template '%s'"), $tmplName)); + &audit('template.delete', $tmplName); } } } @@ -3297,7 +3813,7 @@ { target => 'value', type => 'label', - value => $tmplName + value => "eHTML($tmplName) }, ], }, @@ -3359,7 +3875,7 @@ { target => 'single', type => 'label', - value => $descr, + value => "eHTML($descr), colspan => 2, }, ] @@ -3372,12 +3888,12 @@ { target => 'key', type => 'label', - value => $descr + value => "eHTML($descr) }, { target => 'value', type => 'label', - value => $value + value => "eHTML($value) }, ] }; @@ -3390,19 +3906,26 @@ sub getGroups { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $groups = []; + my $groupTable = $conf->{var}->{TABLES}->{group}; unless (defined $groupTable) { warn "Cannot get Groups. DB Error (group)\n"; return []; } - my @groups = $groupTable->search(['*']); - foreach (@groups) { + my @groupsDB = $groupTable->search(['*']); + my $groupsT = {}; + foreach (@groupsDB) { + $groupsT->{lc($_->{name}) . '_' . $_->{ID}} = $_; + } + + foreach (sort keys %{$groupsT}) { push @$groups, { - ID => $_->{ID}, - name => $_->{name} + ID => $groupsT->{$_}->{ID}, + name => $groupsT->{$_}->{name} }; } + return $groups; } @@ -3429,29 +3952,35 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; my $s = $HaCi::HaCi::session; - my $groupID = &getParam(1, -1, $q->param('groupID')); + my $groupID = &getParam(1, -1, 'groupID'); my $groupTable = $conf->{var}->{TABLES}->{group}; unless (defined $groupTable) { &warnl("Cannot save Group. DB Error (group)"); } if ($groupID < 0) { - unless (defined $q->param('groupName')) { + unless (&getParam(1, 0, 'groupName')) { &warnl(_gettext('Sorry, you have to give me a Name!')); return undef; } } - my $groupName = &getParam(1, '', $q->param('groupName')); + my $groupName = &getParam(1, '', 'groupName'); my $permStr = '1'; + my $perms = ''; foreach (sort {$a<=>$b} keys %{$conf->{static}->{rights}}) { - $permStr .= ($groupName eq 'Administrator') ? 1 : (defined $q->param('groupPerm_' . $_) && $q->param('groupPerm_' . $_)) ? 1 : 0; + my $cPerm = ($groupName eq 'Administrator') ? 1 : (defined &getParam(1, undef, 'groupPerm_' . $_) && &getParam(1, undef, 'groupPerm_' . $_)) ? 1 : 0; + $permStr .= $cPerm; + $perms .= ', ' if $perms; + $perms .= $conf->{static}->{rights}->{$_}->{short} . ":$cPerm"; } my $cryptStr = &lwe(&bin2dec($permStr)); + my $descr = &getParam(1, '', 'groupDescr'); + my $auditData = "description => $descr, permissions => $perms"; $groupTable->clear(); $groupTable->name($groupName); - $groupTable->description(&getParam(1, '', $q->param('groupDescr'))); + $groupTable->description($descr); $groupTable->permissions('1' . $cryptStr); my $DB = ($groupTable->search(['ID'], {name => $groupName}))[0]; @@ -3460,14 +3989,22 @@ $groupTable->modifyDate(&currDate('datetime')); &debug("Change Group for '$groupName'\n"); unless ($groupTable->update({ID => $DB->{'ID'}})) { - &warnl("Cannot update Group '$groupName': " . $groupTable->errorStrs()); + my $errStr = "Cannot update Group '$groupName': " . $groupTable->errorStrs(); + &warnl($errStr); + &audit('group.update', $groupName, $auditData, $errStr, 1); + } else { + &audit('group.update', $groupName, $auditData, '', 1); } } else { $groupTable->ID(undef); $groupTable->createFrom($s->param('username')); $groupTable->createDate(&currDate('datetime')); unless ($groupTable->insert()) { - &warnl("Cannot create Group '$groupName': " . $groupTable->errorStrs()); + my $errStr = "Cannot add Group '$groupName': " . $groupTable->errorStrs(); + &warnl($errStr); + &audit('group.add', $groupName, $auditData, $errStr, 1); + } else { + &audit('group.add', $groupName, $auditData, '', 1); } } my $newGroup = ($groupTable->search(['ID'], {name => $groupName}))[0]; @@ -3520,6 +4057,7 @@ &warnl(_gettext("No Group deleted. Nothing found!")) } else { &warnl(sprintf(_gettext("Successfully deleted Group '%s'"), $groupName)); + &audit('group.delete', $groupName); } } } @@ -3557,19 +4095,26 @@ sub getUsers { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $users = []; + my $userTable = $conf->{var}->{TABLES}->{user}; unless (defined $userTable) { warn "Cannot get Users. DB Error (user)\n"; return []; } - my @users = $userTable->search(['*']); - foreach (@users) { + my @usersDB = $userTable->search(['*']); + my $usersT = {}; + foreach (@usersDB) { + $usersT->{lc($_->{username}) . '_' . $_->{ID}} = $_; + } + + foreach (sort keys %{$usersT}) { push @$users, { - ID => $_->{ID}, - name => $_->{username} + ID => $usersT->{$_}->{ID}, + name => $usersT->{$_}->{username}, }; } + return $users; } @@ -3577,6 +4122,8 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $userID = shift; + return {} unless $userID; + unless (defined $userID) { warn "No User ID given!"; return {}; @@ -3613,38 +4160,43 @@ sub saveUser { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $q = $HaCi::HaCi::q; - my $s = $HaCi::HaCi::session; - my $userID = &getParam(1, -1, $q->param('userID')); - my $userTable = $conf->{var}->{TABLES}->{user}; + my $q = $HaCi::HaCi::q; + my $s = $HaCi::HaCi::session; + my $userID = &getParam(1, -1, 'userID') || 0; + my $userTable = $conf->{var}->{TABLES}->{user}; + my $enableIntAcc = &getParam(1, 0, 'enableInternalAccount'); unless (defined $userTable) { &warnl("Cannot save User. DB Error (user)"); } if ($userID < 0) { - unless (defined $q->param('userName')) { + unless (defined &getParam(1, undef, 'userName')) { &warnl(_gettext('Sorry, you have to give me a Name!')); return undef; } } - my $userName = &getParam(1, '', $q->param('userName')); - + my $userName = &getParam(1, '', 'userName'); + my $descr = &getParam(1, '', 'userDescr'); my $groupStr = ''; + my $auditData = "description => $descr, groups => "; foreach ($q->param) { if (/^userGroup_(\d+)/) { - my $userID = $1; - $groupStr .= ' ' . $userID . ','; + my $groupID = $1; + $auditData .= ', ' if $groupStr; + $groupStr .= ' ' . $groupID . ','; + $auditData .= &groupID2Name($groupID); } } - my $pw = &getParam(1, undef, $q->param('password1')); - my $pw1 = &getParam(1, undef, $q->param('password2')); + my $pw = &getParam(1, '', 'password1'); + my $pw1 = &getParam(1, '', 'password2'); $userTable->clear(); - if ($userID > 0 && (!defined $pw || $pw eq '')) { + my $user = ($userID > 0) ? &getUser($userID) : {}; + if ($userID > 0 && $user->{password} ne '' && $enableIntAcc && $pw eq '') { &debug("Okay, no Password Change!"); } else { - unless ($pw && $pw) { + if ($enableIntAcc && $pw eq '') { &warnl("No Password given"); return undef; } @@ -3654,12 +4206,12 @@ return undef; } - my $crypt = &getCryptPassword($pw); + my $crypt = ($enableIntAcc) ? &getCryptPassword($pw) : ''; $userTable->password($crypt); } $userTable->username($userName); - $userTable->description(&getParam(1, '', $q->param('userDescr'))); + $userTable->description($descr); $userTable->groupIDs($groupStr); my $DB = ($userTable->search(['ID'], {username => $userName}))[0]; @@ -3668,14 +4220,22 @@ $userTable->modifyDate(&currDate('datetime')); &debug("Change User '$userName'\n"); unless ($userTable->update({ID => $DB->{'ID'}})) { - &warnl("Cannot update User '$userName': " . $userTable->errorStrs()); + my $errStr = "Cannot update user '$userName': " . $userTable->errorStrs(); + &warnl($errStr); + &audit('user.update', $userName, $auditData, $errStr, 1); + } else { + &audit('user.update', $userName, $auditData, '', 1); } } else { $userTable->ID(undef); $userTable->createFrom($s->param('username')); $userTable->createDate(&currDate('datetime')); unless ($userTable->insert()) { - &warnl("Cannot create User '$userName': " . $userTable->errorStrs()); + my $errStr = "Cannot add user '$userName': " . $userTable->errorStrs(); + &warnl($errStr); + &audit('user.add', $userName, $auditData, $errStr, 1); + } else { + &audit('user.add', $userName, $auditData, '', 1); } } my $newUser = ($userTable->search(['ID'], {username => $userName}))[0]; @@ -3688,22 +4248,9 @@ sub dec2bin { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $dec = shift; - my $bin = ''; - my $log2 = log(2); - my $hash = {}; - my $highest = 0; - - while ($dec) { - my $curr = int(log($dec)/$log2); - $dec -= 2 ** $curr; - $highest = $curr unless $highest; - $hash->{$curr} = 1; - } - for (0 .. $highest) { - $bin .= (exists $hash->{$_}) ? 1 : 0; - } - $bin = reverse $bin; + my $dec = shift; + + my $bin = sprintf("%b", $dec); return $bin; } @@ -3737,6 +4284,7 @@ unless (defined $rights) { $rights = &getRights($groupID); $s->param('rights_' . $groupID, $rights); + $s->flush(); } $hasRight = (exists $rights->{$right} && $rights->{$right}) ? 1 : 0; } else { @@ -3761,6 +4309,7 @@ my $netID = shift; my $right = shift; my $groupID = shift; + my $showIfInherit = shift || 0; my $checkGroupID = 1 if defined $groupID; my $acls = &getACLCacheEntry('net'); my $s = $HaCi::HaCi::session; @@ -3768,7 +4317,9 @@ my $return = 0; my $fromDB = 0; my $rootID = 0; + my $bInherit = 0; + return 0 if $netID == -1; return 1 if !defined $groupID && $s->param('bAdmin'); my $networkACTable = $conf->{var}->{TABLES}->{networkAC}; @@ -3797,26 +4348,29 @@ ($rootID, my $networkDec, my $ipv6) = &netID2Stuff($netID); my $parent = &getNetworkParentFromDB($rootID, $networkDec, $ipv6); if (defined $parent) { - $acl->{ACL} = &checkNetACL($parent->{ID}, 'ACL', $groupID); + $acl->{ACL} = &checkNetACL($parent->{ID}, 'ACL', $groupID, $showIfInherit); + $bInherit = 1; } } if (defined $acl) { - if ($acl->{ACL} == 1 || $acl->{ACL} == 3) { + if ($acl->{ACL} % 4 == 1 || $acl->{ACL} % 4 == 3) { $acls->{$netID}->{$groupID}->{r} ||= 1; } - if ($acl->{ACL} == 2 || $acl->{ACL} == 3) { + if ($acl->{ACL} % 4 == 2 || $acl->{ACL} % 4 == 3) { $acls->{$netID}->{$groupID}->{w} ||= 1; } } else { $acls->{$netID}->{$groupID}->{r} ||= &checkRootACL($rootID, 'r', $groupID); $acls->{$netID}->{$groupID}->{w} ||= &checkRootACL($rootID, 'w', $groupID); + $bInherit = 1; } my $newACL = 0; $newACL += 1 if $acls->{$netID}->{$groupID}->{r}; $newACL += 2 if $acls->{$netID}->{$groupID}->{w}; $acls->{$netID}->{$groupID}->{ACL} = $newACL if $acls->{$netID}->{$groupID}->{ACL} < $newACL; + $acls->{$netID}->{$groupID}->{ACL} += 4 if $bInherit; $currReturn = $acls->{$netID}->{$groupID}->{$right}; @@ -3830,7 +4384,7 @@ $return ||= 0; &debug("netAC ($netID :@groupIDs :$right [$fromDB]): $return\n") if 0; - return $return; + return ($showIfInherit) ? $return : $return % 4; } sub checkRootACL { @@ -3934,8 +4488,10 @@ my $rootID = shift; my $networkDec = shift; my $ipv6 = shift; + my $limit = shift // 1; $ipv6 = &rootID2ipv6($rootID) unless defined $ipv6; my $parent = undef; + my $limitStr = ($limit) ? "LIMIT $limit" : ''; my $networkTable = $conf->{var}->{TABLES}->{network}; unless (defined $networkTable) { @@ -3957,46 +4513,69 @@ return undef; } - my @potParents = $networkV6Table->search( - ['ID', 'networkPrefix', 'hostPart', 'cidr'], - {rootID => $rootID}, 0, + my $npCol = $networkV6Table->meth2Col('networkPrefix'); + my $hpCol = $networkV6Table->meth2Col('hostPart'); + my $cidrCol = $networkV6Table->meth2Col('cidr'); + my $rootIDFilter = ($rootID == -1) ? {1 => 1} : {rootID => $rootID}; + my @potParents = $networkV6Table->search( + ['ID', 'rootID', 'networkPrefix', 'hostPart', 'cidr'], + $rootIDFilter, 0, "AND ( - (networkPrefix < $net) OR - (networkPrefix = $net AND hostPart < $host) OR - (networkPrefix = $net AND hostPart = $host AND cidr < $cidr) - ) ORDER BY networkPrefix DESC, hostPart DESC, cidr DESC"); + ($npCol < $net) OR + ($npCol = $net AND $hpCol < $host) OR + ($npCol = $net AND $hpCol = $host AND $cidrCol < $cidr) + ) ORDER BY $npCol DESC, $hpCol DESC, $cidrCol DESC"); return $parent unless @potParents; + my $potParentsWR = {}; foreach (@potParents) { my $potParent = $_; $potParent->{network} = &ipv6Parts2NetDec($potParent->{networkPrefix}, $potParent->{hostPart}, $potParent->{cidr}); + push @{$potParentsWR->{$potParent->{rootID}}}, $potParent; } - foreach (reverse &sortDBEntriesBy(\@potParents, 'network', 1, 1)) { - my $potParent = $_; - $networkDec = $potParent->{network}; - my $potBroadcast = &getV6BroadcastNet($networkDec, 128); - if ($potBroadcast >= $broadcast) { - $parent = $potParent; - $parent->{ipv6} = 1; - my $network = ($networkTable->search(['ID', 'network', 'description', 'state', 'defSubnetSize'], {ipv6ID => $parent->{ID}, rootID => $rootID, network => 0}, 0))[0]; - if (defined $network) { - $parent->{ID} = $network->{ID}; - $parent->{description} = $network->{description}; - $parent->{state} = $network->{state}; - $parent->{defSubnetSize} = $network->{defSubnetSize}; - last; - } else { - warn "NetV6 found ($parent->{ID}) with no matching network!\n"; - $parent = undef; + my @parents = (); + foreach (sort {$a<=>$b} keys %{$potParentsWR}) { + my $rootID = $_; + foreach (reverse &sortDBEntriesBy(\@{$potParentsWR->{$rootID}}, 'network', 1, 1)) { + my $potParent = $_; + $networkDec = $potParent->{network}; + my $potBroadcast = &getV6BroadcastNet($networkDec, 128); + if ($potBroadcast >= $broadcast) { + $parent = $potParent; + $parent->{ipv6} = 1; + my $network = ($networkTable->search(['ID', 'network', 'description', 'state', 'defSubnetSize'], {ipv6ID => $parent->{ID}, rootID => $rootID, network => 0}, 0))[0]; + if (defined $network) { + $parent->{ID} = $network->{ID}; + $parent->{description} = $network->{description}; + $parent->{state} = $network->{state}; + $parent->{defSubnetSize} = $network->{defSubnetSize}; + if ($limit == 1) { + last; + } else { + push @parents, $parent; + } + } else { + warn "NetV6 found ($parent->{ID}) with no matching network!\n"; + $parent = undef; + } } } + last if defined $parent && $limit == 1; } + $parent = \@parents unless $limit == 1; } else { - my $broadcast = &getBroadcastFromNet($networkDec); -# warn "BROADCAST (" . &dec2net($networkDec) . "): " . &dec2ip($broadcast) . "\n"; - $parent = ($networkTable->search(['ID', 'network', 'description', 'state', 'defSubnetSize'], "rootID='$rootID' AND ipv6ID='' AND network<'$networkDec' AND (FLOOR(network / 256) + power(2, (32 - MOD(network, 256))) > $broadcast) ORDER BY network DESC LIMIT 1"))[0]; + my $broadcast = &getBroadcastFromNet($networkDec); + my $riCol = $networkTable->meth2Col('rootID'); + my $ipv6IDCol = $networkTable->meth2Col('ipv6ID'); + my $nwCol = $networkTable->meth2Col('network'); + my $rootIDFilter = ($rootID == -1) ? '' : "$riCol='$rootID' AND"; + my @parents = $networkTable->search( + ['ID', 'network', 'description', 'state', 'defSubnetSize'], + "$rootIDFilter $ipv6IDCol='' AND $nwCol<'$networkDec' AND (FLOOR($nwCol / 256) + power(2, (32 - MOD($nwCol, 256))) > $broadcast) ORDER BY $nwCol DESC $limitStr" + ); + $parent = ($limit == 1) ? $parents[0] : \@parents; } return $parent; @@ -4019,7 +4598,7 @@ return {}; } - unless (defined $session->param('groupIDs')) { + unless (defined $session->param('groupIDs') && $session->param('groupIDs')) { my $user = ($userTable->search(['ID', 'groupIDs'], {username => $session->param('username')}))[0]; unless (defined $user) { &warnl("Cannot get Rights. No such User '" . $session->param('username') . "' in Database"); @@ -4038,16 +4617,22 @@ next unless defined $group; $session->param('bAdmin', 1) if !$groupID && $group->{name} eq 'Administrator'; - - my $cnter = 0; - my $cryptStr = substr($group->{permissions}, 1, length($group->{permissions}) - 1); - my $permStr = &dec2bin(&lwd($cryptStr)); - foreach (split//, substr($permStr, 1, length($permStr) - 1)) { - if (exists $conf->{static}->{rights}->{$cnter}) { - my $right = ($_ eq '1') ? 1 : 0; - $rights->{$conf->{static}->{rights}->{$cnter}->{short}} ||= $right; + + if ($group->{name} eq 'Administrator') { + foreach (keys %{$conf->{static}->{rights}}) { + $rights->{$conf->{static}->{rights}->{$_}->{short}} = 1; + } + } else { + my $cnter = 0; + my $cryptStr = substr($group->{permissions}, 1, length($group->{permissions}) - 1); + my $permStr = &dec2bin(&lwd($cryptStr)); + foreach (split//, substr($permStr, 1, length($permStr) - 1)) { + if (exists $conf->{static}->{rights}->{$cnter}) { + my $right = ($_ eq '1') ? 1 : 0; + $rights->{$conf->{static}->{rights}->{$cnter}->{short}} ||= $right; + } + $cnter++; } - $cnter++; } } @@ -4113,9 +4698,9 @@ sub compare { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - my $leftID = &getParam(1, undef, $q->param('leftRootID')); - my $rightID = &getParam(1, undef, $q->param('rightRootID')); - my $rootName = &getParam(1, undef, $q->param('resultName')); + my $leftID = &getParam(1, undef, 'leftRootID'); + my $rightID = &getParam(1, undef, 'rightRootID'); + my $rootName = &getParam(1, undef, 'resultName'); my $leftName = &rootID2Name($leftID); my $rightName = &rootID2Name($rightID); my $ipv6L = &rootID2ipv6($leftID); @@ -4198,12 +4783,13 @@ my $newNetwork = &net2dec($netaddress . '/' . $cidr); $networkTable->clear(); $networkTable->network($newNetwork); + $networkTable->searchStr($netaddress . '/' . $cidr); unless ($networkTable->update({ID => $netID})) { &warnl("Cannot update Net: " . $networkTable->errorStrs); if ($networkTable->errorStrs =~ /Duplicate entry/) { my $newNetwork2 = &net2dec($ip . '/' . 32); $networkTable->clear(); - $networkTable->network($newNetwork2); + $networkTable->network($ip . '/' . 32); unless ($networkTable->update({ID => $netID})) { &warnl("Cannot update Net: " . $networkTable->errorStrs); } @@ -4211,7 +4797,6 @@ } } } - } sub newWindow { @@ -4258,6 +4843,8 @@ my $status = shift; $status = $conf->{var}->{STATUS} unless ref $status eq 'HASH'; + + return unless defined $HaCi::HaCi::session; my $statID = $HaCi::HaCi::session->id(); my $statFile = $conf->{static}->{path}->{statusfile} . '_' . $statID . '.stat'; @@ -4281,7 +4868,10 @@ sub getStatus { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $statID = $HaCi::HaCi::session->id(); + my $session = $HaCi::HaCi::session; + return {} unless defined $session; + + my $statID = $session->id(); my $statFile = $conf->{static}->{path}->{statusfile} . '_' . $statID . '.stat'; return {} unless -f $statFile; @@ -4303,6 +4893,8 @@ my $value = shift; my $rootID = shift; my $s = $HaCi::HaCi::session; + return unless defined $s; + my $expands = $s->param('expands'); $s->clear('expands'); @@ -4315,14 +4907,20 @@ } else { my $ipv6 = &rootID2ipv6($rootID); $value = Math::BigInt->new($value) if $ipv6 && !ref $value; - my $parent = &getNextDBNetwork($rootID, $ipv6, $value, 1); - if (defined $parent) { + + if (0) { # we don't want to check for a parent, because we also want to expand an empty subnet + my $parent = &getNextDBNetwork($rootID, $ipv6, $value, 1); + if (defined $parent) { + $expands->{$target}->{$rootID}->{$value} = ($type eq '+') ? 1 : 0; + } + } else { $expands->{$target}->{$rootID}->{$value} = ($type eq '+') ? 1 : 0; } } } $s->param('expands', $expands); + $s->flush(); } sub splitNet { @@ -4333,7 +4931,7 @@ my $state = shift; my $tmplID = shift; my $delParent = shift; - $conf->{var}->{STATUS} = {TITLE => 'Splitting Network...', STATUS => 'Runnung...'}; &setStatus(); + $conf->{var}->{STATUS} = {TITLE => 'Splitting Network...', STATUS => 'Running...'}; &setStatus(); my ($rootID, $networkDec, $ipv6) = &netID2Stuff($netID); my $netaddressDec = ($ipv6) ? (&netv6Dec2IpCidr($networkDec))[0] : &getIPFromDec($networkDec); @@ -4358,7 +4956,7 @@ } } - &delNet($netID) if $delParent; + &delNet($netID, 0, 0, 0) if $delParent; $conf->{var}->{STATUS}->{STATUS} = 'FINISH'; &setStatus(); } @@ -4366,26 +4964,27 @@ warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - foreach ($q->param('combineNetsNr')) { - my $cnter = $_; - my $rootID = $q->param('combineNets_' . $cnter . '_rootID'); - my $networkDec = $q->param('combineNets_' . $cnter . '_result'); - my @sources = $q->param('combineNets_' . $cnter . '_source'); - my $descr = $q->param('combineNets_' . $cnter . '_descr'); - my $state = $q->param('combineNets_' . $cnter . '_state'); - my $tmplID = $q->param('combineNets_' . $cnter . '_tmplID'); + my $combineNetsNrs = &getParam(0, [], 'combineNetsNr'); + foreach (@{$combineNetsNrs}) { + my $cnter = $_; + my $rootID = &getParam(1, 0, 'combineNets_' . $cnter . '_rootID'); + my $networkDec = &getParam(1, 0, 'combineNets_' . $cnter . '_result'); + my $sources = &getParam(0, [], 'combineNets_' . $cnter . '_source'); + my $descr = &getParam(1, 0, 'combineNets_' . $cnter . '_descr'); + my $state = &getParam(1, 0, 'combineNets_' . $cnter . '_state'); + my $tmplID = &getParam(1, 0, 'combineNets_' . $cnter . '_tmplID'); my $ipv6 = &rootID2ipv6($rootID); $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); my ($ipaddress, $cidr) = split(/\//, $network, 2); if (&addNet(0, $rootID, $ipaddress, $cidr, $descr, $state, $tmplID, 0, 1)) { - foreach (@sources) { + foreach (@{$sources}) { my $networkDec = $_; $networkDec = Math::BigInt->new($networkDec) if $ipv6; my $ipv6ID = ($ipv6) ? &netv6Dec2ipv6ID($networkDec) : ''; my $netID = &getNetID($rootID, $networkDec, $ipv6ID); - &delNet($netID); + &delNet($netID, 0, 0, 0); } } } @@ -4562,10 +5161,13 @@ my $box = {}; - foreach ($q->param('pluginActives')) { + my $pluginActives = &getParam(0, [], 'pluginActives'); + foreach (@{$pluginActives}) { $box->{$_}->{ACTIVE} = 1; } - foreach ($q->param('pluginDefaults')) { + + my $pluginDefaults = &getParam(0, [], 'pluginDefaults'); + foreach (@{$pluginDefaults}) { $box->{$_}->{DEFAULT} = 1; } @@ -4595,7 +5197,7 @@ $networkPluginTable->netID(-1); $networkPluginTable->pluginID($ID); $networkPluginTable->errorStrs(''); - unless ($networkPluginTable->replace()) { + unless ($networkPluginTable->insert()) { # WAS replace. perhaps we have to check if it already exists &warnl("Cannot update Network Plugin Entry for '$name': " . $networkPluginTable->errorStrs()); } } else { @@ -4688,7 +5290,8 @@ return $return; } - my @plugins = $networkPluginTable->search(['*'], "netID='$netID' OR netID='-1'", 0, 0, 1); + my $netIDCol = $networkPluginTable->meth2Col('netID'); + my @plugins = $networkPluginTable->search(['*'], "$netIDCol='$netID' OR $netIDCol='-1'", 0, 0, 1); return $return unless @plugins; foreach (@plugins) { @@ -4704,8 +5307,9 @@ return if $conf->{var}->{DatabaseNotExist}; + my $dbType = &getConfigValue('db', 'dbtype'); eval { - require "HaCi/Tables/$name.pm"; + require "HaCi/Tables/$dbType/$name.pm"; }; if ($@) { warn "Error while loading Table '$name': $@\n"; @@ -4722,7 +5326,7 @@ } $DBIEasy::lastError = ''; - $conf->{var}->{TABLES}->{$name} = "HaCi::Tables::$name"->new($conf->{user}->{db}); + $conf->{var}->{TABLES}->{$name} = "HaCi::Tables::${dbType}::$name"->new($conf->{user}->{db}); if ($DBIEasy::lastError =~ /Unknown database (.*)/) { &warnl("Database $1 is not available! Perhaps you have to create it?"); $conf->{var}->{DatabaseNotExist} = 1; @@ -4849,7 +5453,12 @@ sub diffTable { my $table = shift; my $tableName = $table->TABLE(); + my $dbType = &getConfigValue('db', 'dbtype'); &debug("Checking Table: $tableName"); + my $dbType2Parser = { + mysql => 'MySQL', + postgresql => 'PostgreSQL' + }; my $alterCnter = 0; my $errorCnter = 0; @@ -4857,15 +5466,15 @@ my $orig = ${${$dbh->selectall_arrayref("SHOW CREATE TABLE `$tableName`")}[0]}[1] . ";\n"; my $newTable = "CREATE TABLE `$tableName` (" . $table->CREATETABLE() . ");\n"; $newTable =~ s/\t/ /g; - my $t1 = SQL::Translator->new(parser=>'MySQL', show_warnings=>0); - my $t2 = SQL::Translator->new(parser=>'MySQL', show_warnings=>0); + my $t1 = SQL::Translator->new(parser=>$dbType2Parser->{$dbType}, show_warnings=>0); + my $t2 = SQL::Translator->new(parser=>$dbType2Parser->{$dbType}, show_warnings=>0); my $diff; { BEGIN { $^W = 0 } $diff = SQL::Translator::Diff::schema_diff( - $t1->translate(\$orig), 'MySQL', - $t2->translate(\$newTable), 'MySQL', + $t1->translate(\$orig), $dbType2Parser->{$dbType}, + $t2->translate(\$newTable), $dbType2Parser->{$dbType}, { ignore_index_names => 1, ignore_constraint_names => 1, @@ -4879,6 +5488,11 @@ $diff =~ s/COMMIT;.*/COMMIT;/ms; return 0 if $diff =~ /^\s*BEGIN;\s*ALTER TABLE\s*$tableName\s*;\s*COMMIT;\s*$/ms; + if (0) { + warn "T1: $orig\n"; + warn "T2: $newTable\n"; + } + &debug("Altering Table $tableName..."); foreach (split/\n/, $diff) { s/\s*--.*//; @@ -4904,6 +5518,10 @@ my $checkForce = shift || 0; my $tableHashes = &getTableHashes(); + my $dbType = &getConfigValue('db', 'dbtype'); + + # we currently support database checking only for mysql + return unless $dbType eq 'mysql'; my $bChanged = 0; my $errorTold = 0; @@ -4928,7 +5546,7 @@ my $tableFileName = $_; &debug("Checking Table $tableFileName...\n") if 0; - my $tableFile = $conf->{static}->{path}->{workdir} . "/modules/HaCi/Tables/$tableFileName.pm"; + my $tableFile = $conf->{static}->{path}->{workdir} . "/modules/HaCi/Tables/$dbType/$tableFileName.pm"; unless (-f $tableFile) { warn "Configured Table '$tableFileName' doesnt't exists? ($tableFile: $!)\n"; } @@ -4975,6 +5593,48 @@ return $filename; } +sub checkNetworkTable { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + &debug ("Checking Network table...\n"); + my $networkTable = $conf->{var}->{TABLES}->{network}; + unless (defined $networkTable) { + warn "Cannot check networks. DB Error (network)\n"; + return 0; + } + unless ($networkTable->can('searchStr')) { + warn "Cannot update missing network search strings, because the table network object is not up to date\n"; + return 0; + } + + my @missingNetworkSearchStrs = $networkTable->search(['ID', 'network'], {searchStr => ''}); + my $cnter = 0; + if (scalar @missingNetworkSearchStrs > 0) { + warn '' . scalar @missingNetworkSearchStrs . " missing network search strings found. Updating...\n"; + foreach (@missingNetworkSearchStrs) { + my $networkEntry = $_; + my $netID = $networkEntry->{ID}; + my $networkDec = $networkEntry->{network}; + my $ipv6 = 0; + (undef, $networkDec, $ipv6) = &netID2Stuff($netID) unless $networkDec; + my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); + + if ($ipv6) { + my ($ip, $cidr) = split(/\//, $network, 2); + $ip = Net::IPv6Addr::to_string_compressed($ip); + $network = join('/', $ip, $cidr); + } + $networkTable->searchStr($network); + unless ($networkTable->update({ID => $netID})) { + warn "Cannot update Net: " . $networkTable->errorStrs; + } else { + $cnter++; + } + } + warn "Successfully updated $cnter networks\n"; + } +} + sub checkNetworkACTable { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; @@ -5050,19 +5710,21 @@ return 0; } - my @pluginConfEntries = $pluginConfTable->search(['*'], {pluginID => $pluginID, netID => $netID}); - - unless (@pluginConfEntries) { - my $pluginName = &pluginID2Name($pluginID); - &debug("No Plugin Config for Plugin '$pluginName' found!\n"); - return {}; - } + my @pluginConfEntries = $pluginConfTable->search(['*'], {pluginID => $pluginID, netID => $netID}); + my @pluginConfEntriesGlobal = $pluginConfTable->search(['*'], {pluginID => $pluginID, netID => -1}); foreach (@pluginConfEntries) { my $pluginConfEntry = $_; $pluginConf->{$pluginConfEntry->{name}} = $pluginConfEntry->{value}; } + foreach (@pluginConfEntriesGlobal) { + my $pluginConfEntry = $_; + next if $pluginConfEntry->{value} eq ''; + + $pluginConf->{$pluginConfEntry->{name}} = $pluginConfEntry->{value} unless exists $pluginConf->{$pluginConfEntry->{name}} && $pluginConf->{$pluginConfEntry->{name}} ne ''; + } + return $pluginConf; } @@ -5251,8 +5913,8 @@ my $global = shift || 0; my $q = $HaCi::HaCi::q; - my $pluginID = &getParam(1, undef, $q->param('pluginID')); - my $netID = &getParam(1, undef, $q->param('netID')); + my $pluginID = &getParam(1, undef, 'pluginID'); + my $netID = &getParam(1, undef, 'netID'); my $pluginFilename = &pluginID2File($pluginID); my $pluginInfos = (&getPluginInfos($pluginFilename))[1]; $netID = -1 unless defined $netID; @@ -5284,12 +5946,12 @@ next if exists $entry->{NODB} && $entry->{NODB}; next if $entry->{TYPE} eq 'label' || $entry->{TYPE} eq 'hline'; - my $value = &getParam(1, undef, $q->param('pluginConfName_' . $entry->{NAME})); + my $value = &getParam(1, undef, 'pluginConfName_' . $entry->{NAME}); $value = '' unless defined $value; &updatePluginConf($pluginID, $netID, $entry->{NAME}, $value); } - my $resetLastRun = &getParam(1, 0, $q->param('pluginConfName_def_recurrent_resetLastRun')); - $resetLastRun ||= &getParam(1, 0, $q->param('pluginConfName_def_glob_recurrent_resetLastRun')); + my $resetLastRun = &getParam(1, 0, 'pluginConfName_def_recurrent_resetLastRun'); + $resetLastRun ||= &getParam(1, 0, 'pluginConfName_def_glob_recurrent_resetLastRun'); &updatePluginLastRun($pluginID, 0, 0, '') if $resetLastRun; } @@ -5349,6 +6011,8 @@ &closeTable('networkV6'); &closeTable('networkAC'); &closeTable('networkPlugin'); + &closeTable('networkLock'); + &closeTable('networkTag'); &closeTable('template'); &closeTable('templateEntry'); &closeTable('templateValue'); @@ -5356,6 +6020,7 @@ &closeTable('pluginConf'); &closeTable('pluginValue'); &closeTable('setting'); + &closeTable('audit'); } sub initTables { @@ -5369,6 +6034,8 @@ &getTable('networkV6'); &getTable('networkAC'); &getTable('networkPlugin'); + &getTable('networkLock'); + &getTable('networkTag'); &getTable('template'); &getTable('templateEntry'); &getTable('templateValue'); @@ -5376,6 +6043,7 @@ &getTable('pluginConf'); &getTable('pluginValue'); &getTable('setting'); + &getTable('audit'); } sub initCache { @@ -5414,30 +6082,30 @@ } } else { eval { - $netCache = new Cache::FastMmap->new( + $netCache = Cache::FastMmap->new( share_file => $conf->{static}->{path}->{cachefile} . '_NET' || '/tmp/HaCi.cache_NET', - page_size => '1024k', + page_size => '4024k', num_pages => 3, ); unless (defined $netCache) { - $netCache = new Cache::FastMmap->new( + $netCache = Cache::FastMmap->new( share_file => $conf->{static}->{path}->{cachefile} . '_NET' || '/tmp/HaCi.cache_NET', init_file => 1, - page_size => '1024k', + page_size => '4024k', num_pages => 3, ); } - $aclCache = new Cache::FastMmap->new( + $aclCache = Cache::FastMmap->new( share_file => $conf->{static}->{path}->{cachefile} . '_ACL' || '/tmp/HaCi.cache_ACL', - page_size => '1024k', + page_size => '4024k', num_pages => 3, ); unless (defined $aclCache) { - $aclCache = new Cache::FastMmap->new( + $aclCache = Cache::FastMmap->new( share_file => $conf->{static}->{path}->{cachefile} . '_ACL' || '/tmp/HaCi.cache_ACL', init_file => 1, - page_size => '1024k', + page_size => '4024k', num_pages => 3, ); } @@ -5453,12 +6121,19 @@ sub fillHoles { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $fromNetDec = shift; - my $toNetDec = shift; - my $ipv6 = shift; - my $defSubnetSize = shift || 0; - my $newNets = &getNetCacheEntry('FILL', 0, "$fromNetDec:$toNetDec:$ipv6:$defSubnetSize"); - my @newNets = (); + my $fromNetDec = shift; + my $toNetDec = shift; + my $ipv6 = shift; + my $defSubnetSize = shift || 0; + my $maxNetworks = shift || 0; + my $checkNetworkLock = shift || 0; + my $rootID = shift || 0; + my $newNets = ($checkNetworkLock) ? undef : &getNetCacheEntry('FILL', 0, "$fromNetDec:$toNetDec:$ipv6:$defSubnetSize:$maxNetworks"); + my @newNets = (); + +warn "From: " . (($ipv6) ? &netv6Dec2net($fromNetDec) : &dec2net($fromNetDec)) . "\n" if 0; +warn "To: " . (($ipv6) ? &netv6Dec2net($toNetDec) : &dec2net($toNetDec)) . "\n" if 0; +warn "SNS: $defSubnetSize\n" if 0; unless (defined $newNets) { my $fromIPDec = ($ipv6) ? (&netv6Dec2IpCidr($fromNetDec))[0] : &getIPFromDec($fromNetDec); @@ -5470,8 +6145,8 @@ ($startIP, $startCidr) = split(/\//, &dec2net($fromNetDec)); } - my $startIPDec = ($ipv6) ? $fromIPDec->copy() : $fromIPDec; - + my $startIPDec = ($ipv6) ? $fromIPDec->copy() : $fromIPDec; + my $newNetsCnter = 0; if ($ipv6) { while ($startIPDec->bcmp($endIPDec) < 0) { my $ipDiff = $endIPDec->copy()->bsub($startIPDec); @@ -5479,8 +6154,9 @@ $exp = 128 - $defSubnetSize if $defSubnetSize > (128 - $exp); my $offset = Math::BigInt->new(2)->bpow($exp); last if $exp < 0; - + while ($exp > 0) { +warn "EXP: $exp (" . (128 - $exp) . ")\n" if 0; last if ($startIPDec->copy()->bmod($offset) == 0) && ( @@ -5493,8 +6169,15 @@ my $cidr = 128 - $exp; - my $newNet = &ipv6DecCidr2netv6Dec($startIPDec, $cidr); - push @newNets, $newNet; + if (!$defSubnetSize || ($defSubnetSize && ($cidr == $defSubnetSize))) { + my $newNet = &ipv6DecCidr2netv6Dec($startIPDec, $cidr); +warn "Found new network: " . &netv6Dec2net($newNet) . "\n" if 0; + if (($checkNetworkLock && &checkNetworkLock($rootID, $newNet, $ipv6, 1)) || !$checkNetworkLock) { + push @newNets, $newNet; + $newNetsCnter++; + last if ($maxNetworks && $newNetsCnter >= $maxNetworks) || $newNetsCnter > 10000; + } + } $startIPDec->badd(Math::BigInt->new(2)->bpow($exp)); } @@ -5506,6 +6189,7 @@ last if $exp < 0; while ($exp > 0) { +warn "EXP: $exp (" . (32 - $exp) . ")\n" if 0; last if (($startIPDec % $offset) == 0) && ( @@ -5517,15 +6201,21 @@ } my $cidr = 32 - $exp; - - my $newNet = &net2dec(&dec2ip($startIPDec) . "/$cidr"); - push @newNets, $newNet; + if (!$defSubnetSize || ($defSubnetSize && ($cidr == $defSubnetSize))) { + my $newNet = &net2dec(&dec2ip($startIPDec) . "/$cidr"); +warn "Found new network: " . &dec2net($newNet) . "\n" if 0; + if (($checkNetworkLock && &checkNetworkLock($rootID, $newNet, $ipv6, 1)) || !$checkNetworkLock) { + push @newNets, $newNet; + $newNetsCnter++; + last if ($maxNetworks && $newNetsCnter >= $maxNetworks) || $newNetsCnter > 10000; + } + } $startIPDec += 2 ** $exp; } } - &updateNetcache('FILL', 0, "$fromNetDec:$toNetDec:$ipv6:$defSubnetSize", \@newNets); + &updateNetcache('FILL', 0, "$fromNetDec:$toNetDec:$ipv6:$defSubnetSize:$maxNetworks", \@newNets); } else { @newNets = @{$newNets}; } @@ -5641,16 +6331,20 @@ my $netID = shift; my $scalar = shift || 0; - my $subnetSize = shift; + my $subnetSize = shift || 0; + my $amount = shift || 0; + my $ignoreSubnet = shift || 0; # return also netaddress and broadcast (with v4) my $net = &getMaintInfosFromNet($netID); my $ipv6 = ($net->{ipv6ID}) ? 1 : 0; my $networkDec = $net->{network}; + my $netaddressDec = ($ipv6) ? (&netv6Dec2IpCidr($networkDec))[0] : &getIPFromDec($networkDec); + my $rootID = $net->{rootID}; my $broadcast = ($ipv6) ? &getV6BroadcastNet($networkDec, 128) : &net2dec(&dec2ip(&getBroadcastFromNet($networkDec)) . '/32'); my $nextNetDec = ($ipv6) ? &netv6Dec2NextNetDec($broadcast, 128) : &net2dec(&dec2ip(&getIPFromDec($broadcast) + 1) . '/32'); my $defSubnetSize = $net->{defSubnetSize}; my $freeSubnetst = {}; - my $subnetCnter = 0; $defSubnetSize = $subnetSize if defined $subnetSize; + $amount = 0 if $amount == -1; my @childs = &getNetworkChilds($netID); my $startNet = $networkDec; @@ -5659,41 +6353,75 @@ my $childDec = $child->{network}; my $childNet = ($ipv6) ? &netv6Dec2net($childDec) : &dec2net($childDec); - foreach (&fillHoles($startNet, $childDec, $ipv6, $defSubnetSize)) { - my $network = ($ipv6) ? &netv6Dec2net($_) : &dec2net($_); + foreach (&fillHoles($startNet, $childDec, $ipv6, $defSubnetSize, (($amount) ? ($amount + 1) : $amount), 1, $rootID)) { + my $currNet = $_; + my $network = ($ipv6) ? &netv6Dec2net($currNet) : &dec2net($currNet); my $cidr = (split/\//, $network, 2)[1]; - $freeSubnetst->{$subnetCnter++} = $network if !$defSubnetSize || ($cidr == $defSubnetSize); + my $bOK = 1; + if (!$ignoreSubnet && !$ipv6 && $subnetSize eq (($ipv6) ? 128 : 32)) { + my $currNetaddrDec = ($ipv6) ? &ipv6DecCidr2NetaddressV6Dec(&ipv62dec(&netv6Dec2ip($currNet)), $cidr) : &getNetaddress(&getIPFromDec($currNet), &getNetmaskFromCidr($cidr)); + $bOK = 0 if $currNetaddrDec == $netaddressDec; + + my $currBroadcast = ($ipv6) ? &getV6BroadcastNet($currNet, 128) : &net2dec(&dec2ip(&getBroadcastFromNet($currNet)) . '/32'); + $bOK = 0 if $currBroadcast == $broadcast; + } + $freeSubnetst->{$currNet} = $network if $bOK && (!$defSubnetSize || ($cidr == $defSubnetSize)); } $startNet = ($ipv6) ? &netv6Dec2NextNetDec($childDec, 0) : &net2dec(&dec2ip(&getBroadcastFromNet($childDec) + 1) . '/0'); } - - foreach (&fillHoles($startNet, $nextNetDec, $ipv6, $defSubnetSize)) { - my $network = ($ipv6) ? &netv6Dec2net($_) : &dec2net($_); + foreach (&fillHoles($startNet, $nextNetDec, $ipv6, $defSubnetSize, (($amount) ? ($amount + 1) : $amount), 1, $rootID)) { + my $currNet = $_; + my $network = ($ipv6) ? &netv6Dec2net($currNet) : &dec2net($currNet); my $cidr = (split/\//, $network, 2)[1]; - $freeSubnetst->{$subnetCnter++} = $network if !$defSubnetSize || ($cidr == $defSubnetSize); + my $bOK = 1; + if (!$ignoreSubnet && !$ipv6 && $subnetSize eq (($ipv6) ? 128 : 32)) { + my $currNetaddrDec = ($ipv6) ? &ipv6DecCidr2NetaddressV6Dec(&ipv62dec(&netv6Dec2ip($currNet)), $cidr) : &getNetaddress(&getIPFromDec($currNet), &getNetmaskFromCidr($cidr)); + $bOK = 0 if $currNetaddrDec == $netaddressDec; + + my $currBroadcast = ($ipv6) ? &getV6BroadcastNet($currNet, 128) : &net2dec(&dec2ip(&getBroadcastFromNet($currNet)) . '/32'); + $bOK = 0 if $currBroadcast == $broadcast; + } + $freeSubnetst->{$currNet} = $network if $bOK && ($currNet != $networkDec && (!$defSubnetSize || ($cidr == $defSubnetSize))); } - my @freeSubnets = (); - my @sorted = (); + return scalar keys %{$freeSubnetst} if $scalar; + + my @sorted = (); if ($ipv6) { - @sorted = sort {Math::BigInt->new($a)<=>Math::BigInt->new($b)} keys %{$freeSubnetst}; + @sorted = &ipv6Sort(keys %{$freeSubnetst}); } else { @sorted = sort {$a<=>$b} keys %{$freeSubnetst}; } - map { - push @freeSubnets, $freeSubnetst->{$_}; - } @sorted; - return ($scalar) ? $subnetCnter : @freeSubnets; + + my $cnter = 0; + my @freeSubnets = (); + foreach (@sorted) { + my $networkDec = $_; + my $network = $freeSubnetst->{$networkDec}; + last if $amount && ++$cnter > $amount; + push @freeSubnets, $network; + }; + + if ($conf->{var}->{soap}) { + @{$HaCi::GUI::init::t->{V}->{freeSubnets}} = map { + { + network => $_, + rootName => &rootID2Name($rootID) + }; + } @freeSubnets; + } + + return @freeSubnets; } sub chOwnPW { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; my $q = $HaCi::HaCi::q; - my $oldPW = &getParam(1, undef, $q->param('oldPassword')); - my $newPW = &getParam(1, undef, $q->param('newPassword')); - my $newPWVal = &getParam(1, undef, $q->param('newPasswordVal')); + my $oldPW = &getParam(1, undef, 'oldPassword'); + my $newPW = &getParam(1, undef, 'newPassword'); + my $newPWVal = &getParam(1, undef, 'newPasswordVal'); my $session = $HaCi::HaCi::session; my $userName = $session->param('username') || ''; @@ -5799,14 +6527,16 @@ &warnl("Cannot set settings. DB Error (setting)"); } - foreach ($q->param) { + my @params = $q->param(); + foreach (@params) { if (/^setting_(.*)$/) { my $param = $1; - @{$newSettings->{$param}} = ($q->param($_)); + @{$newSettings->{$param}} = (&getParam(1, undef, $_)); } } - foreach ($q->param('settingParams')) { + my $settingParams = &getParam(0, [], 'settingParams'); + foreach (@{$settingParams}) { my $param = $_; $newSettings->{$param} = [0] unless exists $newSettings->{$param}; } @@ -5863,6 +6593,7 @@ my $settings = &getSettings($userID); $s->param('settings', $settings); + $s->flush(); } sub quoteHTML { @@ -5949,104 +6680,140 @@ sub searchAndGetFreeSubnets { warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; - my $q = $HaCi::HaCi::q; - my $t = $HaCi::GUI::init::t; - my $subnetSize = &getParam(1, -1, $q->param('size')); + my $search = shift || ''; + my $bLike = shift || 0; + my $bFuzzy = shift || 0; + my $bshNrOfFreeSubs = shift || 0; + my $rootID = shift; + my $state = shift; + my $tmplID = shift; + my $tmplBox = shift || {}; + my $subnetSize = shift || 0; + my $amount = shift || 0; + + my $q = $HaCi::HaCi::q; + if (ref($q)) { + $subnetSize = &getParam(1, -1, 'size'); + $amount = &getParam(1, 3, 'amount'); + } - &search(); - my $result = $t->{V}->{searchResult}; + my $result = &search($search, $bLike, $bFuzzy, $bshNrOfFreeSubs, $rootID, $state, $tmplID, $tmplBox); + my $t = $HaCi::GUI::init::t; + $t->{V}->{freeSubnets} = []; - my @freeSubnetst = (); + my $returnFreeSubnets = []; + my @freeSubnetst = (); if (defined $result && ref($result) eq 'ARRAY') { + my $counter = 0; foreach (@{$result}) { - my $network = $_; + my $network = $_; + my ($rootID, $networkDec, undef) = &netID2Stuff($network->{netID}); if ($subnetSize == -1) { $subnetSize = ($network->{network} =~ /:/) ? 128 : 32; } - my @freeSubnets = &getFreeSubnets($network->{netID}, 0, $subnetSize); + my @freeSubnets = &getFreeSubnets($network->{netID}, 0, $subnetSize, $amount); next unless @freeSubnets; - push @freeSubnetst, @freeSubnets; + foreach (@freeSubnets) { + push @freeSubnetst, {rootID => $rootID, network => $_}; + last if ++$counter >= $amount; + } + last if ++$counter >= $amount; + } + + map { + my $ipv6 = ($_ =~ /:/) ? 1 : 0; + my $dec = ($ipv6) ? &netv62Dec($_->{network}) : &net2dec($_->{network}); + my $rootID = $_->{rootID}; + push @{$returnFreeSubnets}, { + network => $_->{network}, + url => "$conf->{var}->{thisscript}?func=addNet&netID=0&rootID=$rootID&networkDec=$dec&fillNet=1", + dec => $dec, + rootID => $rootID, + rootName => &rootID2Name($rootID) + }; + } @freeSubnetst; + $t->{V}->{freeSubnets} = $returnFreeSubnets; + map {$_->{rootName} = "eHTML($_->{rootName})} @{$t->{V}->{freeSubnets}}; + + if (scalar @{$returnFreeSubnets} == 0) { + $t->{V}->{noSearchResult} = 1; + $t->{V}->{'gettext_nothing_found'} = _gettext("No free networks found"); } } - my $freeSubnets = []; - map { - my $ipv6 = ($_ =~ /:/) ? 1 : 0; - push @{$freeSubnets}, { - net => $_, - dec => ($ipv6) ? &netv62Dec($_) : &net2dec($_), - }; - } @freeSubnetst; - - $t->{V}->{freeSubnets} = $freeSubnets; + return $returnFreeSubnets; } sub checkStateRules { - my $netID = shift; - my $rootID = shift; - my $networkDec = shift; - my $state = shift; - my $cidr = shift; - my $ipv6 = shift; - - &debug("Checking Network State ($rootID:" . &dn($networkDec) . " => $state)\n") if 0; - - my $states = $conf->{static}->{misc}->{networkstates}; - foreach (@$states) { - if ($state eq $_->{id}) { - my $se = $_; - my $stateName = &networkStateID2Name($state); - if (exists $se->{minsize} && $cidr > $se->{minsize}) { - &warnl(sprintf(_gettext("The minimum %s size is /%i!"), $stateName, $se->{minsize})); - return 0; - } - if (exists $se->{parents}) { - my $nok = 1; - my $netParent = &getNetworkParentFromDB($rootID, $networkDec); - if (defined $netParent) { - my @parents = split(/\s*,\s*/, $se->{parents}); - foreach (@parents) { - $nok = 0 if $_ == $netParent->{state}; - } - if ($nok) { - &warnl(sprintf(_gettext("%ss can only be made from allocations with a status of %s"), $stateName, join(' ' . _gettext('or') . ' ', map {&networkStateID2Name($_)} @parents))); - return 0; - } + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $netID = shift; + my $rootID = shift; + my $networkDec = shift; + my $state = shift; + my $cidr = shift; + my $ipv6 = shift; + + &debug("Checking Network State ($rootID:" . &dn($networkDec) . " => $state)\n") if 0; + + my $states = $conf->{static}->{misc}->{networkstates}; + foreach (@$states) { + if ($state eq $_->{id}) { + my $se = $_; + my $stateName = &networkStateID2Name($state); + if (exists $se->{minsize} && $cidr > $se->{minsize}) { + &warnl(sprintf(_gettext("The minimum %s size is /%i!"), $stateName, $se->{minsize})); + return 0; + } + if (exists $se->{parents}) { + my $nok = 1; + my $netParent = &getNetworkParentFromDB($rootID, $networkDec); + if (defined $netParent) { + my @parents = split(/\s*,\s*/, $se->{parents}); + foreach (@parents) { + $nok = 0 if $_ == $netParent->{state}; } - } - if (exists $se->{banparents}) { - my @basnishedStates = split(/\s*,\s*/, $se->{banparents}); - if (my $badNet = &checkbanishFromParents($rootID, $networkDec, \@basnishedStates)) { - &warnl(sprintf(_gettext("%ss can only be made when there's no less specific inetnum (%s) with a status of '%s'"), $stateName, &dn($badNet->{network}), join(' ' . _gettext('or') . ' ', map {&networkStateID2Name($_)} @basnishedStates))); - return 0; + if ($nok) { + &warnl(sprintf(_gettext("%ss can only be made from allocations with a status of %s"), $stateName, join(' ' . _gettext('or') . ' ', map {&networkStateID2Name($_)} @parents))); + return 0; } } - if (exists $se->{banish}) { - my @basnishedStates = split(/\s*,\s*/, $se->{banish}); - if (my $badNet = &checkbanishFromParents($rootID, $networkDec, \@basnishedStates)) { - &warnl(sprintf(_gettext("%ss can only be made when there's no less specific inetnum (%s) with an 'Assigned' status"), $stateName, &dn($badNet->{network}))); + } + if (exists $se->{banparents}) { + my @basnishedStates = split(/\s*,\s*/, $se->{banparents}); + if (my $badNet = &checkbanishFromParents($rootID, $networkDec, \@basnishedStates)) { + &warnl(sprintf(_gettext("%ss can only be made when there's no less specific inetnum (%s) with a status of '%s'"), $stateName, &dn($badNet->{network}), join(' ' . _gettext('or') . ' ', map {&networkStateID2Name($_)} @basnishedStates))); + return 0; + } + } + if (exists $se->{banish}) { + my @basnishedStates = split(/\s*,\s*/, $se->{banish}); + if (my $badNet = &checkbanishFromParents($rootID, $networkDec, \@basnishedStates)) { + &warnl(sprintf(_gettext("%ss can only be made when there's no less specific inetnum (%s) with an 'Assigned' status"), $stateName, &dn($badNet->{network}))); + return 0; + } + if ($netID) { + if (my $badNet = &checkbanishFromChilds($netID, \@basnishedStates)) { + &warnl(sprintf(_gettext("%ss can only be made when there's no more specific inetnum (%s) with an 'Assigned' status"), $stateName, &dn($badNet->{network}))); return 0; } - if ($netID) { - if (my $badNet = &checkbanishFromChilds($netID, \@basnishedStates)) { - &warnl(sprintf(_gettext("%ss can only be made when there's no more specific inetnum (%s) with an 'Assigned' status"), $stateName, &dn($badNet->{network}))); - return 0; - } - } - } - if (exists $se->{ipv6} && !$ipv6) { - &warnl(sprintf(_gettext("%s is a new Value for inet6num Objects and so it's not available for inetnum Objects"), $stateName)); - return 0; } - return 1; } + if (exists $se->{ipv6} && !$ipv6) { + &warnl(sprintf(_gettext("%s is a new Value for inet6num Objects and so it's not available for inetnum Objects"), $stateName)); + return 0; + } + return 1; } - &warnl("State id '$state' doesn't exists in Config!", 1); - return 0; + } + &warnl("State id '$state' doesn't exists in Config!", 1); + return 0; } sub checkbanishFromParents { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + my $rootID = shift; my $networkDec = shift; my $basnishedStates = shift; @@ -6061,6 +6828,8 @@ } sub checkbanishFromChilds { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + my $netID = shift; my $basnishedStates = shift; my @childs = &getNetworkChilds($netID, 0, 0); @@ -6080,18 +6849,364 @@ } sub getParam { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $q = $HaCi::HaCi::q; my $onlyScalar = shift; my $ifUndef = shift; - my @values = @_; - - return $ifUndef unless defined $values[0]; + my $paramName = shift; + my $urlEncode = shift || 0; + return $ifUndef unless defined $paramName; + + my @values = $q->param($paramName); + unless (defined $values[0]) { + return $ifUndef if $onlyScalar; + return [] if $ifUndef =~ /^0$/; # return empty list if onlyScalar != 1 && ifUndef == 0 + return $ifUndef; + } if ($onlyScalar) { - &debug("called function 'getParam' with option 'onlyScalar' AND more than one value! (" . (caller(0))[0] . '->' . (caller(0))[2] . ')') if $#values > 0; + &debug("called function 'getParam' on parameter '$paramName' with option 'onlyScalar' AND more than one value! (" . (caller(0))[0] . '->' . (caller(0))[2] . ')') if $#values > 0; + return "eHTML($values[0]) if $urlEncode; return $values[0]; } - return @values; + return \@values; +} + +sub tableContent2Str { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $tableObject = shift; + my $returnStr = ''; + + foreach (sort keys %{$tableObject->{COLOUMNS}}) { + next if $_ eq 'createFrom' || $_ eq 'createDate' || $_ eq 'modifyFrom' || $_ eq 'modifyDate' || $_ eq 'ID'; + $returnStr .= ';' if $returnStr; + $returnStr .= $_ . '=' . ($tableObject->{COLOUMNS}->{$_} || '') + } + + return $returnStr; +} + +sub audit { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $action = shift; + my $object = shift; + my $value = shift || ''; + my $error = shift || ''; + my $global = shift || 0; + my $s = $HaCi::HaCi::session; + my $username = $s->param('username'); + my $groupIDs = $s->param('groupIDs'); + $groupIDs = '*,' if $global; + $groupIDs =~ s/[^\d,\*]//g; + + + my $auditTable = $conf->{var}->{TABLES}->{audit}; + unless (defined $auditTable) { + warn "Cannot add audit log. DB Error (audit)\n"; + return 0; + } + + $auditTable->clear(); + $auditTable->ts(&currDate('datetime')); + $auditTable->username($username); + $auditTable->accessGroups(',' . $groupIDs); + $auditTable->action($action); + $auditTable->object($object); + $auditTable->value($value); + $auditTable->error($error); + + unless ($auditTable->insert()) { + my $errStr = "Cannot insert new audit log: " . $auditTable->errorStrs; + &warnl($errStr, 1); + return 0; + } + return 1; +} + +sub getAuditLogs { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $limit = shift || 100; + my $page = shift || 0; + my $sortBy = shift || 'ts'; + my $bReverse = shift || 0; + my $searchFor = shift || 0; + my $quoteHTML = shift || 0; + my $offset = $limit * $page; + my $s = $HaCi::HaCi::session; + + my $auditTable = $conf->{var}->{TABLES}->{audit}; + unless (defined $auditTable) { + warn "Cannot get audit log. DB Error (audit)\n"; + return 0; + } + + $searchFor =~ s/['"]//g; + my $query = 'WHERE 1=1'; + if ($searchFor) { + my $tsCol = $auditTable->meth2Col('ts'); + my $usernameCol = $auditTable->meth2Col('username'); + my $actionCol = $auditTable->meth2Col('action'); + my $objectCol = $auditTable->meth2Col('object'); + my $valueCol = $auditTable->meth2Col('value'); + my $dbType = &getConfigValue('db', 'dbtype'); + + $query .= qq{ AND (}; + if ($dbType eq 'postgresql') { + $query .= qq{CAST($tsCol AS text) like '%$searchFor%' OR }; + } else { + $query .= qq{$tsCol like '%$searchFor%' OR }; + } + $query .= qq{$usernameCol like '%$searchFor%' OR $actionCol like '%$searchFor%' OR $objectCol like '%$searchFor%' OR $valueCol like '%$searchFor%')}; + } + + my $accGrtCol = $auditTable->meth2Col('accessGroups'); + unless ($s->param('bAdmin')) { + $query .= " AND ($accGrtCol like '%,*,%'"; + my $groupIDs = $s->param('groupIDs'); + + foreach (split(/, /, $groupIDs)) { + s/\D//g; + $query .= " OR $accGrtCol like '%,$_,%'" + } + + $query .= ')'; + } + + my $queryC = $query; + my $sortCol = $auditTable->meth2Col($sortBy); + my $dir = (!$bReverse) ? 'DESC' : 'ASC'; + $query .= " ORDER BY $sortCol $dir LIMIT $limit OFFSET $offset"; + + my @auditLogsT = $auditTable->search(['*'], {}, 0, $query); + my $sorted = {}; + foreach (@auditLogsT) { + my $audit = $_; + if ($quoteHTML) { + foreach (qw(object value username error)) { + $audit->{$_} = "eHTML($audit->{$_}); + } + } + push @{$sorted->{$_->{$sortCol}}}, $audit; + } + my @auditLogs = (); + my @sortKeys = (!$bReverse) ? reverse sort keys %{$sorted} : sort keys %{$sorted}; + foreach (@sortKeys) { + push @auditLogs, @{$sorted->{$_}}; + } + + my $totalAuditLogs = $auditTable->count({}, 0, $queryC); + + return (\@auditLogs, $totalAuditLogs); +} + +sub checkNetworkLock { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $rootID = shift; + my $networkDec = shift; + my $ipv6 = shift; + my $quiet = shift || 0; + my $bOK = 1; + $networkDec = Math::BigInt->new($networkDec) if $ipv6; + my $network = ($ipv6) ? &netv6Dec2net($networkDec) : &dec2net($networkDec); + + &debug("Checking network lock for '$network'"); + + my $networkLockTable = $conf->{var}->{TABLES}->{networkLock}; + unless (defined $networkLockTable) { + my $err = "Cannot check network lock. DB Error (networkLock)"; + &warnl($err); + return 0; + } + + my $networkPrefix = 0; + my $hostPart = 0; + my $cidr = 0; + if ($ipv6) { + ($networkPrefix, $hostPart, $cidr) = &HaCi::Mathematics::netv6Dec2PartsDec($networkDec); + } else { + ($networkPrefix, $cidr) = ($networkDec, &HaCi::Mathematics::getCidrFromDec($networkDec)); + } + + my @networkLocks = $networkLockTable->search(); + foreach (@networkLocks) { + my $networkLockDB = $_; + my $networkLockID = $networkLockDB->{ID}; + my $duration = $networkLockDB->{duration}; + my $cRootID = $networkLockDB->{rootID}; + my $cNetworkPrefix = $networkLockDB->{networkPrefix}; + my $cHostPart = $networkLockDB->{hostPart}; + my $cCidr = $networkLockDB->{cidr}; + my $cIPv6 = $networkLockDB->{ipv6}; + my $start = &convDatetime2time($networkLockDB->{ts}); + my $till = $start + $duration; + my $tillStr = scalar localtime($start + $duration); + my $still = $till - time; + my $cNetwork = ($ipv6) ? &netv6Dec2net(&ipv6Parts2NetDec($cNetworkPrefix, $cHostPart, $cCidr)) : &dec2net($cNetworkPrefix); + + if ((time - $till) < 0) { + if ($networkPrefix eq $cNetworkPrefix && $hostPart eq $cHostPart && $cidr == $cCidr && $rootID eq $cRootID && $ipv6 == $cIPv6) { + &warnl(sprintf(_gettext("Sorry, the network '%s' is still locked for '%i' seconds till '%s'!"), $cNetwork, $still, $tillStr)) unless $quiet; + $bOK = 0; + } + } else { + &debug("Locking for network '$cNetwork' is expired (" . scalar localtime() . " > $tillStr)"); + &removeNetworkLock($networkLockID); + } + } + + return $bOK; +} + +sub removeNetworkLock { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $networkLockID = shift; + + my $networkLockTable = $conf->{var}->{TABLES}->{networkLock}; + unless (defined $networkLockTable) { + my $err = "Cannot remove network lock. DB Error (networkLock)"; + &warnl($err); + return 0; + } + &debug("Deleting network lock '$networkLockID'"); + unless ($networkLockTable->delete({ID => $networkLockID})) { + &warnl(sprintf(_gettext("Error while deleting network lock '%i': %s"), $networkLockID, $networkLockTable->errorStrs)); + } +} + +sub exportSubnets { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $ID = shift; + my $bRootID = shift || 0; + my $name = 'NONAME'; + my $exportData = {}; + + my @childs = (); + if ($bRootID) { + my $rootID = $ID; + my $details = &getMaintInfosFromRoot($rootID); + my $rootName = $details->{name} || ''; + $name = $rootName; + unless (&checkRootACL($rootID, 'r')) { + &warnl(sprintf(_gettext("Not enough rights to export this Root '%s'"), $rootName), 0); + return 0; + } + + @childs = &getNetworkChilds($rootID, 1, 0); + } else { + my $netID = $ID; + my $details = &getMaintInfosFromNet($netID); + my $network = ($details->{ipv6}) ? &netv6Dec2net($details->{network}) : &dec2net($details->{network}); + $name = $network; + + unless (&checkNetACL($netID, 'r')) { + &warnl(sprintf(_gettext("Not enough rights to export this Network '%s'"), $network), 0); + return 0; + } + + @childs = &getNetworkChilds($netID, 0, 0); + } + + my $columns = {}; + foreach (@childs) { + my $child = $_; + my $details = &getMaintInfosFromNet($child->{ID}); + my $tmplData = &getTemplateData($child->{ID}, $details->{tmplID}, 1); + my $network = ($details->{ipv6}) ? &netv6Dec2net($child->{network}) : &dec2net($child->{network}); + + unless (&checkNetACL($child->{ID}, 'r')) { + $exportData->{$child->{network}} = {'01_network' => $network, '02_description' => _gettext("[ permission denied ]")}; + next; + } + + my $childData = { + '01_network' => $network, + '02_description' => $details->{description}, + '03_state' => &networkStateID2Name($details->{state}), + '04_createFrom' => $details->{createFrom}, + '05_createDate' => $details->{createDate}, + '06_modifyFrom' => $details->{modifyFrom}, + '07_modifyDate' => $details->{modifyDate}, + '08_defSubnetSize' => $details->{defSubnetSize}, + '09_tags' => join(' ', @{$details->{tags}}), + }; + map {$columns->{$_} = 1} keys %{$childData}; + + if ($details->{tmplID}) { + my $tmplName = &tmplID2Name($details->{tmplID}); + foreach (keys %{$tmplData}) { + my $key = $_; + my $value = $tmplData->{$key}; + my $colName = $tmplName . '_' . $key; + $value =~ s/[\n\r]+//g; + + $childData->{$colName} = $value; + $columns->{$colName} = 1; + } + } + $exportData->{$child->{network}} = $childData; + } + + print $HaCi::HaCi::q->header( + -type => 'text/csv', + -'Content-Disposition' => 'attachment; filename=HaCi_' . $name . '_export.csv' + ); + + my $csv = Text::CSV->new ( { binary => 1 } ) or die "Cannot use CSV: ".Text::CSV->error_diag (); + $csv->combine(map {s/^0\d_//; $_} sort keys %{$columns}); + print $csv->string() . "\n"; + + foreach (sort {$a<=>$b} keys %{$exportData}) { + my $network = $_; + $csv->combine(map {$exportData->{$network}->{$_}} sort keys %{$columns}); + print $csv->string() . "\n"; + } + exit 0; +} + +sub getAvailTags { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $networkTagTable = $conf->{var}->{TABLES}->{networkTag}; + unless (defined $networkTagTable) { + warn "Cannot get network tags. DB Error (networkTag)"; + return []; + } + + my @tagsDB = $networkTagTable->search(['tag']); + my $tags = {}; + foreach (@tagsDB) { + $tags->{$_->{tag}} = $_->{ID} unless exists $tags->{$_->{tag}}; + } + my @return = keys %{$tags}; + return \@return; +} + +sub getTags { + warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs}; + + my $netID = shift; + + my $networkTagTable = $conf->{var}->{TABLES}->{networkTag}; + unless (defined $networkTagTable) { + warn "Cannot get network tags. DB Error (networkTag)"; + return []; + } + + my @tagsDB = $networkTagTable->search(['tag'], {netID => $netID}); + my $tags = {}; + foreach (@tagsDB) { + $tags->{$_->{tag}} = $_->{ID} unless exists $tags->{$_->{tag}}; + } + my @return = keys %{$tags}; + return \@return; } 1; diff -Nru haci-0.97c/modules/HaCi/XMLRPC.pm haci-0.98c/modules/HaCi/XMLRPC.pm --- haci-0.97c/modules/HaCi/XMLRPC.pm 1970-01-01 00:00:00.000000000 +0000 +++ haci-0.98c/modules/HaCi/XMLRPC.pm 2015-02-16 00:46:27.000000000 +0000 @@ -0,0 +1,1099 @@ +package HaCi::XMLRPC; + +use strict; +use warnings; + +use Frontier::RPC2; +use Data::Dumper; +use Encode; +use File::Basename; +use Digest::MD5 qw/md5_hex/; +use Time::HiRes qw/usleep/; + +use HaCi::Conf; +use HaCi::HaCi; +use HaCi::Utils; +use HaCi::Mathematics; +use HaCi::Log qw/warnl debug/; + +=head1 Class XMLRPC + +This class provides a XML-RPC API for HaCi. + +Basic usage: + + my $api = new Frontier::Client(url => "http://$server/RPC2"); + my $session = $api->call('login', [$user, $pass]); + die 'Login failed!' unless $session; + + print Dumper($api->call($method, $session, @args)); + + $api->call('logout', $session); + + exit 0; + +=cut + +my $aclCacheHandle = undef; +my $netCacheHandle = undef; +my $lockName = undef; + +$SIG{__DIE__} = sub {&releaseLock($lockName) if defined $lockName}; + +my $methods = { + search => \&search, + getFreeSubnets => \&getFreeSubnets, + getFreeSubnetsFromSearch => \&getFreeSubnetsFromSearch, + assignFreeSubnet => \&assignFreeSubnet, + getSubnets => \&getSubnets, + getNetworkDetails => \&getNetworkDetails, + listRoots => \&listRoots, + addRoot => \&addRoot, + editRoot => \&editRoot, + delRoot => \&delRoot, + addNet => \&addNet, + editNet => \&editNet, + delNet => \&delNet, + login => \&login, + logout => \&logout, +}; + +sub handler { + my $r = shift; + my $coder = Frontier::RPC2->new(); + (my $workDir = dirname( __FILE__ )) =~ s#/modules/HaCi##; + &HaCi::Conf::init($workDir); + + my $content = ''; + $r->read($content, $r->headers_in->get('Content-Length')); + + my $response = ''; + eval { + $response = &serve($coder, $content); + }; + if ($@) { + $r->content_type("text/xml"); + $r->print(encode("UTF-8", $coder->encode_fault(1, 'Error: ' . $@))); + return Apache2::Const::SERVER_ERROR; + } else { + #$r->content_type("application/json"); + $r->content_type("text/xml"); + $r->print(encode("UTF-8", $response)); + return Apache2::Const::OK; + } +} + +sub finalize { + if (defined $netCacheHandle) { + warn "Cannot set Cache (netCache-DB!)\n" unless $netCacheHandle->set('DB', $HaCi::HaCi::netCache->{DB}); + warn "Cannot set Cache (netCache-FILL!)\n" unless $netCacheHandle->set('FILL', $HaCi::HaCi::netCache->{FILL}); + warn "Cannot set Cache (netCache-NET!)\n" unless $netCacheHandle->set('NET', $HaCi::HaCi::netCache->{NET}); + } + + if (defined $aclCacheHandle) { + warn "Cannot set Cache (aclCache!)\n" unless $aclCacheHandle->set('HASH', $HaCi::HaCi::aclCache); + } + $HaCi::HaCi::session->flush(); +} + +sub init { + &HaCi::Utils::getConfig(); + + ($aclCacheHandle, $netCacheHandle) = &HaCi::Utils::initCache(); + if (defined $netCacheHandle) { + $HaCi::HaCi::netCache->{DB} = $netCacheHandle->get('DB'); + $HaCi::HaCi::netCache->{NET} = $netCacheHandle->get('NET'); + $HaCi::HaCi::netCache->{FILL} = $netCacheHandle->get('FILL'); + } else { + $HaCi::HaCi::netCache->{DB} = {}; + $HaCi::HaCi::netCache->{NET} = {}; + $HaCi::HaCi::netCache->{FILL} = {}; + } + $HaCi::HaCi::aclCache = (defined $aclCacheHandle) ? $aclCacheHandle->get('HASH') : {}; + + &HaCi::Utils::initTables(); +} + +sub serve { + my $coder = shift; + my $xml = shift; + $xml =~ s/(<\?XML\s+VERSION)/\L$1\E/; + + my $call; + eval { + $call = $coder->decode($xml) + }; + if ($@) { + return $coder->encode_fault(1, "error decoding RPC.\n" . $@); + } + + if ($call->{'type'} ne 'call') { + return $coder->encode_fault(2,"expected RPC \`methodCall', got \`$call->{'type'}'\n"); + } + + my $method = $call->{'method_name'}; + if (!defined $methods->{$method}) { + return $coder->encode_fault(3, "no such method \`$method'\n"); + } + + &init(); + return $coder->encode_fault(7, "error executing RPC \`$method'.\n" . join("\n", @{$HaCi::Conf::conf->{var}->{warnl}})) + if $#{$HaCi::Conf::conf->{var}->{warnl}} > -1; + + my @values = @{$call->{'value'}}; + my $authInfo = shift @values; + return $coder->encode_fault(7, "Authentication error: " . $HaCi::Conf::conf->{var}->{authenticationError}) unless &authenticate($authInfo); + + my $result; + eval { + $result = &{$methods->{$method}}(@values); + }; + if ($@) { + return $coder->encode_fault(4, "error executing RPC \`$method'.\n" . $@); + } + + my $response_xml = $coder->encode_response($result); + + &finalize(); + + return $response_xml; +} + +sub authenticate { + my $authInfo = shift; + + my $user = undef; + my $pass = undef; + my $sessionUser = undef; + my $bLogin = 0; + if (ref($authInfo) eq 'ARRAY') { + &debug("Authentiating via username and password"); + $user = ${$authInfo}[0]; + $pass = ${$authInfo}[1]; + $HaCi::HaCi::session = &HaCi::HaCi::getSession(); + $bLogin = 1; + } + elsif (ref($authInfo) eq '') { + &debug("Authentiating via sessionID: " . $authInfo); + $HaCi::HaCi::session = &HaCi::HaCi::getSession($authInfo); + $sessionUser = $HaCi::HaCi::session->param('username'); + } + my $auth = &HaCi::HaCi::authentication($user, $pass, $bLogin, $sessionUser); + if ($auth) { + &HaCi::Utils::getRights(); + } + + return $auth; +} + +=over + +=item login() + +Login and return your session + + Params + + Returns + - session [string] session token you can use for authentication + +=cut + +sub login { + &debug("Login: return session id"); + return $HaCi::HaCi::session->id(); +} + +=item logout() + +Logout + + Params + + Returns + +=cut + +sub logout { + &debug("Logout: delete session"); + $HaCi::HaCi::session->delete(); + $HaCi::HaCi::session->flush(); + + return 1; +} + +=item search() + +Search networks + + Params + - search [string] string to search for + - state [string] filter the result by that network state (ALLOCATED PA, ASSIGNED, ...) + - exact [string] don't do a substring search + - template name [string] filter the result by that template name + - template query [hash] filter the result by defining special values for template entries (i.e.: {name => 'POOL1'}) + - root name [string] limit the search in that root + - nrOfFreeSubs [boolean] compute the number of free subnets in each found network + - withDetails [boolean] show details for found networks + - tags [string] return only networks with this tags, seperate with spaces (i.e.: 'OR foo bar', 'AND foo bar') + Returns + - networks [array] array of found network blocks (hash) + - netID + - network + - rootName + - description + - state + - nrOfFreeSubs + Example + my $networks = search('Test', 'ASSIGNED', 0, 'DSL-POOL', {name => 'Pool1'}, 'DSL-Test-Pool-Root', 0); + +=cut + +sub search { + my $searchStr = shift || ''; + my $state = shift || ''; + my $exact = shift || 0; + my $tmplName = shift || ''; + my $tmplQuery = shift || {}; + my $rootName = shift || ''; + my $shNrOfFree = shift || 0; + my $withDetails = shift || 0; + my $tagsT = shift || ''; + $tagsT =~ s/^\s+//; + $tagsT =~ s/\s+$//; + my @tags = split(/\s+/, $tagsT); + my $tagOp = ($tagsT ne '') ? shift @tags : 0; + if ($tagsT ne '' && scalar @tags == 0) { + @tags = ($tagOp); + $tagOp = 'OR'; + } + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('search'); + + my $tmplID = ($tmplName ne '') ? &HaCi::Utils::tmplName2ID($tmplName) : -1; + unless (defined $tmplID) { + &daw("No such Template found! ($tmplName)\n"); + } + + my $rootID = ($rootName ne '') ? &HaCi::Utils::rootName2ID($rootName) : -1; + unless ($rootID) { + &daw("No such root found! ($rootName)\n"); + } + $rootID = 0 if $rootID == -1; + + my $tmplBox = {}; + if ($tmplID != -1) { + foreach (keys %{$tmplQuery}) { + my $key = $_; + my $value = $tmplQuery->{$key}; + my $tmplEntryID = &HaCi::Utils::tmplEntryDescr2EntryID($tmplID, $key); + next unless defined $tmplEntryID; + + $tmplBox->{$tmplEntryID} = $value; + } + } + + my $stateID = -1; + if ($state ne '') { + $stateID = &HaCi::Utils::networkStateName2ID($state); + &daw("State not known! ($state)\nAvailable states: " . join(', ', map {$_->{name}} @{$HaCi::Conf::conf->{static}->{misc}->{networkstates}}) . "\n") unless $stateID; + } + + my $networks = &HaCi::Utils::search( + $searchStr, + ($exact) ? 0 : 1, + 0, + $shNrOfFree, + $rootID, + $stateID, + $tmplID, + $tmplBox, + \@tags, + $tagOp, + ); + + map { + delete $_->{url}; + delete $_->{nrOfFreeSubs} unless $shNrOfFree; + if ($withDetails) { + my $orig = $_; + $_ = &getNetworkDetails($_->{rootName}, $_->{network}); + $_->{netID} = $_->{ID}; + $_->{tmplName} = &HaCi::Utils::tmplID2Name($_->{tmplID}); + $_->{rootName} = $rootName; + $_->{nrOfFreeSubs} = $orig->{nrOfFreeSubs} if $shNrOfFree; + delete $_->{ipv6ID}; + delete $_->{ID}; + delete $_->{tmplID}; + delete $_->{rootID}; + } + } @{$networks}; + + return $networks; +} + +=item getFreeSubnets() + +Find free subnets in a specified root and supernet and return the wanted amount of subnets + + Params + - root name [string] search free subnets in that root + - supernet [network] search free subnets in that supernet (e.g. 192.168.0.0/24, 2001::/120) + - cidr [integer] specify the target cidr of your subnets (e.g. 30) + - amount [integer] how many subnets you want to get + Returns + - networks [array] array of free subnets found (hash) + - network + Example + my $freeSubnets = getFreeSubnets('Test root', '10.184.120.0/23', 32, 1); + +=cut + +sub getFreeSubnets { + my $rootName = shift; + my $network = shift; + my $size = shift || 0; + my $amount = shift || 0; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('search'); + &daw("You have to provide a root name!\n") unless $rootName; + my $rootID = &HaCi::Utils::rootName2ID($rootName); + unless ($rootID) { + &daw("No such Root found! ($rootName)\n"); + return; + } + + &daw("You have to provide a network from which you want to get a free subnet!\n") unless $network; + + my $ipv6 = ($network =~ /:/) ? 1 : 0; + my $networkDec = ($ipv6) ? &HaCi::Mathematics::netv62Dec($network) : &HaCi::Mathematics::net2dec($network); + my $ipv6ID = ($ipv6) ? &HaCi::Utils::netv6Dec2ipv6ID($networkDec) : ''; + my $netID = &HaCi::Utils::getNetID($rootID, $networkDec, $ipv6ID); + + unless ($netID) { + &daw("No such network found! ($network)\n"); + return; + } + unless (&HaCi::Utils::checkNetACL($netID, 'r')) { + &daw("Not enouph permissions to read this Network\n"); + return; + } + + my @freeSubnets = &HaCi::Utils::getFreeSubnets($netID, 0, $size, $amount || 1); + return \@freeSubnets; +} + +=item getFreeSubnetsFromSearch() + +Search networks and return free subnets from them + + Params + - search [string] string to search for + - state [string] filter the result by that network state (ALLOCATED PA, ASSIGNED, ...) + - exact [string] don't do a substring search + - template name [string] filter the result by that template name + - template query [hash] filter the result by defining special values for template entries (i.e.: {name => 'POOL1'}) + - root name [string] limit the search in that root + - cidr [integer] specify the target cidr of your subnets (e.g. 30) + - amount [integer] how many subnets you want to get + Returns + - networks [array] array of free subnets found (hash) + - network + - root name + Example + my $freeSubnets = getFreeSubnetsFromSearch('search me', '', 1, '', {}, 'Test-Root', 29, 3); + +=cut + +sub getFreeSubnetsFromSearch { + my $searchStr = shift || ''; + my $state = shift || ''; + my $exact = shift || 0; + my $tmplName = shift || ''; + my $tmplQuery = shift || {}; + my $rootName = shift || ''; + my $size = shift || 0; + my $amount = shift || 0; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('search'); + &daw("You have to provide a search string!\n") unless $searchStr; + + my $tmplID = ($tmplName ne '') ? &HaCi::Utils::tmplName2ID($tmplName) : -1; + unless (defined $tmplID) { + &daw("No such Template found! ($tmplName)\n"); + } + + my $rootID = ($rootName ne '') ? &HaCi::Utils::rootName2ID($rootName) : -1; + unless ($rootID) { + &daw("No such root found! ($rootName)\n"); + } + $rootID = 0 if $rootID == -1; + + my $tmplBox = {}; + if ($tmplID > -1) { + foreach (keys %{$tmplQuery}) { + my $key = $_; + my $value = $tmplQuery->{$key}; + my $tmplEntryID = &HaCi::Utils::tmplEntryDescr2EntryID($tmplID, $key); + next unless defined $tmplEntryID; + + $tmplBox->{$tmplEntryID} = $value; + } + } + + my $stateID = -1; + if ($state ne '') { + $stateID = &HaCi::Utils::networkStateName2ID($state); + &daw("State not known! ($state)\nAvailable states: " . join(', ', map {$_->{name}} @{$HaCi::Conf::conf->{static}->{misc}->{networkstates}}) . "\n") unless $stateID; + } + + my $networks = &HaCi::Utils::searchAndGetFreeSubnets( + $searchStr, + ($exact) ? 0 : 1, + 0, + 0, + $rootID, + $stateID, + $tmplID, + $tmplBox, + $size, + $amount + ); + + map { + delete $_->{url}; + delete $_->{dec}; + delete $_->{rootID}; + } @{$networks}; + + return $networks; +} + +=item listRoots() + +Add a root to HaCi + + Params + Returns + - roots [array] array of found roots (hash) + - ID + - name + - ipv6 (boolean) + +=cut + +sub listRoots { + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('showRoots'); + + my $roots = HaCi::Utils::getRoots(); + + return $roots +} + +=item addRoot() + +Add a root to HaCi + + Params + - root name [string] add a root with this name + - description [string] description of the root + - ipv6 [boolean] this root contains IPv6 networks + Returns + - success [string] 0 on success, error-String at error + +=cut + +sub addRoot { + my $rootName = shift || ''; + my $descr = shift || ''; + my $ipv6 = shift || 0; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('addRoot'); + + my $success = &HaCi::Utils::addRoot( + $rootName, + $descr, + $ipv6, + ); + + my $error = ($success) ? '' : "error adding a new root '$rootName': " . join("\n", @{$HaCi::Conf::conf->{var}->{warnl}}) . "\n"; + &warnl($error) if $error; + + return ($success) ? 0 : $error; +} + +=item editRoot() + +Edit an existing root + + Params + - root name [string] edit this root + - new root name [string] change root name + - description [string] new description of the root + Returns + - success [string] 0 on success, error-String at error + +=cut + +sub editRoot { + my $rootName = shift || ''; + my $newRootName = shift || ''; + my $description = shift || ''; + $newRootName = $rootName if $newRootName eq ''; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('editRoot'); + &daw("No root name committed!\n") unless $rootName; + + my $rootID = &HaCi::Utils::rootName2ID($rootName); + unless ($rootID) { + &daw("No such root found! ($rootName)\n"); + } + + my $root = &HaCi::Utils::getMaintInfosFromRoot($rootID); + $description = $root->{description} if $description eq ''; + + my $success = &HaCi::Utils::addRoot( + $newRootName, + $description, + $root->{ipv6}, + $rootID, + 1, + ); + + my $error = ($success) ? '' : "error while modifying this root '$rootName': " . join("\n", @{$HaCi::Conf::conf->{var}->{warnl}}) . "\n"; + &warnl($error) if $error; + + return ($success) ? 0 : $error; +} + +=item delRoot() + +Delete a root from HaCi + + Params + - root name [string] remove the root + Returns + - success [string] 0 on success, error-String at error + +=cut + +sub delRoot { + my $rootName = shift || ''; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('editRoot'); + &daw("No root name committed!\n") unless $rootName; + + my $rootID = &HaCi::Utils::rootName2ID($rootName); + unless ($rootID) { + &daw("No such root found! ($rootName)\n"); + } + + my $success = &HaCi::Utils::delRoot($rootID); + my $error = ($success) ? '' : "error removing this root '$rootName': " . join("\n", @{$HaCi::Conf::conf->{var}->{warnl}}) . "\n"; + &warnl($error) if $error; + + return ($success) ? 0 : $error; +} + +=item addNet() + +Add a network to HaCi + + Params + - root name [string] add the network to this root + - network [network] add this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + - description [string] description of the network + - state [string] state of the network (e.g. ALLOCATED PA, ASSIGNED, ...) + - def subnet Size [integer] define a default subnet cidr size (e.g. 30) + - template name [string] assign a template to the network + - template values [hash] pass template values (e.g. {hostname => 'abc.de', os => 'redhat'}) + - tags [string] add tags (seperate by comma) + Returns + - success [string] 0 on success, error-String at error + +=cut + +sub addNet { + my $rootName = shift || ''; + my $network = shift || ''; + my $descr = shift || ''; + my $state = shift || ''; + my $defSubSize = shift || 0; + my $tmplName = shift || ''; + my $tmplValues = shift || {}; + my $tags = shift || ''; + my $isIPv4 = qr/(\d{1,3}\.){3}\d{1,3}/i; + my $isIPv6 = qr/(((?=(?>.*?::)(?!.*::)))(::)?([0-9A-F]{1,4}::?){0,5}|([0-9A-F]{1,4}:){6})(\2([0-9A-F]{1,4}(::?|$)){0,2}|((25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])(\.|$)){4}|[0-9A-F]{1,4}:[0-9A-F]{1,4})(?{name}} @{$HaCi::Conf::conf->{static}->{misc}->{networkstates}}) . "\n") unless $stateID; + } + + my $tmplID = ($tmplName ne '') ? &HaCi::Utils::tmplName2ID($tmplName) : -1; + unless (defined $tmplID) { + &daw("No such Template found! ($tmplName)\n"); + } + my $rootID = ($rootName ne '') ? &HaCi::Utils::rootName2ID($rootName) : -1; + unless ($rootID) { + &daw("No such root found! ($rootName)\n"); + } + $rootID = 0 if $rootID == -1; + + my $tmplValueBox = {}; + if ($tmplID != -1) { + my $tmplEntries = &HaCi::Utils::getTemplateEntries($tmplID, 0, 0, 1, 0, 1); + foreach (keys %{$tmplEntries}) { + my $id = $_; + my $name = $tmplEntries->{$id}; + foreach (keys %{$tmplValues}) { + if ($name eq $_) { + $tmplValueBox->{$id} = $tmplValues->{$_}; + } + } + } + } + + my $success = &HaCi::Utils::addNet( + 0, + $rootID, + $ip, + $cidr, + $descr, + $stateID, + $tmplID, + $defSubSize, + 1, + $tmplValueBox, + 0, + $tags, + ); + + my $error = ($success) ? '' : "error adding this new network '$ip/$cidr': " . join("\n", @{$HaCi::Conf::conf->{var}->{warnl}}) . "\n"; + &warnl($error) if $error; + + return ($success) ? 0 : $error; +} + +=item editNet() + +Edit an existing network + + Params + - root name [string] edit the network in this root + - network [network] edit this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + - changes [hash] changes (valid attributes are: network description state rootName defSubnetSize tmplName tmplValues) + e.g.: + {description => 'test_8'} + {network => '192.168.0.8/29', defSubnetSize=>30, state=>'FREE', rootName=>'larsux.de'} + Returns + - success [string] 0 on success, error-String at error + +=cut + +sub editNet { + my $rootName = shift || ''; + my $network = shift || ''; + my $changeData = shift || {}; + my @keys = qw(network description state rootName defSubnetSize tmplName tmplValues tags); + + my $isIPv4 = qr/(\d{1,3}\.){3}\d{1,3}/i; + my $isIPv6 = qr/(((?=(?>.*?::)(?!.*::)))(::)?([0-9A-F]{1,4}::?){0,5}|([0-9A-F]{1,4}:){6})(\2([0-9A-F]{1,4}(::?|$)){0,2}|((25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])(\.|$)){4}|[0-9A-F]{1,4}:[0-9A-F]{1,4})(?{rootName}) { + $newRootID = &HaCi::Utils::rootName2ID($changeData->{rootName}); + unless ($newRootID) { + &daw("No such root found! ($changeData->{rootName})\n"); + } + } + + my $newNetwork = (exists $changeData->{network}) ? $changeData->{network} : $network; + my ($ip, $cidr) = split(/\//, $network); + my ($newIP, $newCIDR) = split(/\//, $newNetwork); + &daw("This '$ip' is not a valid ip address (i.e.: 1.2.3.4/30, 2001:dead:beaf::/66)\n") if $ip !~ /$isIPv4/ && $ip !~ /$isIPv6/; + &daw("This '$newIP' is not a valid ip address (i.e.: 1.2.3.4/30, 2001:dead:beaf::/66)\n") if $newIP !~ /$isIPv4/ && $newIP !~ /$isIPv6/; + + my $ipv6 = ($network =~ /:/) ? 1 : 0; + my $networkDec = ($ipv6) ? &HaCi::Mathematics::netv62Dec($network) : &HaCi::Mathematics::net2dec($network); + my $ipv6ID = ($ipv6) ? &HaCi::Utils::netv6Dec2ipv6ID($networkDec) : ''; + my $netID = &HaCi::Utils::getNetID($rootID, $networkDec, $ipv6ID); + unless ($netID) { + &daw("No such network found! ($network)\n"); + return; + } + my $netDetails = &HaCi::Utils::getMaintInfosFromNet($netID); + my $descr = (exists $changeData->{description}) ? $changeData->{description} : $netDetails->{description}; + my $defSubSize = (exists $changeData->{defSubnetSize}) ? $changeData->{defSubnetSize} : $netDetails->{defSubnetSize}; + my $tags = (exists $changeData->{tags}) ? $changeData->{tags} : join(',', @{$netDetails->{tags}}); + + my $stateID = $netDetails->{state}; + if (exists $changeData->{state}) { + $stateID = &HaCi::Utils::networkStateName2ID($changeData->{state}); + &daw("State not known! ($changeData->{state})\nAvailable states: " . join(', ', map {$_->{name}} @{$HaCi::Conf::conf->{static}->{misc}->{networkstates}}) . "\n") unless $stateID; + } + + my $tmplID = (exists $changeData->{tmplName}) ? $changeData->{tmplName} : $netDetails->{tmplID}; + if (exists $changeData->{tmplName}) { + $tmplID = &HaCi::Utils::tmplName2ID($changeData->{tmplName}); + unless (defined $tmplID) { + &daw("No such Template found! ($changeData->{tmplName})\n"); + } + } + + my $tmplValueBox = 0; + if (exists $changeData->{tmplValues}) { + $tmplValueBox = {}; + die "Template values must be a hash\n" unless ref($changeData->{tmplValues}) eq 'HASH'; + my $tmplEntries = &HaCi::Utils::getTemplateEntries($tmplID, 0, 0, 1, 0, 1); + foreach (keys %{$tmplEntries}) { + my $id = $_; + my $name = $tmplEntries->{$id}; + foreach (keys %{$changeData->{tmplValues}}) { + if ($name eq $_) { + $tmplValueBox->{$id} = $changeData->{tmplValues}->{$_}; + } + } + } + } + + my $success = &HaCi::Utils::addNet( + $netID, + $newRootID, + $newIP, + $newCIDR, + $descr, + $stateID, + $tmplID, + $defSubSize, + 1, + $tmplValueBox, + 1, + $tags, + ); + + my $error = ($success) ? '' : "error while modifying this network '$ip/$cidr': " . join("\n", @{$HaCi::Conf::conf->{var}->{warnl}}) . "\n"; + &warnl($error) if $error; + + return ($success) ? 0 : $error; +} + +=item delNet() + +Delete a network from HaCi + + Params + - root name [string] remove the netork from this root + - network [network] remove this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + - network lock [integer] lock network for X seconds + - withSubnets [boolean] also remve subnets + Returns + - success [string] 0 on success, error-String at error + +=cut + +sub delNet { + my $rootName = shift || ''; + my $network = shift || 0; + my $networkLock = shift || $HaCi::Conf::conf->{user}->{misc}->{dftnetworklock} || 0; + my $bWithSubnets = shift || 0; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('editNet'); + + my $rootID = ($rootName ne '') ? &HaCi::Utils::rootName2ID($rootName) : -1; + unless ($rootID) { + &daw("No such root found! ($rootName)\n"); + } + $rootID = 0 if $rootID == -1; + + my $ipv6 = ($network =~ /:/) ? 1 : 0; + my $networkDec = ($ipv6) ? &HaCi::Mathematics::netv62Dec($network) : &HaCi::Mathematics::net2dec($network); + my $ipv6ID = ($ipv6) ? &HaCi::Utils::netv6Dec2ipv6ID($networkDec) : ''; + my $netID = &HaCi::Utils::getNetID($rootID, $networkDec, $ipv6ID); + + unless ($netID) { + &daw("No such network found! ($network)\n"); + return; + } + + my $success = &HaCi::Utils::delNet($netID, $bWithSubnets, 0, $networkLock); + my $error = ($success) ? '' : "error removing this new network '$network': " . join("\n", @{$HaCi::Conf::conf->{var}->{warnl}}) . "\n"; + &warnl($error) if $error; + + return ($success) ? 0 : $error; +} + +=item assignFreeSubnet() + +Find the next free subnet and assign it in one step + + Params + - root name [string] search free subnets in that root + - supernet [network] search free subnets in that supernet (e.g. 192.168.0.0/24, 2001::/120) + - cidr [integer] specify the target cidr of your subnets (e.g. 30) + - description [string] description of the network + - state [string] state of the network (e.g. ALLOCATED PA, ASSIGNED, ...) + - def subnet Size [integer] define a default subnet cidr size (e.g. 30) + - template name [string] assign a template to the network + - template values [hash] pass template values (e.g. {hostname => 'abc.de', os => 'redhat'}) + Returns + - network details [hash] new network assigned: + - netID + - network + - modify date + - ipv6 (boolean) + - description + - state + - create from + - create date + - default subnet cidr size + - template name + - modify from + +=cut + +sub assignFreeSubnet { + my $rootName = shift; + my $network = shift; + my $size = shift || 0; + my $descr = shift || ''; + my $state = shift || ''; + my $defSubSize = shift || 0; + my $tmplName = shift || ''; + my $tmplValueBox = shift || {}; + my $secondTry = shift || 0; + my $amount = 1; + + &getLock($network); + + my $freeNetworks = &getFreeSubnets($rootName, $network, $size, $amount); + &daw("No free subnets found!\n") if scalar @{$freeNetworks} < 1; + my $freeNet = ${$freeNetworks}[0]; + + if (my $error = &addNet($rootName, $freeNet, $descr, $state, $defSubSize, $tmplName, $tmplValueBox)) { + if (($error =~ /allready exists/ || $error =~ /already exists/) && !$secondTry) { # retry one time + &warnl("Network already exists! Retry one more time..."); + &releaseLock($network); + usleep(rand(1000000)); + return &assignFreeSubnet($rootName, $network, $size, $descr, $state, $defSubSize, $tmplName, $tmplValueBox, 1); + } else { + &releaseLock($network); + &daw($error); + } + } else { + my $netDetails = &getNetworkDetails($rootName, $freeNet); + $netDetails->{netID} = $netDetails->{ID}; + $netDetails->{tmplName} = &HaCi::Utils::tmplID2Name($netDetails->{tmplID}); + $netDetails->{rootName} = $rootName; + delete $netDetails->{ipv6ID}; + delete $netDetails->{ID}; + delete $netDetails->{tmplID}; + delete $netDetails->{rootID}; + + &releaseLock($network); + return $netDetails; + } +} + +=item getNetworkDetails() + +Get details from a network in HaCi + + Params + - root name [string] get details of a network in this root + - network [network] get details of this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + Returns + - network [hash] network details: + - netID + - network + - modify date + - ipv6 (boolean) + - description + - state + - create from + - create date + - default subnet cidr size + - template name + - modify from + +=cut + +sub getNetworkDetails { + my $rootName = shift; + my $network = shift; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('showNetDet'); + + my $rootID = ($rootName ne '') ? &HaCi::Utils::rootName2ID($rootName) : -1; + unless ($rootID) { + &daw("No such root found! ($rootName)\n"); + } + $rootID = 0 if $rootID == -1; + + my $ipv6 = ($network =~ /:/) ? 1 : 0; + my $networkDec = ($ipv6) ? &HaCi::Mathematics::netv62Dec($network) : &HaCi::Mathematics::net2dec($network); + my $ipv6ID = ($ipv6) ? &HaCi::Utils::netv6Dec2ipv6ID($networkDec) : ''; + my $netID = &HaCi::Utils::getNetID($rootID, $networkDec, $ipv6ID); + + unless ($netID) { + &daw("No such network found! ($network)\n"); + return; + } + + my $netDetails = &HaCi::Utils::getMaintInfosFromNet($netID); + $netDetails->{network} = $network; + $netDetails->{state} = &HaCi::Utils::networkStateID2Name($netDetails->{state}); + + if ($netDetails->{tmplID}) { + $netDetails->{templateValues} = &HaCi::Utils::getTemplateData($netID, $netDetails->{tmplID}, 1); + $netDetails->{template} = &HaCi::Utils::tmplID2Name($netDetails->{tmplID}); + } + + return $netDetails; +} + +sub daw { + my $msg = shift; + + &warnl($msg); + die $msg; +} + +sub getLock { + my $name = shift; + my $fileName = md5_hex($name) . '.lock'; + my $lockFile = $HaCi::Conf::conf->{static}->{path}->{lockpath} . '/' . $fileName; + + my $waitCnter = 5; + while (-f $lockFile) { + warn "Lockfile '$lockFile' for '$name' found. Waiting...\n"; + usleep(rand(1000000)); + last unless $waitCnter--; + } + + if (-f $lockFile) { + my $lockProc = 'unkonwn'; + unless (open F, $lockFile) { + warn "Cannot open lockfile '$lockFile' for reading: $!\n"; + } else { + $lockProc = ; + close F; + } + warn "Locking prozess '$lockProc' seems to die. Overwriting lockfile '$lockFile'.\n"; + } + + open F, '>' . $lockFile or warn "Cannot open lockfile '$lockFile' for writing: $!\n"; + print F $$; + close F; + + $lockName = $name; +} + +sub releaseLock { + my $name = shift; + my $fileName = md5_hex($name) . '.lock'; + my $lockFile = $HaCi::Conf::conf->{static}->{path}->{lockpath} . '/' . $fileName; + + unlink $lockFile or warn "Cannot release lockfile '$lockFile': $!\n"; + + $lockName = undef; +} + +=item getSubnets() + +Get subnets from a root and optional from a supernet + + Params + - root name [string] get subnets from this root + - supernet [network] get subnets from this network (e.g. 192.168.0.1/32, 2001::dead:beef:0/125) + Returns + - networks [array] array of found networks (hash) + - netID + - network + - modify date + - ipv6 (boolean) + - description + - state + - create from + - create date + - default subnet cidr size + - template name + - modify from + Example + my $subnets = getSubnets('Test'); + my $subnets = getSubnets('Test', '192.168.0.0/24'); + +=cut +sub getSubnets { + my $rootName = shift; + my $network = shift || 0; + + &daw("Permission denied!\n") unless &HaCi::Utils::checkRight('showNets'); + &daw("You have to provide a root name!\n") unless $rootName; + my $rootID = &HaCi::Utils::rootName2ID($rootName); + unless ($rootID) { + &daw("No such Root found! ($rootName)\n"); + return; + } + my $ipv6 = &HaCi::Utils::rootID2ipv6($rootID); + + my @childs = (); + if ($network) { + my $networkDec = ($ipv6) ? &HaCi::Mathematics::netv62Dec($network) : &HaCi::Mathematics::net2dec($network); + my $ipv6ID = ($ipv6) ? &HaCi::Utils::netv6Dec2ipv6ID($networkDec) : ''; + my $netID = &HaCi::Utils::getNetID($rootID, $networkDec, $ipv6ID); + + @childs = &HaCi::Utils::getNetworkChilds($netID, 0, 0); + } else { + @childs = &HaCi::Utils::getNetworkChilds($rootID, 1, 0); + } + + my @childDetails = map { + my $networkDec = $_->{network}; + my $network = ($ipv6) ? &HaCi::Mathematics::netv6Dec2net($networkDec) : &HaCi::Mathematics::dec2net($networkDec); + my $netDetails = &getNetworkDetails($rootName, $network); + $netDetails->{netID} = $netDetails->{ID}; + $netDetails->{tmplName} = &HaCi::Utils::tmplID2Name($netDetails->{tmplID}); + $netDetails->{rootName} = $rootName; + delete $netDetails->{ipv6ID}; + delete $netDetails->{ID}; + delete $netDetails->{tmplID}; + delete $netDetails->{rootID}; + + $netDetails; + } @childs; + + return \@childDetails; +} + +=back + +=cut + +1; + +# vim:ts=2:sts=2:sw=2 diff -Nru haci-0.97c/README haci-0.98c/README --- haci-0.97c/README 2010-06-22 13:21:06.000000000 +0000 +++ haci-0.98c/README 2015-03-04 02:06:29.000000000 +0000 @@ -1,6 +1,6 @@ ############################################################################### ## HaCi - IP Address Administration # -## Copyright (C) 2006-2010 by Lars Wildemann # +## Copyright (C) 2006-2015 by Lars Wildemann # ## Author: Lars Wildemann # ## # ## HaCi is an IP Address / Network Administration Tool with IPv6 Support. # @@ -19,7 +19,7 @@ ############################################################################### OVERVIEW - HaCi is a web frontend for administrating networks. It consist of a (perl) CGI and a (mySQL) database as backend. + HaCi is a web frontend for administrating networks. It consist of a (perl) CGI and a (mySQL/postgreSQL) database as backend. REQUIRERMENTS All you need is a webserver (e.g.: Apache), a database (e.g.: mySQL) and an OS which supports perl. @@ -34,33 +34,41 @@ - Class::Accessor - Class::MakeMethods - Config::General - - DBD::mysql - Digest::MD5 - Digest::SHA - - DNS::ZoneParse (optional for importing Zonefiles) - Encode - Encode::Guess - File::Temp - HTML::Entities - - IO::Socket::INET6 (optional for IMAP authentication support) - Locale::gettext - Log::LogLite - - Math::BigInt::GMP (optional, but proposed for more performance!) - Math::BigInt v1.87 - Net::CIDR - - Net::DNS (optional for importing Zonefiles) - Net::IPv6Addr - - Net::Ping (optional for Ping-Plugin) - Net::SNMP - - Pod::WSDL (optional for SAOP support) - - SOAP::Transport::HTTP (optional for SAOP support) - - SQL::Translator::Diff (optional for automatic database upgrade support) - - SQL::Translator v0.09000 (optional for automatic database upgrade support) - Storable - Template - - Text::CSV_XS (optional for importing CSV-Files) - Time::Local + - DBD::mysql (for mysql support) + - DBD::Pg (for postgresql support) - Apache::DBI (optional for getting connection persistence when using mod-perl) + - DNS::ZoneParse (optional for importing Zonefiles) + - File::Basename (optional for XMP-RPC API support) + - Frontier::Client (optional for XMP-RPC API support) + - IO::Socket::INET6 (optional for IMAP authentication support) + - Math::BigInt::GMP (optional, but proposed for more performance!) + - Net::DNS (optional for importing Zonefiles) + - Net::LDAP (optional for LDAP authentication) + - Net::Ping (optional for Ping-Plugin) + - Pod::WSDL (optional for SAOP support) + - SOAP::Transport::HTTP (optional for SAOP support) + - SQL::Translator::Diff (optional for automatic database upgrade support) + - SQL::Translator v0.09000 (optional for automatic database upgrade support) + - Text::CSV (optional for ex/importing CSV-Files) + - Text::CSV_XS (optional for faster ex/importing CSV-Files) + - Time::HiRes (optional for XMP-RPC API support) + - JSON (optional for RESTWrapper API support) + - URI::Query (optional for RESTWrapper API support) - HTTP Server - SQL Database @@ -69,6 +77,11 @@ INSTALLATION 1) First, extract the archiv into a directory, from which the HTTP server will process it and check dependencies. + $ cd /var/www + $ wget 'http://downloads.sourceforge.net/project/haci/haci/0.98c/HaCi_0.98c.tar.gz' + $ tar xfzv HaCi_0.98c.tar.gz + $ HaCi/bin/checkPerlDependencies.bash + $ HaCi/bin/checkPerlOptionals.bash 2) If needed, accommodate the file/directory permissions, so the HTTP server will have no problems. @@ -90,8 +103,24 @@ CREATE DATABASE `HaCi`; GRANT ALL PRIVILEGES ON `HaCi`.* TO 'HaCi'@'localhost' WITH GRANT OPTION; ---------------------- 8< --------------------- + - HaCi will automatically initiate/update the database with the latest schema. If you don't want HaCi to do this by itself, you can import the latest schema dump: + $ mysql -u HaCi -p HaCi < docs/HaCi_v0.98c.mysql + - postgresql + - Execute as postgres super user: + $ createuser -PSDR HaCi + $ createdb -O HaCi HaCi + - Add this line to your 'pg_hba.conf' + host HaCi HaCi 127.0.0.1/32 md5 + - import the database schema dump with the latest version in order to initialize the database + $ psql HaCi < docs/HaCi_v0.98c.pgsql + - OR update to a new version (i.e.: from 0.98b to 0.98c): + $ psql HaCi < docs/HaCi_v0.98b-v0.98c.pgsql - - Apache (httpd.conf) + - postgresql v9.0+: Perhaps you need to set the following variable in your 'postgresql.conf', in order to make ipv6 work: + bytea_output = 'escape' + + + - Apache (httpd.conf) ---------------------- 8< --------------------- ServerName haci.domain.tld @@ -110,6 +139,28 @@ Order allow,deny allow from all + + # Exclude the soap api interface from the mod-perl handler + + SetHandler None + + + # Include XML-RPC API + PerlSwitches -I/var/www/HaCi/modules + + SetHandler perl-script + PerlHandler HaCi::XMLRPC + + # disable compressing, because of problems with chunked transfer encodings + SetEnv no-gzip + + + # Simple REST-Wrapper which itself uses the XMLRPC-API + + SetHandler perl-script + PerlHandler HaCi::RESTWrapper + + ---------------------- 8< --------------------- @@ -152,9 +203,27 @@ 6) - HaCiAPI + HaCiAPI (documentation can be found in /doc) + - SOAP (deprecated) HaCi supports a SOAP-Interface for accessing the data not only from the webfrontend but also from a perl/php/... script. You can find a short description and a demo perl script in the 'docs' directory. + - XMLRPC + There is also a XML-RPC API which can be easily integrated into several programming languages. Documentation can be found in the 'docs' directory. + The following methods can be used: + - search + - getFreeSubnets + - getFreeSubnetsFromSearch + - addNet + - editNet + - delNet + - assignFreeSubnet + - getNetworkDetails + - getSubnets + - REST + There is a very basic REST Wrapper which itself uses the XML-RPC-API. + The main reason for this is to support tools which can only communicate via REST (i.e.: Table-JSON-Plugin in Confluence). + The available methods are the same as in the XML-RPC-API. + Authentication is done via HTTP-Basic-Auth or via "username"- and "password"-Parameters. 7) @@ -175,6 +244,54 @@ This tool checks the database for stale and broken entries. Pass '-c' as parameter in order to cleanup found issues. Please make sure to backup your database before. + UPGRADE + + 1) + Make a database backup + + 2) + Stop the web server + + 3) + Rename the HaCi-Document-Root + i.e.: + $ mv /var/www/HaCi /var/www/HaCi_OLD + + 4) + Get the actual code, extract it and check for new dependencies + $ cd /var/www + $ wget 'http://downloads.sourceforge.net/project/haci/haci/0.98c/HaCi_0.98c.tar.gz' + $ tar xfzv HaCi_0.98c.tar.gz + $ cd HaCi + $ bin/checkPerlDependencies.bash + $ bin/checkPerlOptionals.bash + + 5) + If needed, accommodate the file/directory permissions, so the HTTP server will have no problems. + /logs : HTTPServer (rwx) + /spool : HTTPServer (rwx) + + 6) + Update your database + e.g.: + - MySQL + - HaCi will automatically update the database with the latest schema. If you don't want HaCi to do this by itself, you can do the changes manually + $ less docs/manualDatabaseUpgrades_mysql.txt + - postgresql + - update to a new version (i.e.: from 0.98b to 0.98c): + $ psql HaCi < docs/HaCi_v0.98b-v0.98c.pgsql + + 7) + Check for new entries in the webserver configuration (Apache example in INSTALLATION step 4) + + 8) + Check for new configuration items in HaCi.conf and synchronize it with your old config (if it doesn't resides in /etc). + + 9) + Start the webserver & FINISH + The first HaCi request will take some time, because of housekeeping stuff (see in webserver error logfile for more info) + + AUTHOR Lars Wildemann haci@larsux.de diff -Nru haci-0.97c/Template/HaCiBox.tmpl haci-0.98c/Template/HaCiBox.tmpl --- haci-0.97c/Template/HaCiBox.tmpl 2008-10-22 16:41:50.000000000 +0000 +++ haci-0.98c/Template/HaCiBox.tmpl 2015-02-08 03:11:28.000000000 +0000 @@ -25,8 +25,18 @@ [% trOpen = 1 %] [% END %] [% IF entry.value.type == 'hline' %] -
[% trOpen = 0 %] + [% IF entry.value.colspan %] + + [% ELSE %] + + [% END %] +
+
+ + + [% trOpen = 0 %] [% ELSE %] + [% FOREACH element IN entry.elements %] [% UNLESS trOpen %] - [% FOREACH option IN element.values %] [% END %] + [% FOREACH option IN element.values %] + + [% END %] [% ELSIF element.type == 'checkbox' %] [% trOpen = 0 %][% END %] [% END %] -[% FOREACH entry IN hiddens %] +[% FOREACH entry IN hiddens %] - +
+ + - - -
+ + + + +
+
+

[% templateHeader %]

+
+ [% INCLUDE HaCiBox.tmpl + menu = templateMenu + parentFormName = editTemplateFormName + %] +
+
+ +
-

[% templateHeader %]

+

[% editTemplateHeader %]

[% INCLUDE HaCiBox.tmpl - menu = templateMenu + menu = editTemplateMenu + hiddens = editTemplateHiddens parentFormName = editTemplateFormName %]
- -
+
-
-

[% editTemplateHeader %]

-
- [% INCLUDE HaCiBox.tmpl - menu = editTemplateMenu - hiddens = editTemplateHiddens - parentFormName = editTemplateFormName - %] +
+
+

[% editTemplateNameHeader %]

+
+ [% INCLUDE HaCiBox.tmpl + menu = editTemplateNameMenu + parentFormName = editTemplateNameFormName + %] +
- -
-
-

[% editTemplateEntryHeader %]

-
- [% INCLUDE HaCiBox.tmpl - menu = editTemplateEntryMenu - hiddens = editTemplateEntryHiddens - keyWidth = 19 - parentFormName = editTemplateFormName - %] +
+
+

[% editTemplateEntryHeader %]

+
+ [% INCLUDE HaCiBox.tmpl + menu = editTemplateEntryMenu + hiddens = editTemplateEntryHiddens + keyWidth = 19 + parentFormName = editTemplateFormName + %] +
- -
+
diff -Nru haci-0.97c/Template/HaCiEditUser.tmpl haci-0.98c/Template/HaCiEditUser.tmpl --- haci-0.97c/Template/HaCiEditUser.tmpl 2007-10-20 03:26:11.000000000 +0000 +++ haci-0.98c/Template/HaCiEditUser.tmpl 2015-02-13 23:32:18.000000000 +0000 @@ -48,6 +48,4 @@ -
[% gettext_userpassword %]
-
diff -Nru haci-0.97c/Template/HaCiMain.tmpl haci-0.98c/Template/HaCiMain.tmpl --- haci-0.97c/Template/HaCiMain.tmpl 2010-06-23 21:51:57.000000000 +0000 +++ haci-0.98c/Template/HaCiMain.tmpl 2012-09-26 15:54:48.000000000 +0000 @@ -31,6 +31,8 @@ [% INCLUDE HaCiDelRoot.tmpl %] [% ELSIF mainPage == 'search' %] [% INCLUDE HaCiSearch.tmpl %] + [% ELSIF mainPage == 'getFreeSubnetsFromSearch' %] + [% INCLUDE HaCiSearch.tmpl %] [% ELSIF mainPage == 'compare' %] [% INCLUDE HaCiCompare.tmpl %] [% ELSIF mainPage == 'showTemplates' %] @@ -63,6 +65,8 @@ [% INCLUDE HaCiShowSubnets.tmpl %] [% ELSIF mainPage == 'showSettings' %] [% INCLUDE HaCiShowSettings.tmpl %] + [% ELSIF mainPage == 'showAuditLogs' %] + [% INCLUDE HaCiShowAuditLogs.tmpl %] [% END %] diff -Nru haci-0.97c/Template/HaCiSearch.tmpl haci-0.98c/Template/HaCiSearch.tmpl --- haci-0.97c/Template/HaCiSearch.tmpl 2008-10-22 16:41:50.000000000 +0000 +++ haci-0.98c/Template/HaCiSearch.tmpl 2015-01-03 05:11:10.000000000 +0000 @@ -23,10 +23,16 @@ [% gettext_rootName %] [% gettext_network %] - [% gettext_description %] - [% gettext_state %] - [% FOREACH descrEntry IN tmplDescr %] - [% descrEntry.value %] + [% IF !bSearchForFree %] + [% gettext_description %] + [% IF bShowNrOfFreeSubs %] + [% gettext_nrOfFreeSubnets %] + [% END %] + [% gettext_state %] + [% gettext_tags %] + [% FOREACH descrEntry IN tmplDescr %] + [% descrEntry.value %] + [% END %] [% END %] [% IF noSearchResult %] @@ -38,12 +44,18 @@ [% entry.rootName %] [% entry.network %] - [% entry.description %] - [% entry.state %] - [% netID = entry.netID %] - [% FOREACH descrEntry IN tmplDescr %] - [% descrValue = descrEntry.value %] - [% tmplInfos.$netID.$descrValue %] + [% IF !bSearchForFree %] + [% entry.description %] + [% IF bShowNrOfFreeSubs %] + [% entry.nrOfFreeSubs %] + [% END %] + [% entry.state %] + [% entry.tags %] + [% netID = entry.netID %] + [% FOREACH descrEntry IN tmplDescr %] + [% descrValue = descrEntry.value %] + [% tmplInfos.$netID.$descrValue %] + [% END %] [% END %] [% END %] diff -Nru haci-0.97c/Template/HaCiShowAbout.tmpl haci-0.98c/Template/HaCiShowAbout.tmpl --- haci-0.97c/Template/HaCiShowAbout.tmpl 2010-01-10 01:55:06.000000000 +0000 +++ haci-0.98c/Template/HaCiShowAbout.tmpl 2015-02-15 16:47:26.000000000 +0000 @@ -9,7 +9,7 @@
 
   HaCi - IP Address Administration                             
-    Copyright (C) 2006-2010 by Lars Wildemann                               
+    Copyright (C) 2006-2015 by Lars Wildemann                               
     Author: Lars Wildemann <HaCi@larsux.de>                                 
                                                                             
   HaCi is an IP Address / Network Administration Tool with IPv6 Support.
diff -Nru haci-0.97c/Template/HaCiShowAuditLogs.tmpl haci-0.98c/Template/HaCiShowAuditLogs.tmpl
--- haci-0.97c/Template/HaCiShowAuditLogs.tmpl	1970-01-01 00:00:00.000000000 +0000
+++ haci-0.98c/Template/HaCiShowAuditLogs.tmpl	2012-07-15 00:56:50.000000000 +0000
@@ -0,0 +1,59 @@
+
+ +
+ + +
+
+

[% showAuditLogsHeader %]

+
+ [% INCLUDE HaCiBox.tmpl + menu = showAuditLogsMenu + hiddens = showAuditLogsHiddens + parentFormName = showAuditLogsFormName + %] +
+
+
+ +

+ +
+
+

[% showAuditLogs %]

+
+ [% cnter = 0 %] + + + + + + + + + + [% IF noAuditLogs %] + + [% ELSE %] + [% FOREACH entry IN auditLogs %] + [% cnter = cnter + 1 %] [% IF cnter mod 2 %] [% bgColor = '#AAFFAA' %] [% ELSE %] [% bgColor = '#DDFFDD' %] [% END %] + + + + + + + + + [% END %] + [% END %] +
[% gettext_timestamp %][% gettext_username %][% gettext_action %][% gettext_object %][% gettext_value %][% gettext_error %]
[% gettext_noContent %]
[% entry.ts %][% entry.username %][% entry.action %][% entry.object %][% entry.value %][% entry.error %]
+
+
+
+ + + + diff -Nru haci-0.97c/Template/HaCiShowSubnets.tmpl haci-0.98c/Template/HaCiShowSubnets.tmpl --- haci-0.97c/Template/HaCiShowSubnets.tmpl 2008-06-27 16:50:16.000000000 +0000 +++ haci-0.98c/Template/HaCiShowSubnets.tmpl 2012-01-13 00:26:59.000000000 +0000 @@ -21,7 +21,13 @@
[% cnter = 0 %] - + + + + [% IF bAddNet %] + + [% END %] + [% IF noResults %] [% ELSE %] @@ -31,14 +37,16 @@ - + [% IF bAddNet %] + + [% END %] [% END %] [% END %] diff -Nru haci-0.97c/Template/HaCiTreeNetwork.tmpl haci-0.98c/Template/HaCiTreeNetwork.tmpl --- haci-0.97c/Template/HaCiTreeNetwork.tmpl 2008-06-25 16:29:16.000000000 +0000 +++ haci-0.98c/Template/HaCiTreeNetwork.tmpl 2013-03-04 20:30:07.000000000 +0000 @@ -68,16 +68,20 @@

[% IF directaccess %] [% UNLESS network.fillNet OR network.invisible %] - [% network.editAlt %] + [% IF network.bEditNet %] + [% network.editAlt %] + [% END %] + [% IF network.bDelNet %] [% network.delAlt %] + [% END %] [% END %] [% END %]
[% IF network.parent %][% UNLESS network.expanded %][% END %][% END %] [% IF network.parentBroadcast %] - [% i = [ 1 .. network.parentBroadcast ] %] - [% FOREACH i %] + [% iE = [ 1 .. network.parentBroadcast ] %] + [% FOREACH i IN iE %] [% END %] [% END %]
[% gettext_nr %][% gettext_subnet %][% gettext_create %]
[% gettext_nr %][% gettext_subnet %][% gettext_create %]
[% gettext_nothing_found %]
[% cnter %] [% subnet.net %] - - - - + + + +