1 /* Citadel/UX support routines */
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
27 void sttybbs(int cmd);
28 void newprompt(char *prompt, char *str, int len);
29 void val_user(char *user);
30 void formout(char *name);
31 void logoff(int code);
32 void set_keepalives(int s);
33 void strprompt(char *prompt, char *str, int len);
34 void newprompt(char *prompt, char *str, int len);
35 void color(int colornum);
37 #define IFAIDE if(axlevel>=6)
38 #define IFNAIDE if (axlevel<6)
40 extern unsigned userflags;
41 extern char *axdefs[7];
42 extern char sigcaught;
43 extern struct CtdlServInfo serv_info;
44 extern char rc_floor_mode;
45 extern int rc_ansi_color;
47 int struncmp(char *lstr, char *rstr, int len)
52 lc=tolower(lstr[pos]);
53 rc=tolower(rstr[pos]);
54 if ((lc==0)&&(rc==0)) return(0);
55 if (lc<rc) return(-1);
64 * check for the presence of a character within a string (returns count)
66 int haschar(char *st, int ch)
70 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
75 void back(int spaces) /* Destructive backspace */
78 for (a=1; a<=spaces; ++a) {
79 putc(8,stdout); putc(32,stdout); putc(8,stdout);
83 void hit_any_key(void) { /* hit any key to continue */
86 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); /* Display registration, and set access level */
132 strprompt("Password", pass, 19);
133 timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
134 posted = intprompt("Messages posted", posted, 0, INT_MAX);
135 lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
136 userpurge = intprompt("Purge time (in days, 0 for system default",
137 userpurge, 0, INT_MAX);
139 sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
140 who, pass, flags, timescalled, posted, axlevel, usernum,
141 lastcall, userpurge);
145 printf("%s\n",&buf[4]);
150 int set_attr(int sval, char *prompt, unsigned int sbit)
157 printf("%45s [", prompt);
159 printf("%3s", ((temp&sbit) ? "Yes":"No"));
163 a=yesno_d(temp&sbit);
166 if (!a) temp=(temp^sbit);
171 * modes are: 0 - .EC command, 1 - .EC for new user,
172 * 2 - toggle Xpert mode 3 - toggle floor mode
174 void enter_config(int mode)
176 int width,height,flags;
183 printf("%s\n",&buf[4]);
187 width = extract_int(&buf[4],0);
188 height = extract_int(&buf[4],1);
189 flags = extract_int(&buf[4],2);
191 if ((mode==0)||(mode==1)) {
193 width = intprompt("Enter your screen width",width,20,255);
194 height = intprompt("Enter your screen height",height,3,255);
196 flags = set_attr(flags,
197 "Are you an experienced Citadel user",US_EXPERT);
198 if ( ((flags&US_EXPERT)==0) && (mode==1))
200 flags = set_attr(flags,
201 "Print last old message on New message request",US_LASTOLD);
202 if ((flags&US_EXPERT)==0) formout("unlisted");
203 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
204 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
205 if ((flags & US_NOPROMPT)==0)
206 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
207 flags = set_attr(flags,
208 "Pause after each screenful of text",US_PAGINATOR);
209 if (rc_floor_mode == RC_DEFAULT) {
210 flags = set_attr(flags,
211 "View rooms by floor",US_FLOORS);
213 if (rc_ansi_color == 3) {
214 flags = set_attr(flags,
215 "Enable color support",US_COLOR);
220 if (flags & US_EXPERT) {
221 flags = (flags ^ US_EXPERT);
222 printf("Expert mode now OFF\n");
225 flags = (flags | US_EXPERT);
226 printf("Expert mode now ON\n");
231 if (flags & US_FLOORS) {
232 flags = (flags ^ US_FLOORS);
233 printf("Floor mode now OFF\n");
236 flags = (flags | US_FLOORS);
237 printf("Floor mode now ON\n");
241 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
244 if (buf[0]!='2') printf("%s\n",&buf[4]);
249 * getstring() - get a line of text from a file
250 * ignores lines beginning with "#"
252 int getstring(FILE *fp, char *string)
267 } while(string[0]=='#');
268 return(strlen(string));
271 int pattern(char *search, char *patn) /* Searches for patn in search string */
276 for (a=0; a<strlen(search); ++a)
277 { b=struncmp(&search[a],patn,strlen(patn));
283 void interr(int errnum) /* display internal error as defined in errmsgs */
285 printf("*** INTERNAL ERROR %d\n",errnum);
286 printf("(Press any key to continue)\n");
294 * Check to see if we need to pause at the end of a screen.
295 * If we do, we have to disable server keepalives during the pause because
296 * we are probably in the middle of a server operation and the NOOP command
297 * would confuse everything.
299 int checkpagin(int lp, int pagin, int height)
301 if (pagin!=1) return(0);
302 if (lp>=(height-1)) {
303 set_keepalives(KA_NO);
305 set_keepalives(KA_YES);
312 void strproc(char *string)
316 if (strlen(string)==0) return;
318 /* Convert non-printable characters to blanks */
319 for (a=0; a<strlen(string); ++a) {
320 if (string[a]<32) string[a]=32;
321 if (string[a]>126) string[a]=32;
324 /* Remove leading and trailing blanks */
325 while(string[0]<33) strcpy(string,&string[1]);
326 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
328 /* Remove double blanks */
329 for (a=0; a<strlen(string); ++a) {
330 if ((string[a]==32)&&(string[a+1]==32)) {
331 strcpy(&string[a],&string[a+1]);
336 /* remove characters which would interfere with the network */
337 for (a=0; a<strlen(string); ++a) {
338 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
339 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
340 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
341 if (string[a]==',') strcpy(&string[a],&string[a+1]);
342 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
343 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
349 #ifndef HAVE_STRERROR
351 * replacement strerror() for systems that don't have it
353 char *strerror(int e)
357 sprintf(buf,"errno = %d",e);
363 void progress(long int curr, long int cmax)
365 static long dots_printed;
369 printf(".......................................");
370 printf(".......................................\r");
374 else if (curr==cmax) {
375 printf("\r%79s\n","");
378 a=(curr * 100) / cmax;
380 while (dots_printed < a) {
390 * NOT the same locate_host() in locate_host.c. This one just does a
391 * 'who am i' to try to discover where the user is...
393 void locate_host(char *hbuf)
399 who = (FILE *)popen("who am i","r");
401 strcpy(hbuf,serv_info.serv_fqdn);
408 for (a=0; a<strlen(buf); ++a) {
409 if ((buf[a]=='(')||(buf[a]==')')) ++b;
412 strcpy(hbuf,serv_info.serv_fqdn);
416 for (a=0; a<strlen(buf); ++a) {
418 strcpy(buf,&buf[a+1]);
421 for (a=0; a<strlen(buf); ++a) {
422 if (buf[a]==')') buf[a] = 0;
425 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
426 else strncpy(hbuf,buf,24);
430 * miscellaneous server commands (testing, etc.)
432 void misc_server_cmd(char *cmd) {
439 while (serv_gets(buf), strcmp(buf,"000")) {
446 newprompt("> ",buf,255);
448 } while(strcmp(buf,"000"));
455 * compute the checksum of a file
457 int file_checksum(char *filename)
463 fp = fopen(filename,"r");
464 if (fp == NULL) return(0);
466 /* yes, this algorithm may allow cksum to overflow, but that's ok
467 * as long as it overflows consistently, which it will.
469 while (ch=getc(fp), ch>=0) {
470 cksum = (cksum + ch);
478 * nuke a directory and its contents
480 int nukedir(char *dirname)
486 dp = opendir(dirname);
491 while (d = readdir(dp), d != NULL) {
492 sprintf(filename, "%s/%s", dirname, d->d_name);
497 return(rmdir(dirname));