home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / acld-1.11.tar.gz / acld-1.11.tar / acld-1.11 / acld.bro < prev    next >
Text File  |  2010-05-12  |  3KB  |  138 lines

  1. # @(#) $Id: acld.bro 659 2010-04-19 22:36:26Z leres $ (LBL)
  2. #
  3. # Copyright (c) 2008, 2009, 2010
  4. #      The Regents of the University of California.  All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that: (1) source code distributions
  8. # retain the above copyright notice and this paragraph in its entirety, (2)
  9. # distributions including binary code include the above copyright notice and
  10. # this paragraph in its entirety in the documentation or other materials
  11. # provided with the distribution, and (3) all advertising materials mentioning
  12. # features or use of this software display the following acknowledgement:
  13. # ``This product includes software developed by the University of California,
  14. # Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  15. # the University nor the names of its contributors may be used to endorse
  16. # or promote products derived from this software without specific prior
  17. # written permission.
  18. # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  19. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  20. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. #
  22.  
  23. @load remote
  24. @load notice
  25.  
  26. # Define new notices
  27. redef enum Notice += {
  28.     AcldDebug,
  29. };
  30.  
  31. module acld;
  32.  
  33. type acld_request_rec: record {
  34.     cmd: string;
  35.     cookie: count;
  36.     comment: string &optional;
  37. };
  38.  
  39. type acld_reply_rec: record {
  40.     cmd: string;
  41.     cookie: count;
  42.     timestamp: time;
  43.     success: bool;
  44.     comment: string &optional;
  45.     payload: string &optional;
  46. };
  47.  
  48. export {
  49.     global acld_block: function(h: addr);
  50.     global acld_blockhosthost: function(h1: addr, h2: addr);
  51.     global acld_reply: event(rep: acld_reply_rec);
  52.     global acld_request: event(msg: acld_request_rec);
  53.     global acld_restorehosthost: function(h1: addr, h2: addr);
  54.     global acld_unblock: function(h: addr);
  55.  
  56.     # Default acld host and port
  57.     const acldaddr: addr = 127.0.0.1 &redef;
  58.     const acldport: port = 47777/tcp &redef;
  59. }
  60.  
  61. redef Remote::destinations += {
  62.     ["acld"] = [
  63.         $host = acldaddr,
  64.         $p = acldport,
  65.         $class = "acld",
  66.         $events = /acld::acld_reply/,
  67.         $connect = T,
  68.         $retry = 10 secs,
  69.         $ssl=F
  70.     ]
  71. };
  72.  
  73. global cookie: count = 0;
  74.  
  75. # Hook to re-block hosts at startup
  76. event
  77. bro_init()
  78. {
  79.     NOTICE([$note=AcldDebug, $msg=fmt("acld: acldaddr %s @ %s",
  80.         acldaddr, acldport) ]);
  81. }
  82.  
  83. function
  84. acld_block(h: addr)
  85. {
  86.  
  87. NOTICE([$note=AcldDebug, $msg=fmt("acld_block: %s!", h) ]);
  88.  
  89.     event acld::acld_request([$cmd = fmt("drop %s", h), $cookie = cookie]);
  90.     ++cookie;
  91. }
  92.  
  93. function
  94. acld_blockhosthost(h:ddr, h2: addr addr)
  95. {
  96.  
  97. NOTICE([$note=AcldDebug, $msg=fmt("acld_blockhosthost: %s %s!", h1, h2) ]);
  98.  
  99.     event acld::acld_request([$cmd = fmt("blockhosthost %s %s", h1, h2),
  100.         $cookie = cookie]);
  101.     ++cookie;
  102. }
  103.  
  104. function
  105. acld_restorehosthost(h1: addr, h2: addr)
  106. {
  107.  
  108. NOTICE([$note=AcldDebug, $msg=fmt("acld_restorehosthost: %s %s!", h1, h2) ]);
  109.  
  110.     event acld::acld_request([$cmd = fmt("restorehosthost %s %s", h1, h2),
  111.         $cookie = cookie]);
  112.     ++cookie;
  113. }
  114.  
  115. event
  116. acld_reply(rep: acld_reply_rec)
  117. {
  118.     local str: string;
  119.  
  120.     if (rep$success)
  121.         str = "success";
  122.     else
  123.         str = "fail";
  124.  
  125.     NOTICE([$note=AcldDebug, $msg=fmt("acld::reply(): \"%s\" %s (%d)",
  126.         rep$cmd, str, rep$cookie) ]);
  127. }
  128.  
  129. function
  130. acld_unblock(h: addr)
  131. {
  132.  
  133. NOTICE([$note=AcldDebug, $msg=fmt("acld_unblock: %s!", h) ]);
  134.     event acld::acld_request([$cmd = fmt("restore %s", h),
  135.         $cookie = cookie]);
  136.     ++cookie;
  137. }
  138.