1 /* Citadel/UX support routines */
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
26 #ifndef HAVE_GETUTLINE
27 struct utmp *getutline(struct utmp *ut);
37 void sttybbs(int cmd);
38 void newprompt(char *prompt, char *str, int len);
39 void val_user(char *, int);
40 void formout(char *name);
41 void logoff(int code);
42 void set_keepalives(int s);
43 void strprompt(char *prompt, char *str, int len);
44 void newprompt(char *prompt, char *str, int len);
45 void color(int colornum);
47 #define IFAIDE if(axlevel>=6)
48 #define IFNAIDE if (axlevel<6)
50 extern unsigned userflags;
51 extern char *axdefs[7];
52 extern char sigcaught;
53 extern struct CtdlServInfo serv_info;
54 extern char rc_floor_mode;
55 extern int rc_ansi_color;
57 int struncmp(char *lstr, char *rstr, int len)
62 lc=tolower(lstr[pos]);
63 rc=tolower(rstr[pos]);
64 if ((lc==0)&&(rc==0)) return(0);
65 if (lc<rc) return(-1);
74 void back(int spaces) /* Destructive backspace */
77 for (a=1; a<=spaces; ++a) {
78 putc(8,stdout); putc(32,stdout); putc(8,stdout);
82 void hit_any_key(void) { /* hit any key to continue */
87 printf("%s\r",serv_info.serv_moreprompt);
91 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
95 if (b==NEXT_KEY) sigcaught = SIGINT;
96 if (b==STOP_KEY) sigcaught = SIGQUIT;
100 * change a user's access level
115 newprompt("User name: ",who,25);
116 sprintf(buf,"AGUP %s",who);
120 printf("%s\n",&buf[4]);
123 extract(who, &buf[4], 0);
124 extract(pass, &buf[4], 1);
125 flags = extract_int(&buf[4], 2);
126 timescalled = extract_int(&buf[4], 3);
127 posted = extract_int(&buf[4], 4);
128 axlevel = extract_int(&buf[4], 5);
129 usernum = extract_long(&buf[4], 6);
130 lastcall = extract_long(&buf[4], 7);
131 userpurge = extract_int(&buf[4], 8);
133 val_user(who, 0); /* Display registration */
134 strprompt("Password", pass, 19);
135 axlevel = intprompt("Access level", axlevel, 0, 6);
136 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
137 posted = intprompt("Messages posted", posted, 0, INT_MAX);
138 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
139 userpurge = intprompt("Purge time (in days, 0 for system default",
140 userpurge, 0, INT_MAX);
142 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
143 who, pass, flags, timescalled, posted, axlevel, usernum,
144 (long)lastcall, userpurge);
148 printf("%s\n",&buf[4]);
153 int set_attr(int sval, char *prompt, unsigned int sbit)
160 printf("%45s ", prompt);
163 color(BRIGHT_MAGENTA);
164 printf("%3s", ((temp&sbit) ? "Yes":"No"));
168 a=yesno_d(temp&sbit);
171 if (!a) temp=(temp^sbit);
176 * modes are: 0 - .EC command, 1 - .EC for new user,
177 * 2 - toggle Xpert mode 3 - toggle floor mode
179 void enter_config(int mode)
181 int width,height,flags;
188 printf("%s\n",&buf[4]);
192 width = extract_int(&buf[4],0);
193 height = extract_int(&buf[4],1);
194 flags = extract_int(&buf[4],2);
196 if ((mode==0)||(mode==1)) {
198 width = intprompt("Enter your screen width",width,20,255);
199 height = intprompt("Enter your screen height",height,3,255);
201 flags = set_attr(flags,
202 "Are you an experienced Citadel user",US_EXPERT);
203 if ( ((flags&US_EXPERT)==0) && (mode==1))
205 flags = set_attr(flags,
206 "Print last old message on New message request",US_LASTOLD);
207 if ((flags&US_EXPERT)==0) formout("unlisted");
208 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
209 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
210 if ((flags & US_NOPROMPT)==0)
211 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
212 flags = set_attr(flags,
213 "Pause after each screenful of text",US_PAGINATOR);
214 if (rc_floor_mode == RC_DEFAULT) {
215 flags = set_attr(flags,
216 "View rooms by floor",US_FLOORS);
218 if (rc_ansi_color == 3) {
219 flags = set_attr(flags,
220 "Enable color support",US_COLOR);
225 if (flags & US_EXPERT) {
226 flags = (flags ^ US_EXPERT);
227 printf("Expert mode now OFF\n");
230 flags = (flags | US_EXPERT);
231 printf("Expert mode now ON\n");
236 if (flags & US_FLOORS) {
237 flags = (flags ^ US_FLOORS);
238 printf("Floor mode now OFF\n");
241 flags = (flags | US_FLOORS);
242 printf("Floor mode now ON\n");
246 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
249 if (buf[0]!='2') printf("%s\n",&buf[4]);
254 * getstring() - get a line of text from a file
255 * ignores lines beginning with "#"
257 int getstring(FILE *fp, char *string)
272 } while(string[0]=='#');
273 return(strlen(string));
276 int pattern(char *search, char *patn) /* Searches for patn in search string */
281 for (a=0; a<strlen(search); ++a)
282 { b=struncmp(&search[a],patn,strlen(patn));
288 void interr(int errnum) /* display internal error as defined in errmsgs */
290 printf("*** INTERNAL ERROR %d\n",errnum);
291 printf("(Press any key to continue)\n");
299 * Check to see if we need to pause at the end of a screen.
300 * If we do, we have to disable server keepalives during the pause because
301 * we are probably in the middle of a server operation and the NOOP command
302 * would confuse everything.
304 int checkpagin(int lp, int pagin, int height)
306 if (pagin!=1) return(0);
307 if (lp>=(height-1)) {
308 set_keepalives(KA_NO);
310 set_keepalives(KA_YES);
317 void strproc(char *string)
321 if (strlen(string)==0) return;
323 /* Convert non-printable characters to blanks */
324 for (a=0; a<strlen(string); ++a) {
325 if (string[a]<32) string[a]=32;
326 if (string[a]>126) string[a]=32;
329 /* Remove leading and trailing blanks */
330 while(string[0]<33) strcpy(string,&string[1]);
331 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
333 /* Remove double blanks */
334 for (a=0; a<strlen(string); ++a) {
335 if ((string[a]==32)&&(string[a+1]==32)) {
336 strcpy(&string[a],&string[a+1]);
341 /* remove characters which would interfere with the network */
342 for (a=0; a<strlen(string); ++a) {
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]);
348 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
354 #ifndef HAVE_STRERROR
356 * replacement strerror() for systems that don't have it
358 char *strerror(int e)
362 sprintf(buf,"errno = %d",e);
368 void progress(long int curr, long int cmax)
370 static long dots_printed;
374 printf(".......................................");
375 printf(".......................................\r");
379 else if (curr==cmax) {
380 printf("\r%79s\n","");
383 a=(curr * 100) / cmax;
385 while (dots_printed < a) {
395 * NOT the same locate_host() in locate_host.c. This one just does a
396 * 'who am i' to try to discover where the user is...
398 void locate_host(char *hbuf)
405 who = (FILE *)popen("who am i","r");
407 strcpy(hbuf,serv_info.serv_fqdn);
414 for (a=0; a<strlen(buf); ++a) {
415 if ((buf[a]=='(')||(buf[a]==')')) ++b;
418 strcpy(hbuf,serv_info.serv_fqdn);
422 for (a=0; a<strlen(buf); ++a) {
424 strcpy(buf,&buf[a+1]);
427 for (a=0; a<strlen(buf); ++a) {
428 if (buf[a]==')') buf[a] = 0;
431 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
432 else strncpy(hbuf,buf,24);
434 char *tty = ttyname(0);
435 #ifdef HAVE_GETUTXLINE
436 struct utmpx ut, *put;
438 struct utmp ut, *put;
443 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
447 if (strncmp(tty, "/dev/", 5))
450 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
452 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
453 if ((put = getutxline(&ut)) == NULL)
455 if ((put = getutline(&ut)) == NULL)
459 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
460 if (put->ut_type == USER_PROCESS) {
462 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
464 safestrncpy(hbuf, put->ut_host, 24);
467 safestrncpy(hbuf, put->ut_line, 24);
468 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
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));