コード例 #1
0
ファイル: utils.py プロジェクト: nall/pythonista-tradervue
def main():
  global LOG
  LOG = logging.getLogger()
  LOG.setLevel(logging.INFO)
  if DEBUG > 1:
    LOG.setLevel(logging.DEBUG)
  c = logging.StreamHandler()
  c.setFormatter(TradervueLogFormatter())
  LOG.addHandler(c)

  args = get_args(sys.argv[1:])

  actions = { 'set_password': set_password,
           'delete_password': delete_password,
                  'new_note': new_note,
            'update_journal': update_journal }

  ok = False
  if args['action'] not in actions:
    raise ValueError("Invalid action '%s'" % (args['action']))
  elif args['action'].endswith('_password'):
    ok = actions[args['action']](args)
  else:
    p = keychain.get_password(KEYCHAIN_ID, args['user'])
    if p is None:
      # Request one from the user
      p = console.password_alert("Tradervue Credentials", args['user'])
    else:
      tv = Tradervue(args['user'], p, USER_AGENT, verbose_http = True if DEBUG > 1 else False)
      ok = actions[args['action']](args, tv)

  return 0 if ok else 1
コード例 #2
0
    def __init__(self,
                 host='127.0.0.1',
                 port=9022,
                 user='******',
                 passwd=None,
                 privatekey=None):
        '''LocalSSH session
        :host: the default is localhost (127.0.0.1)
        :port: can't be the default 22 since iOS doesn't allow that
        :user: user to login in as
        passwd: can be ignored will be prompted for later
        pirvatekey: 
        '''
        self.client = paramiko.SSHClient()
        self.client.load_system_host_keys()
        self.client.load_host_keys(known_hosts)
        self.client.set_missing_host_key_policy(PromptHost())
        if not passwd:
            passwd = console.password_alert(
                'SSH password for {user}@{host}'.format(user=user, host=host))

        if not privatekey:
            self.client.connect(host,
                                username=user,
                                password=passwd,
                                port=port)
        else:
            try:
                self.client.connect(host,
                                    username=username,
                                    password=passwd,
                                    port=port,
                                    key_filename=privatekey)
            except paramiko.SSHException as e:
                print('Failed to login with SSH Keys: {}'.format(repr(e)))
コード例 #3
0
 def _get_key(self):
     """Retrieve the working copy key or prompt for a new one."""
     key = keychain.get_password('wcSync', 'xcallback')
     if not key:
         key = console.password_alert('Working Copy Key')
         keychain.set_password('wcSync', 'xcallback', key)
     return key
コード例 #4
0
	def _get_key(self):
		''' Retrieve the working copy key or prompt for a new one.
		'''
		key = keychain.get_password('wcSync', 'xcallback')
		if not key:
			key = console.password_alert('Working Copy Key')
			keychain.set_password('wcSync', 'xcallback', key)
		return key
コード例 #5
0
ファイル: working_copy.py プロジェクト: miwagner1/Pythonista
 def _get_key(self):
   ''' Retrieve the working copy key or prompt for a new one. See https://github.com/ahenry91/wc_sync
   '''
 
   key = keychain.get_password('wcSync', 'xcallback')
   if not key:
     key = console.password_alert('Working Copy Key')
     keychain.set_password('wcSync', 'xcallback', key)
   return key  
コード例 #6
0
ファイル: working_copy.py プロジェクト: betoborda/Pythonista
    def _get_key(self):
        ''' Retrieve the working copy key or prompt for a new one. See https://github.com/ahenry91/wc_sync
    '''

        key = keychain.get_password('wcSync', 'xcallback')
        if not key:
            key = console.password_alert('Working Copy Key')
            keychain.set_password('wcSync', 'xcallback', key)
        return key
