Rev 599 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 599 | Rev 800 | ||
|---|---|---|---|
| 1 | #!/usr/bin/perl -w |
1 | #!/usr/bin/perl -w |
| 2 | ################################################ |
2 | ################################################ |
| 3 | # |
3 | # |
| 4 | # This file should not be edited for settings |
4 | # This file should not be edited for settings |
| 5 | # use settings.pl for that |
5 | # use settings.pl for that |
| 6 | # |
6 | # |
| 7 | # author: arune @ efnet |
7 | # author: arune @ efnet |
| 8 | # |
8 | # |
| 9 | ################################################ |
9 | ################################################ |
| 10 | 10 | ||
| 11 | use IO::Socket; |
11 | use IO::Socket; |
| 12 | use integer; |
12 | use integer; |
| 13 | use threads; |
13 | use threads; |
| 14 | 14 | ||
| 15 | #for sending time msg: set to 1, else set to 0 |
15 | #for sending time msg: set to 1, else set to 0 |
| 16 | $sendtime = 0; |
16 | $sendtime = 0; |
| 17 | 17 | ||
| 18 | #for printing timestamps on printed messages: set to 1, else set to 0 |
18 | #for printing timestamps on printed messages: set to 1, else set to 0 |
| 19 | $timestamp = 1; |
19 | $timestamp = 1; |
| 20 | 20 | ||
| 21 | #define filters for id of messages, passed messages will be printed on stdout |
21 | #define filters for id of messages, passed messages will be printed on stdout |
| 22 | @acceptmask_ones = (); |
22 | @acceptmask_ones = (); |
| 23 | @acceptmask_zeros = (); |
23 | @acceptmask_zeros = (); |
| 24 | @denymask_ones = (); |
24 | @denymask_ones = (); |
| 25 | @denymask_zeros = (); |
25 | @denymask_zeros = (); |
| 26 | 26 | ||
| 27 | @input = (); |
27 | @input = (); |
| 28 | @output = (); |
28 | @output = (); |
| 29 | 29 | ||
| 30 | $host = "localhost"; |
30 | $host = "localhost"; |
| 31 | $port = 1200; |
31 | $port = 1200; |
| 32 | 32 | ||
| 33 | require "settings.pl"; |
33 | require "settings.pl"; |
| 34 | 34 | ||
| 35 | $remote = IO::Socket::INET->new( |
35 | $remote = IO::Socket::INET->new( |
| 36 | Proto => "tcp", |
36 | Proto => "tcp", |
| 37 | PeerAddr => $host, |
37 | PeerAddr => $host, |
| 38 | PeerPort => $port, |
38 | PeerPort => $port, |
| 39 | ) |
39 | ) |
| 40 | or die "cannot connect to port 1200 at localhost"; |
40 | or die "cannot connect to port 1200 at localhost"; |
| 41 | 41 | ||
| 42 | if ($sendtime == 1) { |
42 | if ($sendtime == 1) { |
| 43 | $thr = threads->new(\&sendTime); |
43 | $thr = threads->new(\&sendTime); |
| 44 | $thr->detach; |
44 | $thr->detach; |
| 45 | } |
45 | } |
| 46 | 46 | ||
| 47 | $acceptmask_ones = @acceptmask_ones; |
47 | $acceptmask_ones = @acceptmask_ones; |
| 48 | $acceptmask_zeros = @acceptmask_zeros; |
48 | $acceptmask_zeros = @acceptmask_zeros; |
| 49 | if ($acceptmask_ones != $acceptmask_zeros) { |
49 | if ($acceptmask_ones != $acceptmask_zeros) { |
| 50 | print "Acceptmasks must be same length\n"; |
50 | print "Acceptmasks must be same length\n"; |
| 51 | exit; |
51 | exit; |
| 52 | } |
52 | } |
| 53 | 53 | ||
| 54 | $denymask_ones = @denymask_ones; |
54 | $denymask_ones = @denymask_ones; |
| 55 | $denymask_zeros = @denymask_zeros; |
55 | $denymask_zeros = @denymask_zeros; |
| 56 | if ($denymask_ones != $denymask_zeros) { |
56 | if ($denymask_ones != $denymask_zeros) { |
| 57 | print "Denymasks must be same length\n"; |
57 | print "Denymasks must be same length\n"; |
| 58 | exit; |
58 | exit; |
| 59 | } |
59 | } |
| 60 | 60 | ||
| 61 | #get the lengths of the makro arrays: |
61 | #get the lengths of the makro arrays: |
| 62 | $input = @input; |
62 | $input = @input; |
| 63 | $output = @output; |
63 | $output = @output; |
| 64 | if ($input != $output) { |
64 | if ($input != $output) { |
| 65 | print "Input and output makros must be same length\n"; |
65 | print "Input and output makros must be same length\n"; |
| 66 | exit; |
66 | exit; |
| 67 | } |
67 | } |
| 68 | 68 | ||
| 69 | #read line from socket (blocking) |
69 | #read line from socket (blocking) |
| 70 | while ( $line = <$remote> ) { |
70 | while ( $line = <$remote> ) { |
| 71 | if (length($line) > 12) { |
71 | if (length($line) > 12) { |
| 72 | $id = hex(substr($line, 4, 8)); |
72 | $id = hex(substr($line, 4, 8)); |
| 73 | 73 | ||
| 74 | #macro function |
74 | #macro function |
| 75 | for ($i = 0; $i < $input; $i++) { |
75 | for ($i = 0; $i < $input; $i++) { |
| 76 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
76 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
| 77 | print $remote $output[$i]; |
77 | print $remote $output[$i]; |
| 78 | } |
78 | } |
| 79 | } |
79 | } |
| 80 | 80 | ||
| 81 | $printed = 0; |
81 | $printed = 0; |
| 82 | $denied = 0; |
82 | $denied = 0; |
| 83 | #filter function |
83 | #filter function |
| 84 | for ($i = 0; $i < $acceptmask_ones && !$printed && !$denied; $i++) { |
84 | for ($i = 0; $i < $acceptmask_ones && !$printed && !$denied; $i++) { |
| 85 | if ((($id & $acceptmask_ones[$i])==$acceptmask_ones[$i]) && (($id & $acceptmask_zeros[$i])==0)) { |
85 | if ((($id & $acceptmask_ones[$i])==$acceptmask_ones[$i]) && (($id & $acceptmask_zeros[$i])==0)) { |
| 86 | #check if denied by $denymask |
86 | #check if denied by $denymask |
| 87 | for ($j = 0; $j < $denymask_ones; $j++) { |
87 | for ($j = 0; $j < $denymask_ones; $j++) { |
| 88 | if ((($id & $denymask_ones[$j])==$denymask_ones[$j]) && (($id & $denymask_zeros[$j])==0)) { |
88 | if ((($id & $denymask_ones[$j])==$denymask_ones[$j]) && (($id & $denymask_zeros[$j])==0)) { |
| 89 | #this message fits the denymask |
89 | #this message fits the denymask |
| 90 | $denied = 1; |
90 | $denied = 1; |
| 91 | } |
91 | } |
| 92 | 92 | ||
| 93 | } |
93 | } |
| 94 | 94 | ||
| 95 | if (!$denied) { |
95 | if (!$denied) { |
| 96 | #print timestamp |
96 | #print timestamp |
| 97 | if ($timestamp == 1) { |
97 | if ($timestamp == 1) { |
| 98 | print localtime()." "; |
98 | print localtime()." "; |
| 99 | } |
99 | } |
| 100 | print $line; |
100 | print $line; |
| 101 | 101 | ||
| 102 | $printed = 1; |
102 | $printed = 1; |
| 103 | } |
103 | } |
| 104 | } |
104 | } |
| 105 | } |
105 | } |
| 106 | } |
106 | } |
| 107 | } |
107 | } |
| 108 | 108 | ||
| 109 | sub sendTime { |
109 | sub sendTime { |
| 110 | $remote = IO::Socket::INET->new( |
110 | $remote = IO::Socket::INET->new( |
| 111 | Proto => "tcp", |
111 | Proto => "tcp", |
| 112 | PeerAddr => $host, |
112 | PeerAddr => $host, |
| 113 | PeerPort => $port, |
113 | PeerPort => $port, |
| 114 | ) |
114 | ) |
| 115 | or die "cannot connect to port $port at $host"; |
115 | or die "cannot connect to port $port at $host"; |
| 116 | 116 | ||
| 117 | while (1) { |
117 | while (1) { |
| 118 | select(undef, undef, undef, 0.5); |
118 | select(undef, undef, undef, 0.5); |
| 119 | print $remote "PKT 00000000 1 0"; |
119 | print $remote "PKT 00000000 1 0"; |
| 120 | } |
120 | } |
| 121 | } |
121 | } |
| 122 | 122 | ||