Skip to content

Commit cf8a419

Browse files
committed
Merge branch 'development'
Conflicts: src/main/webapp/admin/secure_shell.jsp
2 parents e6289bb + 60c719e commit cf8a419

47 files changed

Lines changed: 2010 additions & 677 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3rdPartyLicenses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jQuery : MIT License - jQuery Foundation, Inc.
2525

2626
jQueryUI : MIT License - jQuery Foundation, Inc.
2727

28-
jQuery Tablescroll : MIT License - Dimas Begunoff
28+
jquery.floatThead : MIT License - Misha Koryak
2929

3030
term.js : MIT License - Christopher Jeffrey

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.keybox</groupId>
66
<artifactId>keybox</artifactId>
7-
<version>2.81.00-SNAPSHOT</version>
7+
<version>2.82.00</version>
88
<packaging>war</packaging>
99
<name>KeyBox</name>
1010
<properties>
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>com.h2database</groupId>
2626
<artifactId>h2</artifactId>
27-
<version>1.4.185</version>
27+
<version>1.4.186</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>com.jcraft</groupId>
@@ -108,7 +108,7 @@
108108
<plugin>
109109
<groupId>org.eclipse.jetty</groupId>
110110
<artifactId>jetty-maven-plugin</artifactId>
111-
<version>9.2.9.v20150224</version>
111+
<version>9.2.10.v20150310</version>
112112
<configuration>
113113
<jettyXml>${basedir}/src/test/resources/jetty.xml,${basedir}/src/test/resources/jetty-ssl.xml,${basedir}/src/test/resources/jetty-https.xml</jettyXml>
114114
<scanIntervalSeconds>-1</scanIntervalSeconds>

