示例#1
0
    def submit(self, session=None, otp='', gui_cmd=None, configFile=None):
        if not session:
            return

        logic_logger.debug("session: " + str(session.hash))

        compute_node = session.hash['node']
        port_string = session.hash.get('port', '')
        if port_string:
            port_number = int(port_string)
        else:
            port_number = 5900 + int(session.hash['display'])

        login_node = session.hash['nodelogin']
        local_port_number = rcm_utils.get_unused_portnumber()

        try:
            tunnelling_method = json.loads(parser.get('Settings',
                                                      'ssh_client'))
        except Exception:
            tunnelling_method = "internal"
        logic_logger.info("Using " + str(tunnelling_method) +
                          " ssh tunnelling")

        plugin_exe = plugin.TurboVNCExecutable()
        plugin_exe.build(session=session, local_portnumber=local_port_number)

        st = thread.SessionThread(plugin_exe.command, login_node,
                                  self.proxynode, self.user, self.password,
                                  gui_cmd, configFile, local_port_number,
                                  compute_node, port_number, tunnelling_method)

        self.session_threads.append(st)
        st.start()
示例#2
0
 def load_settings(self):
     try:
         debug_log_level = json.loads(
             parser.get('Settings', 'debug_log_level'))
         self.settings['debug_log_level'] = debug_log_level
     except Exception:
         self.settings['debug_log_level'] = False
     try:
         ssh_client = json.loads(parser.get('Settings', 'ssh_client'))
         self.settings['ssh_client'] = ssh_client
     except Exception:
         self.settings['ssh_client'] = "internal"
     try:
         preload_command = json.loads(
             parser.get('Settings', 'preload_command'))
         self.settings['preload_command'] = preload_command
     except Exception:
         self.settings['preload_command'] = ""
示例#3
0
    def build(self, session, local_portnumber):
        nodelogin = session.hash['nodelogin']
        # local_portnumber = rcm_utils.get_unused_portnumber()

        tunnel = session.hash['tunnel']
        try:
            tunnelling_method = json.loads(parser.get('Settings',
                                                      'ssh_client'))
        except Exception:
            tunnelling_method = "internal"
        logic_logger.info("Using " + str(tunnelling_method) +
                          " ssh tunnelling")

        # Decrypt password
        vncpassword = session.hash.get('vncpassword', '')
        rcm_cipher = cipher.RCMCipher()
        vncpassword_decrypted = rcm_cipher.decrypt(vncpassword)

        # Darwin
        if sys.platform.startswith('darwin'):
            self.add_arg_value(
                "-W", "vnc://:" + vncpassword_decrypted + "@127.0.0.1:" +
                str(local_portnumber))

        # Win64
        elif sys.platform == 'win32':
            self.add_default_arg("/nounixlogin")
            self.add_default_arg("/noreconnect")
            self.add_default_arg("/nonewconn")
            self.add_arg_value("/loglevel", "0")
            self.add_arg_value("/password", vncpassword_decrypted)

        # Linux
        else:
            self.add_arg_value("-quality", "80")
            self.add_arg_value("-password", vncpassword_decrypted)
            self.add_default_arg("-noreconnect")
            self.add_default_arg("-nonewconn")

        if not sys.platform.startswith('darwin'):
            if tunnel == 'y':
                self.add_default_arg("127.0.0.1:" + str(local_portnumber))
            else:
                self.add_default_arg(nodelogin + ":" +
                                     str(session.hash['display']))

        service_command_without_password = self.command
        if vncpassword_decrypted:
            service_command_without_password = service_command_without_password.replace(
                vncpassword_decrypted, "***")
        logic_logger.debug("service cmd: " +
                           str(service_command_without_password))
示例#4
0
    def __init__(self):
        self.user = ''
        self.password = ''
        self.auth_method = ''
        self.preload = ''

        self.subnet = ''
        self.proxynode = ''
        self.commandnode = ''

        self.server_config = None
        self._api_version = None

        # here we instantiate the remote procedure call stub, it will automatically
        # have all the methods of rcm_protocol_server.rcm_protocol class
        self.protocol = rcm_protocol_client.get_protocol()
        self.protocol.decorate = self.prex

        self.session_threads = []
        self.rcm_server_command = json.loads(
            parser.get('Settings',
                       'preload_command',
                       fallback=defaults['preload_command']))
示例#5
0
    def __init__(self, pack_info=None):
        self.proxynode = ''
        self.remoteuser = ''
        self.passwd = ''
        self.auth_method = ''

        self.session_thread = []
        self.commandnode = ''

        # here we instatiate the remote procedure call stub, it will automatically
        # have all the methods of rcm_protoclo_server.rcm_protocol class
        # --- TO BE DONE --- handle automatically output type
        self.protocol = rcm_protocol_client.get_protocol()

        def mycall(command):
            return self.prex(command)

        self.protocol.mycall = mycall

        if not pack_info:
            self.pack_info = rcm_utils.pack_info()
        else:
            self.pack_info = pack_info

        self.config = dict()
        self.config['ssh'] = dict()
        self.config['ssh']['win32'] = ("PLINK.EXE", " -ssh", "echo yes | ")
        self.config['ssh']['linux2'] = ("ssh", "", "")
        # for python3
        self.config['ssh']['linux'] = ("ssh", "", "")
        self.config['ssh']['darwin'] = ("ssh", "", "")
        self.config['remote_rcm_server'] = json.loads(
            parser.get('Settings', 'preload_command', fallback='""')
        ) + "module load rcm; python $RCM_HOME/bin/server/rcm_new_server.py"

        self.activeConnectionsList = []

        # set the environment
        if getattr(sys, 'frozen', False):
            logic_logger.debug("Running in a bundle")
            # if running in a bundle, we hardcode the path
            # of the built-in vnc viewer and plink (windows only)
            os.environ['JAVA_HOME'] = resource_path('turbovnc')
            os.environ['JDK_HOME'] = os.environ['JAVA_HOME']
            os.environ['JRE_HOME'] = os.path.join(os.environ['JAVA_HOME'],
                                                  'jre')
            os.environ['CLASSPATH'] = os.path.join(os.environ['JAVA_HOME'], 'lib') + \
                os.pathsep + os.path.join(os.environ['JRE_HOME'], 'lib')
            os.environ['PATH'] = os.path.join(
                os.environ['JAVA_HOME'],
                'bin') + os.pathsep + os.environ['PATH']
            logic_logger.debug("JAVA_HOME: " + str(os.environ['JAVA_HOME']))
            logic_logger.debug("JRE_HOME: " + str(os.environ['JRE_HOME']))
            logic_logger.debug("JDK_HOME: " + str(os.environ['JDK_HOME']))
            logic_logger.debug("CLASSPATH: " + str(os.environ['CLASSPATH']))
        logic_logger.debug("PATH: " + str(os.environ['PATH']))

        # ssh executable
        if sys.platform == 'win32':
            sshexe = rcm_utils.which('PLINK')
        else:
            sshexe = rcm_utils.which('ssh')
        if not sshexe:
            if sys.platform == 'win32':
                logic_logger.error(
                    "plink.exe not found! Check the PATH environment variable."
                )
            else:
                logic_logger.error("ssh not found!")
            sys.exit()
        if sys.platform == 'win32':
            # if the executable path contains spaces, it has to be put inside apexes
            sshexe = "\"" + sshexe + "\""
        self.ssh_command = self.config['ssh'][sys.platform][2] + \
                           sshexe + \
                           self.config['ssh'][sys.platform][1]
        logic_logger.debug("ssh command: " + self.ssh_command)

        self.vnc_cmdline_builder = vnc_client.VNCClientCommandLineBuilder()
        self.vnc_cmdline_builder.build()
示例#6
0
    def vncsession(self, session=None, otp='', gui_cmd=None, configFile=None):
        tunnel_command = ''
        vnc_command = ''
        vncpassword_decrypted = ''
        try:
            tunnelling_method = json.loads(parser.get('Settings',
                                                      'ssh_client'))
        except Exception:
            tunnelling_method = "internal"
        logic_logger.info("Using " + str(tunnelling_method) +
                          " ssh tunnelling")

        if session:
            portnumber = 5900 + int(session.hash['display'])
            local_portnumber = rcm_utils.get_unused_portnumber()
            node = session.hash['node']
            nodelogin = session.hash['nodelogin']
            tunnel = session.hash['tunnel']
            vncpassword = session.hash.get('vncpassword', '')

            # Decrypt password
            rcm_cipher = cipher.RCMCipher()
            vncpassword_decrypted = rcm_cipher.decrypt(vncpassword)

            logic_logger.debug("portnumber --> " + str(portnumber) +
                               " node --> " + str(node) + " nodelogin --> " +
                               str(nodelogin) + " tunnel --> " + str(tunnel))

            if sys.platform.startswith('darwin'):
                vnc_command = self.vnc_cmdline_builder.get_executable_path() + " -quality 80 -subsampling 2X" \
                              + " -password " + vncpassword_decrypted
                vnc_command += " -loglevel " + str(rcm_utils.vnc_loglevel)
            elif sys.platform == 'win32':
                vnc_command = "echo " + vncpassword_decrypted + " | " + self.vnc_cmdline_builder.get_executable_path() \
                              + " -autopass -nounixlogin"
                vnc_command += " -logfile " + os.path.join(
                    rcm_utils.log_folder(), 'vncviewer_' + nodelogin + '_' +
                    session.hash.get('sessionid', '') + '.log')
                vnc_command += " -loglevel " + str(rcm_utils.vnc_loglevel)
            else:
                vnc_command = self.vnc_cmdline_builder.get_executable_path() + " -quality 80 " \
                              + " -password " + vncpassword_decrypted

            if sys.platform == 'win32' or sys.platform.startswith('darwin'):
                if tunnel == 'y':
                    tunnel_command = self.ssh_command + " -L 127.0.0.1:" + str(local_portnumber) + ":" + node + ":" \
                                     + str(portnumber) + " " + self.login_options + "@" + nodelogin
                    if sys.platform.startswith('darwin'):
                        tunnel_command += " echo 'rcm_tunnel'; sleep 20"
                    else:
                        tunnel_command += " echo 'rcm_tunnel'; sleep 10"
                    vnc_command += " 127.0.0.1:" + str(local_portnumber)
                else:
                    vnc_command += " " + nodelogin + ":" + str(portnumber)
            else:
                if tunnel == 'y':
                    if tunnelling_method == 'internal':
                        vnc_command += " 127.0.0.1:" + str(local_portnumber)
                    elif tunnelling_method == 'external':
                        tunnel_command = self.ssh_command + " -L 127.0.0.1:" + str(local_portnumber) + ":" + node + ":" \
                                         + str(portnumber) + " " + self.login_options + "@" + nodelogin
                    elif tunnelling_method == 'via':
                        vnc_command += " -via '" + self.login_options + "@" + nodelogin + "' " \
                                       + node + ":" + str(session.hash['display'])
                    else:
                        logic_logger.error(tunnelling_method +
                                           ' is not a valid option')
                        return
                else:
                    vnc_command += ' ' + nodelogin + ":" + session.hash[
                        'display']
        else:
            vnc_command = self.vnc_cmdline_builder.get_executable_path(
            ) + " -config "

        logic_logger.debug("tunnel->" +
                           tunnel_command.replace(self.passwd, "****") +
                           "< vnc->" + vnc_command + "< conffile->" +
                           str(configFile) + "<")

        st = thread.SessionThread(tunnel_command, vnc_command, self.proxynode,
                                  self.remoteuser, self.passwd,
                                  vncpassword_decrypted, otp, gui_cmd,
                                  configFile, self.auth_method,
                                  local_portnumber, node, portnumber,
                                  tunnelling_method)

        logic_logger.debug("session  thread--->" + str(st) +
                           "<--- num thread:" + str(len(self.session_thread)))
        self.session_thread.append(st)
        st.start()
 def load_settings(self):
     for k in defaults:
         self.settings[k] = json.loads(
             parser.get('Settings', k, fallback=defaults[k]))
示例#8
0
    def init_ui(self):
        """
        Initialize the interface
        """

        # Login Layout
        # grid login layout
        grid_login_layout = QGridLayout()

        try:
            sessions_list = parser.get('LoginFields', 'hostList')
            self.sessions_list = collections.deque(json.loads(sessions_list),
                                                   maxlen=5)
        except Exception:
            pass

        session_label = QLabel(self)
        session_label.setText('Sessions:')
        self.session_combo.clear()
        self.session_combo.addItems(self.sessions_list)

        self.session_combo.activated.connect(self.on_session_change)
        if self.sessions_list:
            self.session_combo.activated.emit(0)

        grid_login_layout.addWidget(session_label, 0, 0)
        grid_login_layout.addWidget(self.session_combo, 0, 1)

        host_label = QLabel(self)
        host_label.setText('Host:')

        grid_login_layout.addWidget(host_label, 1, 0)
        grid_login_layout.addWidget(self.host_line, 1, 1)

        user_label = QLabel(self)
        user_label.setText('User:'******'Password:'******'Login', self)
        self.login_button.clicked.connect(self.login)
        self.login_button.setShortcut("Return")

        login_hor_layout = QHBoxLayout()
        login_hor_layout.addStretch(1)
        login_hor_layout.addWidget(self.login_button)
        login_hor_layout.addStretch(1)

        # container login widget
        # it disappears when the user logged in
        login_layout = QVBoxLayout()
        login_layout.addStretch(1)
        login_layout.addLayout(grid_login_layout)
        login_layout.addLayout(login_hor_layout)
        login_layout.addStretch(1)

        self.containerLoginWidget.setLayout(login_layout)

        # Create the main layout
        new_tab_main_layout = QVBoxLayout()
        new_tab_main_layout.addWidget(self.containerLoginWidget)

        # container waiting widget
        ver_waiting_layout = QVBoxLayout()

        first_hor_waiting_layout = QHBoxLayout()
        second_hor_waiting_layout = QHBoxLayout()
        third_hor_waiting_layout = QHBoxLayout()

        connecting_label = QLabel(self)
        connecting_label.setText("Connecting...")

        first_hor_waiting_layout.addStretch(0)
        first_hor_waiting_layout.addWidget(connecting_label)
        first_hor_waiting_layout.addStretch(0)

        prog_bar = QProgressBar(self)
        prog_bar.setMinimum(0)
        prog_bar.setMaximum(0)
        prog_bar.setAlignment(Qt.AlignCenter)

        second_hor_waiting_layout.addStretch(0)
        second_hor_waiting_layout.addWidget(prog_bar)
        second_hor_waiting_layout.addStretch(0)

        waiting_kill_btn = QPushButton(self)
        waiting_kill_btn.setText('Cancel')
        waiting_kill_btn.setToolTip('Kill the ssh login process')
        waiting_kill_btn.clicked.connect(self.kill_login_thread)

        third_hor_waiting_layout.addStretch(0)
        third_hor_waiting_layout.addWidget(waiting_kill_btn)
        third_hor_waiting_layout.addStretch(0)

        ver_waiting_layout.addStretch(0)
        ver_waiting_layout.addLayout(first_hor_waiting_layout)
        ver_waiting_layout.addLayout(second_hor_waiting_layout)
        ver_waiting_layout.addLayout(third_hor_waiting_layout)
        ver_waiting_layout.addStretch(0)

        self.containerWaitingWidget.setLayout(ver_waiting_layout)
        new_tab_main_layout.addWidget(self.containerWaitingWidget)
        self.containerWaitingWidget.hide()

        # reload waiting widget
        ver_reload_layout = QVBoxLayout()

        first_hor_reload_layout = QHBoxLayout()
        second_hor_reload_layout = QHBoxLayout()
        third_hor_reload_layout = QHBoxLayout()

        reload_label = QLabel(self)
        reload_label.setText("Reloading...")

        first_hor_reload_layout.addStretch(0)
        first_hor_reload_layout.addWidget(reload_label)
        first_hor_reload_layout.addStretch(0)

        reload_prog_bar = QProgressBar(self)
        reload_prog_bar.setMinimum(0)
        reload_prog_bar.setMaximum(0)
        reload_prog_bar.setAlignment(Qt.AlignCenter)

        second_hor_reload_layout.addStretch(0)
        second_hor_reload_layout.addWidget(reload_prog_bar)
        second_hor_reload_layout.addStretch(0)

        reload_btn = QPushButton(self)
        reload_btn.setText('Cancel')
        reload_btn.setToolTip('Kill the reload process')
        reload_btn.clicked.connect(self.kill_reload_thread)

        third_hor_reload_layout.addStretch(0)
        third_hor_reload_layout.addWidget(reload_btn)
        third_hor_reload_layout.addStretch(0)

        ver_reload_layout.addStretch(0)
        ver_reload_layout.addLayout(first_hor_reload_layout)
        ver_reload_layout.addLayout(second_hor_reload_layout)
        ver_reload_layout.addLayout(third_hor_reload_layout)
        ver_reload_layout.addStretch(0)

        self.containerReloadWidget.setLayout(ver_reload_layout)
        new_tab_main_layout.addWidget(self.containerReloadWidget)
        self.containerReloadWidget.hide()

        # container session widget
        plusbutton_layout = QGridLayout()
        self.rows_ver_layout.setContentsMargins(0, 0, 0, 0)
        self.rows_ver_layout.setSpacing(0)

        self.session_ver_layout.addLayout(plusbutton_layout)
        self.session_ver_layout.addLayout(self.rows_ver_layout)
        self.session_ver_layout.addStretch(1)

        font = QFont()
        font.setBold(True)

        name = QLabel()
        name.setText("Name")
        name.setFont(font)
        plusbutton_layout.addWidget(name, 0, 0)

        status = QLabel()
        status.setText("Status")
        status.setFont(font)
        plusbutton_layout.addWidget(status, 0, 1)

        time = QLabel()
        time.setText("Time")
        time.setFont(font)
        plusbutton_layout.addWidget(time, 0, 2)

        resources = QLabel()
        resources.setText("Resources")
        resources.setFont(font)
        plusbutton_layout.addWidget(resources, 0, 3)

        x = QLabel()
        x.setText("")
        plusbutton_layout.addWidget(x, 0, 4)
        plusbutton_layout.addWidget(x, 0, 5)

        new_display_ico = QIcon()
        new_display_ico.addFile(resource_path('gui/icons/plus.png'),
                                QSize(16, 16))

        new_display_btn = QPushButton()
        new_display_btn.setIcon(new_display_ico)
        new_display_btn.setToolTip('Create a new display session')
        new_display_btn.clicked.connect(self.add_new_display)
        new_display_btn.setShortcut(Qt.Key_Plus)

        reload_btn = QPushButton()
        reload_btn.setIcon(self.style().standardIcon(QStyle.SP_BrowserReload))
        reload_btn.setToolTip('Reload the page')
        reload_btn.clicked.connect(self.reload)
        reload_btn.setShortcut("F5")

        new_display_layout = QHBoxLayout()
        new_display_layout.addSpacing(70)
        new_display_layout.addWidget(reload_btn)
        new_display_layout.addWidget(new_display_btn)

        plusbutton_layout.addLayout(new_display_layout, 0, 6)

        self.containerSessionWidget.setLayout(self.session_ver_layout)
        new_tab_main_layout.addWidget(self.containerSessionWidget)
        self.containerSessionWidget.hide()

        self.setLayout(new_tab_main_layout)
示例#9
0
    def init_ui(self):
        """
        Initialize the interface
        :return:
        """

        try:
            display_size_list = parser.get('DisplaySizeField',
                                           'displaysizelist')
            self.display_size_list = collections.deque(
                json.loads(display_size_list), maxlen=5)
        except Exception:
            self.display_size_list.appendleft("full_screen")
            self.display_size_list.appendleft("1024x968")

        # create the grid layout
        grid_layout = QGridLayout()

        # Create session layout
        session_name = QLabel(self)
        session_name.setText('session name:')

        grid_layout.addWidget(session_name, 1, 0)

        session_line = QLineEdit(self)
        session_line.setObjectName('session_line')
        grid_layout.addWidget(session_line, 1, 1)

        session_queue = QLabel(self)
        session_queue.setText('Select queue:')

        self.session_queue_combo = QComboBox(self)
        self.session_queue_combo.addItems(self.session_queues)
        grid_layout.addWidget(session_queue, 2, 0)
        grid_layout.addWidget(self.session_queue_combo, 2, 1)

        session_vnc = QLabel(self)
        session_vnc.setText('Select wm+vnc:')

        self.session_vnc_combo = QComboBox(self)
        self.session_vnc_combo.addItems(self.session_vncs)
        grid_layout.addWidget(session_vnc, 3, 0)
        grid_layout.addWidget(self.session_vnc_combo, 3, 1)

        display_label = QLabel(self)
        display_label.setText('Display size:')

        self.display_combo = QComboBox(self)
        self.display_combo.setEditable(True)
        self.display_combo.addItems(list(self.display_size_list))

        grid_layout.addWidget(display_label, 4, 0)
        grid_layout.addWidget(self.display_combo, 4, 1)

        # Ok button
        hor_layout = QHBoxLayout()
        ok_button = QPushButton('Ok', self)
        ok_button.clicked.connect(self.on_ok)
        hor_layout.addStretch(1)
        hor_layout.addWidget(ok_button)

        # Cancel button
        cancel_button = QPushButton('Cancel', self)
        cancel_button.clicked.connect(self.reject)
        hor_layout.addWidget(cancel_button)
        hor_layout.addStretch(1)

        group_box = QGroupBox("Display options:")
        group_box.setLayout(grid_layout)

        dialog_layout = QVBoxLayout()
        dialog_layout.addWidget(group_box)
        dialog_layout.addSpacing(10)
        dialog_layout.addLayout(hor_layout)
        self.setLayout(dialog_layout)
示例#10
0
# std lib
import sys
import os
import json

# pyqt5
from PyQt5.QtWidgets import QApplication

# add python path
source_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(source_root)

# local includes
from client.gui.rcm_main_window import RCMMainWindow
from client.miscellaneous.config_parser import parser
from client.utils.rcm_enum import Mode
from client.miscellaneous.logger import configure_logger

if __name__ == '__main__':
    try:
        debug_log_level = json.loads(parser.get('Settings', 'debug_log_level'))
        configure_logger(Mode.GUI, debug_log_level)
    except Exception:
        configure_logger(Mode.GUI, False)

    app = QApplication(sys.argv)
    rcm_win = RCMMainWindow()
    rcm_win.show()
    sys.exit(app.exec_())