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