Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | <?php /* * CentralACL Version 1.1 * By: Nathan Adams * * Licensed under Apache 2.0 (see LICENSE.txt) * * How to use: * * 1. Replace MySQL credentials with your own * 2. Write the following line at the top of your PHP scripts: * include /path/to/centralacl.php; * 3. ????? * 4. Profit! * * */ $conn = new mysqli( "localhost" , "root" , "root" , "centralacl" ); $IP = $_SERVER [ 'REMOTE_ADDR' ]; $hostname = gethostbyaddr ( $IP ); $tld = "" ; $email = "adamsna [at] datanethost.net" ; $place = "Datanethost" ; function getstr() { try { $getstr = "" ; foreach ( $_GET as $key => $val ) { $getstr .= $key . " => " . $val . "\n" ; } } catch (Exception $e ) { //pass } return $getstr ; } function poststr() { $poststr = "" ; try { foreach ( $_POST as $key => $val ) { $poststr .= $key . " => " . $val . "\n" ; } } catch (Exception $e ) { } return $poststr ; } function logactivity() { global $conn ; $referer = array_key_exists ( 'HTTP_REFERER' , $_SERVER ) ? $_SERVER [ 'HTTP_REFERER' ] : "" ; $servername = array_key_exists ( 'SERVER_NAME' , $_SERVER ) ? $_SERVER [ 'SERVER_NAME' ] : "" ; $useragent = array_key_exists ( 'HTTP_USER_AGENT' , $_SERVER ) ? $_SERVER [ 'HTTP_USER_AGENT' ] : "" ; $q = "INSERT INTO activity (ip_addr,getdata,postdata,servername,referer,user_agent, datestamp) VALUES ('" . $_SERVER ['REMOTE_ADDR '] . "' ,"; $q .= "'" . getstr() . "','" . poststr() . "','" . $servername . "'," ; $q .= "'" . $referer . "','" . $useragent . "', " . time() . ")" ; $conn ->query( $q ); } if ( $hostname ) { $hostnamearr = explode ( "." , $hostname ); $tld = implode( "." , array_splice ( $hostnamearr , -3, 3)); } else { $outtext = "In order to access this site you must have a reverse PTR set for your IP address.<br>" ; $outtext .= "If you would like to be added to a whitelist please email $email\n" ; $conn ->close(); die ( $outtext ); } $nip = sprintf( "%u" , ip2long ( $IP )); //Is the IP on the blocklist? $whitelistip_check = $conn ->query( "SELECT * FROM whitelistip WHERE ip_addr = $nip" ); if ( $whitelistip_check && $whitelistip_check ->num_rows == 0) { $blacklistip_check = $conn ->query( "SELECT * FROM blockedip where start_ip_addr <= $nip AND end_ip_addr >= $nip" ); if ( $blacklistip_check && $blacklistip_check ->num_rows == 0) { //Is the hostname on the whitelist? $blacklistdomain_check = $conn ->query( "SELECT * FROM blockddomains WHERE domain LIKE '$tld'" ); if ( $blacklistdomain_check && $blacklistdomain_check ->num_rows > 0) { //log activity logactivity(); $outtext = "Your hostname has been banned from $place.<br>" ; $outtext .= "If you believe this to be in error please contact $email" ; $conn ->close(); die ( $outtext ); } } else { //log activity logactivity(); $outtext = "Your IP has been banned from $place.<br>" ; $outtext .= "If you believe this to be in error please contact $email" ; $conn ->close(); die ( $outtext ); } } $conn ->close(); ?> |
Source at commit 1379d724abe2 created 11 years 8 months ago. By Nathan Adams, initial commit |
---|