summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: daede60)
raw | patch | inline | side by side (parent: daede60)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 4 Jan 2008 16:02:00 +0000 (16:02 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 4 Jan 2008 16:02:00 +0000 (16:02 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8224 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/functions.inc | patch | blob | history |
index c1f429937b914d39243b1e65aeed646d3f5cb3e7..dc447c3a212c34356dc023f88205bc110b37162b 100644 (file)
}
}
+
/* Create seed with microseconds */
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
}
-
function gosa_log ($message)
{
global $ui;
/* Look for entry or realm */
$ldap= $config->get_ldap_link();
if (!preg_match("/Success/i", $ldap->error)){
- print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
+ msg_dialog::display(_("LDAP error"), sprintf(_('User login failed.').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
$smarty= get_smarty();
$smarty->display(get_template_path('headers.tpl'));
echo "<body>".get_global('errors')."</body></html>";
/* Look for entry or realm */
$ldap= $config->get_ldap_link();
if (!preg_match("/Success/i", $ldap->error)){
- print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
+ msg_dialog::display(_("LDAP error"), sprintf(_('User login failed.').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
$smarty= get_smarty();
$smarty->display(get_template_path('headers.tpl'));
echo "<body>".get_global('errors')."</body></html>";
$ldap->search("(&(objectClass=gosaAccount)(uid=$username))", array("uid"));
/* Found no uniq match? Strange, because we did above... */
if ($ldap->count() != 1) {
- print_red(_("Username / UID is not unique. Please check your LDAP database."));
+ msg_dialog::display(_("LDAP error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), ERROR_DIALOG);
return (NULL);
}
$attrs= $ldap->fetch();
/* look through the entire ldap */
$ldap = $config->get_ldap_link();
if (!preg_match("/Success/i", $ldap->error)){
- print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
+ msg_dialog::display(_("LDAP error"), sprintf(_("User login failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
$smarty= get_smarty();
$smarty->display(get_template_path('headers.tpl'));
echo "<body>".get_global('errors')."</body></html>";
/* found more than one matching id */
default:
- print_red(_("Username / UID is not unique. Please check your LDAP database."));
+ msg_dialog::display(_("Internal error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), ERROR_DIALOG);
return (NULL);
}
return($expired);
}
+
function add_lock ($object, $user)
{
global $config;
/* Just a sanity check... */
if ($object == "" || $user == ""){
- print_red(_("Error while adding a lock. Parameters are not set correctly, please check the source!"));
+ msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
return;
}
$ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
array("gosaUser"));
if (!preg_match("/Success/i", $ldap->error)){
- print_red (sprintf(_("Can't set locking information in LDAP database. Please check the 'config' entry in gosa.conf! LDAP server says '%s'."), $ldap->get_error()));
+ msg_dialog::display(_("Configuration error"), sprintf(_("Cannot create locking information in LDAP tree. Please contact your administrator!")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
return;
}
$attrs["cn"] = "$name";
$ldap->add($attrs);
if (!preg_match("/Success/i", $ldap->error)){
- print_red(sprintf(_("Adding a lock failed. LDAP server says '%s'."),
- $ldap->get_error()));
+ msg_dialog::display(_("Internal error"), sprintf(_("Adding a lock failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
return;
}
}
$ldap->rmdir ($ldap->getDN());
if (!preg_match("/Success/i", $ldap->error)){
- print_red(sprintf(_("Removing a lock failed. LDAP server says '%s'."),
- $ldap->get_error()));
+ msg_dialog::display(_("LDAP error"), sprintf(_("Removing a lock failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
return;
}
}
/* Sanity check */
if ($object == ""){
- print_red(_("Getting the lock from LDAP failed. Parameters are not set correctly, please check the source!"));
+ msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
return("");
}
$ldap->cd ($config->current['CONFIG']);
$ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
if (!preg_match("/Success/i", $ldap->error)){
- print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!"));
+ msg_dialog::display(_("LDAP error"), sprintf(_("Cannot get locking information from LDAP tree!")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
return("");
}
if ($ldap->count() > 1){
/* Hmm. We're removing broken LDAP information here and issue a warning. */
- print_red(_("Found multiple locks for object to be locked. This should not be possible - cleaning up multiple references."));
+ msg_dialog::display(_("Warning"), _("Found multiple locks for object to be locked. This should not happen - cleaning up multiple references."), WARNING_DIALOG);
/* Clean up these references now... */
while ($attrs= $ldap->fetch()){
$ldap->cd ($config->current['CONFIG']);
$ldap->search($filter, array("gosaUser","gosaObject"));
if (!preg_match("/Success/i", $ldap->error)){
- print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!"));
+ msg_dialog::display(_("LDAP error"), sprintf(_("Cannot get locking information from LDAP tree!")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
return("");
}
@@ -812,7 +811,6 @@ function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= arra
}
-
function get_list($filter, $category, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
{
global $config, $ui;
}
}
+
function getMenuCache()
{
$t= array(-2,13);
for ($m=0;$m<strlen($b);$m++) {
$q.= $b[$m++];
}
- print_red(base64_decode($q));
+ msg_dialog::display(_("Internal error"), base64_decode($q), ERROR_DIALOG);
}
}
}
}
-function get_permissions ()
-{
- /* Look for attribute in ACL */
- trigger_error("Don't use get_permissions() its obsolete. Use userinfo::get_permissions() instead.");
- return array("");
-}
-
-
-function get_module_permission()
-{
- trigger_error("Don't use get_module_permission() its obsolete.");
- return ("#none#");
-}
-
-
function &get_userinfo()
{
global $ui;
}
-function chkacl()
-{
- /* Look for attribute in ACL */
- trigger_error("Don't use chkacl() its obsolete. Use userinfo::getacl() instead.");
- return("-deprecated-");
-}
-
-
function is_phone_nr($nr)
{
if ($nr == ""){
return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
}
+
function is_dns_name($str)
{
return(preg_match("/^[a-z0-9\.\-]*$/i",$str));
}
+
function is_url($url)
{
if ($url == ""){
return(FALSE);
}
+
/* Simple is domain check, it checks if the given string looks like "string(...).string" */
function is_domain($str)
{
}
-
function is_id($id)
{
if ($id == ""){
function print_red()
{
+ trigger_error("Use of obsolete print_red");
/* Check number of arguments */
if (func_num_args() < 1){
return;
/* If DEBUGLEVEL is set, we're in web mode, use textual output in
the other case... */
- if (is_global('DEBUGLEVEL')){
- if($string !== NULL){
- if (preg_match("/"._("LDAP error:")."/", $string)){
- $addmsg= _("Problems with the LDAP server mean that you probably lost the last changes. Please check your LDAP setup for possible errors and try again.");
- } else {
- if (!preg_match('/[.!?]$/', $string)){
- $string.= ".";
- }
- $string= preg_replace('/<br>/', ' ', $string);
- $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
- $addmsg = "";
- }
- if(empty($addmsg)){
- $addmsg = _("Error");
+ if($string !== NULL){
+ if (preg_match("/"._("LDAP error:")."/", $string)){
+ $addmsg= _("Problems with the LDAP server mean that you probably lost the last changes. Please check your LDAP setup for possible errors and try again.");
+ } else {
+ if (!preg_match('/[.!?]$/', $string)){
+ $string.= ".";
}
- msg_dialog::display($addmsg, $string,ERROR_DIALOG);
- return;
- }else{
- return;
+ $string= preg_replace('/<br>/', ' ', $string);
+ $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
+ $addmsg = "";
}
-
- } else {
- echo "Error: $string\n";
+ if(empty($addmsg)){
+ $addmsg = _("Error");
+ }
+ msg_dialog::display($addmsg, $string,ERROR_DIALOG);
+ return;
+ }else{
+ return;
}
+
}
}
/* Fill ERROR variable with nice error dialog */
- print_red($complete);
+ msg_dialog::display(_("Error"), $complete, ERROR_DIALOG);
}
{
if (!preg_match("/Success/i", $message)){
if ($addon == ""){
- msg_dialog::display(_("LDAP error:"),$message,ERROR_DIALOG);
+ msg_dialog::display(_("LDAP error:"), $message, ERROR_DIALOG);
} else {
if(!preg_match("/No such object/i",$message)){
msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
return (strip_tags(preg_replace('/\0/', '', $string)));
}
+
function get_gosa_version()
{
global $svn_revision, $svn_path;
return rmdir($path);
}
+
function scan_directory($path,$sort_desc=false)
{
$ret = false;
return($ret);
}
+
function clean_smarty_compile_dir($directory)
{
global $svn_revision;
// create revision file
create_revision($revision_file, $svn_revision);
} else {
-# check for "$config->...['CONFIG']/revision" and the
-# contents should match the revision number
+ # check for "$config->...['CONFIG']/revision" and the
+ # contents should match the revision number
if(!compare_revision($revision_file, $svn_revision)){
// If revision differs, clean compile directory
foreach(scan_directory($directory) as $file) {
is_writable($directory."/".$file)) {
// delete file
if(!unlink($directory."/".$file)) {
- print_red("File ".$directory."/".$file." could not be deleted.");
+ msg_dialog::display(_("Internal error"), sprintf(_("File '%s' could not be deleted."), $directory."/".$file), ERROR_DIALOG);
// This should never be reached
}
} elseif(is_dir($directory."/".$file) &&
}
}
+
function create_revision($revision_file, $revision)
{
$result= false;
}
fclose($fh);
} else {
- print_red("Can not write to revision file");
+ msg_dialog::display(_("Internal error"), _("Cannot write to revision file!"), ERROR_DIALOG);
}
return $result;
}
+
function compare_revision($revision_file, $revision)
{
// false means revision differs
$result= true;
}
} else {
- print_red("Can not open revision file");
+ msg_dialog::display(_("Internal error"), _("Cannot write to revision file!"), ERROR_DIALOG);
}
// Close file
fclose($fh);
return $result;
}
+
function progressbar($percentage,$width=100,$height=15,$showvalue=false)
{
$str = ""; // Our return value will be saved in this var
return($ret);
}
-/* Add "str_split" if this function is missing.
- * This function is only available in PHP5
- */
- if(!function_exists("str_split")){
- function str_split($str,$length =1)
- {
- if($length < 1 ) $length =1;
-
- $ret = array();
- for($i = 0 ; $i < strlen($str); $i = $i +$length){
- $ret[] = substr($str,$i ,$length);
- }
- return($ret);
- }
- }
-
function get_base_from_hook($dn, $attrib)
{
if (preg_match("/^[0-9]+$/", $output[0])){
return ($output[0]);
} else {
- print_red(_("Warning - base_hook is not available. Using default base."));
+ msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base."), WARNING_DIALOG);
return ($config->current['UIDBASE']);
}
} else {
- print_red(_("Warning - base_hook is not available. Using default base."));
+ msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base."), WARNING_DIALOG);
return ($config->current['UIDBASE']);
}
} else {
- print_red(_("Warning - no base_hook defined. Using default base."));
+ msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base."), WARNING_DIALOG);
return ($config->current['UIDBASE']);
}
}
}
-/* Schema validation functions */
function check_schema_version($class, $version)
{
return preg_match("/\(v$version\)/", $class['DESC']);
}
+
function check_schema($cfg,$rfc2307bis = FALSE)
{
$messages= array();
$ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
$objectclasses = $ldap->get_objectclasses();
if(count($objectclasses) == 0){
- print_red(_("Can't get schema information from server. No schema check possible!"));
+ msg_dialog::display(_("LDAP warning"), _("Cannot get schema information from server. No schema check possible!"), WARNING_DIALOG);
}
/* This is the default block used for each entry.
}
-
-
function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
{
$tmp = array(
return ($first < $curr&& $last > $curr);
}
+
/* Return class name in correct case
* mailMethodkolab => mailMethodKolab ( k => K )
*/
return(FALSE);
}
+
// change_password, changes the Password, of the given dn
function change_password ($dn, $password, $mode=0, $hash= "")
{
new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
if ($ldap->error != 'Success') {
- print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),
- $ldap->get_error()));
+ msg_dialog::display(_("LDAP error"), sprintf(_('Setting the password failed!').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
} else {
/* Run backend method for change/create */
exec($command);
} else {
$message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
- print_red ($message);
+ msg_dialog::display(_("Configuration error"), $message, ERROR_DIALOG);
}
}
}
}
+
+
// Return something like array['sambaLMPassword']= "lalla..."
function generate_smb_nt_hash($password)
{
flush();
reset($ar);
$hash= current($ar);
- if ($hash == "")
- {
- print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
- }
- else
- {
+ if ($hash == "") {
+ msg_dialog::display(_("Configuration error"), _("Setting for SMBHASH in gosa.conf is incorrect! Cannot change Samba password."), ERROR_DIALOG);
+ } else {
list($lm,$nt)= split (":", trim($hash));
- if ($config->current['SAMBAVERSION'] == 3)
- {
+ if ($config->current['SAMBAVERSION'] == 3) {
$attrs['sambaLMPassword']= $lm;
$attrs['sambaNTPassword']= $nt;
$attrs['sambaPwdLastSet']= date('U');
}
}
+
function crypt_single($string,$enc_type )
{
return( passwordMethod::crypt_single_str($string,$enc_type));
return("");
}
+
/* This function returns the offset for the default timezone.
* $stamp is used to detect summer or winter time.
* In case of PHP5, the integrated timezone functions are used.
- * For PHP4 we query an array for offset and add summertime hour.
*/
function get_default_timezone($stamp = NULL)
{
}
if(!@date_default_timezone_set($tz)){
- print_red(sprintf(_("The timezone setting \"".$tz."\" in your gosa.conf is not valid. Can not calculate correct timezone offest."),$tz));
+ msg_dialog::display(_("Configuration error"), sprintf(_("The timezone setting '%s' in your gosa.conf is not valid. Cannot calculate correct timezone offest."), $tz), ERROR_DIALOG);
}
$tz_delta = date("Z", $stamp);
$tz_delta = $tz_delta / 3600 ;