当前位置: 首页>>代码示例>>PHP>>正文


PHP parse_options函数代码示例

本文整理汇总了PHP中parse_options函数的典型用法代码示例。如果您正苦于以下问题:PHP parse_options函数的具体用法?PHP parse_options怎么用?PHP parse_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_options函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add_permission

function add_permission($options = "")
{
    global $conf, $self, $onadb;
    printmsg('DEBUG => add_permission(' . $options . ') called', 3);
    // Version - UPDATE on every edit!
    $version = '1.00';
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !$options['name']) {
        $self['error'] = 'ERROR => Insufficient parameters';
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        return array(1, <<<EOM

add_permission-v{$version}
Registers a new permission, this should be used by install scripts that are
creating new functionality that requires a registered permission.

  Synopsis: add_permission(OPTIONS)

  Options:
    name=STRING         Name of permission
    desc=STRING         Quoted string to describe this permission


EOM
);
    }
    // Get a list of the valid "permissions" and their descriptions.
    list($status, $rows, $permissions) = db_get_record($onadb, 'permissions', array('name' => $options['name']), '');
    if ($rows) {
        $self['error'] = "ERROR => add_permission() Permission already exists: {$options['name']}";
        printmsg($self['error'], 0);
        return array(1, $self['error'] . "\n");
    }
    // Get the next ID for the new host record
    $id = ona_get_next_id('permissions');
    if (!$id) {
        $self['error'] = "ERROR => The ona_get_next_id('permissions') call failed!";
        printmsg($self['error'], 0);
        return array(7, $self['error'] . "\n");
    }
    printmsg("DEBUG => ID for new permission record: {$id}", 3);
    // Add the record
    list($status, $rows) = db_insert_record($onadb, 'permissions', array('id' => $id, 'name' => $options['name'], 'description' => $options['desc']));
    if ($status or !$rows) {
        $self['error'] = "ERROR => add_permission() SQL Query failed: " . $self['error'];
        printmsg($self['error'], 0);
        return array(2, $self['error'] . "\n");
    }
    // Return the success notice
    $self['error'] = "INFO => Permission ADDED: {$options['name']} [{$options['desc']}]";
    printmsg($self['error'], 0);
    return array(0, $self['error'] . "\n");
}
开发者ID:edt82,项目名称:ona,代码行数:55,代码来源:permissions.inc.php

示例2: convert

 /**
  * Ecache Plugin Convert (Block) Function
  */
 function convert()
 {
     global $vars, $defaultpage;
     $args = func_get_args();
     if (func_num_args() == 0) {
         return 'ecache(): no arugment.';
     }
     $body = array_pop($args);
     $body = str_replace("\r", "\n", $body);
     //multiline arg has \r
     parse_options($args, $this->options);
     $this->options['page'] = isset($this->options['page']) ? $this->options['page'] : (isset($vars['page']) ? $vars['page'] : $defaultpage);
     return $this->ecache($this->options['page'], $body, $this->options['reset']);
 }
开发者ID:orangeal2o3,项目名称:pukiwiki-plugin,代码行数:17,代码来源:ecache.inc.php

示例3: mangle_ip

function mangle_ip($options)
{
    global $conf, $self;
    printmsg('DEBUG => mangle_ip(' . $options . ') called', 3);
    // Version - UPDATE on every edit!
    $version = '1.00';
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !$options['ip']) {
        $self['error'] = 'ERROR => Insufficient parameters';
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        return array(1, <<<EOM

mangle_ip v{$version}
Converts between various IP address representations

  Synopsis: mangle_ip(OPTIONS)

  Required:
    ip=<inet_addr>  32 or 128-bit Internet address

  Optional:
    format=<specifier>  Desired output format, specified as a string
                        numeric : return ip as an integer
                        dotted  : return ip as an IPv4 address
                        cidr    : return ip as a CIDR netmask
                        binary  : return ip as a 32-bit binary string
                        bin128  : return ip as a 128-bit binary string
                        ipv6    : return ip as an IPv6 address
                        ipv6gz  : return ip as a compressed IPv6 address



EOM
);
    }
    // Now what?  We need to call ip_mangle() with our options
    if (!$options['format']) {
        $options['format'] = 'default';
    }
    $retval = ip_mangle($options['ip'], $options['format']) . "\n";
    if ($self['error'] != '') {
        return array(1, $self['error'] . "\n");
    } else {
        return array(0, $retval);
    }
}
开发者ID:edt82,项目名称:ona,代码行数:48,代码来源:mangle.inc.php

示例4: convert

 function convert()
 {
     $args = func_get_args();
     ///// Support old versions (The 1st arg is tagtok) ///
     $fisrtIsOption = FALSE;
     foreach ($this->options as $key => $val) {
         if (!isset($args) && strpos($args[0], $key) === 0) {
             $firstIsOption = TRUE;
             break;
         }
     }
     if (func_num_args() >= 1 && !$firstIsOption) {
         $this->options['tag'] = array_shift($args);
     }
     //////////////////////////////////////////////////////
     parse_options($args, $this->options);
     return $this->taglist($this->options['tag'], $this->options['related']);
 }
开发者ID:big2men,项目名称:qhm,代码行数:18,代码来源:taglist.inc.php

示例5: convert

 function convert()
 {
     $args = func_get_args();
     parse_options($args, $this->options);
     if ($this->options['limit'] === "0") {
         $this->options['limit'] = NULL;
     }
     if ($this->options['cloud'] === 'off' || $this->options['cloud'] === 'false') {
         $this->options['cloud'] = FALSE;
     }
     //print_r($this->options);
     if ($this->options['cloud']) {
         $html = $this->plugin_tag->display_tagcloud($this->options['limit'], $this->options['related']);
     } else {
         $html = $this->plugin_tag->display_taglist($this->options['limit'], $this->options['related']);
     }
     return $html;
 }
开发者ID:big2men,项目名称:qhm,代码行数:18,代码来源:tagcloud.inc.php

示例6: main

/**
 * Main functions. Just decides what mode we are in and calls the
 * appropriate methods.
 */
function main()
{
    global $info, $config;
    $args = Console_Getopt::readPHPArgv();
    if (count($args) < 2) {
        print_usage_info();
    }
    if (substr($args[1], 0, 1) == "-" || substr($args[1], 0, 1) == "/") {
        print "invalid parameter " . $args[2] . "\n";
        print_usage_info();
    }
    if (substr($args[1], -4) == ".php") {
        // mode 2: create zombie app
        if (!file_exists($args[1])) {
            die("config file " . $args[1] . " does not exist\n");
        }
        read_config_file($args[1]);
        $outdir = ZOMBIE_BASE . '/../' . Horde_String::lower($config['app']);
        if (is_dir($outdir) && $args[2] != "-f") {
            print "Directory {$outdir} already exists.\nUse -f flag to force overwrite\n";
            exit;
        }
        $n = $config['app'];
        print "Creating Horde Application {$n} in directory " . Horde_String::lower($n) . "\n";
        transform($outdir);
        print "\nHorde Application '{$n}' successfully written. Where to go from here:\n" . "1) Paste content of {$n}/registry.stub to horde/config/registry.php.\n" . "   After that, the {$n} should be working!\n" . "2) Replace {$n}.gif with proper application icon\n" . "3) Ensure conf.php is not world-readable as it may contain password data.\n" . "4) Start playing around and enhancing your new horde application. Enjoy!\n";
    } else {
        // mode 1: create config file
        parse_options($args);
        print "creating config file for table " . $config['table'] . "\n";
        create_table_info();
        enhance_info();
        print "writing config file to " . $config['file'] . "\n";
        dump_config_file();
    }
}
开发者ID:Gomez,项目名称:horde,代码行数:40,代码来源:rampage.php

示例7: implode

if (false === $status) {
    $errors = $restore->getErrors();
    if (count($errors) > 0) {
        $errorMsg = 'Errors were encountered: ' . implode(', ', $errors) . ' If seeking support please click to Show Advanced Details above and provide a copy of the log.';
        pb_backupbuddy::status('error', $errorMsg);
    } else {
        $errorMsg = 'Error #894383: Unknown error starting restore. See advanced status log for details.';
    }
    pb_backupbuddy::alert($errorMsg);
    return;
}
$restore->_state['defaultURL'] = $restore->getDefaultUrl();
$restore->_state['defaultDomain'] = $restore->getDefaultDomain();
if ('true' != pb_backupbuddy::_GET('deploy')) {
    // deployment mode pre-loads state data in a file instead of passing via post.
    $restore->_state = parse_options($restore->_state);
}
$restore->_state['skipUnzip'] = $skipUnzip;
// Set up state variables.
if ('db' == $restore->_state['dat']['backup_type'] || false == $restore->_state['restoreFiles']) {
    pb_backupbuddy::status('details', 'Database backup OR not restoring files.');
    $restore->_state['tempPath'] = ABSPATH . 'importbuddy/temp_' . pb_backupbuddy::random_string(12) . '/';
    $restore->_state['restoreFileRoot'] = $restore->_state['tempPath'];
    pb_backupbuddy::anti_directory_browsing($restore->_state['restoreFileRoot'], $die = false);
} else {
    pb_backupbuddy::status('details', 'Restoring files.');
    $restore->_state['restoreFileRoot'] = ABSPATH;
    // Restore files into current root.
}
// Parse submitted options for saving to state.
function parse_options($restoreData)
开发者ID:Offirmo,项目名称:base-wordpress,代码行数:31,代码来源:2.php

示例8: die

<?php

if (!defined('PB_IMPORTBUDDY') || true !== PB_IMPORTBUDDY) {
    die('<html></html>');
}
Auth::require_authentication();
// Die if not logged in.
$data = array('step' => '4');
pb_backupbuddy::set_greedy_script_limits(true);
parse_options();
/**
 *	parse_options()
 *
 *	Parses various submitted options and settings from step 1.
 *
 *	@return		null
 */
function parse_options()
{
    if (isset($_POST['siteurl'])) {
        pb_backupbuddy::$options['siteurl'] = $_POST['siteurl'];
        if (isset($_POST['custom_home'])) {
            pb_backupbuddy::$options['home'] = $_POST['home'];
        } else {
            pb_backupbuddy::$options['home'] = $_POST['siteurl'];
        }
    }
    // end isset post siteurl.
    if (isset($_POST['skip_database_import']) && $_POST['skip_database_import'] == 'on') {
        pb_backupbuddy::$options['skip_database_import'] = true;
    } else {
开发者ID:heyjones,项目名称:crossfitpurpose,代码行数:31,代码来源:4.php

示例9: ona_sql

function ona_sql($options = "")
{
    // The important globals
    global $conf, $onadb, $base;
    // Version - UPDATE on every edit!
    $version = '1.05';
    // TODO: Maybe make this into a sys_config option
    $srvdir = dirname($base) . "/sql";
    printmsg('DEBUG => ona_sql(' . $options . ') called', 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Sanitize delimeter
    if (!$options['delimiter']) {
        $options['delimiter'] = ':';
    }
    // fix up the escaped ' marks.  may need the = and & stuff too????
    $options['sql'] = str_replace('\\\'', '\'', $options['sql']);
    $options['sql'] = str_replace('\\=', '=', $options['sql']);
    // Set "options[commit] to no if it's not set
    if (!array_key_exists('commit', $options)) {
        $options['commit'] = 'N';
    } else {
        $options['commit'] = sanitize_YN($options['commit'], 'N');
    }
    // Set "options[commit] to no if it's not set
    if (!array_key_exists('dataarray', $options)) {
        $options['dataarray'] = 'N';
    } else {
        $options['dataarray'] = sanitize_YN($options['dataarray'], 'N');
    }
    // Set "options[header] to yes if it's not set
    if (!array_key_exists('header', $options)) {
        $options['header'] = 'Y';
    } else {
        $options['header'] = sanitize_YN($options['header'], 'Y');
    }
    // Check permissions
    if (!auth('ona_sql')) {
        $self['error'] = "Permission denied!";
        printmsg($self['error'], 0);
        return array(10, $self['error'] . "\n");
    }
    // Return the usage summary if we need to
    if ($options['help'] or !($options['list'] and !$options['sql'] or !$options['list'] and $options['sql'])) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        return array(1, <<<EOM

ona_sql-v{$version}
Runs the specified SQL query on the database and prints the result

  Synopsis: ona_sql [KEY=VALUE] ...

  Required:
    sql=STATEMENT|FILENAME   quoted SQL statement to execute
    OR
    list                     lists the SQL files available on the server side

  Optional:
    show                     displays contents of SQL, gives usage etc
    commit=yes|no            commit the transaction (no)
    header=yes|no            display record header (yes)
    delimiter=DELIMITER      record delimiter for output (:)
    (1,2,..)=VALUE           bind variables, replaces ? in query sequentially.
                             the first ? found is replaced by 1=value, and so on

  Notes:
    * Query is sent to the configured OpenNetAdmin database server.
    * The use of bind variables requires your options to match positionally.
    * The SQL option will be tried first as a local file, then as a server
      file, then as a raw text SQL query.  Filenames are case sensitive.
    * Server based SQL files are located in {$srvdir}
    * Some plugins may provide their own SQL dir inside the plugin directory
    * Use the show option to display contents of SQL files, this should contain
      a long description and any usage information that is needed.


EOM
);
    }
    // TODO: check that the user has admin privs? or at least a ona_sql priv
    // Get a list of the files
    $plugins = plugin_list();
    $files = array();
    $srvdirs = array();
    array_push($srvdirs, $srvdir);
    // add a local sql dir as well so they don't get overrriden by installs
    array_push($srvdirs, dirname($base) . '/www/local/sql');
    // loop through the plugins and find files inside of their sql directories.
    foreach ($plugins as $plug) {
        array_push($srvdirs, $plug['path'] . '/sql');
    }
    // Loop through each of our plugin directories and the default directory to find .sql files
    foreach ($srvdirs as $srvdir) {
        if ($handle = @opendir($srvdir)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != ".." && substr($file, -4) == '.sql') {
                    // Build an array of filenames
                    array_push($files, $srvdir . '/' . $file);
                }
            }
//.........这里部分代码省略.........
开发者ID:edt82,项目名称:ona,代码行数:101,代码来源:sql.inc.php

示例10: add_module

function add_module($options = "")
{
    global $conf, $self, $onadb;
    printmsg('DEBUG => add_module(' . $options . ') called', 3);
    // Version - UPDATE on every edit!
    $version = '1.00';
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !$options['name']) {
        $self['error'] = 'ERROR => Insufficient parameters';
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        return array(1, <<<EOM

add_module-v{$version}
Registers a new DCM module, this should be used by install scripts that are
creating new functionality that requires a registered module.

  Synopsis: add_module(OPTIONS)

  Options:
    name=STRING         Name of DCM module
    desc=STRING         Quoted string to describe this module
    file=STRING         Path to php file, relative to {$conf['dcm_module_dir']}



EOM
);
    }
    // Get a list of the valid "modules" and their descriptions.
    list($status, $rows, $modules) = db_get_record($onadb, 'dcm_module_list', array('name' => $options['name']), '');
    if ($rows) {
        $self['error'] = "ERROR => add_module() Module name already exists: {$options['name']}";
        printmsg($self['error'], 0);
        return array(1, $self['error'] . "\n");
    }
    // Add the record
    list($status, $rows) = db_insert_record($onadb, 'dcm_module_list', array('name' => $options['name'], 'description' => $options['desc'], 'file' => $options['file']));
    if ($status or !$rows) {
        $self['error'] = "ERROR => add_module() SQL Query failed: " . $self['error'];
        printmsg($self['error'], 0);
        return array(2, $self['error'] . "\n");
    }
    // Return the success notice
    $self['error'] = "INFO => Module ADDED: {$options['name']} [{$options['desc']}] => {$options['file']}";
    printmsg($self['error'], 0);
    return array(0, $self['error'] . "\n");
}
开发者ID:edt82,项目名称:ona,代码行数:49,代码来源:get_module_list.inc.php

示例11: main

function main()
{
    assert(pcntl_signal(SIGINT, 'handle_sigint'));
    parse_options();
    echo "-- Simple DBGp Client --\n";
    global $conn;
    // Start the listening socket.
    list($socket, $port) = start_client($conn->port);
    echo "Listening on port {$port}\n";
    // Accept a connection.
    $fd = null;
    while (true) {
        $fd = @socket_accept($socket);
        if ($fd !== false) {
            echo "Connected to an XDebug server!\n";
            break;
        }
    }
    socket_close($socket);
    $conn->fd = $fd;
    while (true) {
        // Wait for the expected number of responses.  Normally we expect 1
        // response, but with the break command, we expect 2.
        $responses = "";
        while ($conn->expect_responses > 0) {
            $response = read_response($fd);
            if (starts_with($response, "Client socket error")) {
                break;
            }
            // Init packet doesn't end in </response>.
            $conn->expect_responses -= substr_count($response, "</response>");
            $conn->expect_responses -= substr_count($response, "</init>");
            $responses .= $response;
        }
        $conn->expect_responses = 1;
        // Might have been sent a Ctrl-c while waiting for the response.
        if ($conn->send_break) {
            send_command($fd, "break -i SIGINT");
            $conn->send_break = false;
            // We're expecting a response for the break command, and the command
            // before the break command.
            $conn->expect_responses = 2;
            continue;
        }
        // Echo back the response to the user if it isn't a stream.
        if (!is_stream($responses)) {
            echo "{$responses}\n";
        }
        // Received response saying we're stopping.
        if (strpos($responses, "status=\"stopped\"") > 0) {
            echo "-- Request ended, stopping --\n";
            break;
        }
        // Get a command from the user and send it.
        $line = readline("(dbgp) \$ ");
        $line = trim($line);
        if ($line === "") {
            continue;
        }
        if (starts_with("quit", $line)) {
            echo "-- Quitting, request will continue running --\n";
            break;
        }
        send_command($fd, $line);
    }
    socket_close($fd);
    $conn->fd = null;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:68,代码来源:dbgp-client.php

示例12: vlan_campus_display

function vlan_campus_display($options = "")
{
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.00';
    printmsg("DEBUG => vlan_campus_display({$options}) called", 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Sanitize options[verbose] (default is yes)
    $options['verbose'] = sanitize_YN($options['verbose'], 'Y');
    // Return the usage summary if we need to
    if ($options['help'] or !$options['campus']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

vlan_campus_display-v{$version}
Displays a vlan campus record from the database

  Synopsis: vlan_campus_display [KEY=VALUE] ...

  Required:
    campus=NAME or ID      Campus name or ID of the campus display

  Optional:
    verbose=[yes|no]       Display additional info (DEFAULT: yes)


EOM
);
    }
    // The formatting rule on campus names is all upper and trim it
    $options['campus'] = strtoupper(trim($options['campus']));
    // If the campus provided is numeric, check to see if it's valid
    if (is_numeric($options['campus'])) {
        // See if it's an vlan_campus_id
        list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $options['campus']));
        if (!$campus['id']) {
            printmsg("DEBUG => Unable to find campus using the ID {$options['campus']}!", 3);
            $self['error'] = "ERROR => Unable to find campus using the ID {$options['campus']}!";
            return array(2, $self['error'] . "\n");
        }
    } else {
        list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['campus']));
        if (!$campus['id']) {
            $self['error'] = "ERROR => Unable to find campus using the name {$options['campus']}!";
            printmsg("DEBUG => Unable to find campus using the name {$options['campus']}!", 3);
            return array(2, $self['error'] . "\n");
        }
    }
    printmsg("DEBUG => Found campus: {$campus['name']}", 3);
    // Build text to return
    $text = "VLAN CAMPUS RECORD\n";
    $text .= format_array($campus);
    // If 'verbose' is enabled, grab some additional info to display
    if ($options['verbose'] == 'Y') {
        // vlan record(s)
        $i = 0;
        do {
            list($status, $rows, $vlan) = ona_get_vlan_record(array('vlan_campus_id' => $campus['id']));
            if ($rows == 0) {
                break;
            }
            $i++;
            $text .= "\nASSOCIATED VLAN RECORD ({$i} of {$rows})\n";
            $text .= format_array($vlan);
        } while ($i < $rows);
    }
    // Return the success notice
    return array(0, $text);
}
开发者ID:edt82,项目名称:ona,代码行数:71,代码来源:vlan_campus.inc.php

示例13: dhcp_lease_add

function dhcp_lease_add($options = "")
{
    // The important globals
    global $conf, $self, $mysql;
    // Version - UPDATE on every edit!
    $version = '1.00';
    printmsg("DEBUG => dhcp_lease_add({$options}) called", 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !($options['raw'] or $options['ip'] and $options['mac'])) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

dhcp_lease_add-v{$version}
Adds a dhcp lease entry into the tracking database

  Synopsis: dhcp_lease_add [KEY=VALUE] ...

  Required:
    raw=TEXT               The raw text from the DHCP log

  Notes:
    Adding a lease here does NOT effect the actual functioning
    DHCP server.  This is purely to keep track of lease information
    derived from the DHCP logfile itself.


EOM
);
    }
    $name = 'N/A';
    if ($options['raw']) {
        // break the line down into its parts
        $line = preg_split("/( on | to | via )/", $options['raw']);
        $mac = $line[2];
        $iptext = $line[1];
        $ip = ip_mangle($iptext, 'numeric');
        // if the second field has mac and a name in parens then break it out
        if (strpos($line[2], '(')) {
            list($mac, $name) = split('[()]', $line[2]);
            $name = trim($name);
        }
        // make sure the mac has been trimmed
        $mac = trim($mac);
        $text = "DHCP Lease Add: IP={$ip} IPTEXT={$line[1]} MAC={$mac} NAME={$name}\n";
        printmsg("DEBUG => {$text}", 3);
    }
    if ($options['ip'] and $options['mac']) {
        $ip = ip_mangle($options['ip'], 'numeric');
        // make sure the mac has been trimmed
        $mac = trim($options['mac']);
        if ($options['name']) {
            $name = $options['name'];
        }
        $text = "DHCP Lease Add: IP={$ip} IPTEXT={$line[1]} MAC={$mac} NAME={$name}\n";
        printmsg("DEBUG => {$text}", 3);
    }
    // Check to see if the IP is already in the database
    //    list($status, $rows, $lease) = db_get_record($mysql, "dhcp_leases", array('IP_ADDRESS' => $ip));
    //    if ($rows) {
    //        printmsg("DEBUG => updating existing record", 2);
    //        list($status, $rows)  = db_update_record($mysql, "dhcp_leases", array('IP_ADDRESS' => $ip), array('MAC' => $mac, 'HOSTNAME' => $name));
    //    } else {
    //        printmsg("DEBUG => inserting new record", 2);
    //        list($status, $rows)  = db_insert_record($mysql, "dhcp_leases", array('IP_ADDRESS' => $ip,
    //                                                                              'IP_TEXT' => $iptext,
    //                                                                              'MAC' => $mac,
    //                                                                              'HOSTNAME' => $name)
    //                                               );
    //    }
    // Return the success notice
    return array(0, $text);
}
开发者ID:edt82,项目名称:ona,代码行数:75,代码来源:dhcp_pool.inc.php

