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 void back(int spaces) /* Destructive backspace */
74 for (a=1; a<=spaces; ++a) {
75 putc(8,stdout); putc(32,stdout); putc(8,stdout);
79 void hit_any_key(void) { /* hit any key to continue */
84 printf("%s\r",serv_info.serv_moreprompt);
88 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
92 if (b==NEXT_KEY) sigcaught = SIGINT;
93 if (b==STOP_KEY) sigcaught = SIGQUIT;
97 * change a user's access level
112 newprompt("User name: ",who,25);
113 sprintf(buf,"AGUP %s",who);
117 printf("%s\n",&buf[4]);
120 extract(who, &buf[4], 0);
121 extract(pass, &buf[4], 1);
122 flags = extract_int(&buf[4], 2);
123 timescalled = extract_int(&buf[4], 3);
124 posted = extract_int(&buf[4], 4);
125 axlevel = extract_int(&buf[4], 5);
126 usernum = extract_long(&buf[4], 6);
127 lastcall = extract_long(&buf[4], 7);
128 userpurge = extract_int(&buf[4], 8);
130 val_user(who, 0); /* Display registration */
131 strprompt("Password", pass, 19);
132 axlevel = intprompt("Access level", axlevel, 0, 6);
133 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
134 posted = intprompt("Messages posted", posted, 0, INT_MAX);
135 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
136 userpurge = intprompt("Purge time (in days, 0 for system default",
137 userpurge, 0, INT_MAX);
139 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
140 who, pass, flags, timescalled, posted, axlevel, usernum,
141 (long)lastcall, userpurge);
145 printf("%s\n",&buf[4]);
150 int set_attr(int sval, char *prompt, unsigned int sbit)
157 printf("%45s ", prompt);
160 color(BRIGHT_MAGENTA);
161 printf("%3s", ((temp&sbit) ? "Yes":"No"));
165 a=yesno_d(temp&sbit);
168 if (!a) temp=(temp^sbit);
173 * modes are: 0 - .EC command, 1 - .EC for new user,
174 * 2 - toggle Xpert mode 3 - toggle floor mode
176 void enter_config(int mode)
178 int width,height,flags;
185 printf("%s\n",&buf[4]);
189 width = extract_int(&buf[4],0);
190 height = extract_int(&buf[4],1);
191 flags = extract_int(&buf[4],2);
193 if ((mode==0)||(mode==1)) {
195 width = intprompt("Enter your screen width",width,20,255);
196 height = intprompt("Enter your screen height",height,3,255);
198 flags = set_attr(flags,
199 "Are you an experienced Citadel user",US_EXPERT);
200 if ( ((flags&US_EXPERT)==0) && (mode==1))
202 flags = set_attr(flags,
203 "Print last old message on New message request",US_LASTOLD);
204 if ((flags&US_EXPERT)==0) formout("unlisted");
205 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
206 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
207 if ((flags & US_NOPROMPT)==0)
208 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
209 flags = set_attr(flags,
210 "Pause after each screenful of text",US_PAGINATOR);
211 if (rc_floor_mode == RC_DEFAULT) {
212 flags = set_attr(flags,
213 "View rooms by floor",US_FLOORS);
215 if (rc_ansi_color == 3) {
216 flags = set_attr(flags,
217 "Enable color support",US_COLOR);
222 if (flags & US_EXPERT) {
223 flags = (flags ^ US_EXPERT);
224 printf("Expert mode now OFF\n");
227 flags = (flags | US_EXPERT);
228 printf("Expert mode now ON\n");
233 if (flags & US_FLOORS) {
234 flags = (flags ^ US_FLOORS);
235 printf("Floor mode now OFF\n");
238 flags = (flags | US_FLOORS);
239 printf("Floor mode now ON\n");
243 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
246 if (buf[0]!='2') printf("%s\n",&buf[4]);
251 * getstring() - get a line of text from a file
252 * ignores lines beginning with "#"
254 int getstring(FILE *fp, char *string)
269 } while(string[0]=='#');
270 return(strlen(string));
273 int pattern(char *search, char *patn) /* Searches for patn in search string */
278 for (a=0; a<strlen(search); ++a)
279 { b=struncmp(&search[a],patn,strlen(patn));
285 void interr(int errnum) /* display internal error as defined in errmsgs */
287 printf("*** INTERNAL ERROR %d\n",errnum);
288 printf("(Press any key to continue)\n");
296 * Check to see if we need to pause at the end of a screen.
297 * If we do, we have to disable server keepalives during the pause because
298 * we are probably in the middle of a server operation and the NOOP command
299 * would confuse everything.
301 int checkpagin(int lp, int pagin, int height)
303 if (pagin!=1) return(0);
304 if (lp>=(height-1)) {
305 set_keepalives(KA_NO);
307 set_keepalives(KA_YES);
314 void strproc(char *string)
318 if (strlen(string)==0) return;
320 /* Convert non-printable characters to blanks */
321 for (a=0; a<strlen(string); ++a) {
322 if (string[a]<32) string[a]=32;
323 if (string[a]>126) string[a]=32;
326 /* Remove leading and trailing blanks */
327 while(string[0]<33) strcpy(string,&string[1]);
328 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
330 /* Remove double blanks */
331 for (a=0; a<strlen(string); ++a) {
332 if ((string[a]==32)&&(string[a+1]==32)) {
333 strcpy(&string[a],&string[a+1]);
338 /* remove characters which would interfere with the network */
339 for (a=0; a<strlen(string); ++a) {
340 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
341 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
342 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
343 if (string[a]==',') strcpy(&string[a],&string[a+1]);
344 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
345 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
351 #ifndef HAVE_STRERROR
353 * replacement strerror() for systems that don't have it
355 char *strerror(int e)
359 sprintf(buf,"errno = %d",e);
365 void progress(long int curr, long int cmax)
367 static long dots_printed;
371 printf(".......................................");
372 printf(".......................................\r");
376 else if (curr==cmax) {
377 printf("\r%79s\n","");
380 a=(curr * 100) / cmax;
382 while (dots_printed < a) {
392 * NOT the same locate_host() in locate_host.c. This one just does a
393 * 'who am i' to try to discover where the user is...
395 void locate_host(char *hbuf)
402 who = (FILE *)popen("who am i","r");
404 strcpy(hbuf,serv_info.serv_fqdn);
411 for (a=0; a<strlen(buf); ++a) {
412 if ((buf[a]=='(')||(buf[a]==')')) ++b;
415 strcpy(hbuf,serv_info.serv_fqdn);
419 for (a=0; a<strlen(buf); ++a) {
421 strcpy(buf,&buf[a+1]);
424 for (a=0; a<strlen(buf); ++a) {
425 if (buf[a]==')') buf[a] = 0;
428 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
429 else strncpy(hbuf,buf,24);
431 char *tty = ttyname(0);
432 struct utmp ut, *put;
436 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
440 if (strncmp(tty, "/dev/", 5))
443 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
445 if ((put = getutline(&ut)) == NULL)
449 if (put->ut_type == USER_PROCESS) {
453 safestrncpy(hbuf, put->ut_host, 24);
456 safestrncpy(hbuf, put->ut_line, 24);
461 #endif /* HAVE_UTMP_H */
465 * miscellaneous server commands (testing, etc.)
467 void misc_server_cmd(char *cmd) {
474 set_keepalives(KA_NO);
475 while (serv_gets(buf), strcmp(buf,"000")) {
478 set_keepalives(KA_YES);
483 newprompt("> ",buf,255);
485 } while(strcmp(buf,"000"));
492 * compute the checksum of a file
494 int file_checksum(char *filename)
500 fp = fopen(filename,"r");
501 if (fp == NULL) return(0);
503 /* yes, this algorithm may allow cksum to overflow, but that's ok
504 * as long as it overflows consistently, which it will.
506 while (ch=getc(fp), ch>=0) {
507 cksum = (cksum + ch);
515 * nuke a directory and its contents
517 int nukedir(char *dirname)
523 dp = opendir(dirname);
528 while (d = readdir(dp), d != NULL) {
529 sprintf(filename, "%s/%s", dirname, d->d_name);
534 return(rmdir(dirname));