4 * Client-side support functions.
15 #include <sys/types.h>
16 #include <sys/ioctl.h>
30 #ifndef HAVE_GETUTLINE
31 struct utmp *getutline(struct utmp *ut);
41 void sttybbs(int cmd);
42 void newprompt(char *prompt, char *str, int len);
43 void val_user(char *, int);
44 void formout(char *name);
45 void logoff(int code);
46 void set_keepalives(int s);
47 void strprompt(char *prompt, char *str, int len);
48 void newprompt(char *prompt, char *str, int len);
49 void color(int colornum);
51 #define IFAIDE if(axlevel>=6)
52 #define IFNAIDE if (axlevel<6)
54 extern unsigned userflags;
55 extern char *axdefs[7];
56 extern char sigcaught;
57 extern struct CtdlServInfo serv_info;
58 extern char rc_floor_mode;
59 extern int rc_ansi_color;
61 void back(int spaces) /* Destructive backspace */
64 for (a=1; a<=spaces; ++a) {
65 putc(8,stdout); putc(32,stdout); putc(8,stdout);
69 void hit_any_key(void) { /* hit any key to continue */
74 printf("%s\r",serv_info.serv_moreprompt);
78 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
82 if (b==NEXT_KEY) sigcaught = SIGINT;
83 if (b==STOP_KEY) sigcaught = SIGQUIT;
87 * change a user's access level
102 newprompt("User name: ",who,25);
103 sprintf(buf,"AGUP %s",who);
107 printf("%s\n",&buf[4]);
110 extract(who, &buf[4], 0);
111 extract(pass, &buf[4], 1);
112 flags = extract_int(&buf[4], 2);
113 timescalled = extract_int(&buf[4], 3);
114 posted = extract_int(&buf[4], 4);
115 axlevel = extract_int(&buf[4], 5);
116 usernum = extract_long(&buf[4], 6);
117 lastcall = extract_long(&buf[4], 7);
118 userpurge = extract_int(&buf[4], 8);
120 val_user(who, 0); /* Display registration */
121 strprompt("Password", pass, 19);
122 axlevel = intprompt("Access level", axlevel, 0, 6);
123 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
124 posted = intprompt("Messages posted", posted, 0, INT_MAX);
125 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
126 userpurge = intprompt("Purge time (in days, 0 for system default",
127 userpurge, 0, INT_MAX);
129 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
130 who, pass, flags, timescalled, posted, axlevel, usernum,
131 (long)lastcall, userpurge);
135 printf("%s\n",&buf[4]);
140 int set_attr(int sval, char *prompt, unsigned int sbit)
147 printf("%45s ", prompt);
150 color(BRIGHT_MAGENTA);
151 printf("%3s", ((temp&sbit) ? "Yes":"No"));
155 a=yesno_d(temp&sbit);
158 if (!a) temp=(temp^sbit);
163 * modes are: 0 - .EC command, 1 - .EC for new user,
164 * 2 - toggle Xpert mode 3 - toggle floor mode
166 void enter_config(int mode)
168 int width, height, flags, filter;
175 printf("%s\n",&buf[4]);
179 width = extract_int(&buf[4],0);
180 height = extract_int(&buf[4],1);
181 flags = extract_int(&buf[4],2);
182 filter = extract_int(&buf[4],3);
184 if ((mode==0)||(mode==1)) {
186 width = intprompt("Enter your screen width",width,20,255);
187 height = intprompt("Enter your screen height",height,3,255);
189 flags = set_attr(flags,
190 "Are you an experienced Citadel user",US_EXPERT);
191 if ( ((flags&US_EXPERT)==0) && (mode==1))
193 flags = set_attr(flags,
194 "Print last old message on New message request",US_LASTOLD);
195 if ((flags&US_EXPERT)==0) formout("unlisted");
196 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
197 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
198 if ((flags & US_NOPROMPT)==0)
199 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
200 flags = set_attr(flags,
201 "Pause after each screenful of text",US_PAGINATOR);
202 if (rc_floor_mode == RC_DEFAULT) {
203 flags = set_attr(flags,
204 "View rooms by floor",US_FLOORS);
206 if (rc_ansi_color == 3) {
207 flags = set_attr(flags,
208 "Enable color support",US_COLOR);
211 filter = intprompt("Moderation filter level", filter, -63, 63);
216 if (flags & US_EXPERT) {
217 flags = (flags ^ US_EXPERT);
218 printf("Expert mode now OFF\n");
221 flags = (flags | US_EXPERT);
222 printf("Expert mode now ON\n");
227 if (flags & US_FLOORS) {
228 flags = (flags ^ US_FLOORS);
229 printf("Floor mode now OFF\n");
232 flags = (flags | US_FLOORS);
233 printf("Floor mode now ON\n");
237 sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter);
240 if (buf[0]!='2') printf("%s\n",&buf[4]);
245 * getstring() - get a line of text from a file
246 * ignores lines beginning with "#"
248 int getstring(FILE *fp, char *string)
263 } while(string[0]=='#');
264 return(strlen(string));
267 int pattern(char *search, char *patn) /* Searches for patn in search string */
272 for (a=0; a<strlen(search); ++a)
273 { b=strncasecmp(&search[a],patn,strlen(patn));
279 void interr(int errnum) /* display internal error as defined in errmsgs */
281 printf("*** INTERNAL ERROR %d\n",errnum);
282 printf("(Press any key to continue)\n");
289 void strproc(char *string)
293 if (strlen(string)==0) return;
295 /* Convert non-printable characters to blanks */
296 for (a=0; a<strlen(string); ++a) {
297 if (string[a]<32) string[a]=32;
298 if (string[a]>126) string[a]=32;
301 /* Remove leading and trailing blanks */
302 while(string[0]<33) strcpy(string,&string[1]);
303 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
305 /* Remove double blanks */
306 for (a=0; a<strlen(string); ++a) {
307 if ((string[a]==32)&&(string[a+1]==32)) {
308 strcpy(&string[a],&string[a+1]);
313 /* remove characters which would interfere with the network */
314 for (a=0; a<strlen(string); ++a) {
315 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
316 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
317 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
318 if (string[a]==',') strcpy(&string[a],&string[a+1]);
319 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
320 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
326 #ifndef HAVE_STRERROR
328 * replacement strerror() for systems that don't have it
330 char *strerror(int e)
334 sprintf(buf,"errno = %d",e);
340 void progress(long int curr, long int cmax)
342 static long dots_printed;
346 printf(".......................................");
347 printf(".......................................\r");
351 else if (curr==cmax) {
352 printf("\r%79s\n","");
355 a=(curr * 100) / cmax;
357 while (dots_printed < a) {
367 * NOT the same locate_host() in locate_host.c. This one just does a
368 * 'who am i' to try to discover where the user is...
370 void locate_host(char *hbuf)
377 who = (FILE *)popen("who am i","r");
379 strcpy(hbuf,serv_info.serv_fqdn);
386 for (a=0; a<strlen(buf); ++a) {
387 if ((buf[a]=='(')||(buf[a]==')')) ++b;
390 strcpy(hbuf,serv_info.serv_fqdn);
394 for (a=0; a<strlen(buf); ++a) {
396 strcpy(buf,&buf[a+1]);
399 for (a=0; a<strlen(buf); ++a) {
400 if (buf[a]==')') buf[a] = 0;
403 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
404 else strncpy(hbuf,buf,24);
406 char *tty = ttyname(0);
407 #ifdef HAVE_GETUTXLINE
408 struct utmpx ut, *put;
410 struct utmp ut, *put;
415 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
419 if (strncmp(tty, "/dev/", 5))
422 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
424 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
425 if ((put = getutxline(&ut)) == NULL)
427 if ((put = getutline(&ut)) == NULL)
431 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
432 if (put->ut_type == USER_PROCESS) {
434 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
436 safestrncpy(hbuf, put->ut_host, 24);
439 safestrncpy(hbuf, put->ut_line, 24);
440 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
444 #endif /* HAVE_UTMP_H */
448 * miscellaneous server commands (testing, etc.)
450 void misc_server_cmd(char *cmd) {
457 set_keepalives(KA_NO);
458 while (serv_gets(buf), strcmp(buf,"000")) {
461 set_keepalives(KA_YES);
466 newprompt("> ",buf,255);
468 } while(strcmp(buf,"000"));
475 * compute the checksum of a file
477 int file_checksum(char *filename)
483 fp = fopen(filename,"r");
484 if (fp == NULL) return(0);
486 /* yes, this algorithm may allow cksum to overflow, but that's ok
487 * as long as it overflows consistently, which it will.
489 while (ch=getc(fp), ch>=0) {
490 cksum = (cksum + ch);
498 * nuke a directory and its contents
500 int nukedir(char *dirname)
506 dp = opendir(dirname);
511 while (d = readdir(dp), d != NULL) {
512 sprintf(filename, "%s/%s", dirname, d->d_name);
517 return(rmdir(dirname));