Skip to content

Commit

Permalink
More UI enhancements. Check IP when assigning to an epair.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Webb committed Feb 16, 2013
1 parent bb5bbe6 commit ee3fa4a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
14 changes: 9 additions & 5 deletions classes/Jail.php
Expand Up @@ -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)";

Expand Down
16 changes: 0 additions & 16 deletions classes/Network.php
Expand Up @@ -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}');

Expand Down
22 changes: 22 additions & 0 deletions classes/NetworkDevice.php
Expand Up @@ -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}');

Expand Down
2 changes: 1 addition & 1 deletion jailadmin.admin.inc
Expand Up @@ -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;
Expand Down
18 changes: 11 additions & 7 deletions jailnetwork.inc
Expand Up @@ -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'])) {
Expand Down
9 changes: 7 additions & 2 deletions jailstatus.inc
Expand Up @@ -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);
}
Expand Down

0 comments on commit ee3fa4a

Please sign in to comment.