packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/groups.php
author Dan Fuhry <dan@fuhry.us>
Fri, 11 Jan 2013 05:41:41 -0500
changeset 4 2212b2ded8bf
parent 0 3906ca745819
permissions -rw-r--r--
Added OpenSSH public key support in LDAP

<?php

define('NEED_ADMIN', 1);
require('includes/starthere.php');

// POSTed actions
if ( !empty($_SERVER['PATH_INFO']) )
{
	$pi = explode('/', trim($_SERVER['PATH_INFO'], '/'));
	switch($pi[0])
	{
		case 'delete':
			if ( !isset($pi[1]) )
				break;
			
			$group =& $pi[1];
			
			if ( !ldap_get_group($group) )
			{
				break;
			}
			
			if ( delete_group($group) )
			{
				queue_message(E_NOTICE, "The group \"$group\" was deleted.");
			}
			else
			{
				queue_message(E_ERROR, "Failed to delete the group. Ensure that no users have it set as their primary group.");
			}
			
			break;
		case 'create':
			
			if ( empty($_POST) )
			{
				queue_message(E_ERROR, "Bad request");
				break;
			}
			
			if ( ldap_get_group($_POST['cn']) )
			{
				queue_message(E_ERROR, "This group already exists.");
				break;
			}
			
			if ( create_group($_POST['cn'], $_POST['description']) )
				queue_message(E_NOTICE, "The group \"{$_POST['cn']}\" was created.");
			else
				queue_message(E_ERROR, "Failed to create group");
			
			break;
	}
}

// list groups
$groups = ldap_list_groups();

// Present the UI
display_template('groups', array(
		'groups' => $groups
		, 'users_json' => json_encode(ldap_list_users())
		, 'next_gid' => get_next_available_gid()
	));