Java tutorial
/* * ** * * __ ____ __ * * /'\_/`\ __ /\ \ /\ _`\ __/\ \__ * * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __ * * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \ * * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \ * * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \ * * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \ * * /\___/ * * \/__/ * * * * ____ __ ____ * * /\ _`\ /\ \ /\ _`\ * * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____ * * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\ * * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \ * * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/ * * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/ * * \ \_\ * * This file is part of BREW. * * * * BREW is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * BREW is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with BREW. If not, see <http://www.gnu.org/licenses/>. \/_/ * */ package edu.hm.muse.controller; import edu.hm.muse.exception.SuperFatalAndReallyAnnoyingException; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpSession; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * __ ____ __ * /'\_/`\ __ /\ \ /\ _`\ __/\ \__ * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __ * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \ * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \ * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \ * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \ * /\___/ * \/__/ * <p/> * ____ __ ____ * /\ _`\ /\ \ /\ _`\ * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____ * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\ * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \ * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/ * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/ * \ \_\ * This file is part of BREW. * <p/> * BREW is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * <p/> * BREW is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * <p/> * You should have received a copy of the GNU General Public License * along with BREW. If not, see <http://www.gnu.org/licenses/>. \/_/ */ @Controller public class AdminController { private boolean checkToken(HttpSession session, String token) { try { String sessToken = String.valueOf(session.getAttribute("admintoken")); if (sessToken == null || sessToken.isEmpty() || token == null || token.isEmpty()) { throw new SuperFatalAndReallyAnnoyingException("Bad, really bad...."); } if (sessToken.equals(token)) { return true; } } catch (Exception ex) { return false; } return false; } @RequestMapping(value = "/adminintern.secu", method = RequestMethod.GET) public ModelAndView showAdminInternPage(HttpSession session, @CookieValue(value = "admintoken") String adminToken) { if (!checkToken(session, adminToken)) { throw new SuperFatalAndReallyAnnoyingException("Already bad..."); } return new ModelAndView("adminintern"); } @RequestMapping(value = "/admininternpic.secu", method = RequestMethod.GET) private ModelAndView showAllPictures(HttpSession session, @CookieValue(value = "admintoken", required = false) String adminToken, @RequestParam(value = "path", required = false) String pathToWatch) { if (!checkToken(session, adminToken)) { throw new SuperFatalAndReallyAnnoyingException("Already bad..."); } if (pathToWatch == null || pathToWatch.isEmpty()) { pathToWatch = "webapps/secu/img"; } StringBuilder builder = new StringBuilder(); //just works in linux or?? try { ProcessBuilder procBuilder = new ProcessBuilder("bash", "-c", String.format("ls -gGH %s", pathToWatch)); Process proc = procBuilder.start(); proc.waitFor(); BufferedReader bReader = new BufferedReader(new InputStreamReader(proc.getInputStream())); String readLine = bReader.readLine(); while (readLine != null) { builder.append(readLine).append("<br/>"); readLine = bReader.readLine(); } builder.append("Thats All..."); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (InterruptedException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } ModelAndView mv = new ModelAndView("admininterndic"); String result = builder.toString(); mv.addObject("files", result); return mv; } }