home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / hostmode / hostmode.ksc < prev    next >
Text File  |  2020-01-01  |  29KB  |  1,115 lines

  1. ; HOSTMODE.KSC
  2. ;
  3. ; Utility and management functions for Kermit 95 host mode.
  4. ; Authors: F. da Cruz, C. Gianone
  5. ; Date: December 1995 - January 1996
  6. ; Updated February 1997 for OS/2
  7. ; Updated June 1997 for TAPI
  8. ; Setting of MAXUSERS fixed, December 1997.
  9. ; Recommendations of J.v.Jena jvjena@cs.tu-berlin.de incorporated, March 2000
  10. ; Corrections to _k95program and location of default host.cfg file, Apr 6, 2000
  11. ; More of same plus conversion to modern syntax, fdc, 6 July 2001.
  12. ;
  13. ; Uses of hostmode.bat:
  14. ; - hostmode.bat makes the following assumptions:
  15. ;   an empty setting for the CFG variable (default) uses host.cfg
  16. ;   in the SCRIPTS subdirectory.
  17. ; - A nonempty string as CFG value specifies a different subdirectory.
  18. ;   If this subdirectory does not already exist, it is created and
  19. ;   host.cfg is copied to it from the SCRIPTS subdirectory.  You can change
  20. ;   and save this configuration.
  21. ; - Thus you can have different HOSTxxxx.BAT files that specify different
  22. ;   CFG values to pick up different configurations.
  23. ;
  24. ; Use of shortcuts to [scripts]/hostmode.ksc:
  25. ; - Assuming the .ksc extension is registered by k95regtl,
  26. ;   create a shortcut for every needed hostmode configuration.
  27. ;   Set the work directory in the properties contextmenu of the
  28. ;   new shortcut to an existing directory. Host.cfg will be put
  29. ;   there.  If you leave the work directory unchanged you get the
  30. ;   default behavior (host.cfg in the scripts directory).
  31. ;
  32. undef _config_changed
  33. undef _userdb_changed
  34. undef _userdb_locked
  35. undef _userdb_loaded
  36. undef _current_user
  37. undef _current_id
  38.  
  39. if < \v(xversion) 1120 stop 1 K95 1.1.20 or later required.
  40.  
  41. asg _k95program \freplace(\v(exedir)k95.exe,/,\\)
  42. asg _k95d_program \freplace(\v(exedir)k95d.exe,/,\\)
  43. if eq "\v(system)" "OS/2" asg _k95program \freplace(\v(exedir)k2.exe,/,\\)
  44.  
  45. ; CLS is built in now.
  46. ; def CLS write screen \27[H\27[2J
  47.  
  48. def UNLOCK {
  49.     if exist \m(_lockfile) delete \m(_lockfile)
  50.     undef _userdb_locked
  51. }
  52.  
  53. def LOCK {
  54.     if def _userdb_locked end 1
  55.     if exist \m(_lockfile) {
  56.     echo LOCKFILE \m(_lockfile) in use by:
  57.     type \m(_lockfile)
  58.     end 2
  59.     }
  60.     open write \m(_lockfile)
  61.     if fail end 3
  62.     writeln file PROPRIETOR
  63.     if fail end 4
  64.     close write
  65.     if fail end 5
  66.     def _userdb_locked 1
  67.     end 0
  68. }
  69. def HOLDSCREEN echo, getc \%9 {Press Enter to continue: }, goto \%1
  70.  
  71. def MAKEVAR2 _assign \%1 \%2
  72.  
  73. def MAKEVAR {
  74.     if = \findex(=,\%1,1) 0 end
  75.     asg \%9 _\freplace(\%1,=,\32)
  76.     makevar2 \%9
  77. }
  78.  
  79. ; The following code was added to accomodate the new Windows multi-user
  80. ; friendly directory layouts introduced with version 1.1.21.  We have
  81. ; check several locations for the directories that hostmode uses and
  82. ; create them in \v(appdata) if the do not exist at all.
  83.  
  84. if exist \v(common)SCRIPTS/hostmode.ksc {
  85.    asg _hostscripts \v(common)
  86. }
  87.  
  88. if exist \v(appdata)SCRIPTS/hostmode.ksc {
  89.    asg _hostscripts \v(appdata)
  90. }
  91.  
  92. if directory \v(exedir)USERS {
  93.     asg _hostroot \v(exedir)
  94.     forward FOUNDDIRS
  95. }
  96. if directory \v(startup)INCOMING {
  97.     asg _hostroot \v(startup)
  98.     forward FOUNDDIRS
  99. }
  100.  
  101. if directory \v(appdata)INCOMING {
  102.     asg _hostroot \v(appdata)
  103.     forward FOUNDDIRS
  104. }
  105.  
  106. cls
  107. echo {Could not find necessary hostmode dirs, creating them...}
  108. if not directory \v(appdata)USERS if not exist \v(appdata)USERS {
  109.    mkdir \v(appdata)USERS
  110. }
  111. if not directory \v(appdata)PUBLIC if not exist \v(appdata)PUBLIC {
  112.    mkdir \v(appdata)PUBLIC
  113. }
  114. if not directory \v(appdata)INCOMING if not exist \v(appdata)INCOMING {
  115.    mkdir \v(appdata)INCOMING
  116. }
  117. if not directory \v(appdata)LOGS if not exist \v(appdata)LOGS {
  118.    mkdir \v(appdata)LOGS
  119. }
  120. if not directory \v(appdata)TMP if not exist \v(appdata)TMP {
  121.    mkdir \v(appdata)TMP
  122. }
  123.  
  124. if not exist \v(appdata)USERS/hostmode.txt {
  125.    copy \m(_hostscripts)USERS/*.TXT \v(appdata)USERS
  126. }
  127.  
  128. if not exist \v(appdata)PUBLIC/hostuser.txt {
  129.    copy \m(_hostscripts)PUBLIC/*.TXT \v(appdata)PUBLIC
  130. }
  131.  
  132. echo
  133. echo {Directories created in \v(appdata)...}
  134. asg _hostroot \v(appdata)
  135. holdscreen FOUNDDIRS
  136.  
  137. :FOUNDDIRS
  138.  
  139. asg _maxusers 100 ; In case there is no config file
  140.  
  141. def _haveconfig 0         ; Have not found config file yet
  142. asg _configfile host.cfg  ; Use config file in current directory
  143. echo STARTING...
  144. if not exist \m(_hostroot)\m(_configfile) {
  145.     if not exist \m(_hostscripts)scripts/host.cfg {
  146.     ec File \m(_configfile) not found - using built-in configuration
  147.         sleep 3
  148.         forward NOCONFIG
  149.     }
  150.  
  151.     if exist \m(_hostscripts)scripts/host.cfg {
  152.         xecho COPYING \m(_hostscripts)scripts/host.cfg to \m(_hostroot)...
  153.         copy \m(_hostscripts)scripts/host.cfg \m(_hostroot)
  154.         if fail {
  155.            echo FAILED
  156.            forward NOCONFIG
  157.         }
  158.         echo OK
  159.     }
  160. }
  161. echo Configuration file = \m(_hostroot)\m(_configfile)
  162. open read \m(_hostroot)\m(_configfile)
  163. if fail forward NOCONFIG
  164. def _haveconfig 1
  165. echo Loading configuration...
  166. while true { read aline, if fail break, makevar \m(aline) }
  167.  
  168. :NOCONFIG
  169. sleep 1
  170.  
  171. dcl \&u[\m(_maxusers)]
  172. if not def _lockfile asg _lockfile \m(_usertree)/USERS.LCK
  173.  
  174. define SAVEUSERDB {
  175.     if exist \fdef(_userbak) del \fdef(_userbak)
  176.     rename \fdef(_userfile) \fdef(_userbak)
  177.     if fail echo {Warning - Failure to back up user database}
  178.     open write \fdef(_userfile)
  179.     if fail {
  180.     echo Failed to open \fdef(_userfile)
  181.         holdscreen LBL_9
  182.     }
  183.     for \%i 1 \&u[0] 1 {
  184.     writeln file \&u[\%i]
  185.     if fail {
  186.         ec, ec Error writing record \%i to \fdef(_userfile)
  187.         ec Old version preserved as \fdef(_userbak)
  188.         break
  189.     }
  190.     }
  191.     close write
  192.     asg \%9 \v(status)
  193.     UNLOCK
  194.     echo
  195.     if not = \%9 0 echo {WARNING - Failed to close \fdef(_userfile)}
  196.     else echo {\fdef(_userfile) saved: \&u[0] records}
  197.     undef _userdb_changed
  198.     undef _userdb_loaded
  199.     undef _current_user
  200.     end \%9
  201. }
  202.  
  203. define SAVECONFIG {
  204.     asg \%8 \freplace(\m(_hostroot)\m(_configfile),\\,/)
  205.     asg \%9 \freplace(\%8,.CFG,.BAK)
  206.     if exist \%9 delete \%9
  207.     rename \%8 \%9
  208.     if fail echo WARNING - Failed to back up "\%8" to "\%9"
  209.     open write \m(_hostroot)\m(_configfile)
  210.     if fail { echo Failed to open \m(_configfile), end 1 }
  211.     writeln file SESSIONS=\m(_sessions)
  212.     writeln file MAXUSERS=\m(_maxusers)
  213.     writeln file INACTIVITY=\m(_inactivity)
  214.     writeln file LOGINTIME=\m(_logintime)
  215.     writeln file HOSTPORT=\m(_hostport)
  216.     writeln file COMMPORT={\m(_commport)}
  217.     writeln file COMSPEED=\m(_comspeed)
  218.     writeln file MODEM=\m(_modem)
  219.     writeln file ANONOK=\m(_anonok)
  220.     writeln file LOGGING=\m(_logging)
  221.     writeln file DLINCOMING=\m(_dlincoming)
  222.     writeln file MSGMAX=\m(_msgmax)
  223.     writeln file PROTOCOL=\m(_protocol)
  224.     writeln file XFERMODE=\m(_xfermode)
  225.     writeln file OWNER={\m(_owner)}
  226.     writeln file HERALD={\m(_herald)}
  227.     writeln file PUBLIC=\m(_public)
  228.     writeln file INCOMING=\fdef(_incoming)
  229.     writeln file LOGDIR=\fdef(_logdir)
  230.     writeln file USERTREE=\fdef(_usertree)
  231.     writeln file TMPDIR=\fdef(_tmpdir)
  232.     writeln file USERFILE=\fdef(_userfile)
  233.     writeln file GREETING=\fdef(_greeting)
  234.     writeln file HELPFILE=\fdef(_helpfile)
  235.     writeln file MSGFILE=\fdef(_msgfile)
  236.     close write
  237.     if success def _config_changed
  238.     else end 1
  239. }
  240.  
  241. ; SPLIT and GETFIELDS are for parsing user database records
  242. ;
  243. def SPLIT {
  244.     asg \%9 \findex(_,\%1)
  245.     asg _LEFT \fbreak(\%1,_)
  246.     asg _RIGHT \fsubstr(\%1,\%9+1)
  247. }
  248.  
  249. def GETFIELDS {
  250.     split {\%1}
  251.     asg U_ID \m(_LEFT)
  252.     split {\m(_RIGHT)}
  253.     asg U_PW \m(_LEFT)
  254.     split {\m(_RIGHT)}
  255.     asg U_PR \m(_LEFT)
  256.     split {\m(_RIGHT)}
  257.     asg U_NM \m(_LEFT)
  258.     split {\m(_RIGHT)}
  259.     asg U_AD \m(_LEFT)
  260.     split {\m(_RIGHT)}
  261.     asg U_TP \m(_LEFT)
  262.     split {\m(_RIGHT)}
  263.     asg U_EM \m(_LEFT)
  264. }
  265.  
  266. :BEGIN ; Program execution starts here...
  267.  
  268. def _priv_cd  1                ; Symbolic constants.
  269. def _priv_dos 2
  270.  
  271.                                         ; Remember startup values of these
  272. if tapi asg _myport {tapi \v(line)}
  273. if not def _myport asg _myport \v(line)    
  274. asg _myspeed \v(speed)
  275. asg _mymodem \v(modem)
  276.  
  277. set exit warning off            ; Now deassign all comm devices
  278. close
  279.  
  280. :LOOP
  281. asg _userbak \freplace(\m(_userfile),.DAT,.BAK)
  282. cls
  283. echo K-95 Host Mode Management
  284. echo
  285. if def _userdb_locked echo * User database is locked *
  286. else echo User database is not loaded
  287. echo
  288. echo { 1 - Start host mode}
  289. echo { 2 - View configuration}
  290. echo { 3 - Change configuration}
  291. echo { 4 - Save configuration}
  292. echo { 5 - Read messages from users}
  293. echo { 6 - Leave a message for a user}
  294. echo { 7 - View/edit current greeting message}
  295. echo { 8 - Post a new greeting message}
  296. echo { 9 - Manage user database}
  297. echo {10 - Help}
  298. echo {11 - Exit}
  299. echo
  300. ask \%a {Your choice: }
  301. if not def \%a goto loop
  302. if not num \%a {
  303.     ec "\%a" - Not a number
  304.     sleep 1
  305.     goto loop
  306. }
  307. if > \%a 0 if not > \%a 11 forward LBL_\%a
  308. echo "\%a" - out of range
  309. sleep 1
  310. goto loop
  311.  
  312. :LBL_1
  313. cls
  314. echo Start Host Mode...
  315. echo
  316. echo { 1 - Telnet}
  317. echo { 2 - Dialup}
  318. echo { 3 - Direct COM port}
  319. echo { 4 - Return to main menu}
  320. echo
  321. ask \%a {Your choice: }
  322. if not def \%a goto LBL_1
  323. if not num \%a {
  324.     ec "\%a" - not a number
  325.     sleep 1
  326.     goto LBL_1
  327. }
  328. if > \%a 0 if not > \%a 4 forward START_\%a
  329. echo "\%a" - out of range
  330. sleep 1
  331. goto LBL_1
  332.  
  333. :START_1 ; Telnet
  334. cls
  335. echo
  336. if def _hostport forw start_1a
  337. echo HOSTPORT not configured.
  338. echo Please choose "Change configuration".
  339. holdscreen LOOP
  340.  
  341. :START_1A
  342. echo Starting Kermit 95 mode on TCP port \m(_hostport).
  343. getok {OK? }
  344. if fail goto loop
  345. if not def _config_changed forward start_1b
  346. echo
  347. getok {Configuration has changed - do you want to save it first? (y/n) }
  348. if success saveconfig
  349.  
  350. :START_1B
  351. if eq "\v(system)" "WIN32" forward S1BWIN32
  352. if not eq "\v(system)" "OS/2" {
  353.     echo Sorry - so far this only works for Windows 95/NT and OS/2...
  354.     holdscreen LOOP
  355. }
  356. if > \m(_sessions) 1 {
  357.     echo To start a TCP/IP host mode listener in OS/2 please follow the
  358.     echo instructions in DOCS\MANUAL\OS2K95.HTML.
  359.     holdscreen LOOP
  360. }
  361. run start \m(_k95program) \m(_hostscripts)scripts/hosttcp.ksc
  362. goto loop
  363.  
  364. :S1BWIN32
  365. if > \m(_sessions) 1 -
  366.  run start -
  367.   \m(_k95d_program) \m(_hostport) "take \m(_hostscripts)scripts/host.ksc, exit"
  368. else run start \m(_k95program) \m(_hostscripts)scripts/hosttcp.ksc
  369. goto loop
  370.  
  371. :START_2
  372. cls
  373. echo
  374. if not eq "\m(_commport)" "" forward START_2B
  375. echo COMMPORT not configured.
  376. getok {Use TAPI (Windows modem device)? }
  377. if success { asg _commport tapi, asg _modem tapi, goto start_2b }
  378.  
  379. echo
  380. echo The following settings were made in your K-95 initialization file:
  381. echo
  382. echo { set modem \m(_mymodem)}
  383. echo { set port \m(_myport)}
  384. echo { set speed \m(_myspeed)}
  385. echo
  386. getok {Use them? }
  387. if success forward START_2C
  388.  
  389. :START_2A
  390. echo
  391. echo Please "Change configuration" to choose or modify serial device settings.
  392. holdscreen LOOP
  393.  
  394. :START_2B
  395. echo Starting Kermit 95 host mode...
  396. echo Will wait for a call on port \m(_commport).
  397. if def _comspeed echo Speed: \m(_comspeed)
  398. echo Modem: \m(_modem)
  399.  
  400. :START_2C
  401. getok {OK? }
  402. if fail goto loop
  403. if not def _config_changed forward start_2d
  404. echo
  405. getok {Configuration has changed - do you want to save it first? (y/n) }
  406. if success saveconfig
  407.  
  408. :START_2D
  409. run start \m(_k95program) \freplace(\m(_hostscripts)scripts/hostmdm.ksc,/,\\)
  410. goto LOOP
  411.  
  412. :START_3
  413. cls
  414. echo
  415. if def \m(_commport) forward START_3C
  416. echo COMMPORT not configured.
  417. if equal "\v(connection)" "serial" forward START_3B
  418. forward START_3A
  419. :START_3B
  420. echo
  421. echo The following settings were made in your K-95 initialization file:
  422. echo
  423. if tapi echo { set port tapi \v(line)}
  424. else echo { set port \v(line)}
  425. echo { set speed \v(speed)}
  426. echo
  427. getok {Use them? }
  428. if success forward START_3C
  429.  
  430. :START_3A
  431. echo
  432. echo Please "Change configuration" to choose or modify serial device settings.
  433. holdscreen LOOP
  434.  
  435. :START_3C
  436. if not def _config_changed forward start_3d
  437. echo
  438. getok {Configuration has changed - do you want to save it first? (y/n) }
  439. if success saveconfig
  440.  
  441. :START_3D
  442. echo
  443. echo Using direct connection on \m(_commport) at \m(_comspeed) bps.
  444. echo
  445. echo Starting Kermit 95 host mode...
  446. run start \m(_k95program) \freplace(\m(_hostscripts)scripts/hostcom.ksc,/,\\)
  447.  
  448. :START_4
  449. goto loop
  450.  
  451. :LBL_2 ; View configuration
  452. if = \m(_haveconfig) 0 {
  453.     echo Can't find configuration file
  454.     holdscreen LOOP
  455. }
  456. echo
  457. echo SESSIONS=\m(_sessions)
  458. echo MAXUSERS=\m(_maxusers)
  459. echo INACTIVITY=\m(_inactivity)
  460. echo HOSTPORT=\m(_hostport)
  461. echo COMMPORT=\m(_commport)
  462. echo COMSPEED=\m(_comspeed)
  463. echo ANONOK=\m(_anonok)
  464. echo LOGGING=\m(_logging)
  465. echo DLINCOMING=\m(_dlincoming)
  466. echo MSGMAX=\m(_msgmax)
  467. echo PROTOCOL=\m(_protocol)
  468. echo XFERMODE=\m(_xfermode)
  469. echo OWNER=\m(_owner)
  470. echo HERALD=\m(_herald)
  471. echo PUBLIC=\m(_public)
  472. echo INCOMING=\m(_incoming)
  473. echo LOGDIR=\m(_logdir)
  474. echo USERTREE=\m(_usertree)
  475. echo TMPDIR=\m(_tmpdir)
  476. echo USERFILE=\m(_userfile)
  477. echo GREETING=\m(_greeting)
  478. echo HELPFILE=\m(_helpfile)
  479. echo MSGFILE=\m(_msgfile)
  480. echo
  481. clear
  482. ask \%a Press the Enter key to return to main menu...
  483. goto loop
  484.  
  485. :LBL_3 ; Change config
  486. if not eq \m(_haveconfig) 0 forward getchanges
  487. ;
  488. ; Set defaults in case they don't have a config file
  489. ;
  490. asg _sessions 1                       ; Maximum number of Telnet sessions
  491. asg _maxusers 100                     ; Maximum number of user IDs
  492. asg _inactivity 1200                  ; Inactivity limit (seconds)
  493. asg _anonok 1                         ; Anonymous logins OK (0 = not OK)
  494. asg _logging 1                        ; Logging enabled (0 = skip logging)
  495. asg _dlincoming 0                     ; OK to download from INCOMING directory
  496. asg _msgmax 200                       ; Longest message size (lines)
  497. asg _protocol kermit                  ; Default file transfer protocol
  498. asg _xfermode binary                  ; Default file transfer mode
  499. asg _owner THE PROPRIETOR             ; Substitute your name, company name, etc
  500. asg _herald Welcome to K-95 Host Mode ; 
  501. asg _public   \m(_hostroot)PUBLIC     ; Directory that users can get files from
  502. asg _incoming \m(_hostroot)INCOMING   ; Directory that users can send file to
  503. asg _logdir   \m(_hostroot)LOGS       ; Directory for host-mode logs
  504. asg _usertree \m(_hostroot)USERS      ; Root of user directory tree
  505. asg _tmpdir   \m(_hostroot)TMP        ; Directory for temp files
  506. asg _userfile \m(_usertree)/USERS.DAT ; User database file
  507. asg _greeting \m(_usertree)/GREETING.TXT ; Message/greeting text filename
  508. asg _helpfile \m(_usertree)/HOSTMODE.TXT ; Host-mode help file
  509. asg _msgfile  \m(_usertree)/MESSAGES.TXT ; Messages for proprietor
  510.  
  511. :GETCHANGES
  512.  
  513. :CF0
  514. ask \%a { Maximum TCP/IP host sessions [\m(_sessions)]: }
  515. if not def \%a forward CFA
  516. if not numeric \%a goto CF0
  517. getok { SESSIONS=\%a, OK? (y/n): }
  518. if fail goto CF0
  519. asg _config_changed 1
  520. asg _sessions \%a
  521.  
  522. :CFA
  523. ask \%a { Maximum number of user IDs [\m(_maxusers)]: }
  524. if not def \%a forward CF1
  525. if not numeric \%a goto CFA
  526. getok { MAXUSERS=\%a, OK? (y/n): }
  527. if fail goto CFA
  528. asg _config_changed 1
  529. asg _maxusers \%a
  530.  
  531. :CF1
  532. ask \%a { Inactivity limit, seconds [\m(_inactivity)]: }
  533. if not def \%a forward CF2
  534. if not numeric \%a goto CF1
  535. getok { INACTIVITY=\%a, OK? (y/n): }
  536. if fail goto CF1
  537. asg _config_changed 1
  538. asg _inactivity \%a
  539. :CF2
  540. ask \%a { TCP port for incoming TCP/IP connections [\m(_hostport)]: }
  541. if not def \%a forward CF3
  542. getok { HOSTPORT=\%a, OK? (y/n): }
  543. if fail goto CF2
  544. asg _config_changed 1
  545. asg _hostport \%a
  546. :CF3
  547. ask \%a { Communications port for incoming dialups [\m(_commport)]: }
  548. if not def \%a forward CF4
  549. getok { COMMPORT=\%a, OK? (y/n): }
  550. if fail goto CF3
  551. asg _config_changed 1
  552. asg _commport \%a
  553. :CF4
  554. ask \%a { Speed of \m(_commport) [\m(_comspeed)]: }
  555. if not def \%a goto CF5
  556. if < 0 \findex(:\%a:,:14400:19200:38400:28800:57600:115200:) forward CF4A
  557. if < 0 \findex(:\%a:,:230400:1200:2400:9600:300:600:1800:4800:) forward CF4A
  558. echo "\%a" - Unknown speed
  559. goto CF4
  560. :CF4A
  561. getok { SPEED=\%a, OK? (y/n): }
  562. if fail goto CF4
  563. asg _config_changed 1
  564. asg _comspeed \%a
  565. :CF5
  566. ask \%a { Type of modem on \m(_commport) [\m(_modem)]: }
  567. if not def \%a forward CF6
  568. getok { MODEM=\%a, OK? (y/n): }
  569. if fail goto CF5
  570. set modem type \%a
  571. if fail {
  572.     echo "\%a" - Unknown modem type
  573.     goto CF5
  574. }
  575. asg _config_changed 1
  576. asg _modem \%a
  577. :CF6
  578. ask \%a { Anonymous guest logins OK (1 = yes, 0 = no) [\m(_anonok)]: }
  579. if not def \%a forward CF7
  580. if not num \m(_anonok) goto CF6
  581. getok { ANONOK=\%a, OK? (y/n): }
  582. if fail goto CF6
  583. asg _config_changed 1
  584. asg _anonok \%a
  585. :CF7
  586. ask \%a { Maximum number of lines for a message [\m(_msgmax)]: }
  587. if not def \%a forw CF8
  588. if not num \m(_msgmax) goto CF7
  589. getok { MSGMAX=\%a, OK? (y/n): }
  590. if fail goto CF7
  591. asg _config_changed 1
  592. asg _msgmax \%a
  593. :CF8
  594. ask \%a { Default file transfer protocol [\m(_protocol)]: }
  595. if not def \%a forw CF9
  596. set protocol \%a
  597. if fail {
  598.     echo "\%a" - Bad protocol
  599.     goto CF8
  600. }
  601. getok { PROTOCOL=\%a, OK? (y/n): }
  602. if fail goto CF8
  603. asg _config_changed 1
  604. asg _protocol \%a
  605. :CF9
  606. ask \%a { Default file transfer mode (text or binary) [\m(_xfermode)]: }
  607. if not def \%a forw CF10
  608. set file type \%a
  609. if fail goto CF9
  610. getok { XFERMODE=\%a, OK? (y/n): }
  611. if fail goto CF9
  612. asg _config_changed 1
  613. asg _xfermode \%a
  614. :CF10
  615. ask \%a { PC owner's or company's name for users to see [\m(_owner)]: }
  616. if not def \%a forw CF11
  617. getok { OWNER=\%a, OK? (y/n): }
  618. if fail goto CF10
  619. asg _config_changed 1
  620. asg _owner \%a
  621. :CF11
  622. ask \%a { Main menu title [\m(_herald)]: }
  623. if not def \%a forw CF12
  624. getok { HERALD=\%a, OK? (y/n): }
  625. if fail goto CF11
  626. asg _config_changed 1
  627. asg _herald \%a
  628. :CF12
  629. ask \%a { Directory readable by all users [\m(_public)]: }
  630. if not def \%a forw CF13
  631. getok { PUBLIC=\%a, OK? (y/n): }
  632. if fail goto CF12
  633. asg _config_changed 1
  634. asg _public \%a
  635. :CF13
  636. ask \%a { Directory writeable by all users [\m(_incoming)]: }
  637. if not def \%a forw CF14
  638. getok { INCOMING=\%a, OK? (y/n): }
  639. if fail goto CF13
  640. asg _config_changed 1
  641. asg _incoming \%a
  642. :CF14
  643. ask \%a { Directory for temporary files [\m(_tmpdir)]: }
  644. if not def \%a forw CF15
  645. getok { TMPDIR=\%a, OK? (y/n): }
  646. if fail goto CF14
  647. asg _config_changed 1
  648. asg _tmpdir \%a
  649. :CF15
  650. ask \%a -
  651. { OK to download from INCOMING directory (1 = yes, 0 = no) [\m(_dlincoming)]: }
  652. if not def \%a forw CF16
  653. if not numeric \%a goto CF15
  654. getok { DLINCOMING=\%a, OK? (y/n): }
  655. if fail goto CF15
  656. asg _config_changed 1
  657. asg _dlincoming \%a
  658. :CF16
  659. ask \%a { Keep log files (1 = yes, 0 = no) [\m(_logging)]: }
  660. if not def \%a forw CF17
  661. getok { LOGGING=\%a, OK? (y/n): }
  662. if fail goto CF16
  663. asg _config_changed 1
  664. asg _logging \%a
  665. :CF17
  666. ask \%a { Directory for log files [\m(_logdir)]: }
  667. if not def \%a forw CF18
  668. getok { LOGDIR=\%a, OK? (y/n): }
  669. if fail goto CF17
  670. asg _config_changed 1
  671. asg _logdir \%a
  672. :CF18
  673. ask \%a { Root of user directory tree [\m(_usertree)]: }
  674. if not def \%a forw CF19
  675. getok { USERTREE=\%a, OK? (y/n): }
  676. if fail goto CF18
  677. asg _config_changed 1
  678. asg _usertree \%a
  679. :CF19
  680. ask \%a { User database file [\m(_userfile)]: }
  681. if not def \%a forw CF20
  682. getok { USERFILE=\%a, OK? (y/n): }
  683. if fail goto CF19
  684. asg _config_changed 1
  685. asg _userfile \%a
  686. :CF20
  687. ask \%a { Login message file for all users [\m(_greeting)]: }
  688. if not def \%a forw CF21
  689. getok { GREETING=\%a, OK? (y/n): }
  690. if fail goto CF20
  691. asg _config_changed 1
  692. asg _greeting \%a
  693. :CF21
  694. ask \%a { File displayed when user requests help [\m(_helpfile)]: }
  695. if not def \%a forw CF22
  696. getok { HELPFILE=\%a, OK? (y/n): }
  697. if fail goto CF21
  698. asg _config_changed 1
  699. asg _helpfile \%a
  700. :CF22
  701. ask \%a { File in which you receive messages from users [\m(_msgfile)]: }
  702. if not def \%a forw CFXX
  703. getok { MSGFILE=\%a, OK? (y/n): }
  704. if fail goto CF22
  705. asg _config_changed 1
  706. asg _msgfile \%a
  707. :CFXX
  708. echo
  709. clear
  710. ask \%a Press the Enter key to return to main menu...
  711. goto loop
  712.  
  713. :LBL_4 ; Save config
  714. write screen Saving \m(_configfile)...
  715. saveconfig
  716. if success echo OK
  717. holdscreen LOOP
  718.  
  719. :LBL_5 ; Read messages
  720. echo
  721. echo Sorry - this is not really a mail program.
  722. echo Starting notepad to view the message file.
  723. echo Use notepad to remove, copy messages, etc.
  724. echo As yet there is no reply reply mechanism.
  725. echo To reply, just choose "Leave message" from
  726. echo from the main menu...
  727. sleep 1
  728. run notepad \freplace(\m(_msgfile),/,\\)
  729. goto loop
  730.  
  731. :LBL_6 ; Leave message for a user
  732. cls
  733. echo Leave a message...
  734. echo
  735. :MSGTO
  736. ask \%u {To: }
  737. if not def \%u goto MSGTO
  738. if dir \m(_usertree)/\%u forward SENDMESSAGE
  739. echo "\%u" - No such user [\m(_usertree)\%u]
  740. holdscreen LOOP
  741.  
  742. :LBL_7 ; View / edit greeting message
  743. cls
  744. echo Starting notepad.
  745. echo Make any desired changes and then save the file...
  746. sleep 1
  747. run notepad \freplace(\m(_greeting),/,\\)
  748. goto loop
  749.  
  750. :LBL_8 ; Post message to all users
  751. cls
  752. echo Post a message for all users...
  753. echo
  754. :MSGTO
  755. def \%u All
  756. forward sendmessage
  757.  
  758. :LBL_9 ; Manage user database
  759. cls
  760. echo User database management functions...
  761. echo
  762. asg \%a {Database filename: \fdef(_userfile)}
  763. if def _userdb_loaded asg \%a \%a - Loaded
  764. else asg \%a \%a - Not loaded
  765. if def _userdb_changed asg \%a \%a - Changed
  766. asg \%b {Current user:      }
  767. if def _current_user asg \%b \%b\m(_current_id)
  768. else asg \%b \%b(none)
  769. echo \%a
  770. if def _userdb_loaded echo Users:             \&u[0]
  771. echo \%b
  772. echo
  773. if exist \fdef(_userfile) {
  774.     echo { 1 - Load user database}
  775. } else {
  776.     echo { 1 - Create user database}
  777. }
  778. echo { 2 - Display user database}
  779. echo { 3 - Look up a user / set current user}
  780. echo { 4 - Add a new user}
  781. echo { 5 - Remove current user}
  782. echo { 6 - Modify current user}
  783. echo { 7 - Save and unload user database}
  784. echo { 8 - Remove lock}
  785. echo { 9 - Return to main menu}
  786. echo
  787. ask \%a {Your choice: }
  788. if not def \%a goto LBL_9
  789. if not num \%a { ec "\%a" - not a number, holdscreen LBL_9 }
  790. if > \%a 0 if not > \%a 9 forward USER_\%a
  791. echo "\%a" - out of range
  792. holdscreen LBL_9
  793.  
  794. :USER_1 ; Load database
  795. if not exist \fdef(_userfile) forward USER_CREATE_DB
  796. if not def _userdb_loaded forward USER_LOAD
  797. echo
  798. echo User database already loaded.
  799. if not def _userdb_changed goto LBL_9
  800. echo You have made changes to it.
  801. getok {Do you want to abandon your changes? }
  802. if success forward USER_LOAD
  803. echo Load canceled.
  804. holdscreen LBL_9
  805.  
  806. :USER_LOAD
  807. lock
  808. if fail { echo Sorry - can't lock user database., holdscreen LBL_9 }
  809. open read \fdef(_userfile)
  810. if fail { echo {Can't open \fdef(_userfile)}, unlock, goto loop }
  811. asg \&u[0] 0
  812. for \%i 1 \m(_maxusers) 1 {
  813.     read \&u[\%i]
  814.     if fail break
  815.     increment \&u[0]
  816. }
  817. close read
  818. def _userdb_loaded 1
  819. ec
  820. ec \fdef(_userfile) loaded: \&u[0] user(s).
  821. holdscreen LBL_9
  822.  
  823. :USER_CREATE_DB ; Create database
  824. open write \fdef(_userfile)
  825. if fail { echo Can't create \fdef(_userfile), holdscreen LBL_9 }
  826. close write
  827. if fail { echo Can't close \fdef(_userfile), holdscreen LBL_9 }
  828. asg _userdb_loaded 1
  829. asg \&u[0] 0
  830. echo \fdef(_userfile) created, now use "Add" to create user IDs.
  831. holdscreen LBL_9
  832.  
  833. :USER_8
  834. if not exist \m(_lockfile) {
  835.     ec
  836.     ec Lock not found.
  837.     holdscreen LBL_9
  838. }
  839. dir \m(_lockfile)
  840. echo
  841. type \m(_lockfile)
  842. echo
  843. getok {OK to remove? }
  844. if success unlock
  845. holdscreen LBL_9
  846.  
  847. :USER_9
  848. goto LOOP
  849.  
  850. :USER_2
  851. if not def _userdb_loaded { ec User database not loaded, forward user_2x }
  852. echo \&u[0] user(s) in \fdef(_userfile).
  853. if def _userdb_changed echo Changes have not been saved.
  854. else echo No changes have been made.
  855. ec
  856. for \%i 1 \&u[0] 1 { echo \%i. \&u[\%i] }
  857. :USER_2X
  858. holdscreen LBL_9
  859.  
  860. :USER_3 ; Look up a user
  861. if not def _userdb_loaded {
  862.     ec
  863.     ec User database not loaded
  864.     holdscreen LBL_9
  865. }
  866. if < \&u[0] 1 { ec, ec No users in database, holdscreen LBL_9 }
  867. echo
  868. echo
  869. ask \%u {User ID or name to look up: }
  870. asg _current_user
  871. for \%i 1 \&u[0] 1 {
  872.     getfields {\&u[\%i]}
  873.     if eq "\m(U_ID)" "\%u" { asg _current_user \%i, break }
  874. }
  875. if not def _current_user {
  876.     ec \%u - Not found
  877.     holdscreen LBL_9
  878. } else {
  879.     ec \%u = user \m(_current_user)
  880. }
  881. getfields {\&u[\m(_current_user)]}
  882. asg _current_id \m(U_ID)
  883.  
  884. ec User ID:   \m(U_ID)
  885. ec Password:  \m(U_PW)
  886. ec Privs:     \m(U_PR)
  887. ec Name:      \m(U_NM)
  888. ec Address:   \m(U_AD)
  889. ec Phone:     \m(U_TP)
  890. ec Email:     \m(U_EM)
  891. holdscreen LBL_9
  892.  
  893. :USER_4 ; Add a new user
  894. if not def _userdb_loaded { ec, ec User database not loaded, holdscr LBL_9 }
  895. ec
  896. ec
  897. ask \%u {User ID: }
  898. if not def \%u goto LBL_9
  899. for \%i 1 \&u[0] 1 {
  900.      split \&u[\%i]
  901.      if eq "\%u" "\m(_LEFT)" {
  902.      echo User "\%u" already exists.
  903.      holdscr LBL_9
  904.     }
  905. }
  906. :USER_PW
  907. ask \%p {Password for \%u: }
  908. ask \%q {Retype password: }
  909. if not eq "\%p" "\%q" {
  910.    echo Passwords do not match - please try again.
  911.    goto USER_PW
  912. }
  913. :USER_PR
  914. echo
  915. echo Enter privilege level...
  916. echo { 0 = None}
  917. echo { 1 = Allowed to CD to any directory}
  918. echo { 2 = Allowed to give DOS commands}
  919. echo { 3 = 1 and 2}
  920. echo
  921. undef \%x
  922. while not def \%x {
  923.     ask \%x {Privilege level (0-2): }
  924. }
  925. if not numeric \%x {
  926.     ec Please enter a digit: 0 thru 3.
  927.     goto USER_PR
  928. }
  929. echo Privilege level for \%u: \%x
  930. getok {OK? }
  931. if fail goto USER_PR
  932. :USER_ETC
  933. ask \%n {User's name (optional): }
  934. ask \%a {User's address (optional): }
  935. ask \%t {User's phone number (optional): }
  936. ask \%e {User's email address (optional): }
  937. ec
  938. ec User ID:   \%u
  939. ec Password:  \%p
  940. ec Privilege: \%x
  941. ec Name:      \%n
  942. ec Address:   \%a
  943. ec Phone:     \%t
  944. ec Email:     \%e
  945. ec
  946. getok {OK to enter? }
  947. if fail goto LBL_9
  948. asg \%i \&u[0]
  949. incr \%i
  950. ec Adding user number \%i...
  951. asg \&u[\%i] \%u_\f.oox(\%p)_\%x_\%n_\%a_\%t_\%e_
  952. asg \&u[0] \%i
  953. asg _userdb_changed 1
  954. holdscreen LBL_9
  955.  
  956. :USER_7 ; Save database
  957. saveuserdb
  958. holdscreen LBL_9
  959.  
  960. :USER_5 ; Remove a user
  961. if not def _userdb_loaded { ec, ec User database not loaded, holdscr LBL_9 }
  962. if def _current_user forward USER_REMOVE
  963. echo No current user, please use Lookup to select a user to remove.
  964. holdscreen LBL_9
  965. :USER_REMOVE
  966. echo
  967. echo Current user is \m(_current_id):
  968. echo \&u[\m(_current_user)]
  969. getok {OK to remove? }
  970. if fail {
  971.     ec \m(_current_id) not removed
  972.     holdscreen LBL_9
  973. }
  974. decrement \&u[0]
  975. for \%i \m(_current_user) \&u[0] 1 {
  976.      asg \&u[\%i] \&u[\%i+1]
  977. }
  978. echo
  979. echo User \m(_current_id) removed.
  980. asg _userdb_changed 1
  981. echo You should go through the user's files yourself by hand and decide
  982. echo what to do with them.
  983. asg _current_id
  984. asg _current_user
  985. holdscreen LBL_9
  986.  
  987. :USER_6 ; Modify current user info
  988. if def _current_user forward USER_CHANGE
  989. echo No current user - please use Lookup to select a user.
  990. holdscreen LBL_9
  991. :USER_CHANGE
  992. ec Current user:
  993. ec
  994. ec User ID:   \m(U_ID)
  995. ec Password:  \m(U_PW)
  996. ec Privilege: \m(U_PR)
  997. ec Name:      \m(U_NM)
  998. ec
  999. asg \%p \m(U_PW)
  1000. getok {Change this user's password? }
  1001. if fail { echo Password not changed, forward U6_PR }
  1002. :PASS_AGAIN
  1003. ec
  1004. ask \%p {New password:    }
  1005. ask \%q {Retype password: }
  1006. if not eq "\%p" "\%q" {
  1007.     ec Passwords do not match - please try again.
  1008.     goto PASS_AGAIN
  1009. }
  1010. getok {Change \m(U_ID)'s password to "\%p"? }
  1011. if fail { echo Password not changed, forward U6_PR }
  1012. echo Password changed.
  1013. asg _userdb_changed 1
  1014. :U6_PR
  1015. asg \%x \m(U_PR)
  1016. echo \m(U_ID)'s privilege level = \m(U_PR)
  1017. getok {Change it? }
  1018. if fail { echo Privilege not changed, forward USER_XX }
  1019. :U6LOOP
  1020. echo
  1021. echo Enter privilege level...
  1022. echo { 0 = None}
  1023. echo { 1 = Allowed to CD to any directory}
  1024. echo { 2 = Allowed to give DOS commands}
  1025. echo { 3 = 1 and 2}
  1026. echo
  1027. undef \%x
  1028. while not def \%x {
  1029.     ask \%x {Privilege level (0-2): }
  1030. }
  1031. if not numeric \%x { ec Please enter a digit: 0 thru 3., goto U6LOOP }
  1032. echo Privilege level for \m(U_ID): \%x
  1033. getok {OK? }
  1034. if fail goto U6LOOP
  1035. asg _userdb_changed 1
  1036.  
  1037. :USER_XX
  1038. if def _userdb_changed -
  1039. asg \&u[\m(_current_user)] -
  1040.   \m(U_ID)_\f.oox(\%p)_\%x_\m(U_NM)_\m(U_AD)_\m(U_TP)_\m(U_EM)
  1041. holdscreen lbl_9
  1042.  
  1043. :LBL_10 ; Help
  1044. if not exist \m(_usertree)hostmode.txt {
  1045.     echo, echo "\m(_usertree)hostmode.txt" not found
  1046.     holdscreen LOOP
  1047. }
  1048. run notepad \freplace(\m(_usertree)hostmode.txt,/,\\)
  1049. goto loop
  1050.  
  1051. :LBL_11 ; Exit
  1052. if not def _config_changed if not def _userdb_changed forward exit
  1053. echo
  1054. if def _config_changed {
  1055.     echo Configuration is changed.
  1056.     getok {Do you want to save it? }
  1057.     if success saveconfig
  1058. }
  1059. if def _userdb_changed {
  1060.     echo User database is changed.
  1061.     getok {Do you want to save it? }
  1062.     if success saveuserdb
  1063. }
  1064. :EXIT
  1065. unlock
  1066. echo
  1067. exit
  1068.  
  1069. ; Message writer...
  1070.  
  1071. :SENDMESSAGE
  1072. ask \%s {Subject: }
  1073. def \%i 0
  1074. echo Enter the message, finish by entering period (.) alone on a line:
  1075. echo
  1076. dcl \&a[200]
  1077.  
  1078. :MSGLOOP
  1079. incr \%i
  1080. if > \%i 200 goto MSGDONE
  1081. ask \&a[\%i] {\flpad(\%i,3,0)> }
  1082. if not eq "\&a[\%i]" "." goto MSGLOOP
  1083.  
  1084. :MSGDONE
  1085. asg \%n \%i
  1086. echo
  1087. getok {OK to send to \%u? (y/n): }
  1088. if fail goto loop
  1089. if eq "\%u" "All" asg \%f \m(_greeting)
  1090. else asg \%f \m(_usertree)/\%u.MSG
  1091. echo Opening \%f...
  1092. sleep 1
  1093. open append \%f
  1094. if fail { echo Can't open message file \%f, forw msgend }
  1095. writeln file Date: \v(date) \v(time)
  1096. writeln file To: \%u
  1097. writeln file From: \m(_owner)
  1098. writeln file Subject: \%s
  1099. writeln file
  1100. for \%i 1 \%n 1 { writeln file \&a[\%i] }
  1101. close write
  1102. if fail { echo Can't close message file \%f, goto msgend }
  1103.  
  1104. :MSGEND
  1105. dcl \&a[0]
  1106. clear
  1107. ask \%a Press the Enter key to return to main menu...
  1108. goto LOOP
  1109.  
  1110. ; End of HOSTMODE.KSC
  1111.