Commit e577ac27 by Csók Tamás

client: made a python package using distutils

parent a6d13d07
# file GENERATED by distutils, do NOT edit
cloud.py
cloud2
cloud_connect_from_linux.py
remmina_crypt.c
remmina_pref.c
remmina_string_array.c
remminapasswdmodule.c
setup.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Main program of the Client written for CIRCLE Cloud.
The Client job is to help the ease of use of the cloud system.
"""
import platform
import argparse
try:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
except ImportError:
pass
class Struct:
"""
A struct used for parameter passing
Keyword arguments:
state -- State of the Virtual Computer (running, etc..)
protocol -- SSH, NX and RDP possible
host -- Address of the Virtual Computer
port -- The port where we can access the Virtual Computer
user -- Username used for the connection
password -- Password used for the connection
"""
pass
def parse_arguments():
"""
Argument parser, based on the argparse module
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"uri", type=str, help="Specific schema handler", nargs='?',
default=None)
parser.add_argument("-u", "--username", type=str)
parser.add_argument("-p", "--password", type=str)
parser.add_argument(
"-d",
"--driver",
help=("Select webdriver. Aside from Firefox, you have to install "
"first the proper driver."),
type=str,
choices=['firefox', 'chrome', 'ie', 'opera'],
default="firefox")
args = parser.parse_args()
return args
class Browser:
"""
Browser initialisation
Keyword arguments:
@param args -- args.driver tells us which installed browser
we want to use with selenium.
"""
def __init__(self, args):
self.args = args
if args.driver == "firefox":
self.driver = webdriver.Firefox()
elif args.driver == "chrome":
self.driver = webdriver.Chrome()
elif args.driver == "ie":
self.driver = webdriver.Ie()
elif args.driver == "opera":
self.driver = webdriver.Opera()
self.driver.implicitly_wait(10)
def login(self):
"""
Eduid login based on the given console arguments
"""
driver = self.driver
args = self.args
if args.username is not None:
driver.find_element_by_name("j_username").clear()
driver.find_element_by_name("j_username").send_keys(args.username)
if args.password is not None:
driver.find_element_by_name("j_password").clear()
driver.find_element_by_name("j_password").send_keys(args.password)
if args.username is not None and args.password is not None:
driver.find_element_by_css_selector(
"input[type='submit']").click()
def main(self):
"""
Use of the https://cloud.bme.hu/
Keyword arguments:
@return vm -- Necessarily parameters to connect
to the Virtual Machine
"""
vm = Struct()
driver = self.driver
driver.maximize_window()
driver.get("https://cloud.bme.hu/")
# driver.find_element_by_css_selector("a[href*='/login/']").click()
# self.login()
vm.state, vm.protocol = "", "NONE"
try:
while vm.state.upper()[:3] not in ("FUT", "RUN"):
WebDriverWait(driver, 7200).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
"#vm-details-pw-eye.fa.fa-eye-slash")))
vm.state = driver.find_element_by_css_selector(
"#vm-details-state > span").text
# cl: connection string converted to list
cl = driver.find_element_by_css_selector(
"#vm-details-connection-string").get_attribute(
"value").split()
if cl[0] == "sshpass":
vm.protocol = "SSH"
vm.user, vm.host = cl[6].split("@")
vm.password, vm.port = cl[2], cl[8]
elif cl[0] == "rdesktop":
vm.protocol = "RDP"
vm.host, vm.port = cl[1].split(":")
vm.user, vm.password = cl[3], cl[5]
driver.find_element_by_css_selector("a[href*='/logout/']").click()
except:
print "Browser session timed out!"
raise
return vm
def main():
"""
Main program
"""
try:
args = parse_arguments()
if args.uri is not None:
vm = Struct()
x, vm.protocol, vm.user, vm.password, vm.host, vm.port = \
args.uri.split(':', 5)
vm.protocol = vm.protocol.upper()
vm.state = "RUN"
else:
browser = Browser(args)
vm = browser.main()
browser.driver.quit()
if platform.system() == "Linux":
from cloud_connect_from_linux import connect
elif platform.system() == "Windows":
from cloud_connect_from_windows import connect
if vm.state.upper()[:3] in ("FUT", "RUN"):
connect(vm)
except:
print "Unknown error occurred! Please contact the developers!"
if __name__ == "__main__":
main()
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cloud
if __name__ == '__main__':
try:
cloud.main()
finally:
pass
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Configuration of the Linux specific tools to enhance the ease of use
of the CIRCLE cloud. Handles the auto launch and auto configuration
of these specific connectivity programs.
"""
import time
import os
import subprocess
import glob
import remminapasswd
def connect(vm):
"""
Handles to connection to the Virtual Machines from the local
machine
Keyword arguments:
vm.protocol -- SSH, NX and RDP possible
vm.host -- Address of the Virtual Computer
vm.port -- The port where we can access the Virtual Computer
vm.user -- Username used for the connection
vm.password -- Password used for the connection
"""
if vm.protocol == "SSH":
command = ("sshpass -p %(password)s ssh -p %(port)s"
" -o StrictHostKeyChecking=no %(user)s@%(host)s" % {
'password': vm.password,
'port': vm.port,
'user': vm.user,
'host': vm.host
})
subprocess.call(command, shell=True)
elif vm.protocol in ("NX", "RDP"):
server = "%s:%s" % (vm.host, vm.port)
listdir = os.path.expanduser("~/.remmina/*.remmina")
found = False
for config_file in glob.glob(listdir):
with open(config_file) as f:
if server in f.read():
found = True
break
if not found:
config_file = "%s%s%s" % (
os.path.expanduser("~/.remmina/"),
str(int(time.time()*1000)), ".remmina")
password = remminapasswd.remminapasswd(vm.password)
f = open(config_file, 'w')
if vm.protocol == "NX":
f.write(NX_template)
else:
f.write(RDP_template)
f.write("name=%(protocol)s:%(server)s\nprotocol=%(protocol)s\n"
"server=%(server)s\nusername=%(username)s\n"
"password=%(password)s\n" % {
'protocol': vm.protocol,
'server': server,
'username': vm.user,
'password': password
})
f.close()
subprocess.call(["remmina", "-c", config_file])
NX_template = """[remmina]
ssh_auth=0
quality=2
disableencryption=0
ssh_loopback=0
ssh_enabled=0
nx_privatekey=
showcursor=0
disableclipboard=0
window_maximize=1
viewmode=4
"""
RDP_template = """[remmina]
disableclipboard=0
ssh_auth=0
quality=2
console=0
ssh_loopback=0
shareprinter=0
sound=off
ssh_enabled=0
colordepth=24
window_maximize=1
viewmode=4
"""
...@@ -44,6 +44,10 @@ remminapasswd = Extension('remminapasswd', ...@@ -44,6 +44,10 @@ remminapasswd = Extension('remminapasswd',
setup(name='CIRCLE Client', setup(name='CIRCLE Client',
version='0.1', version='0.1',
license='GPLv3',
platform=[
'linux2',
'posix'],
description='Connectivity helper for CIRCLE cloud system', description='Connectivity helper for CIRCLE cloud system',
long_description=( long_description=(
'Tool to enhance ease of use of the CIRCLE by ' 'Tool to enhance ease of use of the CIRCLE by '
...@@ -59,8 +63,18 @@ setup(name='CIRCLE Client', ...@@ -59,8 +63,18 @@ setup(name='CIRCLE Client',
classifiers=[ classifiers=[
'Development Status :: 4 - Beta', 'Development Status :: 4 - Beta',
'Environment :: Web Environment', 'Environment :: Web Environment',
'Environment :: X11 Applications',
'Operating System :: POSIX :: Linux',
'Operating System :: Unix',
'Intended Audience :: End Users/Desktop', 'Intended Audience :: End Users/Desktop',
'Intended Audience :: System Administrators', 'Intended Audience :: System Administrators',
'Programming Language :: Python/C', 'Programming Language :: Python :: 2.7',
'Topic :: Office/Business'], 'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: C',
'Programming Language :: Unix Shell',
('License :: OSI Approved :: GNU General Public'
'License v3 or later (GPLv3+)'),
'Natural Language :: English',
'Topic :: Office/Business',
'Topic :: System :: Networking'],
ext_modules=[remminapasswd]) ext_modules=[remminapasswd])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment