packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/ajax.php
changeset 0 3906ca745819
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/ajax.php	Tue Jan 08 23:13:29 2013 -0500
@@ -0,0 +1,41 @@
+<?php
+
+require('includes/starthere.php');
+
+if ( !isset($_GET['op']) )
+	die();
+
+$result = false;
+switch($_GET['op'])
+{
+	case 'checkAvailability':
+		if ( !preg_match('/^[a-z0-9]{3,32}$/', $_GET['uid']) )
+		{
+			$result = 'Username contains invalid characters, or does not meet length requirement (3-32 characters).';
+			break;
+		}
+		$userinfo = ldap_get_user($_GET['uid']);
+		if ( !$userinfo )
+			$result = true;
+		else
+			$result = 'This username is already taken.';
+	case 'listUsers':
+		$result = ldap_list_users();
+		break;
+	case 'getGroup':
+		$result = ldap_get_group($_GET['gid']);
+		break;
+	case 'removeUserFromGroup':
+		$group = ldap_get_group($_GET['gid']);
+		if ( in_array($_GET['uid'], $group['memberUid']) )
+			$result = ldap_delete_group_member($_GET['gid'], $_GET['uid']);
+		break;
+	case 'addUserToGroup':
+		$group = ldap_get_group($_GET['gid']);
+		if ( $group && !in_array($_GET['uid'], $group['memberUid']) )
+			$result = ldap_add_group_member($_GET['gid'], $_GET['uid']);
+		break;
+}
+
+header('Content-type: text/javascript');
+echo json_encode($result);