-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
211 lines (189 loc) · 5.89 KB
/
post.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
include_once("config.php");
@include_once("header.inc");
$file_complete = file($data_file);
$full_output = "";
$template = file($post_template);
$can_post = 1;
$repost = 0;
function getIP()
{
$ip;
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "UNKNOWN";
return $ip;
}
function valid_email($str)
{
$str = strtolower($str);
if(ereg("^([^[:space:]]+)@(.+)\.(ad|ae|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gov|gd|ge|gf|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nato|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$",$str))
{
return 1;
}
else
{
return 0;
}
}
// Check to make sure they have all the proper fields. If not? Don't let them post! Duh :P
$fields = explode("|", $custom_fields);
foreach($fields as $cfield)
{
$required = explode("|", $required_fields);
foreach($required as $rfield)
{
if($cfield == $rfield)
{
$tfield = $_POST[$rfield];
if(empty($tfield))
{
echo "<b>A REQUIRED FIELD ($rfield) IS EMPTY!</b><br />";
$can_post = 0;
}
if($validate_email == 1)
{
$temp_email = $_POST['email'];
if(($rfield == "email") && !valid_email($temp_email))
{
echo "<b>You have entered an invalid email address ($temp_email). Please fix this before continueing.</b><br />";
$can_post = 0;
}
}
}
}
}
// This little hack makes the searches case-insensitive for the bad word filter.
$badwords = explode("|", $filtered_words);
$goodwords = explode("|", $filtered_replace);
for($curword = 0; $curword < 4; $curword++)
{
$badwords[$curword] = "/$badwords[$curword]/i";
}
if((strtolower($name) == strtolower($admin_name)) && ($password != $admin_password))
{
echo "<b>You have entered and invalid password for that user. Please fix this before continueing.</b><br />";
$can_post = 0;
}
if($can_post == 1)
{
$file_complete = file($data_file);
foreach($file_complete as $entry)
{
$entry = trim($entry);
// Check for the end of an entry
if($entry == "#ENDENTRY")
{
$in_entry = 0;
$gb_count += 1;
if($found == 1)
$repost = 1;
}
if($in_entry == 1)
{
$pos = strpos($entry, " ");
if($pos != false)
{
$key = substr($entry, 0, $pos);
$primkey = substr($key, 3, strlen($key));
$data = substr($entry, $pos);
$data = substr($data, 1);
$newdata = $_POST[$primkey];
trim($newdata);
trim($data);
if((strcmp(strtolower($newdata), strtolower($data)) == 0) && (strcmp($primkey, "timestamp") !== 0) && !empty($data) && !empty($newdata) && ($found < 2))
{
$found = 1;
}
else if((strcmp($primkey, "timestamp") == 0) || empty($data) || empty($newdata))
{
}
else
{
$found = 2;
}
}
}
// Check for the start of an entry
if($entry == "#ENTRY")
{
$output = $orig_output;
$in_entry = 1;
$found = 0;
}
}
if($repost == 1)
{
print("Reposting not allowed.<br />\n");
}
else
{
foreach($template as $myline)
{
$full_output .= $myline;
}
$full_output = str_replace("{field_gb_name}", $name, $full_output);
print("$full_output\n");
$ip = getIP();
if(is_writeable($data_file))
{
$handle = fopen($data_file, "a");
if(!$handle)
{
print("Cannot open file ($data_file) for append.<br />\n");
}
else
{
flock($handle, LOCK_EX);
fwrite($handle, "#ENTRY\n");
$time = time();
fwrite($handle, "gb_timestamp $time\n");
$fields = explode("|", $custom_fields);
foreach($fields as $field)
{
// Here is the meat and potatos of the writing to the file of this script!
if($field != "timestamp")
{
// First step, get rid of ANY html we don't allow!
$temp_storage = strip_tags($_POST[$field],$allowed_html);
// Trim off any extra spaces, cr/lf, etc...
$temp_storage = trim($temp_storage);
$temp_storage = str_replace("\\\"", """, $temp_storage);
$temp_storage = str_replace("\\'", "'", $temp_storage);
$temp_storage = str_replace(" ", "", $temp_storage);
$temp_storage = str_replace("<", "<", $temp_storage);
$temp_storage = str_replace(">", ">", $temp_storage);
$temp_storage = str_replace("\n", "<br />", $temp_storage);
$temp_storage = str_replace("\r", "", $temp_storage);
// Time to check for bad words.... and replace if found.
ksort($badwords);
ksort($goodwords);
$temp_storage = preg_replace($badwords, $goodwords, $temp_storage);
// WRITE IT!
fwrite($handle, "gb_$field $temp_storage\n");
}
}
fwrite($handle, "gb_loggedip $ip\n");
fwrite($handle, "gb_admincomment \n");
fwrite($handle, "#ENDENTRY\n\n");
flock($handle, LOCK_UN);
fclose($handle);
}
}
else
{
print("The file ($data_file) is not writeable.<br />\n");
}
}
}
else
{
print("You are missing some required fields, please fix those before posting.\n");
}
@include_once("footer.inc");
?>