-
Notifications
You must be signed in to change notification settings - Fork 1
/
output-worker.php
192 lines (157 loc) · 6.96 KB
/
output-worker.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/*
Filename: output-worker.php
Rev 2015.0309.0110
Project: ip-addr-to-arin-cidr
Copyright (C) Rex Addiscentis - raddiscentis@addiscent.com
Description:
The OutputWorker class is responsible for output to the web page. It
provides a prompt and input form, and displays the results of the data
recieved from the ARIN Whois-RWS API, via the CIDRdataSet class. It
also annunciates error messages.
For more information about re-using the source code in this product, see
the other project .php files.
License:
The license under which this software product is released is GPLv2.
Disclaimer:
Some of the source code used in this product may have been re-used from
other sources.
None of the source code in this product, original or derived, has been
surveyed for vulnerabilities to potential security risks.
Use at your own risk, author is not liable for damages, product is not
warranted to be useful for anything, copyrights held by their respective
owners.
*/
class OutputWorker
{
private function set_snippet ($snippet_string) {
echo '<span style="font-family:courier new,courier,monospace"><strong><span style="color:#002222"><span style="background-color:#FFFF66">'
. $snippet_string
. '</span></span></strong></span>';
}
public function set_error_msg ($err_msg, $local_home_page) {
$this->display_instructions_form ($local_home_page);
echo '<span style="font-family:courier new,courier,monospace"><strong><span style="color:#002222"><span style="background-color:#FF8822">'
. $err_msg
. '</span></span></strong></span>';
}
// display instructions and IP address input form
private function display_instructions_form ($local_home_page) {
echo '<h1>'
. "Deny From IP"
. "</h1>"
. '<h5>'
. "Project: ip-addr-to-arin-cidr, rev 2015.0309.0110"
. "</h5>"
. '<p>'
. "This is a simple web host administrator's tool. It's only function is to provide
information. It was developed to assist a web host administrator with the job
of blacklisting unauthorized users. One way of disallowing use by
unauthorized users is by blacklisting via the web host's
.htaccess file."
. "</p>"
. '<p>'
. "This tool neither writes nor modifies files on the client side,
nor on the server side. If you wish to use the code
snippet displayed below to modify your .htaccess file, you may copy-and-paste it
into your .htaccess file manually. Note that only the snippet highlighted
in yellow is .htaccess file safe."
. "</p>"
. '<p>'
. "<small>"
. '<span style="background-color:#FF0000"> '
. '<span style="color:#FFFFFF">'
. "Warning: "
. "</span>"
. "</span> "
. "<strong>"
. "Do not edit your .htaccess file unless you are well advised of the risks."
. "</strong>"
. "</small>"
. '<div style="background: #f0f0ff; border: 1px solid #ccc; padding: 5px 10px; width: 50%;">'
. '<p style="text-align: left;">'
. "<small>"
. 'View, download, or fork the "Deny From IP" PHP source code on GitHub at: <br>'
. '<a href="https://github.com/addiscent/ip-addr-to-arin-cidr">'
. "https://github.com/addiscent/ip-addr-to-arin-cidr</a>"
. "</small>"
. "</p>"
. "</div>"
. "<h2>"
. "User Instructions"
. "</h2>"
. '<p>'
. "Submit an IP address, e.g., 127.0.0.1, in the edit box below.
A network CIDR will be displayed, placed in a code snippet
format suitable for copy-and-paste into an .htaccess file."
. "</p>"
. '<form action='
. $local_home_page
. ' method="post">'
. '<p>'
. 'IP Address: <input type="text" name="ipaddr"> <input type="submit">'
. "</p>"
. "</form>";
}
// display CIDR data set
public function set_cidr_data ($CIDRdataSet = NULL, $local_home_page) {
$this->display_instructions_form ($local_home_page);
if ($CIDRdataSet == NULL) {
return;
}
// list company name
$org_name = NULL;
$org_handle = NULL;
$CIDRdataSet->get_company_info ($org_name, $org_handle);
if ($org_name != "") {
echo "<p>"
. "Organization name: "
. $org_name
. "<br/>"
. "Organization handle: "
. $org_handle
. "</p>";
}
// list customer name
$customer_name = NULL;
$customer_handle = NULL;
$CIDRdataSet->get_customer_info ($customer_name, $customer_handle);
if ($customer_name != "") {
echo "<p>"
. "Customer name: "
. $customer_name
. "<br/>"
. "Customer handle: "
. $customer_handle
. "</p>";
}
echo "<p>
<em>
<small>
Note the date and time is GMT/UTC, it is not adjusted for your time zone.</small>
</small>
</em>
</p>";
// construct a courtesy "deny from" code snippet block for user to
// manually copy/paste into .htaccess file.
$date_time = $CIDRdataSet->get_cidr_date_time();
$this->set_snippet ("# Date and time of this entry: $date_time");
echo "<br/>";
$ip_addr = $CIDRdataSet->get_ipaddr ();
$this->set_snippet ("# deny from $ip_addr");
echo "<br/>";
$cidr_netblocks = $CIDRdataSet->get_cidr_spec_nbsize();
foreach ($cidr_netblocks as $net_tuple) {
$cidr_spec = $net_tuple["CIDR_SPEC"];
$this->set_snippet ("# " . $cidr_spec . " netblock size: " . $net_tuple["NETBLOCK_SIZE"]);
echo "<br/>";
}
foreach ($cidr_netblocks as $net_tuple) {
// construct a CDIR IP block spec by using the starting address and the cidrlength.
$cidr_spec = $net_tuple["CIDR_SPEC"];
$this->set_snippet ("deny from " . $cidr_spec);
echo "<br/>";
}
}
}
?>