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

📄 channels.php

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                }            }            $this->ui->outputData($d, 'channel-info');        } else {            return $this->raiseError('Serious error: Channel "' . $params[0] .                '" has a corrupted registry entry');        }    }    // }}}        function doDelete($command, $options, $params)    {        if (sizeof($params) != 1) {            return $this->raiseError('channel-delete: no channel specified');        }        $reg = &$this->config->getRegistry();        if (!$reg->channelExists($params[0])) {            return $this->raiseError('channel-delete: channel "' . $params[0] . '" does not exist');        }        $channel = $reg->channelName($params[0]);        if ($channel == 'pear.php.net') {            return $this->raiseError('Cannot delete the pear.php.net channel');        }        if ($channel == 'pecl.php.net') {            return $this->raiseError('Cannot delete the pecl.php.net channel');        }        if ($channel == '__uri') {            return $this->raiseError('Cannot delete the __uri pseudo-channel');        }        if (PEAR::isError($err = $reg->listPackages($channel))) {            return $err;        }        if (count($err)) {            return $this->raiseError('Channel "' . $channel .                '" has installed packages, cannot delete');        }        if (!$reg->deleteChannel($channel)) {            return $this->raiseError('Channel "' . $channel . '" deletion failed');        } else {            $this->config->deleteChannel($channel);            $this->ui->outputData('Channel "' . $channel . '" deleted', $command);        }    }    function doAdd($command, $options, $params)    {        if (sizeof($params) != 1) {            return $this->raiseError('channel-add: no channel file specified');        }        if (strpos($params[0], '://')) {            $downloader = &$this->getDownloader();            $tmpdir = $this->config->get('temp_dir');            if (!file_exists($tmpdir)) {                require_once 'System.php';                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);                $err = System::mkdir(array('-p', $tmpdir));                PEAR::staticPopErrorHandling();                if (PEAR::isError($err)) {                    return $this->raiseError('channel-add: temp_dir does not exist: "' .                        $tmpdir .                         '" - You can change this location with "pear config-set temp_dir"');                }            }            if (!is_writable($tmpdir)) {                return $this->raiseError('channel-add: temp_dir is not writable: "' .                    $tmpdir .                     '" - You can change this location with "pear config-set temp_dir"');            }            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);            $loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir, null, false);            PEAR::staticPopErrorHandling();            if (PEAR::isError($loc)) {                return $this->raiseError('channel-add: Cannot open "' . $params[0] .                    '" (' . $loc->getMessage() . ')');            } else {                list($loc, $lastmodified) = $loc;                $contents = implode('', file($loc));            }        } else {            $lastmodified = $fp = false;            if (file_exists($params[0])) {                $fp = fopen($params[0], 'r');            }            if (!$fp) {                return $this->raiseError('channel-add: cannot open "' . $params[0] . '"');            }            $contents = '';            while (!feof($fp)) {                $contents .= fread($fp, 1024);            }            fclose($fp);        }        if (!class_exists('PEAR_ChannelFile')) {            require_once 'PEAR/ChannelFile.php';        }        $channel = new PEAR_ChannelFile;        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);        $result = $channel->fromXmlString($contents);        PEAR::staticPopErrorHandling();        if (!$result) {            $exit = false;            if (count($errors = $channel->getErrors(true))) {                foreach ($errors as $error) {                    $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));                    if (!$exit) {                        $exit = $error['level'] == 'error' ? true : false;                    }                }                if ($exit) {                    return $this->raiseError('channel-add: invalid channel.xml file');                }            }        }        $reg = &$this->config->getRegistry();        if ($reg->channelExists($channel->getName())) {            return $this->raiseError('channel-add: Channel "' . $channel->getName() .                '" exists, use channel-update to update entry');        }        $ret = $reg->addChannel($channel, $lastmodified);        if (PEAR::isError($ret)) {            return $ret;        }        if (!$ret) {            return $this->raiseError('channel-add: adding Channel "' . $channel->getName() .                '" to registry failed');        }        $this->config->setChannels($reg->listChannels());        $this->config->writeConfigFile();        $this->ui->outputData('Adding Channel "' . $channel->getName() . '" succeeded', $command);    }    function doUpdate($command, $options, $params)    {        $tmpdir = $this->config->get('temp_dir');        if (!file_exists($tmpdir)) {            require_once 'System.php';            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);            $err = System::mkdir(array('-p', $tmpdir));            PEAR::staticPopErrorHandling();            if (PEAR::isError($err)) {                return $this->raiseError('channel-add: temp_dir does not exist: "' .                    $tmpdir .                     '" - You can change this location with "pear config-set temp_dir"');            }        }        if (!is_writable($tmpdir)) {            return $this->raiseError('channel-add: temp_dir is not writable: "' .                $tmpdir .                 '" - You can change this location with "pear config-set temp_dir"');        }        $reg = &$this->config->getRegistry();        if (sizeof($params) != 1) {            return $this->raiseError("No channel file specified");        }        $lastmodified = false;        if ((!file_exists($params[0]) || is_dir($params[0]))              && $reg->channelExists(strtolower($params[0]))) {            $c = $reg->getChannel(strtolower($params[0]));            if (PEAR::isError($c)) {                return $this->raiseError($c);            }            $this->ui->outputData("Updating channel \"$params[0]\"", $command);            $dl = &$this->getDownloader(array());            // if force is specified, use a timestamp of "1" to force retrieval            $lastmodified = isset($options['force']) ? false : $c->lastModified();            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);            $contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml',                $this->ui, $tmpdir, null, $lastmodified);            PEAR::staticPopErrorHandling();            if (PEAR::isError($contents)) {                return $this->raiseError('Cannot retrieve channel.xml for channel "' .                    $c->getName() . '" (' . $contents->getMessage() . ')');            }            list($contents, $lastmodified) = $contents;            if (!$contents) {                $this->ui->outputData("Channel \"$params[0]\" is up to date");                return;            }            $contents = implode('', file($contents));            if (!class_exists('PEAR_ChannelFile')) {                require_once 'PEAR/ChannelFile.php';            }            $channel = new PEAR_ChannelFile;            $channel->fromXmlString($contents);            if (!$channel->getErrors()) {                // security check: is the downloaded file for the channel we got it from?                if (strtolower($channel->getName()) != strtolower($c->getName())) {                    if (isset($options['force'])) {                        $this->ui->log(0, 'WARNING: downloaded channel definition file' .                            ' for channel "' . $channel->getName() . '" from channel "' .                            strtolower($c->getName()) . '"');                    } else {                        return $this->raiseError('ERROR: downloaded channel definition file' .                            ' for channel "' . $channel->getName() . '" from channel "' .                            strtolower($c->getName()) . '"');                    }                }            }        } else {            if (strpos($params[0], '://')) {                $dl = &$this->getDownloader();                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);                $loc = $dl->downloadHttp($params[0],                    $this->ui, $tmpdir, null, $lastmodified);                PEAR::staticPopErrorHandling();                if (PEAR::isError($loc)) {                    return $this->raiseError("Cannot open " . $params[0] .                         ' (' . $loc->getMessage() . ')');                } else {                    list($loc, $lastmodified) = $loc;                    $contents = implode('', file($loc));                }            } else {                $fp = false;                if (file_exists($params[0])) {                    $fp = fopen($params[0], 'r');                }                if (!$fp) {                    return $this->raiseError("Cannot open " . $params[0]);                }                $contents = '';                while (!feof($fp)) {                    $contents .= fread($fp, 1024);                }                fclose($fp);            }            if (!class_exists('PEAR_ChannelFile')) {                require_once 'PEAR/ChannelFile.php';            }            $channel = new PEAR_ChannelFile;            $channel->fromXmlString($contents);        }        $exit = false;        if (count($errors = $channel->getErrors(true))) {            foreach ($errors as $error) {                $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));                if (!$exit) {                    $exit = $error['level'] == 'error' ? true : false;                }            }            if ($exit) {                return $this->raiseError('Invalid channel.xml file');            }        }        if (!$reg->channelExists($channel->getName())) {            return $this->raiseError('Error: Channel "' . $channel->getName() .                '" does not exist, use channel-add to add an entry');        }        $ret = $reg->updateChannel($channel, $lastmodified);        if (PEAR::isError($ret)) {            return $ret;        }        if (!$ret) {            return $this->raiseError('Updating Channel "' . $channel->getName() .                '" in registry failed');        }        $this->config->setChannels($reg->listChannels());        $this->config->writeConfigFile();        $this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded');    }    function &getDownloader()    {        if (!class_exists('PEAR_Downloader')) {            require_once 'PEAR/Downloader.php';        }        $a = new PEAR_Downloader($this->ui, array(), $this->config);        return $a;    }    function doAlias($command, $options, $params)    {        $reg = &$this->config->getRegistry();        if (sizeof($params) == 1) {            return $this->raiseError('No channel alias specified');        }        if (sizeof($params) != 2) {            return $this->raiseError(                'Invalid format, correct is: channel-alias channel alias');        }        if (!$reg->channelExists($params[0], true)) {            if ($reg->isAlias($params[0])) {                $extra = ' (use "channel-alias ' . $reg->channelName($params[0]) . ' ' .                    strtolower($params[1]) . '")';            } else {                $extra = '';            }            return $this->raiseError('"' . $params[0] . '" is not a valid channel' . $extra);        }        if ($reg->isAlias($params[1])) {            return $this->raiseError('Channel "' . $reg->channelName($params[1]) . '" is ' .                'already aliased to "' . strtolower($params[1]) . '", cannot re-alias');        }        $chan = &$reg->getChannel($params[0]);        if (PEAR::isError($chan)) {            return $this->raiseError('Corrupt registry?  Error retrieving channel "' . $params[0] .                '" information (' . $chan->getMessage() . ')');        }        // make it a local alias        if (!$chan->setAlias(strtolower($params[1]), true)) {            return $this->raiseError('Alias "' . strtolower($params[1]) .                '" is not a valid channel alias');        }        $reg->updateChannel($chan);        $this->ui->outputData('Channel "' . $chan->getName() . '" aliased successfully to "' .            strtolower($params[1]) . '"');    }    /**     * The channel-discover command     *     * @param string $command command name     * @param array  $options option_name => value     * @param array  $params  list of additional parameters.     *               $params[0] should contain a string with either:     *               - <channel name> or     *               - <username>:<password>@<channel name>     * @return null|PEAR_Error     */    function doDiscover($command, $options, $params)    {        $reg = &$this->config->getRegistry();        if (sizeof($params) != 1) {            return $this->raiseError("No channel server specified");        }                // Look for the possible input format "<username>:<password>@<channel>"        if (preg_match('/^(.+):(.+)@(.+)\\z/', $params[0], $matches)) {            $username = $matches[1];            $password = $matches[2];            $channel = $matches[3];        } else {            $channel = $params[0];        }                if ($reg->channelExists($channel)) {            if ($reg->isAlias($channel)) {                return $this->raiseError("A channel alias named \"$channel\" " .                    'already exists, aliasing channel "' . $reg->channelName($channel)                    . '"');            } else {                return $this->raiseError("Channel \"$channel\" is already initialized");            }        }        $this->pushErrorHandling(PEAR_ERROR_RETURN);        $err = $this->doAdd($command, $options, array('http://' . $channel . '/channel.xml'));        $this->popErrorHandling();        if (PEAR::isError($err)) {            return $this->raiseError("Discovery of channel \"$channel\" failed (" .                $err->getMessage() . ')');        }                // Store username/password if they were given        // Arguably we should do a logintest on the channel here, but since        // that's awkward on a REST-based channel (even "pear login" doesn't        // do it for those), and XML-RPC is deprecated, it's fairly pointless.        if (isset($username)) {            $this->config->set('username', $username, 'user', $channel);            $this->config->set('password', $password, 'user', $channel);            $this->config->store();            $this->ui->outputData("Stored login for channel \"$channel\" using username \"$username\"", $command);        }                $this->ui->outputData("Discovery of channel \"$channel\" succeeded", $command);    }}?>

⌨️ 快捷键说明

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