17 #include "sysdep_decls.h"
18 #include "citserver.h"
21 #include "dynloader.h"
27 extern struct CitContext *ContextList;
30 #define MODULE_NAME "Import an unpacked system"
31 #define MODULE_AUTHOR "Art Cancro"
32 #define MODULE_EMAIL "ajc@uncnsrd.mt-kisco.ny.us"
33 #define MAJOR_VERSION 0
34 #define MINOR_VERSION 1
36 static struct DLModule_Info info = {
47 void fpgetfield(fp,string)
66 void import_message(long msgnum, long msglen) {
69 msgtext = malloc(msglen);
70 if (msgtext == NULL) {
71 lprintf(3, "ERROR: cannot allocate memory\n");
72 lprintf(3, "Your data files are now corrupt.\n");
77 fread(msgtext, msglen, 1, imfp);
78 cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
83 char key[256], tag[256], tval[256];
88 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
90 if (!strcasecmp(key, "floor")) {
91 bzero(&fl, sizeof(struct floor));
93 while(fpgetfield(imfp, tag),
94 strcasecmp(tag, "endfloor")) {
95 fpgetfield(imfp, tval);
97 if (!strcasecmp(tag, "f_flags"))
98 fl.f_flags = atoi(tval);
99 if (!strcasecmp(tag, "f_name")) {
100 lprintf(9, "Floor <%s>\n", tval);
101 strcpy(fl.f_name, tval);
103 if (!strcasecmp(tag, "f_ref_count"))
104 fl.f_ref_count = atoi(tval);
107 putfloor(&fl, floornum);
111 lprintf(3, "ERROR: invalid floor section.\n");
112 lprintf(3, "Your data files are now corrupt.\n");
123 char tag[256], tval[256];
130 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
131 if (!strcasecmp(key, "room")) {
132 bzero(&qr, sizeof(struct quickroom));
137 while(fpgetfield(imfp, tag),
138 strcasecmp(tag, "endroom")) {
139 if (strcasecmp(tag, "message")) {
140 fpgetfield(imfp, tval);
146 if (!strcasecmp(tag, "qrname")) {
147 strcpy(qr.QRname, tval);
148 lprintf(9, "<%s>", qr.QRname);
150 if (!strcasecmp(tag, "qrpasswd"))
151 strcpy(qr.QRpasswd, tval);
152 if (!strcasecmp(tag, "qrroomaide"))
153 qr.QRroomaide = atol(tval);
154 if (!strcasecmp(tag, "qrhighest"))
155 qr.QRhighest = atol(tval);
156 if (!strcasecmp(tag, "qrgen"))
157 qr.QRgen = atol(tval);
158 if (!strcasecmp(tag, "qrflags"))
159 qr.QRflags = atoi(tval);
160 if (!strcasecmp(tag, "qrdirname"))
161 strcpy(qr.QRdirname, tval);
162 if (!strcasecmp(tag, "qrinfo"))
163 qr.QRinfo = atol(tval);
164 if (!strcasecmp(tag, "qrfloor"))
165 qr.QRfloor = atoi(tval);
166 if (!strcasecmp(tag, "message")) {
168 fpgetfield(imfp, tval);
170 fpgetfield(imfp, tval);
172 import_message(msgnum, msglen);
174 msglist = realloc(msglist,
175 (sizeof(long)*num_msgs) );
176 msglist[num_msgs - 1] = msgnum;
182 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
183 putroom(&qr, qr.QRname);
187 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
188 CC->msglist = msglist;
189 CC->num_msgs = num_msgs;
199 lprintf(3, "ERROR: invalid room section.\n");
200 lprintf(3, "Your data files are now corrupt.\n");
211 void import_a_user() {
212 char key[256], value[256], list[256];
213 char vkey[256], vvalue[256];
222 bzero(&us, sizeof(struct usersupp));
223 while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
224 if ((strcasecmp(key, "mail"))
225 &&(strcasecmp(key, "lastseen"))
226 &&(strcasecmp(key, "generation"))
227 &&(strcasecmp(key, "forget")) ) {
228 fpgetfield(imfp, value);
234 if (!strcasecmp(key, "usuid"))
235 us.USuid = atoi(value);
236 if (!strcasecmp(key, "password")) {
237 strcpy(us.password, value);
240 if (!strcasecmp(key, "flags"))
241 us.flags = atoi(value);
242 if (!strcasecmp(key, "timescalled"))
243 us.timescalled = atoi(value);
244 if (!strcasecmp(key, "posted"))
245 us.posted = atoi(value);
246 if (!strcasecmp(key, "fullname")) {
247 strcpy(us.fullname, value);
248 lprintf(9, "User <%s>", us.fullname);
250 if (!strcasecmp(key, "axlevel"))
251 us.axlevel = atoi(value);
252 if (!strcasecmp(key, "usscreenwidth"))
253 us.USscreenwidth = atoi(value);
254 if (!strcasecmp(key, "usscreenheight"))
255 us.USscreenheight = atoi(value);
256 if (!strcasecmp(key, "usernum"))
257 us.usernum = atol(value);
258 if (!strcasecmp(key, "lastcall"))
259 us.lastcall = atol(value);
260 if (!strcasecmp(key, "usname"))
261 strcpy(us.USname, value);
262 if (!strcasecmp(key, "usaddr"))
263 strcpy(us.USaddr, value);
264 if (!strcasecmp(key, "uscity"))
265 strcpy(us.UScity, value);
266 if (!strcasecmp(key, "usstate"))
267 strcpy(us.USstate, value);
268 if (!strcasecmp(key, "uszip"))
269 strcpy(us.USzip, value);
270 if (!strcasecmp(key, "usphone"))
271 strcpy(us.USphone, value);
272 if (!strcasecmp(key, "usemail"))
273 strcpy(us.USemail, value);
274 if (!strcasecmp(key, "mail")) {
276 fpgetfield(imfp, list);
278 fpgetfield(imfp, list);
280 import_message(msgnum, msglen);
282 mbox = realloc(mbox, (sizeof(long)*mbox_size) );
283 mbox[mbox_size - 1] = msgnum;
285 if (!strcasecmp(key, "visit")) {
286 lprintf(9,"visit: ");
287 bzero(&vbuf, sizeof(struct visit));
288 bzero(&qr, sizeof(struct quickroom));
289 while(fpgetfield(imfp, vkey),
290 strcasecmp(vkey, "endvisit")) {
291 fpgetfield(imfp, vvalue);
292 if (!strcasecmp(vkey, "vname"))
293 strcpy(qr.QRname, vvalue);
294 if (!strcasecmp(vkey, "vgen")) {
295 qr.QRgen = atol(vvalue);
296 lprintf(9, "<%s><%ld> ",
297 qr.QRname, qr.QRgen);
298 CtdlGetRelationship(&vbuf, &us, &qr);
300 if (!strcasecmp(vkey, "lastseen"))
301 vbuf.v_lastseen = atol(vvalue);
302 if (!strcasecmp(vkey, "flags"))
303 vbuf.v_flags = atoi(vvalue);
305 CtdlSetRelationship(&vbuf, &us, &qr);
310 putuser(&us, us.fullname);
312 /* create a mailbox room */
313 bzero(&qr, sizeof(struct quickroom));
314 MailboxName(qr.QRname, &us, MAILROOM);
315 qr.QRflags = QR_INUSE | QR_MAILBOX;
317 if (mbox_size > 0) qr.QRhighest = mbox[mbox_size - 1];
318 putroom(&qr, qr.QRname);
321 CC->num_msgs = mbox_size;
329 void imp_usersupp() {
330 char key[256], value[256];
332 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
333 if (strcasecmp(key, "user")) {
334 fpgetfield(imfp, value);
339 lprintf(9, " %s = %s\n", key, value);
341 if (!strcasecmp(key, "user")) {
352 char key[256], value[256];
355 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
356 fpgetfield(imfp, value);
357 lprintf(9, " %s = %s\n", key, value);
359 if (!strcasecmp(key, "mmhighest"))
360 CitControl.MMhighest = atol(value);
361 if (!strcasecmp(key, "mmnextuser"))
362 CitControl.MMnextuser = atol(value);
371 char key[256], value[256];
374 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
375 fpgetfield(imfp, value);
376 lprintf(9, " %s = %s\n", key, value);
378 if (!strcasecmp(key, "c_nodename"))
379 strcpy(config.c_nodename, value);
380 if (!strcasecmp(key, "c_fqdn"))
381 strcpy(config.c_fqdn, value);
382 if (!strcasecmp(key, "c_humannode"))
383 strcpy(config.c_humannode, value);
384 if (!strcasecmp(key, "c_phonenum"))
385 strcpy(config.c_phonenum, value);
386 if (!strcasecmp(key, "c_phonenum"))
387 strcpy(config.c_phonenum, value);
388 if (!strcasecmp(key, "c_bbsuid"))
389 config.c_bbsuid = atoi(value);
390 if (!strcasecmp(key, "c_creataide"))
391 config.c_creataide = atoi(value);
392 if (!strcasecmp(key, "c_sleeping"))
393 config.c_sleeping = atoi(value);
394 if (!strcasecmp(key, "c_initax"))
395 config.c_initax = atoi(value);
396 if (!strcasecmp(key, "c_regiscall"))
397 config.c_regiscall = atoi(value);
398 if (!strcasecmp(key, "c_twitdetect"))
399 config.c_twitdetect = atoi(value);
400 if (!strcasecmp(key, "c_twitroom"))
401 strcpy(config.c_twitroom, value);
402 if (!strcasecmp(key, "c_defent"))
403 config.c_defent = atoi(value);
404 if (!strcasecmp(key, "c_moreprompt"))
405 strcpy(config.c_moreprompt, value);
406 if (!strcasecmp(key, "c_restrict"))
407 config.c_restrict = atoi(value);
408 if (!strcasecmp(key, "c_bbs_city"))
409 strcpy(config.c_bbs_city, value);
410 if (!strcasecmp(key, "c_sysadm"))
411 strcpy(config.c_sysadm, value);
412 if (!strcasecmp(key, "c_bucket_dir"))
413 strcpy(config.c_bucket_dir, value);
414 if (!strcasecmp(key, "c_setup_level"))
415 config.c_setup_level = atoi(value);
416 if (!strcasecmp(key, "c_maxsessions"))
417 config.c_maxsessions = atoi(value);
418 if (!strcasecmp(key, "c_net_password"))
419 strcpy(config.c_net_password, value);
420 if (!strcasecmp(key, "c_port_number"))
421 config.c_port_number = atoi(value);
424 fp = fopen("citadel.config", "wb");
425 fwrite(&config, sizeof(struct config), 1, fp);
434 char key[256], value[256];
435 int ssv_maxfloors = MAXFLOORS;
437 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
438 fpgetfield(imfp, value);
439 lprintf(9, " %s = %s\n", key, value);
441 if (!strcasecmp(key, "maxfloors")) {
442 ssv_maxfloors = atol(value);
443 if (ssv_maxfloors > MAXFLOORS) {
444 lprintf(3, "ERROR: maxfloors is %d, need %d\n",
445 ssv_maxfloors, MAXFLOORS);
459 void import_databases() {
462 lprintf(9, " ** IMPORTING ** \n");
463 while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
464 lprintf(9, "Section: <%s>\n", section);
466 if (!strcasecmp(section, "ssv")) imp_ssv();
467 else if (!strcasecmp(section, "config")) imp_config();
468 else if (!strcasecmp(section, "globals")) imp_globals();
469 else if (!strcasecmp(section, "usersupp")) imp_usersupp();
470 else if (!strcasecmp(section, "rooms")) imp_rooms();
471 else if (!strcasecmp(section, "floors")) imp_floors();
473 lprintf(3, "ERROR: invalid import section.\n");
474 lprintf(3, "Your data files are now corrupt.\n");
485 void do_import(char *argbuf) {
486 char import_filename[PATH_MAX];
489 if (num_parms(argbuf) != 1) {
490 cprintf("%d usage: IMPO unpacked_filename\n", ERROR);
493 extract(import_filename, argbuf, 0);
494 imfp = fopen(import_filename, "rb");
496 lprintf(9, "Cannot open %s: %s\n",
497 import_filename, strerror(errno));
498 cprintf("%d Cannot open file\n", ERROR);
503 cprintf("%d ok\n", OK);
507 struct DLModule_Info *Dynamic_Module_Init(void) {
508 CtdlRegisterProtoHook(do_import,
510 "Import an unpacked Cit5");