src/main/java/com/keybox/common/db/DBInitServlet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public void init(ServletConfig config) throws ServletException {
6161
if (rs == null || !rs.next()) {
6262
resetSSHKey = true;
6363
statement.executeUpdate("create table if not exists users (id INTEGER PRIMARY KEY AUTO_INCREMENT, first_nm varchar, last_nm varchar, email varchar, username varchar not null, password varchar, auth_token varchar, enabled boolean not null default true, auth_type varchar not null default '" + Auth.AUTH_BASIC+ "', user_type varchar not null default '" + Auth.ADMINISTRATOR + "', salt varchar, otp_secret varchar)");
64-
64+
65+
statement.executeUpdate("create table if not exists user_theme (user_id INTEGER PRIMARY KEY, bg varchar(7), fg varchar(7), d1 varchar(7), d2 varchar(7), d3 varchar(7), d4 varchar(7), d5 varchar(7), d6 varchar(7), d7 varchar(7), d8 varchar(7), b1 varchar(7), b2 varchar(7), b3 varchar(7), b4 varchar(7), b5 varchar(7), b6 varchar(7), b7 varchar(7), b8 varchar(7), foreign key (user_id) references users(id) on delete cascade) ");
6566

6667
statement.executeUpdate("create table if not exists system (id INTEGER PRIMARY KEY AUTO_INCREMENT, display_nm varchar not null, user varchar not null, host varchar not null, port INTEGER not null, authorized_keys varchar not null, status_cd varchar not null default 'INITIAL')");
6768
statement.executeUpdate("create table if not exists profiles (id INTEGER PRIMARY KEY AUTO_INCREMENT, nm varchar not null, desc varchar not null)");
@@ -76,7 +77,7 @@ public void init(ServletConfig config) throws ServletException {
7677
statement.executeUpdate("create table if not exists public_keys (id INTEGER PRIMARY KEY AUTO_INCREMENT, key_nm varchar not null, type varchar, fingerprint varchar, public_key varchar, enabled boolean not null default true, create_dt timestamp not null default CURRENT_TIMESTAMP(), user_id INTEGER, profile_id INTEGER, foreign key (profile_id) references profiles(id) on delete cascade, foreign key (user_id) references users(id) on delete cascade)");
7778

7879
statement.executeUpdate("create table if not exists session_log (id BIGINT PRIMARY KEY AUTO_INCREMENT, user_id INTEGER, session_tm timestamp default CURRENT_TIMESTAMP, foreign key (user_id) references users(id) on delete cascade )");
79-
statement.executeUpdate("create table if not exists terminal_log (session_id BIGINT, system_id INTEGER, output varchar not null, log_tm timestamp default CURRENT_TIMESTAMP, foreign key (session_id) references session_log(id) on delete cascade, foreign key (system_id) references system(id) on delete cascade)");
80+
statement.executeUpdate("create table if not exists terminal_log (session_id BIGINT, instance_id INTEGER, system_id INTEGER, output varchar not null, log_tm timestamp default CURRENT_TIMESTAMP, foreign key (session_id) references session_log(id) on delete cascade, foreign key (system_id) references system(id) on delete cascade)");
8081

8182
//insert default admin user
8283
String salt = EncryptionUtil.generateSalt();

src/main/java/com/keybox/manage/action/LoginAction.java

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public String menu() {
7070
@Action(value = "/loginSubmit",
7171
results = {
7272
@Result(name = "input", location = "/login.jsp"),
73-
@Result(name = "change_password", location = "/admin/setPassword.action", type = "redirect"),
73+
@Result(name = "change_password", location = "/admin/userSettings.action", type = "redirect"),
7474
@Result(name = "otp", location = "/admin/viewOTP.action", type = "redirect"),
7575
@Result(name = "success", location = "/admin/menu.action", type = "redirect")
7676
}
@@ -130,46 +130,6 @@ public String logout() {
130130
return SUCCESS;
131131
}
132132

133-
@Action(value = "/admin/setPassword",
134-
results = {
135-
@Result(name = "success", location = "/admin/set_password.jsp")
136-
}
137-
)
138-
public String setPassword() {
139-
140-
return SUCCESS;
141-
}
142-
143-
@Action(value = "/admin/passwordSubmit",
144-
results = {
145-
@Result(name = "input", location = "/admin/set_password.jsp"),
146-
@Result(name = "success", location = "/admin/menu.action", type = "redirect")
147-
}
148-
)
149-
public String passwordSubmit() {
150-
String retVal = INPUT;
151-
152-
if (!auth.getPassword().equals(auth.getPasswordConfirm())) {
153-
addActionError("Passwords do not match");
154-
155-
} else if(!PasswordUtil.isValid(auth.getPassword())){
156-
addActionError(PasswordUtil.PASSWORD_REQ_ERROR_MSG);
157-
158-
} else {
159-
auth.setAuthToken(AuthUtil.getAuthToken(servletRequest.getSession()));
160-
161-
if (AuthDB.updatePassword(auth)) {
162-
retVal=SUCCESS;
163-
}else{
164-
addActionError("Current password is invalid");
165-
}
166-
}
167-
168-
169-
return retVal;
170-
}
171-
172-
173133
/**
174134
* Validates fields for auth submit
175135
*/
@@ -187,26 +147,6 @@ public void validateLoginSubmit() {
187147
}
188148

189149

190-
/**
191-
* Validates fields for password submit
192-
*/
193-
public void validatePasswordSubmit() {
194-
if (auth.getPassword() == null ||
195-
auth.getPassword().trim().equals("")) {
196-
addFieldError("auth.password", "Required");
197-
}
198-
if (auth.getPasswordConfirm() == null ||
199-
auth.getPasswordConfirm().trim().equals("")) {
200-
addFieldError("auth.passwordConfirm", "Required");
201-
}
202-
if (auth.getPrevPassword() == null ||
203-
auth.getPrevPassword().trim().equals("")) {
204-
addFieldError("auth.prevPassword", "Required");
205-
}
206-
207-
208-
}
209-
210150
public boolean isOtpEnabled() {
211151
return otpEnabled;
212152
}

src/main/java/com/keybox/manage/action/SecureShellAction.java

Lines changed: 79 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
*/
1616
package com.keybox.manage.action;
1717

18+
import com.google.gson.Gson;
1819
import com.jcraft.jsch.ChannelShell;
1920
import com.keybox.common.util.AuthUtil;
2021
import com.keybox.manage.db.*;
2122
import com.keybox.manage.model.*;
23+
import com.keybox.manage.model.SortedSet;
2224
import com.keybox.manage.util.SSHUtil;
2325
import com.opensymphony.xwork2.ActionSupport;
2426
import 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

src/main/java/com/keybox/manage/action/SessionAuditAction.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class SessionAuditAction extends ActionSupport implements ServletResponse
3838

3939
SortedSet sortedSet=new SortedSet();
4040
Long sessionId;
41-
Long hostSystemId;
41+
Integer instanceId;
4242
SessionAudit sessionAudit;
4343
HttpServletResponse servletResponse;
4444
List<HostSystem> systemList= SystemDB.getSystemSet(new SortedSet(SystemDB.SORT_BY_NAME)).getItemList();
@@ -80,7 +80,7 @@ public String getTermsForSession() {
8080
@Action(value = "/manage/getJSONTermOutputForSession")
8181
public String getJSONTermOutputForSession() {
8282

83-
String json=new Gson().toJson(SessionAuditDB.getTerminalLogsForSession(sessionId, hostSystemId));
83+
String json=new Gson().toJson(SessionAuditDB.getTerminalLogsForSession(sessionId, instanceId));
8484
try {
8585
servletResponse.getOutputStream().write(json.getBytes());
8686
} catch (Exception ex) {
@@ -139,13 +139,11 @@ public void setServletResponse(HttpServletResponse servletResponse) {
139139
this.servletResponse = servletResponse;
140140
}
141141

142-
public Long getHostSystemId() {
143-
return hostSystemId;
142+
public Integer getInstanceId() {
143+
return instanceId;
144144
}
145145

146-
public void setHostSystemId(Long hostSystemId) {
147-
this.hostSystemId = hostSystemId;
146+
public void setInstanceId(Integer instanceId) {
147+
this.instanceId = instanceId;
148148
}
149-
150-
151149
}

0 commit comments

Comments
 (0)