1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?xml version='1.0'?>
<config>
<system>
<daemon>1</daemon>
<webserver>1</webserver>
<admin>m1ndfuck</admin>
<adminpass>test</adminpass>
</system>
<network>
<device1>wlan0</device1>
<device1mac></device1mac>
<device2>eth1</device2>
<device2mac></device2mac>
</network>
<scan>
<channel>6</channel>
</scan>
<attack>
<spoof>1</spoof>
<spoofmac></spoofmac>
</attack>
<logging>
<uselog>1</uselog>
<loglocation>aircracker.log</loglocation>
</logging>
</config>
1 2 3 4 5 6 7 8 9 10 11 12
use XML::Simple; use Data::Dumper; my $cfg = XMLin('aircracker.conf'); sub getcfg { my $value = shift; if ($value eq 'daemon') { return $cfg->{config}{system}{daemon}; } } print Dumper($cfg); print getcfg('daemon');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$VAR1 = {
'logging' => {
'uselog' => '1',
'loglocation' => 'aircracker.log'
},
'network' => {
'device2mac' => {},
'device1' => 'wlan0',
'device1mac' => {},
'device2' => 'eth1'
},
'scan' => {
'channel' => '6'
},
'system' => {
'admin' => 'm1ndfuck',
'adminpass' => 'test',
'daemon' => '1',
'webserver' => '1'
},
'attack' => {
'spoofmac' => {},
'spoof' => '1'
}
};
Use of uninitialized value in print at ./aircracker.pl line 15.
2012-03-06T15:34:21 topeg"undef" wird zurückgeben, weil es den Eintrag "{config}{system}{daemon}" nicht gbt. er wird angelegt, hat aber keinen Wert.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
use XML::Simple; my $cfg = XMLin('aircracker.conf', KeepRoot => 1); sub cfghandler { my $cmd = shift; my $option = shift; my $value = shift; my $xml; if (($cmd eq 'read') && ($option) && (!$value)) { } elsif (($cmd eq 'write') && ($option) && ($value)) { if ($option eq 'daemon') { $xml = { 'system' => { 'daemon' => "$value" } }; print XMLout( { config => $xml }, AttrIndent => 1, KeepRoot => 1, NoAttr => 1, OutputFile => $cfg ); }
cfghandler("write","daemon","test");
QuoteCan't call method "print" on unblessed reference at /usr/share/perl5/XML/Simple.pm line 634.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
sub confighandler { chomp(my $cmd = shift); chomp(my $option = shift); chomp(my $value = shift); open CONFIG, "<","aircracker.conf" or die $!; my @cfgdata = <CONFIG>; close(CONFIG); if (($cmd eq 'read') && ($option)) { foreach (@cfgdata) { if ($_ =~ m/<$option>(.+)<\/$option>/) { return $1; } } return ("Error: not an option: $option"); } elsif (($cmd eq 'write') && ($option) && ($value)) { my @newcfg; foreach (@cfgdata) { $_ =~ s/<$option>.+<\/$option>/<$option>$value<\/$option>/; push(@newcfg, $_); } open NEWCONFIG, ">","aircracker.conf" or die $!; print NEWCONFIG @newcfg; close(NEWCONFIG); return ("Config saved"); } else { return ("Error: read or write?"); } } confighandler("write","daemon","2");