home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
bingrb2b.zip
/
bingrab.cmd
next >
Wrap
OS/2 REXX Batch file
|
1997-09-14
|
20KB
|
633 lines
/*------------------------------------------------------------------
* REXX - OS/2 -- BINGRAB ver 0.2b
* bingrab.cmd : binaries grabber
*
* Current version can be found at http://nfinity.com/~tmillea
*
* Grabs uudecoded Jpeg and Gif files (multiple and single part)
* from newsgroups then decodes them into binaries. A small modification
* can be made to allow it to decode other binaries as well such as Zip
* and EXE.
* Requires rxsock.dll and uudeview.exe to function. I have included
* them, but STRONGLY URGE you to go get the complete file from
* FTP somewhere. They will have documentation on how to setup.
* The .rc files contain group info to track what groups to grab
* and also keep track of messages already downloaded.
* As to the multiple parts - It has it's limitations. You can adjust the
* minimum size of messages to download to a smaller value to maybe
* get the final part of a post, but you are also grabbing a bunch
* of time consuming garbage in the proccess. I have it set to 500.
* This is mainly because I don't want a bunch of small pictures in my
* directory or to spend time downloading files that are not pictures
* like .html files or text files. I have found that multiple part posts are
* missing pieces anyway. The few complete ones that get missed are
* probably not worth the extra coding it would take to go look for them.
* Also another important consideration is the number of group names
* in the bingroup.rc file. For each group name listed, a seperate call to
* BINGRAB.CMD is called and a seperate server connection. This could
* lead to a slow machine or even errors. I recommend limiting it to less
* than 15, I have it set to 10. You can always create multiple .rc files
* that contain 10 - 15 names and run them at different times.
* I have included two utility programs. GROUPS.CMD will get a list of
* available BINARY groups from the server. This list then can be cut
* and pasted into the .rc files for BINGRAB.CMD. MOVE.CMD will move all
* jpg and gif files to a directory named the first characture of the file
* name. It will then delete any jpg or gif files left in the directory. This
* should eliminate any duplicate named files. At this time I have no way
* to determine if there are duplicate pictures with different names.
* My experience has been that there are not to many.
* I hope you like the program. It is EMAILware, so drop me a line if you
* use it and let me know how you like it and what enhancements you
* would like to see. I do not guarantee any further versions, but if any
* major bugs exist I will release an upgrade.
*
* Thanks, CyberLord. CyberLord@Cyber-Wizard.Com
if chars() then key = SysGetKey('noecho')
*------------------------------------------------------------------*/
MINSIZE = 500 /*Minimum size of messages to download*/
SOUND = 0 /*set to 0 if you don't like the beeps*/
MAXGROUPS = 10 /*Maximum number of server connections*/
parse upper source env how self .
parse arg arguments
/**************************************************************
Catch breaks
***************************************************************/
signal on halt
rc = Call_Sys_Funcs()
address cmd
'@ECHO OFF'
rc = Title()
if how = 'FUNCTION' then do
/* we were started as a function call... */
/* start us again as a separate session and return. */
say "Started as a function call"
say "calling ourselves"
'START /C' self arguments
say "Returning to program that called us"
return 0
end
parse arg server group new .
if new > 0 then do
rc = Call_Sys_Funcs()
rc = Title()
rc = Chk_Cmd_Line(server, group)
sock = Init_Sock_Funcs(server)
rc = Interact(sock, group, MINSIZE, SOUND) /*Jump to interact function*/
/*------------------------------------------------------------------
* quittin' time!
*------------------------------------------------------------------*/
rc = SendMessage(sock,"quit")
rc = SockSoclose(sock)
uudeview.exe "+e .jpg.gif.tif -i" group||".uue" /*decode Jpeg and Gif files. If you are grabbing warez*/
/*then change the .jpg.gif.tif to .exe.zip.arc or leave the*/
/*+e .jpg.gif.tif out all together and it will decode all files*/
rc = stream(group||".uue", 'c', 'close')
del group||".uue"
exit
end /*if new > 0 from begining of program way way up at the top*/
else if lines(group) then do
/*say lines(group)*/
number = 0
do while lines(group)
if number < MAXGROUPS then do
line = linein(group)
parse var line groupname .
'START /C' self server groupname 1
number = number + 1
end /*if number*/
else do
say "Max number of groups reached"
exit
end /*else do*/
end /*do while lines*/
exit
end /*else if do*/
else do
say "ERROR: Command line arguments incorrect or RC file on command line not found in bingrab directory."
exit 1
end
/******************************/
/*PROGRAM FUNCTIONS BELOW HERE*/
/******************************/
/********************************************
Initialize socket functions
********************************************/
Init_Sock_funcs: procedure expose !.
server = arg(1)
/*------------------------------------------------------------------
* initialize socket function package
*------------------------------------------------------------------*/
/*load sockets functions if not loaded*/
if RxFuncQuery("SockLoadFuncs") then
do
rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
rc = SockLoadFuncs()
end
/*------------------------------------------------------------------
* get address of server
*------------------------------------------------------------------*/
rc = SockGetHostByName(server,"host.!")
if (rc = 0) then
do
say "Unable to resolve server name" server
exit
end
server = host.!addr
/*------------------------------------------------------------------
* open socket
*------------------------------------------------------------------*/
sock = SockSocket("AF_INET","SOCK_STREAM",0)
if (sock = -1) then
do
say "Error opening socket:" errno
exit
end
/*------------------------------------------------------------------
* connect socket
*------------------------------------------------------------------*/
server.!family = "AF_INET"
server.!port = 119
server.!addr = server
rc = SockConnect(sock,"server.!")
if (rc = -1) then
Error(sock,rc,"Error connecting to server :" errno)
trc = GetResponse(sock)
do i = 1 to line.0
say line.i
end
return sock
/********************************************
Check command line arguments for errors
*********************************************/
Chk_Cmd_Line: procedure expose !.
server = arg(1)
group = arg(2)
if (server = "") then
do
say "Expecting a news server name to be passed as a parameter."
if (group = "") then
do
say "Expecting a newsgroup to be passed as a parameter."
exit 1
end
end
if (group = "") then
do
say "Expecting a newsgroup to be passed as a parameter."
exit 1
end
return 0
/**********************************************
Clear screen and write title
***********************************************/
Title: procedure expose !.
call syscls
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say "BINGRAB v0.2b Newsgroup Binaries Grabber"
say "by Timothy Millea - CyberLord@Cyber-Wizard.com"
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
return 0
/*------------------------------------------------------------------
* Get files from group loop
*------------------------------------------------------------------*/
Interact: procedure expose !.
sock = arg(1)
group = arg(2)
MINSIZE = arg(3) /*Minimum size of messages to download*/
SOUND = arg(4) /*set to 1 if sound wanted, set to 0 if not*/
say "Hit Q to exit. Current message will be downloaded first."
say "Trying slave function support..."
trc = SendMessage(sock,"slave") /*try to use the slave command if server allows*/
trc = GetResponse(sock)
do i =1 to line.0
say line.i
end /*do i*/
trc = SendMessage(sock,"group" group) /*change to desired group*/
trc = GetResponse(sock)
do i = 1 to line.0
say line.i
end /*do i*/
parse var line.1 code total begin end1 . /*here we get the total number of messages, the begining number and the end number*/
rccommand = linein(group||'.rc')
parse var rccommand rccode rctotal rcbegin rcend rcgroup /*here we read from the .rc file the last messages we recieved*/
if group = rcgroup then do /*if the group and the rcgroup match then continue*/
begin = rcend
begin = begin + 1
end /*if*/
else if rcgroup != "" then do
say "Command line "GROUP" does not match with .rc file "RCGROUP
exit
end /*else if*/
say "Last message number read " rcend
say "Newest message number in group " end1
if begin > end1 then do
say "No new messages in " group
call lineout group||'.rc', code (rcend-rcend) rcend rcend group, 1
call lineout group||'.rc'
return ""
end
call lineout group||".uue", group,1
call lineout group||".uue","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
call lineout group||'.rc', code (begin-begin) begin begin group, 1
call lineout group||'.rc'
number = begin
parse value syscurpos() with row col /*get the current cursor position*/
pos = syscurpos(row, col) /*position cursor where we found it*/
say "Getting header number " number
trc = SendMessage(sock, "head" number)
trc = GetResponse(sock)
do i = 1 to line.0
parse var line.i name lines .
if name = "Lines:" then leave
end /*do*/
do i = 1 to line.0
parse var line.i subj subject
if subj = "Subject:" then leave
end /*do*/
if lines > MINSIZE then do
say 'Waiting for duplicates file to be free...'
do while stream('duplicates','c','open') <> 'READY:'
call syssleep 1 /*just sit here and wait for dup file to be free*/
end
say 'Checking for duplicates...'
do while lines("duplicates")
dupsubj = linein("duplicates")
if subject = dupsubj then do
say "Duplicate Subject - Ignoring Message"
if SOUND then do
call beep 400, 100
call beep 500, 100
end /*if sound*/
leave
end /*if*/
end /*do while*/
say 'Closing dup file ... ' stream('duplicates','c','close')
end /*if lines*/
pos = syscurpos(row, col) /*position cursor where we found it*/
say " "
say " "
say " "
say " "
say " "
say " "
if lines > MINSIZE & subject <> dupsubj then do
pos = syscurpos(row, col) /*position cursor where we found it*/
say "Getting " lines "lines from message number " number
trc = SendMessage(sock, "body" number)
trc = GetResponse(sock)
say "Writing " line.0 "lines..."
do i = 1 to line.0
call lineout group||".uue",line.i,1
end /*do i*/
say 'Updating group rc file...'
call lineout group||'.rc', code (number-begin) begin number group, 1 /*don't want to write number out until message*/
call lineout group||'.rc' /*is written to .uue file*/
do while stream('duplicates','c','open') <> 'READY:'
call syssleep 1 /*just sit here and wait for dup file to be free*/
end
say 'Updating duplicates file...'
rc = stream('duplicates','c','seek <' 0) /*seek the end of file*/
call lineout 'duplicates', subject /*write the subject and group to the dup file so we can track it*/
say 'Closing dup file... ' stream('duplicates','c','close')
pos = syscurpos(row, col) /*position cursor where we found it*/
say " "
say " "
say " "
say " "
say " "
say " "
end /*if lines > MINSIZE*/
else do
call lineout group||'.rc', code (number-begin) begin number group, 1 /*write message number out to file*/
call lineout group||'.rc' /*after header is read even if less than MINSIZE lines*/
end /*else do*/
if chars() then key = SysGetKey('noecho')
if key = 'q' | key = 'Q' then halt()
do forever
/**************************************************************
Catch breaks
***************************************************************/
signal on halt
trc = SendMessage(sock, "next")
trc = GetResponse(sock)
parse var line.1 code number .
if code = 421 then do /*code 421 is an error that there are no more messages*/
say line.1
call lineout group||'.rc', code (rcend-rcend) rcend rcend group, 1
call lineout group||'.rc'
return ""
end /*if number*/
pos = syscurpos(row, col) /*position cursor where we found it*/
say "Getting header number " number
trc = SendMessage(sock, "head" number)
trc = GetResponse(sock)
do i = 1 to line.0
parse var line.i name lines .
if name = "Lines:" then leave
end /*if*/
do i = 1 to line.0
parse var line.i subj subject
if subj = "Subject:" then leave
end /*do*/
if lines > MINSIZE then do
say 'Waiting for duplicates file to be free...'
do while stream('duplicates','c','open') <> 'READY:'
call syssleep 1
end
say 'Checking for duplicates...'
do while lines("duplicates")
dupsubj = linein("duplicates")
if subject = dupsubj then do
say "Duplicate Subject - Ignoring Message"
if SOUND then do
call beep 400, 100
call beep 500, 100
end /*if sound*/
leave
end /*if*/
end /*do while*/
say 'Closing dup file... ' stream('duplicates','c','close')
end /*if lines*/
pos = syscurpos(row, col) /*position cursor where we found it*/
say " "
say " "
say " "
say " "
say " "
say " "
if lines > MINSIZE & subject <> dupsubj then do
pos = syscurpos(row, col) /*position cursor where we found it*/
say "Getting " lines "lines from message number " number
trc = SendMessage(sock, "body" number)
trc = GetResponse(sock)
say "Writing " line.0 "lines..."
do i = 1 to line.0
call lineout group||".uue",line.i
end /*do i*/
say 'Updating group rc file...'
call lineout group||'.rc', code (number-begin) begin number group, 1 /*don't want to write number out until message*/
call lineout group||'.rc' /*is written to .uue file*/
do while stream('duplicates','c','open') <> 'READY:'
call syssleep 1 /*just sit here and wait for dup file to be free*/
end
say 'Updating duplicates file...'
rc = stream('duplicates','c','seek <' 0) /*seek end of file*/
call lineout 'duplicates', subject /*write the subject and group to the dup file so we can track it*/
say 'Closing dup file... ' stream('duplicates','c','close')
pos = syscurpos(row, col) /*position cursor where we found it*/
say " "
say " "
say " "
say " "
say " "
say " "
end /*if lines > MINSIZE*/
else do
call lineout group||'.rc', code (number-begin) begin number group, 1 /*write message number out to file*/
call lineout group||'.rc' /*after header is read even if less than MINSIZE lines*/
end /*else do*/
call lineout group||".uue","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
number = number + 1
if number > end1 then do
say "Finished processing newsgroup"
call lineout group||".uue"
leave
end /*if*/
if chars() then key = SysGetKey('noecho')
if key = 'q' | key = 'Q' then halt()
end /*do forever*/
return ""
/*------------------------------------------------------------------
* close socket (and catch signals)
* this function is not working properly yet. It is supposed to run when
* ctrl-break is pressed so it will decode the uue file, delete it and then exit
* I will educate myself on signal traps and fix it sometime. :)
*------------------------------------------------------------------*/
halt:
rc = SendMessage(sock,"quit")
rc = SockSoClose(sock)
if (rc = -1) then
do
say "Error on SockSoClose:" errno
exit
end
uudeview.exe "+e .jpg.gif -i" group||".uue" /*decode file*/
rc = stream(group||".uue", 'c', 'close') /*close and delete .uue file*/
del group||".uue"
exit
/*------------------------------------------------------------------
* halting ...
*------------------------------------------------------------------*/
Halting:
Error(sock,1,"error on line" sigl)
/*------------------------------------------------------------------
* exit with a message and return code
*------------------------------------------------------------------*/
Error: procedure
sock = arg(1)
retc = arg(2)
msg = arg(3)
if (sock <> -1) then
rc = SockSoClose(sock)
say msg
exit retc
/*------------------------------------------------------------------
* get a line from the server
*------------------------------------------------------------------*/
GetResponseLine: procedure expose !.
sock = arg(1)
crlf = d2c(13) || d2c(10)
if (symbol('!.buff') = "LIT") then
!.buff = ""
do while (pos(crlf,!.buff) = 0)
rc = SockRecv(sock,"data",8000)
!.buff = !.buff || data
end
p = pos(crlf,!.buff)
line = substr(!.buff,1,p-1)
!.buff = substr(!.buff,p+2)
return line
/*------------------------------------------------------------------
* get a response from the server
*------------------------------------------------------------------*/
GetResponse: procedure expose !. line.
sock = arg(1)
moreids = "100 215 220 221 222 223 230 231"
line.0 = 1
line.1 = GetResponseLine(sock)
parse var line.1 rid .
if (wordpos(rid,moreids) = 0) then
return ""
if rid = 223 then return "" /*error 223 (no message with that number) does not return to bingrab a blank line */
/*with a '.' in it so we have to force it to return*/
do forever
o = line.0 + 1
line.o = GetResponseLine(sock)
if (line.o = ".") then
return ""
line.0 = o
end
return ""
/*------------------------------------------------------------------
* send a string to the server
*------------------------------------------------------------------*/
SendMessage: procedure expose !.
sock = arg(1)
data = arg(2) || d2c(13) || d2c(10)
len = length(data)
do while (len > 0)
i = SockSend(sock,data);
if (errno <> 0) then
Error(-1,rc,"Error sending data to server.")
if (i <= 0) then
Error(sock,100,"Server closed the connection.")
data = substr(data,len+1)
len = length(data)
end
return 0
/*---------------------------------------------------------------------
* call sys functions
*---------------------------------------------------------------------*/
Call_Sys_Funcs: procedure expose !.
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
return 0