Example #1
0
    def upload_vpn(self, win_zip, mac_zip, account_id):
        """ VPN ACCESS """

        # AWS ACCESS
        aws_access_key_id = config_section_parser(self.config,
                                                  "AWS")['aws_access_key_id']
        aws_secret_access_key = config_section_parser(
            self.config, "AWS")['aws_secret_access_key']
        region_name = config_section_parser(self.config, "AWS")['region_name']

        # CONNECT TO S3
        s3_resource = boto3.resource(
            's3',
            aws_access_key_id=aws_access_key_id,
            aws_secret_access_key=aws_secret_access_key,
            region_name=region_name)

        s3_client = boto3.client('s3',
                                 aws_access_key_id=aws_access_key_id,
                                 aws_secret_access_key=aws_secret_access_key,
                                 region_name=region_name)

        win_url = self.s3_uploader('WINDOWS', win_zip, s3_resource, s3_client,
                                   account_id)
        mac_url = self.s3_uploader('MAC', mac_zip, s3_resource, s3_client,
                                   account_id)

        return [win_url, mac_url]
Example #2
0
    def get_url(self, key):
        """ Return S3 URL """
        assert key, "Key is required."
        # AWS ACCESS
        aws_access_key_id = config_section_parser(self.config,
                                                  "AWS")['aws_access_key_id']
        aws_secret_access_key = config_section_parser(
            self.config, "AWS")['aws_secret_access_key']
        region_name = config_section_parser(self.config, "AWS")['region_name']

        # CONNECT TO S3
        s3_client = boto3.client('s3',
                                 aws_access_key_id=aws_access_key_id,
                                 aws_secret_access_key=aws_secret_access_key,
                                 region_name=region_name)

        s3_params = {
            'Bucket': config_section_parser(self.config, "AWS")['bucket'],
            'Key': key
        }

        expiration = config_section_parser(self.config, "AWS")['image_expires']
        url = s3_client.generate_presigned_url('get_object',
                                               Params=s3_params,
                                               ExpiresIn=expiration,
                                               HttpMethod='GET')
        return url
Example #3
0
    def __init__(self):
        """The Constructor for Invite class"""

        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self.postgres = PostgreSQL()

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']
        super(CreateVessel, self).__init__()

        if self.vpn_db_build.upper() == 'TRUE':
            self.my_ip = config_section_parser(self.config, "IPS")['my']
            self.my_protocol = config_section_parser(self.config,
                                                     "IPS")['my_protocol']

            self.vessel_vpn = config_section_parser(self.config,
                                                    "IPS")['vessel_vpn']
            self.vessel_protocol = config_section_parser(
                self.config, "IPS")['vessel_protocol']

            self.vpn_token = '269c2c3706886d94aeefd6e7f7130ab08346590533d4c5b24ccaea9baa5211ec'
Example #4
0
    def setUp(self):
        """ SET UP """

        self.api_request = APIRequest()

        self.user_id = ""
        self.token = ""

        self.email = config_section_parser(CONFIG, "ADMIN")['username']
        self.password = config_section_parser(CONFIG, "ADMIN")['password']
        self.test_user_login()
Example #5
0
    def __init__(self):
        """The Constructor for PostgreSQL class"""
        # INIT CONFIG
        self.config = ConfigParser()
        # CONFIG FILE
        self.config.read("config/config.cfg")

        # SET CONFIG VALUES
        self.host = config_section_parser(self.config, "POSTGRES")['host']
        self.user = config_section_parser(self.config, "POSTGRES")['username']
        self.password = config_section_parser(self.config,
                                              "POSTGRES")['password']
        self.dbname = config_section_parser(self.config, "POSTGRES")['db_name']
        self.port = config_section_parser(self.config, "POSTGRES")['port']
Example #6
0
    def __init__(self):
        """The Constructor for Device class"""
        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.aws3 = AwsS3()
        self.epoch_default = 26763
        self.db_host = config_section_parser(self.config, "COUCHDB")['host']
        self.db_port = config_section_parser(self.config, "COUCHDB")['port']
        super(Device, self).__init__()
Example #7
0
    def create_database(self):
        """Create Database"""
        self.dbname = config_section_parser(self.config, "POSTGRES")['db_name']
        self.postgres.connection(True)
        self.postgres.create_database(self.dbname)
        self.postgres.close_connection()

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']

        if self.vpn_db_build.upper() == 'TRUE':

            self.my_ip = config_section_parser(self.config, "IPS")['my']
            self.user_vpn = config_section_parser(self.config,
                                                  "IPS")['user_vpn']
            self.vessel_vpn = config_section_parser(self.config,
                                                    "IPS")['vessel_vpn']
