use of io.bastillion.manage.model.SchSession in project KeyBox by skavanagh.
the class SecureShellKtrl method setPtyType.
@Kontrol(path = "/admin/setPtyType", method = MethodType.GET)
public String setPtyType() throws ServletException {
Long sessionId = null;
try {
sessionId = AuthUtil.getSessionId(getRequest().getSession());
} catch (GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
if (SecureShellKtrl.getUserSchSessionMap() != null) {
UserSchSessions userSchSessions = SecureShellKtrl.getUserSchSessionMap().get(sessionId);
if (userSchSessions != null && userSchSessions.getSchSessionMap() != null) {
SchSession schSession = userSchSessions.getSchSessionMap().get(id);
ChannelShell channel = (ChannelShell) schSession.getChannel();
channel.setPtySize((int) Math.floor(userSettings.getPtyWidth() / 8.0000), (int) Math.floor(userSettings.getPtyHeight() / 14.4166), userSettings.getPtyWidth(), userSettings.getPtyHeight());
schSession.setChannel(channel);
}
}
return null;
}
use of io.bastillion.manage.model.SchSession in project KeyBox by skavanagh.
the class SecureShellWS method onMessage.
@OnMessage
public void onMessage(String message) {
if (session.isOpen() && StringUtils.isNotEmpty(message) && !"heartbeat".equals(message)) {
try {
Map jsonRoot = new Gson().fromJson(message, Map.class);
String command = (String) jsonRoot.get("command");
Integer keyCode = null;
Double keyCodeDbl = (Double) jsonRoot.get("keyCode");
if (keyCodeDbl != null) {
keyCode = keyCodeDbl.intValue();
}
for (String idStr : (ArrayList<String>) jsonRoot.get("id")) {
Integer id = Integer.parseInt(idStr);
// get servletRequest.getSession() for user
UserSchSessions userSchSessions = SecureShellKtrl.getUserSchSessionMap().get(sessionId);
if (userSchSessions != null) {
SchSession schSession = userSchSessions.getSchSessionMap().get(id);
if (keyCode != null) {
if (keyMap.containsKey(keyCode)) {
schSession.getCommander().write(keyMap.get(keyCode));
}
} else {
schSession.getCommander().print(command);
}
}
}
// update timeout
AuthUtil.setTimeout(httpSession);
} catch (IllegalStateException | JsonSyntaxException | IOException ex) {
log.error(ex.toString(), ex);
}
}
}
use of io.bastillion.manage.model.SchSession in project KeyBox by skavanagh.
the class SecureShellKtrl method setSystemList.
/**
* set system list once all connections have been attempted
*
* @param userId user id
* @param sessionId session id
*/
private void setSystemList(Long userId, Long sessionId) throws ServletException {
// check user map
if (userSchSessionMap != null && !userSchSessionMap.isEmpty() && userSchSessionMap.get(sessionId) != null) {
// get user sessions
Map<Integer, SchSession> schSessionMap = userSchSessionMap.get(sessionId).getSchSessionMap();
for (SchSession schSession : schSessionMap.values()) {
// add to host system list
systemList.add(schSession.getHostSystem());
// run script it exists
if (script != null && script.getId() != null && script.getId() > 0) {
try {
script = ScriptDB.getScript(script.getId(), userId);
BufferedReader reader = new BufferedReader(new StringReader(script.getScript()));
String line;
while ((line = reader.readLine()) != null) {
schSession.getCommander().println(line);
}
} catch (SQLException | IOException | GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
}
}
}
}
use of io.bastillion.manage.model.SchSession in project KeyBox by skavanagh.
the class SecureShellKtrl method disconnectTerm.
@Kontrol(path = "/admin/disconnectTerm", method = MethodType.GET)
public String disconnectTerm() throws ServletException {
Long sessionId = null;
try {
sessionId = AuthUtil.getSessionId(getRequest().getSession());
} catch (GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
if (SecureShellKtrl.getUserSchSessionMap() != null) {
UserSchSessions userSchSessions = SecureShellKtrl.getUserSchSessionMap().get(sessionId);
if (userSchSessions != null) {
SchSession schSession = userSchSessions.getSchSessionMap().get(id);
// disconnect ssh session
if (schSession != null) {
if (schSession.getChannel() != null)
schSession.getChannel().disconnect();
if (schSession.getSession() != null)
schSession.getSession().disconnect();
schSession.setChannel(null);
schSession.setSession(null);
schSession.setInputToChannel(null);
schSession.setCommander(null);
schSession.setOutFromChannel(null);
}
// remove from map
userSchSessions.getSchSessionMap().remove(id);
}
}
return null;
}
use of io.bastillion.manage.model.SchSession in project KeyBox by skavanagh.
the class UploadAndPushKtrl method push.
@Kontrol(path = "/admin/push", method = MethodType.POST)
public String push() throws ServletException {
try {
Long userId = AuthUtil.getUserId(getRequest().getSession());
Long sessionId = AuthUtil.getSessionId(getRequest().getSession());
// get next pending system
pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
if (pendingSystemStatus != null) {
// get session for system
SchSession session = null;
for (Integer instanceId : SecureShellKtrl.getUserSchSessionMap().get(sessionId).getSchSessionMap().keySet()) {
// if host system id matches pending system then upload
if (pendingSystemStatus.getId().equals(SecureShellKtrl.getUserSchSessionMap().get(sessionId).getSchSessionMap().get(instanceId).getHostSystem().getId())) {
session = SecureShellKtrl.getUserSchSessionMap().get(sessionId).getSchSessionMap().get(instanceId);
}
}
if (session != null) {
// push upload to system
currentSystemStatus = SSHUtil.pushUpload(pendingSystemStatus, session.getSession(), UPLOAD_PATH + "/" + uploadFileName, pushDir + "/" + uploadFileName);
// update system status
SystemStatusDB.updateSystemStatus(currentSystemStatus, userId);
pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
}
}
// if push has finished to all servers then delete uploaded file
if (pendingSystemStatus == null) {
File delFile = new File(UPLOAD_PATH, uploadFileName);
FileUtils.deleteQuietly(delFile);
// delete all expired files in upload path
File delDir = new File(UPLOAD_PATH);
if (delDir.isDirectory()) {
// set expire time to delete all files older than 48 hrs
Calendar expireTime = Calendar.getInstance();
expireTime.add(Calendar.HOUR, -48);
Iterator<File> filesToDelete = FileUtils.iterateFiles(delDir, new AgeFileFilter(expireTime.getTime()), TrueFileFilter.TRUE);
while (filesToDelete.hasNext()) {
delFile = filesToDelete.next();
delFile.delete();
}
}
}
hostSystemList = SystemStatusDB.getAllSystemStatus(userId);
} catch (SQLException | GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
// reset csrf token back since it's already set on page load
getRequest().getSession().setAttribute(SecurityFilter._CSRF, getRequest().getParameter(SecurityFilter._CSRF));
return "/admin/upload_result.html";
}
Aggregations