diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index a904b86c1bf9..2859fd7e5bfd 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -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; @@ -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); diff --git a/core/src/main/resources/hudson/Messages.properties b/core/src/main/resources/hudson/Messages.properties index 4a60b450c3c2..8e6a0d3836ed 100644 --- a/core/src/main/resources/hudson/Messages.properties +++ b/core/src/main/resources/hudson/Messages.properties @@ -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. diff --git a/core/src/main/resources/hudson/Messages_zh_TW.properties b/core/src/main/resources/hudson/Messages_zh_TW.properties index f9e46b82ea08..bf7f1fe6c675 100644 --- a/core/src/main/resources/hudson/Messages_zh_TW.properties +++ b/core/src/main/resources/hudson/Messages_zh_TW.properties @@ -102,3 +102,5 @@ PluginWrapper.NoSuchPlugin=找不到名為「{0}」的外掛 PluginWrapper.Error.Disabling=停用外掛「{0}」時發生錯誤,錯誤\: 「{1}」 TcpSlaveAgentListener.PingAgentProtocol.displayName=Ping 協定 +PluginManager.emptyUpdateSiteUrl=更新站台網址不得為空,請輸入網址 +PluginManager.connectionFailed=無法連線至這個URL diff --git a/core/src/main/resources/hudson/PluginManager/_updateSite.js b/core/src/main/resources/hudson/PluginManager/_updateSite.js new file mode 100644 index 000000000000..93015abe73b5 --- /dev/null +++ b/core/src/main/resources/hudson/PluginManager/_updateSite.js @@ -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"; +}; diff --git a/core/src/main/resources/hudson/PluginManager/advanced.jelly b/core/src/main/resources/hudson/PluginManager/advanced.jelly index 15853cc47236..e636b32173ae 100644 --- a/core/src/main/resources/hudson/PluginManager/advanced.jelly +++ b/core/src/main/resources/hudson/PluginManager/advanced.jelly @@ -77,9 +77,15 @@ THE SOFTWARE.

${%Update Site}

+ + ${%Reset to default} + + id="update-site-url" + value="${app.updateCenter.getSite(app.updateCenter.ID_DEFAULT).url}" + checkUrl="checkUpdateSiteUrl" checkDependsOn=""/> + diff --git a/core/src/main/resources/hudson/PluginManager/advanced_zh_TW.properties b/core/src/main/resources/hudson/PluginManager/advanced_zh_TW.properties index 705271ca5598..0dddbff463d0 100644 --- a/core/src/main/resources/hudson/PluginManager/advanced_zh_TW.properties +++ b/core/src/main/resources/hudson/PluginManager/advanced_zh_TW.properties @@ -34,3 +34,4 @@ Deploy\ Plugin=部署外掛 Deploy=部署 Advanced\ Settings=進階設定 Or=或 +Reset\ to\ default=重設回預設值