Example #8
0
    def __init__(self):
        """The Constructor for EnableUser class"""

        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self.postgres = PostgreSQL()

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']
        super(EnableUser, self).__init__()

        if self.vpn_db_build.upper() == 'TRUE':
            self.my_ip = config_section_parser(self.config, "IPS")['my']
            self.my_protocol = config_section_parser(self.config,
                                                     "IPS")['my_protocol']

            self.user_vpn = config_section_parser(self.config,
                                                  "IPS")['user_vpn']
            self.user_protocol = config_section_parser(self.config,
                                                       "IPS")['user_protocol']

            self.vessel_vpn = config_section_parser(self.config,
                                                    "IPS")['vessel_vpn']
            self.vessel_protocol = config_section_parser(
                self.config, "IPS")['vessel_protocol']
Example #9
0
    def __init__(self):
        """The Constructor for VPNIPUpdate class"""

        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        self.epoch_default = 26763

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']
        super(VPNIPUpdate, self).__init__()

        if self.vpn_db_build.upper() == 'TRUE':
            self.my_ip = config_section_parser(self.config, "IPS")['my']
            self.my_protocol = config_section_parser(self.config,
                                                     "IPS")['my_protocol']

            self.user_vpn = config_section_parser(self.config,
                                                  "IPS")['user_vpn']
            self.user_protocol = config_section_parser(self.config,
                                                       "IPS")['user_protocol']

            self.vessel_vpn = config_section_parser(self.config,
                                                    "IPS")['vessel_vpn']
            self.vessel_protocol = config_section_parser(
                self.config, "IPS")['vessel_protocol']
            # self.generate_token()
            self.vpn_token = '269c2c3706886d94aeefd6e7f7130ab08346590533d4c5b24ccaea9baa5211ec'
Example #10
0
    def api_post(self, url, data, head=None):
        """API Post"""
        api_ip = config_section_parser(CONFIG, "IPS")['my']
        api_protocol = config_section_parser(CONFIG, "IPS")['my_protocol']
        api_endpoint = api_protocol + "://" + api_ip + ":" + PORT + url

        headers = {}
        headers['content-type'] = 'application/json'

        if head:
            # headers = {**headers, **head}
            headers = {}

        req = requests.post(api_endpoint,
                            data=json.dumps(data),
                            headers=headers)

        return req.json()
Example #11
0
    def __init__(self):
        """The Constructor for Directory class"""
        # INIT CONFIG
        self.config = ConfigParser()
        # CONFIG FILE
        self.config.read("config/config.cfg")

        # WEB DIRECTORY
        self.web_directory = config_section_parser(self.config, "PATH")['web']
Example #12
0
    def __init__(self):
        """The Constructor for UpdateINIFiles class"""
        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        super(UpdateINIFiles, self).__init__()

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']

        self.vessel_vpn = config_section_parser(self.config,
                                                "IPS")['vessel_vpn']
        self.vessel_protocol = config_section_parser(self.config,
                                                     "IPS")['vessel_protocol']

        self.vpn_token = '269c2c3706886d94aeefd6e7f7130ab08346590533d4c5b24ccaea9baa5211ec'
Example #13
0
    def __init__(self):
        """The Constructor for User class"""
        self.postgres = PostgreSQL()

        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']
        super(User, self).__init__()
Example #14
0
    def save_file(self, key_file, body_request):
        """ Save File to S3 Bucket """

        # AWS ACCESS
        aws_access_key_id = config_section_parser(self.config,
                                                  "AWS")['aws_access_key_id']
        aws_secret_access_key = config_section_parser(
            self.config, "AWS")['aws_secret_access_key']
        region_name = config_section_parser(self.config, "AWS")['region_name']

        # CONNECT TO S3
        s3_resource = boto3.resource(
            's3',
            aws_access_key_id=aws_access_key_id,
            aws_secret_access_key=aws_secret_access_key,
            region_name=region_name)
        # SAVE TO S3
        save_to_bucket = s3_resource.Bucket('rh.fileserver').put_object(
            Key=key_file, Body=body_request)

        if save_to_bucket:
            return 1
        return 0
Example #15
0
    def __init__(self):
        """The Constructor for Vessels class"""
        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        self.epoch_default = 26763
        self.vessel_name = ""
        self.aws3 = AwsS3()

        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self.vpn_db_build = config_section_parser(self.config, "VPNDB")['build']

        super(MapVessels, self).__init__()
Example #16
0
    def s3_uploader(self, ops, zipdir, s3_resource, s3_client, account_id):
        """ VPN uploader """

        # Bucket
        bucket = config_section_parser(self.config, "AWS")['bucket']

        # Filename
        filename = 'VPN/VPN_' + ops + '_Installer_' + str(account_id) + '.zip'

        # SAVE TO S3
        s3_resource.meta.client.upload_file(zipdir, bucket, filename)

        s3_params = {'Key': filename, 'Bucket': bucket}

        # GET PRESIGNED URL
        pres_url = s3_client.generate_presigned_url('get_object',
                                                    Params=s3_params,
                                                    ExpiresIn=86400,
                                                    HttpMethod='GET')

        return pres_url
Example #17
0
    def __init__(self):
        """The Constructor for CouchDatabase class"""
        # INIT CONFIG
        self.config = ConfigParser()
        # CONFIG FILE
        self.config.read("config/config.cfg")

        # COUCH DATABASE NAME
        self.couchdb_name = config_section_parser(self.config,
                                                  "COUCHDB")['db_name']

        # COUCH CREDENTIALS
        self.couch_protocol = config_section_parser(self.config,
                                                    "COUCHDB")['protocol']
        self.couch_user = config_section_parser(self.config, "COUCHDB")['user']
        self.couch_password = config_section_parser(self.config,
                                                    "COUCHDB")['password']
        self.couch_host = config_section_parser(self.config, "COUCHDB")['host']
        self.couch_port = config_section_parser(self.config, "COUCHDB")['port']
