home *** CD-ROM | disk | FTP | other *** search
/ Magazyn WWW 1999 July / www_07_1999.iso / prez / amiga / stricq_1371.lha / stricq / rexx / ConnectionWizard.rexx next >
OS/2 REXX Batch file  |  1999-05-07  |  10KB  |  321 lines

  1. /*****************************************************************************************
  2.  
  3.    ConnectionWizard.rexx - An easy way to integrate your favourite Internet Programs
  4.    by Giuseppe "Uranya" Di Terlizzi - ICQ Number 24696986 - (also on IRC)
  5.  
  6.    $VER: ConnectionWizard.rexx v1.3 (05.05.1999) Copyright(c) 1999 Giuseppe Di Terlizzi
  7.  
  8.    Brief Instructions: You could personalize your wizard simply changing the record Prg
  9.                        Prg.0.xxxx = The informations about your TCP/IP Stack
  10.                        Prg.x.name = The full path and name of the x program
  11.                        Prg.x.port = The ARexx port of your x program
  12.                        Prg.x.butt = The name on buttons to identify your x program
  13.                        Prg.x.quit = The ARexx Command of x program to quit
  14.  
  15.    Important notes: x is the number of your program (could be greater as you want)
  16.                     Prg.last indicates the last program on the requestchoise window
  17.                     ARexx commands Prg.0.cmd.xxxx are set for Miami3 (earlier not tested)
  18.                     Prg.x.gadg MUST ALWAYS BE FIXED ON -1
  19.  
  20.    Needs: An Amiga ;-), RexxMast started, C:RequestChoice and C:Wait, no more needs!
  21.  
  22. ******************************************************************************************/
  23.  
  24.  
  25.  
  26. /* Constants declarations ---------------------------------------------------------------*/
  27.  
  28. OPTIONS RESULTS
  29. TRUE=1 ; FALSE=0 ; WARN=5
  30. WizRet="ConnWiz.Ret" ; RunFlag="ConnWiz.Run" ; IngFlag="ConnWiz.Ing"
  31.  
  32. /* Control function ---------------------------------------------------------------------*/
  33.  
  34. IF CheckFlag(RunFlag)=FALSE THEN CALL Main
  35. ELSE EXIT
  36.  
  37. Main:
  38.  
  39. /*****************************************************************************************/
  40. /*                                                                                       */
  41. /* YOU COULD MODIFY ONLY THIS SECTION FOR PERSONALIZATION OF WIZARD                      */
  42. /*                                                                                       */
  43. /*****************************************************************************************/
  44.  
  45. /* TCP/IP Stack Informations ------------------------------------------------------------*/
  46.  
  47. Prg.0.name="Miami:Miami SETTINGS=Miami:Miami.hided"
  48. Prg.0.port="MIAMI.1"
  49. Prg.0.butt="Miami"
  50. Prg.0.quit="QUITFORCE"
  51.  
  52. Prg.0.cmd.online="online"
  53. Prg.0.cmd.offline="offline"
  54. Prg.0.cmd.checkline="isonline"
  55. Prg.0.cmd.speed="getconnect"
  56. Prg.0.cmd.time="getconnecttime"
  57.  
  58. /* Programs Informations ----------------------------------------------------------------*/
  59.  
  60. Prg.1.name="Internet:StrICQ/StrICQ"
  61. Prg.1.port="STRICQ.1"
  62. Prg.1.butt="StrICQ"
  63. Prg.1.quit="QUIT"
  64. Prg.1.gadg=-1
  65.  
  66. Prg.2.name="Internet:AmIRC_22/AmIRC020"
  67. Prg.2.port="AMIRC.1"
  68. Prg.2.butt="AmIRC"
  69. Prg.2.quit="QUIT"
  70. Prg.2.gadg=-1
  71.  
  72. Prg.3.name="Internet:Voyager/V030"
  73. Prg.3.port="VOYAGER"
  74. Prg.3.butt="Voyager"
  75. Prg.3.quit="QUIT"
  76. Prg.3.gadg=-1
  77.  
  78. Prg.4.name="Internet:AWeb32/AWeb-II"
  79. Prg.4.port="AWEB.1"
  80. Prg.4.butt="AWeb-II"
  81. Prg.4.quit="QUIT"
  82. Prg.4.gadg=-1
  83.  
  84. Prg.5.name="Internet:YAM/YAM"
  85. Prg.5.port="YAM"
  86. Prg.5.butt="YAM 2"
  87. Prg.5.quit="QUIT"
  88. Prg.5.gadg=-1
  89.  
  90. Prg.Last=5
  91.  
  92. /*****************************************************************************************/
  93. /*                                                                                       */
  94. /* YOU COULD NOT MODIFY THE SECTION BELOW: IT IS THE MAIN CODE                           */
  95. /*                                                                                       */
  96. /*****************************************************************************************/
  97.  
  98. Ask.goline.1=Prg.0.butt "is OFFLINE*nLoad"
  99. Ask.goline.2="in which mode?"
  100.  
  101. CALL SetFlag(RunFlag)
  102. Tit.main="ConnectionWizard v1.3 ⌐1999 Uranya"
  103. Ask.select="Select an Internet Option or Program"
  104. Ask.quit="Are you SURE you want to Quit?"
  105. Tit.infos=""
  106.  
  107. Def.Ok="OK"
  108. Def.No="NO, never!"
  109. Def.Yes="Yes, I want!"
  110. Def.ON="ONLINE"
  111. Def.OFF="OFFLINE"
  112. Def.Quit="QUIT"
  113. Def.Cancel="CANCEL"
  114. Def.Fault="Error: Cannot load the program"
  115. Def.Check="Ok, I will check it..."
  116. Def.TCPFalut="Port" Prg.0.port "not found"
  117.  
  118. /*--------------------------------------------------------------------------------------*/
  119.  
  120. ADDRESS COMMAND
  121.  
  122. IF CheckPort(Prg.0.port)=FALSE THEN DO
  123.     IF LoadTCP()=FALSE THEN DO
  124.         CALL UnSetFlag(RunFlag)
  125.         CALL LoadErr(Prg.0.butt,Def.TCPFault)
  126.         EXIT
  127.     END
  128. END
  129. StrReq='"'Def.Quit'"'
  130. IniTCPStatus=GetTCPStatus()
  131.  
  132. IF IniTCPStatus=TRUE THEN DO
  133.     StrReq=StrReq '"'Def.OFF'"'
  134.     Tit.infos=GetTCPInfos()
  135.     CALL UnSetFlag(IngFlag)
  136. END
  137. ELSE StrReq=StrReq '"'Def.ON'"'
  138.  
  139. Actgad=3
  140. DO Num=1 TO Prg.Last
  141.     Prg.Num.active=CheckPort(Prg.Num.port)
  142.     IF Prg.Num.active=FALSE THEN DO
  143.         Prg.Num.gadg=Actgad
  144.         StrReq=StrReq '"'Prg.Num.butt'"'
  145.         Actgad=Actgad+1
  146.     END
  147. END
  148.  
  149. StrReq='SetEnv' WizRet '`C:RequestChoice "'Tit.main Tit.infos'" "'Ask.select'"' StrReq '"'Def.Cancel'"`'
  150. ADDRESS COMMAND StrReq
  151. Ret=GetResult(WizRet)
  152. CALL UnSetFlag(RunFlag)
  153. SELECT 
  154.     WHEN Ret=1 THEN CALL QuitWizard
  155.     WHEN Ret=2 THEN CALL SwitchTCPStatus
  156.     WHEN Ret>2 THEN DO
  157.         Found=FALSE
  158.         DO Num=1 TO Prg.Last WHILE Found=FALSE
  159.             IF Prg.Num.gadg=Ret THEN DO
  160.                 Offs=Num
  161.                 Found=TRUE
  162.             END
  163.         END
  164.         LRes=LoadPrg(Prg.Offs.name,Prg.Offs.butt)
  165.         IF LRes~=0 THEN DO ; CALL LoadErr(Prg.Offs.butt,'Returned: '||LRes) ; END
  166.     END
  167.     OTHERWISE
  168. END
  169. EXIT
  170.  
  171. /*****************************************************************************************/
  172. /*                                                                                       */
  173. /* BELOW THERE ARE THE SUBROUTINES                                                       */
  174. /*                                                                                       */
  175. /*****************************************************************************************/
  176.  
  177. GetResult:
  178. EnvFile='ENV:'||ARG(1)
  179. CALL OPEN('Logic',EnvFile,'R')
  180. Char=READCH('Logic',1)
  181. CALL CLOSE('Logic')
  182. CALL UnSetFlag ARG(1)
  183. RETURN Char
  184.  
  185. /*****************************************************************************************/
  186.  
  187. CheckPort:
  188. IF ~Show('P',ARG(1)) THEN RETURN FALSE
  189. RETURN TRUE
  190.  
  191. /*****************************************************************************************/
  192.  
  193. LoadPrg:
  194. NamePrg=ARG(1)
  195. ButtPrg=ARG(2)
  196. IF ((GetTCPStatus()=FALSE) & (CheckFlag(IngFlag)=FALSE)) THEN DO
  197.     StrReq='SetEnv' WizRet '`C:RequestChoice "'Tit.main'" "'Ask.goline.1 ButtPrg Ask.goline.2'" "'Def.ON'" "'Def.OFF'" "'Def.Cancel'"`'
  198.     ADDRESS COMMAND StrReq
  199.     Ret=GetResult(WizRet)
  200.     IF Ret=1 THEN CALL GoOnAsync
  201. END
  202. IF Ret>0 THEN ADDRESS COMMAND NamePrg
  203. RETURN RC
  204.  
  205. /*****************************************************************************************/
  206.  
  207. LoadErr:
  208. StrReq= 'C:RequestChoice "'Tit.main Tit.infos'" "'Def.Fault ARG(1)'*n'ARG(2)'" "'Def.Check'"'
  209. ADDRESS COMMAND StrReq
  210. RETURN
  211.  
  212. /*****************************************************************************************/
  213.  
  214. ObtainPort:
  215. MaxTries=10
  216. Tries=0
  217. Chk=FALSE
  218. DO UNTIL ((Chk~=FALSE) | (Tries<MaxTries))
  219.     Tries=Tries+1
  220.     CALL Wait(3)
  221.     Chk=CheckPort(ARG(1))
  222. END
  223. RETURN Chk
  224.  
  225. /*****************************************************************************************/
  226.  
  227. GoOnAsync:
  228. CALL SetFlag(IngFlag)
  229. ADDRESS COMMAND "RUN <>NIL: SYS:Rexxc/rx " '"ADDRESS' Prg.0.port Prg.0.cmd.online'"'
  230. RETURN
  231.  
  232. /*****************************************************************************************/
  233.  
  234. GoOffAsync:
  235. ADDRESS COMMAND "RUN <>NIL: SYS:Rexxc/rx " '"ADDRESS' Prg.0.port Prg.0.cmd.offline'"'
  236. RETURN
  237.  
  238. /*****************************************************************************************/
  239.  
  240. LoadTCP:
  241. ADDRESS COMMAND "RUN <>NIL: " Prg.0.name
  242. RETURN ObtainPort(Prg.0.port)
  243.  
  244. /*****************************************************************************************/
  245.  
  246. GetTCPStatus:
  247. ADDRESS VALUE Prg.0.port ; Prg.0.cmd.checkline
  248. RETURN RC
  249.  
  250. /*****************************************************************************************/
  251.  
  252. SwitchTCPStatus:
  253. IF IniTCPStatus=1 THEN CALL GoOffAsync
  254. ELSE CALL GoOnAsync
  255. RETURN
  256.  
  257. /*****************************************************************************************/
  258.  
  259. GetTCPInfos:
  260. ADDRESS VALUE Prg.0.port ; Prg.0.cmd.speed
  261. Infos=result
  262. ADDRESS VALUE Prg.0.port ; Prg.0.cmd.time
  263. Total=result
  264. Minutes=Total%60
  265. Seconds=Total-(Minutes*60)
  266. IF Minutes>1000 THEN Minutes='+'||(Minutes-15429722)
  267. IF Seconds<10 THEN ColZero=":0"
  268. ELSE ColZero=":"
  269. Infos="  SPEED" Infos "  Online time" Minutes||ColZero||Seconds
  270. RETURN Infos
  271.  
  272. /*****************************************************************************************/
  273.  
  274. QuitWizard:
  275. StrReq='SetEnv' WizRet '`C:RequestChoice "'Tit.main'" "'Ask.quit'" "'Def.Yes'" "'Def.No'"`'
  276. ADDRESS COMMAND StrReq
  277. Ris=GetResult(WizRet)
  278. IF Ris=1 THEN DO
  279.     CALL GoOffAsync
  280.     DO Num=1 TO Prg.Last
  281.         IF Prg.Num.active=TRUE THEN DO
  282.             ADDRESS VALUE Prg.Num.port ; Prg.Num.quit
  283.         END
  284.     END
  285.     ADDRESS VALUE Prg.0.port ; Prg.0.quit
  286. END
  287. RETURN
  288.  
  289. /*****************************************************************************************/
  290.  
  291. SetFlag:
  292. ADDRESS COMMAND "SetEnv" ARG(1) TRUE
  293. RETURN
  294.  
  295. /*****************************************************************************************/
  296.  
  297. UnSetFlag:
  298. ADDRESS COMMAND "UnSetEnv" ARG(1)
  299. RETURN
  300.  
  301. /*****************************************************************************************/
  302.  
  303. CheckFlag:
  304. Flag=ARG(1)
  305. IF EXISTS("ENV:"Flag)=TRUE THEN RETURN TRUE
  306. RETURN FALSE
  307.  
  308. /*****************************************************************************************/
  309.  
  310. Wait:
  311. ADDRESS COMMAND
  312. C:WAIT ARG(1)
  313. RETURN
  314.  
  315. /*****************************************************************************************/
  316. /*                                                                                       */
  317. /* END OF CONNECTION WIZARD                                                              */
  318. /*                                                                                       */
  319. /*****************************************************************************************/
  320.  
  321.