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 /* Destructive backspace */
68 void back(int spaces) {
70 for (a=0; a<spaces; ++a) {
77 void hit_any_key(void) { /* hit any key to continue */
82 scr_printf("%s\r",serv_info.serv_moreprompt);
86 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
90 if ( (rc_prompt_control == 1)
91 || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
92 if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
94 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
118 newprompt("User name: ",who,25);
119 AGUP: snprintf(buf, sizeof buf, "AGUP %s",who);
123 scr_printf("%s\n",&buf[4]);
124 scr_printf("Do you want to create this user? ");
126 snprintf(buf, sizeof buf, "CREU %s", who);
133 scr_printf("%s\n",&buf[4]);
138 extract(who, &buf[4], 0);
139 extract(pass, &buf[4], 1);
140 flags = extract_int(&buf[4], 2);
141 timescalled = extract_int(&buf[4], 3);
142 posted = extract_int(&buf[4], 4);
143 axlevel = extract_int(&buf[4], 5);
144 usernum = extract_long(&buf[4], 6);
145 lastcall = extract_long(&buf[4], 7);
146 userpurge = extract_int(&buf[4], 8);
148 val_user(who, 0); /* Display registration */
151 newprompt("Password: ", pass, -19);
153 else if (boolprompt("Change password", 0)) {
154 strprompt("Password", pass, -19);
157 axlevel = intprompt("Access level", axlevel, 0, 6);
158 if (boolprompt("Ask user to register again", !(flags & US_REGIS)))
162 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
163 posted = intprompt("Messages posted", posted, 0, INT_MAX);
164 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
165 userpurge = intprompt("Purge time (in days, 0 for system default",
166 userpurge, 0, INT_MAX);
168 snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
169 who, pass, flags, timescalled, posted, axlevel, usernum,
170 (long)lastcall, userpurge);
174 scr_printf("%s\n",&buf[4]);
179 int set_attr(int sval, char *prompt, unsigned int sbit)
186 scr_printf("%45s ", prompt);
189 color(BRIGHT_MAGENTA);
190 scr_printf("%3s", ((temp&sbit) ? "Yes":"No"));
194 a=yesno_d(temp&sbit);
197 if (!a) temp=(temp^sbit);
202 * modes are: 0 - .EC command, 1 - .EC for new user,
203 * 2 - toggle Xpert mode 3 - toggle floor mode
205 void enter_config(int mode)
207 int width, height, flags, filter;
210 snprintf(buf, sizeof buf, "GETU");
214 scr_printf("%s\n",&buf[4]);
218 width = extract_int(&buf[4],0);
219 height = extract_int(&buf[4],1);
220 flags = extract_int(&buf[4],2);
221 filter = extract_int(&buf[4],3);
223 if ((mode==0)||(mode==1)) {
225 width = intprompt("Enter your screen width",width,20,255);
226 height = intprompt("Enter your screen height",height,3,255);
228 flags = set_attr(flags,
229 "Are you an experienced Citadel user",US_EXPERT);
230 if ( ((flags&US_EXPERT)==0) && (mode==1))
232 flags = set_attr(flags,
233 "Print last old message on New message request",US_LASTOLD);
234 if ((flags&US_EXPERT)==0) formout("unlisted");
235 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
236 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
237 if ((flags & US_NOPROMPT)==0)
238 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
239 flags = set_attr(flags,
240 "Pause after each screenful of text",US_PAGINATOR);
241 if ( (rc_prompt_control == 3) && (flags & US_PAGINATOR) ) {
242 flags = set_attr(flags,
243 "<N>ext and <S>top work at paginator prompt", US_PROMPTCTL);
245 if (rc_floor_mode == RC_DEFAULT) {
246 flags = set_attr(flags,
247 "View rooms by floor",US_FLOORS);
249 if (rc_ansi_color == 3) {
250 flags = set_attr(flags,
251 "Enable color support",US_COLOR);
257 if (flags & US_EXPERT) {
258 flags = (flags ^ US_EXPERT);
259 scr_printf("Expert mode now OFF\n");
262 flags = (flags | US_EXPERT);
263 scr_printf("Expert mode now ON\n");
268 if (flags & US_FLOORS) {
269 flags = (flags ^ US_FLOORS);
270 scr_printf("Floor mode now OFF\n");
273 flags = (flags | US_FLOORS);
274 scr_printf("Floor mode now ON\n");
278 snprintf(buf, sizeof buf, "SETU %d|%d|%d|%d",width,height,flags,filter);
281 if (buf[0]!='2') scr_printf("%s\n",&buf[4]);
286 * getstring() - get a line of text from a file
287 * ignores lines beginning with "#"
289 int getstring(FILE *fp, char *string)
304 } while(string[0]=='#');
305 return(strlen(string));
309 /* Searches for patn in search string */
310 int pattern(char *search, char *patn) {
313 for (a=0; a<strlen(search); ++a) {
314 b=strncasecmp(&search[a],patn,strlen(patn));
321 /* display internal error as defined in errmsgs */
322 void interr(int errnum) {
323 scr_printf("*** INTERNAL ERROR %d\n"
324 "(Press any key to continue)\n", errnum);
329 void strproc(char *string)
333 if (strlen(string)==0) return;
335 /* Convert non-printable characters to blanks */
336 for (a=0; a<strlen(string); ++a) {
337 if (string[a]<32) string[a]=32;
338 if (string[a]>126) string[a]=32;
341 /* Remove leading and trailing blanks */
342 while(string[0]<33) strcpy(string,&string[1]);
343 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
345 /* Remove double blanks */
346 for (a=0; a<strlen(string); ++a) {
347 if ((string[a]==32)&&(string[a+1]==32)) {
348 strcpy(&string[a],&string[a+1]);
353 /* remove characters which would interfere with the network */
354 for (a=0; a<strlen(string); ++a) {
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]);
360 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
366 #ifndef HAVE_STRERROR
368 * replacement strerror() for systems that don't have it
370 char *strerror(int e)
372 static char buf[128];
374 snprintf(buf, sizeof buf, "errno = %d",e);
380 void progress(long int curr, long int cmax)
382 static long dots_printed;
386 scr_printf(".......................................");
387 scr_printf(".......................................\r");
391 else if (curr==cmax) {
392 scr_printf("\r%79s\n","");
395 a=(curr * 100) / cmax;
397 while (dots_printed < a) {
407 * NOT the same locate_host() in locate_host.c. This one just does a
408 * 'who am i' to try to discover where the user is...
410 void locate_host(char *hbuf)
417 who = (FILE *)popen("who am i","r");
419 strcpy(hbuf,serv_info.serv_fqdn);
422 fgets(buf,sizeof buf,who);
426 for (a=0; a<strlen(buf); ++a) {
427 if ((buf[a]=='(')||(buf[a]==')')) ++b;
430 strcpy(hbuf,serv_info.serv_fqdn);
434 for (a=0; a<strlen(buf); ++a) {
436 strcpy(buf,&buf[a+1]);
439 for (a=0; a<strlen(buf); ++a) {
440 if (buf[a]==')') buf[a] = 0;
443 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
444 else strncpy(hbuf,buf,24);
446 char *tty = ttyname(0);
447 #ifdef HAVE_GETUTXLINE
448 struct utmpx ut, *put;
450 struct utmp ut, *put;
455 safestrncpy(hbuf, serv_info.serv_fqdn, 24);
459 if (strncmp(tty, "/dev/", 5))
462 safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
464 #ifdef HAVE_GETUTXLINE /* Solaris uses this */
465 if ((put = getutxline(&ut)) == NULL)
467 if ((put = getutline(&ut)) == NULL)
471 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
472 if (put->ut_type == USER_PROCESS) {
474 #if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
476 safestrncpy(hbuf, put->ut_host, 24);
479 safestrncpy(hbuf, put->ut_line, 24);
480 #if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
484 #endif /* HAVE_UTMP_H */
488 * miscellaneous server commands (testing, etc.)
490 void misc_server_cmd(char *cmd) {
495 scr_printf("%s\n",buf);
497 set_keepalives(KA_HALF);
498 while (serv_gets(buf), strcmp(buf,"000")) {
499 scr_printf("%s\n",buf);
501 set_keepalives(KA_YES);
506 newprompt("> ",buf,255);
508 } while(strcmp(buf,"000"));
515 * compute the checksum of a file
517 int file_checksum(char *filename)
523 fp = fopen(filename,"r");
524 if (fp == NULL) return(0);
526 /* yes, this algorithm may allow cksum to overflow, but that's ok
527 * as long as it overflows consistently, which it will.
529 while (ch=getc(fp), ch>=0) {
530 cksum = (cksum + ch);
538 * nuke a directory and its contents
540 int nukedir(char *dirname)
546 dp = opendir(dirname);
551 while (d = readdir(dp), d != NULL) {
552 snprintf(filename, sizeof filename, "%s/%s",
558 return(rmdir(dirname));