c5a5af0803a1cc98a7284aec3f0b64084f5a224f
[citadel.git] / citadel / serv_upgrade.c
1 /*
2  * This module imports an "unpacked" system.  The unpacked data may come from
3  * an older version of Citadel, or a different hardware architecture, or
4  * whatever.  You should only run an import when your installed system is
5  * brand new and _empty_ !!
6  *
7  * $Id$
8  */
9
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 <pthread.h>
23 #include "citadel.h"
24 #include "server.h"
25 #include <syslog.h>
26 #include "sysdep_decls.h"
27 #include "citserver.h"
28 #include "support.h"
29 #include "config.h"
30 #include "dynloader.h"
31 #include "room_ops.h"
32 #include "user_ops.h"
33 #include "database.h"
34 #include "control.h"
35
36 extern struct CitContext *ContextList;
37 FILE *imfp, *exfp;
38
39 #define MODULE_NAME     "Import an unpacked system"
40 #define MODULE_AUTHOR   "Art Cancro"
41 #define MODULE_EMAIL    "ajc@uncnsrd.mt-kisco.ny.us"
42 #define MAJOR_VERSION   0
43 #define MINOR_VERSION   3
44
45 static struct DLModule_Info info = {
46         MODULE_NAME,
47         MODULE_AUTHOR,
48         MODULE_EMAIL,
49         MAJOR_VERSION,
50         MINOR_VERSION
51         };
52
53
54
55 void fpgetfield(FILE *fp, char *string)
56 {
57         int a,b;
58         strcpy(string,"");
59         a=0;
60         do {
61                 b=getc(fp);
62                 if (b<1) {
63                         string[a]=0;
64                         return;
65                         }
66                 string[a]=b;
67                 ++a;
68                 } while (b!=0);
69         }
70
71
72 void import_message(long msgnum, long msglen) {
73         char *msgtext;
74
75         msgtext = malloc(msglen);
76         if (msgtext == NULL) {
77                 lprintf(3, "ERROR: cannot allocate memory\n");
78                 lprintf(3, "Your data files are now corrupt.\n");
79                 fclose(imfp);
80                 exit(1);
81                 }
82
83         fread(msgtext, msglen, 1, imfp);
84         cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
85         free(msgtext);
86         }
87
88 void imp_floors(void) {
89         char key[256], tag[256], tval[256];
90         struct floor fl;
91         int floornum = 0;
92
93
94         while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
95
96                 if (!strcasecmp(key, "floor")) {
97                         bzero(&fl, sizeof(struct floor));
98
99                         while(fpgetfield(imfp, tag),
100                              strcasecmp(tag, "endfloor")) {
101                                 fpgetfield(imfp, tval);
102
103                                 if (!strcasecmp(tag, "f_flags")) 
104                                         fl.f_flags = atoi(tval);
105                                 if (!strcasecmp(tag, "f_name")) {
106                                         lprintf(9, "Floor <%s>\n", tval);
107                                         strcpy(fl.f_name, tval);        
108                                         }
109                                 if (!strcasecmp(tag, "f_ref_count")) 
110                                         fl.f_ref_count = atoi(tval);
111                                 if (!strcasecmp(tag, "f_expire_mode")) 
112                                         fl.f_ep.expire_mode = atoi(tval);
113                                 if (!strcasecmp(tag, "f_expire_value")) 
114                                         fl.f_ep.expire_value = atoi(tval);
115                                 }
116
117                         putfloor(&fl, floornum);
118                         ++floornum;
119                         }
120                 else {
121                         lprintf(3, "ERROR: invalid floor section.\n");
122                         lprintf(3, "Your data files are now corrupt.\n");
123                         fclose(imfp);
124                         return;
125                         }
126                 }
127         }
128
129
130
131 void imp_rooms(void) {
132         char key[256];
133         char tag[256], tval[256];
134         int roomnum = 0;
135         struct quickroom qr;
136         long *msglist;
137         int num_msgs = 0;
138         long msgnum, msglen;
139         
140         while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
141                 if (!strcasecmp(key, "room")) {
142                         bzero(&qr, sizeof(struct quickroom));
143                         msglist = NULL;
144                         num_msgs = 0;
145                         lprintf(9, "Room ");
146
147                         while(fpgetfield(imfp, tag),
148                              strcasecmp(tag, "endroom")) {
149                                 if (strcasecmp(tag, "message")) {
150                                         fpgetfield(imfp, tval);
151                                         }
152                                 else {
153                                         strcpy(tval, "");
154                                         }
155
156                                 if (!strcasecmp(tag, "qrname")) {
157                                         strcpy(qr.QRname, tval);
158                                         lprintf(9, "<%s> ", qr.QRname);
159                                         }
160                                 if (!strcasecmp(tag, "qrpasswd"))
161                                         strcpy(qr.QRpasswd, tval);
162                                 if (!strcasecmp(tag, "qrroomaide"))
163                                         qr.QRroomaide = atol(tval);
164                                 if (!strcasecmp(tag, "qrhighest"))
165                                         qr.QRhighest = atol(tval);
166                                 if (!strcasecmp(tag, "qrgen"))
167                                         qr.QRgen = atol(tval);
168                                 if (!strcasecmp(tag, "qrflags"))
169                                         qr.QRflags = atoi(tval);
170                                 if (!strcasecmp(tag, "qrdirname"))
171                                         strcpy(qr.QRdirname, tval);
172                                 if (!strcasecmp(tag, "qrinfo"))
173                                         qr.QRinfo = atol(tval);
174                                 if (!strcasecmp(tag, "qrfloor"))
175                                         qr.QRfloor = atoi(tval);
176                                 if (!strcasecmp(tag, "qrmtime"))
177                                         qr.QRmtime = atol(tval);
178                                 if (!strcasecmp(tag, "qrepmode"))
179                                         qr.QRep.expire_mode = atoi(tval);
180                                 if (!strcasecmp(tag, "qrepvalue"))
181                                         qr.QRep.expire_value = atoi(tval);
182                                 if (!strcasecmp(tag, "message")) {
183                                         fpgetfield(imfp, tval);
184                                         msgnum = atol(tval);
185                                         fpgetfield(imfp, tval);
186                                         msglen = atol(tval);
187                                         import_message(msgnum, msglen);
188                                         ++num_msgs;
189                                         msglist = realloc(msglist,
190                                                 (sizeof(long)*num_msgs) );
191                                         msglist[num_msgs - 1] = msgnum;
192                                         }
193
194                                 }
195
196                         lprintf(9, "(%d messages)\n", num_msgs);
197                         if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
198                                 putroom(&qr, qr.QRname);
199                                 }
200
201                         if (num_msgs > 0) {
202                                 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
203                                         CC->msglist = msglist;
204                                         CC->num_msgs = num_msgs;
205                                         put_msglist(&qr);
206                                         }
207                                 free(msglist);
208                                 }
209
210                         ++roomnum;
211
212                         }
213                 else {
214                         lprintf(3, "ERROR: invalid room section.\n");
215                         lprintf(3, "Your data files are now corrupt.\n");
216                         fclose(imfp);
217                         return;
218                         }
219                 }
220         }
221
222
223
224 void import_a_user(void) {
225         char key[256], value[256];
226         char vkey[256], vvalue[256];
227         struct usersupp us;
228         struct quickroom qr;
229         struct visit vbuf;
230         int visits = 0;
231
232         bzero(&us, sizeof(struct usersupp));    
233         while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
234                 if ((strcasecmp(key, "mail"))
235                    &&(strcasecmp(key, "visit")) ) {
236                         fpgetfield(imfp, value);
237                         }
238                 else {
239                         strcpy(value, "");
240                         }
241
242                 if (!strcasecmp(key, "usuid"))
243                         us.USuid = atoi(value);
244                 if (!strcasecmp(key, "password")) {
245                         strcpy(us.password, value);
246                         }
247
248                 if (!strcasecmp(key, "flags"))
249                         us.flags = atoi(value);
250                 if (!strcasecmp(key, "timescalled"))
251                         us.timescalled = atoi(value);
252                 if (!strcasecmp(key, "posted"))
253                         us.posted = atoi(value);
254                 if (!strcasecmp(key, "fullname")) {
255                         strcpy(us.fullname, value);
256                         lprintf(9, "User <%s> ", us.fullname);
257                         }
258                 if (!strcasecmp(key, "axlevel"))
259                         us.axlevel = atoi(value);
260                 if (!strcasecmp(key, "usscreenwidth"))
261                         us.USscreenwidth = atoi(value);
262                 if (!strcasecmp(key, "usscreenheight"))
263                         us.USscreenheight = atoi(value);
264                 if (!strcasecmp(key, "usernum")) {
265                         us.usernum = atol(value);
266                         lprintf(9, "<#%ld> ", us.usernum);
267                         }
268                 if (!strcasecmp(key, "lastcall"))
269                         us.lastcall = atol(value);
270                 if (!strcasecmp(key, "usname"))
271                         strcpy(us.USname, value);
272                 if (!strcasecmp(key, "usaddr"))
273                         strcpy(us.USaddr, value);
274                 if (!strcasecmp(key, "uscity"))
275                         strcpy(us.UScity, value);
276                 if (!strcasecmp(key, "usstate"))
277                         strcpy(us.USstate, value);
278                 if (!strcasecmp(key, "uszip"))
279                         strcpy(us.USzip, value);
280                 if (!strcasecmp(key, "usphone"))
281                         strcpy(us.USphone, value);
282                 if (!strcasecmp(key, "usemail"))
283                         strcpy(us.USemail, value);
284                 if (!strcasecmp(key, "ususerpurge"))
285                         us.USuserpurge = atoi(value);
286                 if (!strcasecmp(key, "visit")) {
287                         ++visits;
288                         bzero(&vbuf, sizeof(struct visit));
289                         bzero(&qr, sizeof(struct quickroom));
290                         while(fpgetfield(imfp, vkey),
291                           strcasecmp(vkey, "endvisit")) {
292                                 fpgetfield(imfp, vvalue);
293                                 if (!strcasecmp(vkey, "vname")) 
294                                         strcpy(qr.QRname, vvalue);
295                                 if (!strcasecmp(vkey, "vgen"))  {
296                                         qr.QRgen = atol(vvalue);
297                                         CtdlGetRelationship(&vbuf, &us, &qr);
298                                         }
299                                 if (!strcasecmp(vkey, "lastseen"))      
300                                         vbuf.v_lastseen = atol(vvalue);
301                                 if (!strcasecmp(vkey, "flags"))
302                                         vbuf.v_flags = atoi(vvalue);
303                                 }
304                         CtdlSetRelationship(&vbuf, &us, &qr);
305                         }
306                 }
307         
308         putuser(&us, us.fullname);
309
310         lprintf(9, "(%d rooms)\n", visits);
311         }
312
313
314 void imp_usersupp(void) {
315         char key[256], value[256];
316         
317         while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
318                 if (strcasecmp(key, "user")) {
319                         fpgetfield(imfp, value);
320                         }
321                 else {
322                         strcpy(value, "");
323                         }
324
325                 if (!strcasecmp(key, "user")) {
326                         import_a_user();
327                         }
328                 }               
329         }
330
331
332 void imp_globals(void) {
333         char key[256], value[256];
334
335         get_control();
336         while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
337                 fpgetfield(imfp, value);
338                 lprintf(9, " %s = %s\n", key, value);
339
340                 if (!strcasecmp(key, "mmhighest"))
341                         CitControl.MMhighest = atol(value);
342                 if (!strcasecmp(key, "mmnextuser"))
343                         CitControl.MMnextuser = atol(value);
344
345                 }
346         put_control();
347         }
348
349
350
351 void imp_config(void) { 
352         char key[256], value[256];
353         FILE *fp;
354
355         while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
356                 fpgetfield(imfp, value);
357                 lprintf(9, " %s = %s\n", key, value);
358
359                 if (!strcasecmp(key, "c_nodename"))
360                         strcpy(config.c_nodename, value);
361                 if (!strcasecmp(key, "c_fqdn"))
362                         strcpy(config.c_fqdn, value);
363                 if (!strcasecmp(key, "c_humannode"))
364                         strcpy(config.c_humannode, value);
365                 if (!strcasecmp(key, "c_phonenum"))
366                         strcpy(config.c_phonenum, value);
367                 if (!strcasecmp(key, "c_phonenum"))
368                         strcpy(config.c_phonenum, value);
369                 if (!strcasecmp(key, "c_bbsuid"))
370                         config.c_bbsuid = atoi(value);
371                 if (!strcasecmp(key, "c_creataide"))
372                         config.c_creataide = atoi(value);
373                 if (!strcasecmp(key, "c_sleeping"))
374                         config.c_sleeping = atoi(value);
375                 if (!strcasecmp(key, "c_initax"))
376                         config.c_initax = atoi(value);
377                 if (!strcasecmp(key, "c_regiscall"))
378                         config.c_regiscall = atoi(value);
379                 if (!strcasecmp(key, "c_twitdetect"))
380                         config.c_twitdetect = atoi(value);
381                 if (!strcasecmp(key, "c_twitroom"))
382                         strcpy(config.c_twitroom, value);
383                 if (!strcasecmp(key, "c_moreprompt"))
384                         strcpy(config.c_moreprompt, value);
385                 if (!strcasecmp(key, "c_restrict"))
386                         config.c_restrict = atoi(value);
387                 if (!strcasecmp(key, "c_bbs_city"))
388                         strcpy(config.c_bbs_city, value);
389                 if (!strcasecmp(key, "c_sysadm"))
390                         strcpy(config.c_sysadm, value);
391                 if (!strcasecmp(key, "c_bucket_dir"))
392                         strcpy(config.c_bucket_dir, value);
393                 if (!strcasecmp(key, "c_setup_level"))
394                         config.c_setup_level = atoi(value);
395                 if (!strcasecmp(key, "c_maxsessions"))
396                         config.c_maxsessions = atoi(value);
397                 if (!strcasecmp(key, "c_net_password"))
398                         strcpy(config.c_net_password, value);
399                 if (!strcasecmp(key, "c_port_number"))
400                         config.c_port_number = atoi(value);
401                 if (!strcasecmp(key, "c_expire_policy"))
402                         config.c_ep.expire_mode = atoi(value);
403                 if (!strcasecmp(key, "c_expire_value"))
404                         config.c_ep.expire_value = atoi(value);
405                 if (!strcasecmp(key, "c_userpurge"))
406                         config.c_userpurge = atoi(value);
407                 }
408
409         fp = fopen("citadel.config", "wb");
410         fwrite(&config, sizeof(struct config), 1, fp);
411         fclose(fp);
412         }
413                 
414                 
415
416
417
418 void imp_ssv(void) {
419         char key[256], value[256];
420         int ssv_maxfloors = MAXFLOORS;
421         
422         while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
423                 fpgetfield(imfp, value);
424                 lprintf(9, " %s = %s\n", key, value);
425                 
426                 if (!strcasecmp(key, "maxfloors")) {
427                         ssv_maxfloors = atol(value);
428                         if (ssv_maxfloors > MAXFLOORS) {
429                                 lprintf(3, "ERROR: maxfloors is %d, need %d\n",
430                                         ssv_maxfloors, MAXFLOORS);
431                                 fclose(imfp);
432                                 return;
433                                 }
434                         }
435                 }
436         }
437
438
439
440
441
442
443
444 void import_databases(void) {
445         char section[256];
446
447         lprintf(9, " ** IMPORTING ** \n");
448         while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
449                 lprintf(9, "Section: <%s>\n", section);
450
451                 if (!strcasecmp(section, "ssv"))                imp_ssv();
452                 else if (!strcasecmp(section, "config"))        imp_config();
453                 else if (!strcasecmp(section, "globals"))       imp_globals();
454                 else if (!strcasecmp(section, "usersupp"))      imp_usersupp();
455                 else if (!strcasecmp(section, "rooms"))         imp_rooms();
456                 else if (!strcasecmp(section, "floors"))        imp_floors();
457                 else {
458                         lprintf(3, "ERROR: invalid import section.\n");
459                         lprintf(3, "Your data files are now corrupt.\n");
460                         fclose(imfp);
461                         return;
462                         }
463
464                 }
465
466         }
467
468
469
470 void do_import(char *argbuf) {
471         char import_filename[PATH_MAX];
472         
473         extract(import_filename, argbuf, 0);
474         imfp = fopen(import_filename, "rb");
475         if (imfp == NULL) {
476                 lprintf(9, "Cannot open %s: %s\n",
477                         import_filename, strerror(errno));
478                 cprintf("%d Cannot open file\n", ERROR);
479                 return;
480                 }
481
482         import_databases();
483         lprintf(9, "Defragmenting databases (this may take a while)...\n");
484         defrag_databases();
485         lprintf(1, "Import is finished.  Shutting down Citadel...\n");
486         cprintf("%d Import finished.  Shutting down Citadel...\n", OK);
487         master_cleanup();
488         }
489
490
491 void dump_message(long msg_num) {
492         struct cdbdata *dmsgtext;
493
494         dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
495         
496         if (dmsgtext == NULL) {
497                 lprintf(9, "%d Can't find message %ld\n", msg_num);
498                 return;
499                 }
500
501         fprintf(exfp, "message%c%ld%c", 0, msg_num, 0);
502         fprintf(exfp, "%ld%c", (long)dmsgtext->len, 0);
503         fwrite(dmsgtext->ptr, dmsgtext->len, 1, exfp);
504
505         cdb_free(dmsgtext);
506         }
507
508
509 void export_a_room(struct quickroom *qr) {
510         int b = 0;
511         int msgcount = 0;
512
513         lprintf(9,"<%s>\n", qr->QRname);
514         fprintf(exfp, "room%c", 0);
515         fprintf(exfp, "qrname%c%s%c", 0, qr->QRname, 0);
516         fprintf(exfp, "qrpasswd%c%s%c", 0, qr->QRpasswd, 0);
517         fprintf(exfp, "qrroomaide%c%ld%c", 0, qr->QRroomaide, 0);
518         fprintf(exfp, "qrhighest%c%ld%c", 0, qr->QRhighest, 0);
519         fprintf(exfp, "qrgen%c%ld%c", 0, qr->QRgen, 0);
520         fprintf(exfp, "qrflags%c%d%c", 0, qr->QRflags, 0);
521         fprintf(exfp, "qrdirname%c%s%c", 0, qr->QRdirname, 0);
522         fprintf(exfp, "qrinfo%c%ld%c", 0, qr->QRinfo, 0);
523         fprintf(exfp, "qrfloor%c%d%c", 0, qr->QRfloor, 0);
524         fprintf(exfp, "qrmtime%c%ld%c", 0, qr->QRmtime, 0);
525         fprintf(exfp, "qrepmode%c%d%c", 0, qr->QRep.expire_mode, 0);
526         fprintf(exfp, "qrepvalue%c%d%c", 0, qr->QRep.expire_value, 0);
527
528         get_msglist(qr);
529         if (CC->num_msgs > 0) for (b=0; b<(CC->num_msgs); ++b) {
530                 ++msgcount;
531                 lprintf(9, "Message #%ld\n", MessageFromList(b));
532                 dump_message(MessageFromList(b));
533                 }
534
535         fprintf(exfp, "endroom%c", 0);
536         }
537
538
539 void export_rooms(void) {
540         lprintf(9,"Rooms\n");
541         fprintf(exfp, "rooms%c", 0);
542         ForEachRoom(export_a_room);
543         fprintf(exfp, "endsection%c", 0);
544         }
545
546
547
548 void export_floors(void) {
549         int floornum;
550         struct floor fl;
551
552         fprintf(exfp, "floors%c", 0);
553         for (floornum=0; floornum<MAXFLOORS; ++floornum) {
554                 getfloor(&fl, floornum);
555                 fprintf(exfp, "floor%c", 0);
556                 fprintf(exfp, "f_flags%c%d%c", 0, fl.f_flags, 0);
557                 fprintf(exfp, "f_name%c%s%c", 0, fl.f_name, 0);
558                 fprintf(exfp, "f_ref_count%c%d%c", 0, fl.f_ref_count, 0);
559                 fprintf(exfp, "f_expire_mode%c%d%c", 0, fl.f_ep.expire_mode, 0);
560                 fprintf(exfp, "f_expire_value%c%d%c", 0,
561                                 fl.f_ep.expire_value, 0);
562                 fprintf(exfp, "endfloor%c", 0);
563                 }
564         fprintf(exfp, "endsection%c", 0);
565         }
566
567
568
569
570 void export_a_user(struct usersupp *us) {
571         struct cdbdata *cdbvisit;
572         struct visit *visits;
573         int num_visits = 0;
574         int a;
575
576         lprintf(9, "User <%s> ", us->fullname);
577
578         fprintf(exfp, "user%c", 0);
579         fprintf(exfp, "usuid%c%d%c", 0, us->USuid, 0);
580         fprintf(exfp, "password%c%s%c", 0, us->password, 0);
581         fprintf(exfp, "flags%c%d%c", 0, us->flags, 0);
582         fprintf(exfp, "timescalled%c%d%c", 0, us->timescalled, 0);
583         fprintf(exfp, "posted%c%d%c", 0, us->posted, 0);
584         fprintf(exfp, "fullname%c%s%c", 0, us->fullname, 0);
585         fprintf(exfp, "axlevel%c%d%c", 0, us->axlevel, 0);
586         fprintf(exfp, "usscreenwidth%c%d%c", 0, us->USscreenwidth, 0);
587         fprintf(exfp, "usscreenheight%c%d%c", 0, us->USscreenheight, 0);
588         fprintf(exfp, "usernum%c%ld%c", 0, us->usernum, 0);
589         fprintf(exfp, "lastcall%c%ld%c", 0, us->lastcall, 0);
590         fprintf(exfp, "usname%c%s%c", 0, us->USname, 0);
591         fprintf(exfp, "usaddr%c%s%c", 0, us->USaddr, 0);
592         fprintf(exfp, "uscity%c%s%c", 0, us->UScity, 0);
593         fprintf(exfp, "usstate%c%s%c", 0, us->USstate, 0);
594         fprintf(exfp, "uszip%c%s%c", 0, us->USzip, 0);
595         fprintf(exfp, "usphone%c%s%c", 0, us->USphone, 0);
596         fprintf(exfp, "usemail%c%s%c", 0, us->USemail, 0);
597         fprintf(exfp, "ususerpurge%c%d%c", 0, us->USuserpurge, 0);
598
599
600         cdbvisit = cdb_fetch(CDB_VISIT, &us->usernum, sizeof(long));
601         if (cdbvisit != NULL) {
602                 num_visits = cdbvisit->len / sizeof(struct visit);
603                 if (num_visits == 0) {
604                         cdb_free(cdbvisit);
605                         goto VISITS_DONE;
606                         }
607                 visits = (struct visit *)
608                         malloc(num_visits * sizeof(struct visit));
609                 memcpy(visits, cdbvisit->ptr,
610                         (num_visits * sizeof(struct visit)));
611                 cdb_free(cdbvisit);
612
613                 if (num_visits > 0) for (a=0; a<num_visits; ++a) {
614                         fprintf(exfp, "visit%c", 0);
615                         fprintf(exfp, "vname%c%s%c", 0,
616                                         visits[a].v_roomname, 0);
617                         fprintf(exfp, "vgen%c%ld%c", 0,
618                                         visits[a].v_generation, 0);
619                         fprintf(exfp, "lastseen%c%ld%c", 0,
620                                         visits[a].v_lastseen, 0);
621                         fprintf(exfp, "flags%c%d%c", 0,
622                                         visits[a].v_flags, 0);
623                         fprintf(exfp, "endvisit%c", 0);
624                         }
625                 free(visits);
626                 }
627
628 VISITS_DONE:
629         lprintf(9, "(%d rooms)\n", num_visits);
630         fprintf(exfp, "enduser%c", 0);
631         }
632
633
634 void export_usersupp(void) {
635         lprintf(9, "Users\n");
636         fprintf(exfp, "usersupp%c", 0);
637
638         ForEachUser(export_a_user);
639
640         fprintf(exfp, "endsection%c", 0);
641         }
642         
643
644 void do_export(char *argbuf) {
645         char export_filename[PATH_MAX];
646         
647         extract(export_filename, argbuf, 0);
648         exfp = fopen(export_filename, "wb");
649         if (exfp == NULL) {
650                 lprintf(9, "Cannot open %s: %s\n",
651                         export_filename, strerror(errno));
652                 cprintf("%d Cannot open file\n", ERROR);
653                 return;
654                 }
655
656         /* structure size variables */
657         lprintf(9, "Structure size variables\n");
658         fprintf(exfp, "ssv%c", 0);
659         fprintf(exfp, "maxfloors%c%d%c", 0, MAXFLOORS, 0);
660         fprintf(exfp, "endsection%c", 0);
661
662         /* Write out the server config */
663         lprintf(9,"Server config\n");
664         fprintf(exfp, "config%c", 0);
665         fprintf(exfp, "c_nodename%c%s%c", 0, config.c_nodename, 0);
666         fprintf(exfp, "c_fqdn%c%s%c", 0, config.c_fqdn, 0);
667         fprintf(exfp, "c_humannode%c%s%c", 0, config.c_humannode, 0);
668         fprintf(exfp, "c_phonenum%c%s%c", 0, config.c_phonenum, 0);
669         fprintf(exfp, "c_bbsuid%c%d%c", 0, config.c_bbsuid, 0);
670         fprintf(exfp, "c_creataide%c%d%c", 0, config.c_creataide, 0);
671         fprintf(exfp, "c_sleeping%c%d%c", 0, config.c_sleeping, 0);
672         fprintf(exfp, "c_initax%c%d%c", 0, config.c_initax, 0);
673         fprintf(exfp, "c_regiscall%c%d%c", 0, config.c_regiscall, 0);
674         fprintf(exfp, "c_twitdetect%c%d%c", 0, config.c_twitdetect, 0);
675         fprintf(exfp, "c_twitroom%c%s%c", 0, config.c_twitroom, 0);
676         fprintf(exfp, "c_moreprompt%c%s%c", 0, config.c_moreprompt, 0);
677         fprintf(exfp, "c_restrict%c%d%c", 0, config.c_restrict, 0);
678         fprintf(exfp, "c_bbs_city%c%s%c", 0, config.c_bbs_city, 0);
679         fprintf(exfp, "c_sysadm%c%s%c", 0, config.c_sysadm, 0);
680         fprintf(exfp, "c_bucket_dir%c%s%c", 0, config.c_bucket_dir, 0);
681         fprintf(exfp, "c_setup_level%c%d%c", 0, config.c_setup_level, 0);
682         fprintf(exfp, "c_maxsessions%c%d%c", 0, config.c_maxsessions, 0);
683         fprintf(exfp, "c_net_password%c%s%c", 0, config.c_net_password, 0);
684         fprintf(exfp, "c_port_number%c%d%c", 0, config.c_port_number, 0);
685         fprintf(exfp, "c_expire_policy%c%d%c", 0, config.c_ep.expire_mode, 0);
686         fprintf(exfp, "c_expire_value%c%d%c", 0, config.c_ep.expire_value, 0);
687         fprintf(exfp, "c_userpurge%c%d%c", 0, config.c_userpurge, 0);
688         fprintf(exfp, "endsection%c", 0);
689
690         /* Now some global stuff */
691         lprintf(9, "Globals\n");
692         get_control();
693         fprintf(exfp, "globals%c", 0);
694         fprintf(exfp, "mmhighest%c%ld%c", 0, CitControl.MMhighest, 0);
695         fprintf(exfp, "mmnextuser%c%ld%c", 0, CitControl.MMnextuser, 0);
696         fprintf(exfp, "mmflags%c%d%c", 0, CitControl.MMflags, 0);
697         fprintf(exfp, "endsection%c", 0);
698
699         /* Export all of the databases */
700         export_rooms();
701         export_floors();
702         export_usersupp();
703
704         fprintf(exfp, "endfile%c", 0);
705         fclose(exfp);
706         lprintf(1, "Export is finished.\n");
707         cprintf("%d Export is finished.\n", OK);
708         }
709
710
711
712 struct DLModule_Info *Dynamic_Module_Init(void) {
713         CtdlRegisterProtoHook(do_import,
714                                 "IMPO",
715                                 "Import an unpacked system");
716         CtdlRegisterProtoHook(do_export,
717                                 "EXPO",
718                                 "Export the system");
719         return &info;
720         }