Skip to content

Commit

Permalink
[JENKINS-69032] Plugin manager update site URL can be saved empty (#6886
Browse files Browse the repository at this point in the history
)

Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
Co-authored-by: James Nord <jtnord@users.noreply.github.com>
Co-authored-by: Alexander Brandes <mc.cache@web.de>
Co-authored-by: Basil Crow <me@basilcrow.com>
  • Loading branch information
5 people committed Oct 3, 2022
1 parent 175a6ee commit 0cb9e02
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
30 changes: 30 additions & 0 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -1945,6 +1946,35 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
return FormValidation.ok();
}

@Restricted(NoExternalUse.class)
@RequirePOST public FormValidation doCheckUpdateSiteUrl(StaplerRequest request, @QueryParameter String value) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
if (StringUtils.isNotBlank(value)) {
try {
value += ((value.contains("?")) ? "&" : "?") + "version=" + Jenkins.VERSION + "&uctest";

URL url = new URL(value);

// Connect to the URL
HttpURLConnection conn = (HttpURLConnection) ProxyConfiguration.open(url);
conn.setRequestMethod("HEAD");
conn.setConnectTimeout(5000);
if (100 <= conn.getResponseCode() && conn.getResponseCode() <= 399) {
return FormValidation.ok();
} else {
LOGGER.log(Level.FINE, "Obtained a non OK ({0}) response from the update center",
new Object[]{conn.getResponseCode(), url});
return FormValidation.error(Messages.PluginManager_connectionFailed());
}
} catch (IOException e) {
LOGGER.log(Level.FINE, "Failed to check update site", e);
return FormValidation.error(Messages.PluginManager_connectionFailed());
}
} else {
return FormValidation.error(Messages.PluginManager_emptyUpdateSiteUrl());
}
}

@Restricted(NoExternalUse.class)
@RequirePOST public HttpResponse doCheckUpdatesServer() throws IOException {
Jenkins.get().checkPermission(Jenkins.SYSTEM_READ);
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/hudson/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ PluginManager.insecureUrl=\
PluginManager.invalidUrl=\
You are using an invalid URL to download the plugin, only https and http (not recommended) are supported.

PluginManager.emptyUpdateSiteUrl=\
The update site cannot be empty. Please enter a valid url.

PluginManager.connectionFailed=\
Unable to connect to the URL.

AboutJenkins.DisplayName=About Jenkins
AboutJenkins.Description=See the version and license information.
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/hudson/Messages_zh_TW.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ PluginWrapper.NoSuchPlugin=找不到名為「{0}」的外掛
PluginWrapper.Error.Disabling=停用外掛「{0}」時發生錯誤,錯誤\: 「{1}」
TcpSlaveAgentListener.PingAgentProtocol.displayName=Ping 協定

PluginManager.emptyUpdateSiteUrl=更新站台網址不得為空,請輸入網址
PluginManager.connectionFailed=無法連線至這個URL
17 changes: 17 additions & 0 deletions core/src/main/resources/hudson/PluginManager/_updateSite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function () {
const resetButton = document.getElementById("reset-to-default");
const siteUrlInput = document.getElementById("update-site-url");
if (siteUrlInput.value === "https://updates.jenkins.io/update-center.json") {
resetButton.style.display = "none";
} else {
resetButton.style.display = "";
}
})();

document.getElementById("reset-to-default").onclick = function (event) {
event.preventDefault();
const siteUrlInput = document.getElementById("update-site-url");
siteUrlInput.value = "https://updates.jenkins.io/update-center.json";
siteUrlInput.dispatchEvent(new Event("change"));
event.target.style.display = "none";
};
8 changes: 7 additions & 1 deletion core/src/main/resources/hudson/PluginManager/advanced.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ THE SOFTWARE.
<h2 class="jenkins-section__title">${%Update Site}</h2>
<f:form method="post" action="siteConfigure" name="siteConfigure">
<f:entry title="${%URL}">
<j:if test="${app.updateCenter.ID_DEFAULT.equals(app.updateCenter.PREDEFINED_UPDATE_SITE_ID)}">
<a id="reset-to-default" href="#">${%Reset to default}</a>
</j:if>
<f:textbox name="site"
value="${app.updateCenter.getSite(app.updateCenter.ID_DEFAULT).url}"/>
id="update-site-url"
value="${app.updateCenter.getSite(app.updateCenter.ID_DEFAULT).url}"
checkUrl="checkUpdateSiteUrl" checkDependsOn=""/>
</f:entry>
<st:adjunct includes="hudson.PluginManager._updateSite"/>
<l:isAdmin>
<f:block>
<f:submit/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ Deploy\ Plugin=部署外掛
Deploy=部署
Advanced\ Settings=進階設定
Or=
Reset\ to\ default=重設回預設值

0 comments on commit 0cb9e02

Please sign in to comment.