1515 */
1616package com .keybox .manage .action ;
1717
18+ import com .google .gson .Gson ;
1819import com .jcraft .jsch .ChannelShell ;
1920import com .keybox .common .util .AuthUtil ;
2021import com .keybox .manage .db .*;
2122import com .keybox .manage .model .*;
23+ import com .keybox .manage .model .SortedSet ;
2224import com .keybox .manage .util .SSHUtil ;
2325import com .opensymphony .xwork2 .ActionSupport ;
2426import org .apache .struts2 .convention .annotation .Action ;
@@ -47,10 +49,10 @@ public class SecureShellAction extends ActionSupport implements ServletRequestAw
4749 HostSystem pendingSystemStatus ;
4850 String password ;
4951 String passphrase ;
50- Long id ;
52+ Integer id ;
5153 List <HostSystem > systemList = new ArrayList <HostSystem >();
52- Integer ptyWidth ;
53- Integer ptyHeight ;
54+ List < HostSystem > allocatedSystemList = new ArrayList < HostSystem >() ;
55+ UserSettings userSettings ;
5456
5557 static Map <Long , UserSchSessions > userSchSessionMap = new ConcurrentHashMap <Long , UserSchSessions >();
5658
@@ -108,6 +110,21 @@ public String createTerms() {
108110 //set system list if no pending systems
109111 if (SystemStatusDB .getNextPendingSystem (userId ) == null ) {
110112 setSystemList (userId , sessionId );
113+
114+ //set allocated systems for connect to
115+ SortedSet sortedSet =new SortedSet ();
116+ sortedSet .setOrderByField (SystemDB .SORT_BY_NAME );
117+ if (Auth .MANAGER .equals (AuthUtil .getUserType (servletRequest .getSession ()))) {
118+ sortedSet =SystemDB .getSystemSet (sortedSet );
119+ } else {
120+ sortedSet =SystemDB .getUserSystemSet (sortedSet , userId );
121+ }
122+ if (sortedSet !=null && sortedSet .getItemList ()!=null ) {
123+ allocatedSystemList = (List <HostSystem >) sortedSet .getItemList ();
124+ }
125+ //set theme
126+ this .userSettings =UserThemeDB .getTheme (userId );
127+
111128 }
112129
113130
@@ -149,15 +166,10 @@ public String selectSystemsForCompositeTerms() {
149166
150167
151168 Long userId = AuthUtil .getUserId (servletRequest .getSession ());
152- //exit any previous terms
153- exitTerms ();
169+
154170 if (systemSelectId != null && !systemSelectId .isEmpty ()) {
155- //check to see if user has perms to access selected systems
156- if (!Auth .MANAGER .equals (AuthUtil .getUserType (servletRequest .getSession ()))) {
157- systemSelectId = SystemDB .checkSystemPerms (systemSelectId , userId );
158- }
159171
160- SystemStatusDB .setInitialSystemStatus (systemSelectId , userId );
172+ SystemStatusDB .setInitialSystemStatus (systemSelectId , userId , AuthUtil . getUserType ( servletRequest . getSession ()) );
161173 pendingSystemStatus = SystemStatusDB .getNextPendingSystem (userId );
162174
163175 AuthUtil .setSessionId (servletRequest .getSession (), SessionAuditDB .createSessionLog (userId ));
@@ -186,19 +198,27 @@ public String disconnectTerm() {
186198 if (SecureShellAction .getUserSchSessionMap () != null ) {
187199 UserSchSessions userSchSessions = SecureShellAction .getUserSchSessionMap ().get (sessionId );
188200 if (userSchSessions != null ) {
189- SchSession schSession = userSchSessions .getSchSessionMap ().get (id );
190-
191- //disconnect ssh session
192- schSession .getChannel ().disconnect ();
193- schSession .getSession ().disconnect ();
194- schSession .setChannel (null );
195- schSession .setSession (null );
196- schSession .setInputToChannel (null );
197- schSession .setCommander (null );
198- schSession .setOutFromChannel (null );
199- schSession = null ;
200- //remove from map
201- userSchSessions .getSchSessionMap ().remove (id );
201+ try {
202+ SchSession schSession = userSchSessions .getSchSessionMap ().get (id );
203+
204+ //disconnect ssh session
205+ if (schSession !=null ) {
206+ if (schSession .getChannel () != null )
207+ schSession .getChannel ().disconnect ();
208+ if (schSession .getSession () != null )
209+ schSession .getSession ().disconnect ();
210+ schSession .setChannel (null );
211+ schSession .setSession (null );
212+ schSession .setInputToChannel (null );
213+ schSession .setCommander (null );
214+ schSession .setOutFromChannel (null );
215+ schSession = null ;
216+ }
217+ //remove from map
218+ userSchSessions .getSchSessionMap ().remove (id );
219+ } catch (Exception ex ) {
220+ ex .printStackTrace ();
221+ }
202222 }
203223
204224
@@ -208,18 +228,39 @@ public String disconnectTerm() {
208228 return null ;
209229 }
210230
231+
232+ @ Action (value = "/admin/createSession" )
233+ public String createSession () {
234+
235+ Long userId = AuthUtil .getUserId (servletRequest .getSession ());
236+
237+ if (systemSelectId != null && !systemSelectId .isEmpty ()) {
238+
239+ SystemStatusDB .setInitialSystemStatus (systemSelectId , userId , AuthUtil .getUserType (servletRequest .getSession ()));
240+
241+ pendingSystemStatus = SystemStatusDB .getNextPendingSystem (userId );
242+
243+ createTerms ();
244+
245+ }
246+
247+ return null ;
248+
249+
250+ }
251+
211252 @ Action (value = "/admin/setPtyType" )
212253 public String setPtyType () {
213254
214255 Long sessionId = AuthUtil .getSessionId (servletRequest .getSession ());
215256 if (SecureShellAction .getUserSchSessionMap () != null ) {
216257 UserSchSessions userSchSessions = SecureShellAction .getUserSchSessionMap ().get (sessionId );
217- if (userSchSessions != null && userSchSessions .getSchSessionMap () !=null ) {
258+ if (userSchSessions != null && userSchSessions .getSchSessionMap () != null ) {
218259
219260 SchSession schSession = userSchSessions .getSchSessionMap ().get (id );
220261
221262 ChannelShell channel = (ChannelShell ) schSession .getChannel ();
222- channel .setPtySize ((int )Math .floor (ptyWidth / 7.2981 ), (int )Math .floor (ptyHeight / 14.4166 ), ptyWidth , ptyHeight );
263+ channel .setPtySize ((int ) Math .floor (userSettings . getPtyWidth () / 7.2981 ), (int ) Math .floor (userSettings . getPtyHeight () / 14.4166 ), userSettings . getPtyWidth (), userSettings . getPtyHeight () );
223264 schSession .setChannel (channel );
224265
225266 }
@@ -229,6 +270,7 @@ public String setPtyType() {
229270
230271 return null ;
231272 }
273+
232274 /**
233275 * set system list once all connections have been attempted
234276 *
@@ -239,10 +281,10 @@ private void setSystemList(Long userId, Long sessionId) {
239281
240282
241283 //check user map
242- if (userSchSessionMap != null && !userSchSessionMap .isEmpty () && userSchSessionMap .get (sessionId )!= null ) {
284+ if (userSchSessionMap != null && !userSchSessionMap .isEmpty () && userSchSessionMap .get (sessionId ) != null ) {
243285
244286 //get user sessions
245- Map <Long , SchSession > schSessionMap = userSchSessionMap .get (sessionId ).getSchSessionMap ();
287+ Map <Integer , SchSession > schSessionMap = userSchSessionMap .get (sessionId ).getSchSessionMap ();
246288
247289
248290 for (SchSession schSession : schSessionMap .values ()) {
@@ -300,11 +342,11 @@ public void setSystemSelectId(List<Long> systemSelectId) {
300342 this .systemSelectId = systemSelectId ;
301343 }
302344
303- public Long getId () {
345+ public Integer getId () {
304346 return id ;
305347 }
306348
307- public void setId (Long id ) {
349+ public void setId (Integer id ) {
308350 this .id = id ;
309351 }
310352
@@ -372,20 +414,20 @@ public static void setUserSchSessionMap(Map<Long, UserSchSessions> userSchSessio
372414 SecureShellAction .userSchSessionMap = userSchSessionMap ;
373415 }
374416
375- public Integer getPtyWidth () {
376- return ptyWidth ;
417+ public List < HostSystem > getAllocatedSystemList () {
418+ return allocatedSystemList ;
377419 }
378420
379- public void setPtyWidth ( Integer ptyWidth ) {
380- this .ptyWidth = ptyWidth ;
421+ public void setAllocatedSystemList ( List < HostSystem > allocatedSystemList ) {
422+ this .allocatedSystemList = allocatedSystemList ;
381423 }
382424
383- public Integer getPtyHeight () {
384- return ptyHeight ;
425+ public UserSettings getUserSettings () {
426+ return userSettings ;
385427 }
386428
387- public void setPtyHeight ( Integer ptyHeight ) {
388- this .ptyHeight = ptyHeight ;
429+ public void setUserSettings ( UserSettings userSettings ) {
430+ this .userSettings = userSettings ;
389431 }
390432}
391433
0 commit comments