4 * This is the "Art Vandelay" module. It is an importer/exporter.
16 #include <sys/types.h>
24 #include "sysdep_decls.h"
25 #include "citserver.h"
28 #include "dynloader.h"
36 #define END_OF_MESSAGE "---eom---dbd---"
38 char artv_tempfilename1[256];
39 char artv_tempfilename2[256];
40 FILE *artv_global_message_list;
42 void artv_export_users_backend(struct usersupp *usbuf, void *data) {
44 cprintf("%d\n", usbuf->version);
45 cprintf("%d\n", usbuf->uid);
46 cprintf("%s\n", usbuf->password);
47 cprintf("%u\n", usbuf->flags);
48 cprintf("%ld\n", usbuf->timescalled);
49 cprintf("%ld\n", usbuf->posted);
50 cprintf("%d\n", usbuf->axlevel);
51 cprintf("%ld\n", usbuf->usernum);
52 cprintf("%ld\n", usbuf->lastcall);
53 cprintf("%d\n", usbuf->USuserpurge);
54 cprintf("%s\n", usbuf->fullname);
55 cprintf("%d\n", usbuf->USscreenwidth);
56 cprintf("%d\n", usbuf->USscreenheight);
57 cprintf("%d\n", usbuf->moderation_filter);
61 void artv_export_users(void) {
62 ForEachUser(artv_export_users_backend, NULL);
66 void artv_export_room_msg(long msgnum) {
67 cprintf("%ld\n", msgnum);
68 fprintf(artv_global_message_list, "%ld\n", msgnum);
72 void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
74 cprintf("%s\n", qrbuf->QRname);
75 cprintf("%s\n", qrbuf->QRpasswd);
76 cprintf("%ld\n", qrbuf->QRroomaide);
77 cprintf("%ld\n", qrbuf->QRhighest);
78 cprintf("%ld\n", qrbuf->QRgen);
79 cprintf("%u\n", qrbuf->QRflags);
80 cprintf("%s\n", qrbuf->QRdirname);
81 cprintf("%ld\n", qrbuf->QRinfo);
82 cprintf("%d\n", qrbuf->QRfloor);
83 cprintf("%ld\n", qrbuf->QRmtime);
84 cprintf("%d\n", qrbuf->QRep.expire_mode);
85 cprintf("%d\n", qrbuf->QRep.expire_value);
86 cprintf("%ld\n", qrbuf->QRnumber);
87 cprintf("%d\n", qrbuf->QRorder);
89 getroom(&CC->quickroom, qrbuf->QRname);
90 /* format of message list export is all message numbers output
91 * one per line terminated by a 0.
93 CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, NULL,
94 artv_export_room_msg);
101 void artv_export_rooms(void) {
103 artv_global_message_list = fopen(artv_tempfilename1, "w");
104 ForEachRoom(artv_export_rooms_backend, NULL);
105 fclose(artv_global_message_list);
108 * Process the 'global' message list. (Sort it and remove dups.
109 * Dups are ok because a message may be in more than one room, but
110 * this will be handled by exporting the reference count, not by
111 * exporting the message multiple times.)
113 sprintf(cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2);
115 sprintf(cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1);
120 void artv_export_floors(void) {
124 for (i=0; i < MAXFLOORS; ++i) {
128 cprintf("%u\n", flbuf.f_flags);
129 cprintf("%s\n", flbuf.f_name);
130 cprintf("%d\n", flbuf.f_ref_count);
131 cprintf("%d\n", flbuf.f_ep.expire_mode);
132 cprintf("%d\n", flbuf.f_ep.expire_value);
141 * Traverse the room file...
143 void artv_export_visits(void) {
145 struct cdbdata *cdbv;
147 cdb_rewind(CDB_VISIT);
149 while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) {
150 memset(&vbuf, 0, sizeof(struct visit));
151 memcpy(&vbuf, cdbv->ptr,
152 ((cdbv->len > sizeof(struct visit)) ?
153 sizeof(struct visit) : cdbv->len));
157 cprintf("%ld\n", vbuf.v_roomnum);
158 cprintf("%ld\n", vbuf.v_roomgen);
159 cprintf("%ld\n", vbuf.v_usernum);
160 cprintf("%ld\n", vbuf.v_lastseen);
161 cprintf("%u\n", vbuf.v_flags);
166 void artv_export_message(long msgnum) {
167 struct SuppMsgInfo smi;
168 struct CtdlMessage *msg;
174 msg = CtdlFetchMessage(msgnum);
175 if (msg == NULL) return; /* fail silently */
177 cprintf("message\n");
178 GetSuppMsgInfo(&smi, msgnum);
179 cprintf("%ld\n", msgnum);
180 cprintf("%d\n", smi.smi_refcount);
181 cprintf("%s\n", smi.smi_content_type);
182 cprintf("%d\n", smi.smi_mod);
184 serialize_message(&smr, msg);
185 CtdlFreeMessage(msg);
187 /* write it in base64 */
188 strcpy(tempfile, tmpnam(NULL));
189 sprintf(buf, "./base64 -e >%s", tempfile);
190 fp = popen(buf, "w");
191 fwrite(smr.ser, smr.len, 1, fp);
196 fp = fopen(tempfile, "r");
198 while (fgets(buf, sizeof(buf), fp) != NULL) {
199 buf[strlen(buf)-1] = 0;
200 cprintf("%s\n", buf);
203 cprintf("%s\n", END_OF_MESSAGE);
208 void artv_export_messages(void) {
213 artv_global_message_list = fopen(artv_tempfilename1, "r");
214 lprintf(7, "Opened %s\n", artv_tempfilename1);
215 while (fgets(buf, sizeof(buf), artv_global_message_list) != NULL) {
218 artv_export_message(msgnum);
222 fclose(artv_global_message_list);
223 lprintf(7, "Exported %ld messages.\n", count);
229 void artv_do_export(void) {
230 cprintf("%d Yikes.\n", LISTING_FOLLOWS);
232 /* export the config file */
234 cprintf("%s\n", config.c_nodename);
235 cprintf("%s\n", config.c_fqdn);
236 cprintf("%s\n", config.c_humannode);
237 cprintf("%s\n", config.c_phonenum);
238 cprintf("%d\n", config.c_bbsuid);
239 cprintf("%d\n", config.c_creataide);
240 cprintf("%d\n", config.c_sleeping);
241 cprintf("%d\n", config.c_initax);
242 cprintf("%d\n", config.c_regiscall);
243 cprintf("%d\n", config.c_twitdetect);
244 cprintf("%s\n", config.c_twitroom);
245 cprintf("%s\n", config.c_moreprompt);
246 cprintf("%d\n", config.c_restrict);
247 cprintf("%ld\n", config.c_msgbase);
248 cprintf("%s\n", config.c_bbs_city);
249 cprintf("%s\n", config.c_sysadm);
250 cprintf("%s\n", config.c_bucket_dir);
251 cprintf("%d\n", config.c_setup_level);
252 cprintf("%d\n", config.c_maxsessions);
253 cprintf("%s\n", config.c_net_password);
254 cprintf("%d\n", config.c_port_number);
255 cprintf("%d\n", config.c_ipgm_secret);
256 cprintf("%d\n", config.c_ep.expire_mode);
257 cprintf("%d\n", config.c_ep.expire_value);
258 cprintf("%d\n", config.c_userpurge);
259 cprintf("%d\n", config.c_roompurge);
260 cprintf("%s\n", config.c_logpages);
261 cprintf("%d\n", config.c_createax);
262 cprintf("%ld\n", config.c_maxmsglen);
263 cprintf("%d\n", config.c_min_workers);
264 cprintf("%d\n", config.c_max_workers);
265 cprintf("%d\n", config.c_pop3_port);
266 cprintf("%d\n", config.c_smtp_port);
267 cprintf("%d\n", config.c_default_filter);
269 /* Export the control file */
271 cprintf("control\n");
272 cprintf("%ld\n", CitControl.MMhighest);
273 cprintf("%u\n", CitControl.MMflags);
274 cprintf("%ld\n", CitControl.MMnextuser);
275 cprintf("%ld\n", CitControl.MMnextroom);
276 cprintf("%d\n", CitControl.version);
280 artv_export_floors();
281 artv_export_visits();
282 artv_export_messages();
290 void artv_import_config(void) {
293 client_gets(config.c_nodename);
294 client_gets(config.c_fqdn);
295 client_gets(config.c_humannode);
296 client_gets(config.c_phonenum);
297 client_gets(buf); config.c_bbsuid = atoi(buf);
298 client_gets(buf); config.c_creataide = atoi(buf);
299 client_gets(buf); config.c_sleeping = atoi(buf);
300 client_gets(buf); config.c_initax = atoi(buf);
301 client_gets(buf); config.c_regiscall = atoi(buf);
302 client_gets(buf); config.c_twitdetect = atoi(buf);
303 client_gets(config.c_twitroom);
304 client_gets(config.c_moreprompt);
305 client_gets(buf); config.c_restrict = atoi(buf);
306 client_gets(buf); config.c_msgbase = atol(buf);
307 client_gets(config.c_bbs_city);
308 client_gets(config.c_bbs_sysadm);
309 client_gets(config.c_bucket_dir);
310 client_gets(buf); config.c_setup_level = atoi(buf);
311 client_gets(buf); config.c_maxsessions = atoi(buf);
312 client_gets(config.c_net_password);
313 client_gets(buf); config.c_port_number = atoi(buf);
314 client_gets(buf); config.c_ep.expire_mode = atoi(buf);
315 client_gets(buf); config.c_ep.expire_value = atoi(buf);
316 client_gets(buf); config.c_userpurge = atoi(buf);
317 client_gets(buf); config.c_roompurge = atoi(buf);
318 client_gets(config.c_logpages);
319 client_gets(buf); config.c_createax = atoi(buf);
320 client_gets(buf); config.c_maxmsglen = atol(buf);
321 client_gets(buf); config.c_min_workers = atoi(buf);
322 client_gets(buf); config.c_max_workers = atoi(buf);
323 client_gets(buf); config.c_pop3_port = atoi(buf);
324 client_gets(buf); config.c_smtp_port = atoi(buf);
325 client_gets(buf); config.c_default_filter = atoi(buf);
328 lprintf(7, "Imported config file\n");
333 void artv_import_control(void) {
336 client_gets(buf); CitControl.MMhighest = atol(buf);
337 client_gets(buf); CitControl.MMflags = atoi(buf);
338 client_gets(buf); CitControl.MMnextuser = atol(buf);
339 client_gets(buf); CitControl.MMnextroom = atol(buf);
340 client_gets(buf); CitControl.version = atoi(buf);
343 lprintf(7, "Imported control file\n");
350 void artv_do_import(void) {
353 cprintf("%d sock it to me\n", SEND_LISTING);
354 while (client_gets(buf), strcmp(buf, "000")) {
356 if (!strcasecmp(buf, "config")) artv_import_config();
357 else if (!strcasecmp(buf, "control")) artv_import_control();
365 void cmd_artv(char *cmdbuf) {
367 static int is_running = 0;
369 if (CtdlAccessCheck(ac_aide)) return; /* FIXME should be intpgm */
371 cprintf("%d The importer/exporter is already running.\n",
377 strcpy(artv_tempfilename1, tmpnam(NULL));
378 strcpy(artv_tempfilename2, tmpnam(NULL));
380 extract(cmd, cmdbuf, 0);
381 if (!strcasecmp(cmd, "export")) artv_do_export();
382 else if (!strcasecmp(cmd, "import")) artv_do_import();
383 else cprintf("%d illegal command\n", ERROR);
385 unlink(artv_tempfilename1);
386 unlink(artv_tempfilename2);
394 char *Dynamic_Module_Init(void)
396 CtdlRegisterProtoHook(cmd_artv, "ARTV", "import/export data store");