File: ip2name.squidlist2

package info (click to toggle)
lightsquid 1.8-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 532 kB
  • sloc: perl: 2,320; sh: 13; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (4)
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
31
32
33
34
35
36
37
38
39
40
41
#contributor  : vovich2005 
#modification : ESL (use hash for speed up resolve)
#
#convert user -> ip , get user name from file
#file format
#
#192.168.0.96/255.255.255.255 # User1
#192.168.0.106/255.255.255.255 # User2
#192.168.0.105/255.255.255.255 # User3
#
#if user not found -> return IP 

sub StartIp2Name() {
    my $ipfile = "/etc/squid/users.txt";

    open (F, "<".$ipfile) || die ("ERROR: Can't open ".$ipfile."!!!\n");
    while (<F>) {
      chomp;
      @FLD = split (' ', $_);
      @IP = split ('/', $FLD[0]);
      $hIP2NAME{$IP[0]}=$FLD[2];
    }
    close (F);
}

sub Ip2Name($$$) {
    my $ipaddr = shift;

    if (defined $hIP2NAME{$ipaddr}){
       $res = $hIP2NAME{$ipaddr};
    } else {
       $res = $ipaddr;
    }
    return $res;
}

sub StopIp2Name() {
}

#warning !!!
1;