Search in sources :

Example 21 with Kontrol

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";
}
Also used : ServletException(javax.servlet.ServletException) AgeFileFilter(org.apache.commons.io.filefilter.AgeFileFilter) SQLException(java.sql.SQLException) SchSession(io.bastillion.manage.model.SchSession) Calendar(java.util.Calendar) GeneralSecurityException(java.security.GeneralSecurityException) File(java.io.File) Kontrol(loophole.mvc.annotation.Kontrol)

Example 22 with Kontrol

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;
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) File(java.io.File) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) GeneralSecurityException(java.security.GeneralSecurityException) Kontrol(loophole.mvc.annotation.Kontrol)

Example 23 with Kontrol

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";
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) GeneralSecurityException(java.security.GeneralSecurityException) Kontrol(loophole.mvc.annotation.Kontrol)

Example 24 with Kontrol

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();
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) GeneralSecurityException(java.security.GeneralSecurityException) Kontrol(loophole.mvc.annotation.Kontrol)

Example 25 with Kontrol

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";
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) GeneralSecurityException(java.security.GeneralSecurityException) SortedSet(io.bastillion.manage.model.SortedSet) Kontrol(loophole.mvc.annotation.Kontrol)

Aggregations

GeneralSecurityException (java.security.GeneralSecurityException)29 ServletException (javax.servlet.ServletException)29 Kontrol (loophole.mvc.annotation.Kontrol)29 SQLException (java.sql.SQLException)25 SortedSet (io.bastillion.manage.model.SortedSet)5 SchSession (io.bastillion.manage.model.SchSession)3 IOException (java.io.IOException)3 User (io.bastillion.manage.model.User)2 UserSchSessions (io.bastillion.manage.model.UserSchSessions)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 EncodeHintType (com.google.zxing.EncodeHintType)1 WriterException (com.google.zxing.WriterException)1 BitMatrix (com.google.zxing.common.BitMatrix)1 QRCodeWriter (com.google.zxing.qrcode.QRCodeWriter)1 ChannelShell (com.jcraft.jsch.ChannelShell)1 HostSystem (io.bastillion.manage.model.HostSystem)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 Calendar (java.util.Calendar)1