|
45 | 45 | import java.util.logging.Level;
|
46 | 46 | import java.util.logging.Logger;
|
47 | 47 | import java.util.stream.Collectors;
|
| 48 | + |
| 49 | +import org.apache.commons.validator.routines.UrlValidator; |
48 | 50 | import org.opengrok.indexer.Info;
|
49 | 51 | import org.opengrok.indexer.analysis.AnalyzerGuru;
|
50 | 52 | import org.opengrok.indexer.analysis.AnalyzerGuruHelp;
|
@@ -729,9 +731,14 @@ public static String[] parseOptions(String[] argv) throws ParseException {
|
729 | 731 |
|
730 | 732 | parser.on("-U", "--host", "=protocol://host:port/contextPath",
|
731 | 733 | "Send the current configuration to the specified address").Do(webAddr -> {
|
732 |
| - env = RuntimeEnvironment.getInstance(); |
733 |
| - |
734 | 734 | host = (String) webAddr;
|
| 735 | + String[] schemes = {"http", "https"}; |
| 736 | + UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS); |
| 737 | + if (!urlValidator.isValid(host)) { |
| 738 | + die("URL '" + host + "' is not valid."); |
| 739 | + } |
| 740 | + |
| 741 | + env = RuntimeEnvironment.getInstance(); |
735 | 742 | env.setConfigHost(host);
|
736 | 743 | }
|
737 | 744 | );
|
@@ -790,6 +797,12 @@ public static String[] parseOptions(String[] argv) throws ParseException {
|
790 | 797 | }
|
791 | 798 |
|
792 | 799 | private static void checkConfiguration() {
|
| 800 | + env = RuntimeEnvironment.getInstance(); |
| 801 | + |
| 802 | + if (noindex && (env.getConfigHost() == null || env.getConfigHost().isEmpty())) { |
| 803 | + die("Missing host URL"); |
| 804 | + } |
| 805 | + |
793 | 806 | if (repositories.size() > 0 && !cfg.isHistoryEnabled()) {
|
794 | 807 | die("Repositories were specified however history is off");
|
795 | 808 | }
|
|
0 commit comments