Firefox Addon
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

201 líneas
5.5KB

  1. var g_mid = "";
  2. function saveCurrentProxy(e) {
  3. e.preventDefault();
  4. browser.storage.local.set({
  5. currentProxy: document.querySelector("#currentProxy").checked?1:0
  6. });
  7. }
  8. function showproxy(config){
  9. document.querySelector("#host").value = config.host ;
  10. document.querySelector("#port").value = config.port ;
  11. document.querySelector('#type [value="socks"]').selected = true;
  12. document.querySelector("#username").value = config.username;
  13. if (config.host == ""){
  14. document.querySelector("#currentProxy").checked = false;
  15. document.querySelector("#currentProxy").disabled = true;
  16. }else{
  17. document.querySelector("#currentProxy").checked = config.enable;
  18. document.querySelector("#currentProxy").disabled = false;
  19. }
  20. updateState();
  21. }
  22. function updateState() {
  23. if(currentProxy==0)
  24. {
  25. browser.browserAction.setIcon({path: "icons/unlock48.png"});
  26. browser.browserAction.setTitle({title: "Local IP"});
  27. }
  28. else
  29. {
  30. browser.browserAction.setIcon({path: "icons/lock48.png"});
  31. browser.browserAction.setTitle({title: "Biukop Secure Internet"});
  32. }
  33. }
  34. function IsJsonString(str) {
  35. try {
  36. JSON.parse(str);
  37. } catch (e) {
  38. return false;
  39. }
  40. return true;
  41. }
  42. function showMessage(msg) {
  43. var el = document.querySelector("#errMsg");
  44. if (msg != undefined)
  45. el.innerText = msg;
  46. else{
  47. el.innerText = "";
  48. }
  49. }
  50. function showLink(href, text) {
  51. console.log(href);
  52. console.log(text);
  53. var el = document.querySelector("#msgLink");
  54. if ( href != undefined && text !=undefined ) {
  55. el.href = href;
  56. el.innerText = text;
  57. el.visibility = 'visible';
  58. }else{
  59. el.innerText = '';
  60. el.visibility = 'hidden';
  61. }
  62. }
  63. function defaultConfig(){
  64. return {
  65. type: 'direct',
  66. host: '',
  67. port: 0,
  68. username: '',
  69. password: '',
  70. proxyDNS: false,
  71. enable:false,
  72. }
  73. }
  74. function isValidResponse(msg){
  75. if ( IsJsonString(xhr.responseText) ){
  76. config = JSON.parse(xhr.responseText);
  77. config.success = true;
  78. }
  79. return false;
  80. }
  81. function license(val){
  82. if ( val == undefined || val == "" || val.length < 5 ){
  83. showMessage("Please enter a valid license");
  84. return;
  85. }
  86. var xhr = new XMLHttpRequest();
  87. xhr.onreadystatechange = function() {
  88. if (xhr.readyState === 4){
  89. var config = defaultConfig();
  90. if (IsJsonString(xhr.responseText)) {
  91. config = JSON.parse(xhr.responseText);
  92. showMessage(config.errMsg);
  93. showLink(config.link, config.linkText);
  94. }else{
  95. showMessage(xhr.responseText);
  96. showLink('','');
  97. }
  98. showproxy(config);
  99. browser.storage.local.set({
  100. proxySettings: {
  101. type: config.type,
  102. host: config.host,
  103. port: config.port,
  104. username: config.username,
  105. password: config.password,
  106. proxyDNS: config.proxyDNS,
  107. },
  108. skipLocal: true,
  109. mid: g_mid,
  110. license: val,
  111. currentProxy: config.enable? 1: 0
  112. });
  113. }
  114. };
  115. xhr.open('POST', 'https://license.biukop.com.au/dedicatedip/');
  116. //xhr.open('POST', 'https://lawipac.com/dumprequest.php');
  117. xhr.setRequestHeader('Content-Type', 'application/json');
  118. var data = {
  119. license: val,
  120. mid: g_mid
  121. };
  122. xhr.send(JSON.stringify(data));
  123. }
  124. function restoreOptions(e) {
  125. function onGot(item) {
  126. g_mid = item.mid;
  127. init_mid(item.mid); //just in case
  128. document.querySelector("#license").value = item.license;
  129. document.querySelector("#currentProxy").checked = item.currentProxy ==1;
  130. license(item.license);
  131. }
  132. function onError(error) {
  133. console.log(`Error: ${error}`);
  134. }
  135. var gettingItem = browser.storage.local.get({
  136. mid: "",
  137. currentProxy: 0,
  138. skipLocal: true,
  139. license: "",
  140. proxySettings: {
  141. type: 'direct',
  142. host: '',
  143. port: 0,
  144. username: '',
  145. password: '',
  146. proxyDNS: false
  147. }
  148. });
  149. gettingItem.then(onGot, onError);
  150. }
  151. function register(e) {
  152. e.preventDefault();
  153. var license_code = document.querySelector("#license").value;
  154. license(license_code);
  155. }
  156. document.addEventListener("DOMContentLoaded", restoreOptions);
  157. document.querySelector("#currentProxy").addEventListener("change", saveCurrentProxy);
  158. document.querySelector("#register").addEventListener("click", register);
  159. function init_mid(existing_id) {
  160. function createUUID() {
  161. var uuid = new Date().valueOf();
  162. return (uuid + '-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx').replace(/[xy]/g, function(c) {
  163. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  164. return v.toString(16);
  165. });
  166. }
  167. if ( existing_id== undefined || existing_id == "" || existing_id.length < 10 ){
  168. var uuid = createUUID();
  169. console.log("create new mid =:" + uuid) ;
  170. g_mid = uuid;
  171. browser.storage.local.set({mid: uuid});
  172. }
  173. }