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, filter;
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);
178 filter = extract_int(&buf[4],3);
180 if ((mode==0)||(mode==1)) {
182 width = intprompt("Enter your screen width",width,20,255);
183 height = intprompt("Enter your screen height",height,3,255);
185 flags = set_attr(flags,
186 "Are you an experienced Citadel user",US_EXPERT);
187 if ( ((flags&US_EXPERT)==0) && (mode==1))
189 flags = set_attr(flags,
190 "Print last old message on New message request",US_LASTOLD);
191 if ((flags&US_EXPERT)==0) formout("unlisted");
192 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
193 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
194 if ((flags & US_NOPROMPT)==0)
195 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
196 flags = set_attr(flags,
197 "Pause after each screenful of text",US_PAGINATOR);
198 if (rc_floor_mode == RC_DEFAULT) {
199 flags = set_attr(flags,
200 "View rooms by floor",US_FLOORS);
202 if (rc_ansi_color == 3) {
203 flags = set_attr(flags,
204 "Enable color support",US_COLOR);
207 filter = intprompt("Moderation filter level", filter, -63, 63);
212 if (flags & US_EXPERT) {
213 flags = (flags ^ US_EXPERT);
214 printf("Expert mode now OFF\n");
217 flags = (flags | US_EXPERT);
218 printf("Expert mode now ON\n");
223 if (flags & US_FLOORS) {
224 flags = (flags ^ US_FLOORS);
225 printf("Floor mode now OFF\n");
228 flags = (flags | US_FLOORS);
229 printf("Floor mode now ON\n");
233 sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter);
236 if (buf[0]!='2') printf("%s\n",&buf[4]);
241 * getstring() - get a line of text from a file
242 * ignores lines beginning with "#"
244 int getstring(FILE *fp, char *string)
259 } while(string[0]=='#');
260 return(strlen(string));
263 int pattern(char *search, char *patn) /* Searches for patn in search string */
268 for (a=0; a<strlen(search); ++a)
269 { b=strncasecmp(&search[a],patn,strlen(patn));
275 void interr(int errnum) /* display internal error as defined in errmsgs */
277 printf("*** INTERNAL ERROR %d\n",errnum);
278 printf("(Press any key to continue)\n");
285 void strproc(char *string)
289 if (strlen(string)==0) return;
291 /* Convert non-printable characters to blanks */
292 for (a=0; a<strlen(string); ++a) {
293 if (string[a]<32) string[a]=32;
294 if (string[a]>126) string[a]=32;
297 /* Remove leading and trailing blanks */
298 while(string[0]<33) strcpy(string,&string[1]);
299 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
301 /* Remove double blanks */
302 for (a=0; a<strlen(string); ++a) {
303 if ((string[a]==32)&&(string[a+1]==32)) {
304 strcpy(&string[a],&string[a+1]);
309 /* remove characters which would interfere with the network */
310 for (a=0; a<strlen(string); ++a) {
311 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
312 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
313 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
314 if (string[a]==',') strcpy(&string[a],&string[a+1]);
315 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
316 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
322 #ifndef HAVE_STRERROR
324 * replacement strerror() for systems that don't have it
326 char *strerror(int e)
330 sprintf(buf,"errno = %d",e);
336 void progress(long int curr, long int cmax)
338 static long dots_printed;
342 printf(".......................................");
343 printf(".......................................\r");
347 else if (curr==cmax) {
348 printf("\r%79s\n","");
351 a=(curr * 100) / cmax;
353 while (dots_printed < a) {
363 * NOT the same locate_host() in locate_host.c. This one just does a
364 * 'who am i' to try to discover where the user is...
366 void locate_host(char *hbuf)
373 who = (FILE *)popen("who am i","r");
375 strcpy(hbuf,serv_info.serv_fqdn);
382 for (a=0; a<strlen(buf); ++a) {
383 if ((buf[a]=='(')||(buf[a]==')')) ++b;
386 strcpy(hbuf,serv_info.serv_fqdn);
390 for (a=0; a<strlen(buf); ++a) {
392 strcpy(buf,&buf[a+1]);
395 for (a=0; a<strlen(buf); ++a) {
396 if (buf[a]==')') buf[a] = 0;
399 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
400 else strncpy(hbuf,buf,24);
402 char *tty = ttyname(0);
403 #ifdef HAVE_GETUTXLINE
404 struct utmpx ut, *put;
406 struct utmp ut, *put;
411 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
415 if (strncmp(tty, "/dev/", 5))
418 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
420 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
421 if ((put = getutxline(&ut)) == NULL)
423 if ((put = getutline(&ut)) == NULL)
427 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
428 if (put->ut_type == USER_PROCESS) {
430 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
432 safestrncpy(hbuf, put->ut_host, 24);
435 safestrncpy(hbuf, put->ut_line, 24);
436 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
440 #endif /* HAVE_UTMP_H */
444 * miscellaneous server commands (testing, etc.)
446 void misc_server_cmd(char *cmd) {
453 set_keepalives(KA_NO);
454 while (serv_gets(buf), strcmp(buf,"000")) {
457 set_keepalives(KA_YES);
462 newprompt("> ",buf,255);
464 } while(strcmp(buf,"000"));
471 * compute the checksum of a file
473 int file_checksum(char *filename)
479 fp = fopen(filename,"r");
480 if (fp == NULL) return(0);
482 /* yes, this algorithm may allow cksum to overflow, but that's ok
483 * as long as it overflows consistently, which it will.
485 while (ch=getc(fp), ch>=0) {
486 cksum = (cksum + ch);
494 * nuke a directory and its contents
496 int nukedir(char *dirname)
502 dp = opendir(dirname);
507 while (d = readdir(dp), d != NULL) {
508 sprintf(filename, "%s/%s", dirname, d->d_name);
513 return(rmdir(dirname));