Project

General

Profile

Feature #1010 » permission-setting-for-captive-portal.patch

Erik Fonnesbeck, 11/29/2010 03:29 PM

View differences:

etc/inc/auth.inc
return true;
}
function user_with_privilege_exists($privid) {
global $config;
if (is_array($config['system']['user']))
foreach ($config['system']['user'] as $userent)
if (userHasPrivilege($userent, $privid))
return true;
return false;
}
function group_with_privilege_exists($privid) {
global $config;
if (is_array($config['system']['group']))
foreach ($config['system']['group'] as $groupent)
if (is_array($groupent['priv']))
if (in_array($privid, $groupent['priv']))
return true;
return false;
}
function local_backed($username, $passwd) {
$user = getUserEntry($username);
etc/inc/globals.inc
"disablehelpmenu" => false,
"disablehelpicon" => false,
"debug" => false,
"latest_config" => "7.5",
"latest_config" => "7.6",
"nopkg_platforms" => array("cdrom"),
"minimum_ram_warning" => "105",
"minimum_ram_warning_text" => "128 MB",
etc/inc/priv/user.priv.inc
global $priv_list;
$priv_list['user-services-captiveportal-login'] = array();
$priv_list['user-services-captiveportal-login']['name'] = gettext("User - Services - Captive portal login");
$priv_list['user-services-captiveportal-login']['descr'] = gettext("Indicates whether the user is able to login on ".
"the captive portal.");
$priv_list['user-shell-access'] = array();
$priv_list['user-shell-access']['name'] = "User - System - Shell account access";
$priv_list['user-shell-access']['descr'] = "Indicates whether the user is able to login for ".
etc/inc/upgrade_config.inc
$config['system']['user'] = array();
/* migrate captivate portal to user manager */
if (is_array($config['captiveportal']['user'])) {
$config['cpusernames_temp'] = array();
foreach($config['captiveportal']['user'] as $user) {
// avoid user conflicts
$found = false;
......
}
$user['uid'] = $config['system']['nextuid']++;
$config['system']['user'][] = $user;
$config['cpusernames_temp'][] = $user['name'];
}
unset($config['captiveportal']['user']);
}
......
rename_field($config['crl'], 'name', 'descr');
}
function upgrade_075_to_076() {
global $config;
if (!isset($config['captiveportal']['enable']) && !isset($config['cpusernames_temp']))
return;
$cpusers = array();
$cpusers['name'] = "cpusers";
// Search for a group name that doesn't conflict, in case cpusers already exists
if (is_array($config['system']['group'])) {
do {
$found = false;
foreach ($config['system']['group'] as $groupent)
if ($groupent['name'] == $cpusers['name']) {
$found = true;
$cpusers['name'] = "cpusers" . (substr($cpusers['name'], 7) + 1);
break;
}
} while ($found);
} else
$config['system']['group'] = array();
$cpusers['description'] = gettext("Captive Portal Users");
$cpusers['gid'] = $config['system']['nextgid']++;
$cpusers['priv'] = array("user-services-captiveportal-login");
$cpusers['member'] = array();
if (is_array($config['system']['user'])) {
if (isset($config['cpusernames_temp'])) {
foreach ($config['system']['user'] as $userent)
if (in_array($userent['name'], $config['cpusernames_temp']))
$cpusers['member'][] = $userent['uid'];
} else {
foreach ($config['system']['user'] as $userent)
if ($userent['uid'] != 0)
$cpusers['member'][] = $userent['uid'];
}
}
if (isset($config['cpusernames_temp']))
unset($config['cpusernames_temp']);
if (empty($cpusers['member']))
unset($cpusers['member']);
$config['system']['group'][] = $cpusers;
}
?>
usr/local/captiveportal/index.php
//check against local user manager
$loginok = local_backed($_POST['auth_user'], $_POST['auth_pass']);
if ($loginok)
if (!userHasPrivilege(getUserEntry($_POST['auth_user']), "user-services-captiveportal-login"))
$loginok = false;
if ($loginok){
captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"LOGIN");
portal_allow($clientip, $clientmac,$_POST['auth_user']);
usr/local/www/services_captiveportal.php
$config['captiveportal']['passthrumacaddusername'] = $_POST['passthrumacaddusername'] ? true : false;
$config['captiveportal']['radmac_format'] = $_POST['radmac_format'] ? $_POST['radmac_format'] : false;
if ($_POST['enable']) {
// Add a cpusers group if the captive portal login privilege has not been assigned to an existing group or user
if (!group_with_privilege_exists("user-services-captiveportal-login") && !user_with_privilege_exists("user-services-captiveportal-login")) {
$cpusers = array();
$cpusers['name'] = "cpusers";
// Search for a group name that doesn't conflict, in case cpusers already exists
if (is_array($config['system']['group'])) {
do {
$found = false;
foreach ($config['system']['group'] as $groupent)
if ($groupent['name'] == $cpusers['name']) {
$found = true;
$cpusers['name'] = "cpusers" . (substr($cpusers['name'], 7) + 1);
break;
}
} while ($found);
} else
$config['system']['group'] = array();
$cpusers['description'] = gettext("Captive Portal Users");
$cpusers['gid'] = $config['system']['nextgid']++;
$cpusers['priv'] = array("user-services-captiveportal-login");
$config['system']['group'][] = $cpusers;
local_group_set($cpusers);
}
}
/* file upload? */
if (is_uploaded_file($_FILES['htmlfile']['tmp_name']))
$config['captiveportal']['page']['htmltext'] = base64_encode(file_get_contents($_FILES['htmlfile']['tmp_name']));
......
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><span class="vexpl"><span class="red"><strong><?=gettext("Note:"); ?></strong></span><br>
<?=gettext("When using the local user manager for authentication, only users with the Captive Portal Login privilege are allowed access. This may be given by adding the user to a Captive Portal Users group that has the privilege or by assigning the privilege directly."); ?></span></td>
</tr><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
(1-1/2)