1 /* SmoothWall setup program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Misc. stuff for the lib.
20 /* This will rewrite /etc/hosts, /etc/hosts.*, and the apache ServerName file. */
21 int writehostsfiles(void)
23 char address
[STRING_SIZE
] = "";
24 char netaddress
[STRING_SIZE
] = "";
25 char netmask
[STRING_SIZE
] = "";
29 char hostname
[STRING_SIZE
];
30 char domainname
[STRING_SIZE
] = "";
31 char commandstring
[STRING_SIZE
];
32 char buffer
[STRING_SIZE
];
35 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
38 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
41 findkey(kv
, "GREEN_ADDRESS", address
);
42 findkey(kv
, "GREEN_NETADDRESS", netaddress
);
43 findkey(kv
, "GREEN_NETMASK", netmask
);
47 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/main/settings")))
50 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
53 strcpy(hostname
, SNAME
);
54 findkey(kv
, "HOSTNAME", hostname
);
55 findkey(kv
, "DOMAINNAME", domainname
);
58 if (!(file
= fopen(CONFIG_ROOT
"/main/hostname.conf", "w")))
60 sprintf (message
, ctr
[TR_UNABLE_TO_WRITE_VAR_SMOOTHWALL_MAIN_HOSTNAMECONF
], CONFIG_ROOT
);
64 fprintf(file
, "ServerName %s.%s\n", hostname
,domainname
);
67 if (!(file
= fopen(CONFIG_ROOT
"/main/hosts", "r")))
69 errorbox(ctr
[TR_UNABLE_TO_OPEN_HOSTS_FILE
]);
72 if (!(hosts
= fopen("/etc/hosts", "w")))
74 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_HOSTS
]);
77 fprintf(hosts
, "127.0.0.1\tlocalhost\n");
78 if (strlen(domainname
))
79 fprintf(hosts
, "%s\t%s.%s\t%s\n",address
,hostname
,domainname
,hostname
);
81 fprintf(hosts
, "%s\t%s\n",address
,hostname
);
82 while (fgets(buffer
, STRING_SIZE
, file
))
84 char *token
, *ip
, *host
, *domain
;
86 buffer
[strlen(buffer
) - 1] = 0;
88 token
= strtok(buffer
, ",");
90 ip
= strtok(NULL
, ",");
91 host
= strtok(NULL
, ",");
92 domain
= strtok(NULL
, ",");
97 if (strlen(ip
) < 7 || strlen(ip
) > 15
98 || strspn(ip
, "0123456789.") != strlen(ip
))
101 if (strspn(host
, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-") != strlen(host
))
105 fprintf(hosts
, "%s\t%s.%s\t%s\n",ip
,host
,domain
,host
);
107 fprintf(hosts
, "%s\t%s\n",ip
,host
);
112 /* TCP wrappers stuff. */
113 if (!(file
= fopen("/etc/hosts.deny", "w")))
115 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_HOSTS_DENY
]);
118 fprintf(file
, "ALL : ALL\n");
121 if (!(file
= fopen("/etc/hosts.allow", "w")))
123 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_HOSTS_ALLOW
]);
126 fprintf(file
, "sshd : ALL\n");
127 fprintf(file
, "ALL : localhost\n");
128 fprintf(file
, "ALL : %s/%s\n", netaddress
, netmask
);
131 sprintf(commandstring
, "/bin/hostname %s.%s", hostname
, domainname
);
132 if (mysystem(commandstring
))
134 errorbox(ctr
[TR_UNABLE_TO_SET_HOSTNAME
]);
143 char command
[STRING_SIZE
];
144 sprintf(command
, "/etc/rc.d/init.d/mISDN config");
145 if (runcommandwithstatus(command
, ctr
[TR_PROBING_ISDN
]))
146 errorbox(ctr
[TR_ERROR_PROBING_ISDN
]);
147 // Need to write some lines that count the cards and say the names...