1 /******************************************************************************
2  * FIDOCONFIG --- library for fidonet configs
3  ******************************************************************************
4  * Copyright (C) 1998
5  *
6  * Matthias Tichy
7  *
8  * Fido:     2:2433/1245 2:2433/1247 2:2432/605.14
9  * Internet: mtt@tichy.de
10  *
11  * Grimmestr. 12         Buchholzer Weg 4
12  * 33098 Paderborn       40472 Duesseldorf
13  * Germany               Germany
14  *
15  * This file is part of FIDOCONFIG.
16  *
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Library General Public
19  * License as published by the Free Software Foundation; either
20  * version 2 of the License, or (at your option) any later version.
21  *
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Library General Public License for more details.
26  *
27  * You should have received a copy of the GNU Library General Public
28  * License along with this library; see file COPYING. If not, write to the Free
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30  *****************************************************************************/
31 #define AREASONLY 0x1
32 #define NETMAIL 0x2
33 #define ECHOMAIL 0x4
34 #define LOCAL 0x8
35 #define DUPE 0x10
36 #define BAD 0x20
37 
38 
39 #include <stdlib.h>
40 #include <string.h>
41 
42 #include "fidoconf.h"
43 #include "common.h"
44 
45 #ifndef VERSION_H
46 #define VERSION_H
47 
48 #include "version.h"
49 #include "../cvsdate.h"
50 
51 #endif
52 
53 char *fidoconfig=NULL;
54 
usage()55 void usage(){
56       printf(
57       "Usage: fconf2golded [options] <GoldedConfigFileName> [GoldedDefaultConfigFileName]\n"
58       "Options:\n"
59       "\t  -a\t- exports areas only\n"
60       "\t  -cFidoconfig - specify a Husky config file <Fidoconfig>\n"
61       "\t  -h\t- print usage information (this text)\n"
62       "\t  -H\t- print usage information (this text)\n"
63       "\t  -sb\t- skip badmail areas\n"
64       "\t  -sd\t- skip dupes areas\n"
65       "\t  -se\t- skip echomail areas\n"
66       "\t  -sl\t- skip local areas\n"
67       "\t  -sn\t- skip netmail areas\n");
68       exit(1);
69 }
70 
writeArea(FILE * f,s_area * area,char type)71 int writeArea(FILE *f, s_area *area, char type) {
72 
73    if (area->group == NULL) {
74       area->group = malloc(2);
75       strcpy(area->group, "0");
76    }
77 
78    fprintf(f, "areadef %s \"%s\" %s ", area->areaName,
79              (area->description!=NULL) ? area->description : area->areaName, area->group);
80 
81    switch (type) {
82      case 0: fprintf(f, "echo ");
83              break;
84      case 1: fprintf(f, "net ");
85              break;
86      case 2: fprintf(f, "local ");
87    }
88 
89    if (area->msgbType == MSGTYPE_SQUISH) fprintf(f, "Squish ");
90    else if (area->msgbType == MSGTYPE_JAM) fprintf(f, "Jam ");
91    else fprintf(f, "Opus ");
92 
93    fprintf(f, "%s ", area->fileName);
94 
95    fprintf(f, "%u:%u/%u.%u", area->useAka->zone, area->useAka->net, area->useAka->node, area->useAka->point);
96 
97    fprintf(f, "\n");
98 
99    return 0;
100 }
101 
readDefaultConfig(char * cfg_file,char * def_file)102 int readDefaultConfig(char *cfg_file, char *def_file) {
103   FILE *f1,*f2;
104   char buffer[2048];
105 
106   if ((f1=fopen(def_file,"rt"))==NULL) {
107     perror("Orig. file not found!");
108     return -1;
109   }
110   else {
111     if ((f2=fopen (cfg_file,"wt"))==NULL) {
112       perror("Can't create dest. file!");
113       return -2;
114     }
115     else {
116       while (fgets(buffer,sizeof(buffer),f1))
117         fputs (buffer,f2);
118     }
119     fclose(f1);
120     fclose(f2);
121   }
122   return 0;
123 }
124 
generateGoldEdConfig(s_fidoconfig * config,char * fileName,int options)125 int generateGoldEdConfig(s_fidoconfig *config, char *fileName, int options) {
126    FILE *f;
127    unsigned int  i;
128    s_area *area;
129    f = fopen(fileName, "a+");
130    if (f!= NULL) {
131     if (!(options & AREASONLY)) {
132 
133        fprintf(f, "username %s\n\n", config->sysop);
134 
135        for (i=0; i<config->addrCount; i++)
136          fprintf(f, "Address %u:%u/%u.%u\n",
137                     config->addr[i].zone,
138                     config->addr[i].net,
139                     config->addr[i].node,
140                     config->addr[i].point);
141 
142        fprintf(f, "\n");
143      }
144     if (!(options & NETMAIL)) {
145 
146 	     for (i=0; i<config->netMailAreaCount; i++) {
147 		     writeArea(f, &(config->netMailAreas[i]), 1);
148 		}
149 	}if (!(options & DUPE)) {
150 
151 		writeArea(f, &(config->dupeArea), 2);
152 	}
153     if (!(options & BAD)) {
154 		writeArea(f, &(config->badArea), 2);
155 	}
156     if (!(options & ECHOMAIL)) {
157      for (i=0; i<config->echoAreaCount; i++) {
158        area = &(config->echoAreas[i]);
159        if (area->msgbType != MSGTYPE_PASSTHROUGH)
160            writeArea(f, area, 0);
161      }
162 	}
163     if (!(options & LOCAL)) {
164      for (i=0; i<config->localAreaCount; i++) {
165        area = &(config->localAreas[i]);
166        writeArea(f, area, 2);
167      }
168 	}
169      return 0;
170    } else printf("Could not write %s\n", fileName);
171 
172    return 1;
173 }
174 
parseOptions(char * line)175 int parseOptions(char *line){
176 int options=0;
177 char chr=0;
178 
179  if(line[0]!='-'){
180    fprintf(stderr,"parseOptions(): this is not option: \"%s\"\n",line);
181    exit(1);
182  }
183 
184  if (sstrcmp(line+1,"a")==0){
185    options^=AREASONLY;
186    return options;
187  }
188  else if (line[1]=='c'){
189    if(line[2]!='\0') fidoconfig=sstrdup(line+2);
190    return options;
191  }
192  else if (line[1]=='s' && line[3]=='\0')
193    chr=line[2];
194  else if (line[1]=='h' || line[1]=='H'){
195    usage();
196  }
197  else{
198    fprintf(stderr,"this is unknown option: \"%s\"\n",line);
199    exit(1);
200  }
201 
202  switch (chr){
203 
204 	case 'a':	{
205 					options^=AREASONLY;
206 					break;
207 	}
208 	case 'n':	{
209 					options^=NETMAIL;
210 					break;
211 	}
212 	case 'e':	{
213 					options^=ECHOMAIL;
214 					break;
215 	}
216 
217 	case 'l':	{
218 					options^=LOCAL;
219 					break;
220 	}
221 	case 'd':	{
222 					options^=DUPE;
223 					break;
224 	}
225 	case 'b':	{
226 					options^=BAD;
227 					break;
228 	}
229 	default:
230 	    fprintf(stderr,"this is unknown option: \"%s\"\n",line);
231 	    exit(1);
232 
233  }
234 return options;
235 }
236 
main(int argc,char * argv[])237 int main (int argc, char *argv[]) {
238    s_fidoconfig *config;
239    int options=0;
240    int cont=1;
241 
242    { char *temp;
243      printf("%s\n", temp=GenVersionStr( "fconf2golded", FC_VER_MAJOR,
244                FC_VER_MINOR, FC_VER_PATCH, FC_VER_BRANCH, cvs_date ));
245      nfree(temp);
246    }
247 
248    while ((cont<argc)&&(*argv[cont]=='-')){
249 	options|=parseOptions(argv[cont]);
250 	cont++;
251    }
252    if (!(cont<argc)){
253      usage();
254    }
255    printf("Generating Config-file %s\n", argv[cont]);
256 
257    config = readConfig(fidoconfig);
258    if (config!= NULL) {
259      if (argv[cont+1]!=NULL)  readDefaultConfig (argv[cont], argv[cont+1]);
260      else  remove (argv[cont]);
261      generateGoldEdConfig(config, argv[cont], options);
262      disposeConfig(config);
263      return 0;
264    }
265 
266    return 1;
267 }
268