packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/groups.php
author Dan Fuhry <dan@fuhry.us>
Tue, 08 Jan 2013 23:21:25 -0500
changeset 2 700d61d93b1b
parent 0 3906ca745819
child 4 2212b2ded8bf
permissions -rw-r--r--
Fix accidentally hardcoded ldap basedn

<?php

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()
	));