Skip to content

Commit

Permalink
Show next available epair device
Browse files Browse the repository at this point in the history
  • Loading branch information
lattera committed Mar 1, 2012
1 parent 2129085 commit 87b48c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions classes/NetworkDevice.php
Expand Up @@ -89,6 +89,23 @@ public static function IsDeviceAvailable($device) {
return TRUE;
}

public static function NextAvailableDevice() {
$result = db_query('SELECT device FROM {jailadmin_epairs}');

$id = 0;
foreach ($result as $record) {
$i = substr($record->device, strlen("epair"));
if (intval($i) > $id)
$id = intval($i);
}

for (++$id; ; $id++)
if (NetworkDevice::IsDeviceAvailable("epair{$id}"))
break;

return $id;
}

public function Create() {
if (NetworkDevice::IsDeviceAvailable($this->device) == FALSE)
return FALSE;
Expand Down
2 changes: 1 addition & 1 deletion jailconfig.inc
Expand Up @@ -78,7 +78,7 @@ function jailadmin_config($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('New Device Name'),
'#size' => 60,
'#description' => t('e.g. epair0'),
'#description' => t('e.g. epair@device', array('@device' => NetworkDevice::NextAvailableDevice())),
'#disabled' => $jail->IsOnline() || $readonly,
);

Expand Down

0 comments on commit 87b48c1

Please sign in to comment.