} } /* * Actions */ if (isset($_REQUEST['save'])) { if (get_request('nodeid')) { $nodeid = get_request('nodeid'); DBstart(); $result = update_node($nodeid, get_request('name'), get_request('ip'), get_request('port')); $result = DBend($result); show_messages($result, _('Node updated'), _('Cannot update node')); $audit_action = AUDIT_ACTION_UPDATE; } else { DBstart(); $nodeid = add_node(get_request('new_nodeid'), get_request('name'), get_request('ip'), get_request('port'), get_request('nodetype'), get_request('masterid')); $result = DBend($nodeid); show_messages($result, _('Node added'), _('Cannot add node')); $audit_action = AUDIT_ACTION_ADD; } if ($result) { add_audit($audit_action, AUDIT_RESOURCE_NODE, 'Node [' . $_REQUEST['name'] . '] id [' . $nodeid . ']'); unset($_REQUEST['form']); } } elseif (isset($_REQUEST['delete'])) { DBstart(); $result = delete_node($_REQUEST['nodeid']); $result = DBend($result); show_messages($result, _('Node deleted'), _('Cannot delete node')); if ($result) { add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_NODE, 'Node [' . $node['name'] . '] id [' . $node['nodeid'] . ']');
exit; } if ($argv[1] == "--scan-repo") { scan_software_repo($argv[2]); exit; } if ($argv[1] == "--delete-repo") { delete_software_repo($argv[2]); exit; } if ($argv[1] == "--delete-articapkg") { delete_artica_repo($argv[2], $argv[3]); exit; } if ($argv[1] == "--add-node") { add_node(); exit; } if ($argv[1] == "--tests-notifs") { send_notifications("Test From Artica Meta", "This is a test"); exit; } if ($argv[1] == "--ping-host") { ping_host($argv[2]); exit; } if ($argv[1] == "--ping-group") { ping_group($argv[2]); exit; } if (strlen($argv[1]) > 2) {
oci_close($connection); print_r(oci_error()); die("dasdas"); } else { switch ($action) { case "getNodeTypes": get_node_types(); break; case "getPylonsByPowerLineId": get_pylons_by_power_line_id($postdata); break; case "getBranches": get_branches($postdata); break; case "addNode": add_node($postdata); break; case "editNode": edit_node($postdata); break; case "getConnectionNodesByBaseNodeId": get_connection_nodes_by_base_node_id($postdata); break; case "addConnectionNode": add_connection_node($postdata); break; case "deleteConnectionNode": delete_connection_node($postdata); break; } oci_close($connection);
function show_bgpmap($data) { // return a bgp map in a png file global $graph, $nodes, $edges; $graph = new Image_GraphViz(true, array(), "BGPMAP"); $nodes = array(); $edges = array(); function escape($label) { $label = str_replace("&", "&", $label); $label = str_replace(">", ">", $label); $label = str_replace("<", "<", $label); return $label; } function add_node($_as, $fillcolor = NULL, $label = NULL, $shape = NULL) { global $nodes, $graph; if (!array_key_exists($_as, $nodes)) { if (!$label) { $label = "AS" . $_as; } $label = '<table cellborder="0" border="0" cellpadding="0" cellspacing="0"><tr><td align="center">' . str_replace("\r", "<br/>", escape($label)) . '</td></tr></table>'; $attrs = array('style' => 'filled', 'fontsize' => '10', 'label' => $label); if ($shape) { $attrs['shape'] = $shape; } if ($fillcolor) { $attrs['fillcolor'] = $fillcolor; } $nodes[$_as] = $attrs; $graph->addNode($_as, $nodes[$_as]); } return $nodes[$_as]; } function add_edge($_previous_as, $_as, $attrs = array()) { global $edges, $graph; $edge_array = array($_previous_as => $_as); if (!array_key_exists(gek($_previous_as, $_as), $edges)) { $attrs['splines'] = "true"; $edge = array($edge_array, $attrs); $graph->addEdge($edge_array, $attrs); $edges[gek($_previous_as, $_as)] = $edge; } else { if (array_key_exists('label', $attrs)) { $e =& $edges[gek($_previous_as, $_as)]; $label_without_star = str_replace("*", "", $attrs['label']); $labels = explode("\r", $e[1]['label']); if (!in_array($label_without_star . "*", $labels)) { $tmp_labels = array(); foreach ($labels as $l) { if (!startsWith($l, $label_without_star)) { $labels[] = $l; } } $labels = array_merge(array($attrs['label']), $tmp_labels); $cmp = function ($a, $b) { return endsWith($a, "*") ? -1 : 1; }; usort($labels, $cmp); $label = escape(implode("\r", $labels)); $e[1]['label'] = $label; } } } return $edges[gek($_previous_as, $_as)]; } function gek($_previous_as, $_as) { // Generate Edge Key return $_previous_as . '_' . $_as; } foreach ($data as $host => $asmaps) { add_node($host, "#F5A9A9", strtoupper($host), "box"); if ($host == Config::NODE_NAME) { $node = add_node(Config::ASN, "#F5A9A9"); $edge = add_edge(Config::ASN, $host, array('color' => "red", 'style' => "bold")); } } $previous_as = NULL; $hosts = array_keys($data); foreach ($data as $host => $asmaps) { $first = true; foreach ($asmaps as $asmap) { $previous_as = $host; $color = "#" . dechex(rand(0, 16777215)); $hop = false; $hop_label = ""; foreach ($asmap as $_as) { if ($_as == $previous_as) { continue; } if (!$hop) { $hop = true; if (!in_array($_as, $hosts)) { $hop_label = $_as; if ($first) { $hop_label = $hop_label . "*"; } continue; } else { $hop_label = ""; } } if (!strpos($_as, '.')) { add_node($_as, $first ? "#F5A9A9" : "white"); } else { add_node($_as, $first ? "#F5A9A9" : "white", NULL, "box"); } if ($hop_label) { $attrs = array('fontsize' => "7", 'label' => $hop_label); } else { $attrs = array('fontsize' => "7"); } $hop_label = ""; if ($first) { $attrs['style'] = "bold"; $attrs['color'] = "red"; } else { if (!array_key_exists(gek($previous_as, $_as), $edges) || $edges[gek($previous_as, $_as)][1]['color'] != "red") { $attrs['style'] = "dashed"; $attrs['color'] = $color; } } add_edge($previous_as, $_as, $attrs); $previous_as = $_as; } $first = false; } } return $graph->image("jpeg"); }
access_deny(); } if (isset($_REQUEST['save'])) { $result = false; if (isset($_REQUEST['nodeid'])) { $audit_action = AUDIT_ACTION_UPDATE; DBstart(); $result = update_node($_REQUEST['nodeid'], $_REQUEST['new_nodeid'], $_REQUEST['name'], $_REQUEST['timezone'], $_REQUEST['ip'], $_REQUEST['port'], $_REQUEST['slave_history'], $_REQUEST['slave_trends']); $result = DBend($result); $nodeid = $_REQUEST['nodeid']; show_messages($result, S_NODE_UPDATED, S_CANNOT_UPDATE_NODE); } else { $audit_action = AUDIT_ACTION_ADD; $_REQUEST['masterid'] = isset($_REQUEST['masterid']) ? $_REQUEST['masterid'] : null; DBstart(); $nodeid = add_node($_REQUEST['new_nodeid'], $_REQUEST['name'], $_REQUEST['timezone'], $_REQUEST['ip'], $_REQUEST['port'], $_REQUEST['slave_history'], $_REQUEST['slave_trends'], $_REQUEST['node_type'], $_REQUEST['masterid']); $result = DBend($nodeid); show_messages($result, S_NODE_ADDED, S_CANNOT_ADD_NODE); } add_audit_if($result, $audit_action, AUDIT_RESOURCE_NODE, 'Node [' . $_REQUEST['name'] . '] id [' . $nodeid . ']'); if ($result) { unset($_REQUEST['form']); } } else { if (isset($_REQUEST['delete'])) { $node_data = get_node_by_nodeid($_REQUEST['nodeid']); DBstart(); $result = delete_node($_REQUEST['nodeid']); $result = DBend($result); show_messages($result, S_NODE_DELETED, S_CANNOT_DELETE_NODE); add_audit_if($result, AUDIT_ACTION_DELETE, AUDIT_RESOURCE_NODE, 'Node [' . $node_data['name'] . '] id [' . $node_data['nodeid'] . ']');