def main():
    parser = argparse.ArgumentParser("analyze hotspots", add_help=True)
    parser.add_argument('-x', help='report to run', choices=['poc_reliability', 'poc_v10'], required=True)

    parser.add_argument('-c', '--challenges', help='number of challenges to analyze, default:500', default=500, type=int)
    parser.add_argument('-n', '--name', help='hotspot name to analyze with dashes-between-words')
    parser.add_argument('-a', '--address', help='hotspot address to analyze')

    args = parser.parse_args()

    H = Hotspots()
    hotspot = None
    if args.name:
        hotspot = H.get_hotspot_by_name(args.name)
        if hotspot is None:
            raise ValueError(f"could not find hotspot named '{args.name}' use dashes between words")
    elif args.address:
        hotspot = H.get_hotspot_by_addr(args.address)
        if hotspot is None:
            raise ValueError(f"could not find hotspot address '{args.address}' ")
    else:
        raise ValueError("must provide hotspot address '--address' or name '--name'")

    challenges = utils.load_challenges(hotspot['address'], args.challenges)
    if args.x == 'poc_reliability':
        poc_reliability(hotspot, challenges)
    elif args.x == 'poc_v10':
        pocv10_violations(hotspot, challenges)
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser("analyze hotspots", add_help=True)
    parser.add_argument(
        '-x',
        help='report to run',
        choices=['poc_reliability', 'poc_v10', 'poc_polar', 'poc_summary'],
        required=True)

    parser.add_argument('-c',
                        '--challenges',
                        help='number of challenges to analyze, default:500',
                        default=500,
                        type=int)
    parser.add_argument(
        '-n',
        '--name',
        help='hotspot name to analyze with dashes-between-words')
    parser.add_argument('-a', '--address', help='hotspot address to analyze')

    args = parser.parse_args()
    H = Hotspots()
    hotspot = None
    if args.name:
        hotspot = H.get_hotspot_by_name(args.name)
        if hotspot is None:
            raise ValueError(
                f"could not find hotspot named '{args.name}' use dashes between words"
            )
    elif args.address:
        hotspot = H.get_hotspot_by_addr(args.address)
        if hotspot is None:
            raise ValueError(
                f"could not find hotspot address '{args.address}' ")
    else:
        raise ValueError(
            "must provide hotspot address '--address' or name '--name'")

    challenges = utils.load_challenges(hotspot['address'], args.challenges)
    challenges = challenges[:args.challenges]
    if len(challenges) < 2:
        print(
            f"ERROR could not load challenges, either hotspot has been offline too long or you need to increase --challenge arguement"
        )
        return
    days, remainder = divmod(challenges[0]['time'] - challenges[-1]['time'],
                             3600 * 24)
    hours = int(round(remainder / 3600, 0))
    print(
        f"analyzing {len(challenges)} challenges from block {challenges[0]['height']}-{challenges[-1]['height']} over {days} days, {hours} hrs"
    )

    if args.x == 'poc_summary':
        poc_summary(hotspot, challenges)
    if args.x == 'poc_reliability':
        poc_reliability(hotspot, challenges)
    if args.x == 'poc_polar':
        poc_polar(hotspot, challenges)
    if args.x == 'poc_v10':
        pocv10_violations(hotspot, challenges)
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser("analyze hotspots", add_help=True)
    parser.add_argument('-x', help='report to run', choices=['beacons', 'witnesses', 'challenges'], required=True)
    parser.add_argument('-c', '--challenges', help='number of challenges to analyze, default:400', default=400, type=int)
    parser.add_argument('-n', '--name', help='hotspot name to analyze with dashes-between-words')
    parser.add_argument('-a', '--address', help='hotspot address to analyze')
    parser.add_argument('-d', '--details', help='return detailed report (listing each activity)', action='store_true')

    args = parser.parse_args()

    H = Hotspots()
    hotspot = None
    if args.name:
        hotspot = H.get_hotspot_by_name(args.name)
        if hotspot is None:
            raise ValueError(f"could not find hotspot named '{args.name}' use dashes between words")
    elif args.address:
        hotspot = H.get_hotspot_by_addr(args.address)
        if hotspot is None:
            raise ValueError(f"could not find hotspot address '{args.address}' ")
    else:
        raise ValueError("must provide hotspot address '--address' or name '--name'")

    challenges = utils.load_challenges(hotspot['address'], args.challenges)
    challenges = challenges[:args.challenges]
    if len(challenges) < 2:
        print(f"ERROR could not load challenges, either hotspot has been offline too long or you need to increase --challenge arguement")
        return
    days, remainder = divmod(challenges[0]['time'] - challenges[-1]['time'], 3600 * 24)
    hours = int(round(remainder / 3600, 0))
    print(f"analyzing {len(challenges)} challenges from block {challenges[0]['height']}-{challenges[-1]['height']} over {days} days, {hours} hrs")

    if args.x == 'beacons':
        transmit_details(hotspot, challenges, smry_only=not args.details)
    elif args.x == 'witnesses':
        witness_detail(hotspot, challenges, smry_only=not args.details)
    elif args.x == 'challenges':
        challenger_details(hotspot, challenges, smry_only=not args.details)
    else:
        print(f"unsupported report")
Ejemplo n.º 4
0
@login_required
@admin_required
def dalete_user(user_id):
    from models.user import User
    user = User.query.filter(User.id == user_id).first()
    if user and user.login != 'admin':
        db_session.delete(user)
        db_session.commit()
        return jsonify(message='ok'), 200

    return jsonify(message='error'), 400


# This function will automatically remove database sessions at the end of the
# request or when the application shuts down
@app.teardown_appcontext
def shutdown_session(exception=None):
    db_session.remove()


if __name__ == '__main__':
    utils.setup_logger()
    utils.check_privs()
    utils.load_challenges(enabled_challenges, client, solved_challenges)
    utils.build_challenges(enabled_challenges)
    utils.init_database(bcrypt)
    threading.Thread(target=utils.remove_orphans,
                     args=(client, keepalive_containers,
                           enabled_challenges)).start()
    app.run(host='127.0.0.1')