function changecomputername() { if (substr($_POST["userid"], strlen($_POST["userid"]) - 1, 1) != "\$") { $_POST["userid"] = $_POST["userid"] . "\$"; } $comp = new computers($_POST["userid"]); $MAC = $comp->ComputerMacAddress; $_POST["NewHostname"] = trim(strtolower($_POST["NewHostname"])); $_POST["NewHostname"] = str_replace('$', '', $_POST["NewHostname"]); $actualdn = $comp->dn; $newrdn = "cn={$_POST["NewHostname"]}\$"; $ldap = new clladp(); if (!preg_match("#^cn=(.+?),[a-zA-Z\\s]+#", $actualdn, $re)) { echo "Unable to preg_match {$actualdn}\n"; return; } $newDN = str_replace($re[1], $_POST["NewHostname"] . '$', $actualdn); if ($newDN == null) { echo "Unable to preg_match {$actualdn} -> {$re[1]}\n"; return; } if (!$ldap->Ldap_rename_dn($newrdn, $actualdn, null)) { echo "Rename failed {$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}"; return; } $upd["uid"][0] = $_POST["NewHostname"] . '$'; if (!$ldap->Ldap_modify($newDN, $upd)) { echo "Update UID {$upd["uid"][0]} failed:\n{$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}\nExpected value:{$_POST["NewHostname"]}"; return; } $ocs = new ocs($MAC); $ocs->ComputerName = $_POST["NewHostname"]; $ocs->ComputerIP = $comp->ComputerIP; $ocs->EditComputer(); }
function changecomputername() { if (substr($_POST["userid"], strlen($_POST["userid"]) - 1, 1) != "\$") { $_POST["userid"] = $_POST["userid"] . "\$"; } $comp = new computers($_POST["userid"]); $MAC = $comp->ComputerMacAddress; $_POST["NewHostname"] = trim(strtolower($_POST["NewHostname"])); $_POST["NewHostname"] = str_replace('$', '', $_POST["NewHostname"]); $actualdn = $comp->dn; $newrdn = "cn={$_POST["NewHostname"]}\$"; $ldap = new clladp(); if (!preg_match("#^cn=(.+?),[a-zA-Z\\s]+#", $actualdn, $re)) { echo "Unable to preg_match {$actualdn}\n"; return; } $newDN = str_replace($re[1], $_POST["NewHostname"] . '$', $actualdn); if ($newDN == null) { echo "Unable to preg_match {$actualdn} -> {$re[1]}\n"; return; } if ($ldap->ExistsDN("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}")) { $ldap->ldap_delete("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}"); } $newParent = "ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}"; if (!$ldap->Ldap_rename_dn($newrdn, $actualdn, $newParent)) { echo "Rename failed {$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\n\nActual DN:{$actualdn}\nExpected DN:{$newrdn}"; return; } $upd["uid"][0] = $_POST["NewHostname"] . '$'; if (!$ldap->Ldap_modify($newDN, $upd)) { echo "Update UID {$upd["uid"][0]} failed:\n{$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}\nExpected value:{$_POST["NewHostname"]}"; return; } $ocs = new ocs($MAC); $ocs->ComputerName = $_POST["NewHostname"]; $ocs->ComputerIP = $comp->ComputerIP; $ocs->EditComputer(); if (IsPhysicalAddress($comp->ComputerMacAddress)) { include_once dirname(__FILE__) . "/ressources/class.mysql.inc"; $uid = $comp->ComputerIDFromMAC($comp->ComputerMacAddress); $comp = new computers($uid); $sql = "UPDATE dhcpd_fixed SET `hostname`='{$comp->ComputerRealName}' WHERE `mac`='{$comp->ComputerMacAddress}'"; $q = new mysql(); $q->QUERY_SQL($sql, "artica_backup"); } }