4 * 5.80 to 5.90 migration utility for network files
13 #include <sys/types.h>
20 #include "citadel_ipc.h"
25 struct mn_roomlist *next;
34 int main(int argc, char **argv)
47 char roomfilename[SIZ];
49 char nodefilename[SIZ];
51 struct mn_roomlist *mn = NULL;
52 struct mn_roomlist *mnptr = NULL;
57 "This utility migrates your network settings (room sharing with other\n"
58 "Citadel systems) from 5.80 to 5.90. You should only do this ONCE. It\n"
59 "will ERASE your 5.80 configuration files when it is finished, and it will\n"
60 "ERASE any 5.90 configuration files that you have already set up.\n\n"
61 "Are you sure you want to do this? ");
63 fgets(buf, sizeof buf, stdin);
64 if (tolower(buf[0]) != 'y') exit(0);
68 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
69 CtdlIPC_getline(ipc, buf);
70 printf("%s\n", &buf[4]);
71 if ( (buf[0]!='2') && (strncmp(buf,"551",3)) ) {
72 fprintf(stderr, "%s: %s\n", argv[0], &buf[4]);
76 r = CtdlIPCInternalProgram(ipc, config.c_ipgm_secret, buf);
77 fprintf(stderr, "%s\n", buf);
82 if (chdir("network/systems") != 0) {
83 perror("cannot chdir network/systems");
87 strcpy(roomfilename, tmpnam(NULL));
88 roomfp = fopen(roomfilename, "w");
90 perror("cannot open temp file");
94 strcpy(nodefilename, tmpnam(NULL));
95 nodefp = fopen(nodefilename, "w");
97 perror("cannot open temp file");
103 perror("cannot open directory");
107 while (d = readdir(dp), d != NULL) {
109 if ( (d->d_name[0] != '.') && strcasecmp(d->d_name, "CVS")) {
110 fp = fopen(d->d_name, "r");
113 printf("\n*** Processing '%s'\n", d->d_name);
115 fprintf(nodefp, "%s|", d->d_name);
116 printf("Enter shared secret: ");
117 myfgets(buf, sizeof buf, stdin);
118 if (buf[0] == 0) strcpy(buf, config.c_net_password);
119 fprintf(nodefp, "%s|", buf);
120 printf("Enter host name/IP : ");
121 myfgets(buf, sizeof buf, stdin);
122 if (buf[0] == 0) snprintf(buf, sizeof buf, "%s.citadel.org",
124 fprintf(nodefp, "%s|", buf);
125 printf("Enter port number : ");
126 fgets(buf, sizeof buf, stdin);
127 if (buf[0] == 0) strcpy(buf, "504");
128 fprintf(nodefp, "%s\n", buf);
130 fgets(buf, sizeof buf, fp);
131 printf("skipping: %s", buf);
132 while (fgets(room, sizeof room, fp),
133 (fgets(buf, sizeof buf, fp) != NULL) ) {
134 thighest = atol(buf),
135 room[strlen(room) - 1] = 0;
136 fprintf(roomfp, "%s|%s\n",
138 if (thighest > highest) {
150 /* Point of no return */
151 nodefp = fopen(nodefilename, "r");
152 if (nodefp != NULL) {
153 fseek(nodefp, 0L, SEEK_END);
154 listing = malloc(ftell(nodefp) + 1);
156 while (fgets(buf, sizeof buf, nodefp) != NULL) {
157 strcat(listing, buf);
162 /* Set up the node table */
163 printf("Creating neighbor node table\n");
164 r = CtdlIPCSetSystemConfigByType(ipc, IGNETCFG, listing, buf);
171 /* Now go through the table looking for node names to enter */
172 snprintf(buf, sizeof buf, "cat %s |awk -F \"|\" '{ print $2 }' |sort -f |uniq -i",
174 roomfp = popen(buf, "r");
175 if (roomfp == NULL) {
176 perror("cannot open pipe");
177 unlink(roomfilename);
180 while (fgets(room, sizeof room, roomfp) != NULL) {
181 room[strlen(room)-1] = 0;
182 if (strlen(room) > 0) {
183 mnptr = (struct mn_roomlist *)
184 malloc(sizeof (struct mn_roomlist));
185 strcpy(mnptr->roomname, room);
193 /* Enter configurations for each room... */
195 struct ctdlipcroom *current_room = NULL;
197 printf("Room <%s>\n", mn->roomname);
199 r = CtdlIPCGotoRoom(ipc, mn->roomname, NULL,
202 if (r / 100 != 2) goto roomerror;
204 /* Hey IG, what the hell is SNET? */
205 CtdlIPC_putline(ipc, "SNET");
206 CtdlIPC_getline(ipc, buf);
207 if (buf[0] != '4') goto roomerror;
209 snprintf(buf, sizeof buf, "lastsent|%ld", highest);
210 CtdlIPC_putline(ipc, buf);
212 roomfp = fopen(roomfilename, "r");
213 if (roomfp != NULL) {
214 while (fgets(buf, sizeof buf, roomfp) != NULL) {
215 buf[strlen(buf)-1] = 0;
216 extract(node, buf, 0);
217 extract(room, buf, 1);
218 if (!strcasecmp(room, mn->roomname)) {
219 snprintf(buf, sizeof buf,
220 "ignet_push_share|%s", node);
221 CtdlIPC_putline(ipc, buf);
227 CtdlIPC_putline(ipc, "000");
229 roomerror: /* free this record */
235 unlink(roomfilename);
236 unlink(nodefilename);
239 "If this conversion was successful, you do not need your\n"
240 "old network configuration files. Delete them now? "
243 fgets(buf, sizeof buf, stdin);
244 if (tolower(buf[0]) != 'y') exit(0);
247 system("rm -fr ./network/systems");
248 system("rm -f ./network/mail.sysinfo");
249 system("rm -f ./network/internetmail.config");