experimental restconf
This commit is contained in:
parent
dfa30aa39c
commit
0356b2225f
13 changed files with 2886 additions and 62 deletions
|
|
@ -27,7 +27,7 @@ LIBS = @LIBS@
|
|||
|
||||
SHELL = /bin/sh
|
||||
|
||||
SUBDIRS = cli backend dbctrl netconf xmldb
|
||||
SUBDIRS = cli backend dbctrl netconf xmldb restconf
|
||||
|
||||
.PHONY: all clean depend install $(SUBDIRS)
|
||||
|
||||
|
|
|
|||
|
|
@ -284,11 +284,14 @@ terminate(clicon_handle h)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* usage
|
||||
/*! Usage help routine
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] argv0 command line
|
||||
*/
|
||||
static void
|
||||
usage(char *argv0, clicon_handle h)
|
||||
usage(clicon_handle h,
|
||||
char *argv0,
|
||||
|
||||
{
|
||||
char *netconfdir = clicon_netconf_dir(h);
|
||||
|
||||
|
|
@ -328,14 +331,14 @@ main(int argc, char **argv)
|
|||
while ((c = getopt(argc, argv, NETCONF_OPTS)) != -1)
|
||||
switch (c) {
|
||||
case 'h' : /* help */
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'D' : /* debug */
|
||||
debug = 1;
|
||||
break;
|
||||
case 'f': /* override config file */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
|
||||
break;
|
||||
case 'S': /* Log on syslog */
|
||||
|
|
@ -369,11 +372,11 @@ main(int argc, char **argv)
|
|||
break;
|
||||
case 'd': /* Plugin directory */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_NETCONF_DIR", optarg);
|
||||
break;
|
||||
default:
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
}
|
||||
argc -= optind;
|
||||
|
|
|
|||
96
apps/restconf/Makefile.in
Normal file
96
apps/restconf/Makefile.in
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#
|
||||
# Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
|
||||
#
|
||||
# This file is part of CLIXON.
|
||||
#
|
||||
# CLIXON is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# CLIXON is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with CLIXON; see the file LICENSE. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
wwwdir = /www-data
|
||||
libexecdir = @libexecdir@
|
||||
localstatedir = @localstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
|
||||
SH_SUFFIX = @SH_SUFFIX@
|
||||
CLIXON_MAJOR = @CLIXON_VERSION_MAJOR@
|
||||
CLIXON_MINOR = @CLIXON_VERSION_MINOR@
|
||||
|
||||
# Use this clixon lib for linking
|
||||
CLIXON_LIB = libclixon.so.$(CLIXON_MAJOR).$(CLIXON_MINOR)
|
||||
|
||||
# For dependency
|
||||
LIBDEPS = $(top_srcdir)/lib/src/$(CLIXON_LIB)
|
||||
|
||||
LIBS = -L$(top_srcdir)/lib/src @LIBS@ -l:$(CLIXON_LIB)
|
||||
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
|
||||
INCLUDES = -I. -I$(top_srcdir)/lib/src -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@
|
||||
|
||||
SRC = restconf_lib.c
|
||||
|
||||
OBJS = $(SRC:.c=.o)
|
||||
|
||||
APPSRC = restconf_main.c
|
||||
APPOBJ = $(APPSRC:.c=.o)
|
||||
APPL = clixon_restconf
|
||||
|
||||
all: $(APPL)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) *.core $(APPL) $(APPOBJ)
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile *~ .depend
|
||||
|
||||
# Put demon in bin
|
||||
# Put other executables in libexec/
|
||||
# Also create a libexec/ directory for writeable/temporary files.
|
||||
# Put config file in etc/
|
||||
install: $(APPL)
|
||||
install -d $(DESTDIR)$(wwwdir)
|
||||
install $(APPL) $(DESTDIR)$(wwwdir)
|
||||
|
||||
install-include:
|
||||
|
||||
uninstall:
|
||||
rm -f $(wwwdir)/$(APPL)
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .o
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDES) -D__PROGRAM__=\"$(APPL)\" $(CPPFLAGS) $(CFLAGS) -c $<
|
||||
|
||||
$(APPL) : $(APPOBJ) $(OBJS) $(LIBDEPS)
|
||||
$(CC) $(LDFLAGS) $(APPOBJ) $(OBJS) $(LIBS) -o $@
|
||||
|
||||
TAGS:
|
||||
find . -name '*.[chyl]' -print | etags -
|
||||
|
||||
depend:
|
||||
$(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(SRC) $(APPSRC) > .depend
|
||||
|
||||
#include .depend
|
||||
|
||||
32
apps/restconf/README
Normal file
32
apps/restconf/README
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
Work-in-progress restconf server
|
||||
|
||||
See draft-ietf-netconf-restconf-13.txt
|
||||
|
||||
Example nginx-default file:
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server ipv6only=on;
|
||||
|
||||
index index.html index.htm;
|
||||
|
||||
# Make site accessible from http://localhost/
|
||||
server_name localhost;
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
# First attempt to serve request as file, then
|
||||
# as directory, then fall back to displaying a 404.
|
||||
try_files $uri $uri/ =404;
|
||||
# Uncomment to enable naxsi on this location
|
||||
# include /etc/nginx/naxsi.rules
|
||||
|
||||
}
|
||||
|
||||
# pass the REST API to FastCGI server
|
||||
location /restconf {
|
||||
root /usr/share/nginx/html/restconf;
|
||||
fastcgi_pass unix:/www-data/fastcgi_api.sock;
|
||||
include fastcgi_params;
|
||||
}
|
||||
}
|
||||
1133
apps/restconf/restconf_lib.c
Normal file
1133
apps/restconf/restconf_lib.c
Normal file
File diff suppressed because it is too large
Load diff
50
apps/restconf/restconf_lib.h
Normal file
50
apps/restconf/restconf_lib.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
*
|
||||
* $COPYRIGHTSTATEMENT$
|
||||
*
|
||||
* $LICENSE$
|
||||
* This is backend headend sender code, ie communication with a pmagent
|
||||
*/
|
||||
|
||||
#ifndef _RESTCONF_LIB_H_
|
||||
#define _RESTCONF_LIB_H_
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
#define USER_COOKIE "c-user" /* connected user cookie */
|
||||
#define WWW_USER "root"
|
||||
#define WWW_PASSWD "9rundpaj" // XXX
|
||||
#define DEFAULT_TEMPLATE "nordunet" /* XXX Default sender template must be in conf */
|
||||
#define CONFIG_FILE "/usr/local/etc/grideye.conf"
|
||||
#define NETCONF_BIN "/usr/local/bin/clixon_netconf"
|
||||
#define NETCONF_OPTS "-qS"
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int notfound(FCGX_Request *r);
|
||||
|
||||
char *ival2influxdb(char *ival);
|
||||
int openfile(FCGX_Request *r, char *dir, char *filename);
|
||||
int errorfn(FCGX_Request *r, char *root, char *reason);
|
||||
int str2cvec(char *string, char delim1, char delim2, cvec **cvp);
|
||||
int netconf_rpc(cbuf *result, char *format, ...);
|
||||
int netconf_cmd(FCGX_Request *r, char *data);
|
||||
int cli_rpc(cbuf *result, char *mode, char *format, ...);
|
||||
int cli_cmd(FCGX_Request *r, char *mode, char *cmd);
|
||||
int check_credentials(char *passwd, cxobj *cx);
|
||||
int get_db_entry(char *entry, char *attr, char *val, cxobj **cx);
|
||||
int get_user_cookie(char *cookiestr, char *attribute, char **val);
|
||||
int test(FCGX_Request *r, int dbg);
|
||||
cbuf *readdata(FCGX_Request *r);
|
||||
|
||||
int create_database(char *server_addr, char *database, char *www_user, char *www_passwd);
|
||||
int create_db_user(char *server_addr, char *database, char *user, char *password, char *www_user, char *www_passwd);
|
||||
int url_post(char *url, char *username, char *passwd, char *putdata,
|
||||
char *expect, char **getdata);
|
||||
int b64_decode(const char *b64_buf, char *buf, size_t buf_len);
|
||||
int metric_spec_description(char *metric, char **result);
|
||||
int metric_spec_units(char *metric, char **result);
|
||||
|
||||
#endif /* _RESTCONF_LIB_H_ */
|
||||
1386
apps/restconf/restconf_main.c
Normal file
1386
apps/restconf/restconf_main.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue