提交 6c09e723 编写于 作者: K kohsuke

Added form field validation to detect 'localhost' in URL.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11085 71c3de6d-444a-0410-be80-ed276b4c234a
上级 00bcb293
......@@ -1544,10 +1544,10 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
boolean result = true;
for( Descriptor<Builder> d : BuildStep.BUILDERS )
result &= d.configure(req);
result &= d.configure(req,json.getJSONObject(d.getJsonSafeClassName()));
for( Descriptor<Publisher> d : BuildStep.PUBLISHERS )
result &= d.configure(req);
result &= d.configure(req,json.getJSONObject(d.getJsonSafeClassName()));
for( Descriptor<BuildWrapper> d : BuildWrappers.WRAPPERS )
result &= d.configure(req);
......
......@@ -36,6 +36,8 @@ import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.json.JSONObject;
/**
* {@link Publisher} that sends the build result in e-mail.
*
......@@ -219,7 +221,8 @@ public class Mailer extends Publisher {
};
}
public boolean configure(StaplerRequest req) throws FormException {
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
// this code is brain dead
smtpHost = nullify(req.getParameter("mailer_smtp_server"));
adminAddress = req.getParameter("mailer_admin_address");
......@@ -230,7 +233,7 @@ public class Mailer extends Publisher {
}
defaultSuffix = nullify(req.getParameter("mailer_default_suffix"));
String url = nullify(req.getParameter("mailer_hudson_url"));
String url = nullify(json.getString("url"));
if(url!=null && !url.endsWith("/"))
url += '/';
hudsonUrl = url;
......@@ -244,7 +247,7 @@ public class Mailer extends Publisher {
smtpPort = nullify(req.getParameter("mailer_smtp_port"));
useSsl = req.getParameter("mailer_smtp_use_ssl")!=null;
save();
return super.configure(req);
return true;
}
private String nullify(String v) {
......@@ -296,6 +299,21 @@ public class Mailer extends Publisher {
return m;
}
/**
* Checks the URL in <tt>global.jelly</tt>
*/
public void doCheckUrl(StaplerRequest req, StaplerResponse rsp,
@QueryParameter("value") final String value) throws IOException, ServletException {
new FormFieldValidator(req,rsp,false) {
protected void check() throws IOException, ServletException {
if(value.startsWith("http://localhost"))
warning("Please set a valid host name, instead of localhost");
else
ok();
}
}.process();
}
public void doAddressCheck(StaplerRequest req, StaplerResponse rsp,
@QueryParameter("value") final String value) throws IOException, ServletException {
new FormFieldValidator(req,rsp,false) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册