Revision 9ed51b7e ui/views.py

b/ui/views.py
88 88
    return template('machines_console', context)
89 89

  
90 90

  
91
CONNECT_LINUX_LINUX_MESSAGE = _("Trying to connect from linux to linux")
92
CONNECT_LINUX_WINDOWS_MESSAGE = _("Trying to connect from linux to windows")
93
CONNECT_WINDOWS_LINUX_MESSAGE = _("Trying to connect from windows to linux")
91
CONNECT_LINUX_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank"
92
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>.
93
To do so open a terminal and type the following at the prompt to connect to your machine:""")
94
CONNECT_LINUX_WINDOWS_MESSAGE = _("""A direct connection to this machine can be
95
established using <a target="_blank" href="http://en.wikipedia.org/wiki/Remote_Desktop_Services">Remote Desktop Service</a>.
96
To do so, open the following file with an appropriate remote desktop client.""")
97
CONNECT_LINUX_WINDOWS_SUBMESSAGE = _("""If you don't have one already
98
installed, we suggest the use of <a target="_blank" href="http://sourceforge.net/projects/tsclient/files/tsclient/tsclient-unstable/tsclient-2.0.1.tar.bz2/download">tsclient</a>.""")
99

  
100
CONNECT_WINDOWS_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank"
101
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>.
102
Open an ssh client such as PuTTY to connect to your machine at IP:""")
103
CONNECT_WINDOWS_LINUX_SUBMESSAGE = _("""If you do not have an ssh client already installed,
104
<a target="_blank" href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe">Download PuTTY</a>""")
94 105
CONNECT_WINDOWS_WINDOWS_MESSAGE = _("Trying to connect from windows to windows")
95 106

  
107

  
108
# info/subinfo for all os combinations
109
#
110
# [0] info gets displayed on top of the message box
111
# [1] subinfo gets displayed on the bottom as extra info
112
# provided to the user when needed
96 113
CONNECT_PROMT_MESSAGES = {
97 114
    'linux': {
98
            'linux': CONNECT_LINUX_LINUX_MESSAGE,
99
            'windows': CONNECT_LINUX_WINDOWS_MESSAGE
115
            'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""],
116
            'windows': [CONNECT_LINUX_WINDOWS_MESSAGE, CONNECT_LINUX_WINDOWS_SUBMESSAGE]
100 117
        },
101 118
    'windows': {
102
            'linux': CONNECT_WINDOWS_LINUX_MESSAGE,
103
            'windows': CONNECT_WINDOWS_WINDOWS_MESSAGE
119
            'linux': [CONNECT_WINDOWS_LINUX_MESSAGE, CONNECT_WINDOWS_LINUX_SUBMESSAGE],
120
            'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE, ""]
104 121
        }
105 122
    }
106 123

  
107 124
def machines_connect(request):
108 125
    ip_address = request.GET.get('ip_address','')
109 126
    operating_system = request.GET.get('os','')
127
    server_id = request.GET.get('srv', 0)
110 128
    host_os = request.GET.get('host_os','Linux').lower()
111 129

  
112 130
    if operating_system != "windows":
113 131
        operating_system = "linux"
114 132

  
133
    # rdp param is set, the user requested rdp file
115 134
    if operating_system == 'windows' and request.GET.get("rdp", False): #check if we are on windows
116 135
        rdp_file = os.path.join(os.path.dirname(__file__), "static/") + 'synnefo-windows.rdp'
117 136
        connect_data = open(rdp_file, 'r').read()
118 137
        connect_data = connect_data + 'full address:s:' + ip_address + '\n'
119 138
        response = HttpResponse(connect_data, mimetype='application/x-rdp')
120
        response['Content-Disposition'] = 'attachment; filename=synnefo-windows.rdp'
139

  
140
        # proper filename, use server id and ip address
141
        filename = "%d-%s.rdp" % (int(server_id), ip_address)
142
        response['Content-Disposition'] = 'attachment; filename=%s' % filename
121 143
    else:
144
        # no rdp requested return json object with info on how to connect
122 145
        ssh = False
123 146
        if (operating_system != "windows"):
124 147
            ssh = True
125 148

  
126
        info = _("Connect on windows using the following RDP shortcut file")
127
        link_title = _("Windows RDP shortcut file")
128
        link_url = "%s?ip_address=%s&os=%s&rdp=1" % (reverse("machines-connect"), ip_address, operating_system)
149
        link_title = _("Remote desktop to %s") % ip_address
150
        link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d" % (reverse("machines-connect"), ip_address, operating_system,
151
                int(server_id))
129 152

  
130 153
        if (operating_system != "windows"):
131
            info = _("Connect on linux machine using the following url")
132
            link_url = "ssh://%s/" % ip_address
133
            link_title = link_url
154
            link_title = "ssh root@%s" % ip_address
155
            link_url = None
156

  
157
            if host_os == "windows":
158
                link_title = ip_address
134 159

  
135 160
        # try to find a specific message
136 161
        try:
137
            connect_message = CONNECT_PROMT_MESSAGES[host_os][operating_system]
162
            connect_message = CONNECT_PROMT_MESSAGES[host_os][operating_system][0]
163
            subinfo = CONNECT_PROMT_MESSAGES[host_os][operating_system][1]
138 164
        except KeyError:
139 165
            connect_message = _("You are trying to connect from a %s machine to a %s machine") % (host_os, operating_system)
166
            subinfo = ""
140 167

  
141 168
        response_object = {
142 169
                'ip': ip_address,
143 170
                'os': operating_system,
144 171
                'ssh': ssh,
145 172
                'info': unicode(connect_message),
173
                'subinfo': unicode(subinfo),
146 174
                'link': {'title': unicode(link_title), 'url': link_url}
147 175
            }
148 176
        response = HttpResponse(json.dumps(response_object), mimetype='application/json')  #no windows, no rdp

Also available in: Unified diff