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;
45 int struncmp(char *lstr, char *rstr, int len)
50 lc=tolower(lstr[pos]);
51 rc=tolower(rstr[pos]);
52 if ((lc==0)&&(rc==0)) return(0);
53 if (lc<rc) return(-1);
62 * check for the presence of a character within a string (returns count)
64 int haschar(char *st, int ch)
68 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
74 * num_parms() - discover number of parameters...
76 int num_parms(char *source)
81 for (a=0; a<strlen(source); ++a)
82 if (source[a]=='|') ++count;
87 * extract() - extract a parameter from a series of "|" separated...
89 void extract(char *dest, char *source, int parmnum)
95 n = num_parms(source);
102 if ( (parmnum == 0) && (n == 1) ) {
107 while (count++ < parmnum) do {
109 } while( (strlen(buf)>0) && (buf[0]!='|') );
110 if (buf[0]=='|') strcpy(buf,&buf[1]);
111 for (count = 0; count<strlen(buf); ++count)
112 if (buf[count] == '|') buf[count] = 0;
117 * extract_int() - extract an int parm w/o supplying a buffer
119 int extract_int(char *source, int parmnum)
123 extract(buf,source,parmnum);
128 * extract_long() - extract a long parm w/o supplying a buffer
130 long extract_long(char *source, int parmnum)
134 extract(buf,source,parmnum);
138 void back(int spaces) /* Destructive backspace */
141 for (a=1; a<=spaces; ++a) {
142 putc(8,stdout); putc(32,stdout); putc(8,stdout);
146 void hit_any_key(void) { /* hit any key to continue */
149 printf("%s\r",serv_info.serv_moreprompt);
152 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
156 if (b==NEXT_KEY) sigcaught = SIGINT;
157 if (b==STOP_KEY) sigcaught = SIGQUIT;
161 * change a user's access level
176 newprompt("User name: ",who,25);
177 sprintf(buf,"AGUP %s",who);
181 printf("%s\n",&buf[4]);
184 extract(who, &buf[4], 0);
185 extract(pass, &buf[4], 1);
186 flags = extract_int(&buf[4], 2);
187 timescalled = extract_int(&buf[4], 3);
188 posted = extract_int(&buf[4], 4);
189 axlevel = extract_int(&buf[4], 5);
190 usernum = extract_long(&buf[4], 6);
191 lastcall = extract_long(&buf[4], 7);
192 userpurge = extract_int(&buf[4], 8);
194 val_user(who); /* Display registration, and set access level */
195 strprompt("Password", pass, 19);
196 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
197 posted = intprompt("Messages posted", posted, 0, INT_MAX);
198 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
199 userpurge = intprompt("Purge time (in days, 0 for system default",
200 userpurge, 0, INT_MAX);
202 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
203 who, pass, flags, timescalled, posted, axlevel, usernum,
204 lastcall, userpurge);
208 printf("%s\n",&buf[4]);
213 int set_attr(int sval, char *prompt, unsigned int sbit)
220 printf("%45s [", prompt);
222 printf("%3s", ((temp&sbit) ? "Yes":"No"));
226 a=yesno_d(temp&sbit);
229 if (!a) temp=(temp^sbit);
234 * modes are: 0 - .EC command, 1 - .EC for new user,
235 * 2 - toggle Xpert mode 3 - toggle floor mode
237 void enter_config(int mode)
239 int width,height,flags;
246 printf("%s\n",&buf[4]);
250 width = extract_int(&buf[4],0);
251 height = extract_int(&buf[4],1);
252 flags = extract_int(&buf[4],2);
254 if ((mode==0)||(mode==1)) {
256 width = intprompt("Enter your screen width",width,20,255);
257 height = intprompt("Enter your screen height",height,3,255);
259 flags = set_attr(flags,
260 "Are you an experienced Citadel user",US_EXPERT);
261 if ( ((flags&US_EXPERT)==0) && (mode==1))
263 flags = set_attr(flags,
264 "Print last old message on New message request",US_LASTOLD);
265 if ((flags&US_EXPERT)==0) formout("unlisted");
266 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
267 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
268 if ((flags & US_NOPROMPT)==0)
269 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
270 flags = set_attr(flags,
271 "Pause after each screenful of text",US_PAGINATOR);
272 if (rc_floor_mode == RC_DEFAULT) {
273 flags = set_attr(flags,
274 "View rooms by floor",US_FLOORS);
279 if (flags & US_EXPERT) {
280 flags = (flags ^ US_EXPERT);
281 printf("Expert mode now OFF\n");
284 flags = (flags | US_EXPERT);
285 printf("Expert mode now ON\n");
290 if (flags & US_FLOORS) {
291 flags = (flags ^ US_FLOORS);
292 printf("Floor mode now OFF\n");
295 flags = (flags | US_FLOORS);
296 printf("Floor mode now ON\n");
300 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
303 if (buf[0]!='2') printf("%s\n",&buf[4]);
308 * getstring() - get a line of text from a file
309 * ignores lines beginning with "#"
311 int getstring(FILE *fp, char *string)
326 } while(string[0]=='#');
327 return(strlen(string));
330 int pattern(char *search, char *patn) /* Searches for patn in search string */
335 for (a=0; a<strlen(search); ++a)
336 { b=struncmp(&search[a],patn,strlen(patn));
342 void interr(int errnum) /* display internal error as defined in errmsgs */
344 printf("*** INTERNAL ERROR %d\n",errnum);
345 printf("(Press any key to continue)\n");
353 * Check to see if we need to pause at the end of a screen.
354 * If we do, we have to disable server keepalives during the pause because
355 * we are probably in the middle of a server operation and the NOOP command
356 * would confuse everything.
358 int checkpagin(int lp, int pagin, int height)
360 if (pagin!=1) return(0);
361 if (lp>=(height-1)) {
362 set_keepalives(KA_NO);
364 set_keepalives(KA_YES);
371 void strproc(char *string)
375 if (strlen(string)==0) return;
377 /* Convert non-printable characters to blanks */
378 for (a=0; a<strlen(string); ++a) {
379 if (string[a]<32) string[a]=32;
380 if (string[a]>126) string[a]=32;
383 /* Remove leading and trailing blanks */
384 while(string[0]<33) strcpy(string,&string[1]);
385 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
387 /* Remove double blanks */
388 for (a=0; a<strlen(string); ++a) {
389 if ((string[a]==32)&&(string[a+1]==32)) {
390 strcpy(&string[a],&string[a+1]);
395 /* remove characters which would interfere with the network */
396 for (a=0; a<strlen(string); ++a) {
397 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
398 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
399 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
400 if (string[a]==',') strcpy(&string[a],&string[a+1]);
401 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
402 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
408 #ifndef HAVE_STRERROR
410 * replacement strerror() for systems that don't have it
412 char *strerror(int e)
416 sprintf(buf,"errno = %d",e);
422 void progress(long int curr, long int cmax)
424 static long dots_printed;
428 printf(".......................................");
429 printf(".......................................\r");
433 else if (curr==cmax) {
434 printf("\r%79s\n","");
437 a=(curr * 100) / cmax;
439 while (dots_printed < a) {
449 * NOT the same locate_host() in locate_host.c. This one just does a
450 * 'who am i' to try to discover where the user is...
452 void locate_host(char *hbuf)
458 who = (FILE *)popen("who am i","r");
460 strcpy(hbuf,serv_info.serv_fqdn);
467 for (a=0; a<strlen(buf); ++a) {
468 if ((buf[a]=='(')||(buf[a]==')')) ++b;
471 strcpy(hbuf,serv_info.serv_fqdn);
475 for (a=0; a<strlen(buf); ++a) {
477 strcpy(buf,&buf[a+1]);
480 for (a=0; a<strlen(buf); ++a) {
481 if (buf[a]==')') buf[a] = 0;
484 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
485 else strncpy(hbuf,buf,24);
489 * miscellaneous server commands (testing, etc.)
491 void misc_server_cmd(char *cmd) {
498 while (serv_gets(buf), strcmp(buf,"000")) {
505 newprompt("> ",buf,255);
507 } while(strcmp(buf,"000"));
514 * compute the checksum of a file
516 int file_checksum(char *filename)
522 fp = fopen(filename,"r");
523 if (fp == NULL) return(0);
525 /* yes, this algorithm may allow cksum to overflow, but that's ok
526 * as long as it overflows consistently, which it will.
528 while (ch=getc(fp), ch>=0) {
529 cksum = (cksum + ch);
537 * nuke a directory and its contents
539 int nukedir(char *dirname)
545 dp = opendir(dirname);
550 while (d = readdir(dp), d != NULL) {
551 sprintf(filename, "%s/%s", dirname, d->d_name);
556 return(rmdir(dirname));