Thread: [Netpass-devel] NetPass/lib/NetPass Config.pm,1.42,1.43 DB.pm,1.42,1.43
Brought to you by:
jeffmurphy
|
From: jeff m. <jef...@us...> - 2005-06-02 19:05:06
|
Update of /cvsroot/netpass/NetPass/lib/NetPass In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20551/lib/NetPass Modified Files: Config.pm DB.pm Log Message: bug fixes, switch config, snort stuff Index: Config.pm =================================================================== RCS file: /cvsroot/netpass/NetPass/lib/NetPass/Config.pm,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- Config.pm 20 May 2005 20:32:59 -0000 1.42 +++ Config.pm 2 Jun 2005 19:04:53 -0000 1.43 @@ -2004,19 +2004,137 @@ return ($good == $v || $bad == $v) ? 1 : 0; } +=head2 $encodedTagList = encodeTagList($tlHref) -# tagList format: -# port1,port3-port5:good/bad;port7-port10:good/bad -# -# e.g. if the switch services multiple networks (2 in this case) -# -# 1,10-20:12/812;2-9,21-24:13/813 -# -# or more simply, you'll typically have: -# -# 1-24:12/812 -# -# where '12' is the 'good/normal' vlan and '812' is the quarantine +This routine is not a method. Given a tagList hash ref such as + + $tl->{'12/812'} = [ 1,2,3,5,6 ]; + $tl->{'13/813'} = [ 10,11,12,20,21 ]; + +encode it into the format: + + port1,port3-port5:good/bad;port7-port10:good/bad + +See also: expandTagList() + +Returns + "..." encoded tag list + "invalid parameters" routine called improperly + +=cut + +sub encodeTagList { + my $th = shift; + if (ref($th) ne "HASH") { + return "invalid parameters"; + } + + my $v = {}; + foreach my $port (keys %$th) { + my $val = $th->{$port}; + $val =~ s/\|/\//g; + if ( exists $v->{$val} ) { + $v->{$val} = [ $port ]; + } + else { + push @{$v->{$val}}, $port; + } + } + + # now we have th->{'12/812'} = [ 1,2,3,6,7,8 ] + # and we want to go to + # th->{'12/812'} = '1-3,6-8' + + foreach my $vlan (keys %$th) { + $th->{$vlan} = formatPorts($th->{$vlan}); + } + + +} + +sub formatPorts { + my $d = shift; + my $s = ""; + + foreach my $vid (keys %$d) { + my @t = sort {$a<=>$b} @{$d->{$vid}}; + + my $start = $t[0]; + my $prev = $start; + my $cur = $start; + + my @myline; + + for (my $i = 1 ; $i <= $#t ; $i++) { + $cur = $t[$i]; + if ($cur - $prev > 1) { + # we've hit a break + if ($start != $prev) { + push @myline, "$start-$prev"; + } else { + push @myline, "$start"; + } + $prev = $start = $cur ; + } else { + $prev = $cur; + } + } + + if ($start != $prev) { + push @myline, "$start-$prev"; + } else { + push @myline, "$start"; + } + + $s .= join(',', @myline).':'.$vid.';'; + } + return $s; +} + +sub getVlanMap { + my $self = shift; + my $sw = shift; + + $sw ||= ''; + if (recur_exists($self->{'cfg'}, 'vlanmap', $sw)) { + return $self->{'cfg'}->obj('vlanmap')->value($sw); + } + return undef; +} + +sub setVlanMap { + my $self = shift; + my $sw = shift; + my $vm = shift; + + $sw ||= ''; + $self->{'cfg'}->obj('vlanmap')->$sw($vm); + return undef; +} + +=head2 $tlHref = expandTagList($encodedTagList) + +This routine is not a method. Given an encoded tag list (vlanmap) like + + + tagList format: + port1,port3-port5:good/bad;port7-port10:good/bad + + e.g. if the switch services multiple networks (2 in this case) + + 1,10-20:12/812;2-9,21-24:13/813 + + or more simply, you'll typically have: + + 1-24:12/812 + + where '12' is the 'good/normal' vlan and '812' is the quarantine + +Return a hash ref with the port as the key and the vlan as the value. +So, for example, you'll have: $tl->{10} = '12|812'. For historical +reasons the "/" is converted to "|". + +=cut sub expandTagList { my $tl = shift; Index: DB.pm =================================================================== RCS file: /cvsroot/netpass/NetPass/lib/NetPass/DB.pm,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- DB.pm 17 May 2005 20:34:27 -0000 1.42 +++ DB.pm 2 Jun 2005 19:04:54 -0000 1.43 @@ -299,90 +299,6 @@ return 0; } - -=head2 setMessage(mac, message | url) - -This routine will set the message on an already registered MAC. It will over-write -any existing message. If the message begins with "http:" then the web front end -will assume it's a URL. Otherwise, the web frontend will assume it's text or HTML -code and display it appropriately. It's OK to set the message to C<undef>. Returns: - -=over 4 - -=item 1 - -on success - -=item 0 - -on failure (e.g. mac isnt registered) - -=back - -=cut - -sub setMessage { - my $self = shift; - my ($ma, $msg) = (shift, shift); - - #called by macIsReg .. $self->reconnect() || return 0; - - my $rv = $self->macIsRegistered($ma); - return 0 if ($rv < 1); - - if (defined($msg) && ($msg !~ /^null$/i)) { - $msg = $self->{'dbh'}->quote($msg); - } else { - $msg = 'NULL'; - } - - my $sql = "UPDATE register SET message = $msg WHERE macAddress = '$ma'"; - - _log ("DEBUG", "$ma setMessage to $msg (sql=$sql)\n"); - - return 1 if $self->{'dbh'}->do($sql); - - _log("ERROR", "setMessage failed: ".$self->{'dbh'}->errstr."\n"); - - return 0; -} - -=head2 $msg = getMessage(mac) - -This routine will get the message on an already registered MAC. Returns: - -=over 4 - -=item C<scalar> - -on success - -=item undef - -on failure or no message set - -=back - -=cut - -sub getMessage { - my $self = shift; - my $ma = shift; - - #called by macIsReg .. $self->reconnect() || return undef; - - my $rv = $self->macIsRegistered($ma); - return undef if ($rv == 0); - return undef if ($rv == -1); - - my $sql = "SELECT message FROM register WHERE macAddress = '$ma'"; - - my $a = $self->{'dbh'}->selectrow_arrayref($sql); - _log "ERROR", "select failed: ".$self->{'dbh'}->errstr."\n" - unless (defined($a) && (ref($a) eq "ARRAY")); - return $a->[0]; -} - =head2 $rv = getRegisterInfo(-mac => mac, -macs => [], -ip => ip, -ips => []) This routine will get the registered info on an already registered MAC. Returns: @@ -433,7 +349,7 @@ my ($mac, $macs, $ip, $ips) = $parms->get('-mac', '-macs', '-ip', '-ips'); - my $sql = "SELECT macAddress, ipAddress, lastSeen, registeredOn, status, message, username, OS, switchIP, switchPort, uqlinkup FROM register WHERE "; + my $sql = "SELECT macAddress, ipAddress, lastSeen, registeredOn, status, username, OS, switchIP, switchPort, uqlinkup FROM register WHERE "; if ($mac ne "") { $sql .= " macAddress = ".$self->dbh->quote($mac); $kfield = "macAddress"; @@ -2743,8 +2659,6 @@ - - sub commit { my $self = shift; $self->reconnect() || return 0; @@ -2754,6 +2668,24 @@ +=head2 updateRegister(-mac => '', -status => [QUAR|PQUAR|UNQUAR|PUNQUAR]) + +Update the register table for the given MAC address. + +RETURNS + + 0 on success + "invalid parameters" routine called improperly + "mac not exist" given mac doesnt exist (use registerHost first) + "..." db error + +=cut + +sub updateRegister { + my $self = shift; + # params... +} + =head1 AUTHOR |