Example #18
0
    def create_default_entries(self):
        """Create Default Entries"""
        vpn_db_build = config_section_parser(self.config, "VPNDB")['build']

        # PERMISSION
        data = {}
        data['permission_name'] = config_section_parser(
            self.config, "PERMISSION")['permission_name']
        data['permission_details'] = config_section_parser(
            self.config, "PERMISSION")['permission_details']
        data['default_value'] = True
        data['created_on'] = time.time()

        print("Create default permission: ", data['permission_name'])
        permission_id = self.postgres.insert('permission', data,
                                             'permission_id')

        count = 9

        if vpn_db_build.upper() == 'TRUE':

            count = 10

        for dta in range(1, count):

            data1 = {}
            data1['permission_name'] = config_section_parser(
                self.config, "PERMISSION")['permission_name' + str(dta)]
            data1['permission_details'] = config_section_parser(
                self.config, "PERMISSION")['permission_details' + str(dta)]
            data1['default_value'] = True
            data1['created_on'] = time.time()

            print("Create default permission: ", data1['permission_name'])
            self.postgres.insert('permission', data1, 'permission_id')

        if permission_id:

            print("Default Permission successfully created!")

        else:

            self.postgres.connection()

            sql_str = "SELECT * FROM permission WHERE permission_name='" + data[
                'permission_name'] + "'"
            res = self.postgres.query_fetch_one(sql_str)
            permission_id = res['permission_id']

            self.postgres.close_connection()

        # ROLE
        data = {}
        data['role_name'] = config_section_parser(self.config,
                                                  "ROLE")['role_name']
        data['role_details'] = config_section_parser(self.config,
                                                     "ROLE")['role_details']
        data['default_value'] = True
        data['created_on'] = time.time()

        # ROLE1
        data1 = {}
        data1['role_name'] = config_section_parser(self.config,
                                                   "ROLE")['role_name1']
        data1['role_details'] = config_section_parser(self.config,
                                                      "ROLE")['role_details1']
        data1['default_value'] = True
        data1['created_on'] = time.time()

        # ROLE2
        data2 = {}
        data2['role_name'] = config_section_parser(self.config,
                                                   "ROLE")['role_name2']
        data2['role_details'] = config_section_parser(self.config,
                                                      "ROLE")['role_details2']
        data2['default_value'] = True
        data2['created_on'] = time.time()

        if vpn_db_build.upper() == 'TRUE':

            # ROLE3
            data3 = {}
            data3['role_name'] = config_section_parser(self.config,
                                                       "ROLE")['role_name3']
            data3['role_details'] = config_section_parser(
                self.config, "ROLE")['role_details3']
            data3['default_value'] = True
            data3['created_on'] = time.time()

        print("Create default role: ", data['role_name'])
        print("Create default role: ", data1['role_name'])
        print("Create default role: ", data2['role_name'])
        role_id = self.postgres.insert('role', data, 'role_id')
        self.postgres.insert('role', data1, 'role_id')
        self.postgres.insert('role', data2, 'role_id')

        if vpn_db_build.upper() == 'TRUE':
            print("Create default role: ", data3['role_name'])
            self.postgres.insert('role', data3, 'role_id')
            sa_role_id = self.postgres.insert('role', data3, 'role_id')

        if role_id:
            print("Default Role successfully created!")
        else:
            self.postgres.connection()

            sql_str = "SELECT * FROM role WHERE role_name='" + data[
                'role_name'] + "'"
            res = self.postgres.query_fetch_one(sql_str)
            role_id = res['role_id']

            self.postgres.close_connection()

        if vpn_db_build.upper() == 'TRUE':

            if sa_role_id:
                print("Default Role successfully created!")
            else:
                self.postgres.connection()

                sql_str = "SELECT * FROM role WHERE role_name='" + data3[
                    'role_name'] + "'"
                res = self.postgres.query_fetch_one(sql_str)
                sa_role_id = res['role_id']

                self.postgres.close_connection()

        # ROLE PERMISSION
        temp = {}
        temp['role_id'] = role_id
        temp['permission_id'] = permission_id
        self.postgres.insert('role_permission', temp)

        # SUPER ADMIN
        # ROLE PERMISSION
        self.postgres.connection()

        sql_str = "SELECT permission_id FROM permission WHERE permission_name ='all and with admin vessel VPN.'"
        permission = self.postgres.query_fetch_one(sql_str)

        self.postgres.close_connection()

        if vpn_db_build.upper() == 'TRUE':

            temp = {}
            temp['role_id'] = sa_role_id
            temp['permission_id'] = permission['permission_id']
            self.postgres.insert('role_permission', temp)

        # ACCOUNT
        data = {}
        data['username'] = config_section_parser(self.config,
                                                 "ADMIN")['username']
        data['password'] = config_section_parser(self.config,
                                                 "ADMIN")['password']
        data['email'] = config_section_parser(self.config, "ADMIN")['email']
        data['status'] = bool(
            config_section_parser(self.config, "ADMIN")['status'])
        data['state'] = bool(
            config_section_parser(self.config, "ADMIN")['state'])
        data['url'] = "default"
        data['token'] = self.sha_security.generate_token()
        data['default_value'] = True
        data['created_on'] = time.time()
        data['update_on'] = time.time()

        print("Create default user: "******"Default user successfully created!")
        else:
            self.postgres.connection()

            sql_str = "SELECT id FROM account WHERE username='******'username'] + "'"
            res = self.postgres.query_fetch_one(sql_str)
            account_id = res['id']

            self.postgres.close_connection()

        # ACCOUNT ROLE
        temp = {}
        temp['account_id'] = account_id
        temp['role_id'] = role_id
        self.postgres.insert('account_role', temp)

        # COMPANY
        data = {}
        data['company_name'] = config_section_parser(self.config,
                                                     "COMPANY")['company_name']
        data['default_value'] = True
        data['created_on'] = time.time()

        print("Create default company: ", data['company_name'])
        company_id = self.postgres.insert('company', data, 'company_id')
        if company_id:
            print("Default Role successfully created!")
        else:
            self.postgres.connection()

            sql_str = "SELECT * FROM company WHERE company_name='" + data[
                'company_name'] + "'"
            res = self.postgres.query_fetch_one(sql_str)
            company_id = res['company_id']

            self.postgres.close_connection()

        # ACCOUNT COMPANY
        temp = {}
        temp['account_id'] = account_id
        temp['company_id'] = role_id
        self.postgres.insert('account_company', temp)

        #ALARM TYPE
        temp = {}
        alarm_types = ({
            "alarm_type": "Critical",
            "alarm_value": 10
        }, {
            "alarm_type": "Warning",
            "alarm_value": 20
        }, {
            "alarm_type": "Alert",
            "alarm_value": 30
        }, {
            "alarm_type": "Info",
            "alarm_value": 40
        }, {
            "alarm_type": "Debug",
            "alarm_value": 50
        })

        for data in alarm_types:
            alarm_type_id = self.postgres.insert('alarm_type', data)
            if alarm_type_id:
                print("Alarm types successfully added!")
            else:
                print("Failed to add Alarm Type")

        temp = {}
        alarm_operators = ({
            "operator": "TRUE",
            "param_num": 0,
            "label": "Always True",
            "opgroup": "Boolean"
        }, {
            "operator": "FALSE",
            "param_num": 0,
            "label": "Always False",
            "opgroup": "Boolean"
        }, {
            "operator": "!",
            "param_num": 1,
            "label": "Invert Boolean-result",
            "opgroup": "Boolean"
        }, {
            "operator": "=",
            "param_num": 2,
            "label": "True if equal",
            "opgroup": "Boolean"
        }, {
            "operator": "!=",
            "param_num": 2,
            "label": "True if Param1 not equal to Param2",
            "opgroup": "Boolean"
        }, {
            "operator": "LIKE",
            "param_num": 2,
            "label": "True if Param1 LIKE Param2 case insensitive",
            "opgroup": "String"
        }, {
            "operator": "!LIKE",
            "param_num": 2,
            "label": "True if Param1 not LIKE Param2 case insensitive",
            "opgroup": "String"
        }, {
            "operator": ">",
            "param_num": 2,
            "label": "True if Param1 > Param2",
            "opgroup": "Boolean"
        }, {
            "operator": "<",
            "param_num": 2,
            "label": "True if Param1 < Param2",
            "opgroup": "Boolean"
        }, {
            "operator": "AND",
            "param_num": 2,
            "label": "True if Param1 AND Param2 are true",
            "opgroup": "Boolean"
        }, {
            "operator": "OR",
            "param_num": 2,
            "label": "True if Param1 OR Param2 is true",
            "opgroup": "Boolean"
        }, {
            "operator": "+",
            "param_num": 2,
            "label": "Returns the sum of Param1 and Param2",
            "opgroup": "Double"
        }, {
            "operator": "-",
            "param_num": 2,
            "label": "Returns the difference of Param1 and Param2",
            "opgroup": "Double"
        }, {
            "operator": "*",
            "param_num": 2,
            "label": "Returns the Param1 times Param2",
            "opgroup": "Double"
        }, {
            "operator": "/",
            "param_num": 2,
            "label": "Returns the Param1 divided by Param2",
            "opgroup": "Double"
        }, {
            "operator": "BETWEEN",
            "param_num": 3,
            "label": "True if Param1 > Param2 and Param1 < Param3",
            "opgroup": "Boolean"
        }, {
            "operator": "BETWEENEQ",
            "param_num": 3,
            "label": "True if Param1 >= Param2 and Param1 =< Param3",
            "opgroup": "Boolean"
        }, {
            "operator": "!BETWEEN",
            "param_num": 3,
            "label": "True if Param1 < Param2 and Param1 > Param3",
            "opgroup": "Boolean"
        }, {
            "operator": "!BETWEENEQ",
            "param_num": 3,
            "label": "True if Param1 <= Param2 and Param1 >= Param3",
            "opgroup": "Boolean"
        })

        for data in alarm_operators:
            alarm_operator_id = self.postgres.insert('alarm_coperator', data)
            if alarm_operator_id:
                print("Alarm Conditions successfully added!")
            else:
                print("Failed to add Alarm Conditions")
