18bf3b920db98fed23477d640eb58b89036d593d
[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 #include <sys/time.h>
19 #include <sys/wait.h>
20 #include <string.h>
21 #include <limits.h>
22 #include "citadel.h"
23 #include "server.h"
24 #include <time.h>
25 #include "sysdep_decls.h"
26 #include "citserver.h"
27 #include "support.h"
28 #include "config.h"
29 #include "control.h"
30 #include "dynloader.h"
31 #include "room_ops.h"
32 #include "user_ops.h"
33 #include "policy.h"
34 #include "database.h"
35 #include "msgbase.h"
36 #include "tools.h"
37
38
39
40
41 /*
42  * enter user bio
43  */
44 void cmd_ebio(char *cmdbuf) {
45         char buf[SIZ];
46         FILE *fp;
47
48         if (!(CC->logged_in)) {
49                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
50                 return;
51         }
52
53         sprintf(buf,"./bio/%ld",CC->usersupp.usernum);
54         fp = fopen(buf,"w");
55         if (fp == NULL) {
56                 cprintf("%d Cannot create file\n",ERROR);
57                 return;
58         }
59         cprintf("%d  \n",SEND_LISTING);
60         while(client_gets(buf), strcmp(buf,"000")) {
61                 fprintf(fp,"%s\n",buf);
62         }
63         fclose(fp);
64 }
65
66 /*
67  * read user bio
68  */
69 void cmd_rbio(char *cmdbuf)
70 {
71         struct usersupp ruser;
72         char buf[SIZ];
73         FILE *fp;
74
75         extract(buf,cmdbuf,0);
76         if (getuser(&ruser,buf)!=0) {
77                 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
78                 return;
79         }
80         sprintf(buf,"./bio/%ld",ruser.usernum);
81         
82         cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
83                 ruser.fullname, ruser.usernum, ruser.axlevel,
84                 ruser.lastcall, ruser.timescalled, ruser.posted);
85         fp = fopen(buf,"r");
86         if (fp == NULL)
87                 cprintf("%s has no bio on file.\n", ruser.fullname);
88         else {
89                 while (fgets(buf,256,fp)!=NULL) cprintf("%s",buf);
90                 fclose(fp);
91         }
92         cprintf("000\n");
93 }
94
95 /*
96  * list of users who have entered bios
97  */
98 void cmd_lbio(char *cmdbuf) {
99         char buf[SIZ];
100         FILE *ls;
101         struct usersupp usbuf;
102
103         ls=popen("cd ./bio; ls","r");
104         if (ls==NULL) {
105                 cprintf("%d Cannot open listing.\n",ERROR+FILE_NOT_FOUND);
106                 return;
107         }
108
109         cprintf("%d\n",LISTING_FOLLOWS);
110         while (fgets(buf,sizeof buf,ls)!=NULL)
111                 if (getuserbynumber(&usbuf,atol(buf))==0)
112                         cprintf("%s\n",usbuf.fullname);
113         pclose(ls);
114         cprintf("000\n");
115 }
116
117
118
119
120 char *Dynamic_Module_Init(void)
121 {
122         CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
123         CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
124         CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
125         return "$Id$";
126 }
127
128