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 if (boolprompt("Change password", 0)) {
122 strprompt("Password", pass, 19);
124 axlevel = intprompt("Access level", axlevel, 0, 6);
125 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
126 posted = intprompt("Messages posted", posted, 0, INT_MAX);
127 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
128 userpurge = intprompt("Purge time (in days, 0 for system default",
129 userpurge, 0, INT_MAX);
131 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
132 who, pass, flags, timescalled, posted, axlevel, usernum,
133 (long)lastcall, userpurge);
137 printf("%s\n",&buf[4]);
142 int set_attr(int sval, char *prompt, unsigned int sbit)
149 printf("%45s ", prompt);
152 color(BRIGHT_MAGENTA);
153 printf("%3s", ((temp&sbit) ? "Yes":"No"));
157 a=yesno_d(temp&sbit);
160 if (!a) temp=(temp^sbit);
165 * modes are: 0 - .EC command, 1 - .EC for new user,
166 * 2 - toggle Xpert mode 3 - toggle floor mode
168 void enter_config(int mode)
170 int width, height, flags, filter;
177 printf("%s\n",&buf[4]);
181 width = extract_int(&buf[4],0);
182 height = extract_int(&buf[4],1);
183 flags = extract_int(&buf[4],2);
184 filter = extract_int(&buf[4],3);
186 if ((mode==0)||(mode==1)) {
188 width = intprompt("Enter your screen width",width,20,255);
189 height = intprompt("Enter your screen height",height,3,255);
191 flags = set_attr(flags,
192 "Are you an experienced Citadel user",US_EXPERT);
193 if ( ((flags&US_EXPERT)==0) && (mode==1))
195 flags = set_attr(flags,
196 "Print last old message on New message request",US_LASTOLD);
197 if ((flags&US_EXPERT)==0) formout("unlisted");
198 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
199 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
200 if ((flags & US_NOPROMPT)==0)
201 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
202 flags = set_attr(flags,
203 "Pause after each screenful of text",US_PAGINATOR);
204 if (rc_floor_mode == RC_DEFAULT) {
205 flags = set_attr(flags,
206 "View rooms by floor",US_FLOORS);
208 if (rc_ansi_color == 3) {
209 flags = set_attr(flags,
210 "Enable color support",US_COLOR);
213 filter = intprompt("Moderation filter level", filter, -63, 63);
218 if (flags & US_EXPERT) {
219 flags = (flags ^ US_EXPERT);
220 printf("Expert mode now OFF\n");
223 flags = (flags | US_EXPERT);
224 printf("Expert mode now ON\n");
229 if (flags & US_FLOORS) {
230 flags = (flags ^ US_FLOORS);
231 printf("Floor mode now OFF\n");
234 flags = (flags | US_FLOORS);
235 printf("Floor mode now ON\n");
239 sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter);
242 if (buf[0]!='2') printf("%s\n",&buf[4]);
247 * getstring() - get a line of text from a file
248 * ignores lines beginning with "#"
250 int getstring(FILE *fp, char *string)
265 } while(string[0]=='#');
266 return(strlen(string));
269 int pattern(char *search, char *patn) /* Searches for patn in search string */
274 for (a=0; a<strlen(search); ++a)
275 { b=strncasecmp(&search[a],patn,strlen(patn));
281 void interr(int errnum) /* display internal error as defined in errmsgs */
283 printf("*** INTERNAL ERROR %d\n",errnum);
284 printf("(Press any key to continue)\n");
291 void strproc(char *string)
295 if (strlen(string)==0) return;
297 /* Convert non-printable characters to blanks */
298 for (a=0; a<strlen(string); ++a) {
299 if (string[a]<32) string[a]=32;
300 if (string[a]>126) string[a]=32;
303 /* Remove leading and trailing blanks */
304 while(string[0]<33) strcpy(string,&string[1]);
305 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
307 /* Remove double blanks */
308 for (a=0; a<strlen(string); ++a) {
309 if ((string[a]==32)&&(string[a+1]==32)) {
310 strcpy(&string[a],&string[a+1]);
315 /* remove characters which would interfere with the network */
316 for (a=0; a<strlen(string); ++a) {
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]);
321 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
322 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
328 #ifndef HAVE_STRERROR
330 * replacement strerror() for systems that don't have it
332 char *strerror(int e)
336 sprintf(buf,"errno = %d",e);
342 void progress(long int curr, long int cmax)
344 static long dots_printed;
348 printf(".......................................");
349 printf(".......................................\r");
353 else if (curr==cmax) {
354 printf("\r%79s\n","");
357 a=(curr * 100) / cmax;
359 while (dots_printed < a) {
369 * NOT the same locate_host() in locate_host.c. This one just does a
370 * 'who am i' to try to discover where the user is...
372 void locate_host(char *hbuf)
379 who = (FILE *)popen("who am i","r");
381 strcpy(hbuf,serv_info.serv_fqdn);
384 fgets(buf,sizeof buf,who);
388 for (a=0; a<strlen(buf); ++a) {
389 if ((buf[a]=='(')||(buf[a]==')')) ++b;
392 strcpy(hbuf,serv_info.serv_fqdn);
396 for (a=0; a<strlen(buf); ++a) {
398 strcpy(buf,&buf[a+1]);
401 for (a=0; a<strlen(buf); ++a) {
402 if (buf[a]==')') buf[a] = 0;
405 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
406 else strncpy(hbuf,buf,24);
408 char *tty = ttyname(0);
409 #ifdef HAVE_GETUTXLINE
410 struct utmpx ut, *put;
412 struct utmp ut, *put;
417 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
421 if (strncmp(tty, "/dev/", 5))
424 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
426 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
427 if ((put = getutxline(&ut)) == NULL)
429 if ((put = getutline(&ut)) == NULL)
433 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
434 if (put->ut_type == USER_PROCESS) {
436 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
438 safestrncpy(hbuf, put->ut_host, 24);
441 safestrncpy(hbuf, put->ut_line, 24);
442 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
446 #endif /* HAVE_UTMP_H */
450 * miscellaneous server commands (testing, etc.)
452 void misc_server_cmd(char *cmd) {
459 set_keepalives(KA_NO);
460 while (serv_gets(buf), strcmp(buf,"000")) {
463 set_keepalives(KA_YES);
468 newprompt("> ",buf,255);
470 } while(strcmp(buf,"000"));
477 * compute the checksum of a file
479 int file_checksum(char *filename)
485 fp = fopen(filename,"r");
486 if (fp == NULL) return(0);
488 /* yes, this algorithm may allow cksum to overflow, but that's ok
489 * as long as it overflows consistently, which it will.
491 while (ch=getc(fp), ch>=0) {
492 cksum = (cksum + ch);
500 * nuke a directory and its contents
502 int nukedir(char *dirname)
508 dp = opendir(dirname);
513 while (d = readdir(dp), d != NULL) {
514 sprintf(filename, "%s/%s", dirname, d->d_name);
519 return(rmdir(dirname));