Esempio n. 1
0
 def post(self):
     data = request.get_json()
     if 'group_name' not in data:
         return jsonify(message="Missing key 'group_name'"), 400
     if rancid_conf.check_value(data['group_name']) == 1:
         return jsonify(message="BAD FORMAT 'group_name'"), 400
     try:
         content = read_file(CONFIG_FILE_PATH)
         LIST_OF_GROUPS = rancid_conf.get_value(content, "LIST_OF_GROUPS")
         if rancid_conf.if_exist(data['group_name'], LIST_OF_GROUPS) == 1:
             return jsonify(message="'group_name' already exist"), 400
         new_content = rancid_conf.set_value(
             content, "LIST_OF_GROUPS",
             rancid_conf.add_group(LIST_OF_GROUPS, data["group_name"]))
         write_file(CONFIG_FILE_PATH, new_content)
         groups = rancid_conf.get_value(new_content, "LIST_OF_GROUPS")
         rancid_conf.excecute_cmd("/opt/rancid/bin/rancid-cvs")
         return jsonify(groups=groups), 200
     except IOError as e:
         return jsonify(message=str(e)), 500
Esempio n. 2
0
    def delete(self):
        data = request.get_json()
        if 'group_name' not in data:
            return jsonify(message="Missing key 'group_name'"), 400
        try:
            content = read_file(CONFIG_FILE_PATH)
            new_content = rancid_conf.set_value(
                content, "LIST_OF_GROUPS",
                rancid_conf.remove_group(
                    rancid_conf.get_value(content, "LIST_OF_GROUPS"),
                    data["group_name"]))
            write_file(CONFIG_FILE_PATH, new_content)
            groups = rancid_conf.get_value(new_content, "LIST_OF_GROUPS")

            basedir = rancid_conf.get_value(content, "BASEDIR")
            path_groups = basedir + "/" + data["group_name"]
            logdir = basedir + "/logs/" + data["group_name"]
            #            cvsroot = basedir+"/SVN/"+data["group_name"] #gerer le cas CVS ou SVN ou GIT ajout de variable
            rancid_conf.excecute_cmd("./sup.sh " + logdir + "  " +
                                     path_groups + " ")

            return jsonify(groups=groups), 200
        except IOError as e:
            return jsonify(message=str(e)), 500
Esempio n. 3
0
 def get(self):
     try:
         groups = []
         content = read_file(CONFIG_FILE_PATH)
         list_of_groups = rancid_conf.get_value(content, "LIST_OF_GROUPS")
         list_of_groups_split = list_of_groups.split()
         for i in range(len(list_of_groups_split)):
             groups.append(
                 count_device(
                     read_file(ROUTER_FILE_PREFIX +
                               list_of_groups_split[i] + '/router.db'),
                     list_of_groups_split[i]))
         return jsonify(groups=groups), 200
     except IOError as e:
         return jsonify(message=str(e)), 500
Esempio n. 4
0
File: log.py Progetto: rancidGUI/WUI
from rancid_conf import rancid_conf
from flask import jsonify, request
from flask.views import MethodView
from reader_writer.reader import read_file
from reader_writer.writer import write_file
from router_db.router_db import count_device
from wui_log.logs import get_log
from wui_log.logs import delete_log
import pprint
import os

ROUTER_FILE_PREFIX = rancid_conf.get_value(read_file("./conf.ini"),"ROUTER_DB_DIR")
class Log(MethodView):

    def get(self):
        try:
            error = []
            mtime = lambda f: os.stat(os.path.join(ROUTER_FILE_PREFIX + "logs/", f)).st_mtime
            log = list(sorted(os.listdir(ROUTER_FILE_PREFIX + "logs/"), key=mtime))
            for i in reversed(log):
                test = get_log(ROUTER_FILE_PREFIX + "logs/" + i)
                if test['error'] != "":
                    error.append(test)
            if (len(error) == 0):
                error = "No Error"
            return jsonify(log=error), 200
        except IOError as e:
            return jsonify(message=str(e)), 500

    def delete(self, param):
        try:
Esempio n. 5
0
from rancid_conf import rancid_conf
from flask import jsonify, request
from flask.views import MethodView
from reader_writer.reader import read_file
from reader_writer.writer import write_file
from router_db.router_db import count_device
import pprint

CONFIG_FILE_PATH = rancid_conf.get_value(read_file("./conf.ini"),
                                         "RANCID_CONF_PATH")
ROUTER_FILE_PREFIX = rancid_conf.get_value(read_file("./conf.ini"),
                                           "ROUTER_DB_DIR")


class Groups(MethodView):
    def get(self):
        try:
            groups = []
            content = read_file(CONFIG_FILE_PATH)
            list_of_groups = rancid_conf.get_value(content, "LIST_OF_GROUPS")
            list_of_groups_split = list_of_groups.split()
            for i in range(len(list_of_groups_split)):
                groups.append(
                    count_device(
                        read_file(ROUTER_FILE_PREFIX +
                                  list_of_groups_split[i] + '/router.db'),
                        list_of_groups_split[i]))
            return jsonify(groups=groups), 200
        except IOError as e:
            return jsonify(message=str(e)), 500
Esempio n. 6
0
from cloginrc_conf import cloginrc_conf
from flask import jsonify, request
from flask.views import MethodView
from reader_writer.reader import read_file
from reader_writer.writer import write_file
from rancid_conf.rancid_conf import get_value

CONFIG_FILE_PATH = get_value(read_file("./conf.ini"), "CLOGINRC_FILE_PATH")


class Cloginrc(MethodView):
    def get(self, param):

        try:
            content = read_file(CONFIG_FILE_PATH)
            directives = cloginrc_conf.get_value(content, param)
            return jsonify(directives=directives), 200
        except IOError as e:
            return jsonify(message=str(e)), 500

    def post(self, param):
        data = request.get_json()
        if 'directives' not in data:
            return jsonify(message="Missing key 'directives'"), 400
        if cloginrc_conf.check_value(CONFIG_FILE_PATH,
                                     data["directives"]) == 1:
            return jsonify(
                message="'directives' already exist in the file"), 400
        try:
            cloginrc_conf.add_value(CONFIG_FILE_PATH, data["directives"])
            directive = cloginrc_conf.get_value(read_file(CONFIG_FILE_PATH),
Esempio n. 7
0
from multiprocessing import Process
import subprocess
import os
from rancid_conf.rancid_conf import excecute_cmd
from crontab import CronTab
from rancid_conf import rancid_conf
from reader_writer.reader import read_file
import re
user = '******'
TFTP_URL = rancid_conf.get_value(read_file("./conf.ini"),"TFTP_URL")
def get_cronjob(param):
    tab = CronTab(user=user)
    result = []
    cron_lines = []
    if param == 'full':
        regex =r"""^(?P<MIN>[\d\*-,]*) (?P<HOUR>[\d\*-,]*) (?P<MONTH>[\d\*-,]*) (?P<DAY>[A-Z\d\*-,]*) (?P<DOWEEK>[A-Z\d\*-,]*) (?P<Commands>[^#]*)\s?#?(?P<Comments>.+)?$"""
        content = tab.render()
        cron_lines = content.split('\n')
    else:
        regex =r"""^(?P<MIN>[\d\*-,]*) (?P<HOUR>[\d\*-,]*) (?P<MONTH>[\d\*-,]*) (?P<DAY>[A-Z\d\*-,]*) (?P<DOWEEK>[A-Z\d\*-,]*) (?P<Commands>[^#]*%s)\s?#?(?P<Comments>.+)?$""" % param
        lines = tab.find_command(param)
        for l in lines:
            cron_lines.append(l.render())
    for line in cron_lines:
        match = re.match(regex, line)
        if match:
            result.append(match.groupdict())
    return result

def add_cronjob(data):
    if data['cron_job'][0]['Type'] == "tftp":