Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More UI enhancements. Check IP when assigning to an epair.

  • Loading branch information...
commit ee3fa4abc2daefb4baeeb7f081ddedd2d682fe17 1 parent bb5bbe6
@lattera authored
View
14 classes/Jail.php
@@ -119,17 +119,21 @@ public function NetworkStatus() {
foreach ($this->network as $n) {
$status .= (strlen($status) ? ", " : "") . $n->device . " { ";
- if ($n->is_span)
+ $i= 0;
+ if ($n->is_span) {
+ $i++;
$status .= "(SPAN)";
+ }
if ($n->dhcp)
- $status .= " (DHCP), ";
+ $status .= ($i++ > 0 ? "," : "") . " (DHCP)";
if (!count($n->ips))
- $status .= " (NO STATIC IP)";
+ $status .= ($i++ > 0 ? "," : " ") . " (NO STATIC IP)";
- foreach ($n->ips as $ip)
- $status .= " {$ip}";
+ foreach ($n->ips as $ip) {
+ $status .= ($i++ > 0 ? "," : "") . " {$ip}";
+ }
$status .= ($n->IsOnline()) ? " (online)" : " (offline)";
View
16 classes/Network.php
@@ -51,22 +51,6 @@ public static function LoadFromRecord($record=array()) {
return $network;
}
- public static function IsIPAvailable($ip) {
- $result = db_query('SELECT ip FROM {jailadmin_bridge_aliases} WHERE CHAR_LENGTH(ip) > 0');
-
- foreach ($result as $record)
- if (!strcmp($record->ip, $ip))
- return FALSE;
-
- $result = db_query('SELECT ip FROM {jailadmin_epair_aliases} WHERE CHAR_LENGTH(ip) > 0');
-
- foreach ($result as $record)
- if (!strcmp($record->ip, $ip))
- return FALSE;
-
- return TRUE;
- }
-
public static function IsDeviceAvailable($device) {
$result = db_query('SELECT device FROM {jailadmin_bridges}');
View
22 classes/NetworkDevice.php
@@ -119,6 +119,28 @@ public static function IsDeviceAvailable($device) {
return TRUE;
}
+ public static function IsIPAvailable($ip) {
+ $result = db_select('jailadmin_epair_aliases', 'jea')
+ ->fields('jea', array('ip'))
+ ->condition('jea.ip', $ip)
+ ->execute();
+
+ foreach ($result as $record)
+ if ($record->ip == $ip)
+ return false;
+
+ $result = db_select('jailadmin_bridge_aliases', 'jba')
+ ->fields('jba', array('ip'))
+ ->condition('jba.ip', $ip)
+ ->execute();
+
+ foreach ($result as $record)
+ if ($record->ip == $ip)
+ return false;
+
+ return true;
+ }
+
public static function NextAvailableDevice() {
$result = db_query('SELECT device FROM {jailadmin_epairs}');
View
2  jailadmin.admin.inc
@@ -361,7 +361,7 @@ function jailadmin_admin_settings_network_submit($form, &$form_state) {
$network = Network::Load($form_state['values']['network']);
if (isset($form_state['values']['new_bridge_ip']) && strlen($form_state['values']['new_bridge_ip'])) {
- if (Network::IsIPAvailable($form_state['values']['new_bridge_ip']) == FALSE) {
+ if (NetworkDevice::IsIPAvailable($form_state['values']['new_bridge_ip']) == FALSE) {
form_set_error('new_bridge_ip', t('IP not available'));
$form_state['rebuild'] = TRUE;
return;
View
18 jailnetwork.inc
@@ -149,13 +149,17 @@ function jailadmin_config_network_submit($form, &$form_state) {
$new_ip = check_input($form_state, 'new_ip');
if ($new_ip !== FALSE && strlen($new_ip)) {
- db_insert('jailadmin_epair_aliases')
- ->fields(array(
- 'device' => $devicename,
- 'ip' => $new_ip,
- ))->execute();
-
- $form_state['input']['new_ip'] = '';
+ if (NetworkDevice::IsIPAvailable($new_ip) == false) {
+ drupal_set_message(t('@ip is already in use', array('@ip' => $new_ip)), 'error');
+ } else {
+ db_insert('jailadmin_epair_aliases')
+ ->fields(array(
+ 'device' => $devicename,
+ 'ip' => $new_ip,
+ ))->execute();
+
+ $form_state['input']['new_ip'] = '';
+ }
}
if (isset($form_state['values']['is_span'])) {
View
9 jailstatus.inc
@@ -26,8 +26,13 @@ function jailadmin_status($form, &$form_state) {
$action = l("Start", "jailadmin/{$jail->name}/start");
}
- if (user_access("config {$jail->name}"))
- $action .= (strlen($action) ? " | " : "") . l("Snapshot", "jailadmin/{$jail->name}/snapshot");
+ if (user_access("config {$jail->name}")) {
+ $network = l(t("Network Settings"), "jailadmin/{$jail->name}/network");
+
+ $action .= (strlen($action) ? " | " : "")
+ . l("Snapshot", "jailadmin/{$jail->name}/snapshot")
+ . " | {$network}";
+ }
$rows[] = array($name, $jail->IsOnlineString(), $jail->NetworkStatus(), $action);
}
Please sign in to comment.
Something went wrong with that request. Please try again.