mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
903698a7b0
|
@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Log;
|
|||
use Illuminate\Support\Facades\Notification;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
|
@ -93,6 +94,51 @@ class SettingsController extends Controller
|
|||
return response()->json($message, 200);
|
||||
}
|
||||
|
||||
public function ldaptestlogin(Request $request, LdapAd $ldap)
|
||||
{
|
||||
|
||||
if (Setting::getSettings()->ldap_enabled!='1') {
|
||||
\Log::debug('LDAP is not enabled. Cannot test.');
|
||||
return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);
|
||||
}
|
||||
|
||||
|
||||
$rules = array(
|
||||
'ldaptest_user' => 'required',
|
||||
'ldaptest_password' => 'required'
|
||||
);
|
||||
|
||||
$validator = Validator::make($request->all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
\Log::debug('LDAP Validation test failed.');
|
||||
$validation_errors = implode(' ',$validator->errors()->all());
|
||||
return response()->json(['message' => $validator->errors()->all()], 400);
|
||||
}
|
||||
|
||||
|
||||
\Log::debug('Preparing to test LDAP login');
|
||||
try {
|
||||
DB::beginTransaction(); //this was the easiest way to invoke a full test of an LDAP login without adding new users to the DB (which may not be desired)
|
||||
|
||||
// $results = $ldap->ldap->auth()->attempt($request->input('ldaptest_username'), $request->input('ldaptest_password'), true);
|
||||
// can't do this because that's a protected property.
|
||||
|
||||
$results = $ldap->ldapLogin($request->input('ldaptest_user'), $request->input('ldaptest_password')); // this would normally create a user on success (if they didn't already exist), but for the transaction
|
||||
if($results) {
|
||||
return response()->json(['message' => 'It worked! '. $request->input('ldaptest_user').' successfully binded to LDAP.'], 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Login Failed. '. $request->input('ldaptest_user').' did not successfully bind to LDAP.'], 400);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::debug('Connection failed');
|
||||
return response()->json(['message' => $e->getMessage()], 400);
|
||||
} finally {
|
||||
DB::rollBack(); // ALWAYS rollback, whether success or failure
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function slacktest(Request $request)
|
||||
{
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class AssetFileRequest extends Request
|
|||
{
|
||||
$max_file_size = \App\Helpers\Helper::file_upload_max_size();
|
||||
return [
|
||||
'file.*' => 'required|mimes:png,gif,jpg,svg,jpeg,doc,docx,pdf,txt,zip,rar,xls,lic,xml,rtf|max:'.$max_file_size,
|
||||
'file.*' => 'required|mimes:png,gif,jpg,svg,jpeg,doc,docx,pdf,txt,zip,rar,xls,xlsx,lic,xml,rtf|max:'.$max_file_size,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -446,7 +446,7 @@ class LdapAd extends LdapAdConfiguration
|
|||
public function testLdapAdUserConnection(): void
|
||||
{
|
||||
try {
|
||||
$this->ldap->connect(); //uh, this doesn't seem to exist :/
|
||||
$this->ldap->connect();
|
||||
} catch (\Adldap\Auth\BindException $e) {
|
||||
Log::error($e);
|
||||
throw new Exception('Unable to connect to LDAP directory!');
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
"codeception/module-rest": "^1.2",
|
||||
"codeception/module-webdriver": "^1.0",
|
||||
"fzaninotto/faker": "^1.9",
|
||||
"overtrue/phplint": "^2.2",
|
||||
"phpunit/php-token-stream": "^3.1",
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
|
|
114
composer.lock
generated
114
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3fe8a441e49d1299687346810b350e00",
|
||||
"content-hash": "68cf0fb2c06b12c9f8b58efbca2cd72b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adldap2/adldap2",
|
||||
|
@ -8476,6 +8476,116 @@
|
|||
],
|
||||
"time": "2020-01-17T21:11:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "n98/junit-xml",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cmuench/junit-xml.git",
|
||||
"reference": "7df0dbaf413fcaa1a63ffbcef18654e7a4cceb46"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cmuench/junit-xml/zipball/7df0dbaf413fcaa1a63ffbcef18654e7a4cceb46",
|
||||
"reference": "7df0dbaf413fcaa1a63ffbcef18654e7a4cceb46",
|
||||
"shasum": ""
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"N98\\JUnitXml": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Christian Münch",
|
||||
"email": "c.muench@netz98.de"
|
||||
}
|
||||
],
|
||||
"description": "JUnit XML Document generation library",
|
||||
"support": {
|
||||
"issues": "https://github.com/cmuench/junit-xml/issues",
|
||||
"source": "https://github.com/cmuench/junit-xml/tree/master"
|
||||
},
|
||||
"time": "2013-11-23T13:11:26+00:00"
|
||||
},
|
||||
{
|
||||
"name": "overtrue/phplint",
|
||||
"version": "2.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/overtrue/phplint.git",
|
||||
"reference": "dcbb1b9c728de2f05ce6208db7dacb8b3df1c446"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/overtrue/phplint/zipball/dcbb1b9c728de2f05ce6208db7dacb8b3df1c446",
|
||||
"reference": "dcbb1b9c728de2f05ce6208db7dacb8b3df1c446",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"n98/junit-xml": "1.0.0",
|
||||
"php": ">=5.5.9",
|
||||
"symfony/console": "^3.2|^4.0|^5.0",
|
||||
"symfony/finder": "^3.0|^4.0|^5.0",
|
||||
"symfony/process": "^3.3|^4.0|^5.0",
|
||||
"symfony/yaml": "^3.0|^4.0|^5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"brainmaestro/composer-git-hooks": "^2.7",
|
||||
"friendsofphp/php-cs-fixer": "^2.16",
|
||||
"jakub-onderka/php-console-highlighter": "^0.3.2 || ^0.4"
|
||||
},
|
||||
"bin": [
|
||||
"bin/phplint"
|
||||
],
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"hooks": {
|
||||
"pre-commit": [
|
||||
"composer fix-style"
|
||||
],
|
||||
"pre-push": [
|
||||
"composer check-style"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Overtrue\\PHPLint\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "overtrue",
|
||||
"email": "anzhengchao@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "`phplint` is a tool that can speed up linting of php files by running several lint processes at once.",
|
||||
"keywords": [
|
||||
"check",
|
||||
"lint",
|
||||
"phplint",
|
||||
"syntax"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/overtrue/phplint/issues",
|
||||
"source": "https://github.com/overtrue/phplint/tree/2.2.0"
|
||||
},
|
||||
"time": "2020-11-04T23:50:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phar-io/manifest",
|
||||
"version": "1.0.3",
|
||||
|
@ -9618,5 +9728,5 @@
|
|||
"platform-overrides": {
|
||||
"php": "7.2"
|
||||
},
|
||||
"plugin-api-version": "1.1.0"
|
||||
"plugin-api-version": "2.0.0"
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ return array(
|
|||
'title' => 'Puesto',
|
||||
'to_restore_them' => 'para restaurarlos.',
|
||||
'updateuser' => 'Actualizar Usuario',
|
||||
'username' => 'UsuarioUsuario',
|
||||
'username' => 'Usuario',
|
||||
'user_deleted_text' => 'Este usuario ha sido marcado como eliminado.',
|
||||
'username_note' => '(Esto se usa solo para la conexión con Active Directory, no para el inicio de sesión.)',
|
||||
'cloneuser' => 'Clonar Usuario',
|
||||
|
|
|
@ -30,7 +30,7 @@ return array(
|
|||
'title' => 'Puesto',
|
||||
'to_restore_them' => 'para restaurarlos.',
|
||||
'updateuser' => 'Actualizar Usuario',
|
||||
'username' => 'UsuarioUsuario',
|
||||
'username' => 'Usuario',
|
||||
'user_deleted_text' => 'Este usuario ha sido marcado como eliminado.',
|
||||
'username_note' => '(Esto se usa solo para la conexión con Active Directory, no para el inicio de sesión.)',
|
||||
'cloneuser' => 'Clonar Usuario',
|
||||
|
|
|
@ -379,6 +379,38 @@
|
|||
|
||||
</div>
|
||||
|
||||
<!-- LDAP Login test -->
|
||||
<div class="form-group">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('test_ldap_login', 'Test LDAP Login') }}
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<input type="text" name="ldaptest_user" id="ldaptest_user" class="form-control" placeholder="LDAP username">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<input type="password" name="ldaptest_password" id="ldaptest_password" class="form-control" placeholder="LDAP password">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a class="btn btn-default btn-sm" id="ldaptestlogin" style="margin-right: 10px;">Test LDAP</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<span id="ldaptestloginicon"></span>
|
||||
<span id="ldaptestloginresult"></span>
|
||||
<span id="ldaptestloginstatus"></span>
|
||||
</div>
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<p class="help-block">{{ trans('admin/settings/general.ldap_login_test_help') }}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@endif
|
||||
|
||||
<!-- LDAP Forgotten password -->
|
||||
|
@ -527,5 +559,76 @@
|
|||
body += "</tbody>"
|
||||
return body;
|
||||
}
|
||||
|
||||
$("#ldaptestlogin").click(function(){
|
||||
$("#ldaptestloginrow").removeClass('text-success');
|
||||
$("#ldaptestloginrow").removeClass('text-danger');
|
||||
$("#ldaptestloginstatus").removeClass('text-danger');
|
||||
$("#ldaptestloginstatus").html('');
|
||||
$("#ldaptestloginicon").html('<i class="fa fa-spinner spin"></i> Testing LDAP Authentication...');
|
||||
$.ajax({
|
||||
url: '{{ route('api.settings.ldaptestlogin') }}',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
data: {
|
||||
'ldaptest_user': $('#ldaptest_user').val(),
|
||||
'ldaptest_password': $('#ldaptest_password').val()
|
||||
},
|
||||
|
||||
dataType: 'json',
|
||||
|
||||
success: function (data) {
|
||||
$("#ldaptestloginicon").html('');
|
||||
$("#ldaptestloginrow").addClass('text-success');
|
||||
$("#ldaptestloginstatus").addClass('text-success');
|
||||
$("#ldaptestloginstatus").html('<i class="fa fa-check text-success"></i> User authenticated against LDAP successfully!');
|
||||
},
|
||||
|
||||
error: function (data) {
|
||||
|
||||
if (data.responseJSON) {
|
||||
var errors = data.responseJSON.message;
|
||||
} else {
|
||||
var errors;
|
||||
}
|
||||
|
||||
var error_text = '';
|
||||
|
||||
$("#ldaptestloginicon").html('');
|
||||
$("#ldaptestloginstatus").addClass('text-danger');
|
||||
$("#ldaptestloginicon").html('<i class="fa fa-exclamation-triangle text-danger"></i>');
|
||||
|
||||
if (data.status == 500) {
|
||||
$('#ldaptestloginstatus').html('500 Server Error');
|
||||
} else if (data.status == 400) {
|
||||
|
||||
if (typeof errors !='string') {
|
||||
|
||||
for (i = 0; i < errors.length; i++) {
|
||||
if (errors[i]) {
|
||||
error_text += '<li>Error: ' + errors[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
error_text = errors;
|
||||
}
|
||||
|
||||
$('#ldaptestloginstatus').html(error_text);
|
||||
|
||||
} else {
|
||||
$('#ldaptestloginstatus').html(data.responseText.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
|
Loading…
Reference in a new issue