Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
157 lines (136 sloc) 4.88 KB
<?php
require_once('classes/Jail.php');
require_once('classes/Network.php');
require_once('classes/NetworkDevice.php');
require_once('classes/Service.php');
require_once('classes/Mount.php');
/**
* Implements hook_permission().
*/
function jailadmin_permission() {
$jails = Jail::LoadAll();
$perms = array(
'administer jails' => array(
'title' => t('Administer FreeBSD Jail Admin'),
),
'start jails' => array(
'title' => t('Start/Stop jails'),
),
'view jails' => array(
'title' => t('View jails'),
),
'administer networks' => array(
'title' => t('Administer networks'),
),
);
foreach ($jails as $jail) {
$perms['config ' . $jail->name] = array(
'title' => t('Configure jail @jail', array('@jail' => $jail->name))
);
$perms['view ' . $jail->name . ' config'] = array(
'title' => t('View @jail\'s config', array('@jail' => $jail->name))
);
}
return $perms;
}
function jailadmin_menu() {
/* Admin settings */
$items['admin/config/jailadmin'] = array(
'title' => 'FreeBSD Jail Admin',
'description' => 'FreeBSD Jail Admin settings',
'position' => 'right',
'weight' => -5,
'page callback' => 'system_admin_menu_block_page',
'access callback' => 'jail_settings_access',
'access arguments' => array(array('administer jails', 'administer networks')),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/config/jailadmin/settings'] = array(
'title' => 'FreeBSD Jail Admin Settings',
'description' => 'Settings for FreeBSD Jail Admin',
'page callback' => 'drupal_get_form',
'page arguments' => array('jailadmin_admin_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer jails'),
'type' => MENU_NORMAL_ITEM,
'file' => 'jailadmin.admin.inc',
);
$items['admin/config/jailadmin/networks'] = array(
'title' => 'FreeBSD Jail Networks',
'description' => 'Networks for Jails',
'page callback' => 'drupal_get_form',
'page arguments' => array('jailadmin_admin_settings_network'),
'access callback' => 'user_access',
'access arguments' => array('administer networks'),
'type' => MENU_NORMAL_ITEM,
'file' => 'jailadmin.admin.inc',
);
/* Actions */
$items['jailadmin/status'] = array(
'title' => 'Jail Status',
'page callback' => 'drupal_get_form',
'page arguments' => array('jailadmin_status'),
'file' => 'jailstatus.inc',
'access callback' => 'user_access',
'access arguments' => array('view jails'),
'type' => MENU_NORMAL_ITEM,
);
$items['jailadmin/%/config'] = array(
'title' => 'Configure Jail',
'page callback' => 'drupal_get_form',
'page arguments' => array('jailadmin_config', 1),
'file' => 'jailconfig.inc',
'access callback' => 'jail_config_access',
'access arguments' => array(1),
'type' => MENU_NORMAL_ITEM,
);
$items['jailadmin/%/network'] = array(
'title' => 'Configure Jail Network',
'page callback' => 'drupal_get_form',
'page arguments' => array('jailadmin_config_network', 1),
'file' => 'jailnetwork.inc',
'access callback' => 'jail_config_access',
'access arguments' => array(1),
'type' => MENU_NORMAL_ITEM,
);
$items['jailadmin/%/start'] = array(
'title' => 'Start Jail',
'page callback' => 'drupal_get_form',
'page arguments' => array('jail_start', 1),
'file' => 'jailstatus.inc',
'access callback' => 'jail_config_access',
'access arguments' => array(1),
'type' => MENU_NORMAL_ITEM,
);
$items['jailadmin/%/stop'] = array(
'title' => 'Stop Jail',
'page callback' => 'drupal_get_form',
'page arguments' => array('jail_stop', 1),
'file' => 'jailstatus.inc',
'access callback' => 'jail_config_access',
'access arguments' => array(1),
'type' => MENU_NORMAL_ITEM,
);
$items['jailadmin/%/snapshot'] = array(
'title' => 'Snapshot Jail',
'page callback' => 'drupal_get_form',
'page arguments' => array('jail_snapshot', 1),
'file' => 'jailstatus.inc',
'access callback' => 'jail_config_access',
'access arguments' => array(1),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function jail_config_access($jail) {
if (user_access('view ' . $jail . ' config') || user_access('config ' . $jail))
return TRUE;
return FALSE;
}
function jail_settings_access($perms=array()) {
foreach($perms as $perm)
if (user_access($perm))
return TRUE;
return FALSE;
}
Jump to Line
Something went wrong with that request. Please try again.