4 * 5.80 to 5.90 migration utility for network files
12 #include <sys/types.h>
19 #include "citadel_ipc.h"
24 struct mn_roomlist *next;
33 int main(int argc, char **argv)
46 char roomfilename[SIZ];
48 char nodefilename[SIZ];
50 struct mn_roomlist *mn = NULL;
51 struct mn_roomlist *mnptr = NULL;
56 "This utility migrates your network settings (room sharing with other\n"
57 "Citadel systems) from 5.80 to 5.90. You should only do this ONCE. It\n"
58 "will ERASE your 5.80 configuration files when it is finished, and it will\n"
59 "ERASE any 5.90 configuration files that you have already set up.\n\n"
60 "Are you sure you want to do this? ");
62 fgets(buf, sizeof buf, stdin);
63 if (tolower(buf[0]) != 'y') exit(0);
67 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
68 CtdlIPC_getline(ipc, buf);
69 printf("%s\n", &buf[4]);
70 if ( (buf[0]!='2') && (strncmp(buf,"551",3)) ) {
71 fprintf(stderr, "%s: %s\n", argv[0], &buf[4]);
75 r = CtdlIPCInternalProgram(ipc, config.c_ipgm_secret, buf);
76 fprintf(stderr, "%s\n", buf);
81 if (chdir("network/systems") != 0) {
82 perror("cannot chdir network/systems");
86 strcpy(roomfilename, tmpnam(NULL));
87 roomfp = fopen(roomfilename, "w");
89 perror("cannot open temp file");
93 strcpy(nodefilename, tmpnam(NULL));
94 nodefp = fopen(nodefilename, "w");
96 perror("cannot open temp file");
102 perror("cannot open directory");
106 while (d = readdir(dp), d != NULL) {
108 if ( (d->d_name[0] != '.') && strcasecmp(d->d_name, "CVS")) {
109 fp = fopen(d->d_name, "r");
112 printf("\n*** Processing '%s'\n", d->d_name);
114 fprintf(nodefp, "%s|", d->d_name);
115 printf("Enter shared secret: ");
116 myfgets(buf, sizeof buf, stdin);
117 if (buf[0] == 0) strcpy(buf, config.c_net_password);
118 fprintf(nodefp, "%s|", buf);
119 printf("Enter host name/IP : ");
120 myfgets(buf, sizeof buf, stdin);
121 if (buf[0] == 0) snprintf(buf, sizeof buf, "%s.citadel.org",
123 fprintf(nodefp, "%s|", buf);
124 printf("Enter port number : ");
125 fgets(buf, sizeof buf, stdin);
126 if (buf[0] == 0) strcpy(buf, "504");
127 fprintf(nodefp, "%s\n", buf);
129 fgets(buf, sizeof buf, fp);
130 printf("skipping: %s", buf);
131 while (fgets(room, sizeof room, fp),
132 (fgets(buf, sizeof buf, fp) != NULL) ) {
133 thighest = atol(buf),
134 room[strlen(room) - 1] = 0;
135 fprintf(roomfp, "%s|%s\n",
137 if (thighest > highest) {
149 /* Point of no return */
150 nodefp = fopen(nodefilename, "r");
151 if (nodefp != NULL) {
152 fseek(nodefp, 0L, SEEK_END);
153 listing = malloc(ftell(nodefp) + 1);
155 while (fgets(buf, sizeof buf, nodefp) != NULL) {
156 strcat(listing, buf);
161 /* Set up the node table */
162 printf("Creating neighbor node table\n");
163 r = CtdlIPCSetSystemConfigByType(ipc, IGNETCFG, listing, buf);
170 /* Now go through the table looking for node names to enter */
171 snprintf(buf, sizeof buf, "cat %s |awk -F \"|\" '{ print $2 }' |sort -f |uniq -i",
173 roomfp = popen(buf, "r");
174 if (roomfp == NULL) {
175 perror("cannot open pipe");
176 unlink(roomfilename);
179 while (fgets(room, sizeof room, roomfp) != NULL) {
180 room[strlen(room)-1] = 0;
181 if (strlen(room) > 0) {
182 mnptr = (struct mn_roomlist *)
183 malloc(sizeof (struct mn_roomlist));
184 strcpy(mnptr->roomname, room);
192 /* Enter configurations for each room... */
194 struct ctdlipcroom *current_room = NULL;
196 printf("Room <%s>\n", mn->roomname);
198 r = CtdlIPCGotoRoom(ipc, mn->roomname, NULL,
201 if (r / 100 != 2) goto roomerror;
203 /* Hey IG, what the hell is SNET? */
204 CtdlIPC_putline(ipc, "SNET");
205 CtdlIPC_getline(ipc, buf);
206 if (buf[0] != '4') goto roomerror;
208 snprintf(buf, sizeof buf, "lastsent|%ld", highest);
209 CtdlIPC_putline(ipc, buf);
211 roomfp = fopen(roomfilename, "r");
212 if (roomfp != NULL) {
213 while (fgets(buf, sizeof buf, roomfp) != NULL) {
214 buf[strlen(buf)-1] = 0;
215 extract(node, buf, 0);
216 extract(room, buf, 1);
217 if (!strcasecmp(room, mn->roomname)) {
218 snprintf(buf, sizeof buf,
219 "ignet_push_share|%s", node);
220 CtdlIPC_putline(ipc, buf);
226 CtdlIPC_putline(ipc, "000");
228 roomerror: /* free this record */
234 unlink(roomfilename);
235 unlink(nodefilename);
238 "If this conversion was successful, you do not need your\n"
239 "old network configuration files. Delete them now? "
242 fgets(buf, sizeof buf, stdin);
243 if (tolower(buf[0]) != 'y') exit(0);
246 system("rm -fr ./network/systems");
247 system("rm -f ./network/mail.sysinfo");
248 system("rm -f ./network/internetmail.config");