Example #19
0
        for data in alarm_operators:
            alarm_operator_id = self.postgres.insert('alarm_coperator', data)
            if alarm_operator_id:
                print("Alarm Conditions successfully added!")
            else:
                print("Failed to add Alarm Conditions")


if __name__ == '__main__':

    # INIT CONFIG
    CONFIG = ConfigParser()
    # CONFIG FILE
    CONFIG.read("config/config.cfg")

    SERVER_TYPE = config_section_parser(CONFIG, "SERVER")['server_type']

    if SERVER_TYPE != 'production':
        SETUP = Setup()
        SETUP.main()

    else:

        print("YOU'RE TRYING TO UPDATE LIVE SERVER!!!")

#drop table device;
#drop table module;
#drop table option;
#drop table report_temp;
#drop table email_schedule;
#drop table email_vessel;
Example #20
0
# --------------------------------------------------------------
# VERSION
# --------------------------------------------------------------
VERSION = version.Version()
CREATE_VERSION = create_version.CreateVersion()
SET_VERSION = set_version.SetVersion()

# CATEGORY ROUTE
APP.route('/version', methods=['GET'])(VERSION.version)
APP.route('/version/create', methods=['POST'])(CREATE_VERSION.create_version)
APP.route('/version/set', methods=['POST'])(SET_VERSION.set_version)

# --------------------------------------------------------------
# CRON
# --------------------------------------------------------------
MONITORING = config_section_parser(CONFIG, "MONITORING")['enable']

if MONITORING.upper() == "TRUE":

    LOG.info("Cron will start in a while!")
    CRON = BackgroundScheduler()

    # EMAIL VESSEL INFO
    from controllers.cron import email_vessel_info
    EMAIL_VESSEL_INFO = email_vessel_info.EmailVesselInfo()

    # UPDATE VESSEL STATE
    from controllers.cron import cron_update_vessel_state
    CRON_UPDATE_VESSEL_STATE = cron_update_vessel_state.UpdateVesselState()

    # UPDATE DEVICE STATE