1 /* Citadel/UX support routines */
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
27 void sttybbs(int cmd);
28 void newprompt(char *prompt, char *str, int len);
29 void val_user(char *, int);
30 void formout(char *name);
31 void logoff(int code);
32 void set_keepalives(int s);
33 void strprompt(char *prompt, char *str, int len);
34 void newprompt(char *prompt, char *str, int len);
35 void color(int colornum);
37 #define IFAIDE if(axlevel>=6)
38 #define IFNAIDE if (axlevel<6)
40 extern unsigned userflags;
41 extern char *axdefs[7];
42 extern char sigcaught;
43 extern struct CtdlServInfo serv_info;
44 extern char rc_floor_mode;
45 extern int rc_ansi_color;
47 int struncmp(char *lstr, char *rstr, int len)
52 lc=tolower(lstr[pos]);
53 rc=tolower(rstr[pos]);
54 if ((lc==0)&&(rc==0)) return(0);
55 if (lc<rc) return(-1);
64 * check for the presence of a character within a string (returns count)
66 int haschar(char *st, int ch)
70 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
75 void back(int spaces) /* Destructive backspace */
78 for (a=1; a<=spaces; ++a) {
79 putc(8,stdout); putc(32,stdout); putc(8,stdout);
83 void hit_any_key(void) { /* hit any key to continue */
86 printf("%s\r",serv_info.serv_moreprompt);
89 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
93 if (b==NEXT_KEY) sigcaught = SIGINT;
94 if (b==STOP_KEY) sigcaught = SIGQUIT;
98 * change a user's access level
113 newprompt("User name: ",who,25);
114 sprintf(buf,"AGUP %s",who);
118 printf("%s\n",&buf[4]);
121 extract(who, &buf[4], 0);
122 extract(pass, &buf[4], 1);
123 flags = extract_int(&buf[4], 2);
124 timescalled = extract_int(&buf[4], 3);
125 posted = extract_int(&buf[4], 4);
126 axlevel = extract_int(&buf[4], 5);
127 usernum = extract_long(&buf[4], 6);
128 lastcall = extract_long(&buf[4], 7);
129 userpurge = extract_int(&buf[4], 8);
131 val_user(who, 0); /* Display registration */
132 strprompt("Password", pass, 19);
133 axlevel = intprompt("Access level", axlevel, 0, 6);
134 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
135 posted = intprompt("Messages posted", posted, 0, INT_MAX);
136 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
137 userpurge = intprompt("Purge time (in days, 0 for system default",
138 userpurge, 0, INT_MAX);
140 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
141 who, pass, flags, timescalled, posted, axlevel, usernum,
142 lastcall, userpurge);
146 printf("%s\n",&buf[4]);
151 int set_attr(int sval, char *prompt, unsigned int sbit)
158 printf("%45s [", prompt);
160 printf("%3s", ((temp&sbit) ? "Yes":"No"));
164 a=yesno_d(temp&sbit);
167 if (!a) temp=(temp^sbit);
172 * modes are: 0 - .EC command, 1 - .EC for new user,
173 * 2 - toggle Xpert mode 3 - toggle floor mode
175 void enter_config(int mode)
177 int width,height,flags;
184 printf("%s\n",&buf[4]);
188 width = extract_int(&buf[4],0);
189 height = extract_int(&buf[4],1);
190 flags = extract_int(&buf[4],2);
192 if ((mode==0)||(mode==1)) {
194 width = intprompt("Enter your screen width",width,20,255);
195 height = intprompt("Enter your screen height",height,3,255);
197 flags = set_attr(flags,
198 "Are you an experienced Citadel user",US_EXPERT);
199 if ( ((flags&US_EXPERT)==0) && (mode==1))
201 flags = set_attr(flags,
202 "Print last old message on New message request",US_LASTOLD);
203 if ((flags&US_EXPERT)==0) formout("unlisted");
204 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
205 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
206 if ((flags & US_NOPROMPT)==0)
207 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
208 flags = set_attr(flags,
209 "Pause after each screenful of text",US_PAGINATOR);
210 if (rc_floor_mode == RC_DEFAULT) {
211 flags = set_attr(flags,
212 "View rooms by floor",US_FLOORS);
214 if (rc_ansi_color == 3) {
215 flags = set_attr(flags,
216 "Enable color support",US_COLOR);
221 if (flags & US_EXPERT) {
222 flags = (flags ^ US_EXPERT);
223 printf("Expert mode now OFF\n");
226 flags = (flags | US_EXPERT);
227 printf("Expert mode now ON\n");
232 if (flags & US_FLOORS) {
233 flags = (flags ^ US_FLOORS);
234 printf("Floor mode now OFF\n");
237 flags = (flags | US_FLOORS);
238 printf("Floor mode now ON\n");
242 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
245 if (buf[0]!='2') printf("%s\n",&buf[4]);
250 * getstring() - get a line of text from a file
251 * ignores lines beginning with "#"
253 int getstring(FILE *fp, char *string)
268 } while(string[0]=='#');
269 return(strlen(string));
272 int pattern(char *search, char *patn) /* Searches for patn in search string */
277 for (a=0; a<strlen(search); ++a)
278 { b=struncmp(&search[a],patn,strlen(patn));
284 void interr(int errnum) /* display internal error as defined in errmsgs */
286 printf("*** INTERNAL ERROR %d\n",errnum);
287 printf("(Press any key to continue)\n");
295 * Check to see if we need to pause at the end of a screen.
296 * If we do, we have to disable server keepalives during the pause because
297 * we are probably in the middle of a server operation and the NOOP command
298 * would confuse everything.
300 int checkpagin(int lp, int pagin, int height)
302 if (pagin!=1) return(0);
303 if (lp>=(height-1)) {
304 set_keepalives(KA_NO);
306 set_keepalives(KA_YES);
313 void strproc(char *string)
317 if (strlen(string)==0) return;
319 /* Convert non-printable characters to blanks */
320 for (a=0; a<strlen(string); ++a) {
321 if (string[a]<32) string[a]=32;
322 if (string[a]>126) string[a]=32;
325 /* Remove leading and trailing blanks */
326 while(string[0]<33) strcpy(string,&string[1]);
327 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
329 /* Remove double blanks */
330 for (a=0; a<strlen(string); ++a) {
331 if ((string[a]==32)&&(string[a+1]==32)) {
332 strcpy(&string[a],&string[a+1]);
337 /* remove characters which would interfere with the network */
338 for (a=0; a<strlen(string); ++a) {
339 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
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]);
350 #ifndef HAVE_STRERROR
352 * replacement strerror() for systems that don't have it
354 char *strerror(int e)
358 sprintf(buf,"errno = %d",e);
364 void progress(long int curr, long int cmax)
366 static long dots_printed;
370 printf(".......................................");
371 printf(".......................................\r");
375 else if (curr==cmax) {
376 printf("\r%79s\n","");
379 a=(curr * 100) / cmax;
381 while (dots_printed < a) {
391 * NOT the same locate_host() in locate_host.c. This one just does a
392 * 'who am i' to try to discover where the user is...
394 void locate_host(char *hbuf)
400 who = (FILE *)popen("who am i","r");
402 strcpy(hbuf,serv_info.serv_fqdn);
409 for (a=0; a<strlen(buf); ++a) {
410 if ((buf[a]=='(')||(buf[a]==')')) ++b;
413 strcpy(hbuf,serv_info.serv_fqdn);
417 for (a=0; a<strlen(buf); ++a) {
419 strcpy(buf,&buf[a+1]);
422 for (a=0; a<strlen(buf); ++a) {
423 if (buf[a]==')') buf[a] = 0;
426 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
427 else strncpy(hbuf,buf,24);
431 * miscellaneous server commands (testing, etc.)
433 void misc_server_cmd(char *cmd) {
440 set_keepalives(KA_NO);
441 while (serv_gets(buf), strcmp(buf,"000")) {
444 set_keepalives(KA_YES);
449 newprompt("> ",buf,255);
451 } while(strcmp(buf,"000"));
458 * compute the checksum of a file
460 int file_checksum(char *filename)
466 fp = fopen(filename,"r");
467 if (fp == NULL) return(0);
469 /* yes, this algorithm may allow cksum to overflow, but that's ok
470 * as long as it overflows consistently, which it will.
472 while (ch=getc(fp), ch>=0) {
473 cksum = (cksum + ch);
481 * nuke a directory and its contents
483 int nukedir(char *dirname)
489 dp = opendir(dirname);
494 while (d = readdir(dp), d != NULL) {
495 sprintf(filename, "%s/%s", dirname, d->d_name);
500 return(rmdir(dirname));