| [ Index ] |
PHP Cross Reference of Jalakai Designs - DokuWiki Plugins & Templates |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @author Andreas Gohr <gohr@cosmocode.de> 6 */ 7 8 // must be run within Dokuwiki 9 if(!defined('DOKU_INC')) die(); 10 define('BB2_CWD', dirname(__FILE__)); 11 12 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 require_once (DOKU_PLUGIN.'action.php'); 14 15 class action_plugin_badbehaviour extends DokuWiki_Action_Plugin { 16 17 /** 18 * return some info 19 */ 20 function getInfo(){ 21 include (BB2_CWD.'/info.php'); 22 return $info; 23 } 24 25 /** 26 * register the eventhandlers and initialize some options 27 */ 28 function register(&$controller){ 29 30 $controller->register_hook('DOKUWIKI_STARTED', 31 'BEFORE', 32 $this, 33 'handle_start', 34 array()); 35 36 $controller->register_hook('TPL_METAHEADER_OUTPUT', 37 'BEFORE', 38 $this, 39 'handle_metaheaders', 40 array()); 41 } 42 43 /** 44 * Do the magic 45 */ 46 function handle_start(&$event, $param){ 47 require_once (BB2_CWD . "/bad-behavior/version.inc.php"); 48 require_once (BB2_CWD . "/bad-behavior/core.inc.php"); 49 50 bb2_start(array( 'log_table' => 'badbehaviour', 51 'display_stats' => true, 52 'strict' => false, 53 'verbose' => false, 54 'skipblackhole' => $this->getConf('skipblackhole') 55 )); 56 } 57 58 /** 59 * Extend the meta headers 60 */ 61 function handle_metaheaders(&$event, $param){ 62 global $bb2_javascript; 63 if (!$bb2_javascript) return; 64 65 // we just use some values from the bb2 script but build our own (better) version 66 67 preg_match('/(bb2_addLoadEvent\(function\(\) \{)(.*)(\}\);)/s',$bb2_javascript,$match); 68 $data = 'addInitEvent(function(){'.$match[2].'});'; 69 70 $event->data['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>$data); 71 } 72 73 } 74 75 /* 76 * Bad Behavior expects certain global functions. Mostly related to the DB logging, 77 * which is not used in DokuWiki 78 */ 79 80 function bb2_relative_path() { return DOKU_BASE; } 81 function bb2_db_date() { return gmdate('Y-m-d H:i:s'); } 82 function bb2_db_affected_rows() { return false; } 83 function bb2_db_escape($string) { return $string; } 84 function bb2_db_num_rows($result) { return ($result === FALSE) ? 0 : count($result); } 85 function bb2_db_query($query) { return false; } 86 function bb2_db_rows($result) { return $result; } 87 function bb2_email() { 88 $bb2 =& plugin_load('action','badbehaviour'); 89 return $bb2->getConf('email'); 90 } 91 92 /** 93 * This is an extension hook provided by BB2, we use it to do our 94 * own logging. 95 */ 96 function bb2_banned_callback($settings, $package, $key){ 97 global $conf; 98 99 $data = array(); 100 $data[] = time(); 101 $data[] = stripctl($package['ip']); 102 $data[] = stripctl($package['request_method']); 103 $data[] = stripctl($package['request_uri']); 104 $data[] = stripctl($package['server_protocol']); 105 $data[] = stripctl($package['user_agent']); 106 $data[] = stripctl($key); 107 108 io_saveFile($conf['cachedir'].'/badbehaviour.log',join("\t",$data)."\n",true); 109 } 110 111 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Dec 16 05:46:24 2006 | Cross-referenced by PHPXref 0.6 |