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 */
95 printf("%s\r",serv_info.serv_moreprompt);
99 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
103 if (b==NEXT_KEY) sigcaught = SIGINT;
104 if (b==STOP_KEY) sigcaught = SIGQUIT;
108 * change a user's access level
123 newprompt("User name: ",who,25);
124 sprintf(buf,"AGUP %s",who);
128 printf("%s\n",&buf[4]);
131 extract(who, &buf[4], 0);
132 extract(pass, &buf[4], 1);
133 flags = extract_int(&buf[4], 2);
134 timescalled = extract_int(&buf[4], 3);
135 posted = extract_int(&buf[4], 4);
136 axlevel = extract_int(&buf[4], 5);
137 usernum = extract_long(&buf[4], 6);
138 lastcall = extract_long(&buf[4], 7);
139 userpurge = extract_int(&buf[4], 8);
141 val_user(who, 0); /* Display registration */
142 strprompt("Password", pass, 19);
143 axlevel = intprompt("Access level", axlevel, 0, 6);
144 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
145 posted = intprompt("Messages posted", posted, 0, INT_MAX);
146 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
147 userpurge = intprompt("Purge time (in days, 0 for system default",
148 userpurge, 0, INT_MAX);
150 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
151 who, pass, flags, timescalled, posted, axlevel, usernum,
152 (long)lastcall, userpurge);
156 printf("%s\n",&buf[4]);
161 int set_attr(int sval, char *prompt, unsigned int sbit)
168 printf("%45s ", prompt);
171 color(BRIGHT_MAGENTA);
172 printf("%3s", ((temp&sbit) ? "Yes":"No"));
176 a=yesno_d(temp&sbit);
179 if (!a) temp=(temp^sbit);
184 * modes are: 0 - .EC command, 1 - .EC for new user,
185 * 2 - toggle Xpert mode 3 - toggle floor mode
187 void enter_config(int mode)
189 int width,height,flags;
196 printf("%s\n",&buf[4]);
200 width = extract_int(&buf[4],0);
201 height = extract_int(&buf[4],1);
202 flags = extract_int(&buf[4],2);
204 if ((mode==0)||(mode==1)) {
206 width = intprompt("Enter your screen width",width,20,255);
207 height = intprompt("Enter your screen height",height,3,255);
209 flags = set_attr(flags,
210 "Are you an experienced Citadel user",US_EXPERT);
211 if ( ((flags&US_EXPERT)==0) && (mode==1))
213 flags = set_attr(flags,
214 "Print last old message on New message request",US_LASTOLD);
215 if ((flags&US_EXPERT)==0) formout("unlisted");
216 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
217 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
218 if ((flags & US_NOPROMPT)==0)
219 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
220 flags = set_attr(flags,
221 "Pause after each screenful of text",US_PAGINATOR);
222 if (rc_floor_mode == RC_DEFAULT) {
223 flags = set_attr(flags,
224 "View rooms by floor",US_FLOORS);
226 if (rc_ansi_color == 3) {
227 flags = set_attr(flags,
228 "Enable color support",US_COLOR);
233 if (flags & US_EXPERT) {
234 flags = (flags ^ US_EXPERT);
235 printf("Expert mode now OFF\n");
238 flags = (flags | US_EXPERT);
239 printf("Expert mode now ON\n");
244 if (flags & US_FLOORS) {
245 flags = (flags ^ US_FLOORS);
246 printf("Floor mode now OFF\n");
249 flags = (flags | US_FLOORS);
250 printf("Floor mode now ON\n");
254 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
257 if (buf[0]!='2') printf("%s\n",&buf[4]);
262 * getstring() - get a line of text from a file
263 * ignores lines beginning with "#"
265 int getstring(FILE *fp, char *string)
280 } while(string[0]=='#');
281 return(strlen(string));
284 int pattern(char *search, char *patn) /* Searches for patn in search string */
289 for (a=0; a<strlen(search); ++a)
290 { b=struncmp(&search[a],patn,strlen(patn));
296 void interr(int errnum) /* display internal error as defined in errmsgs */
298 printf("*** INTERNAL ERROR %d\n",errnum);
299 printf("(Press any key to continue)\n");
307 * Check to see if we need to pause at the end of a screen.
308 * If we do, we have to disable server keepalives during the pause because
309 * we are probably in the middle of a server operation and the NOOP command
310 * would confuse everything.
312 int checkpagin(int lp, int pagin, int height)
314 if (pagin!=1) return(0);
315 if (lp>=(height-1)) {
316 set_keepalives(KA_NO);
318 set_keepalives(KA_YES);
325 void strproc(char *string)
329 if (strlen(string)==0) return;
331 /* Convert non-printable characters to blanks */
332 for (a=0; a<strlen(string); ++a) {
333 if (string[a]<32) string[a]=32;
334 if (string[a]>126) string[a]=32;
337 /* Remove leading and trailing blanks */
338 while(string[0]<33) strcpy(string,&string[1]);
339 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
341 /* Remove double blanks */
342 for (a=0; a<strlen(string); ++a) {
343 if ((string[a]==32)&&(string[a+1]==32)) {
344 strcpy(&string[a],&string[a+1]);
349 /* remove characters which would interfere with the network */
350 for (a=0; a<strlen(string); ++a) {
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]);
354 if (string[a]==',') strcpy(&string[a],&string[a+1]);
355 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
356 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
362 #ifndef HAVE_STRERROR
364 * replacement strerror() for systems that don't have it
366 char *strerror(int e)
370 sprintf(buf,"errno = %d",e);
376 void progress(long int curr, long int cmax)
378 static long dots_printed;
382 printf(".......................................");
383 printf(".......................................\r");
387 else if (curr==cmax) {
388 printf("\r%79s\n","");
391 a=(curr * 100) / cmax;
393 while (dots_printed < a) {
403 * NOT the same locate_host() in locate_host.c. This one just does a
404 * 'who am i' to try to discover where the user is...
406 void locate_host(char *hbuf)
413 who = (FILE *)popen("who am i","r");
415 strcpy(hbuf,serv_info.serv_fqdn);
422 for (a=0; a<strlen(buf); ++a) {
423 if ((buf[a]=='(')||(buf[a]==')')) ++b;
426 strcpy(hbuf,serv_info.serv_fqdn);
430 for (a=0; a<strlen(buf); ++a) {
432 strcpy(buf,&buf[a+1]);
435 for (a=0; a<strlen(buf); ++a) {
436 if (buf[a]==')') buf[a] = 0;
439 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
440 else strncpy(hbuf,buf,24);
442 char *tty = ttyname(0);
443 struct utmp ut, *put;
447 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
451 if (strncmp(tty, "/dev/", 5))
454 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
456 if ((put = getutline(&ut)) == NULL)
460 if (put->ut_type == USER_PROCESS) {
464 safestrncpy(hbuf, put->ut_host, 24);
467 safestrncpy(hbuf, put->ut_line, 24);
472 #endif /* HAVE_UTMP_H */
476 * miscellaneous server commands (testing, etc.)
478 void misc_server_cmd(char *cmd) {
485 set_keepalives(KA_NO);
486 while (serv_gets(buf), strcmp(buf,"000")) {
489 set_keepalives(KA_YES);
494 newprompt("> ",buf,255);
496 } while(strcmp(buf,"000"));
503 * compute the checksum of a file
505 int file_checksum(char *filename)
511 fp = fopen(filename,"r");
512 if (fp == NULL) return(0);
514 /* yes, this algorithm may allow cksum to overflow, but that's ok
515 * as long as it overflows consistently, which it will.
517 while (ch=getc(fp), ch>=0) {
518 cksum = (cksum + ch);
526 * nuke a directory and its contents
528 int nukedir(char *dirname)
534 dp = opendir(dirname);
539 while (d = readdir(dp), d != NULL) {
540 sprintf(filename, "%s/%s", dirname, d->d_name);
545 return(rmdir(dirname));