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