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>
41 #ifndef HAVE_GETUTLINE
42 struct utmp *getutline(struct utmp *ut);
52 void sttybbs(int cmd);
53 void newprompt(char *prompt, char *str, int len);
54 void val_user(char *, int);
55 void formout(char *name);
56 void logoff(int code);
57 void set_keepalives(int s);
58 void strprompt(char *prompt, char *str, int len);
59 void newprompt(char *prompt, char *str, int len);
60 void color(int colornum);
62 #define IFAIDE if(axlevel>=6)
63 #define IFNAIDE if (axlevel<6)
65 extern unsigned userflags;
66 extern char *axdefs[7];
67 extern char sigcaught;
68 extern struct CtdlServInfo serv_info;
69 extern char rc_floor_mode;
70 extern int rc_ansi_color;
72 void back(int spaces) /* Destructive backspace */
75 for (a=1; a<=spaces; ++a) {
76 putc(8,stdout); putc(32,stdout); putc(8,stdout);
80 void hit_any_key(void) { /* hit any key to continue */
85 printf("%s\r",serv_info.serv_moreprompt);
89 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
93 if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
95 if (b == 'n' || b == 'N')
97 if (b==NEXT_KEY) sigcaught = SIGINT;
98 if (b==STOP_KEY) sigcaught = SIGQUIT;
102 * change a user's access level
117 newprompt("User name: ",who,25);
118 sprintf(buf,"AGUP %s",who);
122 printf("%s\n",&buf[4]);
125 extract(who, &buf[4], 0);
126 extract(pass, &buf[4], 1);
127 flags = extract_int(&buf[4], 2);
128 timescalled = extract_int(&buf[4], 3);
129 posted = extract_int(&buf[4], 4);
130 axlevel = extract_int(&buf[4], 5);
131 usernum = extract_long(&buf[4], 6);
132 lastcall = extract_long(&buf[4], 7);
133 userpurge = extract_int(&buf[4], 8);
135 val_user(who, 0); /* Display registration */
136 if (boolprompt("Change password", 0)) {
137 strprompt("Password", pass, 19);
139 axlevel = intprompt("Access level", axlevel, 0, 6);
140 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
141 posted = intprompt("Messages posted", posted, 0, INT_MAX);
142 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
143 userpurge = intprompt("Purge time (in days, 0 for system default",
144 userpurge, 0, INT_MAX);
146 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
147 who, pass, flags, timescalled, posted, axlevel, usernum,
148 (long)lastcall, userpurge);
152 printf("%s\n",&buf[4]);
157 int set_attr(int sval, char *prompt, unsigned int sbit)
164 printf("%45s ", prompt);
167 color(BRIGHT_MAGENTA);
168 printf("%3s", ((temp&sbit) ? "Yes":"No"));
172 a=yesno_d(temp&sbit);
175 if (!a) temp=(temp^sbit);
180 * modes are: 0 - .EC command, 1 - .EC for new user,
181 * 2 - toggle Xpert mode 3 - toggle floor mode
183 void enter_config(int mode)
185 int width, height, flags, filter;
192 printf("%s\n",&buf[4]);
196 width = extract_int(&buf[4],0);
197 height = extract_int(&buf[4],1);
198 flags = extract_int(&buf[4],2);
199 filter = extract_int(&buf[4],3);
201 if ((mode==0)||(mode==1)) {
203 width = intprompt("Enter your screen width",width,20,255);
204 height = intprompt("Enter your screen height",height,3,255);
206 flags = set_attr(flags,
207 "Are you an experienced Citadel user",US_EXPERT);
208 if ( ((flags&US_EXPERT)==0) && (mode==1))
210 flags = set_attr(flags,
211 "Print last old message on New message request",US_LASTOLD);
212 if ((flags&US_EXPERT)==0) formout("unlisted");
213 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
214 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
215 if ((flags & US_NOPROMPT)==0)
216 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
217 flags = set_attr(flags,
218 "Pause after each screenful of text",US_PAGINATOR);
219 if (rc_floor_mode == RC_DEFAULT) {
220 flags = set_attr(flags,
221 "View rooms by floor",US_FLOORS);
223 if (rc_ansi_color == 3) {
224 flags = set_attr(flags,
225 "Enable color support",US_COLOR);
228 /* filter = intprompt("Moderation filter level", filter, -63, 63); */
233 if (flags & US_EXPERT) {
234 flags = (flags ^ US_EXPERT);
235 printf("Expert mode now OFF\n");
238 flags = (flags | US_EXPERT);
239 printf("Expert mode now ON\n");
244 if (flags & US_FLOORS) {
245 flags = (flags ^ US_FLOORS);
246 printf("Floor mode now OFF\n");
249 flags = (flags | US_FLOORS);
250 printf("Floor mode now ON\n");
254 sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter);
257 if (buf[0]!='2') printf("%s\n",&buf[4]);
262 * getstring() - get a line of text from a file
263 * ignores lines beginning with "#"
265 int getstring(FILE *fp, char *string)
280 } while(string[0]=='#');
281 return(strlen(string));
284 int pattern(char *search, char *patn) /* Searches for patn in search string */
289 for (a=0; a<strlen(search); ++a)
290 { b=strncasecmp(&search[a],patn,strlen(patn));
296 void interr(int errnum) /* display internal error as defined in errmsgs */
298 printf("*** INTERNAL ERROR %d\n",errnum);
299 printf("(Press any key to continue)\n");
306 void strproc(char *string)
310 if (strlen(string)==0) return;
312 /* Convert non-printable characters to blanks */
313 for (a=0; a<strlen(string); ++a) {
314 if (string[a]<32) string[a]=32;
315 if (string[a]>126) string[a]=32;
318 /* Remove leading and trailing blanks */
319 while(string[0]<33) strcpy(string,&string[1]);
320 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
322 /* Remove double blanks */
323 for (a=0; a<strlen(string); ++a) {
324 if ((string[a]==32)&&(string[a+1]==32)) {
325 strcpy(&string[a],&string[a+1]);
330 /* remove characters which would interfere with the network */
331 for (a=0; a<strlen(string); ++a) {
332 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
333 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
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]);
343 #ifndef HAVE_STRERROR
345 * replacement strerror() for systems that don't have it
347 char *strerror(int e)
351 sprintf(buf,"errno = %d",e);
357 void progress(long int curr, long int cmax)
359 static long dots_printed;
363 printf(".......................................");
364 printf(".......................................\r");
368 else if (curr==cmax) {
369 printf("\r%79s\n","");
372 a=(curr * 100) / cmax;
374 while (dots_printed < a) {
384 * NOT the same locate_host() in locate_host.c. This one just does a
385 * 'who am i' to try to discover where the user is...
387 void locate_host(char *hbuf)
394 who = (FILE *)popen("who am i","r");
396 strcpy(hbuf,serv_info.serv_fqdn);
399 fgets(buf,sizeof buf,who);
403 for (a=0; a<strlen(buf); ++a) {
404 if ((buf[a]=='(')||(buf[a]==')')) ++b;
407 strcpy(hbuf,serv_info.serv_fqdn);
411 for (a=0; a<strlen(buf); ++a) {
413 strcpy(buf,&buf[a+1]);
416 for (a=0; a<strlen(buf); ++a) {
417 if (buf[a]==')') buf[a] = 0;
420 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
421 else strncpy(hbuf,buf,24);
423 char *tty = ttyname(0);
424 #ifdef HAVE_GETUTXLINE
425 struct utmpx ut, *put;
427 struct utmp ut, *put;
432 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
436 if (strncmp(tty, "/dev/", 5))
439 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
441 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
442 if ((put = getutxline(&ut)) == NULL)
444 if ((put = getutline(&ut)) == NULL)
448 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
449 if (put->ut_type == USER_PROCESS) {
451 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
453 safestrncpy(hbuf, put->ut_host, 24);
456 safestrncpy(hbuf, put->ut_line, 24);
457 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
461 #endif /* HAVE_UTMP_H */
465 * miscellaneous server commands (testing, etc.)
467 void misc_server_cmd(char *cmd) {
474 set_keepalives(KA_NO);
475 while (serv_gets(buf), strcmp(buf,"000")) {
478 set_keepalives(KA_YES);
483 newprompt("> ",buf,255);
485 } while(strcmp(buf,"000"));
492 * compute the checksum of a file
494 int file_checksum(char *filename)
500 fp = fopen(filename,"r");
501 if (fp == NULL) return(0);
503 /* yes, this algorithm may allow cksum to overflow, but that's ok
504 * as long as it overflows consistently, which it will.
506 while (ch=getc(fp), ch>=0) {
507 cksum = (cksum + ch);
515 * nuke a directory and its contents
517 int nukedir(char *dirname)
523 dp = opendir(dirname);
528 while (d = readdir(dp), d != NULL) {
529 sprintf(filename, "%s/%s", dirname, d->d_name);
534 return(rmdir(dirname));