@@ -80,86 +80,162 @@ function update($event_name,$data) {
8080 $ server_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'server ' );
8181
8282 // Configure the debian network card settings
83- if (is_file ('/etc/debian_version ' ) && $ server_config ['auto_network_configuration ' ] == 'y ' ) {
84- copy ('/etc/network/interfaces ' ,'/etc/network/interfaces~ ' );
83+ if ($ server_config ['auto_network_configuration ' ] == 'y ' ) {
8584
86- $ app ->load ('tpl ' );
85+ if (is_file ('/etc/debian_version ' ))
86+ {
87+ copy ('/etc/network/interfaces ' ,'/etc/network/interfaces~ ' );
8788
88- $ network_tpl = new tpl ();
89- $ network_tpl ->newTemplate ("debian_network_interfaces.master " );
89+ $ app ->load ('tpl ' );
9090
91- $ network_tpl ->setVar ('ip_address ' ,$ server_config ["ip_address " ]);
92- $ network_tpl ->setVar ('netmask ' ,$ server_config ["netmask " ]);
93- $ network_tpl ->setVar ('gateway ' ,$ server_config ["gateway " ]);
94- $ network_tpl ->setVar ('broadcast ' ,$ this ->broadcast ($ server_config ["ip_address " ],$ server_config ["netmask " ]));
95- $ network_tpl ->setVar ('network ' ,$ this ->network ($ server_config ["ip_address " ],$ server_config ["netmask " ]));
96-
97- $ records = $ app ->db ->queryAllRecords ("SELECT ip_address FROM server_ip WHERE server_id = " .intval ($ conf ["server_id " ]) . " order by ip_address " );
98- $ ip_records = array ();
99- $ additionl_ip_records = 0 ;
100- $ n = 0 ;
101- if (is_array ($ records )) {
102- foreach ($ records as $ rec ) {
103- /*
104- * don't insert the main-ip again!
105- */
106- if ($ rec ['ip_address ' ] != $ server_config ["ip_address " ])
107- {
108- $ ip_records [$ n ] = array (
109- 'id ' => $ n ,
110- 'ip_address ' => $ rec ['ip_address ' ],
111- 'netmask ' => $ server_config ["netmask " ],
112- 'gateway ' => $ server_config ["gateway " ],
113- 'broadcast ' => $ this ->broadcast ($ rec ['ip_address ' ],$ server_config ["netmask " ]),
114- 'network ' => $ this ->network ($ rec ['ip_address ' ],$ server_config ["netmask " ])
115- );
116- $ additionl_ip_records = 1 ;
117- $ n ++;
91+ $ network_tpl = new tpl ();
92+ $ network_tpl ->newTemplate ("debian_network_interfaces.master " );
93+
94+ $ network_tpl ->setVar ('ip_address ' ,$ server_config ["ip_address " ]);
95+ $ network_tpl ->setVar ('netmask ' ,$ server_config ["netmask " ]);
96+ $ network_tpl ->setVar ('gateway ' ,$ server_config ["gateway " ]);
97+ $ network_tpl ->setVar ('broadcast ' ,$ this ->broadcast ($ server_config ["ip_address " ],$ server_config ["netmask " ]));
98+ $ network_tpl ->setVar ('network ' ,$ this ->network ($ server_config ["ip_address " ],$ server_config ["netmask " ]));
99+
100+ $ records = $ app ->db ->queryAllRecords ("SELECT ip_address FROM server_ip WHERE server_id = " .intval ($ conf ["server_id " ]) . " order by ip_address " );
101+ $ ip_records = array ();
102+ $ additionl_ip_records = 0 ;
103+ $ n = 0 ;
104+ if (is_array ($ records )) {
105+ foreach ($ records as $ rec ) {
106+ /*
107+ * don't insert the main-ip again!
108+ */
109+ if ($ rec ['ip_address ' ] != $ server_config ["ip_address " ])
110+ {
111+ $ ip_records [$ n ] = array (
112+ 'id ' => $ n ,
113+ 'ip_address ' => $ rec ['ip_address ' ],
114+ 'netmask ' => $ server_config ["netmask " ],
115+ 'gateway ' => $ server_config ["gateway " ],
116+ 'broadcast ' => $ this ->broadcast ($ rec ['ip_address ' ],$ server_config ["netmask " ]),
117+ 'network ' => $ this ->network ($ rec ['ip_address ' ],$ server_config ["netmask " ])
118+ );
119+ $ additionl_ip_records = 1 ;
120+ $ n ++;
121+ }
118122 }
119123 }
120- }
121-
122- /*
123- * If we have more than 1 IP we have to add the main-ip at the end
124- * of the network-ip-list. If we don't do so, there may be problems
125- * in multi-server-settings (with the acces from other server to the
126- * main-server) because the LAST IP in the list is the IP mysql uses
127- * to determine the host, the user is logging in from.
128- */
129- if ($ additionl_ip_records != 0 )
124+
125+ /*
126+ * If we have more than 1 IP we have to add the main-ip at the end
127+ * of the network-ip-list. If we don't do so, there may be problems
128+ * in multi-server-settings (with the acces from other server to the
129+ * main-server) because the LAST IP in the list is the IP mysql uses
130+ * to determine the host, the user is logging in from.
131+ */
132+ if ($ additionl_ip_records != 0 )
133+ {
134+ $ swap ["ip_address " ] = $ ip_records [$ n -1 ]["ip_address " ];
135+ $ swap ["netmask " ] = $ ip_records [$ n -1 ]["netmask " ];
136+ $ swap ["gateway " ] = $ ip_records [$ n -1 ]["gateway " ];
137+
138+ $ ip_records [$ n -1 ] = array (
139+ 'id ' => $ n -1 ,
140+ 'ip_address ' => $ server_config ['ip_address ' ],
141+ 'netmask ' => $ server_config ["netmask " ],
142+ 'gateway ' => $ server_config ["gateway " ],
143+ 'broadcast ' => $ this ->broadcast ($ server_config ['ip_address ' ],$ server_config ["netmask " ]),
144+ 'network ' => $ this ->network ($ server_config ['ip_address ' ],$ server_config ["netmask " ])
145+ );
146+ $ network_tpl ->setVar ('ip_address ' ,$ swap ["ip_address " ]);
147+ $ network_tpl ->setVar ('netmask ' ,$ swap ["netmask " ]);
148+ $ network_tpl ->setVar ('gateway ' ,$ swap ["gateway " ]);
149+ $ network_tpl ->setVar ('broadcast ' ,$ this ->broadcast ($ swap ["ip_address " ],$ swap ["netmask " ]));
150+ $ network_tpl ->setVar ('network ' ,$ this ->network ($ swap ["ip_address " ],$ swap ["netmask " ]));
151+ }
152+
153+ $ network_tpl ->setVar ('additionl_ip_records ' ,$ additionl_ip_records );
154+ $ network_tpl ->setLoop ('interfaces ' ,$ ip_records );
155+ file_put_contents ('/etc/network/interfaces ' ,$ network_tpl ->grab ());
156+ unset($ network_tpl );
157+
158+ $ app ->log ("Changed Network settings " ,LOGLEVEL_DEBUG );
159+ exec ('/etc/init.d/networking force-reload ' );
160+ }
161+ elseif (is_file ('/etc/gentoo-release ' ))
130162 {
131- $ swap ["ip_address " ] = $ ip_records [$ n -1 ]["ip_address " ];
132- $ swap ["netmask " ] = $ ip_records [$ n -1 ]["netmask " ];
133- $ swap ["gateway " ] = $ ip_records [$ n -1 ]["gateway " ];
163+ copy ('/etc/conf.d/net ' ,'/etc/conf.d/net~ ' );
164+
165+ $ app ->load ('tpl ' );
166+
167+ $ network_tpl = new tpl ();
168+ $ network_tpl ->newTemplate ("gentoo_network_interfaces.master " );
134169
135- $ ip_records [$ n -1 ] = array (
136- 'id ' => $ n -1 ,
137- 'ip_address ' => $ server_config ['ip_address ' ],
138- 'netmask ' => $ server_config ["netmask " ],
139- 'gateway ' => $ server_config ["gateway " ],
140- 'broadcast ' => $ this ->broadcast ($ server_config ['ip_address ' ],$ server_config ["netmask " ]),
141- 'network ' => $ this ->network ($ server_config ['ip_address ' ],$ server_config ["netmask " ])
142- );
143- $ network_tpl ->setVar ('ip_address ' ,$ swap ["ip_address " ]);
144- $ network_tpl ->setVar ('netmask ' ,$ swap ["netmask " ]);
145- $ network_tpl ->setVar ('gateway ' ,$ swap ["gateway " ]);
146- $ network_tpl ->setVar ('broadcast ' ,$ this ->broadcast ($ swap ["ip_address " ],$ swap ["netmask " ]));
147- $ network_tpl ->setVar ('network ' ,$ this ->network ($ swap ["ip_address " ],$ swap ["netmask " ]));
170+ $ network_tpl ->setVar ('ip_address ' ,$ server_config ["ip_address " ]);
171+ $ network_tpl ->setVar ('netmask ' ,$ server_config ["netmask " ]);
172+ $ network_tpl ->setVar ('gateway ' ,$ server_config ["gateway " ]);
173+ $ network_tpl ->setVar ('broadcast ' ,$ this ->broadcast ($ server_config ["ip_address " ],$ server_config ["netmask " ]));
174+
175+ $ records = $ app ->db ->queryAllRecords ("SELECT ip_address FROM server_ip WHERE server_id = " .intval ($ conf ["server_id " ]) . " order by ip_address " );
176+ $ ip_records = array ();
177+ $ additionl_ip_records = 0 ;
178+ $ n = 0 ;
179+ if (is_array ($ records )) {
180+ foreach ($ records as $ rec ) {
181+ /*
182+ * don't insert the main-ip again!
183+ */
184+ if ($ rec ['ip_address ' ] != $ server_config ["ip_address " ])
185+ {
186+ $ ip_records [$ n ] = array (
187+ 'id ' => $ n ,
188+ 'ip_address ' => $ rec ['ip_address ' ],
189+ 'netmask ' => $ server_config ["netmask " ],
190+ 'gateway ' => $ server_config ["gateway " ],
191+ 'broadcast ' => $ this ->broadcast ($ rec ['ip_address ' ],$ server_config ["netmask " ])
192+ );
193+ $ additionl_ip_records = 1 ;
194+ $ n ++;
195+ }
196+ }
197+ }
198+
199+ /*
200+ * If we have more than 1 IP we have to add the main-ip at the end
201+ * of the network-ip-list. If we don't do so, there may be problems
202+ * in multi-server-settings (with the acces from other server to the
203+ * main-server) because the LAST IP in the list is the IP mysql uses
204+ * to determine the host, the user is logging in from.
205+ */
206+ if ($ additionl_ip_records != 0 )
207+ {
208+ $ swap ["ip_address " ] = $ ip_records [$ n -1 ]["ip_address " ];
209+ $ swap ["netmask " ] = $ ip_records [$ n -1 ]["netmask " ];
210+ $ swap ["gateway " ] = $ ip_records [$ n -1 ]["gateway " ];
211+
212+ $ ip_records [$ n -1 ] = array (
213+ 'id ' => $ n -1 ,
214+ 'ip_address ' => $ server_config ['ip_address ' ],
215+ 'netmask ' => $ server_config ["netmask " ],
216+ 'gateway ' => $ server_config ["gateway " ],
217+ 'broadcast ' => $ this ->broadcast ($ server_config ['ip_address ' ],$ server_config ["netmask " ])
218+ );
219+ $ network_tpl ->setVar ('ip_address ' ,$ swap ["ip_address " ]);
220+ $ network_tpl ->setVar ('netmask ' ,$ swap ["netmask " ]);
221+ $ network_tpl ->setVar ('gateway ' ,$ swap ["gateway " ]);
222+ $ network_tpl ->setVar ('broadcast ' ,$ this ->broadcast ($ swap ["ip_address " ],$ swap ["netmask " ]));
223+ }
224+
225+ $ network_tpl ->setVar ('additionl_ip_records ' ,$ additionl_ip_records );
226+ $ network_tpl ->setLoop ('interfaces ' ,$ ip_records );
227+ file_put_contents ('/etc/conf.d/net ' ,$ network_tpl ->grab ());
228+ unset($ network_tpl );
229+
230+ $ app ->log ("Changed Network settings " ,LOGLEVEL_DEBUG );
231+ exec ('/etc/init.d/net.eth0 restart ' );
232+ }
233+ else {
234+ $ app ->log ("Network configuration not available for this linux distribution. " ,LOGLEVEL_DEBUG );
148235 }
149236
150- $ network_tpl ->setVar ('additionl_ip_records ' ,$ additionl_ip_records );
151- $ network_tpl ->setLoop ('interfaces ' ,$ ip_records );
152- file_put_contents ('/etc/network/interfaces ' ,$ network_tpl ->grab ());
153- unset($ network_tpl );
154-
155- $ app ->log ("Changed Network settings " ,LOGLEVEL_DEBUG );
156- exec ('/etc/init.d/networking force-reload ' );
157237 } else {
158- if (is_file ('/etc/debian_version ' )) {
159- $ app ->log ("Network configuration disabled in server settings. " ,LOGLEVEL_WARN );
160- } else {
161- $ app ->log ("Network configuration not available for this linux distribution. " ,LOGLEVEL_DEBUG );
162- }
238+ $ app ->log ("Network configuration disabled in server settings. " ,LOGLEVEL_WARN );
163239 }
164240
165241 }
0 commit comments