⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldap.php

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
        return(parent::getOne($query, $data));    }    /**     * Fetch the first row of data returned from a query.  Takes care     * of doing the query and freeing the results when finished.     *     * @param $query the SQL query     * @param $fetchmode the fetch mode to use     * @param $data array if supplied, prepare/execute will be used     *        with this array as execute parameters     * @param string $action type of request to perform, defaults to search (ldap_search())     * @param array $params array of additional parameters to pass to the PHP ldap function requested     * @access public     * @return array the first row of results as an array indexed from     * 0, or a DB error code.     * @see DB_common::getRow()     * @access public     */    function &getRow($query,                     $data = null,                     $fetchmode = DB_FETCHMODE_DEFAULT,                     $action = null, $params = array())    {        $this->q_action = $action ? $action : $this->action;        $this->q_params = $params;        return(parent::getRow($query, $data, $fetchmode));    }    /**     * Fetch the first column of data returned from a query.  Takes care     * of doing the query and freeing the results when finished.     *     * @param $query the SQL query     * @param $col which column to return (integer [column number,     * starting at 0] or string [column name])     * @param $data array if supplied, prepare/execute will be used     *        with this array as execute parameters     * @param string $action type of request to perform, defaults to search (ldap_search())     * @param array $params array of additional parameters to pass to the PHP ldap function requested     * @access public     * @return array an indexed array with the data from the first     * row at index 0, or a DB error code.     * @see DB_common::getCol()     * @access public     */    function &getCol($query, $col = 0, $data = array(), $action = null, $params = array())    {        $this->q_action = $action ? $action : $this->action;        $this->q_params = $params;        return(parent::getCol($query, $col, $data));    }    /**     * Calls DB_common::getAssoc()     *     * @param $query the SQL query     * @param $force_array (optional) used only when the query returns     * exactly two columns.  If true, the values of the returned array     * will be one-element arrays instead of scalars.     * starting at 0] or string [column name])     * @param array $data if supplied, prepare/execute will be used     *        with this array as execute parameters     * @param $fetchmode the fetch mode to use     * @param boolean $group see DB_Common::getAssoc()     * @param string $action type of request to perform, defaults to search (ldap_search())     * @param array $params array of additional parameters to pass to the PHP ldap function requested     * @access public     * @return array an indexed array with the data from the first     * row at index 0, or a DB error code.     * @see DB_common::getAssoc()     * @access public     */    function &getAssoc($query, $force_array = false, $data = array(),                       $fetchmode = DB_FETCHMODE_ORDERED, $group = false,                       $action = null, $params = array())    {        $this->q_action = $action ? $action : $this->action;        $this->q_params = $params;        return(parent::getAssoc($query, $force_array, $data, $fetchmode, $group));    }    /**     * Fetch all the rows returned from a query.     *     * @param $query the SQL query     * @param array $data if supplied, prepare/execute will be used     *        with this array as execute parameters     * @param $fetchmode the fetch mode to use     * @param string $action type of request to perform, defaults to search (ldap_search())     * @param array $params array of additional parameters to pass to the PHP ldap function requested     * @access public     * @return array an nested array, or a DB error     * @see DB_common::getAll()     */    function &getAll($query,                     $data = null,                     $fetchmode = DB_FETCHMODE_DEFAULT,                     $action = null, $params = array())    {        $this->q_action = $action ? $action : $this->action;        $this->q_params = $params;        return(parent::getAll($query, $data, $fetchmode));    }    function numRows($result)    {        return $result->numRows();    }    function getTables()    {        return $this->ldapRaiseError(DB_ERROR_NOT_CAPABLE);    }    function getListOf($type)    {        return $this->ldapRaiseError(DB_ERROR_NOT_CAPABLE);    }    function isManip($action)    {        return(in_array($action, $this->manip));    }    function freeResult()    {        return true;    }    function freeQuery($query = '')    {        $this->q_action = '';        $this->q_base   = '';        $this->q_params = array();        $this->attributes = null;        $this->sorting = '';        return true;    }    // Deprecated, will be removed in future releases.    function base($base = null)    {        $this->q_base = ($base !== null) ? $base : null;        return true;    }    function ldapSetBase($base = null)    {        $this->base = ($base !== null) ? $base : $this->d_base;        $this->q_base = '';        return true;    }    function ldapSetAction($action = 'search')    {        if ($action != 'search' && $action != 'list' && $action != 'read') {            return $this->ldapRaiseError(DB_ERROR_UNKNOWN_LDAP_ACTION);        }        $this->action = $action;        $this->q_action = '';        return true;    }    /**     * Get the next value in a sequence.     *     * LDAP provides transactions for only one entry and we need to     * prevent race condition. If unique value before and after modify     * aren't equal then wait and try again.     *     * The name of sequence is LDAP DN of entry.     *     * @access public     * @param string $seq_name the DN of the sequence     * @param bool $ondemand whether to create the sequence on demand     * @return a sequence integer, or a DB error     */    function nextId($seq_name, $ondemand = true)    {        $repeat = 0;        do {            // Get the sequence entry            $this->base($seq_name);            $this->pushErrorHandling(PEAR_ERROR_RETURN);            $data = $this->getRow("objectClass=*");            $this->popErrorHandling();            if (DB::isError($data)) {                // DB_ldap doesn't use DB_ERROR_NOT_FOUND                if ($ondemand && $repeat == 0                && $data->getCode() == DB_ERROR) {                // Try to create sequence and repeat                    $repeat = 1;                    $data = $this->createSequence($seq_name);                    if (DB::isError($data)) {                        return $this->ldapRaiseError($data);                    }                } else {                    // Other error                    return $this->ldapRaiseError($data);                }            } else {                // Increment sequence value                $data["cn"]++;                // Unique identificator of transaction                $seq_unique = mt_rand();                $data["uid"] = $seq_unique;                // Modify the LDAP entry                $this->pushErrorHandling(PEAR_ERROR_RETURN);                $data = $this->simpleQuery($data, 'modify');                $this->popErrorHandling();                if (DB::isError($data)) {                    return $this->ldapRaiseError($data);                }                // Get the entry and check if it contains our unique value                $this->base($seq_name);                $data = $this->getRow("objectClass=*");                if (DB::isError($data)) {                    return $this->ldapRaiseError($data);                }                if ($data["uid"] != $seq_unique) {                    // It is not our entry. Wait a little time and repeat                    sleep(1);                    $repeat = 1;                } else {                    $repeat = 0;                }            }        } while ($repeat);        if (DB::isError($data)) {            return $data;        }        return $data["cn"];    }    /**     * Create the sequence     *     * The sequence entry is based on core schema with extensibleObject,     * so it should work with any LDAP server which doesn't check schema     * or supports extensibleObject object class.     *     * Sequence name have to be DN started with "sn=$seq_id,", i.e.:     *     * $seq_name = "sn=uidNumber,ou=sequences,dc=php,dc=net";     *     * dn: $seq_name     * objectClass: top     * objectClass: extensibleObject     * sn: $seq_id     * cn: $seq_value     * uid: $seq_uniq     *     * @param string $seq_name the DN of the sequence     * @return mixed DB_OK on success or DB error on error     * @access public     */    function createSequence($seq_name)    {        // Extract $seq_id from DN        ereg("^([^,]*),", $seq_name, $regs);        $seq_id = $regs[1];        // Create the sequence entry        $data = array(            dn => $seq_name,            objectclass => array("top", "extensibleObject"),            sn => $seq_id,            cn => 0,            uid => 0        );        // Add the LDAP entry        $this->pushErrorHandling(PEAR_ERROR_RETURN);        $data = $this->simpleQuery($data, 'add');        $this->popErrorHandling();        return $data;    }    /**     * Drop a sequence     *     * @param string $seq_name the DN of the sequence     * @return mixed DB_OK on success or DB error on error     * @access public     */    function dropSequence($seq_name)    {        // Delete the sequence entry        $data = array(            dn => $seq_name,        );        $this->pushErrorHandling(PEAR_ERROR_RETURN);        $data = $this->simpleQuery($data, 'delete');        $this->popErrorHandling();        return $data;    }    // {{{ ldapRaiseError()    function ldapRaiseError($errno = null)    {        if ($errno === null) {            $errno = $this->errorCode(ldap_errno($this->connection));        }        if ($this->q_action !== null) {            return $this->raiseError($errno, null, null,                sprintf('%s base="%s" filter="%s"',                    $this->q_action, $this->q_base, $this->last_query                ),                $errno == DB_ERROR_UNKNOWN_LDAP_ACTION ? null : @ldap_error($this->connection));        } else {            return $this->raiseError($errno, null, null, "???",                @ldap_error($this->connection));        }    }    // }}}}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -