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);
53 #include "citadel_decls.h"
54 #include "routines2.h"
56 #define IFAIDE if(axlevel>=6)
57 #define IFNAIDE if (axlevel<6)
59 extern unsigned userflags;
60 extern char *axdefs[7];
61 extern char sigcaught;
62 extern struct CtdlServInfo serv_info;
63 extern char rc_floor_mode;
64 extern int rc_ansi_color;
65 extern int rc_prompt_control;
67 void back(int spaces) /* Destructive backspace */
70 for (a=1; a<=spaces; ++a) {
71 scr_putc(8); scr_putc(32); scr_putc(8);
75 void hit_any_key(void) { /* hit any key to continue */
80 scr_printf("%s\r",serv_info.serv_moreprompt);
84 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
88 if ( (rc_prompt_control == 1)
89 || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
90 if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
92 if (b == 'n' || b == 'N')
95 if (b==NEXT_KEY) sigcaught = SIGINT;
96 if (b==STOP_KEY) sigcaught = SIGQUIT;
100 * change a user's access level
116 newprompt("User name: ",who,25);
117 AGUP: snprintf(buf, sizeof buf, "AGUP %s",who);
121 scr_printf("%s\n",&buf[4]);
122 scr_printf("Do you want to create this user? ");
124 snprintf(buf, sizeof buf, "CREU %s", who);
131 scr_printf("%s\n",&buf[4]);
136 extract(who, &buf[4], 0);
137 extract(pass, &buf[4], 1);
138 flags = extract_int(&buf[4], 2);
139 timescalled = extract_int(&buf[4], 3);
140 posted = extract_int(&buf[4], 4);
141 axlevel = extract_int(&buf[4], 5);
142 usernum = extract_long(&buf[4], 6);
143 lastcall = extract_long(&buf[4], 7);
144 userpurge = extract_int(&buf[4], 8);
146 val_user(who, 0); /* Display registration */
149 newprompt("Password: ", pass, -19);
151 else if (boolprompt("Change password", 0)) {
152 strprompt("Password", pass, -19);
155 axlevel = intprompt("Access level", axlevel, 0, 6);
156 if (boolprompt("Ask user to register again", !(flags & US_REGIS)))
160 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
161 posted = intprompt("Messages posted", posted, 0, INT_MAX);
162 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
163 userpurge = intprompt("Purge time (in days, 0 for system default",
164 userpurge, 0, INT_MAX);
166 snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
167 who, pass, flags, timescalled, posted, axlevel, usernum,
168 (long)lastcall, userpurge);
172 scr_printf("%s\n",&buf[4]);
177 int set_attr(int sval, char *prompt, unsigned int sbit)
184 scr_printf("%45s ", prompt);
187 color(BRIGHT_MAGENTA);
188 scr_printf("%3s", ((temp&sbit) ? "Yes":"No"));
192 a=yesno_d(temp&sbit);
195 if (!a) temp=(temp^sbit);
200 * modes are: 0 - .EC command, 1 - .EC for new user,
201 * 2 - toggle Xpert mode 3 - toggle floor mode
203 void enter_config(int mode)
205 int width, height, flags, filter;
208 snprintf(buf, sizeof buf, "GETU");
212 scr_printf("%s\n",&buf[4]);
216 width = extract_int(&buf[4],0);
217 height = extract_int(&buf[4],1);
218 flags = extract_int(&buf[4],2);
219 filter = extract_int(&buf[4],3);
221 if ((mode==0)||(mode==1)) {
223 width = intprompt("Enter your screen width",width,20,255);
224 height = intprompt("Enter your screen height",height,3,255);
226 flags = set_attr(flags,
227 "Are you an experienced Citadel user",US_EXPERT);
228 if ( ((flags&US_EXPERT)==0) && (mode==1))
230 flags = set_attr(flags,
231 "Print last old message on New message request",US_LASTOLD);
232 if ((flags&US_EXPERT)==0) formout("unlisted");
233 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
234 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
235 if ((flags & US_NOPROMPT)==0)
236 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
237 flags = set_attr(flags,
238 "Pause after each screenful of text",US_PAGINATOR);
239 if ( (rc_prompt_control == 3) && (flags & US_PAGINATOR) ) {
240 flags = set_attr(flags,
241 "<N>ext and <S>top work at paginator prompt", US_PROMPTCTL);
243 if (rc_floor_mode == RC_DEFAULT) {
244 flags = set_attr(flags,
245 "View rooms by floor",US_FLOORS);
247 if (rc_ansi_color == 3) {
248 flags = set_attr(flags,
249 "Enable color support",US_COLOR);
255 if (flags & US_EXPERT) {
256 flags = (flags ^ US_EXPERT);
257 scr_printf("Expert mode now OFF\n");
260 flags = (flags | US_EXPERT);
261 scr_printf("Expert mode now ON\n");
266 if (flags & US_FLOORS) {
267 flags = (flags ^ US_FLOORS);
268 scr_printf("Floor mode now OFF\n");
271 flags = (flags | US_FLOORS);
272 scr_printf("Floor mode now ON\n");
276 snprintf(buf, sizeof buf, "SETU %d|%d|%d|%d",width,height,flags,filter);
279 if (buf[0]!='2') scr_printf("%s\n",&buf[4]);
284 * getstring() - get a line of text from a file
285 * ignores lines beginning with "#"
287 int getstring(FILE *fp, char *string)
302 } while(string[0]=='#');
303 return(strlen(string));
306 int pattern(char *search, char *patn) /* Searches for patn in search string */
311 for (a=0; a<strlen(search); ++a)
312 { b=strncasecmp(&search[a],patn,strlen(patn));
318 void interr(int errnum) /* display internal error as defined in errmsgs */
320 scr_printf("*** INTERNAL ERROR %d\n"
321 "(Press any key to continue)\n", errnum);
328 void strproc(char *string)
332 if (strlen(string)==0) return;
334 /* Convert non-printable characters to blanks */
335 for (a=0; a<strlen(string); ++a) {
336 if (string[a]<32) string[a]=32;
337 if (string[a]>126) string[a]=32;
340 /* Remove leading and trailing blanks */
341 while(string[0]<33) strcpy(string,&string[1]);
342 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
344 /* Remove double blanks */
345 for (a=0; a<strlen(string); ++a) {
346 if ((string[a]==32)&&(string[a+1]==32)) {
347 strcpy(&string[a],&string[a+1]);
352 /* remove characters which would interfere with the network */
353 for (a=0; a<strlen(string); ++a) {
354 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
355 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
356 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
357 if (string[a]==',') strcpy(&string[a],&string[a+1]);
358 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
359 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
365 #ifndef HAVE_STRERROR
367 * replacement strerror() for systems that don't have it
369 char *strerror(int e)
371 static char buf[128];
373 snprintf(buf, sizeof buf, "errno = %d",e);
379 void progress(long int curr, long int cmax)
381 static long dots_printed;
385 scr_printf(".......................................");
386 scr_printf(".......................................\r");
390 else if (curr==cmax) {
391 scr_printf("\r%79s\n","");
394 a=(curr * 100) / cmax;
396 while (dots_printed < a) {
406 * NOT the same locate_host() in locate_host.c. This one just does a
407 * 'who am i' to try to discover where the user is...
409 void locate_host(char *hbuf)
416 who = (FILE *)popen("who am i","r");
418 strcpy(hbuf,serv_info.serv_fqdn);
421 fgets(buf,sizeof buf,who);
425 for (a=0; a<strlen(buf); ++a) {
426 if ((buf[a]=='(')||(buf[a]==')')) ++b;
429 strcpy(hbuf,serv_info.serv_fqdn);
433 for (a=0; a<strlen(buf); ++a) {
435 strcpy(buf,&buf[a+1]);
438 for (a=0; a<strlen(buf); ++a) {
439 if (buf[a]==')') buf[a] = 0;
442 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
443 else strncpy(hbuf,buf,24);
445 char *tty = ttyname(0);
446 #ifdef HAVE_GETUTXLINE
447 struct utmpx ut, *put;
449 struct utmp ut, *put;
454 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
458 if (strncmp(tty, "/dev/", 5))
461 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
463 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
464 if ((put = getutxline(&ut)) == NULL)
466 if ((put = getutline(&ut)) == NULL)
470 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
471 if (put->ut_type == USER_PROCESS) {
473 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
475 safestrncpy(hbuf, put->ut_host, 24);
478 safestrncpy(hbuf, put->ut_line, 24);
479 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
483 #endif /* HAVE_UTMP_H */
487 * miscellaneous server commands (testing, etc.)
489 void misc_server_cmd(char *cmd) {
494 scr_printf("%s\n",buf);
496 set_keepalives(KA_NO);
497 while (serv_gets(buf), strcmp(buf,"000")) {
498 scr_printf("%s\n",buf);
500 set_keepalives(KA_YES);
505 newprompt("> ",buf,255);
507 } while(strcmp(buf,"000"));
514 * compute the checksum of a file
516 int file_checksum(char *filename)
522 fp = fopen(filename,"r");
523 if (fp == NULL) return(0);
525 /* yes, this algorithm may allow cksum to overflow, but that's ok
526 * as long as it overflows consistently, which it will.
528 while (ch=getc(fp), ch>=0) {
529 cksum = (cksum + ch);
537 * nuke a directory and its contents
539 int nukedir(char *dirname)
545 dp = opendir(dirname);
550 while (d = readdir(dp), d != NULL) {
551 snprintf(filename, sizeof filename, "%s/%s", dirname, d->d_name);
556 return(rmdir(dirname));