use of loophole.mvc.annotation.Kontrol 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";
}
use of loophole.mvc.annotation.Kontrol in project KeyBox by skavanagh.
the class UploadAndPushKtrl method uploadSubmit.
@Kontrol(path = "/admin/uploadSubmit", method = MethodType.POST)
public String uploadSubmit() {
String retVal = "/admin/upload_result.html";
try {
Long userId = AuthUtil.getUserId(getRequest().getSession());
List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(getRequest());
for (FileItem item : multiparts) {
if (!item.isFormField()) {
uploadFileName = new File(item.getName()).getName();
File path = new File(UPLOAD_PATH);
if (!path.exists()) {
path.mkdirs();
}
upload = new File(UPLOAD_PATH + File.separator + uploadFileName);
item.write(upload);
} else {
pushDir = item.getString();
}
}
pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
hostSystemList = SystemStatusDB.getAllSystemStatus(userId);
} catch (Exception ex) {
log.error(ex.toString(), ex);
retVal = "/admin/upload.html";
}
// reset csrf token back since it's already set on page load
getRequest().getSession().setAttribute(SecurityFilter._CSRF, getRequest().getParameter(SecurityFilter._CSRF));
return retVal;
}
use of loophole.mvc.annotation.Kontrol in project KeyBox by skavanagh.
the class ProfileUsersKtrl method viewProfileUsers.
@Kontrol(path = "/manage/viewProfileUsers", method = MethodType.GET)
public String viewProfileUsers() throws ServletException {
if (profile != null && profile.getId() != null) {
try {
profile = ProfileDB.getProfile(profile.getId());
sortedSet = UserDB.getAdminUserSet(sortedSet, profile.getId());
} catch (SQLException | GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
}
return "/manage/view_profile_users.html";
}
use of loophole.mvc.annotation.Kontrol in project KeyBox by skavanagh.
the class AuthKeysKtrl method savePublicKeys.
@Kontrol(path = "/admin/savePublicKey", method = MethodType.POST)
public String savePublicKeys() throws ServletException {
try {
Long userId = AuthUtil.getUserId(getRequest().getSession());
String userType = AuthUtil.getUserType(getRequest().getSession());
publicKey.setUserId(userId);
if (Auth.MANAGER.equals(userType) || UserProfileDB.checkIsUsersProfile(userId, publicKey.getProfile().getId())) {
if (publicKey.getId() != null) {
PublicKeyDB.updatePublicKey(publicKey);
} else {
PublicKeyDB.insertPublicKey(publicKey);
}
distributePublicKeys(publicKey);
}
} catch (SQLException | GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
return "redirect:/admin/viewKeys.ktrl?sortedSet.orderByDirection=" + sortedSet.getOrderByDirection() + "&sortedSet.orderByField=" + sortedSet.getOrderByField() + "&keyNm=" + publicKey.getKeyNm();
}
use of loophole.mvc.annotation.Kontrol in project KeyBox by skavanagh.
the class AuthKeysKtrl method disablePublicKey.
@Kontrol(path = "/manage/disablePublicKey", method = MethodType.GET)
public String disablePublicKey() throws ServletException {
try {
publicKey = PublicKeyDB.getPublicKey(publicKey.getId());
PublicKeyDB.disableKey(publicKey.getId());
profileList = ProfileDB.getAllProfiles();
userList = UserDB.getUserSet(new SortedSet(SessionAuditDB.SORT_BY_USERNAME)).getItemList();
sortedSet = PublicKeyDB.getPublicKeySet(sortedSet);
} catch (SQLException | GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
distributePublicKeys(publicKey);
return "/manage/view_keys.html";
}
Aggregations