def influx_db_info(vm_type):
    user = configp.get(vm_type, 'username')
    pas = configp.get(vm_type, 'password')
    host = configp.get(vm_type, 'host')
    db_influx = configp.get(vm_type, 'database')
    conn = MySQLdb.connect(host=host, user=user, passwd=pas, db=db_influx)
    c = conn.cursor()
    return c, conn
            def mysql_connection():
                user = configp.get('mysql', 'username')
                pas = base64.b64decode(configp.get('mysql', 'password'))
                host = configp.get('mysql', 'host')
                db_pcli = configp.get('mysql', 'database')

                mysql_conn = MySQLdb.connect(host=host,
                                             user=user,
                                             passwd=pas,
                                             db=db_pcli)
                return mysql_conn
    def __init__(self):
        rhost = configp.get('rabbitmq', 'ip')
        username = configp.get('rabbitmq', 'username')
        password = configp.get('rabbitmq', 'password')
        credentials = pika.PlainCredentials(username, password)
        parameters = pika.ConnectionParameters(rhost, 5672, '/', credentials)

        self.connection = pika.BlockingConnection(parameters)

        self.channel = self.connection.channel()

        result = self.channel.queue_declare(exclusive=True)

        self.callback_queue = result.method.queue
    def post(self):
        try:
            mobile_number = request.get_json().get('mobile_number', '')
            emulator_name = request.get_json().get('emulator_name', '')
            message_body = request.get_json().get('message_body', '')
            if mobile_number == '' or emulator_name == '' or message_body == '':
                return make_response(
                    jsonify({
                        "status": "0",
                        "message": "Insufficient Parameters"
                    }), 422)

            mobile_format_validation = carrier._is_mobile(
                number_type(phonenumbers.parse(mobile_number)))

            if not mobile_format_validation:
                return make_response(
                    jsonify({
                        "status":
                        "0",
                        "message":
                        "Mobile number not in International Indian Format. Ex: +91 XXXXX XXXXX"
                    }), 400)

            final_message = json.dumps({
                "mobile_number": mobile_number,
                "emulator_name": emulator_name,
                "message_body": message_body
            })

            single_message_queue_name = configp.get('queue_name',
                                                    'single_message')

            corr_id = Rabbit().msgproducer(single_message_queue_name,
                                           final_message, emulator_name,
                                           'send_only')

            if corr_id:
                return make_response(
                    jsonify({
                        "status": "1",
                        "message": "Singal received for sending message",
                        "corr_id": corr_id
                    }), 200)
            else:
                return make_response(
                    jsonify({
                        "status": "0",
                        "message": "Signal Failed",
                        "corr_id": 0
                    }), 400)

        except Exception as e:
            self.apilog.error("SGLog:" + str(e))
            return make_response(
                jsonify({
                    "status": "0",
                    "message": "Exception Occured. Check Logs"
                }), 500)
    def main(self):

        global LOGGER

        FORMAT = '%(levelname)s: %(asctime)-15s: %(filename)s: %(funcName)s: %(module)s: %(message)s'
        logging.basicConfig(filename="/var/log/whatsapp_single_worker.log",
                            level=logging.DEBUG,
                            format=FORMAT)
        LOGGER = logging.getLogger("single_worker")
        single_message_queue_name = configp.get('queue_name', 'single_message')
        try:
            self.msgworker(single_message_queue_name)
        except Exception as e:
            LOGGER.error(e)
Beispiel #6
0
    def post(self):
        try:
            special_code = request.get_json().get('special_code', '')
            if special_code == '':
                return make_response(
                    jsonify({
                        "status": "0",
                        "message": "Insufficient Parameters"
                    }), 422)

            if special_code != 'e3gi8d2i8d2382@@#':
                return make_response(
                    jsonify({
                        "status":
                        "0",
                        "message":
                        "Special Code needs to be passed to listen message"
                    }), 400)

            listen_message_queue_name = configp.get('queue_name',
                                                    'listen_message')

            corr_id = Rabbit().msgproducer(listen_message_queue_name)

            if corr_id:
                return make_response(
                    jsonify({
                        "status": "1",
                        "message": "Singal received for listening message",
                        "corr_id": corr_id
                    }), 200)
            else:
                return make_response(
                    jsonify({
                        "status": "0",
                        "message": "Singal Failed",
                        "corr_id": 0
                    }), 400)

        except Exception as e:
            self.apilog.error("SGLog:" + str(e))
            return make_response(
                jsonify({
                    "status": "0",
                    "message": "Exception Occured. Check Logs"
                }), 500)
    def get(self):
        influx_ip = None
        secondary_influx_node = None
        try:
            self.data = request.get_json()
            self.serverip = self.data['serverip']
            self.vm_type = self.data.get("vm_template", None).lower()

            cur, con = influx_db_info(self.vm_type)

            if self.vm_type not in ['application', 'database']:
                return "Invalid VM template", 400

            self.table_influx = configp.get(self.vm_type, 'tablename')

            query = "select influx_node,secondary_influx_node from %s where ip='%s'" % (
                self.table_influx, self.serverip)

            val = valid_ipv4(self.serverip)

            if val == True:
                pass
            else:
                print "Invalid IP address %s" % (self.serverip)
                return "Invalid IP address", 400

            cur.execute(query)

            rows = cur.fetchall()
            for row in rows:
                influx_ip = row[0]
                secondary_influx_node = row[1]
                break

        except Exception as e:
            print e

        finally:
            cur.close()
            con.close()
        return make_response(
            jsonify({
                "influx_ip": influx_ip,
                "secondary_influx_node": secondary_influx_node
            }))
