|
|
|
@ -84,17 +84,32 @@ class UsersController extends AppController {
|
|
|
|
|
throw new NotFoundException('Something went wrong. Your user account could not be accessed.');
|
|
|
|
|
}
|
|
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
|
|
|
|
// What fields should be saved (allowed to be saved)
|
|
|
|
|
$fieldList = array('email', 'autoalert', 'gpgkey', 'certif_public', 'nids_sid', 'contactalert', 'disabled');
|
|
|
|
|
if ("" != $this->request->data['User']['password'])
|
|
|
|
|
$fieldList[] = 'password';
|
|
|
|
|
// Save the data
|
|
|
|
|
if ($this->User->save($this->request->data, true ,$fieldList)) {
|
|
|
|
|
$this->Session->setFlash(__('The profile has been updated'));
|
|
|
|
|
$this->_refreshAuth();
|
|
|
|
|
$this->redirect(array('action' => 'view', $id));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The profile could not be updated. Please, try again.'));
|
|
|
|
|
if (!$this->_isRest()) {
|
|
|
|
|
if (!empty($this->request->data['User']['current_password'])) {
|
|
|
|
|
$hashed = $this->User->verifyPassword($this->Auth->user('id'), $this->request->data['User']['current_password']);
|
|
|
|
|
if (!$hashed) {
|
|
|
|
|
$abortPost = true;
|
|
|
|
|
$this->Session->setFlash('Invalid password. Please enter your current password to continue.');
|
|
|
|
|
}
|
|
|
|
|
unset($this->request->data['User']['current_password']);
|
|
|
|
|
} else {
|
|
|
|
|
$abortPost = true;
|
|
|
|
|
$this->Session->setFlash('Please enter your current password to continue.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!$abortPost) {
|
|
|
|
|
// What fields should be saved (allowed to be saved)
|
|
|
|
|
$fieldList = array('email', 'autoalert', 'gpgkey', 'certif_public', 'nids_sid', 'contactalert', 'disabled');
|
|
|
|
|
if ("" != $this->request->data['User']['password'])
|
|
|
|
|
$fieldList[] = 'password';
|
|
|
|
|
// Save the data
|
|
|
|
|
if ($this->User->save($this->request->data, true ,$fieldList)) {
|
|
|
|
|
$this->Session->setFlash(__('The profile has been updated'));
|
|
|
|
|
$this->_refreshAuth();
|
|
|
|
|
$this->redirect(array('action' => 'view', $id));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The profile could not be updated. Please, try again.'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->User->set('password', '');
|
|
|
|
@ -110,31 +125,47 @@ class UsersController extends AppController {
|
|
|
|
|
|
|
|
|
|
public function change_pw() {
|
|
|
|
|
$id = $this->Auth->user('id');
|
|
|
|
|
$this->User->id = $id;
|
|
|
|
|
$user = $this->User->find('first', array(
|
|
|
|
|
'conditions' => array('User.id' => $id),
|
|
|
|
|
'recursive' => -1
|
|
|
|
|
));
|
|
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
|
|
|
|
// What fields should be saved (allowed to be saved)
|
|
|
|
|
$fieldList[] = 'password';
|
|
|
|
|
// Save the data
|
|
|
|
|
if ($this->User->save($this->request->data, true ,$fieldList)) {
|
|
|
|
|
$this->Session->setFlash(__('Password Changed.'));
|
|
|
|
|
$this->User->saveField('email', $this->Auth->user('email'));
|
|
|
|
|
$this->User->saveField('change_pw', 0);
|
|
|
|
|
$this->_refreshAuth();
|
|
|
|
|
$this->redirect(array('action' => 'view', $id));
|
|
|
|
|
$abortPost = false;
|
|
|
|
|
if (!empty($this->request->data['User']['current_password'])) {
|
|
|
|
|
$hashed = $this->User->verifyPassword($this->Auth->user('id'), $this->request->data['User']['current_password']);
|
|
|
|
|
if (!$hashed) {
|
|
|
|
|
$abortPost = true;
|
|
|
|
|
$this->Session->setFlash('Invalid password. Please enter your current password to continue.');
|
|
|
|
|
}
|
|
|
|
|
unset($this->request->data['User']['current_password']);
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The password could not be updated. Please, try again.'));
|
|
|
|
|
$abortPost = true;
|
|
|
|
|
$this->Session->setFlash('Please enter your current password to continue.');
|
|
|
|
|
}
|
|
|
|
|
if (!$abortPost) {
|
|
|
|
|
// What fields should be saved (allowed to be saved)
|
|
|
|
|
$user['User']['change_pw'] = 0;
|
|
|
|
|
$user['User']['password'] = $this->request->data['User']['password'];
|
|
|
|
|
$user['User']['confirm_password'] = $this->request->data['User']['confirm_password'];
|
|
|
|
|
$temp = $user['User']['password'];
|
|
|
|
|
// Save the data
|
|
|
|
|
if ($this->User->save($user)) {
|
|
|
|
|
$this->Session->setFlash(__('Password Changed.'));
|
|
|
|
|
$this->_refreshAuth();
|
|
|
|
|
$this->__extralog("change_pw");
|
|
|
|
|
$this->redirect(array('action' => 'view', $id));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The password could not be updated. Make sure you meet the minimum password length / complexity requirements.'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->loadModel('Server');
|
|
|
|
|
$this->set('complexity', !empty(Configure::read('Security.password_policy_complexity')) ? Configure::read('Security.password_policy_complexity') : $this->Server->serverSettings['Security']['password_policy_complexity']['value']);
|
|
|
|
|
$this->set('length', !empty(Configure::read('Security.password_policy_length')) ? Configure::read('Security.password_policy_length') : $this->Server->serverSettings['Security']['password_policy_length']['value']);
|
|
|
|
|
$this->User->recursive = 0;
|
|
|
|
|
$this->User->read(null, $id);
|
|
|
|
|
$this->User->set('password', '');
|
|
|
|
|
$this->request->data = $this->User->data;
|
|
|
|
|
}
|
|
|
|
|
// XXX ACL roles
|
|
|
|
|
$this->__extralog("change_pw");
|
|
|
|
|
$this->loadModel('Server');
|
|
|
|
|
$this->set('complexity', !empty(Configure::read('Security.password_policy_complexity')) ? Configure::read('Security.password_policy_complexity') : $this->Server->serverSettings['Security']['password_policy_complexity']['value']);
|
|
|
|
|
$this->set('length', !empty(Configure::read('Security.password_policy_length')) ? Configure::read('Security.password_policy_length') : $this->Server->serverSettings['Security']['password_policy_length']['value']);
|
|
|
|
|
$this->User->recursive = 0;
|
|
|
|
|
$this->User->read(null, $id);
|
|
|
|
|
$this->User->set('password', '');
|
|
|
|
|
$this->request->data = $this->User->data;
|
|
|
|
|
$roles = $this->User->Role->find('list');
|
|
|
|
|
$this->set(compact('roles'));
|
|
|
|
|
}
|
|
|
|
@ -512,105 +543,121 @@ class UsersController extends AppController {
|
|
|
|
|
if (!isset($this->request->data['User'])) {
|
|
|
|
|
$this->request->data['User'] = $this->request->data;
|
|
|
|
|
}
|
|
|
|
|
$this->request->data['User']['id'] = $id;
|
|
|
|
|
if (!isset($this->request->data['User']['email'])) {
|
|
|
|
|
$this->request->data['User']['email'] = $userToEdit['User']['email'];
|
|
|
|
|
}
|
|
|
|
|
if (isset($this->request->data['User']['role_id']) && !array_key_exists($this->request->data['User']['role_id'], $syncRoles)) $this->request->data['User']['server_id'] = 0;
|
|
|
|
|
$fields = array();
|
|
|
|
|
$blockedFields = array('id', 'invited_by');
|
|
|
|
|
if (!$this->_isSiteAdmin()) {
|
|
|
|
|
$blockedFields[] = 'org_id';
|
|
|
|
|
}
|
|
|
|
|
foreach (array_keys($this->request->data['User']) as $field) {
|
|
|
|
|
if (in_array($field, $blockedFields)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ($field != 'password') array_push($fields, $field);
|
|
|
|
|
}
|
|
|
|
|
// TODO Audit, __extralog, fields get orig
|
|
|
|
|
$fieldsOldValues = array();
|
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
|
if ($field == 'enable_password') continue;
|
|
|
|
|
if ($field != 'confirm_password') array_push($fieldsOldValues, $this->User->field($field));
|
|
|
|
|
else array_push($fieldsOldValues, $this->User->field('password'));
|
|
|
|
|
}
|
|
|
|
|
// TODO Audit, __extralog, fields get orig END
|
|
|
|
|
if (
|
|
|
|
|
isset($this->request->data['User']['enable_password']) && $this->request->data['User']['enable_password'] != '0' &&
|
|
|
|
|
isset($this->request->data['User']['password']) && "" != $this->request->data['User']['password']
|
|
|
|
|
) {
|
|
|
|
|
$fields[] = 'password';
|
|
|
|
|
if ($this->_isRest() && !isset($this->request->data['User']['confirm_password'])) {
|
|
|
|
|
$this->request->data['User']['confirm_password'] = $this->request->data['User']['password'];
|
|
|
|
|
$fields[] = 'confirm_password';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$abortPost = false;
|
|
|
|
|
if (!$this->_isRest()) {
|
|
|
|
|
$fields[] = 'role_id';
|
|
|
|
|
}
|
|
|
|
|
if (!$this->_isSiteAdmin()) {
|
|
|
|
|
$this->loadModel('Role');
|
|
|
|
|
$this->Role->recursive = -1;
|
|
|
|
|
$chosenRole = $this->Role->findById($this->request->data['User']['role_id']);
|
|
|
|
|
if (empty($chosenRole) || (($chosenRole['Role']['id'] != $allowedRole) && ($chosenRole['Role']['perm_site_admin'] == 1 || $chosenRole['Role']['perm_regexp_access'] == 1 || $chosenRole['Role']['perm_sync'] == 1))) {
|
|
|
|
|
throw new Exception('You are not authorised to assign that role to a user.');
|
|
|
|
|
if (!empty($this->request->data['User']['current_password'])) {
|
|
|
|
|
$hashed = $this->User->verifyPassword($this->Auth->user('id'), $this->request->data['User']['current_password']);
|
|
|
|
|
if (!$hashed) {
|
|
|
|
|
$abortPost = true;
|
|
|
|
|
$this->Session->setFlash('Invalid password. Please enter your current password to continue.');
|
|
|
|
|
}
|
|
|
|
|
unset($this->request->data['User']['current_password']);
|
|
|
|
|
} else {
|
|
|
|
|
$abortPost = true;
|
|
|
|
|
$this->Session->setFlash('Please enter your current password to continue.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($this->User->save($this->request->data, true, $fields)) {
|
|
|
|
|
// TODO Audit, __extralog, fields compare
|
|
|
|
|
// newValues to array
|
|
|
|
|
$fieldsNewValues = array();
|
|
|
|
|
if (!$abortPost) {
|
|
|
|
|
$this->request->data['User']['id'] = $id;
|
|
|
|
|
if (!isset($this->request->data['User']['email'])) {
|
|
|
|
|
$this->request->data['User']['email'] = $userToEdit['User']['email'];
|
|
|
|
|
}
|
|
|
|
|
if (isset($this->request->data['User']['role_id']) && !array_key_exists($this->request->data['User']['role_id'], $syncRoles)) $this->request->data['User']['server_id'] = 0;
|
|
|
|
|
$fields = array();
|
|
|
|
|
$blockedFields = array('id', 'invited_by');
|
|
|
|
|
if (!$this->_isSiteAdmin()) {
|
|
|
|
|
$blockedFields[] = 'org_id';
|
|
|
|
|
}
|
|
|
|
|
foreach (array_keys($this->request->data['User']) as $field) {
|
|
|
|
|
if (in_array($field, $blockedFields)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ($field != 'password') array_push($fields, $field);
|
|
|
|
|
}
|
|
|
|
|
// TODO Audit, __extralog, fields get orig
|
|
|
|
|
$fieldsOldValues = array();
|
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
|
if ($field != 'confirm_password') {
|
|
|
|
|
$newValue = $this->data['User'][$field];
|
|
|
|
|
if (gettype($newValue) == 'array') {
|
|
|
|
|
$newValueStr = '';
|
|
|
|
|
$cP = 0;
|
|
|
|
|
foreach ($newValue as $newValuePart) {
|
|
|
|
|
if ($cP < 2) $newValueStr .= '-' . $newValuePart;
|
|
|
|
|
else $newValueStr = $newValuePart . $newValueStr;
|
|
|
|
|
$cP++;
|
|
|
|
|
}
|
|
|
|
|
array_push($fieldsNewValues, $newValueStr);
|
|
|
|
|
} else {
|
|
|
|
|
array_push($fieldsNewValues, $newValue);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
array_push($fieldsNewValues, $this->data['User']['password']);
|
|
|
|
|
if ($field == 'enable_password') continue;
|
|
|
|
|
if ($field != 'confirm_password') array_push($fieldsOldValues, $this->User->field($field));
|
|
|
|
|
else array_push($fieldsOldValues, $this->User->field('password'));
|
|
|
|
|
}
|
|
|
|
|
// TODO Audit, __extralog, fields get orig END
|
|
|
|
|
if (
|
|
|
|
|
isset($this->request->data['User']['enable_password']) && $this->request->data['User']['enable_password'] != '0' &&
|
|
|
|
|
isset($this->request->data['User']['password']) && "" != $this->request->data['User']['password']
|
|
|
|
|
) {
|
|
|
|
|
$fields[] = 'password';
|
|
|
|
|
if ($this->_isRest() && !isset($this->request->data['User']['confirm_password'])) {
|
|
|
|
|
$this->request->data['User']['confirm_password'] = $this->request->data['User']['password'];
|
|
|
|
|
$fields[] = 'confirm_password';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// compare
|
|
|
|
|
$fieldsResultStr = '';
|
|
|
|
|
$c = 0;
|
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
|
if (isset($fieldsOldValues[$c]) && $fieldsOldValues[$c] != $fieldsNewValues[$c]) {
|
|
|
|
|
if (!$this->_isRest()) {
|
|
|
|
|
$fields[] = 'role_id';
|
|
|
|
|
}
|
|
|
|
|
if (!$this->_isSiteAdmin()) {
|
|
|
|
|
$this->loadModel('Role');
|
|
|
|
|
$this->Role->recursive = -1;
|
|
|
|
|
$chosenRole = $this->Role->findById($this->request->data['User']['role_id']);
|
|
|
|
|
if (empty($chosenRole) || (($chosenRole['Role']['id'] != $allowedRole) && ($chosenRole['Role']['perm_site_admin'] == 1 || $chosenRole['Role']['perm_regexp_access'] == 1 || $chosenRole['Role']['perm_sync'] == 1))) {
|
|
|
|
|
throw new Exception('You are not authorised to assign that role to a user.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($this->User->save($this->request->data, true, $fields)) {
|
|
|
|
|
// TODO Audit, __extralog, fields compare
|
|
|
|
|
// newValues to array
|
|
|
|
|
$fieldsNewValues = array();
|
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
|
if ($field != 'confirm_password') {
|
|
|
|
|
$fieldsResultStr = $fieldsResultStr . ', ' . $field . ' (' . $fieldsOldValues[$c] . ') => (' . $fieldsNewValues[$c] . ')';
|
|
|
|
|
$newValue = $this->data['User'][$field];
|
|
|
|
|
if (gettype($newValue) == 'array') {
|
|
|
|
|
$newValueStr = '';
|
|
|
|
|
$cP = 0;
|
|
|
|
|
foreach ($newValue as $newValuePart) {
|
|
|
|
|
if ($cP < 2) $newValueStr .= '-' . $newValuePart;
|
|
|
|
|
else $newValueStr = $newValuePart . $newValueStr;
|
|
|
|
|
$cP++;
|
|
|
|
|
}
|
|
|
|
|
array_push($fieldsNewValues, $newValueStr);
|
|
|
|
|
} else {
|
|
|
|
|
array_push($fieldsNewValues, $newValue);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
array_push($fieldsNewValues, $this->data['User']['password']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$c++;
|
|
|
|
|
}
|
|
|
|
|
$fieldsResultStr = substr($fieldsResultStr, 2);
|
|
|
|
|
$this->__extralog("edit", "user", $fieldsResultStr); // TODO Audit, check: modify User
|
|
|
|
|
// TODO Audit, __extralog, fields compare END
|
|
|
|
|
if ($this->_isRest()) {
|
|
|
|
|
$user = $this->User->find('first', array(
|
|
|
|
|
'conditions' => array('User.id' => $this->User->id),
|
|
|
|
|
'recursive' => -1
|
|
|
|
|
));
|
|
|
|
|
$user['User']['password'] = '******';
|
|
|
|
|
return $this->RestResponse->viewData($user, $this->response->type());
|
|
|
|
|
// compare
|
|
|
|
|
$fieldsResultStr = '';
|
|
|
|
|
$c = 0;
|
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
|
if (isset($fieldsOldValues[$c]) && $fieldsOldValues[$c] != $fieldsNewValues[$c]) {
|
|
|
|
|
if ($field != 'confirm_password') {
|
|
|
|
|
$fieldsResultStr = $fieldsResultStr . ', ' . $field . ' (' . $fieldsOldValues[$c] . ') => (' . $fieldsNewValues[$c] . ')';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$c++;
|
|
|
|
|
}
|
|
|
|
|
$fieldsResultStr = substr($fieldsResultStr, 2);
|
|
|
|
|
$this->__extralog("edit", "user", $fieldsResultStr); // TODO Audit, check: modify User
|
|
|
|
|
// TODO Audit, __extralog, fields compare END
|
|
|
|
|
if ($this->_isRest()) {
|
|
|
|
|
$user = $this->User->find('first', array(
|
|
|
|
|
'conditions' => array('User.id' => $this->User->id),
|
|
|
|
|
'recursive' => -1
|
|
|
|
|
));
|
|
|
|
|
$user['User']['password'] = '******';
|
|
|
|
|
return $this->RestResponse->viewData($user, $this->response->type());
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The user has been saved'));
|
|
|
|
|
$this->_refreshAuth(); // in case we modify ourselves
|
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The user has been saved'));
|
|
|
|
|
$this->_refreshAuth(); // in case we modify ourselves
|
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($this->_isRest()) {
|
|
|
|
|
return $this->RestResponse->saveFailResponse('Users', 'admin_edit', $id, $this->User->validationErrors, $this->response->type());
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
|
|
|
|
|
if ($this->_isRest()) {
|
|
|
|
|
return $this->RestResponse->saveFailResponse('Users', 'admin_edit', $id, $this->User->validationErrors, $this->response->type());
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -702,12 +749,30 @@ class UsersController extends AppController {
|
|
|
|
|
throw new ForbiddenException('You have reached the maximum number of login attempts. Please wait ' . Configure::read('SecureAuth.expire') . ' seconds and try again.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
|
|
|
|
// Check the length of the user's authkey
|
|
|
|
|
$userPass = $this->User->find('first', array(
|
|
|
|
|
'conditions' => array('User.email' => $this->request->data['User']['email']),
|
|
|
|
|
'fields' => array('User.password'),
|
|
|
|
|
'recursive' => -1
|
|
|
|
|
));
|
|
|
|
|
if (strlen($userPass['User']['password']) == 40) {
|
|
|
|
|
$this->AdminSetting = ClassRegistry::init('AdminSetting');
|
|
|
|
|
$db_version = $this->AdminSetting->find('all', array('conditions' => array('setting' => 'db_version')));
|
|
|
|
|
$versionRequirementMet = $this->User->checkVersionRequirements($db_version[0]['AdminSetting']['value'], '2.4.77');
|
|
|
|
|
if ($versionRequirementMet) {
|
|
|
|
|
$passwordToSave = $this->request->data['User']['password'];
|
|
|
|
|
}
|
|
|
|
|
unset($this->Auth->authenticate['Form']['passwordHasher']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($this->Auth->login()) {
|
|
|
|
|
$this->__extralog("login"); // TODO Audit, __extralog, check: customLog i.s.o. __extralog, no auth user?: $this->User->customLog('login', $this->Auth->user('id'), array('title' => '','user_id' => $this->Auth->user('id'),'email' => $this->Auth->user('email'),'org' => 'IN2'));
|
|
|
|
|
$this->User->Behaviors->disable('SysLogLogable.SysLogLogable');
|
|
|
|
|
$this->User->id = $this->Auth->user('id');
|
|
|
|
|
$this->User->saveField('last_login', $this->Auth->user('current_login'));
|
|
|
|
|
$this->User->saveField('current_login', time());
|
|
|
|
|
if (empty($this->Auth->authenticate['Form']['passwordHasher']) && !empty($passwordToSave)) $this->User->saveField('password', $passwordToSave);
|
|
|
|
|
$this->User->Behaviors->enable('SysLogLogable.SysLogLogable');
|
|
|
|
|
// TODO removed the auto redirect for now, due to security concerns - will look more into this
|
|
|
|
|
// $this->redirect($this->Auth->redirectUrl());
|
|
|
|
|