binary - PHP Logonhours format -
i'm trying set logonhours ldap users using php. i've gotten point i've created gui looks active directories blue , grey cells representing allowed , denied logon hours. problem intermittently receive "server unwilling perform" , think has pack("c", bindec(strrev($chunk))) nested in foreach loop isn't spitting out correct format. there should tack on pack("c", bindec(strrev($chunk))) statement ensure it's in right format dc accept it?
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 $chunk){ $logondec = pack("c", bindec(strrev($chunk))); //inconsistently works } echo $logondec; $adldap->user()->modify($_post['username'], array("logonhours"=>$logondec)); echo '<br>'; echo ldap_error($adldap->getldapconnection()) . '<br>'; }
after few months decided revisit taking different approach , figured out passing arguments powershell script!
php: --replace foreach in question foreach below , add wshell object/command
foreach ($set_eighthourchunks $chunk){ // $logondec .= pack("c", bindec(strrev($chunk))); gets row correct 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 in same directory called runaslogonhours.ps1 content below
if (-not (get-module activedirectory)){ import-module activedirectory } $password = $args[1] #password cred rights set logon hours $username = $args[0] #username rights set logonhours $cmd = "c:\inetpub\wwwroot\adldap\acctmgmt\logonhours.ps1" $user = $args[2] #user want set logon hours $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
Comments
Post a Comment