sendemail.pl
Copying Source is Forbidden
141 lines of code
1
#!/usr/local/bin/perl
2
3
($<,$>) = (getpwnam('nobody'), getpwnam('nobody')) or die $!;
4
5
binmode(STDIN, ":utf8");
6
binmode(STDOUT, ":utf8");
7
8
# must have's!
9
use strict;
10
use warnings;
11
use CGI::Carp qw(fatalsToBrowser);
12
use DBI;
13
use URI::Escape;
14
15
use lib "/var/www/html/Pm";
16
17
use Html qw(pre_html_header header);
18
use Bc_chef qw(cookie_get);
19
use Bc_misc qw(get_param referrer get_params_asHash);
20
use Bc_sql qw(sql_execute
21
get_constant
22
user_exists
23
$QUERY_PAGE
24
$QUERY_UID
25
$LOGGEDIN
26
27
$DB
28
);
29
use Redir qw(notice_redir error_redir);
30
use User qw(isUserModerator
31
$USER_DATA
32
get_user_stat
33
isUserAdmin
34
get_user_stats);
35
use Security qw(banned); Security::count_hits();
36
37
my $DEBUG = 0;
38
my $ACTUALLY_SEND = 1;
39
40
my $output;
41
42
if ((not user_exists($LOGGEDIN) or banned($LOGGEDIN)) and not isUserModerator($LOGGEDIN)) {
43
my $msg = "Access Denied";
44
if ($DEBUG) { $msg .= " (sendemail.pl)"; }
45
$output = error_redir("/", $msg);
46
47
} else {
48
49
############################################################
50
51
### YOUR CONTENT HERE
52
$output = pre_html_header();
53
$output .= header("send email to user", "?nogrid=1&nobg_img=1");
54
55
# we need the UID of the user we are messaging
56
my %params = get_params_asHash();
57
58
if (user_exists($params{$QUERY_UID})) {
59
if (user_exists($params{$QUERY_UID})) {
60
if ($params{send}) {
61
my %stats = get_user_stats($params{$QUERY_UID});
62
my $to_email = $stats{email};
63
my $to_name = $stats{nickname};
64
my $subject = $params{subject};
65
$subject =~ s/\"/\\"/g;
66
my $message = $params{message};
67
$message =~ s/\"/\\"/g;
68
my $from = "admin<admin\@night-stand.ca>";
69
my $send_command = "echo \"$message\" | mail -s \"$subject\" -r \"$from\" $to_email";
70
71
if ($DEBUG) {
72
$output .= "to uid: <b>$params{$QUERY_UID}</b><br>\n";
73
$output .= "to email: <b>$to_email</b><br>\n";
74
$output .= "to name: <b>$to_name</b><br>\n";
75
$output .= "from: <input value=\"$from\"></b><br>\n";
76
$output .= "subject: <b>$subject</b><br>\n";
77
$output .= "message: <b>$message</b><br>\n";
78
$output .= "send message command: <b>$send_command</b><br>\n";
79
}
80
81
if ($ACTUALLY_SEND) {
82
`$send_command`;
83
if ($DEBUG) {
84
$output .= "message SHOULD have been sent to $to_email<br>\n";
85
} else {
86
}
87
} else {
88
if ($DEBUG) {
89
$output .= "send email skipped by request<br>\n";
90
} else {
91
}
92
}
93
} else {
94
# present message entry form
95
my %stats = get_user_stats($params{$QUERY_UID});
96
97
if ($DEBUG) {
98
}
99
100
$output .= "<form style=\"height: 100%;\">\n";
101
$output .= " <table border=0 cellpadding=0 cellspacing=0 height=100% width=100%><tr><td colspan=3 height=1>\n";
102
$output .= " Send message to: <b>$stats{nickname}</b>";
103
if (isUserAdmin()) { $output .= " <$stats{email}>"; }
104
$output .= "\n";
105
$output .= " </td></tr><tr><td class=spacery colspan=3>\n";
106
$output .= " </td></tr><tr><td colspan=3 valign=top height=1>\n";
107
$output .= " <input type=\"hidden\" name=\"$QUERY_UID\" value=\"$params{$QUERY_UID}\">\n";
108
$output .= " <table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1>Subject</td><td class=spacerx></td><td><input type=\"text\" name=\"subject\" style=\"width: 100%;\"></td></tr></table>\n";
109
$output .= " </td></tr><tr><td class=spacery colspan=3>\n";
110
$output .= " </td></tr><tr><td colspan=3 valign=top height=278>\n";
111
$output .= " <textarea name=\"message\" style=\"height: 100%; width: 100%; resize: none;\"></textarea><br>\n";
112
$output .= " </td></tr><tr><td class=spacery colspan=3>\n";
113
$output .= " </td></tr><tr><td height=1>\n";
114
$output .= " <button class=\"cancel\" onclick=\"window.history.back();\" type=button>Cancel</button>\n";
115
$output .= " </td><td align=center height=1>\n";
116
$output .= " <button class=yellow-button onclick=\"//document.location.reload();\" title='Clear' type=reset>Clear</button>\n";
117
$output .= " </td><td align=right height=1>\n";
118
$output .= " <button class=\"save\" name=\"send\" value=\"1\">Send</button>\n";
119
$output .= " </td></tr></table>\n";
120
$output .= "</form>\n";
121
}
122
} else {
123
if ($DEBUG) {
124
$output .= "no such uid: <b>$params{$QUERY_UID}</b><br>\n";
125
} else {
126
}
127
}
128
} else {
129
# no such uid
130
if ($DEBUG) {
131
$output .= "no such uid: $params{$QUERY_UID}<br>\n";
132
} else {
133
}
134
}
135
136
############################################################
137
}
138
139
print $output;
140
141
exit 1;