[4] | 1 | ############################################################################ |
---|
| 2 | # |
---|
| 3 | # SAGE UI Users Server - A server that handles users, fsManagers and chat for SAGE |
---|
| 4 | # |
---|
| 5 | # Copyright (C) 2005 Electronic Visualization Laboratory, |
---|
| 6 | # University of Illinois at Chicago |
---|
| 7 | # |
---|
| 8 | # All rights reserved. |
---|
| 9 | # |
---|
| 10 | # Redistribution and use in source and binary forms, with or without |
---|
| 11 | # modification, are permitted provided that the following conditions are met: |
---|
| 12 | # |
---|
| 13 | # * Redistributions of source code must retain the above copyright |
---|
| 14 | # notice, this list of conditions and the following disclaimer. |
---|
| 15 | # * Redistributions in binary form must reproduce the above |
---|
| 16 | # copyright notice, this list of conditions and the following disclaimer |
---|
| 17 | # in the documentation and/or other materials provided with the distribution. |
---|
| 18 | # * Neither the name of the University of Illinois at Chicago nor |
---|
| 19 | # the names of its contributors may be used to endorse or promote |
---|
| 20 | # products derived from this software without specific prior written permission. |
---|
| 21 | # |
---|
| 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 25 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 27 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 28 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 30 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 31 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 32 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 33 | # |
---|
| 34 | # Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum |
---|
| 35 | # |
---|
| 36 | # Author: Ratko Jagodic |
---|
| 37 | # |
---|
| 38 | ############################################################################ |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | import wx |
---|
| 42 | import xmlrpclib |
---|
| 43 | import string |
---|
| 44 | |
---|
| 45 | server = None |
---|
| 46 | REGISTERED_USERS = 1 |
---|
| 47 | CONNECTED_USERS = 2 |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | class MyFrame(wx.Frame): |
---|
| 51 | |
---|
| 52 | def __init__(self): |
---|
| 53 | wx.Frame.__init__(self, None, -1, "SAGE Server Admin", pos = (100,100), size=(450,500)) |
---|
| 54 | self.CreateControls() |
---|
| 55 | self.usersType = REGISTERED_USERS |
---|
| 56 | |
---|
| 57 | self.Show(True) |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | def CreateControls(self): |
---|
| 61 | userLabel = wx.StaticText(self, -1, "Registered Users", style=wx.ALIGN_CENTER) |
---|
| 62 | #self.userCombo = wx.ComboBox(self, -1, "Registered Users", choices=["Registered Users", "Connected Users"], style = wx.CB_DROPDOWN | wx.CB_READONLY) |
---|
| 63 | machineLabel = wx.StaticText(self, -1, "Registered Machines", style=wx.ALIGN_CENTER) |
---|
| 64 | self.userList = wx.ListBox(self, -1, choices=server.GetRegisteredUsers(), style=wx.LB_SINGLE) |
---|
| 65 | self.machineList = wx.ListBox(self, -1, choices=server.GetRegisteredMachines(), style=wx.LB_SINGLE) |
---|
| 66 | self.disconnectUserBtn = wx.Button(self, -1, "Disconnect User") |
---|
| 67 | self.disconnectMachineBtn = wx.Button(self, -1, "Disconnect Machine") |
---|
| 68 | self.infoArea = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY | wx.TE_MULTILINE) |
---|
| 69 | self.refreshBtn = wx.Button(self, -1, "Refresh") |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | # registering event handlers |
---|
| 73 | self.userList.Bind(wx.EVT_LISTBOX, self.OnUserListSelect) |
---|
| 74 | self.machineList.Bind(wx.EVT_LISTBOX, self.OnMachineListSelect) |
---|
| 75 | self.disconnectUserBtn.Bind(wx.EVT_BUTTON, self.OnUserDisconnectBtn) |
---|
| 76 | self.disconnectMachineBtn.Bind(wx.EVT_BUTTON, self.OnMachineDisconnectBtn) |
---|
| 77 | self.refreshBtn.Bind(wx.EVT_BUTTON, self.UpdateLists) |
---|
| 78 | #self.userCombo.Bind(wx.EVT_COMBOBOX, self.OnUserComboBox) |
---|
| 79 | |
---|
| 80 | # placement of the controls |
---|
| 81 | gridSizer = wx.FlexGridSizer(3,2,0,20) |
---|
| 82 | gridSizer.Add(userLabel, 0, wx.ALIGN_CENTER | wx.BOTTOM | wx.LEFT | wx.EXPAND, border=5) |
---|
| 83 | gridSizer.Add(machineLabel, 0, wx.ALIGN_CENTER | wx.BOTTOM, border=5) |
---|
| 84 | gridSizer.Add(self.userList, 1, wx.EXPAND | wx.LEFT, border=15) |
---|
| 85 | gridSizer.Add(self.machineList, 1, wx.EXPAND | wx.RIGHT, border=15) |
---|
| 86 | gridSizer.Add(self.disconnectUserBtn, 0, wx.ALIGN_CENTER | wx.TOP, border=5) |
---|
| 87 | gridSizer.Add(self.disconnectMachineBtn, 0, wx.ALIGN_CENTER | wx.TOP, border=5) |
---|
| 88 | gridSizer.AddGrowableRow(1) |
---|
| 89 | gridSizer.AddGrowableCol(0) |
---|
| 90 | gridSizer.AddGrowableCol(1) |
---|
| 91 | |
---|
| 92 | boxSizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 93 | boxSizer.AddSpacer((10,10)) |
---|
| 94 | boxSizer.Add( gridSizer, 1, wx.ALIGN_CENTER | wx.EXPAND) |
---|
| 95 | boxSizer.AddSpacer((10,10)) |
---|
| 96 | boxSizer.Add( self.infoArea, 1, wx.ALIGN_CENTER | wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 15) |
---|
| 97 | boxSizer.AddSpacer((20,20)) |
---|
| 98 | boxSizer.Add( self.refreshBtn, 0, wx.ALIGN_CENTER | wx.BOTTOM, border=10) |
---|
| 99 | self.SetSizer(boxSizer) |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | ## def OnUserComboBox(self, event): |
---|
| 103 | ## if self.userCombo.GetValue() == "Registered Users": |
---|
| 104 | ## self.usersType = REGISTERED_USERS |
---|
| 105 | ## else: |
---|
| 106 | ## self.usersType = CONNECTED_USERS |
---|
| 107 | ## self.UpdateLists() |
---|
| 108 | |
---|
| 109 | def OnUserListSelect(self, event): |
---|
| 110 | if event.IsSelection(): |
---|
| 111 | if self.usersType == REGISTERED_USERS: |
---|
| 112 | machines = server.GetUserInfo( event.GetString() ) |
---|
| 113 | if machines == -1: |
---|
| 114 | machines = "Unable to retrieve a list of connections" |
---|
| 115 | else: |
---|
| 116 | machines = "This user is not even registered with the server so he\nis not connected to any machines yet" |
---|
| 117 | info = "USER: " + event.GetString() + "\nCONNECTED TO: " + str(machines) |
---|
| 118 | self.infoArea.Clear() |
---|
| 119 | self.infoArea.WriteText(info) |
---|
| 120 | |
---|
| 121 | def OnMachineListSelect(self, event): |
---|
| 122 | if event.IsSelection(): |
---|
| 123 | (name, ip, port, machineId, alive, displayString, userList) = server.GetMachineInfo( event.GetString().split(" - ", 1)[1].strip() ) |
---|
| 124 | info = "MACHINE: " + str(event.GetString()) |
---|
| 125 | info = info + "\n---------------------------------------------------------" |
---|
| 126 | if name == -1: |
---|
| 127 | info = info + str("\nCould not retrieve additional information") |
---|
| 128 | else: |
---|
| 129 | displayInfo = displayString.split(" ", 5) |
---|
| 130 | info = info + "\nPORT FOR SAGE UI CONNECTIONS:" + str(port) |
---|
| 131 | if alive == 1: |
---|
| 132 | info = info + "\nRUNNING:\tYes" |
---|
| 133 | else: |
---|
| 134 | info = info + "\nRUNNING:\tNo" |
---|
| 135 | info = info + "\nTILE ARRANGEMENT:\t"+str(displayInfo[0])+" x "+str(displayInfo[1]) |
---|
| 136 | info = info + "\nDISPLAY SIZE:\t"+str(displayInfo[2])+" x "+str(displayInfo[3])+" pixels" |
---|
| 137 | info = info + "\nTILE SIZE:\t"+str(displayInfo[4])+" x "+str(displayInfo[5])+ " pixels" |
---|
| 138 | info = info + "\nUSERS CONNECTED:\t"+str(userList) |
---|
| 139 | |
---|
| 140 | self.infoArea.Clear() |
---|
| 141 | self.infoArea.WriteText(info) |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | def UpdateLists(self, event=None): |
---|
| 145 | if self.usersType == REGISTERED_USERS: |
---|
| 146 | self.userList.Set(server.GetRegisteredUsers()) |
---|
| 147 | else: |
---|
| 148 | self.userList.Set(server.GetConnectedUsers()) |
---|
| 149 | self.machineList.Set(server.GetRegisteredMachines()) |
---|
| 150 | self.infoArea.Clear() |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | def OnUserDisconnectBtn(self, event): |
---|
| 154 | selection = self.userList.GetStringSelection() |
---|
| 155 | if not selection == "": |
---|
| 156 | if self.usersType == REGISTERED_USERS: |
---|
| 157 | server.DisconnectUser(selection) |
---|
| 158 | else: |
---|
| 159 | server.DisconnectConnectedUser(selection) |
---|
| 160 | self.UpdateLists() |
---|
| 161 | |
---|
| 162 | def OnMachineDisconnectBtn(self, event): |
---|
| 163 | selection = self.machineList.GetStringSelection() |
---|
| 164 | if not selection == "": |
---|
| 165 | server.DisconnectMachine(selection.split(" - ", 1)[1].strip()) |
---|
| 166 | self.UpdateLists() |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | class MyApp(wx.App): |
---|
| 171 | def __init__(self): |
---|
| 172 | wx.App.__init__(self, redirect=False) |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | def OnInit(self): |
---|
| 176 | self.frame = MyFrame() |
---|
| 177 | self.SetTopWindow(self.frame) |
---|
| 178 | return True |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | def main(argv): |
---|
| 183 | name, ext = os.path.splitext(argv[1]) |
---|
| 184 | module = __import__(name) |
---|
| 185 | |
---|
| 186 | if len(argv) == 2: |
---|
| 187 | serverIP = "sage.sl.startap.net" |
---|
| 188 | serverPort = 8009 |
---|
| 189 | elif len(argv) == 3: |
---|
| 190 | print "Usage: python status.py [SERVER_IP] [SERVER_PORT]\n" |
---|
| 191 | sys.exit(0) |
---|
| 192 | else: |
---|
| 193 | serverIP = argv[2] |
---|
| 194 | serverPort = int(argv[3]) |
---|
| 195 | |
---|
| 196 | global server |
---|
| 197 | server = xmlrpclib.ServerProxy("http://"+serverIP+":"+str(serverPort)) |
---|
| 198 | print "\nServer running:", server |
---|
| 199 | |
---|
| 200 | app = MyApp() |
---|
| 201 | app.MainLoop() |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | if __name__ == '__main__': |
---|
| 206 | import sys, os |
---|
| 207 | main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) |
---|