コード例 #7
0
def arm_system(sender):
	global system_armed
	password = "******"
	if system_armed == False:
		password = console.password_alert("Enter Password to Arm System")
		if (password == "pied"):
			console.alert("WARNING! System Armed", "System Is Now Ready To Fire.  Please Use Caution.", button1="Okay", hide_cancel_button=True)
			system_armed = True
			v['status_label'].text = ("System Status: ARMED Ready to Fire")
			sound.play_effect('digital:TwoTone2')
			v['status_label'].text_color = ("red")
			v['arm_system_button'].enabled = False
			v['audio_test_button'].enabled=False
			v['disarm_system_button'].enabled=True
		if (password != "pied"):
			console.alert("Password Incorrect", "Please try again", button1= "OK", hide_cancel_button = True)
			arm_system(sender)
コード例 #8
0
ファイル: util.py プロジェクト: MotherTeresaHS/gitsynchista
def get_password_from_keychain(service, account, message=None):
  ''' Retrieve the working copy key or prompt for a new one. See https://github.com/ahenry91/wc_sync
  '''
  
  if not message:
    message = "Enter password for account '%s' of service '%s'" % (account, service)
  key = keychain.get_password(service, account)
  if not key:
    try:
      key = console.password_alert(message)
    except KeyboardInterrupt as k:
      key = None
    
    if key:
      keychain.set_password(service, account, key)
    else:
      keychain.delete_password(service, account)
  return key  
  
コード例 #9
0
def checkKey():
	global key
	key = keychain.get_password('wcSync','xcallback')
	if key == None:
		pwd = console.password_alert('Working Copy Key')
		keychain.set_password('wcSync','xcallback',pwd)
コード例 #10
0
	def bt_connect(self, sender):
		self.host = host = self.view['tf_host'].text
		self.user = user = self.view['tf_user'].text
		self.passkey = passkey = self.view['tf_passkey'].text
		
		if host == '' or user == '' or passkey == '':
			return
		else:
			self.close_keyboard()
			
			
		port = 22
		if self.connect:
			console.show_activity('Disconnecting.....')
			if self.stash:
				#self.stash.user_action_proxy.vk_tapped( self.stash.ui.k_CD ) #kill ssh connection
				self.stash.stashssh.close = True
				
				self.stash = None
				self.busy = False
			try:
				self.ssh.close()
				
			except Exception as e:
				console.hide_activity()
				console.hud_alert(str(e), 'error')
				logging.info('color:red {}'.format(e))
				return
			console.hide_activity()
			self.connect = False
			if not sender == None:
				sender.title = 'Connect'
			self.view['bt_ssh'].enabled = False
			
		else:
			console.show_activity('Connecting.....')
			self.remote_dict = {}
			
			#self.transport = paramiko.Transport((host, port))
			#self.transport.connect(username = user, password = password)
			try:
			
				if self.pass_or_key == 'pass':
					self.ssh = SSHSession(host, username = user, password = passkey)
				elif self.pass_or_key == 'key':
					if host in self.config and 'pass_phrase' in self.config[host]:
						logging.info('color:blown Try to login by using password pharase')
						pass_phrase = self.config[host]['pass_phrase']
						self.ssh = SSHSession(host, username = user, key_file = passkey, password=pass_phrase)
					else:
						self.ssh = SSHSession(host, username = user, key_file = passkey)
						
						
			except paramiko.PasswordRequiredException as e:
				console.hide_activity()
				pass_phrase = console.password_alert('CleverSFTPClient','Private key file is encrypted\nInput password phrase','',hide_cancel_button=False)
				if not host in self.config:
					self.make_new_host(host)
				self.config[host]['pass_phrase'] = pass_phrase
				self.config.write(open(config_path, 'w'))
				self.bt_connect(sender)
				return
				
			except Exception as e:
				if e.message == 'Unable to parse key file' or e.message == 'Not a valid RSA private key file (bad ber encoding)' or e.message == 'Not a valid DSS private key file (bad ber encoding)':
					console.hud_alert('Wrong pass phrase','error')
					pass_phrase = console.password_alert('CleverSFTPClient','Private key file is encrypted\nInput pass phrase','',hide_cancel_button=False)
					if not host in self.config:
						self.make_new_host(host)
					self.config[host]['pass_phrase'] = pass_phrase
					self.config.write(open(config_path, 'w'))
					self.bt_connect(sender)
					return
					
				console.hide_activity()
				console.hud_alert(str(e), 'error')
				logging.info('color:red {}'.format(e))
				print(traceback.format_exc())
				return
				
			self.connect = True
			console.hud_alert('Successful!!',duration=0.5)
		
			self.view['bt_ssh'].enabled = True
			#threading.Thread(target=self.bt_ssh, args=(None,)).start()
			try:
				try:
					from stash.stash import StaSh
				except:
					stash_installer()
				finally:
					from stash.stash import StaSh
					
				self.stash = StaSh()
				self.stash.ui.width, self.stash.ui.height = ui.get_screen_size()
				self.stash.csc_ssh = self.ssh.ssh
				self.stash("'{}'&".format(os.path.join(core_path, 'ssh')))
				
				
			except Exception as e:
				print('fr'+str(e))
				
			#self.csc_ssh = threading.enumerate()[0].csc_ssh
			
			
			if not host in self.config:
				self.make_new_host(host)
			self.config[host]['user'] = user
			if self.pass_or_key == 'pass':
				self.config[host]['password'] = passkey
			elif self.pass_or_key == 'key':
				self.config[host]['key'] = passkey
				
			self.config.write(open(config_path, 'w'))
			
			#self.sftp = paramiko.SFTPClient.from_transport(self.transport)
			self.sftp = self.ssh.sftp
			self.sftp.chdir('.')
			self.remotePath = self.sftp.getcwd()
			
			self.refresh_remote_list()
			
			sender.title = 'Disconnect'
			console.hide_activity()
			
			logging.info( 'color:blown Connect with {}:{}'.format(host,port))
			logging.info( 'color:blown Name {}'.format(self.config[host]['name']))
コード例 #11
0
    outfile.close()

def file_get_contents(filename):
    with open(filename,'rb') as f:
        return f.read()

def file_set_contents(filename, contents):
    with open(filename,'wb') as f:
        f.write(contents)
				
#input = workflow.get_input()
#input = file_get_contents(editor.get_path())
input = editor.get_text()

root, documentfilename = editor.to_relative_path(editor.get_path())

# prompt user for password
password = console.password_alert("Document Password Required", "Enter your password",'',"OK")

inputfile = tempfile.NamedTemporaryFile(delete=False)
outputfile = tempfile.NamedTemporaryFile(delete=False)
file_set_contents(inputfile.name, input)
encryptFile(inputfile, password, outputfile)
result = file_get_contents(outputfile.name)
os.remove(inputfile.name)
os.remove(outputfile.name)
end = len(input)
result64 = base64.b64encode(result)
editor.replace_text(0,end,result64)
console.hud_alert('Encryption Completed', 'info')
コード例 #12
0
# https://gist.github.com/greinacker/0a4f2b0a64b7c5b13a48

import sys
import clipboard
import keychain
import console
import api
import webbrowser

return_url = None
if len(sys.argv) >= 2:
    return_url = sys.argv[1]

api_key = keychain.get_password("linode", "api_key")
if api_key == None:
    api_key = console.password_alert("Enter Linode API key")
    keychain.set_password("linode", "api_key", api_key)

linode = api.Api(api_key)

DATACENTER_ID = 2
PLAN_ID = 1
IMAGE_NAME = "dev image"
NODE_LABEL = "dev01"
NODE_GROUP = "Dev"
DISK1_SIZE = 22000
DISK_SWAP_SIZE = 256

print "selecting kernel"
kernel_id = 0
kernels = linode.avail_kernels(isKVM=1)
コード例 #13
0
SITE_BRANCH = 'master' # either master or gh-pages
COMMITTER = {'name': 'Joe Bloggs', 'email': '*****@*****.**'}

#keychain.delete_password('GitHub', 'username')    # Uncomment these lines
#keychain.delete_password('GitHub', 'token')       # to change the details
#keychain.delete_password('GitHub', 'repository')  # stored in the keychain

# Get Username, API Token and Repository
username = keychain.get_password('GitHub', 'username')
if not username:
	username = console.input_alert("Username", "Enter your GitHub Username", '', "Save")
	keychain.set_password('GitHub', 'username', username)
	
tokn = keychain.get_password('GitHub', 'token')
if not tokn:
	tokn = console.password_alert("API Token", "Enter your GitHub API Token", '', "Save")
	keychain.set_password('GitHub', 'token', tokn)

repo = keychain.get_password('GitHub', 'repository')
if not repo:
	repo = console.input_alert("Repository", "Enter your GitHub Repository name", '', "Save")
	keychain.set_password('GitHub', 'repository', repo)

# Mangle the post ;)
post_text = editor.get_text()

post_sections = post_text.split('---')
if len(post_sections) > 1:
	yaml_header = post_sections[1].splitlines()
	
  # Find the title in the YAML
コード例 #14
0
ファイル: ec2_stop.py プロジェクト: DionGijswijt/Pythonista-1
import time
import keychain
import clipboard
import console
import webbrowser

instance_id = "i-123456ab"
key = "ABCDEFGHIJKLMNOPQRST"

return_url = None
if len(sys.argv) >= 2:
    return_url = sys.argv[1]

secret = keychain.get_password("aws", key)
if secret == None:
    secret = console.password_alert("Enter secret key")
    keychain.set_password("aws", key, secret)

print "Connecting"
ec2_conn = boto.connect_ec2(aws_access_key_id=key,
                            aws_secret_access_key=secret)

print "Stopping instance"
ec2_conn.stop_instances(instance_ids=[instance_id])

msg = "Shutdown in progress"
clipboard.set(msg)
print msg

if return_url != None:
    webbrowser.open(return_url)
コード例 #15
0
def checkKey():
	global key
	key = keychain.get_password('wcSync','xcallback')
	if key == None:
		pwd = console.password_alert('Working Copy Key')
		keychain.set_password('wcSync','xcallback',pwd)
コード例 #16
0
    with open(filename, 'rb') as f:
        return f.read()


def file_set_contents(filename, contents):
    with open(filename, 'wb') as f:
        f.write(contents)


#input = workflow.get_input()
#input = file_get_contents(editor.get_path())
input64 = editor.get_text()
input = base64.b64decode(input64)

root, documentfilename = editor.to_relative_path(editor.get_path())

# prompt user for password
password = console.password_alert("Document Password Required",
                                  "Enter your password", '', "OK")

inputfile = tempfile.NamedTemporaryFile(delete=False)
outputfile = tempfile.NamedTemporaryFile(delete=False)
file_set_contents(inputfile.name, input)
decryptFile(inputfile, password, outputfile)
result = file_get_contents(outputfile.name)
os.remove(inputfile.name)
os.remove(outputfile.name)
end = len(input64)
editor.replace_text(0, end, result)
console.hud_alert('Decryption Completed', 'info')
コード例 #17
0
ファイル: utils.py プロジェクト: nall/pythonista-tradervue
def set_password(args):
  p = console.password_alert("Tradervue Credentials", args['user'])
  keychain.set_password(KEYCHAIN_ID, args['user'], p)
  return True
コード例 #18
0
ファイル: tennis game.py プロジェクト: TypeRHonda/Clone1
#coding: utf-8
import random
import console
import speech
password = '******'
start = console.password_alert('enter the password: '******'Times_New_Roman', 15)
    purple = 0.5
    computer = random.randrange(1, 4)
    volleys = 1
    player = int(
        raw_input(
            '<1> forehand \n <2> backhand \n <3> lob \n <4> spike \n pick a swing: '
        ))
    #swings and outputs
    while player and volleys < 25:
        console.set_color(0.5, 0.3, purple)
        if player == 1 and computer == 2:
            speech.say('it\'s on the left')
        elif player == 1 and computer == 3:
            speech.say('it\'s up')
        elif player == 1 and computer == 4:
            speech.say('it\'s coming fast')
        if player == 2 and computer == 1:
            speech.say('he hit it back')
        elif player == 2 and computer == 3: