home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
webmail1.zip
/
webmail2.cmd
< prev
Wrap
OS/2 REXX Batch file
|
2000-02-18
|
13KB
|
392 lines
/* WebMail/2 v1.0 by sehh <sehh@altered.com> */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
call RxFuncAdd 'SockLoadFuncs','RxSock','SockLoadFuncs'
call SockLoadFuncs
/*
call RxFuncAdd 'MD5LoadFuncs','rxmd5','MD5LoadFuncs'
call MD5LoadFuncs
*/
Globals.!myinfo = "WebMail/2 v1.0 beta 1"
tmp = value("QUERY_STRING",,'os2environment')
parse value tmp with Globals.!stat1 "&" Globals.!user "&" Globals.!pazz "&" Globals.!stat2
Globals.!mail.0 = 0
Globals.!totalmail = 0
Globals.!myself = value("SCRIPT_NAME",,'os2environment')
if pos(Globals.!myself,value("HTTP_REFERER",,'os2environment'))<1 then call UserLoginScreen
else if pos("login=",Globals.!stat1)>0 & Globals.!stat2="" then call CheckLogon("checkemail")
else if pos("read",Globals.!stat1)>0 & Globals.!stat2<>"" then call CheckLogon("read")
else if pos("delete",Globals.!stat1)>0 & Globals.!stat2<>"" then call CheckLogon("delete")
else call UserLoginScreen
return
CheckLogon: procedure expose Globals.
ConfigFile = value("ETC",,'os2environment')||"\webmail2.cfg"
i = stream(ConfigFile, 'c', 'open')
if i == "" then call CGIErrorScreen("Configuration error")
i=0
do while lines(ConfigFile)>0
tmp = linein(ConfigFile)
if substr(tmp,1,1)<>"#" & tmp<>"" & tmp<>'0d0a'x then do
i=i+1
Globals.!data.i=tmp
end
end
call stream ConfigFile, 'c', 'close'
Globals.!data.0=i
Globals.!user = substr(Globals.!user,3,length(Globals.!user)-2)
Globals.!pazz = substr(Globals.!pazz,3,length(Globals.!pazz)-2)
do i=1 to Globals.!data.0
parse value Globals.!data.i with Globals.!serv ":" Globals.!port ":" username ":" password
if Globals.!user = username & Globals.!pazz = password then do
if ARG(1) = "checkemail" then call CheckEmail
else if ARG(1) = "read" then call ReceiveEmail
else if ARG(1) = "delete" then call DeleteEmail
end
end
call SysSleep 6
call ServerErrorScreen("Login refused")
return
ReceiveEmail: procedure expose Globals.
rc = SockGetHostByName(Globals.!serv,"host.!")
if (rc = 0) then call CGIErrorScreen("Error in hostname/ip resolv")
server = host.!addr;
port = Globals.!port
socket = SockSocket("AF_INET","SOCK_STREAM",0)
if (socket = -1) then call CGIErrorScreen("Error open socket")
server.!family = "AF_INET"
server.!port = port
server.!addr = server
rc = SockConnect(socket,"server.!")
if (rc = -1) then call CGIErrorScreen("Error on Socket/Port Connection")
call ReceiveData
if substr(newData,1,3)<>"+OK" then call ServerErrorScreen("Server refused connection")
call SendData("USER "||Globals.!user||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server refused user login")
end
call SendData("PASS "||Globals.!pazz||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Failed login due to password error")
end
call SendData("RETR "||Globals.!stat2||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server couldn't retrieve email")
end
call ReceiveData
call SendData("QUIT"||'0d0a'x)
rc = SockSoClose(socket)
if (rc = -1) then call CGIErrorScreen("Error on SockSoClose")
call ReadEmailScreen(newData)
return
DeleteEmail: procedure expose Globals.
rc = SockGetHostByName(Globals.!serv,"host.!")
if (rc = 0) then call CGIErrorScreen("Error in hostname/ip resolv")
server = host.!addr;
port = Globals.!port
socket = SockSocket("AF_INET","SOCK_STREAM",0)
if (socket = -1) then call CGIErrorScreen("Error open socket")
server.!family = "AF_INET"
server.!port = port
server.!addr = server
rc = SockConnect(socket,"server.!")
if (rc = -1) then call CGIErrorScreen("Error on Socket/Port Connection")
call ReceiveData
if substr(newData,1,3)<>"+OK" then call ServerErrorScreen("Server refused connection")
call SendData("USER "||Globals.!user||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server refused user login")
end
call SendData("PASS "||Globals.!pazz||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Failed login due to password error")
end
if pos("all",Globals.!stat2)>0 then do
call SendData("STAT"||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Email server couldn't get status")
end
parse value newData with . Globals.!totalmail .
if datatype(Globals.!totalmail,"N")<>1 then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server returned wrong value")
end
do i=1 to Globals.!totalmail
call SendData("DELE "||i||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server couldn't delete email<br> or email already deleted")
end
end
end; else do
call SendData("DELE "||Globals.!stat2||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server couldn't delete email<br> or email already deleted")
end
end
call SendData("QUIT"||'0d0a'x)
rc = SockSoClose(socket)
if (rc = -1) then call CGIErrorScreen("Error on SockSoClose")
call CheckEmail
return
CheckEmail: procedure expose Globals.
rc = SockGetHostByName(Globals.!serv,"host.!")
if (rc = 0) then call CGIErrorScreen("Error in hostname/ip resolv")
server = host.!addr;
port = Globals.!port
socket = SockSocket("AF_INET","SOCK_STREAM",0)
if (socket = -1) then call CGIErrorScreen("Error open socket")
server.!family = "AF_INET"
server.!port = port
server.!addr = server
rc = SockConnect(socket,"server.!")
if (rc = -1) then call CGIErrorScreen("Error on Socket/Port Connection"||port)
call ReceiveData
if substr(newData,1,3)<>"+OK" then call ServerErrorScreen("Server refused connection")
call SendData("USER "||Globals.!user||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server refused user login")
end
call SendData("PASS "||Globals.!pazz||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Failed login due to password error")
end
call SendData("STAT"||'0d0a'x)
call ReceiveData
if substr(newData,1,3)<>"+OK" then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Email server couldn't get status")
end
parse value newData with . Globals.!totalmail .
if datatype(Globals.!totalmail,"N")<>1 then do
call SendData("QUIT"||'0d0a'x)
call ServerErrorScreen("Server returned wrong value")
end
do i=1 to Globals.!totalmail
call SendData("TOP "||i||" 1"||'0d0a'x)
call ReceiveData
if substr(newData,1,3)="+OK" then do
call ReceiveData
Globals.!mail.i = newData
end
end
Globals.!mail.0 = i
ListMail.0 = 0
do i=1 to Globals.!totalmail
tmp1 = pos("From:",Globals.!mail.i)+6
tmp2 = pos('0d0a'x,Globals.!mail.i,tmp1)
tmp3 = space(substr(Globals.!mail.i,tmp1,tmp2-tmp1))
ListMail.i.!From = space(substr(tmp3,1,pos("<",tmp3)-1)||"("||substr(tmp3,pos("<",tmp3)+1,(lastpos(">",tmp3))-(pos("<",tmp3)+1))||")")
tmp1 = pos("Subject:",Globals.!mail.i)+9
tmp2 = pos('0d0a'x,Globals.!mail.i,tmp1)
ListMail.i.!Subject = space(substr(Globals.!mail.i,tmp1,tmp2-tmp1))
tmp1 = pos("Date:",Globals.!mail.i)+6
tmp2 = pos('0d0a'x,Globals.!mail.i,tmp1)
ListMail.i.!Date = space(substr(Globals.!mail.i,tmp1,16))
end
call SendData("QUIT"||'0d0a'x)
rc = SockSoClose(socket)
if (rc = -1) then call CGIErrorScreen("Error on SockSoClose")
call CheckScreen
return
SendData: procedure expose socket
rc = SockSend(socket,ARG(1))
if (rc = -1) then call CGIErrorScreen("Error on SockSend")
return
ReceiveData: procedure expose socket newData
length = ARG(1)
if length = "" then length = 1024
rc = SockRecv(socket,"newData",length)
if (rc = -1) then call CGIErrorScreen("Error on SockRecv")
return
UserLoginScreen: procedure expose Globals.
say "Content-type: text/html"
say ""
say "<html>"
say "<title> "||Globals.!myinfo||" created by sehh </title>"
say "<body text=""#ffffff"" bgcolor=""#000000"" link=""#00BFFF"" vlink=""#00BFFF"">"
say "<center>"
say "<br><p><br>"
say "<b>Welcome to WebMail/2</b><br>"
say "<br><p><br>"
say "<pre>User Login"
say "<form action="""||Globals.!myself||""" method=get>"
say "<input type=""Hidden"" name=""login"" value=""1"">"
say "login: <INPUT type=text value="""" framewidth=4 name=l size=8> password: <INPUT type=password value="""" framewidth=4 name=p size=8><br>"
say " "
say "<input type=submit value=""Login"">"
say "</form>"
say "</pre>"
say "<br><p><br>"
say "</center>"
say "</body>"
say "</html>"
return
CheckScreen: procedure expose Globals. ListMail.
say "Content-type: text/html"
say ""
say "<html>"
say "<title> "||Globals.!myinfo||" </title>"
say "<body text=""#ffffff"" bgcolor=""#000000"" link=""#00BFFF"" vlink=""#00BFFF"">"
say "<center>"
say "<br><p><br>"
say "<b>Email account for "||Globals.!user||"</b><br>"
say "<br><p><br>"
if Globals.!totalmail > 0 then do
say "<table Nowrap Border=5 Align=Center>"
say "<caption><nobr><b>Email Listing</b></nobr></caption>"
say "<Tr bgcolor=""#000000"" text=""ffffff"">"
say "<Td Align=Center>"
say "Actions"
say "<Td Align=Center>"
say "From"
say "<Td Align=Center>"
say "Subject"
say "<Td Align=Center>"
say "Date"
say "</Tr>"
do i=1 to Globals.!totalmail
say "<Tr bgcolor=""#000000"" text=""ffffff"">"
say "<Td Align=Center>"
say "<a href="""||Globals.!myself||"?read&l="||Globals.!user||"&p="||Globals.!pazz||"&"||i||""">READ</a> - <a href="""||Globals.!myself||"?delete&l="||Globals.!user||"&p="||Globals.!pazz||"&"||i||""">DELETE</a>"
say "<Td Align=Center>"
say ListMail.i.!From
say "<Td Align=Center>"
say ListMail.i.!Subject
say "<Td Align=Center>"
say ListMail.i.!Date
say "</Tr>"
end
say "</table>"
end; else do
say "<b>No mail</b><br>"
end
say "<br><p><br>"
say "Options<br>"
say "<br>"
if Globals.!totalmail > 0 then say "<a href="""||Globals.!myself||"?delete&l="||Globals.!user||"&p="||Globals.!pazz||"&all"">Delete all mail</a><br>"
say "<a href="""||Globals.!myself||""">LogOff</a><br>"
say "<br><p><br>"
say "</center>"
say "</body>"
say "</html>"
exit
return
ReadEmailScreen: procedure expose Globals.
i=1
tmp1 = pos("From:",ARG(1))+6
tmp2 = pos('0d0a'x,ARG(1),tmp1)
tmp3 = space(substr(ARG(1),tmp1,tmp2-tmp1))
ListMail.i.!From = space(substr(tmp3,1,pos("<",tmp3)-1)||"("||substr(tmp3,pos("<",tmp3)+1,(lastpos(">",tmp3))-(pos("<",tmp3)+1))||")")
tmp1 = pos("Subject:",ARG(1))+9
tmp2 = pos('0d0a'x,ARG(1),tmp1)
ListMail.i.!Subject = space(substr(ARG(1),tmp1,tmp2-tmp1))
tmp1 = pos("Date:",ARG(1))+6
tmp2 = pos('0d0a'x,ARG(1),tmp1)
ListMail.i.!Date = space(substr(ARG(1),tmp1,16))
say "Content-type: text/html"
say ""
say "<html>"
say "<title> "||Globals.!myinfo||" </title>"
say "<body text=""#ffffff"" bgcolor=""#000000"" link=""#00BFFF"" vlink=""#00BFFF"">"
say "<center>"
say "<p>"
say "<table Nowrap Border=5 Align=Center>"
say "<caption><nobr><b>Email</b></nobr></caption>"
say "<Tr bgcolor=""#000000"" text=""ffffff"">"
say "<Td Align=Center>"
say "Actions"
say "<Td Align=Center>"
say "From"
say "<Td Align=Center>"
say "Subject"
say "<Td Align=Center>"
say "Date"
say "</Tr>"
say "<Tr bgcolor=""#000000"" text=""ffffff"">"
say "<Td Align=Center>"
say "<a href="""||Globals.!myself||"?delete&l="||Globals.!user||"&p="||Globals.!pazz||"&"||i||""">DELETE</a>"
say "<Td Align=Center>"
say ListMail.i.!From
say "<Td Align=Center>"
say ListMail.i.!Subject
say "<Td Align=Center>"
say ListMail.i.!Date
say "</Tr>"
say "</table><br></center><pre>"
say ARG(1)
say "</pre><center><br><p><br>"
say "Options<br>"
say "<br>"
say "<a href="""||value("HTTP_REFERER",,'os2environment')||""">Return to email listing</a><br>"
say "<br><p><br>"
say "</center>"
say "</body>"
say "</html>"
exit
return
ServerErrorScreen: procedure expose Globals.
say "Content-type: text/html"
say ""
say "<html>"
say "<title> "||Globals.!myinfo||" </title>"
say "<body text=""#ffffff"" bgcolor=""#000000"" link=""#00BFFF"" vlink=""#00BFFF"">"
say "<center>"
say "<br><p><br>"
say "<b>WebMail/2: An error occured:</b><br>"
say "<p><b>"||ARG(1)||"</b><br>"
say "<br><p><br>"
say "</center>"
say "</body>"
say "</html>"
exit
return
CGIErrorScreen: procedure expose Globals.
say "Content-type: text/html"
say ""
say "<html>"
say "<title> "||Globals.!myinfo||" </title>"
say "<body text=""#ffffff"" bgcolor=""#000000"" link=""#00BFFF"" vlink=""#00BFFF"">"
say "<center>"
say "<br><p><br>"
say "<b>WebMail/2: There was an internal error,<br>"
say "please contact your administrator.</b><br>"
say "<br><p><br>"
say "<b>"||ARG(1)||"</b><br>"
say "<br><p><br>"
say "</center>"
say "</body>"
say "</html>"
exit
return