|
851 | 851 | $('<hr></hr>').appendTo(divOuter); |
852 | 852 | line = $('<div></div>').appendTo(divOuter); |
853 | 853 | $('<div></div').appendTo(line).checkbox({ labelText: 'Use Proxy to njsPC Server', binding: binding + 'useProxy' }); |
| 854 | + // Internal-only hostname warning container (hidden by default) |
| 855 | + var warnLine = $('<div class="picOptionLine internal-host-warning" style="display:none;margin-top:.5rem;"></div>').appendTo(divOuter); |
| 856 | + $('<div class="picMessage warn internal-host-msg"></div>') |
| 857 | + .css({ color: '#c09853', background: '#fcf8e3', padding: '.35rem .5rem', border: '1px solid #fbeed5', borderRadius: '.25rem', fontSize: '.8rem', maxWidth: '32rem' }) |
| 858 | + .html('<i class="fas fa-exclamation-triangle" style="margin-right:.35rem;"></i> Hostname looks internal-only. Enable "Use Proxy" or change to a resolvable host / IP for direct browser access.') |
| 859 | + .appendTo(warnLine); |
854 | 860 | //$('<div class="picOptionLine"><label>Server Address</label><input class="picServerAddress" type="text" value="' + settings.services.ip + '"></input><span>:</span><input class="picServerPort" type="text" value="' + settings.services.port + '"></input></div>').appendTo(contents); |
855 | 861 | var btnPnl = $('<div class="picBtnPanel btn-panel"></div>'); |
856 | 862 | btnPnl.appendTo(contents); |
|
907 | 913 | var btnApply = $('<div></div>'); |
908 | 914 | btnApply.appendTo(btnPnl); |
909 | 915 | btnApply.actionButton({ text: 'Apply', icon: '<i class="fas fa-save"></i>' }); |
| 916 | + function evaluateInternalHostWarning() { |
| 917 | + try { |
| 918 | + var cfg = dataBinder.fromElement(divOuter) || {}; |
| 919 | + var services = cfg.services || {}; |
| 920 | + var host = (services.ip || '').trim(); |
| 921 | + var useProxy = !!services.useProxy; |
| 922 | + var warn = false; |
| 923 | + if (!useProxy && host) { |
| 924 | + var isIPv4 = /^\d+\.\d+\.\d+\.\d+$/.test(host); |
| 925 | + var isIPv6 = /:/.test(host); // coarse check |
| 926 | + var hasDot = host.indexOf('.') !== -1; |
| 927 | + if (!isIPv4 && !isIPv6 && !hasDot && host.toLowerCase() !== 'localhost') warn = true; |
| 928 | + } |
| 929 | + if (warn) warnLine.show(); else warnLine.hide(); |
| 930 | + } catch (ex) { /* ignore */ } |
| 931 | + } |
| 932 | + // Bind events to re-evaluate |
| 933 | + divOuter.on('keyup change', 'input', evaluateInternalHostWarning); |
| 934 | + divOuter.on('click', '.picCheckbox', evaluateInternalHostWarning); |
| 935 | + // Initial eval after binding |
| 936 | + setTimeout(evaluateInternalHostWarning, 150); |
| 937 | + |
910 | 938 | btnApply.on('click', function (e) { |
911 | 939 | if (dataBinder.checkRequired(divOuter)) { |
912 | 940 | var cfg = dataBinder.fromElement(divOuter); |
| 941 | + evaluateInternalHostWarning(); |
913 | 942 | $.putLocalService('/config/serviceUri', cfg.services, 'Updating Connection...', function (data, status, xhr) { |
914 | | - $('div.picDashboard, div.picMessageManager').each(function () { |
915 | | - this.reset(); |
916 | | - }); |
917 | | - |
| 943 | + $('div.picDashboard, div.picMessageManager').each(function () { this.reset(); }); |
918 | 944 | }); |
919 | 945 | } |
920 | | - |
921 | 946 | }); |
922 | 947 | dataBinder.bind(divOuter, settings); |
| 948 | + // Re-evaluate after final bind (in case settings loaded asynchronously) |
| 949 | + setTimeout(evaluateInternalHostWarning, 300); |
923 | 950 | }); |
924 | 951 | }, |
925 | 952 | _buildBackupTab: function (settings) { |
|
0 commit comments