예제 #1
0
def sql_process(*args):
    host, user, password = json_parser.parse_json(sql_server_file, 'host',
                                                  'user', 'password', 'server')
    database = json_parser.parse_json(sql_server_file, 'database', 'login_db')
    db, cursor, flag = sql_connect.validate_database(host, user, password,
                                                     database)
    if flag:
        cursor, rows = sql_query.query_sql(args)
        if str(rows) != 0:
            return cursor.fetchall()
        else:
            return None
예제 #2
0
    def validate_pincode(self, *args):
        valid_pincode_flag = False
        multi_data_found_flag = False
        cmd = json_parser.parse_json(sql_command_file,
                                     'show_records_with_value', 'commands')
        table_name = json_parser.parse_json(sql_server_file, 'table',
                                            'lat_lng_db')
        data = sql_process(cmd, table_name, 'pincode', args[0])
        if data:
            valid_pincode_flag = True

            if len(data) > 1:
                multi_data_found_flag = True

        else:
            popup_obj = popup.popup_widget('Invalid Pincode\nPlease try again')
            start = time.time()
            while time.time() - start < 3:
                pass
            popup.popup_dismiss(popup_obj)
예제 #3
0
def main():
    
    url = 'https://github.com/mitre/cti/raw/master/enterprise-attack/attack-pattern/'
    
    fields = [
        "id",
        "objects[0].name",
        "objects[0].kill_chain_phases"
    ]
    
    for f in jp.get_json_files(url):
        print(jp.parse_json(f, fields))
    
    return 0
def process_login(cmd, column_name, field_name, field_value, pwd):
    user_exist_flag = False
    pwd_correct_flag = False
    db, cursor, valid_database_flag = sql_connect.validate_database(
        json_parser.parse_json(server_credentials, 'server', 'user',
                               'password', 'database', 'login_db'))
    cursor, rows = sql_query.query_sql(
        cmd, column_name,
        json_parser.parse_json(server_credentials, 'table', 'login_db'),
        field_name, field_value, db, cursor, valid_database_flag, 4)
    if str(rows) != '0':
        user_exist_flag = True
        data = cursor.fetchone()
        if pwd == data[0]:
            pwd_correct_flag = True
        else:
            popup.popup_widget(invalid_pwd_popup)
            pwd_correct_flag = False
    else:
        popup.popup_widget(invalid_email_popup)
        user_exist_flag = False  # if this is not set false here then it will allow to login with
        # invalid email id after first login was successful
    db.close()
    return pwd_correct_flag and user_exist_flag
예제 #5
0
def main():
    # set vars
    token = ''
    user_list_file = ''
    user_list = ['']

    parser = argparse.ArgumentParser(
        description='make namecard from slack api')
    parser.add_argument('-t', '--token', default='', help='slack api token')
    parser.add_argument('-f', '--file', default='', help='user list file')
    parser.add_argument('-u',
                        '--user',
                        nargs='*',
                        default=[],
                        help='user list')
    args = parser.parse_args()
    if args.token != '':
        token = args.token
    if args.file != '':
        user_list_file = args.file
    if args.user != []:
        user_list = args.user

    if user_list_file != '':
        with open(user_list_file) as f:
            for user in f.readlines():
                user_list.append(user.replace('\n', ''))

    with open('template.yaml', 'r') as f:
        template = yaml.load(f)

    # get and parse json
    json_user, json_team = json_parser.parse_json(token)

    if json_user['ok']:
        # make user information list and team information
        user_info_list, team_info = json_parser.make_info(
            json_user, json_team, user_list)

        # make namecard
        card_maker.make_namecard(user_info_list, team_info,
                                 template['default'])

        # make pdf for print
        card_maker.make_pdf(user_info_list, team_info, template['default'])

    else:
        print('Error: invalid token\n')
