16 void openTokenFile(char * FileName
)
18 tokenizedFile
= fopen(FileName
, "r");
24 tokenizerLine
= new char[8192];
33 fclose(tokenizedFile
);
40 void getNextToken(char* tk
)
46 token
= strtok(NULL
, tk
);
51 if (!feof(tokenizedFile
)) {
53 fgets(tokenizerLine
, 8192, tokenizedFile
);
54 if (tokenizerLine
== NULL
) {
58 token
= strtok(tokenizerLine
, tk
);
78 char config
[8192]; // arostcp/db path here
83 strcpy(IP
, "10.1.0.1");
84 strcpy(mask
, "255.255.255.0");
85 strcpy(gate
, "10.1.0.250");
86 strcpy(DNS
[0], "10.1.0.251");
87 strcpy(DNS
[1], "10.1.0.252");
88 strcpy(interf
, "DEVS:networks/prm-rtl8029.device");
89 strcpy(host
, "aros1");
90 strcpy(domain
, "arosnet.com");
92 strcpy(config
, "ENV:AROSTCP/db");
104 strcpy(temp
, "ENV:AROSTCP/Config");
105 tok
.openTokenFile(temp
);
106 if (tok
.tokenizedFile
) {
107 tok
.getNextToken(" \n");
108 strlcpy(config
, tok
.token
,8191);
109 tok
.closeTokenFile();
111 strcpy(config
, "ENV:AROSTCP/db");
113 FileName
= new char[strlen(config
) + 20];
115 sprintf(FileName
, "%s/general.config", config
);
116 tok
.openTokenFile(FileName
);
118 if (tok
.newline
) { // read tokens from the beginning of line
120 if (strcmp(tok
.token
, "HOSTNAME") == 0) {
121 tok
.getNextToken("=\n");
122 tstring
= strchr(tok
.token
, '.');
123 strlcpy(domain
, tstring
+ 1,999);
125 strlcpy(host
, tok
.token
,999);
129 tok
.getNextToken("=\n");
131 tok
.closeTokenFile();
133 sprintf(FileName
, "%s/interfaces", config
);
134 tok
.openTokenFile(FileName
);
135 // reads only first uncommented interface
137 tok
.getNextToken(" \n");
139 if (tok
.newline
) comment
= false;
140 if (strncmp(tok
.token
, "#", 1) == 0) comment
= true;
143 if (strncmp(tok
.token
, "DEV=", 4) == 0) {
144 tstring
= strchr(tok
.token
, '=');
145 strlcpy(interf
, tstring
+ 1,4095);
147 if (strncmp(tok
.token
, "IP=", 3) == 0) {
148 tstring
= strchr(tok
.token
, '=');
149 strlcpy(IP
, tstring
+ 1,999);
151 if (strncmp(tok
.token
, "MASK=", 5) == 0) {
152 tstring
= strchr(tok
.token
, '=');
153 strlcpy(mask
, tstring
+ 1,999);
158 tok
.closeTokenFile();
160 sprintf(FileName
, "%s/netdb-myhost", config
);
161 tok
.openTokenFile(FileName
);
164 tok
.getNextToken(" \n");
166 if (strncmp(tok
.token
, "NAMESERVER", 4) == 0) {
167 tok
.getNextToken(" \n");
168 strlcpy(DNS
[dnsc
], tok
.token
,999);
170 if (dnsc
> 1) dnsc
= 1;
174 tok
.closeTokenFile();
176 sprintf(FileName
, "%s/static-routes", config
);
177 tok
.openTokenFile(FileName
);
179 tok
.getNextToken(" \n");
181 if (strncmp(tok
.token
, "DEFAULT", 4) == 0) {
182 tok
.getNextToken(" \n");
183 if (strncmp(tok
.token
, "GATEWAY", 4) == 0) {
184 tok
.getNextToken(" \n");
185 strlcpy(gate
, tok
.token
,999);
190 tok
.closeTokenFile();
192 sprintf(FileName
, "%s/DHCP", config
);
193 tok
.openTokenFile(FileName
);
195 tok
.getNextToken(" \n");
197 if (strncmp(tok
.token
, "True", 4) == 0) {
208 tok
.closeTokenFile();
214 int writePrefs(char* dokad
)
219 FileName
= new char[strlen(dokad
) + 20];
221 ConfFile
= fopen("ENV:AROSTCP/Config", "w");
222 if (!ConfFile
) return 0;
223 fprintf(ConfFile
, "ENV:AROSTCP/db");
226 ConfFile
= fopen("ENVARC:AROSTCP/Config", "w");
228 fprintf(ConfFile
, "ENV:AROSTCP/db");
232 sprintf(FileName
, "%s/DHCP", dokad
);
233 ConfFile
= fopen(FileName
, "w");
234 if (!ConfFile
) return 0;
235 fprintf(ConfFile
, "%s\n", (DHCP
) ? "True" : "False");
238 sprintf(FileName
, "%s/general.config", dokad
);
239 ConfFile
= fopen(FileName
, "w");
240 if (!ConfFile
) return 0;
241 fprintf(ConfFile
, "USELOOPBACK=YES\n");
242 fprintf(ConfFile
, "DEBUGSANA=NO\n");
243 fprintf(ConfFile
, "USENS=SECOND\n");
244 fprintf(ConfFile
, "GATEWAY=NO\n");
245 fprintf(ConfFile
, "HOSTNAME=%s.%s\n", host
, domain
);
246 fprintf(ConfFile
, "LOG FILTERFILE=5\n");
247 fprintf(ConfFile
, "GUI PANEL=MUI\n");
248 fprintf(ConfFile
, "OPENGUI=YES\n");
251 sprintf(FileName
, "%s/interfaces", dokad
);
252 ConfFile
= fopen(FileName
, "w");
253 if (!ConfFile
) return 0;
254 fprintf(ConfFile
,"eth0 DEV=%s UNIT=0 NOTRACKING IP=%s NETMASK=%s UP\n",interf
,IP
,mask
);
258 sprintf(FileName
, "%s/netdb-myhost", dokad
);
259 ConfFile
= fopen(FileName
, "w");
260 if (!ConfFile
) return 0;
261 fprintf(ConfFile
, "HOST %s %s.%s %s\n", IP
, host
, domain
, host
);
262 fprintf(ConfFile
, "HOST %s gateway\n", gate
);
263 fprintf(ConfFile
, "; Domain names\n");
264 // DOMAIN dupa.com.pl
265 //fprintf(ConfFile,"DOMAIN %d.%d.%d. %s\n",IP[0]&mask[0],IP[1]&mask[1],IP[2]&mask[2],domain);
266 //fprintf(ConfFile,"DOMAIN %d.%d.%d.%d %s\n",IP[0]&mask[0],IP[1]&mask[1],IP[2]&mask[2],IP[3]&mask[3],domain);
267 fprintf(ConfFile
, "; Name servers\n");
268 fprintf(ConfFile
, "NAMESERVER %s\n", DNS
[0]);
269 fprintf(ConfFile
, "NAMESERVER %s\n", DNS
[1]);
272 sprintf(FileName
, "%s/static-routes", dokad
);
273 ConfFile
= fopen(FileName
, "w");
274 if (!ConfFile
) return 0;
275 fprintf(ConfFile
, "DEFAULT GATEWAY %s\n", gate
);
287 int WriteTCPPrefs(char* DestDir
);
298 void SetIP(char * w
);
299 void SetMask(char * w
);
300 void SetGate(char * w
);
301 void SetDNS(int m
, char * w
);
303 void SetInterf(char* w
);
304 void SetHost(char* w
);
305 void SetDomain(char* w
);