cbi-select-input-add.htm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <script>
  2. function vpn_add()
  3. {
  4. var vpn_name = div_add.querySelector("#instance_name1").value.replace(/[^\x00-\x7F]|[\s\.!@#$%^&*()\-+=\[\]{};':"\\|,<>\/?]/g,'');
  5. var vpn_template = div_add.querySelector("#instance_template").value;
  6. var form = document.getElementsByName('cbi')[0];
  7. if (!vpn_name || !vpn_name.length)
  8. {
  9. return info_message(vpn_output, "<%=pcdata(translate("The 'Name' field must not be empty!"))%>", 2000);
  10. }
  11. document.getElementById("instance_name1").value = vpn_name;
  12. if (document.getElementById("cbi-openvpn-" + vpn_name) != null)
  13. {
  14. return info_message(vpn_output, "<%=pcdata(translate("Instance with that name already exists!"))%>", 2000);
  15. }
  16. if (!vpn_template || !vpn_template.length)
  17. {
  18. return info_message(vpn_output, "<%=pcdata(translate("Please select a valid VPN template!"))%>", 2000);
  19. }
  20. if (form)
  21. {
  22. form.submit();
  23. }
  24. }
  25. function vpn_upload()
  26. {
  27. var vpn_name = div_upload.querySelector("#instance_name2").value.replace(/[^\x00-\x7F]|[\s\.!@#$%^&*()\-+=\[\]{};':"\\|,<>\/?]/g,'');
  28. var vpn_file = document.getElementById("ovpn_file").value;
  29. var form = document.getElementsByName('cbi')[0];
  30. if (!vpn_name || !vpn_name.length)
  31. {
  32. return info_message(vpn_output, "<%=pcdata(translate("The 'Name' field must not be empty!"))%>", 2000);
  33. }
  34. document.getElementById("instance_name2").value = vpn_name;
  35. if (document.getElementById("cbi-openvpn-" + vpn_name) != null)
  36. {
  37. return info_message(vpn_output, "<%=pcdata(translate("Instance with that name already exists!"))%>", 2000);
  38. }
  39. if (!vpn_file || !vpn_file.length)
  40. {
  41. return info_message(vpn_output, "<%=pcdata(translate("Please select a valid OVPN config file to upload!"))%>", 2000);
  42. }
  43. if (form)
  44. {
  45. form.enctype = 'multipart/form-data';
  46. form.action = '<%=url('admin/vpn/openvpn/upload')%>';
  47. form.submit();
  48. }
  49. }
  50. function info_message(output, msg, timeout)
  51. {
  52. timeout = timeout || 0;
  53. output.innerHTML = '<em>' + msg + '</em>';
  54. if (timeout > 0)
  55. {
  56. setTimeout(function(){ output.innerHTML=""}, timeout);
  57. }
  58. }
  59. </script>
  60. <%+openvpn/ovpn_css%>
  61. <div class="cbi-section-node">
  62. <div class="table cbi-section-table">
  63. <h4><%:Template based configuration%></h4>
  64. <div class="tr cbi-section-table-row" id="div_add">
  65. <div class="td left">
  66. <input type="text" maxlength="20" placeholder="Instance name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.text" id="instance_name1" />
  67. </div>
  68. <div class="td left">
  69. <select id="instance_template" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.select">
  70. <option value="" selected="selected" disabled="disabled"><%:Select template ...%></option>
  71. <%- for k, v in luci.util.kspairs(self.add_select_options) do %>
  72. <option value="<%=k%>"><%=luci.xml.pcdata(v)%></option>
  73. <% end -%>
  74. </select>
  75. </div>
  76. <div class="td left">
  77. <input class="btn cbi-button cbi-button-add" type="submit" onclick="vpn_add(); return false;" value="<%:Add%>" title="<%:Add template based configuration%>" /><br />
  78. </div>
  79. </div>
  80. <h4><%:OVPN configuration file upload%></h4>
  81. <div class="tr cbi-section-table-row" id="div_upload">
  82. <div class="td left">
  83. <input type="text" maxlength="20" placeholder="Instance name" name="instance_name2" id="instance_name2" />
  84. </div>
  85. <div class="td left">
  86. <input type="file" name="ovpn_file" id="ovpn_file" accept="application/x-openvpn-profile,.ovpn" />
  87. </div>
  88. <div class="td left">
  89. <input class="btn cbi-button cbi-button-add" type="submit" onclick="vpn_upload(); return false;" value="<%:Upload%>" title="<%:Upload ovpn file%>" />
  90. </div>
  91. </div>
  92. </div>
  93. <div class="vpn-output">
  94. <span id="vpn_output"></span>
  95. </div>
  96. </div>