1 package rero.client.functions; 2 3 import sleep.engine.*; 4 import sleep.runtime.*; 5 import sleep.interfaces.*; 6 7 import rero.util.*; 8 import rero.client.*; 9 import rero.config.*; 10 import java.util.*; 11 import java.text.*; 12 13 import rero.dialogs.server.*; 14 15 import sleep.bridges.BridgeUtilities; 16 17 18 public class ServerOperators extends Feature implements Loadable 19 { 20 public void init() 21 { 22 getCapabilities().getScriptCore().addBridge(this); 23 } 24 25 public boolean scriptLoaded(ScriptInstance script) 26 { 27 script.getScriptEnvironment().getEnvironment().put("&getAllServers", new getAllServers()); 28 script.getScriptEnvironment().getEnvironment().put("&getAllNetworks", new getAllNetworks()); 29 30 script.getScriptEnvironment().getEnvironment().put("&getServerInfo", new getServerInfo()); 31 script.getScriptEnvironment().getEnvironment().put("&getServersForNetwork", new getServersForNetwork()); 32 33 script.getScriptEnvironment().getEnvironment().put("&serverInfoHost", new serverInfoHost()); 34 script.getScriptEnvironment().getEnvironment().put("&serverInfoPortRange", new serverInfoPorts()); 35 script.getScriptEnvironment().getEnvironment().put("&serverInfoNetwork", new serverInfoNetwork()); 36 script.getScriptEnvironment().getEnvironment().put("&serverInfoIsSecure", new serverInfoIsSecure()); 37 script.getScriptEnvironment().getEnvironment().put("&serverInfoPassword", new serverInfoPassword()); 38 script.getScriptEnvironment().getEnvironment().put("&serverInfoDescription", new serverInfoDescription()); 39 script.getScriptEnvironment().getEnvironment().put("&serverInfoConnectPort", new serverInfoConnectPort()); 40 script.getScriptEnvironment().getEnvironment().put("&serverInfoCommand", new serverInfoCommand()); 41 42 return true; 43 } 44 45 public boolean scriptUnloaded(ScriptInstance script) 46 { 47 return true; 48 } 49 50 private static class getAllServers implements Function 51 { 52 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 53 { 54 return SleepUtils.getArrayWrapper(ServerData.getServerData().getAllServers()); 55 } 56 } 57 58 private static class getAllNetworks implements Function 59 { 60 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 61 { 62 return SleepUtils.getArrayWrapper(ServerData.getServerData().getGroups()); 63 } 64 } 65 66 private static class getServerInfo implements Function 67 { 68 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 69 { 70 String temp = BridgeUtilities.getString(locals, ""); 71 if (temp == null) return SleepUtils.getEmptyScalar(); 72 return SleepUtils.getScalar(ServerData.getServerData().getServerByName(temp).toString()); 73 } 74 } 75 76 private static class getServersForNetwork implements Function 77 { 78 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 79 { 80 String temp = BridgeUtilities.getString(locals, ""); 81 if (temp == null) return SleepUtils.getEmptyScalar(); 82 return SleepUtils.getArrayWrapper(ServerData.getServerData().getGroup(temp).getServers()); 83 } 84 } 85 86 private static class serverInfoPassword implements Function 87 { 88 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 89 { 90 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 91 if (temp == null) return SleepUtils.getEmptyScalar(); 92 return SleepUtils.getScalar(temp.getPassword()); 93 } 94 } 95 96 private static class serverInfoDescription implements Function 97 { 98 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 99 { 100 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 101 if (temp == null) return SleepUtils.getEmptyScalar(); 102 return SleepUtils.getScalar(temp.getDescription()); 103 } 104 } 105 106 private static class serverInfoConnectPort implements Function 107 { 108 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 109 { 110 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 111 if (temp == null) return SleepUtils.getEmptyScalar(); 112 return SleepUtils.getScalar(temp.getConnectPort()); 113 } 114 } 115 116 private static class serverInfoCommand implements Function 117 { 118 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 119 { 120 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 121 if (temp == null) return SleepUtils.getEmptyScalar(); 122 return SleepUtils.getScalar(temp.getCommand()); 123 } 124 } 125 126 private static class serverInfoHost implements Function 127 { 128 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 129 { 130 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 131 if (temp == null) return SleepUtils.getEmptyScalar(); 132 return SleepUtils.getScalar(temp.getHost()); 133 } 134 } 135 136 private static class serverInfoPorts implements Function 137 { 138 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 139 { 140 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 141 if (temp == null) return SleepUtils.getEmptyScalar(); 142 return SleepUtils.getScalar(temp.getPorts()); 143 } 144 } 145 146 private static class serverInfoNetwork implements Function 147 { 148 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 149 { 150 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 151 152 if (temp == null) return SleepUtils.getEmptyScalar(); 153 154 155 return SleepUtils.getScalar(temp.getNetwork()); 156 } 157 } 158 159 private static class serverInfoIsSecure implements Function 160 { 161 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 162 { 163 Server temp = Server.decode(BridgeUtilities.getString(locals, "")); 164 if (temp == null) return SleepUtils.getEmptyScalar(); 165 166 if (temp.isSecure()) 167 { 168 return SleepUtils.getScalar(1); 169 } 170 171 return SleepUtils.getEmptyScalar(); 172 } 173 } 174 } 175 176 | Popular Tags |