import boto3
import time
import os
from configs.readconfig import configp

#--------------------------------Variable declaration section starts---------------------------------------#

if os.environ["ENV"] == 'dev':
    aws_access_key_id = configp.get('aws', 'aws_access_key_id')
    aws_secret_access_key = configp.get('aws', 'aws_secret_access_key')
else:
    from configs.readconfig import aws_configp
    aws_access_key_id = aws_configp['accessKey']
    aws_secret_access_key = aws_configp['serverAccessKey']

aws_region_name = configp.get('aws', 'aws_region_name')
aws_ec2_key = configp.get('aws', 'aws_ec2_key')
aws_ec2_value = configp.get('aws', 'aws_ec2_value')
assessment_run_time = configp.get('aws', 'assessment_run_time')
timestr = time.strftime("%Y%m%d-%H%M%S")
aws_assessment_target_name = configp.get(
    'aws', 'aws_assessment_target_name') + '_' + timestr
aws_assessment_template_name = configp.get(
    'aws', 'aws_assessment_template_name') + '_' + timestr
aws_assessment_run_name = configp.get(
    'aws', 'aws_assessment_run_name') + '_' + timestr
cve_rule_arn = configp.get('aws', 'cve_rule_arn')

#--------------------------------Variable declaration section Ends---------------------------------------#

client = boto3.client('inspector',
    def updateconfig(self):

        try:
            if self.vm_type == "application":

                ### ANSIBLE PATHS
                ansible_base_path = configp.get('application-ansibleconfig', 'path')

                ### CONFIGS
                hostname = configp.get('application-ansibleconfig', 'hostname')
                port = int(configp.get('application-ansibleconfig', 'port'))
                username = configp.get('application-ansibleconfig', 'username')
                self.rsa_private_key = configp.get('application-ansibleconfig', 'rsakey')

                ###COMMANDS
                ansible_command = 'sudo ansible-playbook -i %s, playbooks/telegraf.yml -e "nginx_plus_enabled_required=False" -e "nginx_plus_enabled_required_auth=False"' % (
                self.serverip)
                command = "cd " + ansible_base_path + " && " + ansible_command

            elif self.vm_type == "database":
                ### ANSIBLE PATHS
                ansible_base_path = configp.get('database-ansibleconfig', 'path')

                ### CONFIGS
                hostname = configp.get('database-ansibleconfig', 'hostname')
                port = int(configp.get('database-ansibleconfig', 'port'))
                username = configp.get('database-ansibleconfig', 'username')
                self.rsa_private_key = configp.get('database-ansibleconfig', 'rsakey')

                ###COMMANDS
                ansible_command = 'ansible-playbook -i %s, /etc/ansible/ -e "rtpasswd=%s"' % (
                self.serverip, rpassword)
                command = "cd " + ansible_base_path + " && " + ansible_command

            else:
                return False, "VM type incorrect", 400

            ### SETTING PASSWORD ON SERVER
            print 'Establishing SSH connection to:', hostname, port, '...'
            t = None
            exitstatus = -1
            try:
                t = paramiko.Transport((hostname, port))
                t.start_client()
                self.agent_auth(t, username)

                if not t.is_authenticated():
                    print 'RSA key auth failed! Trying password login...'
                else:

                    ssh = paramiko.SSHClient()

                    try:
                        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                        ssh.connect(hostname=hostname, username=username, key_filename=self.rsa_private_key)
                        chan = ssh.get_transport().open_session()

                        chan.exec_command(command)

                        exitstatus = chan.recv_exit_status()


                    finally:
                        ssh.close()
            finally:
                if t:
                    t.close()

            if exitstatus == 0:
                return True, "Telegraf Config Updated Successfully", 200
            else:
                requests.request('DELETE', msecreturl, headers=headers)
                return False, "Telegraf Config Updation Failed", 400

        except Exception as e:
            print e
import boto3
import MySQLdb
import csv
import time
import os
from configs.readconfig import configp

# --------------------------------Variable declaration section starts---------------------------------------#

if os.environ["ENV"] == 'dev':
    aws_access_key_id = configp.get('aws', 'aws_access_key_id')
    aws_secret_access_key = configp.get('aws', 'aws_secret_access_key')
else:
    from configs.readconfig import aws_configp
    aws_access_key_id = aws_configp['accessKey']
    aws_secret_access_key = aws_configp['serverAccessKey']

aws_region_name = configp.get('aws', 'aws_region_name')
mysql_host = configp.get('mysql', 'mysql_host')
mysql_user = configp.get('mysql', 'mysql_user')
mysql_password = configp.get('mysql', 'mysql_password')
mysql_db = configp.get('mysql', 'mysql_db')
timestr = time.strftime("%Y%m%d")
#timestr = '20181205'
aws_assessment_run_name = configp.get(
    'aws', 'aws_assessment_run_name') + '_' + timestr
download_dir = "aws_vulnerability" + '_' + timestr + ".csv"

# --------------------------------Variable declaration section Ends---------------------------------------#

conn = MySQLdb.Connection(host=mysql_host,