33Plugin Name: HTTP:BL
44Plugin URI: https://github.com/joshp23/YOURLS-httpBL
55Description: An implementation of Project Honeypot's http:BL for YOURLS
6- Version: 2.0.6
6+ Version: 2.1.0
77Author: Josh Panter
88Author URI: https://unfettered.net
99**/
@@ -146,7 +146,6 @@ function httpBL_wl_mgr() {
146146// Admiin whitelist page 0.1 - printing the list
147147function httpBL_wl_list () {
148148
149- global $ ydb ;
150149 $ cip = yourls_get_ip ();
151150 $ q = httpBL_wl_chk ($ cip );
152151 if ($ q == true ) {
@@ -181,9 +180,14 @@ function httpBL_wl_list() {
181180HTML ;
182181
183182 // populate table rows with flag data if there is any
183+ global $ ydb ;
184184 $ table = 'httpBL_wl ' ;
185- $ sql = "SELECT * FROM ` $ table` ORDER BY timestamp DESC " ;
186- $ httpBL_white_listed = $ ydb ->fetchObjects ($ sql );
185+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
186+ $ sql = "SELECT * FROM ` $ table` ORDER BY timestamp DESC " ;
187+ $ httpBL_white_listed = $ ydb ->fetchObjects ($ sql );
188+ } else {
189+ $ httpBL_white_listed = $ ydb ->get_results ("SELECT * FROM ` $ table` ORDER BY timestamp DESC " );
190+ }
187191 $ found_rows = false ;
188192 if ($ httpBL_white_listed ) {
189193 $ found_rows = true ;
@@ -248,9 +252,13 @@ function httpBL_wl_add() {
248252 } else {
249253 global $ ydb ;
250254 $ table = 'httpBL_wl ' ;
251- $ binds = array ('ip ' => $ ip , 'notes ' => $ notes );
252- $ sql = "REPLACE INTO ` $ table` (ip, notes) VALUES (:ip, :notes) " ;
253- $ insert = $ ydb ->fetchAffected ($ sql , $ binds );
255+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
256+ $ binds = array ('ip ' => $ ip , 'notes ' => $ notes );
257+ $ sql = "REPLACE INTO ` $ table` (ip, notes) VALUES (:ip, :notes) " ;
258+ $ insert = $ ydb ->fetchAffected ($ sql , $ binds );
259+ } else {
260+ $ insert = $ ydb ->query ("REPLACE INTO `httpBL_wl` (ip, notes) VALUES (' $ ip', ' $ notes') " );
261+ }
254262
255263 echo '<h3 style="color:green">IP added to the whitelist. Have a nice day.</h3> ' ;
256264 }
@@ -265,9 +273,13 @@ function httpBL_wl_remove() {
265273 $ ip = $ _GET ['ip ' ];
266274 global $ ydb ;
267275 $ table = 'httpBL_wl ' ;
268- $ binds = array ('ip ' => $ ip , 'notes ' => $ notes );
269- $ sql = "DELETE FROM ` $ table` WHERE ip=:ip " ;
270- $ delete = $ ydb ->fetchAffected ($ sql , $ binds );
276+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
277+ $ binds = array ('ip ' => $ ip , 'notes ' => $ notes );
278+ $ sql = "DELETE FROM ` $ table` WHERE ip=:ip " ;
279+ $ delete = $ ydb ->fetchAffected ($ sql , $ binds );
280+ } else {
281+ $ delete = $ ydb ->query ("DELETE FROM ` $ table` WHERE ip=' $ ip' " );
282+ }
271283
272284 echo '<h3 style="color:green">IP removed from the whitelist. Have a nice day.</h3> ' ;
273285 }
@@ -279,7 +291,6 @@ function httpBL_log_view($log_vis,$nonce) {
279291 // should we bother with this data?"
280292 if ( ($ opt [5 ] == "true " ) || ($ opt [6 ] == "true " ) ) {
281293 // Log are checked
282- global $ ydb ;
283294 echo <<<HTML
284295 <div style="display: $ log_vis;" id="stat_tab_logs" class="tab">
285296
@@ -297,7 +308,8 @@ function httpBL_log_view($log_vis,$nonce) {
297308 </form>
298309 <h3>http:BL Log Table</h3>
299310
300- <p>These values are from Project Honeypot. More information on that can be found <a href="https://www.projecthoneypot.org/httpBL_api.php" target="_blank">here</a>.</p>
311+ <p>These values are from Project Honeypot. More information on the api can be found <a href="https://www.projecthoneypot.org/httpbl_api.php" target="_blank">here</a>.</p>
312+ <p>Information regarding the http:BL threat levels can be found <a href="https://www.projecthoneypot.org/threat_info.php" target="_blank">here</a>.</p>
301313
302314 <table id="main_table" class="tblSorter" border="1" cellpadding="5" style="border-collapse: collapse">
303315 <thead>
@@ -313,10 +325,14 @@ function httpBL_log_view($log_vis,$nonce) {
313325 <tbody>
314326HTML ;
315327 // populate table rows with flag data if there is any
316-
328+ global $ ydb ;
317329 $ table = 'httpBL_log ' ;
318- $ sql = "SELECT * FROM ` $ table` ORDER BY timestamp DESC " ;
319- $ logs = $ ydb ->fetchObjects ($ sql );
330+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
331+ $ sql = "SELECT * FROM ` $ table` ORDER BY timestamp DESC " ;
332+ $ logs = $ ydb ->fetchObjects ($ sql );
333+ } else {
334+ $ logs = $ ydb ->get_results ("SELECT * FROM ` $ table` ORDER BY timestamp DESC " );
335+ }
320336
321337 $ found_rows = false ;
322338 if ($ logs ) {
@@ -380,8 +396,12 @@ function httpBL_flush_logs() {
380396
381397 global $ ydb ;
382398 $ table = 'httpBL_log ' ;
383- $ sql = "TRUNCATE TABLE ` $ table` " ;
384- $ ydb ->fetchAffected ($ sql );
399+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
400+ $ sql = "TRUNCATE TABLE ` $ table` " ;
401+ $ ydb ->fetchAffected ($ sql );
402+ } else {
403+ $ ydb ->query ("TRUNCATE TABLE ` $ table` " );
404+ }
385405
386406 yourls_update_option ('httpBL_init_log ' , time ());
387407 $ init_log_2 = yourls_get_option ('httpBL_init_log ' );
@@ -403,9 +423,12 @@ function httpBL_flush_wl() {
403423
404424 global $ ydb ;
405425 $ table = 'httpBL_wl ' ;
406- $ sql = "TRUNCATE TABLE ` $ table` " ;
407- $ ydb ->fetchAffected ($ sql );
408-
426+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
427+ $ sql = "TRUNCATE TABLE ` $ table` " ;
428+ $ ydb ->fetchAffected ($ sql );
429+ } else {
430+ $ ydb ->query ("TRUNCATE TABLE ` $ table` " );
431+ }
409432 yourls_update_option ('httpBL_init_wl ' , time ());
410433 $ init_wl_2 = yourls_get_option ('httpBL_init_wl ' );
411434 if ($ init_wl_2 == false || $ init_wl_1 == $ init_wl_2 ) {
@@ -462,7 +485,7 @@ function httpBL_human_check() {
462485 if (isset ($ _COOKIE ['notabot ' ])) {
463486 if ($ opt [6 ] == "true " ) httpBL_logme (false , $ ip );
464487 } else {
465- httpBL_check ($ opt );
488+ httpBL_check ($ opt, $ ip );
466489 }
467490 }
468491}
@@ -473,25 +496,27 @@ function httpBL_wl_chk($ip) {
473496 $ result = false ;
474497
475498 $ table = 'httpBL_wl ' ;
476- $ binds = array ('ip ' => $ ip );
477- $ sql = "SELECT * FROM ` $ table` WHERE `ip` = :ip " ;
478- $ w_listed = $ ydb ->fetchObject ($ sql , $ binds );
499+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
500+ $ binds = array ('ip ' => $ ip );
501+ $ sql = "SELECT * FROM ` $ table` WHERE `ip` = :ip " ;
502+ $ w_listed = $ ydb ->fetchObject ($ sql , $ binds );
503+ } else {
504+ $ w_listed = $ ydb ->get_row ("SELECT * FROM ` $ table` WHERE `ip` = ' $ ip' " );
505+ }
479506
480507 if ( $ w_listed ) $ result = true ;
481508
482509 return $ result ;
483510}
484511// Check visitor IP
485- function httpBL_check ($ opt ) {
486-
487- $ ip = yourls_get_ip ();
512+ function httpBL_check ($ opt , $ ip ) {
488513
489514 // build the lookup DNS query
490515 // Example : for '127.9.1.2' you should query 'abcdefghijkl.2.1.9.127.dnsbl.httpBL.org'
491- $ lookup = $ opt [0 ] . '. ' . implode ('. ' , array_reverse (explode ('. ' , $ ip ))) . '.dnsbl.httpBL .org ' ;
492-
516+ $ querry = $ opt [0 ] . '. ' . implode ('. ' , array_reverse (explode ('. ' , $ ip ))) . '.dnsbl.httpbl .org ' ;
517+ $ lookup = gethostbyname ( $ querry );
493518 // check query response
494- $ result = explode ( '. ' , gethostbyname ( $ lookup) );
519+ $ result = explode ( '. ' , $ lookup );
495520
496521 if ($ result [0 ] == 127 ) {
497522 // query successful !
@@ -541,10 +566,13 @@ function httpBL_logme($block = false, $ip='', $typemeaning='',$threat='',$activi
541566
542567 global $ ydb ;
543568 $ table = 'httpBL_log ' ;
544- $ binds = array ('action ' => $ action , 'ip ' => $ ip , 'type ' => $ typemeaning , 'threat ' => $ threat , 'activity ' => $ activity , 'page ' => $ page , 'ua ' => $ ua );
545- $ sql = "INSERT INTO ` $ table` (action, ip, type, threat, activity, page, ua) VALUES (:action, :ip, :type, :threat, :activity, :page, :ua) " ;
546- $ insert = $ ydb ->fetchAffected ($ sql , $ binds );
547-
569+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
570+ $ binds = array ('action ' => $ action , 'ip ' => $ ip , 'type ' => $ typemeaning , 'threat ' => $ threat , 'activity ' => $ activity , 'page ' => $ page , 'ua ' => $ ua );
571+ $ sql = "INSERT INTO ` $ table` (action, ip, type, threat, activity, page, ua) VALUES (:action, :ip, :type, :threat, :activity, :page, :ua) " ;
572+ $ insert = $ ydb ->fetchAffected ($ sql , $ binds );
573+ } else {
574+ $ insert = $ ydb ->query ("INSERT INTO ` $ table` (action, ip, type, threat, activity, page, ua) VALUES (' $ action', ' $ ip', ' $ typemeaning', ' $ threat', ' $ activity', ' $ page', ' $ ua') " );
575+ }
548576}
549577// Primary blocking function
550578function httpBL_blockme ($ ip ,$ typemeaning ,$ threat ,$ opt ) {
@@ -619,7 +647,12 @@ function httpBL_activated() {
619647 $ table_httpBL_log .= "ua varchar(255) NOT NULL, " ;
620648 $ table_httpBL_log .= "PRIMARY KEY (timestamp) " ;
621649 $ table_httpBL_log .= ") ENGINE=MyISAM DEFAULT CHARSET=latin1; " ;
622- $ tables = $ ydb ->fetchAffected ($ table_httpBL_log );
650+
651+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
652+ $ tables = $ ydb ->fetchAffected ($ table_httpBL_log );
653+ } else {
654+ $ tables = $ ydb ->query ($ table_httpBL_log );
655+ }
623656
624657 yourls_update_option ('httpBL_init_log ' , time ());
625658 $ init_log = yourls_get_option ('httpBL_init_log ' );
@@ -640,7 +673,12 @@ function httpBL_activated() {
640673 $ table_httpBL_wl .= "notes varchar(255) NOT NULL, " ;
641674 $ table_httpBL_wl .= "PRIMARY KEY (timestamp) " ;
642675 $ table_httpBL_wl .= ") ENGINE=MyISAM DEFAULT CHARSET=latin1; " ;
643- $ tables = $ ydb ->fetchAffected ($ table_httpBL_wl );
676+
677+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
678+ $ tables = $ ydb ->fetchAffected ($ table_httpBL_wl );
679+ } else {
680+ $ tables = $ ydb ->query ($ table_httpBL_wl );
681+ }
644682
645683 yourls_update_option ('httpBL_init_wl ' , time ());
646684 $ init_wl = yourls_get_option ('httpBL_init_wl ' );
@@ -662,8 +700,12 @@ function httpBL_deactivate() {
662700 if ($ init_log !== false ) {
663701 yourls_delete_option ('httpBL_init_log ' );
664702 $ table = "httpBL_log " ;
665- $ sql = "DROP TABLE IF EXISTS $ table " ;
666- $ ydb ->fetchAffected ($ sql );
703+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
704+ $ sql = "DROP TABLE IF EXISTS $ table " ;
705+ $ ydb ->fetchAffected ($ sql );
706+ } else {
707+ $ ydb ->query ("DROP TABLE IF EXISTS ` $ table` " );
708+ }
667709 }
668710 }
669711 // Whitelist table
@@ -675,8 +717,12 @@ function httpBL_deactivate() {
675717 if ($ init_wl !== false ) {
676718 yourls_delete_option ('httpBL_init_wl ' );
677719 $ table = "httpBL_wl " ;
678- $ sql = "DROP TABLE IF EXISTS $ table " ;
679- $ ydb ->fetchAffected ($ sql );
720+ if (version_compare (YOURLS_VERSION , '1.7.3 ' ) >= 0 ) {
721+ $ sql = "DROP TABLE IF EXISTS $ table " ;
722+ $ ydb ->fetchAffected ($ sql );
723+ } else {
724+ $ ydb ->query ("DROP TABLE IF EXISTS ` $ table` " );
725+ }
680726 }
681727 }
682728}
0 commit comments