]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/setup/misc.c
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.
13 #define _(x) dgettext("setup", x)
22 /* This will rewrite /etc/hosts, /etc/hosts.*, and the apache ServerName file. */
23 int writehostsfiles(void)
25 char address
[STRING_SIZE
] = "";
26 char netaddress
[STRING_SIZE
] = "";
27 char netmask
[STRING_SIZE
] = "";
31 char hostname
[STRING_SIZE
];
32 char domainname
[STRING_SIZE
] = "localdomain";
33 char commandstring
[STRING_SIZE
];
34 char buffer
[STRING_SIZE
];
37 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
40 errorbox(_("Unable to open settings file"));
43 findkey(kv
, "GREEN_ADDRESS", address
);
44 findkey(kv
, "GREEN_NETADDRESS", netaddress
);
45 findkey(kv
, "GREEN_NETMASK", netmask
);
49 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/main/settings")))
52 errorbox(_("Unable to open settings file"));
55 strcpy(hostname
, SNAME
);
56 findkey(kv
, "HOSTNAME", hostname
);
57 findkey(kv
, "DOMAINNAME", domainname
);
60 if (!(file
= fopen(CONFIG_ROOT
"/main/hostname.conf", "w")))
62 sprintf (message
, _("Unable to write %s/main/hostname.conf"), CONFIG_ROOT
);
66 fprintf(file
, "ServerName %s.%s\n", hostname
,domainname
);
69 if (!(file
= fopen(CONFIG_ROOT
"/main/hosts", "r")))
71 errorbox(_("Unable to open main hosts file."));
74 if (!(hosts
= fopen("/etc/hosts", "w")))
76 errorbox(_("Unable to write /etc/hosts."));
79 fprintf(hosts
, "127.0.0.1\tlocalhost\n");
80 if (strlen(domainname
))
81 fprintf(hosts
, "%s\t%s.%s\t%s\n",address
,hostname
,domainname
,hostname
);
83 fprintf(hosts
, "%s\t%s\n",address
,hostname
);
84 while (fgets(buffer
, STRING_SIZE
, file
))
86 char *token
, *ip
, *host
, *domain
;
88 buffer
[strlen(buffer
) - 1] = 0;
90 token
= strtok(buffer
, ",");
92 ip
= strtok(NULL
, ",");
93 host
= strtok(NULL
, ",");
94 domain
= strtok(NULL
, ",");
99 if (strlen(ip
) < 7 || strlen(ip
) > 15
100 || strspn(ip
, "0123456789.") != strlen(ip
))
103 if (strspn(host
, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-") != strlen(host
))
107 fprintf(hosts
, "%s\t%s.%s\t%s\n",ip
,host
,domain
,host
);
109 fprintf(hosts
, "%s\t%s\n",ip
,host
);
114 /* TCP wrappers stuff. */
115 if (!(file
= fopen("/etc/hosts.deny", "w")))
117 errorbox(_("Unable to write /etc/hosts.deny."));
120 fprintf(file
, "ALL : ALL\n");
123 if (!(file
= fopen("/etc/hosts.allow", "w")))
125 errorbox(_("Unable to write /etc/hosts.allow."));
128 fprintf(file
, "sshd : ALL\n");
129 fprintf(file
, "ALL : localhost\n");
130 fprintf(file
, "ALL : %s/%s\n", netaddress
, netmask
);
133 sprintf(commandstring
, "/bin/hostname %s.%s", hostname
, domainname
);
134 if (mysystem(NULL
, commandstring
))
136 errorbox(_("Unable to set hostname."));
145 char command
[STRING_SIZE
];
146 sprintf(command
, "/etc/rc.d/init.d/mISDN config");
147 if (runcommandwithstatus(command
, _("ISDN"), _("Scanning and configuring ISDN devices."), NULL
))
148 errorbox(_("Unable to scan for ISDN devices."));
149 // Need to write some lines that count the cards and say the names...