$attr_r) {
if (isset($_POST[$attribute])) {
$this_attribute = array();
if (is_array($_POST[$attribute])) {
$this_attribute['count'] = count($_POST[$attribute]);
foreach($_POST[$attribute] as $key => $value) {
$this_attribute[$key] = filter_var($value, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}
}
else {
$this_attribute['count'] = 1;
$this_attribute[0] = filter_var($_POST[$attribute], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}
$$attribute = $this_attribute;
}
if (!isset($$attribute) and isset($attr_r['default'])) {
$$attribute['count'] = 1;
$$attribute[0] = $attr_r['default'];
}
if (isset($$attribute)) {
$new_account_r[$attribute] = $$attribute;
unset($new_account_r[$attribute]['count']);
}
}
##
if (isset($_GET['account_request'])) {
$givenname[0]=filter_var($_GET['first_name'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$new_account_r['givenname'] = $givenname;
$givenname['count'] = 1;
$sn[0]=filter_var($_GET['last_name'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$new_account_r['sn'][0] = $sn;
$sn['count'] = 1;
$uid[0] = generate_username($givenname,$sn);
$new_account_r['uid'][0] = $uid;
$uid['count'] = 1;
if ($ENFORCE_SAFE_SYSTEM_NAMES == TRUE) {
$cn[0] = "$givenname$sn";
}
else {
$cn[0] = "$givenname $sn";
}
$new_account_r['cn'] = $cn;
$cn['count'] = 1;
$mail[0]=filter_var($_GET['email'], FILTER_SANITIZE_EMAIL);
if ($mail[0] == "") {
if (isset($EMAIL_DOMAIN)) {
$mail[0] = $uid . "@" . $EMAIL_DOMAIN;
$disabled_email_tickbox = FALSE;
}
}
else {
$disabled_email_tickbox = FALSE;
}
$new_account_r['mail'] = $mail;
$mail['count'] = 1;
}
if (isset($_POST['create_account'])) {
$password = $_POST['password'];
$new_account_r['password'][0] = $password;
$account_identifier = $new_account_r[$account_attribute][0];
$this_cn=$cn[0];
$this_mail=$mail[0];
$this_givenname=$givenname[0];
$this_sn=$sn[0];
$this_password=$password[0];
if (!isset($this_cn) or $this_cn == "") { $invalid_cn = TRUE; }
if ((!isset($account_identifier) or $account_identifier == "") and $invalid_cn != TRUE) { $invalid_account_identifier = TRUE; }
if ((!is_numeric($_POST['pass_score']) or $_POST['pass_score'] < 3) and $ACCEPT_WEAK_PASSWORDS != TRUE) { $weak_password = TRUE; }
if (isset($this_mail) and !is_valid_email($this_mail)) { $invalid_email = TRUE; }
if (preg_match("/\"|'/",$password)) { $invalid_password = TRUE; }
if ($password != $_POST['password_match']) { $mismatched_passwords = TRUE; }
if ($ENFORCE_SAFE_SYSTEM_NAMES == TRUE and !preg_match("/$USERNAME_REGEX/",$account_identifier)) { $invalid_account_identifier = TRUE; }
if (isset($_POST['send_email']) and isset($mail) and $EMAIL_SENDING_ENABLED == TRUE) { $send_user_email = TRUE; }
if ( isset($this_givenname)
and isset($this_sn)
and isset($this_password)
and !$mismatched_passwords
and !$weak_password
and !$invalid_password
and !$invalid_account_identifier
and !$invalid_cn
and !$invalid_email) {
$ldap_connection = open_ldap_connection();
$new_account = ldap_new_account($ldap_connection, $new_account_r);
if ($new_account) {
$creation_message = "The account was created.";
if (isset($send_user_email) and $send_user_email == TRUE) {
include_once "mail_functions.inc.php";
$mail_body = parse_mail_text($new_account_mail_body, $password, $account_identifier, $this_givenname, $this_sn);
$mail_subject = parse_mail_text($new_account_mail_subject, $password, $account_identifier, $this_givenname, $this_sn);
$sent_email = send_email($this_mail,"$this_givenname $this_sn",$mail_subject,$mail_body);
$creation_message = "The account was created";
if ($sent_email) {
$creation_message .= " and an email sent to $this_mail.";
}
else {
$creation_message .= " but unfortunately the email wasn't sent.
More information will be available in the logs.";
}
}
if ($admin_setup == TRUE) {
$member_add = ldap_add_member_to_group($ldap_connection, $LDAP['admins_group'], $account_identifier);
if (!$member_add) { ?>
Unfortunately adding it to the admin group failed.
Failed to create the account:
There were issues creating the account: