示例#1
0
def sendMail(msg, type):

	MAIL_OPTIONS = Options.OptionReader('MailOptions.txt')

	if type == 'alert':
		msg['To'] = email.utils.formataddr(('', MAIL_OPTIONS.getValue('alertmail_recipients')))
	elif type == 'publication':
		msg['To'] = email.utils.formataddr(('', MAIL_OPTIONS.getValue('publicationmail_recipients')))
	else:
		return

	msg['From'] = email.utils.formataddr((MAIL_OPTIONS.getValue('mail_from'), MAIL_OPTIONS.getValue('mail_sender')))

	if type == 'alert':
		recipients = MAIL_OPTIONS.getValue('alertmail_recipients').split(',')
	elif type == 'publication':
		recipients = MAIL_OPTIONS.getValue('publicationmail_recipients').split(',')
	else:
		return

	with open(MAIL_OPTIONS.getValue('mail_credentials'), 'r') as f:
		password = f.read()[:-1]
	server_connection = smtplib.SMTP(MAIL_OPTIONS.getValue('mail_server'), int(MAIL_OPTIONS.getValue('mail_port')))
	try:
		# initiate connection
		server_connection.ehlo()
		# Try to encrypt the session
		if server_connection.has_extn('STARTTLS'):
			server_connection.starttls()
			# reinitiate server connection over TLS
			server_connection.ehlo()
		server_connection.login(MAIL_OPTIONS.getValue('mail_user'), password)
		server_connection.sendmail(MAIL_OPTIONS.getValue('mail_sender'), recipients, msg.as_string())
	finally:
		server_connection.quit()
示例#2
0
	def __init__(self, ip, port):
		Thread.__init__(self)
		self.ip = ip
		self.port = int(port)

		if port == PROXY_OPTIONS.getValue('API_port'):
			self.type = 'API'
			# read client_ips, plainkeys from the key file, generate and store the AES-keys
			self.AES_keys = Options.OptionReader(PROXY_OPTIONS.getValue('AES_key_file'))
			for ip, plainkey in self.AES_keys.options.iteritems():
				AES_key = SHA256.new()
				AES_key.update(plainkey)
				AES_key = AES_key.digest()
				self.AES_keys.setValue(ip, AES_key)			
			
		if port == PROXY_OPTIONS.getValue('tracker_port'):
			self.type = 'tracker'
		
		self.start()
示例#3
0
    def __init__(self, mode, system_options=None):
        self.mode = mode

        # if we want to contact the Proxy, we need SystemOptions.txt for the AESkey and Proxy address:port
        if self.mode == 'Proxy':
            if system_options is not None:
                self.SYSTEMoptions = system_options
                required_keys = ('AES_key', 'proxy_address', 'API_port')
                self.SYSTEMoptions.checkKeys(required_keys)
            else:
                raise Errors.FatalError(
                    msg=
                    'SystemOptions info not provided, only direct API calls possible'
                )

        # if we want to contact the API directly, we need ProxyOptions for the APIkeys and URLs
        if self.mode == 'PPMS API':
            try:
                self.APIoptions = Options.OptionReader('ProxyOptions.txt')
            except:
                raise Errors.FatalError(
                    msg='ProxyOptions.txt is missing, only Proxy calls possible'
                )
示例#4
0
    print(f'FB Bio: {active_users.number_of_users("bio")}, '
          f'FB Che: {active_users.number_of_users("che")}, '
          f'FB Phy: {active_users.number_of_users("phy")}')
    print('--------------------')
    print('Facility statistics:')
    year = 2020
    print(
        f'The facility has given {active_users.number_of_trainings(year)} trainings in {year}.'
    )
    print(f'FB Bio: {active_users.number_of_trainings(year, "bio")}, '
          f'FB Che: {active_users.number_of_trainings(year, "che")}, '
          f'FB Phy: {active_users.number_of_trainings(year, "phy")}')
    print('--------------------')


SYSTEM_OPTIONS = Options.OptionReader('SystemOptions.txt')
calling_mode = SYSTEM_OPTIONS.getValue('calling_mode')

with Timer('Getting facility system info from PPMS...',
           'Microscope list populated!'):
    equipment = Equipment()

with Timer('Getting active users from PPMS...', 'Active user list populated!'):
    active_bic_users = ActiveBICUsers(equipment)

print_microscope_users(equipment.microscope_list)
print_user_info(active_bic_users.user_list)
print_facility_statistics(equipment, active_bic_users)

