&1 | /usr/bin/grep -c "pw: unknown group"` -gt 0 ]; then /usr/sbin/pw groupadd {$pkg_group} -g {$pkg_gid} fi if [ `/usr/sbin/pw usershow {$pkg_login} 2>&1 | /usr/bin/grep -c "pw: no such user"` -gt 0 ]; then /usr/sbin/pw useradd {$pkg_login} -u {$pkg_uid} -g {$pkg_gid} -c "{$pkg_gecos}" -d {$pkg_homedir} -s {$pkg_shell} fi /bin/mkdir -p {$bgpd_config_base} /usr/sbin/chown -R root:wheel {$bgpd_config_base} /bin/chmod 0600 {$bgpd_config_base}/bgpd.conf NUMBGPD=`/bin/ps auxw | /usr/bin/grep -c '[b]gpd.*parent'` if [ \${NUMBGPD} -lt 1 ] ; then {$carp_ip_status_check} {$pkg_bin}/bgpd -f {$bgpd_config_base}/bgpd.conf else {$pkg_bin}/bgpctl reload fi EOF; write_rcfile(array( "file" => "bgpd.sh", "start" => $rc_file_start, "stop" => $rc_file_stop ) ); unset($rc_file_start, $rc_file_stop); $_gb = exec("/sbin/sysctl net.inet.ip.ipsec_in_use=1"); // Is bgpd process running? If so, reload, else start. // Kick off newly created rc.d script if (is_ipaddr($openbgpd_conf['carpstatusip'])) { $status = openbgpd_get_carp_status_by_ip($openbgpd_conf['carpstatusip']); switch (strtoupper($status)) { // Stop the service if the VIP is in BACKUP or INIT state. case "BACKUP": case "INIT": stop_service("bgpd"); break; // Start the service if the VIP is MASTER state. case "MASTER": // Assume it's up if the status can't be determined. default: openbgpd_restart(); break; } } else { openbgpd_restart(); } conf_mount_ro(); } function openbgpd_restart() { if (is_openbgpd_running() == true) { exec("{$pkg_bin}/bgpctl reload"); } else { exec("{$pkg_bin}/bgpd -f {$bgpd_config_base}/bgpd.conf"); } } // Get the raw openbgpd config file for manual inspection/editing function openbgpd_get_raw_config() { $conf = PKG_BGPD_CONFIG_BASE . "/bgpd.conf"; if (file_exists($conf)) { return file_get_contents($conf); } else { return ""; } } // Serialize the raw openbgpd config file to config.xml function openbgpd_put_raw_config($conffile) { global $config; if ($conffile == "") { unset($config['installedpackages']['openbgpd']['rawconfig']); } else { $config['installedpackages']['openbgpd']['rawconfig'] = array(); $config['installedpackages']['openbgpd']['rawconfig']['item'] = explode("\n", $_POST['openbgpd_raw']); //$config['installedpackages']['openbgpd']['rawconfig'] = $conffile; } } function check_group_usage($groupname) { global $config, $g; if ($config['installedpackages']['openbgpd']['config']) { $openbgpd_conf = &$config['installedpackages']['openbgpd']['config'][0]; } if ($config['installedpackages']['openbgpd']['config'][0]['row']) { $openbgpd_rows = &$config['installedpackages']['openbgpd']['config'][0]['row']; } if ($config['installedpackages']['openbgpdgroups']['config']) { $openbgpd_groups = &$config['installedpackages']['openbgpdgroups']['config']; } if ($config['installedpackages']['openbgpdneighbors']['config']) { $openbgpd_neighbors = &$config['installedpackages']['openbgpdneighbors']['config']; } if (is_array($openbgpd_groups)) { foreach ($openbgpd_groups as $group) { foreach ($openbgpd_neighbors as $neighbor) { if ($neighbor['groupname'] == $group['name']) { return $neighbor['groupname']; } } } } return ""; } function bgpd_validate_input() { global $config, $g, $input_errors; if (!empty($_POST['asnum']) && !is_numeric($_POST['asnum'])) { $input_errors[] = "AS must be entered as a number only."; } if (!empty($_POST['routerid']) && !is_ipaddr($_POST['routerid'])) { $input_errors[] = "Router ID must be an IP address."; } if (!empty($_POST['holdtime']) && !is_numeric($_POST['holdtime'])) { $input_errors[] = "Holdtime must be entered as a number."; } if (!empty($_POST['listenip']) && !is_ipaddr($_POST['listenip'])) { $input_errors[] = "Listen IP must be an IP address or blank to bind to all IPs."; } } function bgpd_validate_group() { global $config, $g, $id, $input_errors; if (!is_numeric($_POST['remoteas'])) { $input_errors[] = "Remote AS must be entered as a number only."; } if ($_POST['name'] == "") { $input_errors[] = "You must enter a name."; } $_POST['name'] = remove_bad_chars($_POST['name']); } function remove_bad_chars($string) { return preg_replace('/[^a-z|_|0-9]/i','', $string); } function grey_out_value_boxes() { echo << function grey_out_value_boxes() { var x = 0; for(x=0; x<99; x++) { if( \$('parameters' + x) ) { var fieldvalue = $('parameters' + x).options[$('parameters' + x).selectedIndex].text; var length = fieldvalue.length; length = length -2; var last_two = fieldvalue.substring(length); var without_last_two = fieldvalue.substring(0,length); if( \$('parmvalue' + x) ) { if(last_two != ' X') { \$('parmvalue' + x).value = ''; \$('parmvalue' + x).disabled = true; } else { \$('parmvalue' + x).disabled = false; } } } } var timerID = setTimeout("grey_out_value_boxes()", 1200); } grey_out_value_boxes(); EOF; } function is_openbgpd_running() { $status = shell_exec("/bin/ps auxw | /usr/bin/grep -c '[b]gpd.*parent'"); if (intval($status) > 0) { return true; } else { return false; } } function openbgpd_get_carp_status_by_ip($ipaddr) { $iface = trim(find_carp_interface($ipaddr)); if ($iface) { $status = get_carp_interface_status($iface); // If there is no status for that interface, return null. if (!$status) { $status = null; } } else { // If there is no VIP by that IP, return null. $status = null; } return $status; } function openbgpd_plugin_carp($pluginparams) { global $config; require_once("service-utils.inc"); // Called when a CARP interface changes state // $pluginparams['event'] either 'rc.carpmaster' or 'rc.carpbackup' // $pluginparams['interface'] contains the affected interface /* If there is no bgp config, then stop */ if (is_array($config['installedpackages']['openbgpd']['config'])) { $openbgpd_conf = &$config['installedpackages']['openbgpd']['config'][0]; } else { return null; } /* If there is no properly configured CARP status check IP, then stop */ if (!is_ipaddr($openbgpd_conf['carpstatusip'])) { return null; } list($vhid, $iface) = explode("@", trim($pluginparams['interface'])); $friendly = convert_real_interface_to_friendly_interface_name($iface); $carp_iface = "{$friendly}_vip${vhid}"; /* If this CARP transition is not from the IP address to check, then stop. */ if (get_interface_ip($carp_iface) != $openbgpd_conf['carpstatusip']) { return null; } /* Start or stop the service as needed based on the CARP transition. */ if ($pluginparams['event'] == "rc.carpmaster") { start_service("bgpd"); } elseif ($pluginparams['event'] == "rc.carpbackup") { stop_service("bgpd"); } } ?>