1 /* Citadel/UX support routines */
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
26 void sttybbs(int cmd);
27 void newprompt(char *prompt, char *str, int len);
28 void val_user(char *user);
29 void formout(char *name);
30 void logoff(int code);
31 void set_keepalives(int s);
32 void strprompt(char *prompt, char *str, int len);
33 void newprompt(char *prompt, char *str, int len);
34 void color(int colornum);
36 #define IFAIDE if(axlevel>=6)
37 #define IFNAIDE if (axlevel<6)
39 extern unsigned userflags;
40 extern char *axdefs[7];
41 extern char sigcaught;
42 extern struct CtdlServInfo serv_info;
43 extern char rc_floor_mode;
44 extern int rc_ansi_color;
46 int struncmp(char *lstr, char *rstr, int len)
51 lc=tolower(lstr[pos]);
52 rc=tolower(rstr[pos]);
53 if ((lc==0)&&(rc==0)) return(0);
54 if (lc<rc) return(-1);
63 * check for the presence of a character within a string (returns count)
65 int haschar(char *st, int ch)
69 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
75 * num_parms() - discover number of parameters...
77 int num_parms(char *source)
82 for (a=0; a<strlen(source); ++a)
83 if (source[a]=='|') ++count;
88 * extract() - extract a parameter from a series of "|" separated...
90 void extract(char *dest, char *source, int parmnum)
96 n = num_parms(source);
103 if ( (parmnum == 0) && (n == 1) ) {
108 while (count++ < parmnum) do {
110 } while( (strlen(buf)>0) && (buf[0]!='|') );
111 if (buf[0]=='|') strcpy(buf,&buf[1]);
112 for (count = 0; count<strlen(buf); ++count)
113 if (buf[count] == '|') buf[count] = 0;
118 * extract_int() - extract an int parm w/o supplying a buffer
120 int extract_int(char *source, int parmnum)
124 extract(buf,source,parmnum);
129 * extract_long() - extract a long parm w/o supplying a buffer
131 long extract_long(char *source, int parmnum)
135 extract(buf,source,parmnum);
139 void back(int spaces) /* Destructive backspace */
142 for (a=1; a<=spaces; ++a) {
143 putc(8,stdout); putc(32,stdout); putc(8,stdout);
147 void hit_any_key(void) { /* hit any key to continue */
150 printf("%s\r",serv_info.serv_moreprompt);
153 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
157 if (b==NEXT_KEY) sigcaught = SIGINT;
158 if (b==STOP_KEY) sigcaught = SIGQUIT;
162 * change a user's access level
177 newprompt("User name: ",who,25);
178 sprintf(buf,"AGUP %s",who);
182 printf("%s\n",&buf[4]);
185 extract(who, &buf[4], 0);
186 extract(pass, &buf[4], 1);
187 flags = extract_int(&buf[4], 2);
188 timescalled = extract_int(&buf[4], 3);
189 posted = extract_int(&buf[4], 4);
190 axlevel = extract_int(&buf[4], 5);
191 usernum = extract_long(&buf[4], 6);
192 lastcall = extract_long(&buf[4], 7);
193 userpurge = extract_int(&buf[4], 8);
195 val_user(who); /* Display registration, and set access level */
196 strprompt("Password", pass, 19);
197 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
198 posted = intprompt("Messages posted", posted, 0, INT_MAX);
199 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
200 userpurge = intprompt("Purge time (in days, 0 for system default",
201 userpurge, 0, INT_MAX);
203 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
204 who, pass, flags, timescalled, posted, axlevel, usernum,
205 lastcall, userpurge);
209 printf("%s\n",&buf[4]);
214 int set_attr(int sval, char *prompt, unsigned int sbit)
221 printf("%45s [", prompt);
223 printf("%3s", ((temp&sbit) ? "Yes":"No"));
227 a=yesno_d(temp&sbit);
230 if (!a) temp=(temp^sbit);
235 * modes are: 0 - .EC command, 1 - .EC for new user,
236 * 2 - toggle Xpert mode 3 - toggle floor mode
238 void enter_config(int mode)
240 int width,height,flags;
247 printf("%s\n",&buf[4]);
251 width = extract_int(&buf[4],0);
252 height = extract_int(&buf[4],1);
253 flags = extract_int(&buf[4],2);
255 if ((mode==0)||(mode==1)) {
257 width = intprompt("Enter your screen width",width,20,255);
258 height = intprompt("Enter your screen height",height,3,255);
260 flags = set_attr(flags,
261 "Are you an experienced Citadel user",US_EXPERT);
262 if ( ((flags&US_EXPERT)==0) && (mode==1))
264 flags = set_attr(flags,
265 "Print last old message on New message request",US_LASTOLD);
266 if ((flags&US_EXPERT)==0) formout("unlisted");
267 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
268 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
269 if ((flags & US_NOPROMPT)==0)
270 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
271 flags = set_attr(flags,
272 "Pause after each screenful of text",US_PAGINATOR);
273 if (rc_floor_mode == RC_DEFAULT) {
274 flags = set_attr(flags,
275 "View rooms by floor",US_FLOORS);
277 if (rc_ansi_color == 3) {
278 flags = set_attr(flags,
279 "Enable color support",US_COLOR);
284 if (flags & US_EXPERT) {
285 flags = (flags ^ US_EXPERT);
286 printf("Expert mode now OFF\n");
289 flags = (flags | US_EXPERT);
290 printf("Expert mode now ON\n");
295 if (flags & US_FLOORS) {
296 flags = (flags ^ US_FLOORS);
297 printf("Floor mode now OFF\n");
300 flags = (flags | US_FLOORS);
301 printf("Floor mode now ON\n");
305 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
308 if (buf[0]!='2') printf("%s\n",&buf[4]);
313 * getstring() - get a line of text from a file
314 * ignores lines beginning with "#"
316 int getstring(FILE *fp, char *string)
331 } while(string[0]=='#');
332 return(strlen(string));
335 int pattern(char *search, char *patn) /* Searches for patn in search string */
340 for (a=0; a<strlen(search); ++a)
341 { b=struncmp(&search[a],patn,strlen(patn));
347 void interr(int errnum) /* display internal error as defined in errmsgs */
349 printf("*** INTERNAL ERROR %d\n",errnum);
350 printf("(Press any key to continue)\n");
358 * Check to see if we need to pause at the end of a screen.
359 * If we do, we have to disable server keepalives during the pause because
360 * we are probably in the middle of a server operation and the NOOP command
361 * would confuse everything.
363 int checkpagin(int lp, int pagin, int height)
365 if (pagin!=1) return(0);
366 if (lp>=(height-1)) {
367 set_keepalives(KA_NO);
369 set_keepalives(KA_YES);
376 void strproc(char *string)
380 if (strlen(string)==0) return;
382 /* Convert non-printable characters to blanks */
383 for (a=0; a<strlen(string); ++a) {
384 if (string[a]<32) string[a]=32;
385 if (string[a]>126) string[a]=32;
388 /* Remove leading and trailing blanks */
389 while(string[0]<33) strcpy(string,&string[1]);
390 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
392 /* Remove double blanks */
393 for (a=0; a<strlen(string); ++a) {
394 if ((string[a]==32)&&(string[a+1]==32)) {
395 strcpy(&string[a],&string[a+1]);
400 /* remove characters which would interfere with the network */
401 for (a=0; a<strlen(string); ++a) {
402 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
403 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
404 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
405 if (string[a]==',') strcpy(&string[a],&string[a+1]);
406 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
407 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
413 #ifndef HAVE_STRERROR
415 * replacement strerror() for systems that don't have it
417 char *strerror(int e)
421 sprintf(buf,"errno = %d",e);
427 void progress(long int curr, long int cmax)
429 static long dots_printed;
433 printf(".......................................");
434 printf(".......................................\r");
438 else if (curr==cmax) {
439 printf("\r%79s\n","");
442 a=(curr * 100) / cmax;
444 while (dots_printed < a) {
454 * NOT the same locate_host() in locate_host.c. This one just does a
455 * 'who am i' to try to discover where the user is...
457 void locate_host(char *hbuf)
463 who = (FILE *)popen("who am i","r");
465 strcpy(hbuf,serv_info.serv_fqdn);
472 for (a=0; a<strlen(buf); ++a) {
473 if ((buf[a]=='(')||(buf[a]==')')) ++b;
476 strcpy(hbuf,serv_info.serv_fqdn);
480 for (a=0; a<strlen(buf); ++a) {
482 strcpy(buf,&buf[a+1]);
485 for (a=0; a<strlen(buf); ++a) {
486 if (buf[a]==')') buf[a] = 0;
489 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
490 else strncpy(hbuf,buf,24);
494 * miscellaneous server commands (testing, etc.)
496 void misc_server_cmd(char *cmd) {
503 while (serv_gets(buf), strcmp(buf,"000")) {
510 newprompt("> ",buf,255);
512 } while(strcmp(buf,"000"));
519 * compute the checksum of a file
521 int file_checksum(char *filename)
527 fp = fopen(filename,"r");
528 if (fp == NULL) return(0);
530 /* yes, this algorithm may allow cksum to overflow, but that's ok
531 * as long as it overflows consistently, which it will.
533 while (ch=getc(fp), ch>=0) {
534 cksum = (cksum + ch);
542 * nuke a directory and its contents
544 int nukedir(char *dirname)
550 dp = opendir(dirname);
555 while (d = readdir(dp), d != NULL) {
556 sprintf(filename, "%s/%s", dirname, d->d_name);
561 return(rmdir(dirname));