diff options
author | root <root@colazero.tele.tg18.gathering.org> | 2018-03-21 14:13:32 +0100 |
---|---|---|
committer | root <root@colazero.tele.tg18.gathering.org> | 2018-03-21 14:13:32 +0100 |
commit | 05e09f3b63269a48d1beb0dc9900b180101cec7f (patch) | |
tree | b96dbc2cc53a79968e4c60a7b3a729ea4d937299 /web/api/write/network-add | |
parent | c6d676b8d07dcd081626ad86849900977327bbb7 (diff) | |
parent | 8bee35e8be72510d8bdc7ed5de49a8d031e829a5 (diff) |
Merge branch 'master' of github.com:tech-server/gondul
Diffstat (limited to 'web/api/write/network-add')
-rw-r--r-- | web/api/write/network-add | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/web/api/write/network-add b/web/api/write/network-add new file mode 100644 index 0000000..d1aab4e --- /dev/null +++ b/web/api/write/network-add @@ -0,0 +1,49 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +#use CGI qw(fatalsToBrowser); +use DBI; +use lib '/opt/gondul/include'; +use nms; +use nms::web qw(%get_params %json finalize_output get_input $dbh); +use nms::util qw(guess_placement); +use strict; +use warnings; +use JSON; +use Data::Dumper; +use nms::oplog qw(oplog); + +$nms::web::cc{'max-age'} = "0"; + +my $in = get_input(); +my @tmp = @{JSON::XS::decode_json($in)}; + +my @added; +my @dups; + +my $sth = $nms::web::dbh->prepare("SELECT name FROM networks WHERE name=?"); + +foreach my $tmp2 (@tmp) { + my %network = %{$tmp2}; + my $affected = 0; + my %template = (); + if (not defined($network{'name'})) { + next; + } + + $sth->execute( $network{'name'}); + while ( my @row = $sth->fetchrow_array ) { + $affected += 1; + } + + if ($affected == 0) { + $nms::web::dbh->do("INSERT INTO NETWORKS (name) VALUES ('$network{'name'}');"); + push @added, $network{'name'}; + oplog("\"" . $network{'name'} . "\"", "Network added: " . $network{'name'}); + } +} + +$json{'networks_addded'} = \@added; + +print "X-ban: /api/.*\n"; +finalize_output(); |