4 * Client-side support functions.
15 #include <sys/types.h>
16 #include <sys/ioctl.h>
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
27 # include <sys/time.h>
43 #ifndef HAVE_GETUTLINE
44 struct utmp *getutline(struct utmp *ut);
54 void sttybbs(int cmd);
55 void newprompt(char *prompt, char *str, int len);
56 void val_user(char *, int);
57 void formout(char *name);
58 void logoff(int code);
59 void set_keepalives(int s);
60 void strprompt(char *prompt, char *str, int len);
61 void newprompt(char *prompt, char *str, int len);
62 void color(int colornum);
64 #define IFAIDE if(axlevel>=6)
65 #define IFNAIDE if (axlevel<6)
67 extern unsigned userflags;
68 extern char *axdefs[7];
69 extern char sigcaught;
70 extern struct CtdlServInfo serv_info;
71 extern char rc_floor_mode;
72 extern int rc_ansi_color;
74 void back(int spaces) /* Destructive backspace */
77 for (a=1; a<=spaces; ++a) {
78 scr_putc(8); scr_putc(32); scr_putc(8);
82 void hit_any_key(void) { /* hit any key to continue */
87 scr_printf("%s\r",serv_info.serv_moreprompt);
91 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
95 if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
97 if (b == 'n' || b == 'N')
99 if (b==NEXT_KEY) sigcaught = SIGINT;
100 if (b==STOP_KEY) sigcaught = SIGQUIT;
104 * change a user's access level
119 newprompt("User name: ",who,25);
120 sprintf(buf,"AGUP %s",who);
124 scr_printf("%s\n",&buf[4]);
127 extract(who, &buf[4], 0);
128 extract(pass, &buf[4], 1);
129 flags = extract_int(&buf[4], 2);
130 timescalled = extract_int(&buf[4], 3);
131 posted = extract_int(&buf[4], 4);
132 axlevel = extract_int(&buf[4], 5);
133 usernum = extract_long(&buf[4], 6);
134 lastcall = extract_long(&buf[4], 7);
135 userpurge = extract_int(&buf[4], 8);
137 val_user(who, 0); /* Display registration */
138 if (boolprompt("Change password", 0)) {
139 strprompt("Password", pass, 19);
141 axlevel = intprompt("Access level", axlevel, 0, 6);
142 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
143 posted = intprompt("Messages posted", posted, 0, INT_MAX);
144 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
145 userpurge = intprompt("Purge time (in days, 0 for system default",
146 userpurge, 0, INT_MAX);
148 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
149 who, pass, flags, timescalled, posted, axlevel, usernum,
150 (long)lastcall, userpurge);
154 scr_printf("%s\n",&buf[4]);
159 int set_attr(int sval, char *prompt, unsigned int sbit)
166 scr_printf("%45s ", prompt);
169 color(BRIGHT_MAGENTA);
170 scr_printf("%3s", ((temp&sbit) ? "Yes":"No"));
174 a=yesno_d(temp&sbit);
177 if (!a) temp=(temp^sbit);
182 * modes are: 0 - .EC command, 1 - .EC for new user,
183 * 2 - toggle Xpert mode 3 - toggle floor mode
185 void enter_config(int mode)
187 int width, height, flags, filter;
194 scr_printf("%s\n",&buf[4]);
198 width = extract_int(&buf[4],0);
199 height = extract_int(&buf[4],1);
200 flags = extract_int(&buf[4],2);
201 filter = extract_int(&buf[4],3);
203 if ((mode==0)||(mode==1)) {
205 width = intprompt("Enter your screen width",width,20,255);
206 height = intprompt("Enter your screen height",height,3,255);
208 flags = set_attr(flags,
209 "Are you an experienced Citadel user",US_EXPERT);
210 if ( ((flags&US_EXPERT)==0) && (mode==1))
212 flags = set_attr(flags,
213 "Print last old message on New message request",US_LASTOLD);
214 if ((flags&US_EXPERT)==0) formout("unlisted");
215 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
216 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
217 if ((flags & US_NOPROMPT)==0)
218 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
219 flags = set_attr(flags,
220 "Pause after each screenful of text",US_PAGINATOR);
221 if (rc_floor_mode == RC_DEFAULT) {
222 flags = set_attr(flags,
223 "View rooms by floor",US_FLOORS);
225 if (rc_ansi_color == 3) {
226 flags = set_attr(flags,
227 "Enable color support",US_COLOR);
230 /* filter = intprompt("Moderation filter level", filter, -63, 63); */
235 if (flags & US_EXPERT) {
236 flags = (flags ^ US_EXPERT);
237 scr_printf("Expert mode now OFF\n");
240 flags = (flags | US_EXPERT);
241 scr_printf("Expert mode now ON\n");
246 if (flags & US_FLOORS) {
247 flags = (flags ^ US_FLOORS);
248 scr_printf("Floor mode now OFF\n");
251 flags = (flags | US_FLOORS);
252 scr_printf("Floor mode now ON\n");
256 sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter);
259 if (buf[0]!='2') scr_printf("%s\n",&buf[4]);
264 * getstring() - get a line of text from a file
265 * ignores lines beginning with "#"
267 int getstring(FILE *fp, char *string)
282 } while(string[0]=='#');
283 return(strlen(string));
286 int pattern(char *search, char *patn) /* Searches for patn in search string */
291 for (a=0; a<strlen(search); ++a)
292 { b=strncasecmp(&search[a],patn,strlen(patn));
298 void interr(int errnum) /* display internal error as defined in errmsgs */
300 scr_printf("*** INTERNAL ERROR %d\n"
301 "(Press any key to continue)\n", errnum);
308 void strproc(char *string)
312 if (strlen(string)==0) return;
314 /* Convert non-printable characters to blanks */
315 for (a=0; a<strlen(string); ++a) {
316 if (string[a]<32) string[a]=32;
317 if (string[a]>126) string[a]=32;
320 /* Remove leading and trailing blanks */
321 while(string[0]<33) strcpy(string,&string[1]);
322 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
324 /* Remove double blanks */
325 for (a=0; a<strlen(string); ++a) {
326 if ((string[a]==32)&&(string[a+1]==32)) {
327 strcpy(&string[a],&string[a+1]);
332 /* remove characters which would interfere with the network */
333 for (a=0; a<strlen(string); ++a) {
334 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
335 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
336 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
337 if (string[a]==',') strcpy(&string[a],&string[a+1]);
338 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
339 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
345 #ifndef HAVE_STRERROR
347 * replacement strerror() for systems that don't have it
349 char *strerror(int e)
351 static char buf[128];
353 sprintf(buf,"errno = %d",e);
359 void progress(long int curr, long int cmax)
361 static long dots_printed;
365 scr_printf(".......................................");
366 scr_printf(".......................................\r");
370 else if (curr==cmax) {
371 scr_printf("\r%79s\n","");
374 a=(curr * 100) / cmax;
376 while (dots_printed < a) {
386 * NOT the same locate_host() in locate_host.c. This one just does a
387 * 'who am i' to try to discover where the user is...
389 void locate_host(char *hbuf)
396 who = (FILE *)popen("who am i","r");
398 strcpy(hbuf,serv_info.serv_fqdn);
401 fgets(buf,sizeof buf,who);
405 for (a=0; a<strlen(buf); ++a) {
406 if ((buf[a]=='(')||(buf[a]==')')) ++b;
409 strcpy(hbuf,serv_info.serv_fqdn);
413 for (a=0; a<strlen(buf); ++a) {
415 strcpy(buf,&buf[a+1]);
418 for (a=0; a<strlen(buf); ++a) {
419 if (buf[a]==')') buf[a] = 0;
422 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
423 else strncpy(hbuf,buf,24);
425 char *tty = ttyname(0);
426 #ifdef HAVE_GETUTXLINE
427 struct utmpx ut, *put;
429 struct utmp ut, *put;
434 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
438 if (strncmp(tty, "/dev/", 5))
441 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
443 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
444 if ((put = getutxline(&ut)) == NULL)
446 if ((put = getutline(&ut)) == NULL)
450 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
451 if (put->ut_type == USER_PROCESS) {
453 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
455 safestrncpy(hbuf, put->ut_host, 24);
458 safestrncpy(hbuf, put->ut_line, 24);
459 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
463 #endif /* HAVE_UTMP_H */
467 * miscellaneous server commands (testing, etc.)
469 void misc_server_cmd(char *cmd) {
474 scr_printf("%s\n",buf);
476 set_keepalives(KA_NO);
477 while (serv_gets(buf), strcmp(buf,"000")) {
478 scr_printf("%s\n",buf);
480 set_keepalives(KA_YES);
485 newprompt("> ",buf,255);
487 } while(strcmp(buf,"000"));
494 * compute the checksum of a file
496 int file_checksum(char *filename)
502 fp = fopen(filename,"r");
503 if (fp == NULL) return(0);
505 /* yes, this algorithm may allow cksum to overflow, but that's ok
506 * as long as it overflows consistently, which it will.
508 while (ch=getc(fp), ch>=0) {
509 cksum = (cksum + ch);
517 * nuke a directory and its contents
519 int nukedir(char *dirname)
525 dp = opendir(dirname);
530 while (d = readdir(dp), d != NULL) {
531 sprintf(filename, "%s/%s", dirname, d->d_name);
536 return(rmdir(dirname));