1 /* Citadel/UX support routines */
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
30 void sttybbs(int cmd);
31 void newprompt(char *prompt, char *str, int len);
32 void val_user(char *, int);
33 void formout(char *name);
34 void logoff(int code);
35 void set_keepalives(int s);
36 void strprompt(char *prompt, char *str, int len);
37 void newprompt(char *prompt, char *str, int len);
38 void color(int colornum);
40 #define IFAIDE if(axlevel>=6)
41 #define IFNAIDE if (axlevel<6)
43 extern unsigned userflags;
44 extern char *axdefs[7];
45 extern char sigcaught;
46 extern struct CtdlServInfo serv_info;
47 extern char rc_floor_mode;
48 extern int rc_ansi_color;
50 int struncmp(char *lstr, char *rstr, int len)
55 lc=tolower(lstr[pos]);
56 rc=tolower(rstr[pos]);
57 if ((lc==0)&&(rc==0)) return(0);
58 if (lc<rc) return(-1);
67 * check for the presence of a character within a string (returns count)
69 int haschar(char *st, int ch)
73 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
78 void back(int spaces) /* Destructive backspace */
81 for (a=1; a<=spaces; ++a) {
82 putc(8,stdout); putc(32,stdout); putc(8,stdout);
86 void hit_any_key(void) { /* hit any key to continue */
89 printf("%s\r",serv_info.serv_moreprompt);
92 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
96 if (b==NEXT_KEY) sigcaught = SIGINT;
97 if (b==STOP_KEY) sigcaught = SIGQUIT;
101 * change a user's access level
116 newprompt("User name: ",who,25);
117 sprintf(buf,"AGUP %s",who);
121 printf("%s\n",&buf[4]);
124 extract(who, &buf[4], 0);
125 extract(pass, &buf[4], 1);
126 flags = extract_int(&buf[4], 2);
127 timescalled = extract_int(&buf[4], 3);
128 posted = extract_int(&buf[4], 4);
129 axlevel = extract_int(&buf[4], 5);
130 usernum = extract_long(&buf[4], 6);
131 lastcall = extract_long(&buf[4], 7);
132 userpurge = extract_int(&buf[4], 8);
134 val_user(who, 0); /* Display registration */
135 strprompt("Password", pass, 19);
136 axlevel = intprompt("Access level", axlevel, 0, 6);
137 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
138 posted = intprompt("Messages posted", posted, 0, INT_MAX);
139 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
140 userpurge = intprompt("Purge time (in days, 0 for system default",
141 userpurge, 0, INT_MAX);
143 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
144 who, pass, flags, timescalled, posted, axlevel, usernum,
145 lastcall, userpurge);
149 printf("%s\n",&buf[4]);
154 int set_attr(int sval, char *prompt, unsigned int sbit)
161 printf("%45s [", prompt);
163 printf("%3s", ((temp&sbit) ? "Yes":"No"));
167 a=yesno_d(temp&sbit);
170 if (!a) temp=(temp^sbit);
175 * modes are: 0 - .EC command, 1 - .EC for new user,
176 * 2 - toggle Xpert mode 3 - toggle floor mode
178 void enter_config(int mode)
180 int width,height,flags;
187 printf("%s\n",&buf[4]);
191 width = extract_int(&buf[4],0);
192 height = extract_int(&buf[4],1);
193 flags = extract_int(&buf[4],2);
195 if ((mode==0)||(mode==1)) {
197 width = intprompt("Enter your screen width",width,20,255);
198 height = intprompt("Enter your screen height",height,3,255);
200 flags = set_attr(flags,
201 "Are you an experienced Citadel user",US_EXPERT);
202 if ( ((flags&US_EXPERT)==0) && (mode==1))
204 flags = set_attr(flags,
205 "Print last old message on New message request",US_LASTOLD);
206 if ((flags&US_EXPERT)==0) formout("unlisted");
207 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
208 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
209 if ((flags & US_NOPROMPT)==0)
210 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
211 flags = set_attr(flags,
212 "Pause after each screenful of text",US_PAGINATOR);
213 if (rc_floor_mode == RC_DEFAULT) {
214 flags = set_attr(flags,
215 "View rooms by floor",US_FLOORS);
217 if (rc_ansi_color == 3) {
218 flags = set_attr(flags,
219 "Enable color support",US_COLOR);
224 if (flags & US_EXPERT) {
225 flags = (flags ^ US_EXPERT);
226 printf("Expert mode now OFF\n");
229 flags = (flags | US_EXPERT);
230 printf("Expert mode now ON\n");
235 if (flags & US_FLOORS) {
236 flags = (flags ^ US_FLOORS);
237 printf("Floor mode now OFF\n");
240 flags = (flags | US_FLOORS);
241 printf("Floor mode now ON\n");
245 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
248 if (buf[0]!='2') printf("%s\n",&buf[4]);
253 * getstring() - get a line of text from a file
254 * ignores lines beginning with "#"
256 int getstring(FILE *fp, char *string)
271 } while(string[0]=='#');
272 return(strlen(string));
275 int pattern(char *search, char *patn) /* Searches for patn in search string */
280 for (a=0; a<strlen(search); ++a)
281 { b=struncmp(&search[a],patn,strlen(patn));
287 void interr(int errnum) /* display internal error as defined in errmsgs */
289 printf("*** INTERNAL ERROR %d\n",errnum);
290 printf("(Press any key to continue)\n");
298 * Check to see if we need to pause at the end of a screen.
299 * If we do, we have to disable server keepalives during the pause because
300 * we are probably in the middle of a server operation and the NOOP command
301 * would confuse everything.
303 int checkpagin(int lp, int pagin, int height)
305 if (pagin!=1) return(0);
306 if (lp>=(height-1)) {
307 set_keepalives(KA_NO);
309 set_keepalives(KA_YES);
316 void strproc(char *string)
320 if (strlen(string)==0) return;
322 /* Convert non-printable characters to blanks */
323 for (a=0; a<strlen(string); ++a) {
324 if (string[a]<32) string[a]=32;
325 if (string[a]>126) string[a]=32;
328 /* Remove leading and trailing blanks */
329 while(string[0]<33) strcpy(string,&string[1]);
330 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
332 /* Remove double blanks */
333 for (a=0; a<strlen(string); ++a) {
334 if ((string[a]==32)&&(string[a+1]==32)) {
335 strcpy(&string[a],&string[a+1]);
340 /* remove characters which would interfere with the network */
341 for (a=0; a<strlen(string); ++a) {
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]);
346 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
347 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
353 #ifndef HAVE_STRERROR
355 * replacement strerror() for systems that don't have it
357 char *strerror(int e)
361 sprintf(buf,"errno = %d",e);
367 void progress(long int curr, long int cmax)
369 static long dots_printed;
373 printf(".......................................");
374 printf(".......................................\r");
378 else if (curr==cmax) {
379 printf("\r%79s\n","");
382 a=(curr * 100) / cmax;
384 while (dots_printed < a) {
394 * NOT the same locate_host() in locate_host.c. This one just does a
395 * 'who am i' to try to discover where the user is...
397 void locate_host(char *hbuf)
404 who = (FILE *)popen("who am i","r");
406 strcpy(hbuf,serv_info.serv_fqdn);
413 for (a=0; a<strlen(buf); ++a) {
414 if ((buf[a]=='(')||(buf[a]==')')) ++b;
417 strcpy(hbuf,serv_info.serv_fqdn);
421 for (a=0; a<strlen(buf); ++a) {
423 strcpy(buf,&buf[a+1]);
426 for (a=0; a<strlen(buf); ++a) {
427 if (buf[a]==')') buf[a] = 0;
430 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
431 else strncpy(hbuf,buf,24);
433 char *tty = ttyname(0);
434 struct utmp ut, *put;
438 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
442 if (strncmp(tty, "/dev/", 5))
445 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
447 if ((put = getutline(&ut)) == NULL)
450 if (put->ut_type == USER_PROCESS) {
452 safestrncpy(hbuf, put->ut_host, 24);
454 safestrncpy(hbuf, put->ut_line, 24);
461 * miscellaneous server commands (testing, etc.)
463 void misc_server_cmd(char *cmd) {
470 set_keepalives(KA_NO);
471 while (serv_gets(buf), strcmp(buf,"000")) {
474 set_keepalives(KA_YES);
479 newprompt("> ",buf,255);
481 } while(strcmp(buf,"000"));
488 * compute the checksum of a file
490 int file_checksum(char *filename)
496 fp = fopen(filename,"r");
497 if (fp == NULL) return(0);
499 /* yes, this algorithm may allow cksum to overflow, but that's ok
500 * as long as it overflows consistently, which it will.
502 while (ch=getc(fp), ch>=0) {
503 cksum = (cksum + ch);
511 * nuke a directory and its contents
513 int nukedir(char *dirname)
519 dp = opendir(dirname);
524 while (d = readdir(dp), d != NULL) {
525 sprintf(filename, "%s/%s", dirname, d->d_name);
530 return(rmdir(dirname));