Skip to content

Commit

Permalink
added basic checking for mime types in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
jack775544 committed May 16, 2016
1 parent e4a9506 commit a2e5e4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/jTransfer/ExecServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.*;
import java.net.URLDecoder;

/**
* @author jack775544
*/
@WebServlet(name = "ExecServlet")
public class ExecServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection connection;
HttpSession session = request.getSession();

Expand All @@ -30,8 +27,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
}

connection = (Connection) session.getAttribute(Connection.CONNECTION_NAME);
Session sshSession = connection.getSshSession();

Session sshSession = connection.getSshSession();
ChannelExec execChannel;
try {
execChannel = (ChannelExec) sshSession.openChannel("exec");
Expand All @@ -40,8 +37,13 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
return;
}

String pwd = URLDecoder.decode(request.getParameter("pwd"), "UTF-8");
if (pwd == null){
return;
}

execChannel.setOutputStream(response.getOutputStream());
execChannel.setCommand("ls -al");
execChannel.setCommand("file -ib " + pwd);
try {
synchronized (execChannel) {
try {
Expand All @@ -55,4 +57,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
e.printStackTrace();
}
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
16 changes: 16 additions & 0 deletions web/js/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ $(document).ready(function(){
var params = common.getParameters();
var filename = decodeURIComponent(params.filename);
var location = decodeURIComponent(params.pwd) + '/' + filename;
$.ajax({
type: "POST",
url: './exec',
mimeType: 'text/plain',
data: {"pwd": encodeURIComponent(location)},
success: function (data) {
var args = data.split(";");
var type = args[1].trim().split("=");

console.log(type[1]);

if (type[1] == 'binary') {
alert('This is a binary file');
}
}
});
$.get(common.buildUrl('get', {filename: location, name:filename}), function (e) {
$('#editor').text(e);
initEditor();
Expand Down

0 comments on commit a2e5e4b

Please sign in to comment.