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==NEXT_KEY) sigcaught = SIGINT;
94 if (b==STOP_KEY) sigcaught = SIGQUIT;
98 * change a user's access level
113 newprompt("User name: ",who,25);
114 sprintf(buf,"AGUP %s",who);
118 printf("%s\n",&buf[4]);
121 extract(who, &buf[4], 0);
122 extract(pass, &buf[4], 1);
123 flags = extract_int(&buf[4], 2);
124 timescalled = extract_int(&buf[4], 3);
125 posted = extract_int(&buf[4], 4);
126 axlevel = extract_int(&buf[4], 5);
127 usernum = extract_long(&buf[4], 6);
128 lastcall = extract_long(&buf[4], 7);
129 userpurge = extract_int(&buf[4], 8);
131 val_user(who, 0); /* Display registration */
132 if (boolprompt("Change password", 0)) {
133 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, filter;
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);
195 filter = extract_int(&buf[4],3);
197 if ((mode==0)||(mode==1)) {
199 width = intprompt("Enter your screen width",width,20,255);
200 height = intprompt("Enter your screen height",height,3,255);
202 flags = set_attr(flags,
203 "Are you an experienced Citadel user",US_EXPERT);
204 if ( ((flags&US_EXPERT)==0) && (mode==1))
206 flags = set_attr(flags,
207 "Print last old message on New message request",US_LASTOLD);
208 if ((flags&US_EXPERT)==0) formout("unlisted");
209 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
210 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
211 if ((flags & US_NOPROMPT)==0)
212 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
213 flags = set_attr(flags,
214 "Pause after each screenful of text",US_PAGINATOR);
215 if (rc_floor_mode == RC_DEFAULT) {
216 flags = set_attr(flags,
217 "View rooms by floor",US_FLOORS);
219 if (rc_ansi_color == 3) {
220 flags = set_attr(flags,
221 "Enable color support",US_COLOR);
224 /* filter = intprompt("Moderation filter level", filter, -63, 63); */
229 if (flags & US_EXPERT) {
230 flags = (flags ^ US_EXPERT);
231 printf("Expert mode now OFF\n");
234 flags = (flags | US_EXPERT);
235 printf("Expert mode now ON\n");
240 if (flags & US_FLOORS) {
241 flags = (flags ^ US_FLOORS);
242 printf("Floor mode now OFF\n");
245 flags = (flags | US_FLOORS);
246 printf("Floor mode now ON\n");
250 sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter);
253 if (buf[0]!='2') printf("%s\n",&buf[4]);
258 * getstring() - get a line of text from a file
259 * ignores lines beginning with "#"
261 int getstring(FILE *fp, char *string)
276 } while(string[0]=='#');
277 return(strlen(string));
280 int pattern(char *search, char *patn) /* Searches for patn in search string */
285 for (a=0; a<strlen(search); ++a)
286 { b=strncasecmp(&search[a],patn,strlen(patn));
292 void interr(int errnum) /* display internal error as defined in errmsgs */
294 printf("*** INTERNAL ERROR %d\n",errnum);
295 printf("(Press any key to continue)\n");
302 void strproc(char *string)
306 if (strlen(string)==0) return;
308 /* Convert non-printable characters to blanks */
309 for (a=0; a<strlen(string); ++a) {
310 if (string[a]<32) string[a]=32;
311 if (string[a]>126) string[a]=32;
314 /* Remove leading and trailing blanks */
315 while(string[0]<33) strcpy(string,&string[1]);
316 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
318 /* Remove double blanks */
319 for (a=0; a<strlen(string); ++a) {
320 if ((string[a]==32)&&(string[a+1]==32)) {
321 strcpy(&string[a],&string[a+1]);
326 /* remove characters which would interfere with the network */
327 for (a=0; a<strlen(string); ++a) {
328 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
329 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
330 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
331 if (string[a]==',') strcpy(&string[a],&string[a+1]);
332 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
333 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
339 #ifndef HAVE_STRERROR
341 * replacement strerror() for systems that don't have it
343 char *strerror(int e)
347 sprintf(buf,"errno = %d",e);
353 void progress(long int curr, long int cmax)
355 static long dots_printed;
359 printf(".......................................");
360 printf(".......................................\r");
364 else if (curr==cmax) {
365 printf("\r%79s\n","");
368 a=(curr * 100) / cmax;
370 while (dots_printed < a) {
380 * NOT the same locate_host() in locate_host.c. This one just does a
381 * 'who am i' to try to discover where the user is...
383 void locate_host(char *hbuf)
390 who = (FILE *)popen("who am i","r");
392 strcpy(hbuf,serv_info.serv_fqdn);
395 fgets(buf,sizeof buf,who);
399 for (a=0; a<strlen(buf); ++a) {
400 if ((buf[a]=='(')||(buf[a]==')')) ++b;
403 strcpy(hbuf,serv_info.serv_fqdn);
407 for (a=0; a<strlen(buf); ++a) {
409 strcpy(buf,&buf[a+1]);
412 for (a=0; a<strlen(buf); ++a) {
413 if (buf[a]==')') buf[a] = 0;
416 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
417 else strncpy(hbuf,buf,24);
419 char *tty = ttyname(0);
420 #ifdef HAVE_GETUTXLINE
421 struct utmpx ut, *put;
423 struct utmp ut, *put;
428 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
432 if (strncmp(tty, "/dev/", 5))
435 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
437 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
438 if ((put = getutxline(&ut)) == NULL)
440 if ((put = getutline(&ut)) == NULL)
444 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
445 if (put->ut_type == USER_PROCESS) {
447 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
449 safestrncpy(hbuf, put->ut_host, 24);
452 safestrncpy(hbuf, put->ut_line, 24);
453 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
457 #endif /* HAVE_UTMP_H */
461 * miscellaneous server commands (testing, etc.)
463 void misc_server_cmd(char *cmd) {
470 set_keepalives(KA_NO);
471 while (serv_gets(buf), strcmp(buf,"000")) {
474 set_keepalives(KA_YES);
479 newprompt("> ",buf,255);
481 } while(strcmp(buf,"000"));
488 * compute the checksum of a file
490 int file_checksum(char *filename)
496 fp = fopen(filename,"r");
497 if (fp == NULL) return(0);
499 /* yes, this algorithm may allow cksum to overflow, but that's ok
500 * as long as it overflows consistently, which it will.
502 while (ch=getc(fp), ch>=0) {
503 cksum = (cksum + ch);
511 * nuke a directory and its contents
513 int nukedir(char *dirname)
519 dp = opendir(dirname);
524 while (d = readdir(dp), d != NULL) {
525 sprintf(filename, "%s/%s", dirname, d->d_name);
530 return(rmdir(dirname));