home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 January / SOFM_Jan1996.bin / pc / os2 / zoc / install.fil / SCRIPT / REXXHOST < prev    next >
Encoding:
Text File  |  1995-11-25  |  10.8 KB  |  426 lines

  1. /* REXX */
  2.  
  3.     /* use this to debug script
  4.     TRACE A */
  5.     
  6.     ADDRESS ZOC
  7.     
  8.     /* clear screen */
  9.     WRITE '^[[2J^[[1H'
  10.     
  11.     /* check, whether valid cd option is set */
  12.     IF zoccarrier() == 'N/A' THEN
  13.     DO
  14.         WRITE '"Please enable CD Valid in OPTIONS SERIAL^M^J^M^J"'
  15.         EXIT
  16.     END
  17.  
  18.     /* set variables with default values - may be changed */
  19.     curdrive= 'c:'
  20.     curdir= '\'
  21.     guestdrive= ''
  22.     guestdir= 'script\guest\'
  23.     superpass= '"secret"'
  24.     guestpass= '"guest"'
  25.  
  26.     /* ask for passwords */
  27.     ASK '"Supervisor password"' superpass
  28.     if(zocresult()="##CANCEL##") then
  29.     do
  30.         write "REXXHOST cancelled^M^J^M^J"
  31.         exit
  32.     end
  33.     else
  34.         superpass= zocresult()
  35.     ASK '"Guest password"' guestpass
  36.     if(zocresult()="##CANCEL##") then
  37.     do
  38.         write "REXXHOST cancelled^M^J^M^J"
  39.         exit
  40.     end
  41.     else
  42.         guestpass= zocresult()
  43.  
  44.     /* don't give other side an echo */
  45.     SETHOST 0
  46.     
  47.     /* use a timeout of 60 for any input */
  48.     TIMEOUT 60
  49.  
  50.     /* switch our modem into answer mode */
  51.     WRITE '^[[2J^[[1H'
  52.     SETAUTOANSWER 1
  53.     DELAY 1
  54.  
  55.  
  56. /* -------------------------------------------------------------- */
  57. /* wait for connect, set serial speed and check password          */
  58. /* -------------------------------------------------------------- */
  59. allover:
  60.  
  61.     /* put infos on screen */
  62.     WRITE '^[[2J^[[1H'
  63.     WRITE '"Waiting for call ...^M^J^M^J"'
  64.  
  65.     
  66.     WAIT 'CONNECT'                    /* wait for connect */
  67.     DO WHILE rc <> 0
  68.         WAIT 'CONNECT'
  69.     END
  70.  
  71.     WAIT '^M'
  72.     
  73.     CALL wsend '^[[2J^[[1H'
  74.     CALL wsend '"Press BACKSPACE key to start host ...^M^J"'
  75.     WAIT '^H'
  76.     
  77.     IF zoccarrier()=='NO CARRIER' | rc <> 0 THEN SIGNAL endit
  78.  
  79.     /* show welcome screen */
  80.     CALL wsend '^[[2J^[[1H'
  81.     CALL welcome
  82.     CALL wsend '"Enter Password: "'
  83.  
  84.     WAIT '^M'
  85.     pass= zoclastline()
  86.     pass= STRIP(pass)
  87.  
  88.     IF pass= superpass THEN
  89.         status= 'super'
  90.     ELSE
  91.     IF pass= guestpass THEN
  92.     DO
  93.         status= 'guest'
  94.         curdrive= guestdrive
  95.         curdir= guestdir
  96.     END
  97.     ELSE
  98.     DO
  99.         CALL wsend '^M^J^M^J'
  100.         CALL wsend '"Sorry, authorization failed !"'
  101.         SIGNAL endit
  102.     END
  103.  
  104.  
  105. /* -------------------------------------------------------------- */
  106. /* print a new menu and ask choice                                */
  107. /* -------------------------------------------------------------- */
  108. menu:
  109.     
  110.     /* now give the other side an echo */
  111.     SETHOST 1
  112.     choice= ' '
  113.  
  114.     CALL showmenu
  115.     CALL wsend '^[[0m'
  116.     CALL wsend '^[[19;12H'
  117.     
  118.     IF status= 'super' THEN
  119.         CALL wsend '"Your Choice (C/F/S/T/U/D/H/G): "'
  120.     ELSE
  121.         CALL wsend '"Your Choice (F/T/U/D/G): "'
  122.  
  123.  
  124. menuask:
  125.     WAIT '^M'
  126.  
  127.     /* if the carrier was lost, restart the whole story */
  128.     IF zoccarrier()=='NO CARRIER' THEN SIGNAL endit
  129.  
  130.     /* if input timed out redo input */
  131.     IF rc <> 0 THEN SIGNAL menuask
  132.  
  133.     /* text cosmetics for user input string */
  134.     choice= zoclastline()
  135.     choice= STRIP(choice)
  136.  
  137.     /* change directory */
  138.     IF (choice='C' | choice='c') & status= 'super' THEN CALL changedir
  139.  
  140.     /* show files in directory */
  141.     IF choice='F' | choice='f' THEN CALL showdir ddir
  142.  
  143.     /* search for entry */
  144.     IF (choice='S' | choice='s') & status= 'super' THEN CALL search
  145.  
  146.     /* type file */
  147.     IF choice='T' | choice='t' THEN CALL type
  148.  
  149.     /* zmodem upload */
  150.     IF choice='U' | choice='u' THEN CALL upload
  151.  
  152.     /* zmodem download */
  153.     IF choice='D' | choice='d' THEN CALL download
  154.  
  155.     /* shutdown host */
  156.     IF (choice='H' | choice='h') & status= 'super' THEN CALL shutdown
  157.  
  158.     /* goodbye */
  159.     IF choice='G' | choice='g' THEN
  160.     DO
  161.         CALL wsend '^[[21;12H'
  162.         CALL wsend '"Have a nice day ...^M^J"'
  163.         SIGNAL endit
  164.     END
  165.     
  166.     SIGNAL menu
  167.  
  168.  
  169. endit:
  170.     
  171.     /* give the other side no echo */
  172.     SETHOST 0
  173.     HANGUP
  174.     DELAY 5
  175.     SIGNAL allover
  176.  
  177.  
  178.  
  179. /* ============================================================== */
  180. /* SUBROUTINES                                                    */
  181. /* ============================================================== */
  182.  
  183. /* -------------------------------------------------------------- */
  184. /* change current directory                                       */
  185. /* -------------------------------------------------------------- */
  186. changedir:
  187.     
  188.     CALL wsend '^[[21;12H'
  189.     CALL wsend '"Enter full directory path: "'
  190.     WAIT '^M'
  191.  
  192.     IF rc= 0 THEN
  193.     DO
  194.         curdir= zoclastline()
  195.         IF RIGHT(curdir, 1) \= '\' THEN curdir= curdir'\'
  196.         IF SUBSTR(curdir, 2, 1) = ':' THEN
  197.         DO
  198.             curdrive= SUBSTR(curdir, 1, 2)
  199.             curdir= RIGHT(curdir, length(curdir)-2)
  200.         END
  201.         IF SUBSTR(curdir, 1, 1) \= '\' THEN curdir= '\'curdir
  202.     END
  203.     
  204.     RETURN
  205.  
  206.  
  207. /* -------------------------------------------------------------- */
  208. /* show current directory                                         */
  209. /* -------------------------------------------------------------- */
  210. showdir: 
  211.     ADDRESS CMD '"dir 'curdrive||curdir' >shellout.tmp"'
  212.     CALL wsend '^[[2J^[[1H'
  213.     UPLOAD 'a1+0' 'shellout.tmp'
  214.     ADDRESS CMD 'del shellout.tmp'
  215.     CALL wsend '^M^J'
  216.     CALL wsend '"Press Enter to return..."'
  217.     WAIT '^M'
  218.     RETURN
  219.  
  220.  
  221. /* -------------------------------------------------------------- */
  222. /* search on current drive                                        */
  223. /* -------------------------------------------------------------- */
  224. search: 
  225.     CALL wsend '^[[21;12H'
  226.     CALL wsend '"Enter filename to search on drive 'curdrive' "'
  227.     WAIT '^M'
  228.     
  229.     IF rc= 0 THEN
  230.     DO
  231.         sname= zoclastline()
  232.         sname= STRIP(sname)
  233.     END
  234.     ELSE
  235.         RETURN
  236.     
  237.     CALL wsend '^[[22;12H'
  238.     CALL wsend '"Searching on drive 'curdrive', please wait ..."'
  239.     ADDRESS CMD '"dir 'curdrive'\'sname' /s >shellout.tmp"'
  240.     CALL wsend '^[[2J^[[1H'
  241.     UPLOAD 'a1+0' 'shellout.tmp' 
  242.     ADDRESS CMD 'del shellout.tmp'
  243.     CALL wsend '^M^J'
  244.     CALL wsend '"Press Enter to return..."'
  245.     WAIT '^M'
  246.     RETURN
  247.  
  248.  
  249. /* -------------------------------------------------------------- */
  250. /* type file                                                      */
  251. /* -------------------------------------------------------------- */
  252. type: 
  253.     CALL wsend '^[[21;12H'
  254.     CALL wsend '"Enter filename to type: 'curdrive||curdir'"'
  255.     WAIT '^M'
  256.     
  257.     IF rc= 0 THEN
  258.     DO
  259.         sname= zoclastline()
  260.         sname= STRIP(sname)
  261.     END
  262.     ELSE
  263.         RETURN
  264.     
  265.     ADDRESS CMD '"type 'curdrive||curdir||sname' >shellout.tmp"'
  266.     CALL wsend '^[[2J^[[1H'
  267.     UPLOAD 'a1+0' 'shellout.tmp' 
  268.     ADDRESS CMD 'del shellout.tmp'
  269.     CALL wsend '^M^J'
  270.     CALL wsend '"Press Enter to return..."'
  271.     WAIT '^M'
  272.     RETURN
  273.  
  274.  
  275. /* -------------------------------------------------------------- */
  276. /* upload file                                                    */
  277. /* -------------------------------------------------------------- */
  278. upload:
  279.     CALL wsend '^[[21;12H'
  280.     CALL wsend '"Please start your Zmodem upload"'
  281.     CALL wsend '^[[22;12H'
  282.     
  283.     SAY curdrive||curdir
  284.     DOWNLOAD z curdrive||curdir 
  285.     RETURN
  286.  
  287.  
  288. /* -------------------------------------------------------------- */
  289. /* download file                                                  */
  290. /* -------------------------------------------------------------- */
  291. download:
  292.     CALL wsend '^[[21;12H'
  293.     CALL wsend '"Enter filename to receive: 'curdrive||curdir'"'
  294.     WAIT '^M'
  295.     CALL wsend '^[[22;12H'
  296.  
  297.     IF rc= 0 THEN
  298.     DO
  299.         file= zoclastline()
  300.         file= STRIP(file)
  301.     END
  302.     ELSE
  303.         RETURN
  304.  
  305.     IF file \= '' THEN
  306.         UPLOAD z curdrive||curdir||file
  307.     RETURN
  308.  
  309.  
  310. /* -------------------------------------------------------------- */
  311. /* Shutdown host                                                  */
  312. /* -------------------------------------------------------------- */
  313. shutdown:
  314.     CALL wsend '^[[21;12H'
  315.     CALL wsend '"Hostmode will be quit now ...^M^J"'
  316.     SETHOST 0
  317.     HANGUP
  318.     DELAY 5
  319.     SETAUTOANSWER 0
  320.     EXIT
  321.  
  322.  
  323. /* ============================================================== */
  324. /* HELP-FUNCTIONS */
  325. /* ============================================================== */
  326.  
  327. /* -------------------------------------------------------------- */
  328. /* draw one menu-point with ARG(line, col, shortcut, name)        */
  329. /* -------------------------------------------------------------- */
  330. menupoint:
  331.     
  332.     CALL wsend '"^[['ARG(1)';'ARG(2)'H"'
  333.     CALL wsend '"^[[1;37;47m┌───^[[0;30;47m┐"'
  334.     CALL wsend '"^[[1;37m┌────────────────────^[[0;30;47m┐^[[40m"'
  335.  
  336.     CALL wsend '"^[['ARG(1)+1';'ARG(2)'H"'
  337.     CALL wsend '"^[[1;37;47m│ ^[[0;34;47m'ARG(3)' ^[[30m│"'
  338.     CALL wsend '"^[[1;37m│^[[0;30;47m'ARG(4)'│^[[40m"'
  339.  
  340.     CALL wsend '"^[['ARG(1)+2';'ARG(2)'H"'
  341.     CALL wsend '"^[[1;37;47m└^[[0;30;47m───┘"'
  342.     CALL wsend '"^[[1;37m└^[[0;30;47m────────────────────┘^[[40m"'
  343.  
  344.     RETURN
  345.  
  346.  
  347. /* -------------------------------------------------------------- */
  348. /* draw one info-point with ARG(line, col, text)                  */
  349. /* -------------------------------------------------------------- */
  350. infopoint:
  351.     
  352.     CALL wsend '"^[['ARG(1)';'ARG(2)'H"'
  353.     CALL wsend '"^[[1;37;47m┌──────────────────────────────────"'
  354.     CALL wsend '"──────────────────────────^[[0;30;47m┐"'
  355.  
  356.     CALL wsend '"^[['ARG(1)+1';'ARG(2)'H"'
  357.     CALL wsend '"^[[1;37;47m│ ^[[0;30;47m'ARG(3)' ^[[30m│"'
  358.     
  359.     CALL wsend '"^[['ARG(1)+2';'ARG(2)'H"'
  360.     CALL wsend '"^[[1;37;47m└^[[0;30;47m────────────────────────"'
  361.     CALL wsend '"────────────────────────────────────┘"'
  362.  
  363.     RETURN
  364.  
  365.  
  366. /* -------------------------------------------------------------- */
  367. /* draw the whole menu with alle menu- and info-points            */
  368. /* -------------------------------------------------------------- */
  369. showmenu:
  370.     CALL wsend '"^[[2J^[[1H"'
  371.  
  372.     IF status= 'super' THEN
  373.     DO
  374.         CALL menupoint 2,  10, 'C', ' (C)hange directory '
  375.         CALL menupoint 5,  10, 'F', ' Show dir (F)iles   ' 
  376.         CALL menupoint 8,  10, 'S', ' (S)earch a file    '
  377.         CALL menupoint 11, 10, 'T', ' (T)ype a file      ' 
  378.         CALL menupoint 2,  45, 'U', ' (U)pload a file    '
  379.         CALL menupoint 5,  45, 'D', ' (D)ownload a file  '
  380.         CALL menupoint 8,  45, 'H', ' Shutdown (H)ost    '
  381.         CALL menupoint 11, 45, 'G', ' (G)oodbye          '
  382.      END
  383.     ELSE
  384.     DO
  385.         CALL menupoint 3,  10, 'F', ' Show dir (F)iles   ' 
  386.         CALL menupoint 6,  10, 'T', ' (T)ype a file      ' 
  387.         CALL menupoint 3,  45, 'U', ' (U)pload a file    '
  388.         CALL menupoint 6,  45, 'D', ' (D)ownload a file  '
  389.         CALL menupoint 10, 27, 'G', ' (G)oodbye          '
  390.     END
  391.     
  392.     curpath= curdrive||curdir
  393.     CALL infopoint 15, 10, '^[[0;34;47mCurrent Dir:^[[30m  'overlay(curpath,'                                            ')
  394.     RETURN
  395.  
  396.  
  397. /* -------------------------------------------------------------- */
  398. /* draw beginning text                                            */
  399. /* -------------------------------------------------------------- */
  400. welcome:
  401.     CALL wsend '"                 ^M^J"'
  402.     CALL wsend '" ___  ___ ___    ^M^J"'
  403.     CALL wsend '"|__ || _ | __|   ^M^J"'
  404.     CALL wsend '" / /_||_|| |_     ZOC RexxHost-Script V1.0^M^J"'
  405.     CALL wsend '"|____|___|___|   ^M^J^M^J^M^J"'
  406.  
  407.     RETURN
  408.  
  409.  
  410. /* -------------------------------------------------------------- */
  411. /* send and write at the same time                                */
  412. /* -------------------------------------------------------------- */
  413. wsend:
  414.  
  415.     SEND ARG(1)
  416.     WRITE ARG(1)
  417.  
  418.     RETURN
  419.  
  420.  
  421.  
  422.  
  423.  
  424. /* END OF REXX-MODULE */
  425.  
  426.