예제 #6
0
def main():
    # set vars
    token = ''
    user_list_file = ''
    user_list = []

    parser = argparse.ArgumentParser(description='get slack users icon')
    parser.add_argument('-t', '--token', default='', help='slack api token')
    parser.add_argument('-f', '--file', default='', help='user list file')
    parser.add_argument('-u',
                        '--user',
                        nargs='*',
                        default=[],
                        help='user list')
    args = parser.parse_args()
    if args.token != '':
        token = args.token
    if args.file != '':
        user_list_file = args.file
    if args.user != []:
        user_list = args.user

    if user_list_file != '':
        with open(user_list_file) as f:
            for user in f.readlines():
                user_list.append(user.replace('\n', ''))

    # get and parse json
    json_user, json_team = json_parser.parse_json(token)

    if json_user['ok']:
        # make user information list and team information
        user_info_list, team_info = json_parser.make_info(
            json_user, json_team, user_list)

        # collect icons
        icon_collect(user_info_list, team_info)

    else:
        print('Error: invalid token\n')
예제 #7
0
        StructField('trade_pr', DecimalType(7, 3), True),
        StructField('trade_size', IntegerType(), True),
        StructField('bid_pr', DecimalType(7, 3), True),
        StructField('bid_size', IntegerType(), True),
        StructField('ask_pr', DecimalType(7, 3), True),
        StructField('ask_size', IntegerType(), True),
        StructField('partition', StringType(), False),
        StructField('bad_line', StringType(), True)
    ])

    # Import csv file, parse it and write out with the partition on append mode.
    raw = spark.sparkContext.textFile(f"../data/{current_date}.csv")
    parsed_csv = raw.map(lambda line: csv_parser.parse_csv(line))
    csv_df = spark.createDataFrame(parsed_csv, schema=output_schema)
    csv_df.write.partitionBy("partition").mode("append").parquet(
        f"../output/{current_date}/")

    # Import json file, parse it and write out with the partition on append mode.
    raw = spark.sparkContext.textFile(f"../data/{current_date}.json")
    parsed_json = raw.map(lambda line: json_parser.parse_json(line))
    json_df = spark.createDataFrame(parsed_json, schema=output_schema)
    json_df.write.partitionBy("partition").mode("append").parquet(
        f"../output/{current_date}/")

    # Update job status accordingly in MySQL if there is no exception
    tracker.update_job_status("success")
except Exception as e:
    print(e)
    # Update job status accordingly in MySQL if there is exception
    tracker.update_job_status("failed")
예제 #8
0
파일: cli.py 프로젝트: Monospark/firebender
def main():
    parser = argparse.ArgumentParser(add_help=True,
                                     description="Control firebender")
    subparsers = parser.add_subparsers(help="commands")
    start_group = subparsers.add_parser("start")
    start_group.add_argument("engine",
                             action="store",
                             choices=("dragon", "wsr"))
    start_group.add_argument("-s", "--shell", action="store_true")
    start_group.add_argument("-l", "--locale", action="store", default="en")
    start_group.add_argument("-m", "--modules", action="store", default=None)
    start_group.add_argument("-c", "--configs", action="store", default=None)

    stop_group = subparsers.add_parser("stop")

    status_group = subparsers.add_parser("status")

    link_group = subparsers.add_parser("dragon")
    link_group.add_argument("action",
                            action="store",
                            choices=("link", "unlink"))

    args = parser.parse_args()

    if "status" in sys.argv:
        print Server.get_status_string()
        return 0

    if "dragon" == sys.argv[1]:
        if args.action == "link":
            dragon_link.install()
        else:
            dragon_link.uninstall()
        return

    if "stop" in sys.argv:
        Server.send_stop()
        return 0

    if not args.shell:
        modified_arguments = list(sys.argv[1:])
        modified_arguments.insert(0, "firebender")
        modified_arguments.append("-s")
        subprocess.Popen(" ".join(modified_arguments))
        return 0

    if Server.get_status() != Status.INACTIVE:
        print "Server is already running"
        return 1

    if args.modules is None:
        print("Missing modules parameter")
        return 1
    if not os.path.isdir(args.modules):
        print("modules parameter is not an existing directory")
        return 1
    if args.configs is None:
        print("Missing configs parameter")
        return 1
    if not os.path.isdir(args.configs):
        print("configs parameter is not an existing directory")
        return 1
    loader.modules_directory = args.modules
    loader.configs_directory = args.configs
    loader.locale = args.locale

    logging.basicConfig(level=logging.INFO)
    if args.engine == "dragon":
        data = json_parser.parse_json("dragon_data.json")
        if data is None:
            print("Run firebender dragon link first.")
            return 1

        DragonServer(data["location"])
    else:
        WsrServer()