Ironed out the last migration bugs (hopefully) with assistance from the EDB-robot.
This commit is contained in:
1 parent
1b6ebc3f56
commit
95f8e11663
7 files changed
+66
-25
No files matched your search
@@ -17,13 +17,12 @@ function update_user($username, $password) {
|
||||
$uid = getCurrentUser();
|
||||
|
||||
/* Update the current user's username and password */
|
||||
$sql = sprintf("UPDATE din_user SET user='%s', password=PASSWORD('%s') WHERE id=%s LIMIT 1",
|
||||
$sql = sprintf("UPDATE din_user SET username='%s', password=PASSWORD('%s') WHERE id=%s LIMIT 1",
|
||||
mysql_real_escape_string($username),
|
||||
mysql_real_escape_string($password),
|
||||
$uid);
|
||||
//$result = $conn->query($sql);
|
||||
return true;
|
||||
//return ! DB :: isError($result) and $ldap_updated;
|
||||
$result = $conn->query($sql);
|
||||
return ! DB :: isError($result);
|
||||
}
|
||||
function user_exists($username) {
|
||||
$conn = db_connect();
|
||||
@@ -76,8 +75,12 @@ function find_groups() {
|
||||
if(DB :: isError($result)) {
|
||||
return false;
|
||||
}
|
||||
$arr = array();
|
||||
foreach($result as $column => $group) {
|
||||
$arr[] = $group['posix_group'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $arr;
|
||||
}
|
||||
function enc_password($password, $key) {
|
||||
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
|
||||
|
||||
@@ -3,9 +3,9 @@ function init_validation() {
|
||||
rules: {
|
||||
username: {
|
||||
required: true,
|
||||
rangelength: [3, 15],
|
||||
rangelength: [3, 12],
|
||||
lettersonly: true,
|
||||
remote: "./migration/user_exists.php",
|
||||
remote: "./migration/username_available.php",
|
||||
},
|
||||
password: {
|
||||
required: true,
|
||||
@@ -17,6 +17,11 @@ function init_validation() {
|
||||
equalTo: "#id_password",
|
||||
},
|
||||
},
|
||||
messages: {
|
||||
username: {
|
||||
remote: 'Username is taken.',
|
||||
}
|
||||
},
|
||||
submitHandler: function(form) {
|
||||
var form_username = $("#id_username").val();
|
||||
var form_password = $("#id_password").val();
|
||||
@@ -46,7 +51,7 @@ function init_validation() {
|
||||
/* Output the errors (will never happend). */
|
||||
var output = '<div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">';
|
||||
for(var error in result.errors) {
|
||||
output += '<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span><strong>'+ error +':</strong> ' + result.errors[error][0] + '</p>';
|
||||
output += '<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span><strong>'+ error +':</strong> ' + result.errors[error] + '</p>';
|
||||
}
|
||||
output += '</div>';
|
||||
$("#infomodal").prepend(output);
|
||||
|
||||
@@ -39,4 +39,10 @@ function ldap_add_user($username, $firstname, $lastname, $email, $password, $gro
|
||||
$result = var_export(file_get_contents("http://brukerinfo.neuf.no/addNewUser.php?" . implode("&", $arr)), true);
|
||||
return $result;
|
||||
}
|
||||
function _log($str) {
|
||||
$time = date("[Y-m-d H:i:s.u]");
|
||||
file_put_contents("migration.log", $time .
|
||||
$str . "\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
[2011-08-11 18:11:21.000000]'Added cn=olivaqtest,ou=Groups,dc=neuf,dc=no
|
||||
Added uid=olivaqtest,ou=People,dc=neuf,dc=no
|
||||
Created home directory
|
||||
Added cn=olivaqtest,ou=auto.home,ou=Automount,dc=neuf,dc=no
|
||||
Created users kerberos credentials
|
||||
Could not add olivaqtest to cn=Array,ou=Groups,dc=neuf,dc=no
|
||||
Could not add olivaqtest to cn=Array,ou=Groups,dc=neuf,dc=no
|
||||
'
|
||||
[2011-08-11 18:37:45.000000]UPDATE din_user SET user='olivaqtesting', password=PASSWORD('hemmelig') WHERE id=1 LIMIT 1
|
||||
[2011-08-11 18:38:23.000000]UPDATE din_user SET user='olivaqtesting', password=PASSWORD('hemmelig') WHERE id=1 LIMIT 1
|
||||
[2011-08-11 18:38:23.000000][db_error: message="DB Error: no such field" code=-19 mode=return level=notice prefix="" info="UPDATE din_user SET user='olivaqtesting', password=PASSWORD('hemmelig') WHERE id=1 LIMIT 1 [nativecode=1054 ** Unknown column 'user' in 'field list']"]
|
||||
[2011-08-11 18:39:48.000000]UPDATE din_user SET username='olivaqtesting', password=PASSWORD('hemmelig') WHERE id=1 LIMIT 1
|
||||
[2011-08-11 18:47:48.000000]'Added cn=olivaqtestin,ou=Groups,dc=neuf,dc=no
|
||||
Added uid=olivaqtestin,ou=People,dc=neuf,dc=no
|
||||
Created home directory
|
||||
Added cn=olivaqtestin,ou=auto.home,ou=Automount,dc=neuf,dc=no
|
||||
Created users kerberos credentials
|
||||
Added olivaqtestin to cn=dns-alle,ou=Groups,dc=neuf,dc=no
|
||||
Added olivaqtestin to cn=dns-administrator,ou=Groups,dc=neuf,dc=no
|
||||
'
|
||||
@@ -9,14 +9,14 @@ if( !( isset($_POST['username']) || isset($_POST['password']) || isset($_POST['p
|
||||
/* Server side field validation */
|
||||
$errors = Array();
|
||||
/* Validate username */
|
||||
if( strlen($_POST['username']) < 3 && strlen($_POST['username']) > 15 ) {
|
||||
$result['errors']['username'][] = "Please enter a value between 3 and 15 characters long.";
|
||||
if( strlen($_POST['username']) < 3 && strlen($_POST['username']) > 12 ) {
|
||||
$result['errors']['username'][] = "Please enter a username between 3 and 12 characters long.";
|
||||
}
|
||||
if( !preg_match("/[a-z]/", $_POST['username']) ) {
|
||||
$result['errors']['username'][] = "Please enter only lowercase letters (english alphabet).";
|
||||
}
|
||||
if( file_get_contents("./user_exists.php") == "false" ) {
|
||||
$result['errors']['username'][] = "Username is taken.";
|
||||
if( file_get_contents("./username_available.php") == "false" ) {
|
||||
$result['errors']['username'][] = "Username taken.";
|
||||
}
|
||||
/* Validate password */
|
||||
if( strlen($_POST['password']) < 8 ) {
|
||||
@@ -38,11 +38,11 @@ if ( !isset($result) ) {
|
||||
/* migrated? */
|
||||
$migrated = ldap_add_user($_POST['username'], $user->firstname, $user->lastname, $user->email, $_POST['password'], $groups);
|
||||
/* Note: Assume success every time, but log result of migrated anyway. */
|
||||
/* TODO nikolark log $migrated. */
|
||||
_log($migrated);
|
||||
set_migrated();
|
||||
echo json_encode( Array('result' => 'success', 'groups' => $groups);
|
||||
echo json_encode( Array('result' => 'success', 'groups' => $groups) );
|
||||
} else {
|
||||
echo json_encode( Array('result' => 'error', 'errors' => Array('database' => 'User not update.')) );
|
||||
echo json_encode( Array('result' => 'error', 'errors' => Array('database' => 'User not migrated.')) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
require_once("inside_functions.php");
|
||||
|
||||
if ( user_exists($_GET['username']) ) {
|
||||
echo "true";
|
||||
}
|
||||
else {
|
||||
echo "false";
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once("inside_functions.php");
|
||||
|
||||
$user = new User(getCurrentUser());
|
||||
|
||||
$current_username = getCurrentUserName();
|
||||
|
||||
/* Check for username availability.
|
||||
* - You are the owner of the username (the logged in user).
|
||||
* - The username is not allready taken. */
|
||||
if ( ! user_exists($_GET['username']) || $_GET['username'] == $current_username) {
|
||||
echo "true";
|
||||
}
|
||||
else {
|
||||
echo "false";
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user