示例14: build_bind_domain

function build_bind_domain($options = "")
{
    // The important globals
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.50';
    printmsg("DEBUG => build_bind_domain({$options}) called", 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !$options['domain']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOF

build_bind_domain-v{$version}
Builds a zone file for a dns server from the database

  Synopsis: build_bind_domain [KEY=VALUE] ...

  Required:
    domain=DOMAIN or ID      build zone file for specified domain



EOF
);
    }
    // Get the domain information
    list($status, $rows, $domain) = ona_find_domain($options['domain']);
    printmsg("DEBUG => build_bind_domain() Domain record: {$domain['domain']}", 3);
    if (!$domain['id']) {
        printmsg("DEBUG => Unknown domain record: {$options['domain']}", 3);
        $self['error'] = "ERROR => Unknown domain record: {$options['domain']}";
        return array(2, $self['error'] . "\n");
    }
    // if for some reason the domains default_ttl is not set, use the one from the $conf['dns']['default_ttl']
    if ($domain['default_ttl'] == 0) {
        $domain['default_ttl'] = $conf['dns']['default_ttl'];
    }
    if ($domain['primary_master'] == '') {
        $domain['primary_master'] = 'localhost';
    }
    // loop through records and display them
    $q = "\n    SELECT  *\n    FROM    dns\n    WHERE   domain_id = {$domain['id']}\n    ORDER BY type";
    // exectue the query
    $rs = $onadb->Execute($q);
    if ($rs === false or !$rs->RecordCount()) {
        $self['error'] = 'ERROR => build_zone(): SQL query failed: ' . $onadb->ErrorMsg();
        printmsg($self['error'], 0);
        $exit += 1;
    }
    $rows = $rs->RecordCount();
    // check if this is a ptr domain that has delegation
    if (strpos(str_replace('in-addr.arpa', '', $domain['fqdn']), '-')) {
        $ptrdelegation = true;
    }
    // Start building the named.conf - save it in $text
    $text = "; DNS zone file for {$domain['fqdn']} built on " . date($conf['date_format']) . "\n";
    // print the opening host comment with row count
    $text .= "; TOTAL RECORDS (count={$rows})\n\n";
    // FIXME: MP do more to ensure that dots are at the end as appropriate
    $text .= "\$ORIGIN {$domain['fqdn']}.\n";
    $text .= "\$TTL {$domain['default_ttl']}\n";
    $text .= ";Serial number is current unix timestamp (seconds since UTC)\n\n";
    // NOTE: There are various ways that one could generate the serial.  The bind book suggests YYYYMMDDXX where XX is 1/100th of the day or some counter in the day.
    // I feel this is too limiting.  I prefer the Unix timestamp (seconds since UTC) method.  TinyDNS uses this method as well and it allows for much more granularity.
    // Referr to the following for some discussion on the topic: http://www.lifewithdjbdns.com/#Migration
    // NOTE: for now I am generating the serial each time the zone is built.  I'm ignoring, and may remove, the one stored in the database.
    $serial_number = time();
    // Build the SOA record
    // FIXME: MP do a bit more to ensure that dots are where they should be
    $text .= "@      IN      SOA   {$domain['primary_master']}. {$domain['admin_email']} ({$serial_number} {$domain['refresh']} {$domain['retry']} {$domain['expiry']} {$domain['minimum']})\n\n";
    // Loop through the record set
    while ($dnsrecord = $rs->FetchRow()) {
        // Dont build records that begin in the future
        if (strtotime($dnsrecord['ebegin']) > time()) {
            continue;
        }
        if (strtotime($dnsrecord['ebegin']) < 0) {
            continue;
        }
        // If there are notes, put the comment character in front of it
        if ($dnsrecord['notes']) {
            $dnsrecord['notes'] = '; ' . str_replace("\n", "; ", $dnsrecord['notes']);
        }
        // If the ttl is empty then make it truely empty
        if ($dnsrecord['ttl'] == 0) {
            $dnsrecord['ttl'] = '';
        }
        // Also, if the records ttl is the same as the domains ttl then dont display it, just to keep it "cleaner"
        if (!strcmp($dnsrecord['ttl'], $domain['default_ttl'])) {
            $dnsrecord['ttl'] = '';
        }
        // Dont print a dot unless hostname has a value
        if ($dnsrecord['name']) {
            $dnsrecord['name'] = $dnsrecord['name'] . '.';
        }
        if ($dnsrecord['type'] == 'A') {
            // Find the interface record
//.........这里部分代码省略.........
开发者ID:dmartinb,项目名称:build_bind,代码行数:101,代码来源:build_bind.inc.php

示例15: subnet_nextip

function subnet_nextip($options = "")
{
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.00';
    printmsg('DEBUG => subnet_del(' . $options . ') called', 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Sanitize options[commit] (default is no)
    $options['commit'] = sanitize_YN($options['commit'], 'N');
    // Return the usage summary if we need to
    if ($options['help'] or !$options['subnet']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

subnet_del-v{$version}
Return the next available IP address on a subnet.

  Synopsis: subnet_nextip [KEY=VALUE] ...

  Required:
    subnet=IP or ID               select subnet by search string

  Optional:
    offset=NUMBER                 Starting offset to find next available IP
    output=[dotted|numeric]       Return the number as a dotted or numeric value
                                  DEFAULT: numeric


EOM
);
    }
    // Find the subnet record we're deleting
    list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
    if ($status or !$rows) {
        $self['error'] = "ERROR => Subnet not found";
        return array(2, $self['error'] . "\n");
    }
    // Create a few variables that will be handy later
    $num_ips = 0xffffffff - $subnet['ip_mask'];
    $last_ip = $subnet['ip_addr'] + $num_ips - 1;
    // check that offset is a number
    if (isset($options['offset']) and !is_numeric($options['offset'])) {
        $self['error'] = "ERROR => Offset must be a numeric number";
        return array(3, $self['error'] . "\n");
    } else {
        $offsetmsg = " beyond offset {$options['offset']}";
    }
    // make sure the offset does not extend beyond the specified subnet
    if ($options['offset'] >= $num_ips - 1) {
        $self['error'] = "ERROR => Offset extends beyond specified subnet boundary";
        return array(4, $self['error'] . "\n");
    }
    if (!isset($options['output'])) {
        $options['output'] = '1';
    } else {
        if ($options['output'] != 'dotted' && $options['output'] != 'numeric') {
            $self['error'] = "ERROR => Output option must be 'dotted' or 'numeric'";
            return array(5, $self['error'] . "\n");
        }
    }
    // Find the first number based on our subnet and offset
    $ip = $subnet['ip_addr'] + $options['offset'];
    // Make sure we skip past the subnet IP to the first usable IP
    if ($ip == $subnet['ip_addr']) {
        $ip++;
    }
    // Start looping through our IP addresses until we find an available one
    while ($ip <= $last_ip) {
        // Find out if the ip is used in an interface
        list($status, $rows, $interfaces) = db_get_records($onadb, 'interfaces', array('ip_addr' => $ip));
        // If we find a free address.. check that it is not in a DHCP pool
        if (!$rows) {
            list($status, $rows, $pool) = db_get_record($onadb, 'dhcp_pools', "{$ip} >= ip_addr_start AND {$ip} <= ip_addr_end");
            if ($rows) {
                $ip = $pool['ip_addr_end'];
            } else {
                break;
            }
        }
        $ip++;
        // increment by one and check again
    }
    // If we checked all the IPs, make sure we are not on the broadcast IP of the subnet
    if ($ip == $last_ip + 1) {
        $self['error'] = "ERROR => No available IP addresses found on subnet{$offsetmsg}";
        return array(5, $self['error'] . "\n");
    }
    // return the IP
    return array(0, ip_mangle($ip, $options['output']) . "\n");
}
开发者ID:edt82,项目名称:ona,代码行数:92,代码来源:subnet.inc.php


注:本文中的parse_options函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。