Rev 753 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 753 | 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 | $wiki = "http://localhost"; |
32 | $wiki = "http://localhost"; |
| 33 | $namespace = "homeautomation:livestats"; |
33 | $namespace = "homeautomation:livestats"; |
| 34 | $pagename = "default"; |
34 | $pagename = "default"; |
| 35 | 35 | ||
| 36 | require "settings.pl"; |
36 | require "settings.pl"; |
| 37 | require "dokuwiki.pl"; |
37 | require "dokuwiki.pl"; |
| 38 | #dokuwikipost("http://www.arune.se/temp/post.php", "homeautomation:livestats:arune", "texten att posta", "med summary"); |
38 | #dokuwikipost("http://www.arune.se/temp/post.php", "homeautomation:livestats:arune", "texten att posta", "med summary"); |
| 39 | #dokuwikipost($wiki."/doku.php", $namespace.":".$pagename, "texten att posta", "med summary"); |
39 | #dokuwikipost($wiki."/doku.php", $namespace.":".$pagename, "texten att posta", "med summary"); |
| 40 | 40 | ||
| 41 | $remote = IO::Socket::INET->new( |
41 | $remote = IO::Socket::INET->new( |
| 42 | Proto => "tcp", |
42 | Proto => "tcp", |
| 43 | PeerAddr => $host, |
43 | PeerAddr => $host, |
| 44 | PeerPort => $port, |
44 | PeerPort => $port, |
| 45 | ) |
45 | ) |
| 46 | or die "cannot connect to port $port at $host"; |
46 | or die "cannot connect to port $port at $host"; |
| 47 | 47 | ||
| 48 | #read line from socket (blocking) |
48 | #read line from socket (blocking) |
| 49 | while ( $line = <$remote> ) { |
49 | while ( $line = <$remote> ) { |
| 50 | if (length($line) > 12) { |
50 | if (length($line) > 12) { |
| 51 | $id = hex(substr($line, 4, 8)); |
51 | $id = hex(substr($line, 4, 8)); |
| 52 | 52 | ||
| 53 | #macro function |
53 | #macro function |
| 54 | for ($i = 0; $i < $input; $i++) { |
54 | for ($i = 0; $i < $input; $i++) { |
| 55 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
55 | if ($input[$i] eq substr($line, 0, length($input[$i]))) { |
| 56 | print $remote $output[$i]; |
56 | print $remote $output[$i]; |
| 57 | } |
57 | } |
| 58 | } |
58 | } |
| 59 | 59 | ||
| 60 | $printed = 0; |
60 | $printed = 0; |
| 61 | $denied = 0; |
61 | $denied = 0; |
| 62 | #filter function |
62 | #filter function |
| 63 | for ($i = 0; $i < $acceptmask_ones && !$printed && !$denied; $i++) { |
63 | for ($i = 0; $i < $acceptmask_ones && !$printed && !$denied; $i++) { |
| 64 | if ((($id & $acceptmask_ones[$i])==$acceptmask_ones[$i]) && (($id & $acceptmask_zeros[$i])==0)) { |
64 | if ((($id & $acceptmask_ones[$i])==$acceptmask_ones[$i]) && (($id & $acceptmask_zeros[$i])==0)) { |
| 65 | #check if denied by $denymask |
65 | #check if denied by $denymask |
| 66 | for ($j = 0; $j < $denymask_ones; $j++) { |
66 | for ($j = 0; $j < $denymask_ones; $j++) { |
| 67 | if ((($id & $denymask_ones[$j])==$denymask_ones[$j]) && (($id & $denymask_zeros[$j])==0)) { |
67 | if ((($id & $denymask_ones[$j])==$denymask_ones[$j]) && (($id & $denymask_zeros[$j])==0)) { |
| 68 | #this message fits the denymask |
68 | #this message fits the denymask |
| 69 | $denied = 1; |
69 | $denied = 1; |
| 70 | } |
70 | } |
| 71 | 71 | ||
| 72 | } |
72 | } |
| 73 | 73 | ||
| 74 | if (!$denied) { |
74 | if (!$denied) { |
| 75 | #print timestamp |
75 | #print timestamp |
| 76 | if ($timestamp == 1) { |
76 | if ($timestamp == 1) { |
| 77 | print localtime()." "; |
77 | print localtime()." "; |
| 78 | } |
78 | } |
| 79 | print $line; |
79 | print $line; |
| 80 | 80 | ||
| 81 | $printed = 1; |
81 | $printed = 1; |
| 82 | } |
82 | } |
| 83 | } |
83 | } |
| 84 | } |
84 | } |
| 85 | } |
85 | } |
| 86 | } |
86 | } |
| 87 | 87 | ||
| 88 | sub sendTime { |
88 | sub sendTime { |
| 89 | $remote = IO::Socket::INET->new( |
89 | $remote = IO::Socket::INET->new( |
| 90 | Proto => "tcp", |
90 | Proto => "tcp", |
| 91 | PeerAddr => $host, |
91 | PeerAddr => $host, |
| 92 | PeerPort => $port, |
92 | PeerPort => $port, |
| 93 | ) |
93 | ) |
| 94 | or die "cannot connect to port $port at $host"; |
94 | or die "cannot connect to port $port at $host"; |
| 95 | 95 | ||
| 96 | while (1) { |
96 | while (1) { |
| 97 | select(undef, undef, undef, 0.5); |
97 | select(undef, undef, undef, 0.5); |
| 98 | print $remote "PKT 00000000 1 0"; |
98 | print $remote "PKT 00000000 1 0"; |
| 99 | } |
99 | } |
| 100 | } |
100 | } |
| 101 | 101 | ||