- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想寻求帮助,我正在尝试编辑 ldapsync 文件。因为我需要同步manager属性。问题是该属性采用 dn 格式。我有功能只从 dn 中爆炸 cn,然后以该用户名作为条件从 mysql 中选择 id。我的问题是,当我运行 ldap 同步时,它看起来可以工作一段时间,但不会显示。请帮我。
FatalThrowableError 调用未定义函数 App\Console\Commands\getCNofDNn()
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Setting;
use App\Models\Ldap;
use App\Models\User;
use App\Models\Location;
use Log;
class LdapSync extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'snipeit:ldap-sync {--location=} {--location_id=} {--summary} {--json_summary}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command line LDAP sync';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
ini_set('max_execution_time', 600); //600 seconds = 10 minutes
ini_set('memory_limit', '500M');
$ldap_result_username = Setting::getSettings()->ldap_username_field;
$ldap_result_last_name = Setting::getSettings()->ldap_lname_field;
$ldap_result_first_name = Setting::getSettings()->ldap_fname_field;
$ldap_result_active_flag = Setting::getSettings()->ldap_active_flag_field;
$ldap_result_emp_num = Setting::getSettings()->ldap_emp_num;
$ldap_result_email = Setting::getSettings()->ldap_email;
$ldap_result_mobile = Setting::getSettings()->ldap_mobile;
$ldap_result_manager = Setting::getSettings()->ldap_manager;
$ldap_result_title = Setting::getSettings()->ldap_title;
$ldap_result_cost_center = Setting::getSettings()->ldap_cost_center;
try {
$ldapconn = Ldap::connectToLdap();
Ldap::bindAdminToLdap($ldapconn);
} catch (\Exception $e) {
if ($this->option('json_summary')) {
$json_summary = [ "error" => true, "error_message" => $e->getMessage(), "summary" => [] ];
$this->info(json_encode($json_summary));
}
LOG::error($e);
return [];
}
$summary = array();
$results = Ldap::findLdapUsers();
// Retrieve locations with a mapped OU, and sort them from the shallowest to deepest OU (see #3993)
$ldap_ou_locations = Location::where('ldap_ou', '!=', '')->get()->toArray();
$ldap_ou_lengths = array();
foreach ($ldap_ou_locations as $location) {
$ldap_ou_lengths[] = strlen($location["ldap_ou"]);
}
array_multisort($ldap_ou_lengths, SORT_ASC, $ldap_ou_locations);
if (sizeof($ldap_ou_locations) > 0) {
LOG::debug('Some locations have special OUs set. Locations will be automatically set for users in those OUs.');
}
// Inject location information fields
for ($i = 0; $i < $results["count"]; $i++) {
$results[$i]["ldap_location_override"] = false;
$results[$i]["location_id"] = 0;
}
if ($this->option('location')!='') {
$location = Location::where('name', '=', $this->option('location'))->first();
LOG::debug('Location name '.$this->option('location').' passed');
LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
} elseif ($this->option('location_id')!='') {
$location = Location::where('id', '=', $this->option('location_id'))->first();
LOG::debug('Location ID '.$this->option('location_id').' passed');
LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
} else {
$location = NULL;
}
if (!isset($location)) {
LOG::debug('That location is invalid or a location was not provided, so no location will be assigned by default.');
}
// Grab subsets based on location-specific DNs, and overwrite location for these users.
foreach ($ldap_ou_locations as $ldap_loc) {
$location_users = Ldap::findLdapUsers($ldap_loc["ldap_ou"]);
$usernames = array();
for ($i = 0; $i < $location_users["count"]; $i++) {
$location_users[$i]["ldap_location_override"] = true;
$location_users[$i]["location_id"] = $ldap_loc["id"];
$usernames[] = $location_users[$i][$ldap_result_username][0];
}
// Delete located users from the general group.
foreach ($results as $key => $generic_entry) {
if (in_array($generic_entry[$ldap_result_username][0], $usernames)) {
unset($results[$key]);
}
}
$global_count = $results['count'];
$results = array_merge($location_users, $results);
$results['count'] = $global_count;
}
$tmp_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
$pass = bcrypt($tmp_pass);
for ($i = 0; $i < $results["count"]; $i++) {
if (empty($ldap_result_active_flag) || $results[$i][$ldap_result_active_flag][0] == "TRUE") {
$item = array();
$item["username"] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : "";
$item["employee_number"] = isset($results[$i][$ldap_result_emp_num][0]) ? $results[$i][$ldap_result_emp_num][0] : "";
$item["lastname"] = isset($results[$i][$ldap_result_last_name][0]) ? $results[$i][$ldap_result_last_name][0] : "";
$item["firstname"] = isset($results[$i][$ldap_result_first_name][0]) ? $results[$i][$ldap_result_first_name][0] : "";
$item["email"] = isset($results[$i][$ldap_result_email][0]) ? $results[$i][$ldap_result_email][0] : "" ;
$item["mobile"] = isset($results[$i][$ldap_result_mobile][0]) ? $results[$i][$ldap_result_mobile][0] : "" ;
$item["manager"] = isset($results[$i][$ldap_result_manager][0]) ? $results[$i][$ldap_result_manager][0] : "" ;
$item["title"] = isset($results[$i][$ldap_result_title][0]) ? $results[$i][$ldap_result_title][0] : "" ;
$item["cost_center"] = isset($results[$i][$ldap_result_cost_center][0]) ? $results[$i][$ldap_result_cost_center][0] : "" ;
$item["ldap_location_override"] = isset($results[$i]["ldap_location_override"]) ? $results[$i]["ldap_location_override"]:"";
$item["location_id"] = isset($results[$i]["location_id"]) ? $results[$i]["location_id"]:"";
function getCNofDN($dn) {
$return=preg_match('/[^cn=]([^,]*)/i',$dn,$dn);
if ($dn != "") {
return($dn[0]);
}
return null;
}
if ( array_key_exists('useraccountcontrol', $results[$i]) ) {
$enabled_accounts = [
'512', '544', '66048', '66080', '262656', '262688', '328192', '328224'
];
$item['activated'] = ( in_array($results[$i]['useraccountcontrol'][0], $enabled_accounts) ) ? 1 : 0;
} else {
$item['activated'] = 0;
}
// insert
include "connn.php";
$dn = isset($results[$i][$ldap_result_manager][0]) ? $results[$i][$ldap_result_manager][0] : "" ;
$managername = getCNofDNn($dn);
if ( $managername != "") {
mysqli_query($connn,"SET NAMES 'utf8'");
$sql = "SELECT id FROM users WHERE username = '$managername';";
$result = mysqli_query($connn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$manager_idd = "$row[id] ";
}
} else {
echo "0 results getCNofDN('$dn'); $managername";
}
mysqli_close($connn);
} else {
$manager_idd = "0";
}
// User exists
$item["createorupdate"] = 'updated';
if (!$user = User::where('username', $item["username"])->first()) {
$user = new User;
$user->password = $pass;
$item["createorupdate"] = 'created';
}
// Create the user if they don't exist.
$user->first_name = e($item["firstname"]);
$user->last_name = e($item["lastname"]);
$user->username = e($item["username"]);
$user->email = e($item["email"]);
$user->employee_num = e($item["employee_number"]);
$user->activated = $item['activated'];
$user->phone = e($item['mobile']);
$user->manager_id = $manager_idd;
$user->jobtitle = e($item['title']);
$user->cost_center = e($item['cost_center']);
if ($item['ldap_location_override'] == true) {
$user->location_id = $item['location_id'];
} else if ($location) {
$user->location_id = e($location->id);
}
//$user->notes = 'Imported from LDAP';
$user->ldap_import = 1;
$errors = '';
if ($user->save()) {
$item["note"] = $item["createorupdate"];
$item["status"]='success';
} else {
foreach ($user->getErrors()->getMessages() as $key => $err) {
$errors .= $err[0];
}
$item["note"] = $errors;
$item["status"]='error';
}
array_push($summary, $item);
}
}
if ($this->option('summary')) {
for ($x = 0; $x < count($summary); $x++) {
if ($summary[$x]['status']=='error') {
$this->error('ERROR: '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].' was not imported: '.$summary[$x]['note']);
} else {
$this->info('User '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].' was '.strtoupper($summary[$x]['createorupdate']).'.');
}
}
} else if ($this->option('json_summary')) {
$json_summary = [ "error" => false, "error_message" => "", "summary" => $summary ];
$this->info(json_encode($json_summary));
} else {
return $summary;
}
}
}
最佳答案
您在 if 和 for 循环内创建函数 getCNofDN。如果代码不运行,则您的函数不存在。
将函数声明为私有(private)方法并调用它。
关于php - FatalThrowableError 调用未定义的函数 App\Console\Commands\getCNofDNn(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46973478/
已经有几个关于捕获或重定向 console.log 的问题: redirect Javascript syntax errors and console.log to somewhere else C
console.log(String(console.log('Not undefined')) === 'undefined'); console.log(String(console.log('N
我知道这是一个新手错误,但我不知道如何修复它。 public static void main (String args[]){ Console kitty = System.console(); S
我正在使用 Visual Studio 2015。 我试图打印一些语句只是为了跟踪一个非常长时间运行的测试。当使用 VSTest.Console 和/Logger:trx 时,调试输出(无论我们使用
这个问题在这里已经有了答案: Accessing console and devtools of extension's background.js (8 个回答) 5年前关闭。 我的 Chrome
我在括号中收到此错误。 我想强调一个事实,这是我第二次打开 JS 文件。 正如我强调的那样,我还想强调一个事实,即我不知道 Eslint 和 node.js 是什么。 StackOverflow 和其
我按照文档中的描述安装了 Drupal Console Launcher: curl https://drupalconsole.com/installer -L -o drupal.phar mv
Console.WriteLine() 和有什么区别和Trace.WriteLine() ? 最佳答案 从“调试”的角度来看这些。 我们开始使用 Console.WriteLine() 进行调试 后来
我一直在尝试连接到 serial console of a Raspberry Pi 3 with Android Things使用USB to TTL cable从我的 Linux (Ubuntu)
namespace Pro { class ErrorLog { public ErrorLog(RenderWindow app) {
以下代码是一个众所周知的示例,用于显示调试版本和发布版本之间的区别: using System; using System.Threading; public static class Program
if (open_date) { open_date = get_date_from_string(open_date); window.console && cons
在 Xcode 中工作时,我通常只为控制台打开一个单独的窗口,以便我可以看到尽可能多的输出行。我今天刚刚更新到 Xcode 12,在更新之前,您可以将编辑器 Pane 和控制台 Pane 之间的分隔线
在 Google Play Console 上,在所有应用程序的第一页,它会显示已安装的受众和用户获取。 我知道已安装的受众是在他们的设备上安装我的应用程序的受众。但什么是用户获取?通常,用户获取的数
Qt Quick uses qDebug执行日志记录,其中标准 Javascript 日志记录方法映射到 Qt 日志类型 console.log() -> qDebug() console.deb
Qt Quick uses qDebug执行日志记录,其中标准 Javascript 日志记录方法映射到 Qt 日志类型 console.log() -> qDebug() console.deb
我有以下代码: bool loop = true; LongbowWorkerThread Worker = new LongbowWorkerThread(); Th
我遇到了这两个 API,用于在 C# 的简单控制台应用程序中读取用户的输入: System.Console.ReadLine() System.Console.In.ReadLine() 这是一个我试
我是编程和 js 的新手,我正在尝试学习 javascript 的关键。 var obj1 = { name: 'rawn', fn: function() { con
using System; namespace ConsoleApplication1 { class Program { static void Main(strin
我是一名优秀的程序员,十分优秀!