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