Sharedwww / cgi-bin / openwebmail / userstat.plOpen in CoCalc
Author: William A. Stein
1
#!/usr/bin/perl
2
#
3
# userstat.pl - a mail status javascript generator for static html page
4
#
5
# 2003/10/08 tung.AT.turtle.ee.ncku.edu.tw
6
#
7
# This script is designed to be used by static html pages to
8
# display openwebmail user mail/calendar status dynamically.
9
# All you need to do is to include the following block in html source code.
10
#
11
# <table cellspacing=0 cellpadding=0><tr><td>
12
# <script language="JavaScript"
13
# src="http://you_server_domainname/cgi-bin/openwebmail/userstat.pl">
14
# </script>
15
# </td></tr></table>
16
#
17
use strict;
18
use CGI qw(-private_tempfiles :standard);
19
20
# where to find the openwebmail scripts
21
my $ow_cgidir="/usr/local/www/cgi-bin/openwebmail";
22
my $ow_cgiurl="/cgi-bin/openwebmail";
23
24
# play newmail sound if cgi param playsound==1
25
my $soundurl="/openwebmail/sounds/YouGotMail.English.wav";
26
27
# status text to be displayed
28
my %text = (
29
has_newmail => "_USER_ has 1 new mail",
30
has_newmails => "_USER_ has _N_ new mails",
31
has_mail => "_USER_ has 1 mail",
32
has_mails => "_USER_ has _N_ mails",
33
has_newevent => "_USER_ has new event",
34
has_event => "_USER_ has event",
35
user_calendar => "_USER_'s calendar"
36
);
37
38
########## No configuration required from here ###################
39
40
if (!defined($ENV{'GATEWAY_INTERFACE'})) { # cmd mode
41
print qq|\nThis script is designed to be used by static html pages to\n|.
42
qq|display openwebmail user mail/calendar status dynamically.\n|.
43
qq|All you need to do is to include the following block in html source code.\n\n|.
44
qq|<table cellspacing=0 cellpadding=0><tr><td>\n|.
45
qq|<script language="JavaScript"\n|.
46
qq|src="http://you_server_domainname/cgi-bin/openwebmail/userstat.pl">\n|.
47
qq|</script>\n|.
48
qq|\nor\n\n|.
49
qq|<table cellspacing=0 cellpadding=0><tr><td>\n|.
50
qq|<script language="JavaScript"\n|.
51
qq|src="http://you_server_domainname/cgi-bin/openwebmail/userstat.pl?logionname=someuser">\n|.
52
qq|</script>\n|.
53
qq|</td></tr></table>\n\n|;
54
exit 1;
55
}
56
57
my $user=param('loginname')||cookie('openwebmail-loginname')||'';
58
my $status='';
59
my $playsound = param('playsound')||'';
60
my $html=qq|<a href="_URL_" target="_blank" style="text-decoration: none">|.
61
qq|<font color="_COLOR_">_TEXT_</font></a>|;
62
63
$user=~s/[\/\"\'\`\|\<\>\\\(\)\[\]\{\}\$\s;&]//g; # filter out dangerous chars
64
if ($user ne '' && length($user)<80) {
65
$status=`$ow_cgidir/openwebmail-tool.pl -m -e $user`;
66
}
67
if ($user eq '' or
68
$status eq '' or
69
$status =~ /doesn't exist/) {
70
sleep 8;
71
print qq|Pragma: no-cache\n|.
72
qq|Cache-control: no-cache,no-store\n|.
73
qq|Content-Type: application/x-javascript\n\n|.
74
qq|//\n|;
75
exit 1;
76
}
77
78
if ($status =~ /has no mail/) {
79
$html=~s|_URL_|$ow_cgiurl/openwebmail.pl?action=calmonth|;
80
if ($status =~ /has new event/) {
81
$html=~s|_COLOR_|#cc0000|;
82
$html=~s|_TEXT_|$text{'has_newevent'}|;
83
} elsif ($status =~ /has event/) {
84
$html=~s|_COLOR_|#000000|;
85
$html=~s|_TEXT_|$text{'has_event'}|;
86
} else {
87
$html=~s|_COLOR_|#000000|;
88
$html=~s|_TEXT_|$text{'user_calendar'}|;
89
}
90
} else {
91
$html=~s|_URL_|$ow_cgiurl/openwebmail.pl|;
92
if ($status =~ /has (\d+) new mail/) {
93
my $n=$1;
94
if ($n>1) {
95
$html=~s|_TEXT_|$text{'has_newmails'}|;
96
$html=~s|_N_|$n|;
97
} else {
98
$html=~s|_TEXT_|$text{'has_newmail'}|;
99
}
100
$html=~s|_COLOR_|#cc0000|;
101
if ($playsound) {
102
$html.=qq|<embed src="$soundurl" autostart=true hidden=true>|;
103
}
104
} elsif ($status =~ /has (\d+) mail/) {
105
my $n=$1;
106
if ($n>1) {
107
$html=~s|_TEXT_|$text{'has_mails'}|;
108
$html=~s|_N_|$n|;
109
} else {
110
$html=~s|_TEXT_|$text{'has_mail'}|;
111
}
112
$html=~s|_COLOR_|#000000|;
113
}
114
}
115
$html=~s|_TEXT_|Open WebMail|;
116
$html=~s/_USER_/$user/g;
117
$html=~s|_COLOR_|#000000|;
118
$html=~s/'/\\'/g;
119
120
print qq|Pragma: no-cache\n|.
121
qq|Cache-control: no-cache,no-store\n|.
122
qq|Content-Type: application/x-javascript\n\n|.
123
qq|document.write('$html');\n|;
124
125
exit 0;
126