19820a956090175d66801541fdce7de50bb55a79
[citadel.git] / citadel / serv_bio.c
1 /*
2  * $Id$
3  *
4  * This module implementsserver commands related to the display and
5  * manipulation of user "bio" files.
6  *
7  */
8
9 #include "sysdep.h"
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <sys/types.h>
18
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # if HAVE_SYS_TIME_H
24 #  include <sys/time.h>
25 # else
26 #  include <time.h>
27 # endif
28 #endif
29
30 #include <sys/wait.h>
31 #include <string.h>
32 #include <limits.h>
33 #include "citadel.h"
34 #include "server.h"
35 #include "sysdep_decls.h"
36 #include "citserver.h"
37 #include "support.h"
38 #include "config.h"
39 #include "control.h"
40 #include "serv_extensions.h"
41 #include "room_ops.h"
42 #include "user_ops.h"
43 #include "policy.h"
44 #include "database.h"
45 #include "msgbase.h"
46 #include "tools.h"
47 #include "citadel_dirs.h"
48
49
50
51 /*
52  * enter user bio
53  */
54 void cmd_ebio(char *cmdbuf) {
55         char buf[SIZ];
56         FILE *fp;
57
58         unbuffer_output();
59
60         if (!(CC->logged_in)) {
61                 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
62                 return;
63         }
64
65         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
66         fp = fopen(buf,"w");
67         if (fp == NULL) {
68                 cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
69                                 strerror(errno));
70                 return;
71         }
72         cprintf("%d  \n",SEND_LISTING);
73         while(client_getln(buf, sizeof buf), strcmp(buf,"000")) {
74                 if (ftell(fp) < config.c_maxmsglen) {
75                         fprintf(fp,"%s\n",buf);
76                 }
77         }
78         fclose(fp);
79 }
80
81 /*
82  * read user bio
83  */
84 void cmd_rbio(char *cmdbuf)
85 {
86         struct ctdluser ruser;
87         char buf[256];
88         FILE *fp;
89
90         extract_token(buf, cmdbuf, 0, '|', sizeof buf);
91         if (getuser(&ruser, buf) != 0) {
92                 cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
93                 return;
94         }
95         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
96         
97         cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
98                 ruser.fullname, ruser.usernum, ruser.axlevel,
99                 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
100         fp = fopen(buf,"r");
101         if (fp == NULL)
102                 cprintf("%s has no bio on file.\n", ruser.fullname);
103         else {
104                 while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
105                 fclose(fp);
106         }
107         cprintf("000\n");
108 }
109
110 /*
111  * list of users who have entered bios
112  */
113 void cmd_lbio(char *cmdbuf) {
114         char buf[256];
115         FILE *ls;
116         struct ctdluser usbuf;
117         char listbios[256];
118
119         snprintf(listbios, sizeof(listbios),"cd %s; ls",ctdl_bio_dir);
120         ls = popen(listbios, "r");
121         if (ls == NULL) {
122                 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
123                 return;
124         }
125
126         cprintf("%d\n", LISTING_FOLLOWS);
127         while (fgets(buf, sizeof buf, ls)!=NULL)
128                 if (getuserbynumber(&usbuf,atol(buf))==0)
129                         cprintf("%s\n", usbuf.fullname);
130         pclose(ls);
131         cprintf("000\n");
132 }
133
134
135
136
137 char *serv_bio_init(void)
138 {
139         CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
140         CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
141         CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
142
143         /* return our Subversion id for the Log */
144         return "$Id$";
145 }
146
147