Commit efa78969 authored by Otto Jonassen Wittner's avatar Otto Jonassen Wittner
Browse files

Map and db-api generalized, conf.json added

parent ff56ef36
Pipeline #41241 passed with stages
in 51 seconds
......@@ -3,6 +3,11 @@ use CGI;
#use CGI qw/:standard -debug/;
#use WWW::Curl::Easy
my $credfile="../etc/loyndom"; # Path to file with ES credentials
my $es_host="localhost:9200";
my $es_ro_user;
my $es_ro_password;
my $q = CGI->new;
my $yesterday= `date --date yesterday "+%Y-%m-%d"`;
chomp($yesterday);
......@@ -22,6 +27,25 @@ if ( $debug > 0 ){
print $q->header('application/json');
}
# Read credentials file
my $creds;
{
# local $/;
if ( open my $fh, '<' . $credfile ) {
print "Credfile found.\n" if ($debug > 0);
while (<$fh>) {
if ( /(\w+)\s*=\s*'(.*)'/ ) { # Assume line format: var-name='value'
# print if ($debug > 0);
print $1, " ", $2, "\n" if ($debug > 0);
$es_host = $2 if ($1 eq "es_host");
$es_ro_user = $2 if ($1 eq "es_ro_user");
$es_ro_password = $2 if ($1 eq "es_ro_password");
}
}
}
}
# my $curl = WWW::Curl::Easy->new;
# $curl->setopt(CURLOPT_HEADER,1);
......@@ -103,7 +127,13 @@ if ( $type eq "jitter" ){
print $search."\n" if $debug > 0;
my $url='http://admin:no+nz+br@localhost:9200/' . $index . '/_search?';
#my $url='http://admin:no+nz+br@localhost:9200/' . $index . '/_search?';
# Build url
my $url='https://';
$url .= $es_ro_user if ($es_ro_user);
$url .= ':' . $es_ro_password if ($es_ro_password);
$url .= '@' if ($es_ro_user);
$url .= $es_host . '/' . $index . '/_search?';
# $curl->setopt(CURLOPT_URL, $url);
# my $response_body;
......@@ -120,7 +150,7 @@ my $url='http://admin:no+nz+br@localhost:9200/' . $index . '/_search?';
# print("An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n");
#}
my $cmd='curl -X POST -H "Content-Type: application/json" "' . $url . '" -d \'' . $search . '\' 2>/dev/null';
my $cmd='curl -X POST -H "Content-Type: application/json" "' . $url . '" --insecure -d \'' . $search . '\' 2>/dev/null';
print "<p>$cmd\n" if $debug > 0;
print `$cmd`;
......
......@@ -9,10 +9,12 @@ use DBI;
use Socket;
use JSON;
use CGI::Simple;
use CGI;
#use CGI::Carp 'fatalsToBrowser';
my $q = CGI::Simple->new;
my $q = CGI->new;
my $config_file="conf.json";
my $debug=parm('debug');
if ( $debug > 0 ){
......@@ -25,7 +27,20 @@ my $file=parm('file');
printf " $r_ip $r_host $variant %s %s\n", $q->remote_addr(), $q->remote_host() if $debug;
my $config_dir="/var/lib/microdep/$variant";
# Get config from file
my $config;
{
local $/;
if ( open my $fh, '<' . $config_file ) {
$config = decode_json(<$fh>);
}
}
my $config_dir="/var/lib/microdep/$variant"; # Set default config dir
if ( $config->{$variant} ) {
$config_dir=$config->{$variant}; # Apply config dir from configfile
}
my $mp_list="$config_dir/etc/mp-address.txt";
my $database="$config_dir/etc/microdep.db";
......
......@@ -6,11 +6,12 @@
#use v5.10;
use strict;
use CGI::Simple;
#use CGI::Simple;
use CGI;
#use CGI::Carp 'fatalsToBrowser';
use JSON;
my $q = CGI::Simple->new;
my $q = CGI->new;
my $config_file="conf.json";
......
......@@ -950,7 +950,7 @@ function get_topology(){
var start = new Date($("#datepicker").val() + " 00:00:00").getTime()/1000;
var end= new Date($("#datepicker").val() + " 23:59:59").getTime()/1000;
var network=parms.net;
var url="microdep-config.cgi?variant=mp-" + network + "&start=" + start + "&end=" + end;
var url="microdep-config.cgi?variant=" + network + "&start=" + start + "&end=" + end;
$.getJSON( url,
function(topology){
draw_topology( topology );
......@@ -958,7 +958,7 @@ function get_topology(){
// draw_topology( duplex_topology( topology) );
}).fail( function( jqxhr, textStatus, error ) {
var err = textStatus + ", " + error;
console.log( "Request" + url + " Failed: " + err );
console.log( "Request " + url + " Failed: " + err );
});
}
......@@ -1375,7 +1375,7 @@ function load_name_to_address(){
if ( ! name_loaded[network] ){
var config_url='microdep-config.cgi';
var url= config_url + "?secret=virre-virre-vapp&variant=mp-" + network + "&file=mp-address.txt";
var url= config_url + "?secret=virre-virre-vapp&variant=" + network + "&file=mp-address.txt";
$.get( url, function( lines ){
for ( var line of lines.split(/\n/) ){
var l=line.split(/\s+/);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment