1
1
/* GDHCPD, a GTK+ frontend for ISC DHCPD
2
* Copyright C 2004, 2005 Magnus Loef <magnus-swe@telia.com>
2
* Copyright C 2004, 2005, 2006 Magnus Loef <magnus-swe@telia.com>
4
4
* This program is free software; you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License as published by
25
25
#include "widgets.h"
26
26
#include "gettext.h"
27
27
#include "reread_conf.h"
29
extern char DHCPD_CONF_BUF[1024];
31
28
#include "allocate.h"
32
29
#include "show_info.h"
33
30
#include "clear_ptr_array.h"
34
31
#include "set_num_ranges.h"
35
32
#include "populate_ranges.h"
36
33
#include "populate_scope_settings.h"
39
void add_range(struct gdhcpd_widgets *widgets)
34
#include "failover_functions.h"
37
extern char global_netmask[1024];
38
extern char global_subnet[1024];
39
extern char global_nic[1024];
41
extern char DHCPD_CONF_BUF[1024];
45
void add_range(struct w *widgets)
52
int have_failover = 0;
55
gchar *range_line, *info;
47
56
G_CONST_RETURN gchar *range_from;
48
57
G_CONST_RETURN gchar *range_to;
59
/* Check if this is subnet has a failover declaration */
60
gchar *nic = g_strdup_printf("%s", global_nic);
61
gchar *subnet = g_strdup_printf("%s", global_subnet);
62
gchar *netmask = g_strdup_printf("%s", global_netmask);
64
have_failover = failover_exists(nic, subnet, netmask);
70
/* get the ranges from the entries */
50
71
range_from = gtk_entry_get_text(GTK_ENTRY(widgets->ranges_add_from_entry));
51
72
range_to = gtk_entry_get_text(GTK_ENTRY(widgets->ranges_add_to_entry));
53
74
if( strlen(range_from) < 7 )
55
info = g_strdup_printf(_("The range from IP-address is too short, range not added\n"));
76
info = g_strdup_printf(_("The range from IP-address is too short, the range was not added.\n"));
61
82
if( strlen(range_to) < 7 )
63
info = g_strdup_printf(_("The range to IP-address is too short, range not added\n"));
84
info = g_strdup_printf(_("The range to IP-address is too short, the range was not added.\n"));
75
96
if((fp=fopen(DHCPD_CONF_BUF, "r"))==NULL)
77
printf("Couldnt find: %s\n", DHCPD_CONF_BUF);
98
printf("Couldnt open dhcpd.conf here: %s\n", DHCPD_CONF_BUF);
80
101
fseek(fp, 0, SEEK_END);
81
102
conf_size = ftell(fp);
105
line = allocate(conf_size+1);
107
/* If this range already exists, dont add it */
108
range_line = g_strdup_printf("range %s %s;\n", range_from, range_to);
111
while(fgets(line, conf_size, fp)!=NULL)
113
if( ( strstr(line, scope_line1) || strstr(line, scope_line2)
114
|| strstr(line, scope_line3) ) && ! strstr(line, "#") )
116
while(fgets(line, conf_size, fp)!=NULL)
118
if( strstr(line, nic_line) && ! strstr(line, "#") )
128
while(fgets(line, conf_size, fp)!=NULL)
130
if( strstr(line, range_line) && ! strstr(line, "#") )
150
info = g_strdup_printf(_("The range already exists, the range was not added.\n"));
84
157
/* Widget range limited anti-overflow */
85
158
new_conf = allocate(conf_size+1024);
87
line = allocate(conf_size);
89
165
while(fgets(line, conf_size, fp)!=NULL)
91
167
if( ( strstr(line, scope_line1) || strstr(line, scope_line2)
96
172
while(fgets(line, conf_size, fp)!=NULL)
98
174
strcat(new_conf, line);
100
if( strstr(line, nic_line) && ! strstr(line, "#") )
176
/* Adds a new range after the interface line if its not a failover configuration */
177
if( strstr(line, nic_line) && ! have_failover && ! strstr(line, "#") )
103
180
/* Cosmetics and readability. */
104
181
strcat(new_conf, " range ");
105
182
strcat(new_conf, range_from);
108
185
strcat(new_conf, ";\n");
189
/* Adds a new range after the dynamic bootp line if its a failover configuration. */
190
if( strstr(line, "deny dynamic bootp clients") && have_failover && ! strstr(line, "#") )
193
/* Cosmetics and readability. */
194
strcat(new_conf, " range ");
195
strcat(new_conf, range_from);
196
strcat(new_conf, " ");
197
strcat(new_conf, range_to);
198
strcat(new_conf, ";\n");
114
204
strcat(new_conf, line);
121
if((fp=fopen(DHCPD_CONF_BUF, "w+"))==NULL)
123
printf("Couldnt find: %s\n", DHCPD_CONF_BUF);
135
208
g_free(scope_line1);
136
209
g_free(scope_line2);
137
210
g_free(scope_line3);
216
if((fp=fopen(DHCPD_CONF_BUF, "w+"))==NULL)
218
printf("Could not write dhcpd.conf here: %s\n", DHCPD_CONF_BUF);
139
228
if( range_added )