2017-10-21 20:04:42 +00:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Author: Tlams
|
|
|
|
|
Langage: Python
|
|
|
|
|
Minimum version require: 3.4
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from api.v1.api import *
|
2018-02-09 12:18:52 +00:00
|
|
|
|
from core.libs.logs import *
|
2017-10-21 20:04:42 +00:00
|
|
|
|
from core.modules.mod_access import *
|
|
|
|
|
import configparser
|
|
|
|
|
import getpass
|
|
|
|
|
import os
|
|
|
|
|
import stat
|
|
|
|
|
import urllib3
|
|
|
|
|
global passhash
|
|
|
|
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-02-09 12:18:52 +00:00
|
|
|
|
|
2017-10-21 20:04:42 +00:00
|
|
|
|
""" Read conf """
|
|
|
|
|
localconf = configparser.ConfigParser()
|
|
|
|
|
localconf.read('private/conf/config')
|
|
|
|
|
|
|
|
|
|
CritConf = CryticalData()
|
|
|
|
|
""" Step One: test private key or create it """
|
|
|
|
|
key_pvt = Path(localconf['system']['key_pvt'])
|
|
|
|
|
|
|
|
|
|
if not key_pvt.is_file():
|
|
|
|
|
print("No key found, auto-generation started ...")
|
|
|
|
|
passhash = encodepassphrase(getpass.getpass("Need a passphrase to start the generation:"))
|
|
|
|
|
|
|
|
|
|
print("This action can take some minutes, please wait.")
|
|
|
|
|
gen = CritConf.generate_key(localconf['system']['key_pvt'], localconf['system']['key_pub'], passhash)
|
|
|
|
|
if gen['result'] == "OK":
|
|
|
|
|
print("Your new key has been generate ! "
|
|
|
|
|
"\n - Private Key: {0} "
|
|
|
|
|
"\n - Public Key: {1}"
|
|
|
|
|
.format(localconf['system']['key_pvt'], localconf['system']['key_pvt']))
|
|
|
|
|
print("Passphrase HASH: {0}".format(passhash))
|
|
|
|
|
print("You must save your passphrase hash in a security place !")
|
|
|
|
|
else:
|
|
|
|
|
print(gen['Error'])
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
""" Test valid right for your private Key """
|
|
|
|
|
if oct(stat.S_IMODE(os.stat(localconf['system']['key_pvt']).st_mode)) != oct(0o600):
|
|
|
|
|
print("Your private key has not the good right({0})..."
|
|
|
|
|
"This problem can be very critical for your security.".
|
|
|
|
|
format(oct(stat.S_IMODE(os.stat(localconf['system']['key_pvt']).st_mode))))
|
|
|
|
|
os.chmod(localconf['system']['key_pvt'], 0o600)
|
|
|
|
|
print("Auto correction... done !")
|
|
|
|
|
|
|
|
|
|
""" Step two"""
|
|
|
|
|
if 'passhash' not in vars():
|
|
|
|
|
passhash = encodepassphrase(getpass.getpass("This system need a passphrase to start:"))
|
|
|
|
|
key_pvt = CritConf.read_private_key(localconf['system']['key_pvt'], passhash)
|
|
|
|
|
if key_pvt['result'] != "OK":
|
|
|
|
|
print("{0}: {1}"
|
|
|
|
|
"\n Please verify your passphrase".format(key_pvt['type'], key_pvt['error']))
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
key_pub = CritConf.read_public_key(localconf['system']['key_pub'])
|
2017-11-07 09:30:33 +00:00
|
|
|
|
|
2017-10-21 20:04:42 +00:00
|
|
|
|
# URL MAPPING
|
|
|
|
|
urls = \
|
|
|
|
|
(
|
2018-02-11 18:40:30 +00:00
|
|
|
|
|
|
|
|
|
# FRESH DATA
|
|
|
|
|
|
2017-10-21 20:04:42 +00:00
|
|
|
|
# MAPPING INSTANCES
|
|
|
|
|
'/api/v1/instance', 'Instance',
|
|
|
|
|
'/api/v1/instance/new', 'Instance',
|
|
|
|
|
'/api/v1/instance/([0-9]+)', 'Instance',
|
2018-02-18 17:53:15 +00:00
|
|
|
|
'/api/v1/instance/id/([a-z0-9]+)/status/(start|stop|current|reset|shutdown)', 'Instance',
|
2017-10-21 20:04:42 +00:00
|
|
|
|
|
|
|
|
|
'/api/v1/instance/([0-9]+)/package', 'package',
|
|
|
|
|
'/api/v1/instance/([0-9]+)/vhost(?:/([0-9]+))', 'vhost',
|
|
|
|
|
'/api/v1/instance/([0-9]+)/database(?:/([0-9]+))', 'database',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# MAPPING SERVICES
|
|
|
|
|
'/api/v1/service/([a-z]+)/instance/([0-9]+)/vhost(?:/([0-9]+))', 'service',
|
|
|
|
|
|
|
|
|
|
# AUTH
|
|
|
|
|
'/api/v1/auth', 'Auth',
|
|
|
|
|
|
2018-02-15 11:05:50 +00:00
|
|
|
|
# MANAGEMENT CLUSTER
|
2018-02-11 18:40:30 +00:00
|
|
|
|
'/api/v1/administration/cluster/(?:[0-9a-zA-Z\_\-]+)', 'Cluster',
|
|
|
|
|
'/api/v1/administration/cluster/', 'Cluster',
|
2017-10-21 20:04:42 +00:00
|
|
|
|
'/api/v1/administration/cluster/new', 'Cluster',
|
2018-02-04 22:10:18 +00:00
|
|
|
|
|
|
|
|
|
# CACHE DATA (MONGO)
|
|
|
|
|
# date/cluster/node/vmid
|
2018-02-08 18:18:02 +00:00
|
|
|
|
# Disks mapping
|
2018-02-11 18:40:30 +00:00
|
|
|
|
'/api/v1/static/(disks)/([0-9]+)/([0-9a-zA-Z\_\-]+)/([0-9a-zA-Z\_\-]+)/([0-9]+)', 'QueryCache_Infra',
|
|
|
|
|
'/api/v1/static/(disks)/([0-9]+)/([0-9a-zA-Z\_\-]+)/([0-9a-zA-Z\_\-]+)/', 'QueryCache_Infra',
|
|
|
|
|
'/api/v1/static/(disks)/([0-9]+)/([0-9a-zA-Z\_\-]+)/', 'QueryCache_Infra',
|
2018-02-08 18:18:02 +00:00
|
|
|
|
'/api/v1/static/(disks)/([0-9]+)/', 'QueryCache_Infra',
|
|
|
|
|
|
|
|
|
|
# Storages mapping
|
2018-02-11 18:40:30 +00:00
|
|
|
|
'/api/v1/static/(storages)/([0-9]+)/([0-9a-zA-Z\_\-]+)/([0-9a-zA-Z\_\-]+)/', 'QueryCache_Infra',
|
|
|
|
|
'/api/v1/static/(storages)/([0-9]+)/([0-9a-zA-Z\_\-]+)/', 'QueryCache_Infra',
|
2018-02-08 18:18:02 +00:00
|
|
|
|
'/api/v1/static/(storages)/([0-9]+)/', 'QueryCache_Infra',
|
|
|
|
|
|
|
|
|
|
# Instances mapping
|
2018-02-13 16:42:12 +00:00
|
|
|
|
'/api/v1/static/(instances)/([0-9]+)/([0-9a-zA-Z\_\-]+)/([0-9a-zA-Z\_\-]+)/([0-9]+)', 'QueryCache_Infra',
|
|
|
|
|
'/api/v1/static/(instances)/([0-9]+)/([0-9a-zA-Z\_\-]+)/([0-9a-zA-Z\_\-]+)/', 'QueryCache_Infra',
|
|
|
|
|
'/api/v1/static/(instances)/([0-9]+)/([0-9a-zA-Z\_\-]+)/', 'QueryCache_Infra',
|
2018-02-07 17:59:47 +00:00
|
|
|
|
'/api/v1/static/(instances)/([0-9]+)/', 'QueryCache_Infra',
|
|
|
|
|
|
2018-02-08 18:18:02 +00:00
|
|
|
|
# Nodes mapping
|
2018-02-13 16:42:12 +00:00
|
|
|
|
'/api/v1/static/(nodes)/([0-9]+)/([0-9a-zA-Z\_\-]+)/([0-9a-zA-Z\_\-]+)', 'QueryCache_Infra',
|
|
|
|
|
'/api/v1/static/(nodes)/([0-9]+)/([0-9a-zA-Z\_\-]+)/', 'QueryCache_Infra',
|
2018-02-07 17:59:47 +00:00
|
|
|
|
'/api/v1/static/(nodes)/([0-9]+)/', 'QueryCache_Infra',
|
|
|
|
|
|
2018-02-08 18:18:02 +00:00
|
|
|
|
# cluster mapping
|
2018-02-13 16:42:12 +00:00
|
|
|
|
'/api/v1/static/(clusters)/([0-9]+)/(?:[0-9a-zA-Z\_\-]+)', 'QueryCache_Infra',
|
2018-02-07 17:59:47 +00:00
|
|
|
|
'/api/v1/static/(clusters)/([0-9]+)/', 'QueryCache_Infra',
|
|
|
|
|
|
2018-02-04 22:10:18 +00:00
|
|
|
|
# date
|
2018-02-09 14:28:11 +00:00
|
|
|
|
'/api/v1/static/dates/(all|last)', 'QueryDates',
|
2018-02-07 17:59:47 +00:00
|
|
|
|
|
2018-02-04 22:10:18 +00:00
|
|
|
|
# mongoid
|
2018-02-09 12:18:52 +00:00
|
|
|
|
'/api/v1/static/(instances|nodes|clusters|storages|disks)/id/([a-z0-9]+)', 'General_Search',
|
2018-02-04 22:10:18 +00:00
|
|
|
|
|
2017-10-21 20:04:42 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
generalconf = {
|
2018-02-08 19:40:17 +00:00
|
|
|
|
"logger": {"debug": localconf['logger']['debug'], "debug_level": localconf['logger']['debug_level'],
|
2018-02-09 12:18:52 +00:00
|
|
|
|
"logs_dir": localconf['logger']['logs_dir']},
|
2018-02-08 19:40:17 +00:00
|
|
|
|
"analyst": {"walker": localconf['walker']['walker'], "walker_lock": localconf['walker']['walker_lock']},
|
2017-10-21 20:04:42 +00:00
|
|
|
|
"keys": {"key_pvt": key_pvt["data"], "key_pub": key_pub["data"]},
|
|
|
|
|
"mongodb": {"ip": localconf['databases']['mongodb_ip'], 'port': localconf['databases']['mongodb_port']},
|
|
|
|
|
"redis": {"ip": localconf['databases']['redis_ip'], 'port': localconf['databases']['redis_port']},
|
2018-02-08 19:40:17 +00:00
|
|
|
|
"deploy": {'concurrencydeploy': localconf['deploy']['concurrencydeploy'], 'delayrounddeploy': localconf['deploy']['delayrounddeploy']}
|
2017-10-21 20:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 12:18:52 +00:00
|
|
|
|
""" Active logger"""
|
|
|
|
|
logger = Logger(generalconf)
|
|
|
|
|
|
2017-10-21 20:04:42 +00:00
|
|
|
|
""" Init Core thread """
|
2018-02-08 14:30:00 +00:00
|
|
|
|
core = Core(generalconf)
|
2017-10-21 20:04:42 +00:00
|
|
|
|
|
|
|
|
|
""" Init API thread """
|
2018-02-08 14:30:00 +00:00
|
|
|
|
api_th = ThreadAPI(1, "ThreadAPI", urls, core, generalconf)
|
2017-10-21 20:04:42 +00:00
|
|
|
|
api_th.start()
|
|
|
|
|
|