Esempio n. 1
0
/**
 * Prints an HTML-formatted error string. If you specify the optional
 * parameters $ldap_err_msg and $ldap_err_no, this function will
 * lookup the error number and display a verbose message in addition
 * to the message you pass it.
 *
 * @param string $msg The error message to display.
 * @param string $ldap_err_msg (optional) The error message supplied by the LDAP server
 * @param string $ldap_err_no (optional) The hexadecimal error number string supplied by the LDAP server
 * @param bool $fatal (optional) If true, phpLDAPadmin will terminate execution with the PHP die() function.
 *
 * @see die
 * @see ldap_errno
 * @see pla_verbose_error
 */
function pla_error($msg, $ldap_err_msg = null, $ldap_err_no = -1, $fatal = true)
{
    if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) {
        debug_log('pla_error(): Entered with (%s,%s,%s,%s)', 1, $msg, $ldap_err_msg, $ldap_err_no, $fatal);
    }
    @(include_once HTDOCDIR . 'header.php');
    global $config;
    ?>
	<center>
	<table class="error"><tr><td class="img"><img src="images/warning.png" /></td>
	<td><center><h2><?php 
    echo _('Error');
    ?>
</h2></center>
	<?php 
    echo $msg;
    ?>
	<br />
	<br />
	<?php 
    if (function_exists('syslog_err')) {
        syslog_err($msg);
    }
    if ($ldap_err_msg) {
        echo sprintf(_('LDAP said: %s'), htmlspecialchars($ldap_err_msg));
        echo '<br />';
    }
    if ($ldap_err_no != -1) {
        $ldap_err_no = '0x' . str_pad(dechex($ldap_err_no), 2, 0, STR_PAD_LEFT);
        $verbose_error = pla_verbose_error($ldap_err_no);
        if ($verbose_error) {
            echo sprintf(_('Error number: %s (%s)'), $ldap_err_no, $verbose_error['title']);
            echo '<br />';
            echo sprintf(_('Description: %s <br /><br />'), $verbose_error['desc']);
        } else {
            echo sprintf(_('Error number: %s<br /><br />'), $ldap_err_no);
            echo '<br />';
            echo _('Description: (no description available)<br />');
        }
        if (function_exists('syslog_err')) {
            syslog_err(sprintf(_('Error number: %s<br /><br />'), $ldap_err_no));
        }
    }
    ?>
	<br />
	<!-- Commented out due to too many false bug reports. :)
	<br />
	<center>
	<small>
		<?php 
    echo sprintf(_('Is this a phpLDAPadmin bug? If so, please <a href=\'%s\'>report it</a>.'), get_href('add_bug'));
    ?>
        <?php 
    if (function_exists("debug_print_backtrace")) {
        debug_print_backtrace();
    }
    ?>
	</small>
	</center>
	-->
	</td></tr></table>
	</center>
	<?php 
    if ($fatal) {
        echo "</body>\n</html>";
        die;
    }
}
Esempio n. 2
0
/**
 * Print an LDAP error message
 */
function ldap_error_msg($msg, $errnum)
{
    if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
        debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    }
    $body = '<table border="0">';
    $errnum = '0x' . str_pad(dechex($errnum), 2, 0, STR_PAD_LEFT);
    $verbose_error = pla_verbose_error($errnum);
    $body .= sprintf('<tr><td><b>%s</b>:</td><td>%s</td></tr>', _('LDAP said'), $msg);
    if ($verbose_error) {
        $body .= sprintf('<tr><td><b>%s</b>:</td><td>%s (%s)</td></tr>', _('Error number'), $errnum, $verbose_error['title']);
        $body .= sprintf('<tr><td><b>%s</b>:</td><td>%s</td></tr>', _('Description'), $verbose_error['desc']);
    } else {
        $body .= sprintf('<tr><td><b>%s</b>:</td><td>%s</td></tr>', _('Error number'), $errnum);
        $body .= sprintf('<tr><td><b>%s</b>:</td><td>(%s)</td></tr>', _('Description'), _('no description available'));
    }
    $body .= '</table>';
    return $body;
}
Esempio n. 3
0
echo "<pre>";
require_once realpath('functions.php');
// test DN sorting
if (false) {
    $dns = array("ou=people,dc=example,dc=com", "cn=Admin,ou=People,dc=example,dc=com", "cn=Joe,ou=people,dc=example,dc=com", "dc=example,dc=com", "cn=Fred,ou=people,dc=example,dc=org", "cn=Dave,ou=people,dc=example,dc=org", "dc=com");
    usort($dns, "pla_compare_dns");
    foreach ($dns as $dn) {
        echo pretty_print_dn($dn) . "<br>";
    }
}
// test pla_verbose_error() using ldap_error_codes.txt
if (false) {
    for ($i = 0; $i < 255; $i++) {
        $num = "0x" . str_pad(dechex($i), 2, "0", STR_PAD_LEFT);
        var_dump($num);
        print_r(pla_verbose_error($num));
    }
}
// tests is_dn_string()
if (false) {
    $dn_strs = array(' cn=joe,dc=example,dc=com', 'cn = joe, dc= example, dc =com', '  cn=asdf asdf, ou= foo bar, o =foo bar, dc=com', 'cn=True!=False,dc=example,dc=com');
    $not_dn_strs = array(' asdf asdf ', '== asdf asdf ', ' = = = = = = = =');
    echo "All should be true:\n";
    foreach ($dn_strs as $str) {
        echo "\"{$str}\"\n";
        var_dump(is_dn_string($str));
    }
    echo "\nAll should be false:\n";
    foreach ($not_dn_strs as $str) {
        echo "\"{$str}\"\n";
        var_dump(is_dn_string($str));
function pla_error($msg, $ldap_err_msg = null, $ldap_err_no = -1)
{
    include_once 'header.php';
    ?>
	<center>
	<table class="error"><tr><td class="img"><img src="images/warning.png" /></td>
	<td><center><h2>Error</h2></center>
	<?php 
    echo $msg;
    ?>
	<br />
	<?php 
    if ($ldap_err_msg) {
        echo "<b>LDAP said</b>: " . htmlspecialchars($ldap_err_msg) . "<br /><br />\n";
    }
    if ($ldap_err_no != -1) {
        $ldap_err_no = '0x' . str_pad(dechex($ldap_err_no), 2, 0, STR_PAD_LEFT);
        $verbose_error = pla_verbose_error($ldap_err_no);
        if ($verbose_error) {
            echo "<b>Error number</b>: {$ldap_err_no} <small>(" . $verbose_error['title'] . ")</small><br /><br />\n";
            echo "<b>Description</b>: " . $verbose_error['desc'] . "<br /><br />\n\n";
        } else {
            echo "<b>Error number</b>: {$ldap_err_no}<br /><br />\n";
            echo "<b>Description</b>: (no description available)<br />\n\n";
        }
    }
    ?>
	<br />
	<br />
	<center>
	<small>
		Is this a phpLDAPadmin bug? If so, please 
		<a href="<?php 
    echo get_href('add_bug');
    ?>
">report it</a>.
	</small>
	</center>
	</td></tr></table>
	</center>
	<?php 
    die;
}