def run(self, args, cfg):
     terminal = Terminal()
     src = sources.load_source(cfg, args.source)
     if src.rulesPermit(args.src_ip, args.dst_ip, args.app):
         if not args.quiet:
             print terminal.black_on_green("Flow permitted")
     else:
         if not args.quiet:
             print terminal.black_on_red("Flow not permitted")
         sys.exit(1)
コード例 #2
0
ファイル: denied.py プロジェクト: Chonghao/build-fwunit
 def run(self, args, cfg):
     terminal = Terminal()
     src = sources.load_source(cfg, args.source)
     if src.rulesDeny(args.src_ip, args.dst_ip, args.app):
         if not args.quiet:
             print terminal.black_on_green("Flow denied")
     else:
         if not args.quiet:
             print terminal.black_on_red("Flow not denied")
         sys.exit(1)
コード例 #3
0
def poll_chargepoint_stations(scraper, stations_of_interest=None, stations_to_ignore=None):
    if stations_to_ignore is None:
        stations_to_ignore = []
    if stations_of_interest is None:
        stations_of_interest = scraper.get_station_data()['stations'].keys()
    stations_of_interest = [x for x in stations_of_interest if x not in stations_to_ignore]
    old_free_spots = None
    old_open_stations = []
    t = Terminal()
    try:
        i = 0
        while True:
            new_free_spots = 0
            new_open_stations = []
            try:
                data = scraper.get_station_data()
            except ChargePointAuthenticationExpiredException:
                data = scraper.get_station_data()
            if i % 10 == 0:
                print '\t\t\t' + '\t'.join([station for station in stations_of_interest])
            line_parts = [data['time'].strftime('%Y/%m/%d %H:%M:%S')]
            for k in stations_of_interest:
                line_part = '%d / %d'.center(9) % (data['stations'][k]['available'], data['stations'][k]['total'])
                if data['stations'][k]['available'] == data['stations'][k]['total']:
                    line_part = t.black_on_green(line_part)
                elif data['stations'][k]['available'] == 0:
                    line_part = t.black_on_red(line_part)
                else:
                    line_part = t.black_on_yellow(line_part)
                line_parts.append(line_part)
                new_free_spots += data['stations'][k]['available']
                new_open_stations.extend([k] * data['stations'][k]['available'])
            print '\t'.join(line_parts)
            if old_free_spots is not None and new_free_spots > old_free_spots:
                newly_open_stations = new_open_stations
                for elem in old_open_stations:
                    try:
                        newly_open_stations.remove(elem)
                    except ValueError:
                        pass
                title = '%s station(s) are open' % ', '.join(newly_open_stations)
                message = '%d Free Spots' % new_free_spots
                if _platform == 'darwin':
                    Notifier.notify(title=title, message=message)
                send_boxcar_notification(title=title, message=message)
            old_free_spots = new_free_spots
            old_open_stations = new_open_stations
            i += 1
            sleep(60)
    except KeyboardInterrupt:
        pass
    except KeyError:
        exit("Unexpected response json.")
コード例 #4
0
def poll_chargepoint_stations(scraper,
                              stations_of_interest=None,
                              stations_to_ignore=None):
    if stations_to_ignore is None:
        stations_to_ignore = []
    if stations_of_interest is None:
        stations_of_interest = scraper.get_station_data()['stations'].keys()
    stations_of_interest = [
        x for x in stations_of_interest if x not in stations_to_ignore
    ]
    old_free_spots = None
    old_open_stations = []
    t = Terminal()
    try:
        i = 0
        while True:
            new_free_spots = 0
            new_open_stations = []
            try:
                data = scraper.get_station_data()
            except ChargePointAuthenticationExpiredException:
                data = scraper.get_station_data()
            if i % 10 == 0:
                print '\t\t\t' + '\t'.join(
                    [station for station in stations_of_interest])
            line_parts = [data['time'].strftime('%Y/%m/%d %H:%M:%S')]
            for k in stations_of_interest:
                line_part = '%d / %d'.center(9) % (
                    data['stations'][k]['available'],
                    data['stations'][k]['total'])
                if data['stations'][k]['available'] == data['stations'][k][
                        'total']:
                    line_part = t.black_on_green(line_part)
                elif data['stations'][k]['available'] == 0:
                    line_part = t.black_on_red(line_part)
                else:
                    line_part = t.black_on_yellow(line_part)
                line_parts.append(line_part)
                new_free_spots += data['stations'][k]['available']
                new_open_stations.extend([k] *
                                         data['stations'][k]['available'])
            print '\t'.join(line_parts)
            if old_free_spots is not None and new_free_spots > old_free_spots:
                newly_open_stations = new_open_stations
                for elem in old_open_stations:
                    try:
                        newly_open_stations.remove(elem)
                    except ValueError:
                        pass
                title = '%s station(s) are open' % ', '.join(
                    newly_open_stations)
                message = '%d Free Spots' % new_free_spots
                if _platform == 'darwin':
                    Notifier.notify(title=title, message=message)
                send_boxcar_notification(title=title, message=message)
            old_free_spots = new_free_spots
            old_open_stations = new_open_stations
            i += 1
            sleep(60)
    except KeyboardInterrupt:
        pass
    except KeyError:
        exit("Unexpected response json.")
コード例 #5
0
#TIME
now=time.strftime("%Y%m%d_%H%M%S", time.localtime())

#VARIABLES
filename='bckp-'+now+'.tar.gz'

print('\n[INFO] Starting program. It will backup `' + folder + '` to `' + dbx_data.dbx_path + filename)
print("[INFO] Authenticating at Dropbox... ", end="")
sys.stdout.flush()

#DROPBOX AUTHENTICATION
try:
	dbx = dropbox.Dropbox(dbx_data.dbx_access_token)
	account = dbx.users_get_current_account()
	print(term.black_on_green("						[OK]"))
	#print('	- Modified: `' + dbx.files_get_metadata('/Backup/').client_modified + '`')
	print('	- Account_id: `' + account.account_id + '`')
	print('	- Account_name: `' + account.name.given_name+ '`')
	print('	- Account_e-mail: `' + account.email+ '`')
	#print('	- Account_type: `' + account.account_type+ '`')
	#sys.stdout.flush()
except:
	print(term.black_on_red("		[KO]"))
	print("[ERROR] Authentication NOT successful!")
	sys.exit()

#FILE COMPRESSION
print("[INFO] Compressing folders and files... ", end="")
sys.stdout.flush()
try: