home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
timesync.zip
/
timesync.cmd
next >
Wrap
OS/2 REXX Batch file
|
2001-04-09
|
9KB
|
329 lines
/******************************************************
Webé┼PCé╠Ä₧ìÅìçéφé╣ü⌠ for OS/2
Ver 1.0 2001.Apr.09 by Achain
******************************************************/
/********************************************************
É┌æ▒ɵWebâyü[âWé╠É▌ÆΦ
ô·Ä₧é≡ô╟é▌Åoé╖Weâyü[âWé≡É▌ÆΦé╡é▄é╖üDâTü[âoü[é╠Ä₧ìÅé¬é┐éßé±é╞
É│é╡é¡É▌ÆΦé│éΩé─é¿éΦüCé⌐é┬âAâNâZâXé╔Ä₧è╘é╠é⌐é⌐éτé╚éóâyü[âWé≡
ùÿùpé╡é▄é╡éσéñüD
ùßüF http://www.google.com/ é≡ùpéóéΘÅΩìçé═
server = 'www.google.com'
port = 80
page = '/'
é╞é╡é▄é╖üD
********************************************************/
server = 'www.google.com'
port = 80
page = '/'
/********************************************************
http proxyé╠É▌ÆΦ
http proxy é≡Ägùpé╖éΘÅΩìçé═
proxy = 'âzâXâgû╝éαé╡é¡é═IPâAâhâîâX'
proxyport = â|ü[âgö╘ìå
é╞é╡é▄é╖üDhttp proxyé≡Ägùpé╡é╚éóÅΩìçé═
proxy = ''
proxyport = ôKôûé╚ÉöÄÜ
é╞é╡é─é¡é╛é│éóüD
********************************************************/
proxy = ''
proxyport = 8080
/********************************************************
âOâèâjâbâWòWÅÇÄ₧é⌐éτé╠Ä₧è╘ì╖é╠É▌ÆΦ
ô·û{é╚éτ +9 é╔é╚éΦé▄é╖üD
********************************************************/
timeoffset = +9
/********************************************************/
/********************************************************/
/* âüâCâôâïü[â`âô */
/********************************************************/
/* REXX Socketsè╓ÉöîQé≡âìü[âhé╖éΘ */
if RxFuncQuery('SockLoadFuncs') then do
call RxFuncAdd 'SockLoadFuncs','RxSock','SockLoadFuncs'
call SockLoadFuncs
end
parse arg argv
argv = translate(argv)
/* ò╧Éöé╠Åëè·ë╗ */
recbuf = '' /* Ä≤ÉMâoâbâtâ@ */
rectxt = '' /* ìsâoâbâtâ@ */
crlf = '0d0a'x /* ëⁿìsâRü[âh */
status = 0
/* Ctrl+Cé╚é╟é╔éµéΘÆåÆfÄ₧é╔EndProcessé╔ö≥é╘éµéñé╔é╖éΘ */
signal on halt name EndProcess
/* É┌æ▒ɵâzâXâgé╠Åεò±é≡ÅÇö⌡é╖éΘ */
if proxy \= '' then do
/* proxyé¬ï≤ò╢ÄÜù±é┼é╚é»éΩé╬http proxyé╞î⌐é╚é╡é─é╗éΩé≡Ägùpé╖éΘ */
hostname = proxy
hostport = proxyport
end
else do
/* É┌æ▒âTü[âoü[é╔â_âCâîâNâgé╔É┌æ▒é╖éΘ */
hostname = server
hostport = port
end
/* É┌æ▒ɵâzâXâgû╝é¬ÉöÄÜé╞âsâèâIâhé╠é▌é╚éτIPâAâhâîâX */
if verify(hostname, '0123456789.') = 0 then
rc = SockGetHostByAddr(hostname, 'host.!')
else
rc = SockGetHostByName(hostname, 'host.!')
if rc = 0 then do
say 'Unknown host [' || hostname || ']'
exit 1
end
/* â\âPâbâgé≡ùpê╙é╖éΘ */
sock = SockSocket('AF_INET','SOCK_STREAM',0 )
if sock < 0 then do
say 'SocketError'
exit 2
end
/* WebâTü[âoü[é╔É┌æ▒é╖éΘ */
address.!family = 'AF_INET'
address.!port = hostport
address.!addr = host.!addr
rc = SockConnect(sock, 'address.!')
if rc < 0 then do
say 'Cannot connect host [' || hostname || ']'
rc = SockSoClose(sock)
exit 3
end
/* æùÉMé╖éΘâfü[â^é≡ÅÇö⌡é╖éΘ */
if proxy \= '' then
sdata = 'HEAD http://'||server||':'||port||page||' HTTP/1.0'||crlf
else
sdata = 'HEAD '||page||' HTTP/1.0'||crlf
sdata = sdata || 'Connection: close' || crlf
sdata = sdata || 'User-Agent: TimerSync/2 (OS/2; U)' || crlf
sdata = sdata || 'Host: ' || server || crlf
sdata = sdata || 'Accept: */*' || crlf
sdata = sdata || 'Accept-Language: en' || crlf
sdata = sdata || 'Accept-Charset: iso-8859-1,*,utf-8' || crlf
/* âfü[â^é≡æùÉMé╖éΘ */
rc = SendString(sdata)
/* âfü[â^é≡Ä≤ÉMé╖éΘ */
receivedDateTime = 0
do forever
rc = RecvString()
if rc = -1 then exit 4
if rectxt = '' then LEAVE
/* Ä≤ÉMâfü[â^é╠Æåé╠ô·Ä₧âfü[â^é≡éαé╞é╔PCé╠Ä₧ìÅé≡É▌ÆΦé╖éΘ */
rc = GetDateTime(argv)
receivedDateTime = receivedDateTime | rc
end
if receivedDateTime = 0 then do
say 'Data from host does not contain Data: line'
status = 5
end
EndProcess:
/* Æ╩ÉMé≡Ä╒Æfé╡üDâ\âPâbâgé≡öjèⁿé╖éΘ */
rc = SockShutDown(sock, 2)
rc = SockSoClose(sock)
/* âvâìâOâëâÇÅIù╣ */
exit status
/******************************************************
Ä≤ÉMé╡é╜âfü[â^é⌐éτô·Ä₧âfü[â^é≡ÆTé╡üCî⌐é┬é⌐é┴é╜ÅΩìçé═
é╗éΩé≡éαé╞é╔PCé╠Ä₧ìÅé≡É▌ÆΦé╖éΘâTâuâïü[â`âô
òKùvé╚é╠é═üCâTü[âoü[é⌐éτÄ≤ÉMé╡é╜ò╢ÄÜù±é╠Æåé╠
"Date: Sat, 07 Apr 2001 16:04:06 GMT" é╞éóéñìsé┼éáéΘüD
ìsé¬î⌐é┬é⌐éΦÄ₧ìÅÉ▌ÆΦé≡é╡é╜éτû▀éΦÆlé═1
ìsé¬î⌐é┬é⌐éτé╚é⌐é┴é╜éτû▀éΦÆlé═0
******************************************************/
GetDateTime:
procedure expose rectxt timeoffset
parse arg argv
po = pos('Date: ', rectxt)
if po = 0 then return 0
/* ìsé¬î⌐é┬é⌐é┴é╜éτò¬ë≡é╖éΘ */
ct.mday = format(substr(rectxt, po + 11, 2))
ct.smon = substr(rectxt, po + 14, 3)
ct.year = format(substr(rectxt, po + 18, 4))
ct.hour = format(substr(rectxt, po + 23, 2))
ct.min = format(substr(rectxt, po + 26, 2))
ct.sec = format(substr(rectxt, po + 29, 2))
/* îÄé╠û╝æOé≡ÉöÄÜé╔ò╧è╖é╖éΘ */
select
when ct.smon = 'Jan' then ct.mon = 1
when ct.smon = 'Feb' then ct.mon = 2
when ct.smon = 'Mar' then ct.mon = 3
when ct.smon = 'Apr' then ct.mon = 4
when ct.smon = 'May' then ct.mon = 5
when ct.smon = 'Jun' then ct.mon = 6
when ct.smon = 'Jul' then ct.mon = 7
when ct.smon = 'Aug' then ct.mon = 8
when ct.smon = 'Sep' then ct.mon = 9
when ct.smon = 'Oct' then ct.mon = 10
when ct.smon = 'Nov' then ct.mon = 11
when ct.smon = 'Dec' then ct.mon = 12
otherwise
end
/* GMTé≡âìü[âJâïâ^âCâÇé╔é╖éΘ */
call GetLocalTimeFromGMT
cdate = date('S')
cdate = insert('-', cdate, 4)
cdate = insert('-', cdate, 7)
ctime = time('N')
st.date = ct.year || '-' || ct.mon || '-' || ct.mday
st.time = ct.hour || ':' || ct.min || ':' || ct.sec
say 'adjust date/time from ['cdate' 'ctime'] to ['st.date' 'st.time']'
if argv \= 'DUMMY' then do
'@date ' || st.date
'@time ' || st.time
say 'Adjusted.'
end
return 1
/******************************************************
GMTé≡âìü[âJâïâ^âCâÇé╔é╖éΘâTâuâïü[â`âô
******************************************************/
GetLocalTimeFromGMT:
procedure expose ct. timeoffset
mdays.1 = 31
mdays.2 = 28 + GetYearLeaped(ct.year)
mdays.3 = 31
mdays.4 = 30
mdays.5 = 31
mdays.6 = 30
mdays.7 = 31
mdays.8 = 31
mdays.9 = 30
mdays.10 = 31
mdays.11 = 30
mdays.12 = 31
ct.hour = ct.hour + timeoffset
cmonth = ct.mon
if ct.hour >= 24 then do
ct.hour = ct.hour - 24
ct.mday = ct.mday + 1
if ct.mday > mdays.cmonth then do
ct.mday = 1
ct.mon = ct.mon + 1
if ct.mon > 12 then do
ct.mon = 1
ct.year = ct.year + 1
end
end
end
if ct.hour < 0 then do
ct.hour = ct.hour + 24
ct.mday = ct.mday - 1
if ct.mday < 1 then do
cmonth = cmonth - 1
if cmonth < 1 then do
cmonth = 12
ct.year = ct.year - 1
end
ct.mon = cmonth
ct.mday = mdays.cmonth
end
end
ct.mday = right(ct.mday, 2, '0')
ct.mon = right(ct.mon, 2, '0')
ct.year = right(ct.year, 4, '0')
ct.hour = right(ct.hour, 2, '0')
ct.min = right(ct.min, 2, '0')
ct.sec = right(ct.sec, 2, '0')
return 0
/******************************************************
ë[öNé≡ö╗ÆΦé╖éΘâuâïü[â`âô
ôné│éΩé╜É╝ù∩öNé¬ë[öNé╚éτ1é≡ò╘é╖üD
é╗éΩê╚èOé╠ÅΩìçé═0é≡ò╘é╖üD
******************************************************/
GetYearLeaped:
procedure
parse arg year
leaped = 0
if year // 4 = 0 then do
if year // 100 = 0 then do
if year // 400 = 0 then do
leaped = 1
end
else leaped = 0
end
else leaped = 1
end
else leaped = 0
return leaped
/******************************************************
âlâbâgâÅü[âNé⌐éτêΩìsé≡Ä≤ÉMé╖éΘâTâuâïü[â`âô
Ä≤ÉMé╡é╜êΩìsé≡âOâìü[âoâïò╧Éö rectxt é╔èiö[é╖éΘüD
É│Åφé╔Ä└ìsé┼é½é╜éτû▀éΦÆlé═0
âGâëü[é¬ö¡É╢é╡é╜ÅΩìçé═É┌æ▒é≡ò┬é╢üCû▀éΦÆlé═-1
******************************************************/
RecvString:
if sock < 0 then return -1
do forever
/* Ä≤ÉMâoâbâtâ@é╠Æåé⌐éτëⁿìsâRü[âhé≡ÆTé╖ */
if pos(crlf, recbuf) == 0 then do
/* ëⁿìsâRü[âhé¬î⌐é┬é⌐éΘé▄é┼âfü[â^é≡Ä≤ÉMé╡üC */
txt = ''
rc = SockRecv(sock, 'txt', 4096)
if rc <= 0 then do
rc = SockSoClose(sock)
sock = -1
return -1
end
/* Ä≤ÉMâoâbâtâ@é╔Æ╟ë┴é╡é─éóé¡ */
recbuf = recbuf || txt
end
else do
/* ëⁿìsâRü[âhé¬î⌐é┬é⌐é┴é╜éτüCé╗é╠ÄΦæOé▄é┼êΩìsé≡Ä≤ÉM
âoâbâtâ@é⌐éτÉ╪éΦÅoé╡é─rectxté╔èiö[é╡é─ö▓é»éΘ */
parse var recbuf rectxt (crlf) recbuf
leave
end
end
return 0
/******************************************************
âlâbâgâÅü[âNé╔êΩìsé≡æùÉMé╖éΘâTâuâïü[â`âô
ê°Éöé┼ôné│éΩé╜ò╢ÄÜù±é╔ëⁿìsâRü[âhé≡òtë┴é╡é─æùÉMé╖éΘüD
É│Åφé╔Ä└ìsé┼é½é╜éτû▀éΦÆlé═0
âGâëü[é¬ö¡É╢é╡é╜ÅΩìçé═É┌æ▒é≡ò┬é╢üCû▀éΦÆlé═-1
******************************************************/
SendString:
if sock < 0 then return -1
parse arg buf
/* ôné│éΩé╜ò╢ÄÜù±é╠ì┼îπé╔ëⁿìsâRü[âhé≡òtë┴é╡æùÉMé╖éΘ */
rc = SockSend(sock, buf || crlf)
if rc <= 0 then do
rc = SockSoClose(sock)
sock = -1
return -1
end
return 0