centralacl

centralacl Commit Details


Date:2013-08-11 16:41:00 (11 years 4 months ago)
Author:Natalie Adams
Branch:default
Commit:1379d724abe2
Message:initial commit

Changes:
Aengine/LICENSE.txt (full)
Aengine/centralacl.php (full)
Aengine/centralacl.sql (full)

File differences

engine/LICENSE.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
Copyright [2011] [Nathan Adams]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
engine/centralacl.php
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 .= "More information: http://en.wikipedia.org/wiki/PTR_Record.\n";
$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();
?>
engine/centralacl.sql
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
/*
SQLyog Community v8.82
MySQL - 5.5.8 : Database - centralacl
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`centralacl` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `centralacl`;
/*Table structure for table `activity` */
DROP TABLE IF EXISTS `activity`;
CREATE TABLE `activity` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ip_addr` char(16) NOT NULL,
`getdata` text NOT NULL,
`postdata` text NOT NULL,
`servername` text,
`referer` text,
`user_agent` text,
`datestamp` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Table structure for table `blockeddomains` */
DROP TABLE IF EXISTS `blockeddomains`;
CREATE TABLE `blockeddomains` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`domain` char(100) NOT NULL,
`date_added` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Table structure for table `blockedip` */
DROP TABLE IF EXISTS `blockedip`;
CREATE TABLE `blockedip` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`start_ip_addr` int(11) unsigned NOT NULL,
`end_ip_addr` int(11) unsigned NOT NULL,
`date_added` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Table structure for table `whitelistip` */
DROP TABLE IF EXISTS `whitelistip`;
CREATE TABLE `whitelistip` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ip_addr` int(11) unsigned NOT NULL,
`date_added` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

Archive Download the corresponding diff file

Branches

Tags

Page rendered in 0.44243s using 14 queries.