1 /* Citadel/UX support routines */
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
23 #ifndef HAVE_GETUTLINE
24 struct utmp *getutline(struct utmp *ut);
34 void sttybbs(int cmd);
35 void newprompt(char *prompt, char *str, int len);
36 void val_user(char *, int);
37 void formout(char *name);
38 void logoff(int code);
39 void set_keepalives(int s);
40 void strprompt(char *prompt, char *str, int len);
41 void newprompt(char *prompt, char *str, int len);
42 void color(int colornum);
44 #define IFAIDE if(axlevel>=6)
45 #define IFNAIDE if (axlevel<6)
47 extern unsigned userflags;
48 extern char *axdefs[7];
49 extern char sigcaught;
50 extern struct CtdlServInfo serv_info;
51 extern char rc_floor_mode;
52 extern int rc_ansi_color;
54 int struncmp(char *lstr, char *rstr, int len)
59 lc=tolower(lstr[pos]);
60 rc=tolower(rstr[pos]);
61 if ((lc==0)&&(rc==0)) return(0);
62 if (lc<rc) return(-1);
71 * check for the presence of a character within a string (returns count)
73 int haschar(char *st, int ch)
77 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
82 void back(int spaces) /* Destructive backspace */
85 for (a=1; a<=spaces; ++a) {
86 putc(8,stdout); putc(32,stdout); putc(8,stdout);
90 void hit_any_key(void) { /* hit any key to continue */
93 printf("%s\r",serv_info.serv_moreprompt);
96 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
100 if (b==NEXT_KEY) sigcaught = SIGINT;
101 if (b==STOP_KEY) sigcaught = SIGQUIT;
105 * change a user's access level
120 newprompt("User name: ",who,25);
121 sprintf(buf,"AGUP %s",who);
125 printf("%s\n",&buf[4]);
128 extract(who, &buf[4], 0);
129 extract(pass, &buf[4], 1);
130 flags = extract_int(&buf[4], 2);
131 timescalled = extract_int(&buf[4], 3);
132 posted = extract_int(&buf[4], 4);
133 axlevel = extract_int(&buf[4], 5);
134 usernum = extract_long(&buf[4], 6);
135 lastcall = extract_long(&buf[4], 7);
136 userpurge = extract_int(&buf[4], 8);
138 val_user(who, 0); /* Display registration */
139 strprompt("Password", pass, 19);
140 axlevel = intprompt("Access level", axlevel, 0, 6);
141 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
142 posted = intprompt("Messages posted", posted, 0, INT_MAX);
143 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
144 userpurge = intprompt("Purge time (in days, 0 for system default",
145 userpurge, 0, INT_MAX);
147 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
148 who, pass, flags, timescalled, posted, axlevel, usernum,
149 (long)lastcall, userpurge);
153 printf("%s\n",&buf[4]);
158 int set_attr(int sval, char *prompt, unsigned int sbit)
165 printf("%45s ", prompt);
168 color(BRIGHT_MAGENTA);
169 printf("%3s", ((temp&sbit) ? "Yes":"No"));
173 a=yesno_d(temp&sbit);
176 if (!a) temp=(temp^sbit);
181 * modes are: 0 - .EC command, 1 - .EC for new user,
182 * 2 - toggle Xpert mode 3 - toggle floor mode
184 void enter_config(int mode)
186 int width,height,flags;
193 printf("%s\n",&buf[4]);
197 width = extract_int(&buf[4],0);
198 height = extract_int(&buf[4],1);
199 flags = extract_int(&buf[4],2);
201 if ((mode==0)||(mode==1)) {
203 width = intprompt("Enter your screen width",width,20,255);
204 height = intprompt("Enter your screen height",height,3,255);
206 flags = set_attr(flags,
207 "Are you an experienced Citadel user",US_EXPERT);
208 if ( ((flags&US_EXPERT)==0) && (mode==1))
210 flags = set_attr(flags,
211 "Print last old message on New message request",US_LASTOLD);
212 if ((flags&US_EXPERT)==0) formout("unlisted");
213 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
214 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
215 if ((flags & US_NOPROMPT)==0)
216 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
217 flags = set_attr(flags,
218 "Pause after each screenful of text",US_PAGINATOR);
219 if (rc_floor_mode == RC_DEFAULT) {
220 flags = set_attr(flags,
221 "View rooms by floor",US_FLOORS);
223 if (rc_ansi_color == 3) {
224 flags = set_attr(flags,
225 "Enable color support",US_COLOR);
230 if (flags & US_EXPERT) {
231 flags = (flags ^ US_EXPERT);
232 printf("Expert mode now OFF\n");
235 flags = (flags | US_EXPERT);
236 printf("Expert mode now ON\n");
241 if (flags & US_FLOORS) {
242 flags = (flags ^ US_FLOORS);
243 printf("Floor mode now OFF\n");
246 flags = (flags | US_FLOORS);
247 printf("Floor mode now ON\n");
251 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
254 if (buf[0]!='2') printf("%s\n",&buf[4]);
259 * getstring() - get a line of text from a file
260 * ignores lines beginning with "#"
262 int getstring(FILE *fp, char *string)
277 } while(string[0]=='#');
278 return(strlen(string));
281 int pattern(char *search, char *patn) /* Searches for patn in search string */
286 for (a=0; a<strlen(search); ++a)
287 { b=struncmp(&search[a],patn,strlen(patn));
293 void interr(int errnum) /* display internal error as defined in errmsgs */
295 printf("*** INTERNAL ERROR %d\n",errnum);
296 printf("(Press any key to continue)\n");
304 * Check to see if we need to pause at the end of a screen.
305 * If we do, we have to disable server keepalives during the pause because
306 * we are probably in the middle of a server operation and the NOOP command
307 * would confuse everything.
309 int checkpagin(int lp, int pagin, int height)
311 if (pagin!=1) return(0);
312 if (lp>=(height-1)) {
313 set_keepalives(KA_NO);
315 set_keepalives(KA_YES);
322 void strproc(char *string)
326 if (strlen(string)==0) return;
328 /* Convert non-printable characters to blanks */
329 for (a=0; a<strlen(string); ++a) {
330 if (string[a]<32) string[a]=32;
331 if (string[a]>126) string[a]=32;
334 /* Remove leading and trailing blanks */
335 while(string[0]<33) strcpy(string,&string[1]);
336 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
338 /* Remove double blanks */
339 for (a=0; a<strlen(string); ++a) {
340 if ((string[a]==32)&&(string[a+1]==32)) {
341 strcpy(&string[a],&string[a+1]);
346 /* remove characters which would interfere with the network */
347 for (a=0; a<strlen(string); ++a) {
348 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
349 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
350 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
351 if (string[a]==',') strcpy(&string[a],&string[a+1]);
352 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
353 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
359 #ifndef HAVE_STRERROR
361 * replacement strerror() for systems that don't have it
363 char *strerror(int e)
367 sprintf(buf,"errno = %d",e);
373 void progress(long int curr, long int cmax)
375 static long dots_printed;
379 printf(".......................................");
380 printf(".......................................\r");
384 else if (curr==cmax) {
385 printf("\r%79s\n","");
388 a=(curr * 100) / cmax;
390 while (dots_printed < a) {
400 * NOT the same locate_host() in locate_host.c. This one just does a
401 * 'who am i' to try to discover where the user is...
403 void locate_host(char *hbuf)
410 who = (FILE *)popen("who am i","r");
412 strcpy(hbuf,serv_info.serv_fqdn);
419 for (a=0; a<strlen(buf); ++a) {
420 if ((buf[a]=='(')||(buf[a]==')')) ++b;
423 strcpy(hbuf,serv_info.serv_fqdn);
427 for (a=0; a<strlen(buf); ++a) {
429 strcpy(buf,&buf[a+1]);
432 for (a=0; a<strlen(buf); ++a) {
433 if (buf[a]==')') buf[a] = 0;
436 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
437 else strncpy(hbuf,buf,24);
439 char *tty = ttyname(0);
440 struct utmp ut, *put;
444 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
448 if (strncmp(tty, "/dev/", 5))
451 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
453 if ((put = getutline(&ut)) == NULL)
457 if (put->ut_type == USER_PROCESS) {
461 safestrncpy(hbuf, put->ut_host, 24);
464 safestrncpy(hbuf, put->ut_line, 24);
469 #endif /* HAVE_UTMP_H */
473 * miscellaneous server commands (testing, etc.)
475 void misc_server_cmd(char *cmd) {
482 set_keepalives(KA_NO);
483 while (serv_gets(buf), strcmp(buf,"000")) {
486 set_keepalives(KA_YES);
491 newprompt("> ",buf,255);
493 } while(strcmp(buf,"000"));
500 * compute the checksum of a file
502 int file_checksum(char *filename)
508 fp = fopen(filename,"r");
509 if (fp == NULL) return(0);
511 /* yes, this algorithm may allow cksum to overflow, but that's ok
512 * as long as it overflows consistently, which it will.
514 while (ch=getc(fp), ch>=0) {
515 cksum = (cksum + ch);
523 * nuke a directory and its contents
525 int nukedir(char *dirname)
531 dp = opendir(dirname);
536 while (d = readdir(dp), d != NULL) {
537 sprintf(filename, "%s/%s", dirname, d->d_name);
542 return(rmdir(dirname));