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 void back(int spaces) /* Destructive backspace */
60 for (a=1; a<=spaces; ++a) {
61 putc(8,stdout); putc(32,stdout); putc(8,stdout);
65 void hit_any_key(void) { /* hit any key to continue */
70 printf("%s\r",serv_info.serv_moreprompt);
74 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
78 if (b==NEXT_KEY) sigcaught = SIGINT;
79 if (b==STOP_KEY) sigcaught = SIGQUIT;
83 * change a user's access level
98 newprompt("User name: ",who,25);
99 sprintf(buf,"AGUP %s",who);
103 printf("%s\n",&buf[4]);
106 extract(who, &buf[4], 0);
107 extract(pass, &buf[4], 1);
108 flags = extract_int(&buf[4], 2);
109 timescalled = extract_int(&buf[4], 3);
110 posted = extract_int(&buf[4], 4);
111 axlevel = extract_int(&buf[4], 5);
112 usernum = extract_long(&buf[4], 6);
113 lastcall = extract_long(&buf[4], 7);
114 userpurge = extract_int(&buf[4], 8);
116 val_user(who, 0); /* Display registration */
117 strprompt("Password", pass, 19);
118 axlevel = intprompt("Access level", axlevel, 0, 6);
119 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
120 posted = intprompt("Messages posted", posted, 0, INT_MAX);
121 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
122 userpurge = intprompt("Purge time (in days, 0 for system default",
123 userpurge, 0, INT_MAX);
125 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
126 who, pass, flags, timescalled, posted, axlevel, usernum,
127 (long)lastcall, userpurge);
131 printf("%s\n",&buf[4]);
136 int set_attr(int sval, char *prompt, unsigned int sbit)
143 printf("%45s ", prompt);
146 color(BRIGHT_MAGENTA);
147 printf("%3s", ((temp&sbit) ? "Yes":"No"));
151 a=yesno_d(temp&sbit);
154 if (!a) temp=(temp^sbit);
159 * modes are: 0 - .EC command, 1 - .EC for new user,
160 * 2 - toggle Xpert mode 3 - toggle floor mode
162 void enter_config(int mode)
164 int width,height,flags;
171 printf("%s\n",&buf[4]);
175 width = extract_int(&buf[4],0);
176 height = extract_int(&buf[4],1);
177 flags = extract_int(&buf[4],2);
179 if ((mode==0)||(mode==1)) {
181 width = intprompt("Enter your screen width",width,20,255);
182 height = intprompt("Enter your screen height",height,3,255);
184 flags = set_attr(flags,
185 "Are you an experienced Citadel user",US_EXPERT);
186 if ( ((flags&US_EXPERT)==0) && (mode==1))
188 flags = set_attr(flags,
189 "Print last old message on New message request",US_LASTOLD);
190 if ((flags&US_EXPERT)==0) formout("unlisted");
191 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
192 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
193 if ((flags & US_NOPROMPT)==0)
194 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
195 flags = set_attr(flags,
196 "Pause after each screenful of text",US_PAGINATOR);
197 if (rc_floor_mode == RC_DEFAULT) {
198 flags = set_attr(flags,
199 "View rooms by floor",US_FLOORS);
201 if (rc_ansi_color == 3) {
202 flags = set_attr(flags,
203 "Enable color support",US_COLOR);
208 if (flags & US_EXPERT) {
209 flags = (flags ^ US_EXPERT);
210 printf("Expert mode now OFF\n");
213 flags = (flags | US_EXPERT);
214 printf("Expert mode now ON\n");
219 if (flags & US_FLOORS) {
220 flags = (flags ^ US_FLOORS);
221 printf("Floor mode now OFF\n");
224 flags = (flags | US_FLOORS);
225 printf("Floor mode now ON\n");
229 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
232 if (buf[0]!='2') printf("%s\n",&buf[4]);
237 * getstring() - get a line of text from a file
238 * ignores lines beginning with "#"
240 int getstring(FILE *fp, char *string)
255 } while(string[0]=='#');
256 return(strlen(string));
259 int pattern(char *search, char *patn) /* Searches for patn in search string */
264 for (a=0; a<strlen(search); ++a)
265 { b=strncasecmp(&search[a],patn,strlen(patn));
271 void interr(int errnum) /* display internal error as defined in errmsgs */
273 printf("*** INTERNAL ERROR %d\n",errnum);
274 printf("(Press any key to continue)\n");
281 void strproc(char *string)
285 if (strlen(string)==0) return;
287 /* Convert non-printable characters to blanks */
288 for (a=0; a<strlen(string); ++a) {
289 if (string[a]<32) string[a]=32;
290 if (string[a]>126) string[a]=32;
293 /* Remove leading and trailing blanks */
294 while(string[0]<33) strcpy(string,&string[1]);
295 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
297 /* Remove double blanks */
298 for (a=0; a<strlen(string); ++a) {
299 if ((string[a]==32)&&(string[a+1]==32)) {
300 strcpy(&string[a],&string[a+1]);
305 /* remove characters which would interfere with the network */
306 for (a=0; a<strlen(string); ++a) {
307 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
308 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
309 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
310 if (string[a]==',') strcpy(&string[a],&string[a+1]);
311 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
312 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
318 #ifndef HAVE_STRERROR
320 * replacement strerror() for systems that don't have it
322 char *strerror(int e)
326 sprintf(buf,"errno = %d",e);
332 void progress(long int curr, long int cmax)
334 static long dots_printed;
338 printf(".......................................");
339 printf(".......................................\r");
343 else if (curr==cmax) {
344 printf("\r%79s\n","");
347 a=(curr * 100) / cmax;
349 while (dots_printed < a) {
359 * NOT the same locate_host() in locate_host.c. This one just does a
360 * 'who am i' to try to discover where the user is...
362 void locate_host(char *hbuf)
369 who = (FILE *)popen("who am i","r");
371 strcpy(hbuf,serv_info.serv_fqdn);
378 for (a=0; a<strlen(buf); ++a) {
379 if ((buf[a]=='(')||(buf[a]==')')) ++b;
382 strcpy(hbuf,serv_info.serv_fqdn);
386 for (a=0; a<strlen(buf); ++a) {
388 strcpy(buf,&buf[a+1]);
391 for (a=0; a<strlen(buf); ++a) {
392 if (buf[a]==')') buf[a] = 0;
395 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
396 else strncpy(hbuf,buf,24);
398 char *tty = ttyname(0);
399 #ifdef HAVE_GETUTXLINE
400 struct utmpx ut, *put;
402 struct utmp ut, *put;
407 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
411 if (strncmp(tty, "/dev/", 5))
414 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
416 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
417 if ((put = getutxline(&ut)) == NULL)
419 if ((put = getutline(&ut)) == NULL)
423 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
424 if (put->ut_type == USER_PROCESS) {
426 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
428 safestrncpy(hbuf, put->ut_host, 24);
431 safestrncpy(hbuf, put->ut_line, 24);
432 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
436 #endif /* HAVE_UTMP_H */
440 * miscellaneous server commands (testing, etc.)
442 void misc_server_cmd(char *cmd) {
449 set_keepalives(KA_NO);
450 while (serv_gets(buf), strcmp(buf,"000")) {
453 set_keepalives(KA_YES);
458 newprompt("> ",buf,255);
460 } while(strcmp(buf,"000"));
467 * compute the checksum of a file
469 int file_checksum(char *filename)
475 fp = fopen(filename,"r");
476 if (fp == NULL) return(0);
478 /* yes, this algorithm may allow cksum to overflow, but that's ok
479 * as long as it overflows consistently, which it will.
481 while (ch=getc(fp), ch>=0) {
482 cksum = (cksum + ch);
490 * nuke a directory and its contents
492 int nukedir(char *dirname)
498 dp = opendir(dirname);
503 while (d = readdir(dp), d != NULL) {
504 sprintf(filename, "%s/%s", dirname, d->d_name);
509 return(rmdir(dirname));