fma.pl
Copying Source is Forbidden
293 lines of code
1
#!/usr/local/bin/perl
2
3
#/
4
# this script will only return 1 or 0;
5
# 1 when post succeeds
6
# and 0 when post fails
7
#/
8
9
# must have's!
10
use strict;
11
use warnings;
12
use CGI::Carp qw(fatalsToBrowser);
13
use DBI;
14
use URI::Escape;
15
16
use lib "/var/www/html/Pm";
17
18
use Bc_chef qw(cookie_get);
19
use Bc_misc qw(get_param referrer);
20
use Bc_sql qw(
21
get_constant
22
sql_execute
23
user_exists
24
$QUERY_PAGE
25
$QUERY_UID
26
$LOGGEDIN
27
fma_exists
28
add_points
29
30
$DB
31
);
32
33
use Html qw(header pre_html_header);
34
use User qw(isUserSubscriber $USER_DATA);
35
use Redir qw(error_redir notice_redir);
36
use Security qw(banned);
37
38
if (not $DB) { die("internal server error: db connection failed"); }
39
40
if (not $LOGGEDIN or not isUserSubscriber()) {
41
print error_redir("/?$QUERY_PAGE=" . get_constant("PAY_PAGE"), "Premium Membership Required");
42
exit 1;
43
}
44
45
my $rv = 0;
46
my $op = get_param("i");
47
# when $op eq 1 = ignored (default)
48
# when $op eq 2 = reciprocated
49
# when $op eq 3 = retracted
50
# $op, of course, is ignored when creating a new FMA
51
# and, years later, i'm left wondering what op stands for lol
52
# operation?
53
54
my $to_uid = get_param($QUERY_UID);
55
my $redir = get_param("r");
56
57
my $DBPL = 0;
58
my $DEBUG = 0;
59
60
if (get_param('debug')) { $DEBUG = 1; }
61
if (get_param('dbpl')) { $DBPL = 1; }
62
63
my $refurl = referrer();
64
if ($DBPL) { $refurl .= "#subtests"; }
65
66
my $output = "";
67
68
if ($DEBUG) {
69
$output = pre_html_header() . header("fma.pl", "", "", "", "fuck me alert listener", "");
70
$output .= "DEBUG MODE ENABLED<hr>\n";
71
} else {
72
if (not $redir) { $output .= pre_html_header(); }
73
}
74
75
####################
76
if ($op eq 1) {
77
# ignore fma
78
if ($DEBUG) { $output .= "ignore fma<br>\n"; }
79
# check if bobby sent an FMA
80
if (fma_exists($to_uid, $LOGGEDIN)) {
81
my $sql = "update fuck_alerts set ignored='2' where to_UID=" . $DB->quote($LOGGEDIN) . " and from_UID=" . $DB->quote($to_uid);
82
$sql .= " and reciprocated='1' and ignored='1'";
83
if ($DEBUG) { $output .= "sql: <i>$sql</i><br>\n"; }
84
85
if (sql_execute($sql, "fma.pl")) {
86
# fma ignored
87
if ($DEBUG) {
88
$output .= "fma ignored<br>\n";
89
} else {
90
if ($redir)
91
{ $output = notice_redir($refurl, "fma ignored"); } else
92
{ $output .= 1; }
93
}
94
} else {
95
# fma not ignored
96
if ($DEBUG) {
97
$output .= "fma not ignored<br>\n";
98
} else {
99
if ($redir)
100
{ $output = error_redir($refurl, "fma not ignored"); } else
101
{ $output .= 2; }
102
}
103
}
104
} else {
105
# fma doesn't exist
106
if ($DEBUG) {
107
$output .= "fma not found<br>\n";
108
} else {
109
if ($redir)
110
{ $output = error_redir($refurl, "fma not found"); } else
111
{ $output .= 3; }
112
}
113
}
114
115
####################
116
} elsif ($op eq 2) {
117
# reciprocate fma
118
# origin is from jamroll ($to_uid)
119
# now, we gotta do it back to jamroll.
120
if ($DEBUG) { $output .= "reciprocate fma<br>\n"; }
121
# check if $LOGGEDIN sent an FMA
122
if (fma_exists($to_uid, $LOGGEDIN)) {
123
# yes, $LOGGEDIN sent an FMA
124
# update the record
125
my $sql = "update fuck_alerts set reciprocated='2'";
126
$sql .= " where to_UID=" . $DB->quote($LOGGEDIN);
127
$sql .= " and from_UID=" . $DB->quote($to_uid); # from jamroll
128
$sql .= " and reciprocated='1' and ignored='1'";
129
if ($DEBUG) { $output .= "sql: <i>$sql</i><br>\n"; }
130
if (sql_execute($sql, "fma.pl")) {
131
# that sets reciprocated set to 2
132
# now, check if we haven't already sent an FMA to jamroll
133
if (not fma_exists($LOGGEDIN, $to_uid)) {
134
# okay, send an FMA to jamroll now
135
$sql = "insert into fuck_alerts (to_UID, from_UID, reciprocated, ignored) values (";
136
$sql .= $DB->quote($to_uid) . ", ";
137
$sql .= $DB->quote($LOGGEDIN) . ", ";
138
$sql .= "'1', ";
139
$sql .= "'1'";
140
$sql .= ")";
141
if ($DEBUG) { $output .= "sql: <i>$sql</i><br>\n"; }
142
if (sql_execute($sql, "fma.pl")) {
143
if ($DEBUG) {
144
$output .= "the favour has been returned<br>\n";
145
} else {
146
if ($redir)
147
{ $output = notice_redir($refurl, "you returned the favour!"); } else
148
{ $output .= 4; }
149
}
150
} else {
151
if ($DEBUG) {
152
$output .= "failed to return the favour<br>\n";
153
} else {
154
if ($redir)
155
{ $output = error_redir($refurl, "failed to return the favour"); } else
156
{ $output .= 5; }
157
}
158
}
159
}
160
} else {
161
# failed to update FMA
162
if ($DEBUG) {
163
$output .= "original fma no longer exists<br>\n";
164
} else {
165
if ($redir)
166
{ $output = error_redir($refurl, "original fma no longer exists"); } else
167
{ $output .= 6; }
168
}
169
}
170
} else {
171
# member didn't send an FMA
172
if ($DEBUG) {
173
$output .= "originating fma not found<br>\n";
174
} else {
175
if ($redir)
176
{ $output = error_redir($refurl, "originating fma not found"); } else
177
{ $output .= 7; }
178
}
179
}
180
181
####################
182
} elsif ($op eq 3) {
183
# retract existing fma
184
if ($DEBUG) { $output .= "retract fma<br>\n"; }
185
if (fma_exists($LOGGEDIN, $to_uid)) {
186
my $sql = "delete from fuck_alerts where" .
187
" from_UID=" . $DB->quote($LOGGEDIN) .
188
" and" .
189
" to_UID=" . $DB->quote($to_uid);
190
if (sql_execute($sql, "fma.pl")) {
191
if ($DEBUG) {
192
$output .= "originating fma was retracted!<br>\n";
193
} else {
194
if ($redir)
195
{ $output = notice_redir($refurl, "originating fma retracted!"); } else
196
{ $output .= 8; }
197
}
198
} else {
199
if ($DEBUG) {
200
$output .= "failed to retract originating fma!<br>\n";
201
} else {
202
if ($redir)
203
{ $output = error_redir($refurl, "failed to retract originating fma!"); } else
204
{ $output .= 9; }
205
}
206
}
207
} else {
208
if ($DEBUG) {
209
$output .= "originating fma not found!<br>\n";
210
} else {
211
if ($redir)
212
{ $output = error_redir($refurl, "originating fma not found!"); } else
213
{ $output .= 10; }
214
}
215
}
216
217
####################
218
} else {
219
# new fma
220
if ($DEBUG) { $output .= "new fma<br>\n"; }
221
# check for existence!
222
if (not fma_exists($LOGGEDIN, $to_uid)) {
223
my $sql = "insert into fuck_alerts (to_UID, from_UID, reciprocated, ignored) values (";
224
$sql .= $DB->quote($to_uid) . ", ";
225
$sql .= $DB->quote($LOGGEDIN) . ", ";
226
$sql .= "'1', ";
227
$sql .= "'1'";
228
$sql .= ")";
229
if ($DEBUG) { $output .= "sql: <i>$sql</i><br>\n"; }
230
231
if (sql_execute($sql, "fma.pl")) {
232
# fma created
233
if ($DEBUG) { $output .= "fma created<br>\n"; }
234
235
# what if, by chance, jamroll has sent an FMA
236
# then we gotta change its reciprocated to '2'
237
if (fma_exists($to_uid, $LOGGEDIN)) {
238
my $sql = "update fuck_alerts set reciprocated='2'";
239
$sql .= " where to_UID=" . $DB->quote($LOGGEDIN);
240
$sql .= " and from_UID=" . $DB->quote($to_uid); # from jamroll
241
$sql .= " and reciprocated='1' and ignored='1'";
242
if ($DEBUG) { $output .= "sql: <i>$sql</i><br>\n"; }
243
if (sql_execute($sql, "fma.pl")) {
244
if ($DEBUG) {
245
$output .= "fma reciprocated<br>\n";
246
} else {
247
if ($redir)
248
{ $output = notice_redir($refurl, "fma reciprocated"); } else
249
{ $output .= 11; }
250
}
251
} else {
252
if ($DEBUG) {
253
$output .= "fma not reciprocated<br>\n";
254
} else {
255
if ($redir)
256
{ $output = notice_redir($refurl, "failed to reciprocate fma"); } else
257
{ $output .= 12; }
258
}
259
}
260
} else {
261
if ($DEBUG) {
262
$output .= "fma sent<br>\n";
263
} else {
264
if ($redir)
265
{ $output = notice_redir($refurl, "fma sent"); } else
266
{ $output .= 13; }
267
}
268
}
269
} else {
270
# failed to create fma
271
if ($DEBUG) {
272
$output .= "fma not created<br>\n";
273
} else {
274
if ($redir)
275
{ $output = error_redir($refurl, "failed to send fma"); } else
276
{ $output .= 14; }
277
}
278
}
279
} else {
280
# fma already exists!
281
if ($DEBUG) {
282
$output .= "fma already exists<br>\n";
283
} else {
284
if ($redir)
285
{ $output = error_redir($refurl, "they already got an fma from you"); } else
286
{ $output .= 15; }
287
}
288
}
289
}
290
291
print $output;
292
293
exit 1;