2015-05-11 33 views
0

我試圖設置使用PHP LDAP用戶logonhours。我已經開始創建一個GUI,它看起來像活動目錄,其中藍色和灰色單元表示允許和拒絕的登錄時間。我的問題是間歇,我收到「服務器不願意執行」,我認爲這是與我的包(「C」,bindec(strrev($塊)))嵌套在foreach循環是不隨地吐痰正確的格式。有什麼我應該釘到包(「C」,bindec(strrev($塊)))聲明,以確保它總是在正確的格式爲我的DC接受呢?PHP Logonhours格式

if (isset($_POST['logonhours'])){ 
$set_logonhours = $_POST['logonhours']; 
$set_logonhours_end = mb_substr($set_logonhours, -5); // EST TIMEZONE 
$set_logonhours_begin = mb_substr($set_logonhours, 0, -5); // EST TIMEZONE 
$set_logonhours_tz = $set_logonhours_end . $set_logonhours_begin; 

$set_eighthourchunks = str_split($set_logonhours_tz, 8); 


foreach ($set_eighthourchunks as $chunk){ 
$logondec = pack("C", bindec(strrev($chunk))); //inconsistently works sometimes 
} 
echo $logondec; 
$adldap->user()->modify($_POST['username'], array("logonhours"=>$logondec)); 


echo '<br>'; 
echo ldap_error($adldap->getLdapConnection()) . '<br>'; 
} 
+0

有人嗎?........ – Noob01

回答

0

幾個月後,我決定重新審視該採取不同的方法,計算出來的參數傳遞給PowerShell腳本!

PHP:--replace FOREACH在用foreach下方加入WSHELL對象的問題/命令

foreach ($set_eighthourchunks as $chunk){ 
// $logondec .= pack("c", bindec(strrev($chunk))); GETS THE ROW CORRECT BUT CANT CHANGE TOUCHING ROWS 
$logondec .= bindec(strrev($chunk)) . ","; 
} 
$logondec = substr($logondec, 0, -1); 

$WshShell = new COM("WScript.Shell"); 
$WshShell->Run('powershell.exe -ExecutionPolicy ByPass -file C:\\inetpub\\wwwroot\\adLDAP\\acctmgmt\\runaslogonhours.ps1 "DOMAINNAMEHERE\\' . ADMINUSERNAME . '" "' . ADMINPASSWORD . '" ' . $user . ' "' . $logondec . '"'); 

POWERSHELL:--create一個PS1 SCRIPT名爲runaslogonhours.ps1與內容下方

相同的目錄
if (-not (Get-Module ActiveDirectory)){    
    Import-Module ActiveDirectory    
} 

$PASSWORD = $args[1] #password for cred with rights to set logon hours 
$USERNAME = $args[0] #username with rights to set logonhours 

$CMD = "C:\inetpub\wwwroot\adLDAP\acctmgmt\logonhours.ps1" 
$user = $args[2] #user you want to set logon hours for 
$inputhours = $args[3] #logon hours 
$arrhours = $inputhours.ToString().Replace("'","").Split(",") 
[byte[]]$hours= @($arrhours) 
$replaceHashTable = New-Object HashTable 
$replaceHashTable.Add("logonHours", $hours) 
$ARGS = @($user, $hours) 

$pw = convertto-securestring $PASSWORD -asplaintext –force 
$credential = new-object -typename system.management.automation.pscredential -argumentlist $USERNAME,$pw 



Set-ADUser -Identity $user -Replace $replaceHashTable -Credential $credential