home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
WDR Computer Club Digital 1995 February
/
CLUB0295.BIN
/
demos
/
telix
/
tfw.5
/
WINHOST.SLT
< prev
Wrap
Text File
|
1994-12-07
|
39KB
|
1,369 lines
//
// W I N H O S T . S L T
//
// Copyright (C) 1988-1994 deltaComm Development.
//
// - Written by Colin Sampaleanu.
// - Modifications by Jeff Woods, Feb '91, to add help function and support
// for locked modems.
// - Modifications by Dan Horn, Nov '92, fixed 'floating' timer bug.
// - Thanks to Jon Fleming for his help in porting this to Windows.
//
// This is a Host Mode for Telix, written as a script file.
// To configure Host Mode parameters such as passwords, run the 'WCONFIG'
// script. That script is run automatically if the Host Mode configuration
// file 'WINHOST.CNF' is missing.
//
// This script will only work with Hayes compatible modems, but may be
// modified for operation with other modems.
//
//////////////////////////////////////////////////////////////////////////////
// Parameters which are configured from the WinHost configuration file
str host_downloads[64], // Default where users may download from
host_uploads[64]; // Default where uploaded files go
int direct_connect = 0, // 0 = using a modem
modem_lock = 0,
closed_sys = 0; // 0 = users may sign up on line if not
// found in the config file
// Various global variables
str current_caller[31], // storage of current caller's name
our_dir[64]; // Winhost directory (either Telix's
// scripts directory or the contents
// of the HOST2DIR environment variable
// if it exists)
int finished_caller, // set to TRUE when must return to top
local_mode, // set to TRUE when local test mode
access_level, // access level of current caller
carrier_counts = 1, // TRUE if should watch Carrier signal
already_connected = 0,
exit_requested = 0, // set to TRUE if Sysop has pressed Esc
connection_lost = 0, // set to TRUE when carrier lost
kill_user = 0, // set to TRUE when user must be purged
min_user_name = 5, // Minimum length of user's name
user_has_own_dir; // Flag to restrict the user to one dir
int old_scr_chk_key, // storage for some system variables
old_cisb_auto, // which we have to modify and put
old_zmod_auto, // back to what they were when done
old_sound;
str old_down_dir[64],
old_up_dir[64],
tfw_down_dir[64],
tfw_up_dir[64],
old_usage_fname[64];
#INCLUDE "WHUTILS.SLT" // Functions which are shared with the
// configuration managements script
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
main() {
int c;
str s[80];
tfw_up_dir = _up_dir;
tfw_down_dir = _down_dir;
clear_scr;
get_our_dir;
if (read_host_config_file == -1) {
prints("Unable to read WINHOST.CNF...");
prints("Running WCONFIG, the Host Mode configuration script.^M^J");
s = our_dir;
strcat (s, "WCONFIG");
calld (s);
if (read_host_config_file() == -1) {
prints("Still unable to read WINHOST.CNF. Aborting Host Mode.^M^J");
return -1;
}
}
prints ("Checking existence of download directory ...");
if (!check_directory (host_downloads)) {
prints("Aborting Host Mode.");
return -1;
}
prints ("Checking existence of upload directory ...");
if (!check_directory (host_uploads)) {
prints("Aborting Host Mode.");
return -1;
}
old_scr_chk_key = _scr_chk_key;
_scr_chk_key = 0;
old_cisb_auto = _cisb_auto;
_cisb_auto = 0;
old_zmod_auto = _zmod_auto;
_zmod_auto = 0;
old_sound = _sound_on;
_sound_on = 0;
old_down_dir = _down_dir;
old_usage_fname = _usage_fname;
s = our_dir;
strcat (s, "HOST2.LOG");
usagelog (s);
if (direct_connect)
carrier_counts = 0;
else
carrier_counts = 1;
if (!direct_connect && carrier())
already_connected = 1;
while (1) {
_down_dir = host_uploads; // these are reversed because we are the Host
old_up_dir = _up_dir;
_up_dir = host_downloads; // these are reversed because we are the Host
user_has_own_dir = 0;
if (!direct_connect && !already_connected) {
if (!modem_lock)
set_cparams(modem_lock, 0, 8, 1);
delay_scr(3);
prints("Sending Modem Init string...");
cputs_tr(_mdm_init_str);
delay_scr(10);
prints("Sending Auto-Answer string...");
cputs_tr(_auto_ans_str);
}
finished_caller = kill_user = 0;
if (direct_connect)
carrier_counts = 0;
else
carrier_counts = 1;
if (!direct_connect) {
prints("^M^JHost Mode: Waiting for call...");
prints("(Press Esc to exit, or 'L' for local test mode).^M^J");
do {
if (carrier()) {
local_mode = 0;
break;
}
c = inkey();
if (c) {
if (c == 27) {
exit_requested = 1;
break;
}
else if (c == 'l' || c == 'L') { // local test mode
prints("Local test mode entered");
local_mode = 1;
carrier_counts = 0;
}
}
}
while (toupper(c) != 'L');
}
if (!exit_requested) {
prints("Incoming call. Sysop: press Esc to exit, or END to terminate user.");
do_one_caller();
if ((connection_lost || kill_user) && carrier_counts && carrier())
hangup(); // make sure nobody sneaks in
}
already_connected = 0;
if (exit_requested) {
if (!carrier() && !direct_connect) {
prints("Sending Modem Init string...");
cputs_tr(_mdm_init_str);
}
_scr_chk_key = old_scr_chk_key;
_cisb_auto = old_cisb_auto;
_zmod_auto = old_zmod_auto;
_sound_on = old_sound;
_down_dir = tfw_down_dir;
_up_dir = tfw_up_dir;
prints("^M^JHost mode script finished.");
usagelog("*CLOSE*");
_usage_fname = old_usage_fname;
return 1;
}
}
}
//////////////////////////////////////////////////////////////////////////////
host_help (str mode, str option) {
str fname[64];
fname = our_dir;
strcat (fname, mode);
strcat (fname, "_HELP_");
StrCat (fname, option);
StrCat (fname, ".TXT");
if (FileFind (fname, 0)) {
type_file (fname);
return (1);
}
else {
printsc ("^MCan't find help file ");
prints (fname);
return (0);
}
}
//////////////////////////////////////////////////////////////////////////////
do_one_caller() {
str strn[80], fname[64], s[80], temporary[1];
int option, status, c, i, i2, f, len;
access_level = 1;
flushbuf();
if (already_connected)
prints("Already connected, or modem Carrier Detect switch improperly set!");
else if (carrier_counts) {
flushbuf();
if (!modem_lock)
if (!determine_baud())
; // do something else here if this is a problem
}
delay_scr(20);
if (type_file("LOGO.MSG") == -1) {
s = our_dir;
strcat (s, "LOGO.MSG");
type_file (s);
}
flushbuf();
get_user_name ();
access_level = setup_user(3);
if (access_level) {
ustamp("Logon by ", 1, 0);
ustamp(current_caller, 0, 1);
}
else {
ustamp("Failed logon attempt by ", 1, 0);
ustamp(current_caller, 0, 1);
send_goodbye ();
if (carrier_counts) {
delay_scr(10);
hangup();
}
return;
}
if (type_file("WELCOME.MSG") == -1) {
s = our_dir;
strcat (s, "WELCOME.MSG");
type_file (s);
}
while (1) {
if (finished_caller)
return;
if (access_level == 3) {
if (type_file ("MMENU3.TXT") == -1) {
s = our_dir;
strcat (s, "MMENU3.TXT");
if (type_file (s) == -1) {
host_send("^M^JFiles Type Upload Download Shell Chat Help Goodbye ? ");
}
}
}
else {
if (type_file ("MMENU.TXT") == -1) {
s = our_dir;
strcat (s, "MMENU.TXT");
if (type_file (s) == -1) {
host_send("^M^JFiles Type Upload Download Chat Help Goodbye ? ");
}
}
}
host_send ("^M^JCommand: ");
host_input_strn(strn, 1, 1);
option = toupper(subchr(strn, 0));
host_send("^M^J");
if (option == 'H') { // Help
host_send("^M^JWhich item above do you wish help on? ");
host_input_strn(strn, 1, 1);
substr (strn, 0, 1, strn);
strupper (strn);
Host_send("^M^J");
host_help( "H", strn);
}
if (option == 'F') { // Files directory
if (access_level >= 2) {
host_send("Enter 'filespec' or press Return for *.*,^M^J: ");
host_input_strn(fname, 64, 1);
host_send("^M^J");
ustamp ("Requested file listing of ", 1, 0);
ustamp (fname, 0, 1);
if (strcmpi (fname, "") == 0) {
fname = "*.*";
}
if (just_filename(fname)) {
strn = _down_dir;
strcat(strn, fname);
}
else if (user_has_own_dir == 1) {
host_send ("^M^JAccess outside ");
host_send (_down_dir);
host_send (" not allowed^M^J");
strn = _down_dir;
strcat(strn, "*.*");
}
else {
len = strlen (fname);
substr (fname, len - 1, 1, temporary);
if (strcmpi (temporary, "\") == 0) {
strn = fname;
strcat (strn, "*.*");
}
else {
strn = fname;
}
}
}
else {
strn = _down_dir;
strcat(strn, "*.*");
ustamp ("Requested listing of files", 1, 1);
}
host_show_directory(strn);
ustamp ("Displayed ", 1, 0);
ustamp (strn, 0, 1);
}
else if (option == 'T') { // Type a file
host_send("Type what file? ");
host_input_strn(strn, 64, 1);
host_send("^M^J");
ustamp ("Requested to type ", 1, 0);
ustamp (strn, 0, 1);
if ((access_level == 1) || (user_has_own_dir == 1))
fnstrip(strn, 3, fname);
else
fname = strn;
if (just_filename(fname)) {
strn = _down_dir;
strcat(strn, fname);
fname = strn;
}
if (!filefind(fname, 0, strn)) {
host_send("Unable to find ");
host_send(fname);
continue;
}
type_file(fname);
ustamp ("Typed ", 1, 0);
ustamp (fname, 0, 1);
}
else if (option == 'G') { // Goodbye (Hang-up)
send_goodbye ();
ustamp("User logged off.", 1, 1);
if (carrier_counts) {
delay_scr(10);
hangup();
}
return;
}
else if (option == 'C') { // Chat mode
prints("Sysop: Press Space to chat, any other key not to.^M^J");
c = 0;
_sound_on = 1;
for (i = 8; i && !c; --i) {
host_send (".");
if (carrier_counts && !carrier()) {
prints("^M^JConnection has been lost, call terminated.^M^J");
connection_lost = 1;
finished_caller = 1;
break;
}
cputc('^G');
tone(523, 20);
tone(659, 20);
tone(523, 20);
tone(659, 20);
tone(523, 20);
tone(659, 20);
for (i2 = 30; i2 && (c = inkey()) == 0; --i2)
delay_scr(1);
}
_sound_on = 0;
host_send ("^M^J");
if (finished_caller)
continue;
if (c != ' ' || !c) {
host_send("Sorry, the Sysop is unavailable^M^J");
continue;
}
host_send("The sysop is here!^M^J");
chatmode(1);
}
else if (option == 'U') { // User upload
option = host_get_prot();
if (!option)
continue;
ustamp ("Upload ", 1, 0);
status = 1;
if (option == 'T' || option == 'M' || option == 'S' ||
option == 'Y' || option == 'Z' || option == 'E') {
ustamp ("with name-transferrring protocol ", 0, 1);
send_transfer_msg();
status = receive(option, "");
}
else {
host_send("Upload what file? ");
host_input_strn(strn, 48, 1);
host_send("^M^J");
if (!strn)
continue;
ustamp (strn, 0, 1);
if ((access_level == 1) || (user_has_own_dir == 1)) // if access 1, name and ext only
fnstrip(strn, 3, fname);
else
fname = strn;
if (just_filename(fname)) {
strn = _up_dir;
strcat(strn, fname);
fname = strn;
}
if (filefind(fname, 23, strn)) {
host_send("File already exists!^M^J");
ustamp ("File already exists", 1, 1);
}
else {
send_transfer_msg();
status = receive(option, fname);
}
}
if (status == -2) { // Carrier lost
connection_lost = finished_caller = 1;
ustamp ("Lost carrier", 1, 1);
}
else if (status == -1) {
host_send("^M^J^M^J^GOne or more files not received!^M^J");
ustamp ("One or more files not received", 1, 1);
}
else {
ustamp ("Transfer complete", 1, 1);
}
}
else if (option == 'D') { // User download
option = host_get_prot();
if (!option)
continue;
host_send("Download what file(s)? ");
host_input_strn(strn, 48, 1);
host_send("^M^J");
if (!strn)
continue;
ustamp ("Attempt to download ", 1, 0);
ustamp (strn, 0, 1);
if ((access_level == 1) || (user_has_own_dir == 1)) // if not level 2, keep only name & ext
fnstrip(strn, 3, fname);
else
fname = strn;
if (just_filename(fname)) {
strn = _down_dir;
strcat(strn, fname);
fname = strn;
}
if (!filefind(fname, 0, strn)) {
host_send("Unable to find any matching file(s)!^M^J");
ustamp ("No such file", 1, 1);
continue;
}
status = 1;
send_transfer_msg();
status = send(option, fname);
if (status == -2) { // Carrier lost
connection_lost = finished_caller = 1;
ustamp ("Lost carrier", 1, 1);
}
else if (status == -1) {
host_send("^M^J^M^J^GOne or more files not sent!^M^J");
ustamp ("One or more files not sent", 1, 1);
}
else {
ustamp ("Transfer complete", 1, 1);
}
}
else if (option == 'S') { // Remote shell
ustamp ("Attempted shell", 1, 1);
if (access_level == 3) {
host_send("Type EXIT and then press Enter to come back.^M^J");
if (get_baud() == 300)
delay_scr(10);
if (local_mode)
dos("", 0);
// See if user has prepared a custom file for shell operation
// and call that if it exists
else if (filefind("RSHELL.BAT", 0, strn))
dos("RSHELL.BAT", 0);
else { // otherwise make our own temporary batch file for redirection
// now want to make a temporary batch file which will be
// called to redirect DOS input and output, then shell to
// another copy of the command interpreter
f = fopen("HOSTTEMP.BAT", "w");
if (f) {
if (get_port() != 1 && get_port() != 2) {
host_send("Remote Shell not supported on this comm port due to DOS limits!^M^J");
continue;
}
strn = "COMx";
setchr(strn, 3, get_port() + '0'); // get right name to redirect
fputs("CTTY ", f); // write to batch file
fputs(strn, f);
fputs("^M^J", f);
if (getenv ("COMSPEC", s) == 0) {
s = "COMMAND.COM";
}
fputs (s, f);
fputs("^M^J", f);
fputs("CTTY CON^M^J", f);
fputs("EXIT^M^J", f);
fclose(f); // close the file
if (!local_mode) // call batch file
dos("HOSTTEMP.BAT", 0);
}
else
host_send("Can't open temporary batch file!^M^J");
}
}
else {
ustamp ("Request denied", 1, 1);
}
}
else if (option == '^Z') { // Shut down Host Mode
if (access_level == 3) {
host_send("Shutting down Host mode. ");
ustamp("User shut down Host Mode.", 1, 1);
}
send_goodbye ();
ustamp("User logged off.", 1, 1);
if (carrier_counts)
hangup();
finished_caller = 1;
exit_requested = 1;
}
}
}
//////////////////////////////////////////////////////////////////////////////
host_get_prot() {
str prot[1], strn[1], s[64];
int Option;
prot = "H";
while (strcmpi (prot, "H") == 0) {
if (type_file ("PMENU.TXT") == -1) {
s = our_dir;
strcat (s, "PMENU.TXT");
if (type_file (s) == -1) {
host_send("^M^JXmodem 1k-Xmodem G-1k-Xmodem Ymodem YmodEm-g Zmodem^M^J");
host_send("Help Cancel^M^J");
}
}
host_send("Which protocol, or H for help ? ");
host_input_strn(prot, 1, 1);
strupper (prot);
host_send("^M^J");
if (strcmpi (prot, "H") == 0) {
host_send ("^M^JHelp on which protocol, or ^"A^" for ALL? ");
host_input_strn (strn, 1, 1);
substr (strn, 0, 1, strn);
strupper (strn);
Host_send("^M^J");
host_help( "P", strn);
}
if (strposi("X1GYEZH", prot, 0) == -1) // if illegal prot or cancel
prot = ""; // return 0
}
return (toupper(subchr(prot, 0)));
}
//////////////////////////////////////////////////////////////////////////////
send_transfer_msg() {
host_send("Ready to transfer file(s)... Press Ctrl-X at least twice to abort^M^J");
}
//////////////////////////////////////////////////////////////////////////////
// Determine the baud rate once a Carrier Detect Signal has been detected
// Since no characters were read, the 'CONNECT' string should still be
// in the receive buffer.
determine_baud() {
int t3, t12, t24, t48, t96, t144, t192;
int tmark, stat;
int new_baud = 0;
printsc("Determining baud... ");
track_free(0); // clear all existing tracks
t3 = track("CONNECT^M", 0); // check for connect strings
t12 = track("CONNECT 1200", 0);
t24 = track("CONNECT 2400", 0);
t48 = track("CONNECT 4800", 0);
t96 = track("CONNECT 9600", 0);
t144 = track("CONNECT 14400", 0);
t192 = track("CONNECT 19200", 0);
tmark = timer_start(30); // wait up to 3 seconds for string
while (!time_up(tmark)) {
if (!carrier()) {
track_free(0); // clear all existing tracks
timer_free(tmark); // free existing timer
return 0;
}
if (cinp_cnt())
track_addchr(cgetc());
stat = track_hit(0);
if (stat == 0)
continue;
if (stat == t3)
new_baud = 300;
else if (stat == t24)
new_baud = 2400;
else if (stat == t48)
new_baud = 4800;
else if (stat == t96)
new_baud = 9600;
else if (stat == t144)
new_baud = 14400;
else if (stat == t192)
new_baud = 19200;
else
new_baud = 1200;
break; // have baud rate, get out
}
track_free(0); // clear all existing tracks
timer_free(tmark); // free existing timer
if (!new_baud) { // time-up without CONNECT string
prints("Failed!");
return 0;
}
printn(new_baud);
prints("");
set_cparams(new_baud, get_parity(), get_datab(), get_stopb());
return 1; // indicate success
}
//////////////////////////////////////////////////////////////////////////////
type_file(str fname) {
int f;
str s[80], buf[100];
int ichar, lines_sent = 0;
f = fopen(fname, "r");
if (!f)
return -1;
host_send("^M^J");
while (1) {
if (carrier_counts)
if (!carrier()) {
connection_lost = 1;
finished_caller = 1;
fclose(f);
return 0;
}
if (fgets(buf, 80, f) == -1) {
fclose(f);
return 1;
}
host_send(buf);
host_send("^M^J");
++lines_sent;
if (lines_sent >= 22) {
lines_sent = 0;
host_send("[More]");
host_input(1);
if (finished_caller) { // if user inactivity
fclose(f);
return 0;
}
host_send("^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H");
}
while (cinp_cnt()) {
ichar = cgetc();
if (ichar == '^C' || ichar == '^K') {
host_send("^M^J");
fclose(f);
return 1;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
host_send(str outstr) {
printsc(outstr);
if (!local_mode)
cputs(outstr);
}
//////////////////////////////////////////////////////////////////////////////
host_send_c(int chr) {
printc(chr);
if (!local_mode)
cputc(chr);
}
//////////////////////////////////////////////////////////////////////////////
host_input_strn(str buf, int maximum, int echoable) {
int i = 0, key;
while (1) {
key = host_input(echoable);
if (!key) { // timeout or user disconnect
setchr(buf, 0, 0); // set string to empty
return 0; // indicate there is a problem
}
if (key == '^M')
break;
if (key == 127 || key == 8) {
if (i) {
--i;
host_send_c(key);
}
continue;
}
if (i < maximum) {
setchr(buf, i, key);
i = i + 1;
}
else
i = i + 1;
}
if (i > maximum)
i = maximum;
setchr(buf, i, '^0');
if (subchr(buf, 0))
return 1;
else
return 0;
}
//////////////////////////////////////////////////////////////////////////////
host_input(int echoable) {
int c, t;
t = timer_start(2400); // 4 minutes inactivity allowed
while (1) {
if (time_up(t) && !direct_connect) {
host_send("^M^J^M^JInactivity period too long. Connection terminated!^M^J");
if (carrier_counts)
hangup();
finished_caller = 1;
kill_user = 1;
break;
}
if (carrier_counts)
if (!carrier()) {
prints("^M^JConnection has been lost, call terminated.^M^J");
connection_lost = 1;
finished_caller = 1;
break;
}
if ((c = inkey()) != 0) {
if (c == 27) { // ESC key, sysop wants to exit
finished_caller = 1;
exit_requested = 1;
break;
}
else if (c == 0x4f00) { // END key, terminate user
prints("^M^JUser terminated!");
ustamp("User terminated!", 1, 1);
if (carrier_counts)
hangup();
finished_caller = 1;
kill_user = 1;
break;
}
else if (c <= 255) {
if (c != 8 && c != 127)
if (!echoable)
host_send_c('*');
else
host_send_c(c);
break;
}
}
if (!local_mode)
if (cinp_cnt()) {
c = cgetc();
if (c != 8 && c != 127)
if (!echoable)
host_send_c('*');
else
host_send_c(c);
break;
}
}
timer_free(t); // free existing timer
if (finished_caller)
return 0; // return 0 - no character
return c; // return received/pressed character
}
//////////////////////////////////////////////////////////////////////////////
// This routine maintains an ASCII file in the Telix files directory called
// WHPASS.TXT. The format for each line is:
// name;password;working_dir;access_level (optional comment)
// The name, password, working_dir, and access_level fields MUST be
// separated by semicolons
// The working_dir field is optional (but the semicolons before and after
// it are _NOT_). If there's no working_dir field, the default host
// upload and download direcories are used.
// The routine searches the file for a line on which the "name" field
// matches the global variable "current_caller" (not case sensitive).
// If a match is found, and the user can type a password that matches
// the "password" field (not case sensitive), the routine returns
// the integer "access_level".
// If no match is found, the user is given an opportunity to register
// (at access level 1).
// If the user registers, the file is updated with the new user name,
// password, and access level (1), and the routine returns 1.
// If the user does not register, or if the user cannot match the password
// in the file in "maxtries", or if the user registers and cannot match
// the password he/she chose in "maxtries", the routine returns 0.
setup_user (int maxtries) {
str password_file[64], line_from_file[80], password_from_file[16],
name_from_file[31], temporary[16], typed_password[16],
working_dir[64], last_char[1];
int password_file_handle, field_length, field_start,
found_password = 0, access_from_file, counter = 0,
file_ends_in_control_z = 0, line_number = 0, length;
password_file = our_dir;
strcat (password_file, "WHPASS.TXT");
for (counter = 1; counter <= maxtries; counter = counter + 1) {
// Try to open password file
if (password_file_handle = fopen (password_file, "r")) {
// Read next line from file.
while (fgets (line_from_file, 64, password_file_handle) != -1) {
// Check for ^Z termination
if (line_from_file == "^Z") {
file_ends_in_control_z = 1;
break;
}
line_number = line_number + 1;
// If line is long enough . . .
if (strlen (line_from_file) >= min_user_name+4) {
// Get length of name
if ( (field_length = strchr (line_from_file, 0, ';')) > 0) {
// Get name
substr (line_from_file, 0, field_length, name_from_file);
// If name matches . . . .
if (strcmpi (name_from_file, current_caller) == 0) {
// Get password
field_start = field_length + 1;
if ( (field_length = strchr (line_from_file, field_start, ';') - field_start) > 0) {
substr (line_from_file, field_start, field_length, password_from_file);
// Get working directory
field_start = field_start + field_length + 1;
if ( (field_length = strchr (line_from_file, field_start, ';') - field_start) >= 0) {
substr (line_from_file, field_start, field_length, working_dir);
// Get access level
field_start = field_start + field_length + 1;
substr (line_from_file, field_start, 1, temporary);
access_from_file = stoi (temporary);
// Set flag that we got an old user
found_password = 1;
break;
}
else {
password_file_error (line_number, line_from_file, "no third semicolon");
}
}
else {
password_file_error (line_number, line_from_file, "no second semicolon");
}
}
}
else {
password_file_error (line_number, line_from_file, "no first semicolon");
}
}
else {
password_file_error (line_number, line_from_file, "line too short");
}
}
fclose (password_file_handle);
}
if (found_password) {
break;
}
else {
host_send ("^M^JNo user ^"");
host_send (current_caller);
host_send ("^" on file; re-type name? (y/n): ");
host_input_strn (temporary, 1, 1);
host_send ("^M^J");
if (strcmpi (temporary, "y") != 0) {
break;
}
else {
get_user_name ();
}
}
}
if (found_password) {
// Password is on file; ask for it
host_send ("Password: ");
for (counter = 1; counter <= maxtries; counter = counter + 1) {
host_input_strn (typed_password, 16, 0);
// If a match
if (strcmpi (typed_password, password_from_file) == 0) {
host_send ("^M^J");
// If the user has a working directory ...
if (strcmpi (working_dir, "") != 0) {
// Check for a "\" on the end and add it if necessary
length = strlen (working_dir);
substr (working_dir, length - 1, 1, last_char);
if (strcmpi (last_char, "\") != 0) {
strcat (working_dir, "\");
}
// Establish download & upload directories
strupper (working_dir);
if (check_directory (working_dir)) {
_down_dir = working_dir;
_up_dir = working_dir;
user_has_own_dir = 1;
}
else {
prints ("Using defaults");
ustamp (working_dir, 1, 0);
ustamp (" does not exist, using default", 0, 1);
}
}
// Return the user's access level
return (access_from_file);
}
if (counter < maxtries) {
host_send ("^M^JDoes not match password on file! Please try again: ");
}
else {
host_send ("^M^JMaximum number of tries exceeded!^M^J");
}
}
}
// Password is not on file
else if (!closed_sys) {
// Offer chance to register
host_send ("No user ^"");
host_send (current_caller);
host_send ("^" found in user file.^M^JDo you want to register? (Y/N): ");
host_input_strn (temporary, 1, 1);
host_send ("^M^J");
// If user doesn't want to register
if (not ((temporary == "Y") || (temporary == "y"))) {
return (0);
}
// If user wants to register
host_send ("Pick a password (16 characters maximum): ");
host_input_strn (password_from_file, 16, 0);
// Make sure password is right
host_send ("^M^JRe-enter your password to verify: ");
for (counter = 1; counter <= maxtries; counter = counter + 1) {
host_input_strn (typed_password, 16, 0);
// If all is ok
if (strcmpi (typed_password, password_from_file) == 0) {
// Build new line for password file
line_from_file = current_caller;
strcat (line_from_file, ";");
strcat (line_from_file, password_from_file);
strcat (line_from_file, ";;1 **NEW USER** ");
date (curtime(), temporary);
strcat (line_from_file, temporary);
// Open password file for appending
// password_file_handle = fopen (password_file, "a+");
password_file_handle = fopen (password_file, "a");
if (file_ends_in_control_z) {
fseek (password_file_handle, -1, 2);
}
// Now we can write the line
fwrite (line_from_file, strlen (line_from_file), password_file_handle);
fwrite ("^M^J", 2, password_file_handle);
fclose (password_file_handle);
host_send ("^M^J");
// Return access level
return (1);
}
if (counter < maxtries){
host_send ("^M^JDoes not match! Please try again: ");
}
else {
host_send ("^M^JMaximum number of tries exceeded!^M^J");
}
}
}
return (0);
}
//////////////////////////////////////////////////////////////////////////////
// A routine to print an error message to the local screen when something
// is wrong with the password file
password_file_error (int line_number, str line, str error_specifier) {
str line_number_string[4];
itos (line_number, line_number_string);
prints ("");
printsc ("Bad line ");
printsc (line_number_string);
prints (" in password file:");
printsc (" ^"");
printsc (line);
prints ("^"");
prints (error_specifier);
return (1);
}
//////////////////////////////////////////////////////////////////////////////
// returns TRUE if passed filespec is just a filename. Also handles the
// forward slash as a path separator.
just_filename(str filespec) {
int slash, space;
if (strpos(filespec, ":", 0) != -1)
return 0;
if (strpos(filespec, "\", 0) != -1)
return 0;
if ((slash = strpos(filespec, "/")) == -1)
return 1;
space = strpos(filespec, " ");
if (space == -1)
return 0;
if (space < slash)
return 1;
return 0;
}
//////////////////////////////////////////////////////////////////////////////
host_show_directory (str dir_spec) {
str file_name[13], f_name_ext[12], f_size_str[20], f_date_str[20],
f_time_str[20], buffer[80], path[67], full_name[80],
temp[26], hours_str[2], minutes_str[2], seconds_str[2];
int file_exists, fsize, ftime, lines, dot_pos, bps, seconds,
minutes, hours;
bps = get_baud (1);
fnstrip (dir_spec, 12, path);
file_exists = FileFind (dir_spec, 0, file_name);
if (!file_exists) {
host_send ("^M^JNo matching file found.^M^J");
}
else {
lines = 2;
// host_send (" Name Size Date Time ESTIMATED Zmodem^M^J");
// host_send (" transfer time^M^J");
host_send (" Name Size Date Time^M^J");
}
while (file_exists) {
// Get the file size, as a string, with commas where appropriate
fsize = FileSize ("");
ItoS (fsize, temp);
insert_commas (temp, f_size_str);
// Get the file date and time as a string
ftime = FileTime ("");
Date (ftime, f_date_str);
Time (ftime, f_time_str);
// Estimate how long it'll take to transfer the file with Zmodem
seconds = (fsize*10)/bps;
// Guess at about 95% efficiency
seconds = seconds + seconds/20;
if (seconds == 0) {
seconds = 1;
}
minutes = seconds/60;
seconds = seconds - minutes*60;
hours = minutes/60;
minutes = minutes - hours*60;
// Convert the transfer time to a string
if (seconds < 10) {
ItoS (seconds, temp);
seconds_str = "0";
strcat (seconds_str, temp);
}
else {
ItoS (seconds, seconds_str);
}
if (minutes < 10) {
ItoS (minutes, temp);
minutes_str = "0";
strcat (minutes_str, temp);
}
else {
ItoS (minutes, minutes_str);
}
ItoS (hours, hours_str);
// Stuff the buffer with just enough spaces so the periods in the
// file names line up
dot_pos = strpos (file_name, ".", 0);
if (dot_pos > 0) {
substr (" ", 0, 8 - dot_pos, buffer);
}
else {
substr (" ", 0, 8 - strlen (file_name), buffer);
}
// Put the file name into the buffer
strcat (buffer, file_name);
// Append just enough spaces to the buffer to make the right sides of
// the file sizes line up
substr (" ", 0, 26 - strlen (buffer) - strlen (f_size_str), temp);
strcat (buffer, temp);
// Put the file size into the buffer
strcat (buffer, f_size_str);
// Put the file date and time into the buffer
strcat (buffer, " ");
strcat (buffer, f_date_str);
strcat (buffer, " ");
strcat (buffer, f_time_str);
// Put the transfer time into the buffer
// if (hours < 10) {
// strcat (buffer, " ");
// }
// else {
// strcat (buffer, " ");
// }
// strcat (buffer, hours_str);
// strcat (buffer, ":");
// strcat (buffer, minutes_str);
// strcat (buffer, ":");
// strcat (buffer, seconds_str);
// See if we've filled a screen yet ...
if (lines > 23) {
host_send ("[More]");
host_input (1);
lines = 0;
}
else {
lines = lines + 1;
}
// Send the line
host_send (buffer);
host_send ("^M^J");
file_exists = FileFind ("", 0, file_name);
}
}
//////////////////////////////////////////////////////////////////////////////
// Insert commas into a string representation of an integer, up to
// 999,999,999,999 (the largest SALT integer is 2,147,483,647)
insert_commas (str input, str output) {
str tmp1[15], tmp2[15];
int len, delta;
output = input;
for (delta = 3; delta <= 11; delta = delta + 4) {
if ((len = strlen (output)) > delta) {
substr (output, 0, len - delta, tmp1);
substr (output, len - delta, 15, tmp2);
output = tmp1;
strcat (output, ",");
strcat (output, tmp2);
}
else {
break;
}
}
}
//////////////////////////////////////////////////////////////////////////////
send_goodbye () {
str s[80];
if (type_file("GOODBYE.MSG") == -1) {
s = our_dir;
strcat (s, "GOODBYE.MSG");
if (type_file (s) == -1) {
host_send ("^M^JGoodbye^M^J");
}
}
delay_scr(20);
}
//////////////////////////////////////////////////////////////////////////////
get_user_name () {
str temporary[1];
while (1) {
host_send("Please enter your full name: ");
host_input_strn(current_caller, 30, 1);
host_send("^M^J");
if (finished_caller)
return;
if (strlen(current_caller) >= min_user_name) {
host_send ("^"");
host_send (current_caller);
host_send ("^", correct? (y/n): ");
host_input_strn (temporary, 1, 1);
host_send ("^M^J");
if (strcmpi (temporary, "y") == 0)
break;
}
else
host_send ("Name too short!^M^J");
}
}