# for user_login in active_users:
# 	user = BICUser(user_login)
示例#5
0
                data += packet
            return data

        encrypted_call = receive_data(self.connection)

        iv2 = encrypted_call[:AES.block_size]
        ciphered_msg = encrypted_call[AES.block_size:]

        decryptor = AES.new(self.AES_key, AES.MODE_CFB, iv2)
        decrypted_message = decryptor.decrypt(ciphered_msg)
        data_from_client = pickle.loads(decrypted_message)

        print self.address[0] + ' says ' + data_from_client[
            'h'] + data_from_client['s']
        server_response = {'h': 'Hello ', 'c': 'client'}

        iv = Random.new().read(AES.block_size)
        cipher = AES.new(self.AES_key, AES.MODE_CFB, iv)
        pickled_response = pickle.dumps(server_response)
        server_message = iv + cipher.encrypt(pickled_response)

        data_to_client = struct.pack('>I',
                                     len(server_message)) + server_message
        self.connection.sendall(data_to_client)
        self.connection.close()


proxy_options = Options.OptionReader('ServerOptions.txt')
PUMAPIproxy = ListeningSocket(proxy_options.getValue('host_ip'),
                              proxy_options.getValue('API_port'))
                self.itemlist.append(self.child.text)
        return self.itemlist

    def writeRISFile(self, file_name):
        with open(file_name, 'w') as self.f:
            for self.child in self.root.iter('Item'):
                if self.child.get('Name') in EncodeToRIS.Pubmed_to_RIS:
                    try:
                        self.f.write(
                            EncodeToRIS.Pubmed_to_RIS[self.child.get('Name')] +
                            ' - ' + self.child.text + '\n')
                    except TypeError:  # self.child.text returns None if field is empty
                        pass


OPTIONS = Options.OptionReader('PublicationTrackerOptions.txt')

parser = argparse.ArgumentParser("Publication Tracker")
parser.add_argument(
    "year",
    nargs='?',
    help=
    "Specify the year of publication, if omitted current year (last year, if Jan-Mar) will be used",
    type=int)
args = parser.parse_args()

# at the beginning of the year we want to search for papers submitted the year before
if args.year is None:
    date = datetime.now()
    if date.month < 4:
        year = str(date.year - 1)
示例#7
0
		newCall.callParis()

		self.connection.close()

class NewTrackerCall:

	def __init__(self):
		self.header = {
		'Content-Type': 'application/x-www-form-urlencoded',
		}
		# explained in PUMAPI documentation
		self.data = {}
		self.URL = PROXY_OPTIONS.getValue('tracker_URL')

	# adds the parameters specific to each Tracker call
	def config(self, new_settings):
		self.data.update(new_settings)

	# generate full Tracker URL
	def callParis(self):
		url = self.URL + '?i=' + self.data['id'] + '&f=' + self.data['freq'] + '&u=' + self.data['user']
		requests.post(url, headers=self.header, data=self.data['code'])


PROXY_OPTIONS = Options.OptionReader('ProxyOptions.txt')
API_proxy = ListeningSocket(PROXY_OPTIONS.getValue('host_ip'), PROXY_OPTIONS.getValue('API_port'))
tracker_proxy = ListeningSocket(PROXY_OPTIONS.getValue('host_ip'), PROXY_OPTIONS.getValue('tracker_port'))



示例#8
0
            if not packet:
                return None
            data += packet
        return data

    proxy_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    proxy_socket.connect((APIoptions.getValue('proxy_address'),
                          int(APIoptions.getValue('API_port'))))
    proxy_socket.sendall(message)

    response = receive_data(proxy_socket)
    proxy_socket.close()
    return response


APIoptions = Options.OptionReader('ClientOptions.txt')

test_dict = {'h': 'Hello ', 's': 'Server'}
pickled_dict = pickle.dumps(test_dict)

AES_plainkey = APIoptions.getValue('AES_key')
AES_key = SHA256.new()
AES_key.update(AES_plainkey)
AES_key = AES_key.digest()

iv = Random.new().read(AES.block_size)
cipher = AES.new(AES_key, AES.MODE_CFB, iv)
msg = iv + cipher.encrypt(pickled_dict)
data_to_server = struct.pack('>I', len(msg)) + msg

response = sendToProxy(data_to_server)
示例#9
0
#!/usr/bin/env python
# -*- coding: utf-8

import datetime
import os

from lib import Options, PPMSAPICalls, Errors

try:
	current_directory = os.path.dirname(__file__)
	parent_directory = os.path.split(current_directory)[0]
	print(parent_directory)
	SYSTEM_OPTIONS = Options.OptionReader(parent_directory + '/SystemOptions.txt')
except Errors.FatalError as e:
	exit(e.msg)

facility_id = SYSTEM_OPTIONS.getValue('PPMS_facilityid')
system_id = SYSTEM_OPTIONS.getValue('PPMS_systemid')
calling_mode = SYSTEM_OPTIONS.getValue('calling_mode')
user_login = SYSTEM_OPTIONS.getValue('user_login')

get_systemname = PPMSAPICalls.NewCall(calling_mode, SYSTEM_OPTIONS)
try:
	system_name = get_systemname.getSystemName(system_id)
	print(system_name)
except Errors.APIError as e:
	print(e.msg)

get_booking = PPMSAPICalls.NewCall(calling_mode, SYSTEM_OPTIONS)
print(get_booking.getTodaysBookings(facility_id, system_name))