📄 formreplacer.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program 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 2 of
* the License, or (at your option) any later version.
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.replacementproxy.replacers;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sslexplorer.boot.CaseInsensitiveMap;
import com.sslexplorer.boot.Replacer;
public class FormReplacer implements Replacer {
private URL context;
private String ticket;
public FormReplacer(URL context, String ticket) {
this.context = context;
this.ticket = ticket;
}
/* (non-Javadoc)
* @see com.sslexplorer.services.Replacer#getReplacement(java.util.regex.Pattern, java.util.regex.Matcher, java.lang.String)
*/
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String attrs = matcher.group(2);
return doRepl(attrs);
}
private String doRepl(String attrs) {
StringBuffer attrName = new StringBuffer();
char quote = ' ';
StringBuffer attrVal = new StringBuffer();
boolean doName = true;
boolean doVal = false;
CaseInsensitiveMap a = new CaseInsensitiveMap();
for(int i = 0 ; i < attrs.length(); i++) {
char ch = attrs.charAt(i);
if(ch == '\'' && quote == ' ') {
quote = '\'';
}
else if(ch == '"' && quote == ' ') {
quote = '"';
}
else if( ( ( doName && ( ch == '\r' || ch == '\n' ) ) ||
( doVal && ch == ' ' && quote == ' ' && attrVal.length() > 0) ||
( doVal && ch == '\'' && quote == '\'' ) ||
( doVal && ch == '\"' && quote == '\"' ) ) ) {
quote = ' ';
String an = attrName.toString();
if(!an.equals("")) {
a.put(attrName.toString(), attrVal.toString());
}
attrName.setLength(0);
attrVal.setLength(0);
doVal = false;
doName = true;
}
else if(ch == '=' && doName) {
doName = false;
doVal = true;
}
else {
if(doName) {
if( ( ch != ' ' && ch != '\r' && ch != '\n' ) || attrName.length() > 0) {
attrName.append(ch);
}
}
else if(doVal) {
attrVal.append(ch);
}
}
}
// if("get".equalsIgnoreCase((String)a.get("method"))) {
// a.put("action", "getURL.do");
// }
// else {
StringBuffer buf = new StringBuffer("<form");
String sslexUrl = context.toExternalForm();
if(a.containsKey("action")) {
try {
String contextPath = context.toExternalForm();
if(contextPath.endsWith("/")) {
contextPath = contextPath.substring(0, contextPath.length() - 1);
}
sslexUrl = new URL(new URL(contextPath), a.get("action").toString()).toExternalForm();
} catch (MalformedURLException e) {
}
}
/* If the file uses multipart/form-data. The form must be handled by a different
* action. This is because by the time the headers / parameters have been read
* its too late for GetURLAction to change its route.
*/
if("multipart/form-data".equalsIgnoreCase((String)a.get("enctype"))) {
a.put("action", "getURLMultipartForm.do");
}
else {
a.put("action", "/replacementProxyEngine");
}
//
for(Iterator i = a.entrySet().iterator(); i.hasNext(); ) {
buf.append(" ");
Map.Entry entry = (Map.Entry)i.next();
buf.append(entry.getKey().toString());
buf.append("=\"");
buf.append(entry.getValue());
buf.append("\"");
}
buf.append(">");
if(sslexUrl != null) {
buf.append("\n<input type=\"hidden\" name=\"sslex_url\" value=\"" + sslexUrl + "\"/>");
buf.append("\n<input type=\"hidden\" name=\"sslex_ticket\" value=\"" + ticket + "\"/>");
}
return buf.toString();
}
public static void main(String[] args) throws Exception {
FormReplacer rep = new FormReplacer(new URL("https://pdc.3sp.co.uk/exchange/brett/Drafts"), "SPT12345");
rep.doRepl("name=\"MainForm\"\n" +
"action=\"https://pdc.3sp.co.uk/exchange/brett/Drafts\"\n" +
"METHOD=\"post\"");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -