Advertisement
Guest User

Untitled

a guest
Aug 28th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.87 KB | None | 0 0
  1. kiwi.plugin('nickserv', function(kiwi) {
  2.  
  3. // Plugin Config #########################################################################
  4.  
  5. // NickServ Identify Regex
  6. var IDString = "^Questo nick è registrato e protetto. Se questo è il tuo";
  7. // NickServ Identify text
  8. var IDText = "Il nick scelto risulta registrato, inserisci la password per autenticarti.";
  9. // IDentify Button text
  10. var LoginText = "Effettua il login ad un account";
  11. // IDentify Button text
  12. var RegisterText = "Registra il nickname attualmente in uso:";
  13. // IDentify Button text
  14. var IDButton = "IDENTIFICATI";
  15. // IDentify Button text
  16. var RegButton = "REGISTRATI";
  17. // Wrong password Regex
  18. var WPString = "^Password errata";
  19. // Wrong password text
  20. var WPText = "Password errata!";
  21. // Bad password text on register
  22. var BPText = "Attenzione, prova di nuovo con una password più sicura.<br> Le password devono essere lunghe almeno 5 caratteri, non devono essere facilmente intuibili (ad es. il proprio nome o nick)<br> e non possono contenere i caratteri di spazio e di tabulazione.";
  23. // Services enforce nick Regex
  24. var ENString = "^Il tuo nick sarà cambiato in";
  25. // Login success Regex
  26. var LSString = "^Password accettata - adesso sei riconosciuto";
  27. // Account confirmation request Regex
  28. var ConfirmReqString = "^Il tuo indirizzo email non è stato confermato. Per confermarlo, segui le istruzioni contenute nella email che hai ricevuto quando ti sei registrato";
  29. // Account confirmation text
  30. var ConfirmReqText = "Inserisci il codice di conferma ricevuto per email per completare la registrazione dell\' account.";
  31. // Invalid Confirmation code Regex
  32. var InvalidConfirmString = "^Codice di attivazione non valido";
  33. // Invalid Confirmation code text
  34. var InvalidConfirmText = "Codice di attivazione non valido. Inserisci il codice di conferma ricevuto per email per completare la registrazione dell\' account.";
  35. // A valid confirmation code has been entered
  36. var ValidConfirmString = "^Il tuo indirizzo email per (.*) è stato confermato.";
  37. // Bad Password Notify
  38. var BadPwdString = "^Attenzione, prova di nuovo con una password più sicura.";
  39. // Bad Email Notify
  40. var BadEmailString = "non è un indirizzo e-mail valido.";
  41. // Register delay
  42. var RegDelayString = "^E' necessario aver usato questo nick per almeno 30 secondi prima di poterlo registrare.";
  43. // Valid Password
  44. var ValidPwdString = "^Password accettata - adesso sei riconosciuto.";
  45. // Already identified
  46. var AlreadyIdString ="^Sei già identificato.";
  47. // Confirm Button text
  48. var ConfirmButton = "CONFERMA REGISTRAZIONE";
  49. // End Plugin Config ####################################################################
  50.  
  51. var IDRe = new RegExp(IDString ,"");
  52. var WPRe = new RegExp(WPString ,"");
  53. var ENRe = new RegExp(ENString ,"");
  54. var LSRe = new RegExp(LSString ,"");
  55. var ConfirmReqRe = new RegExp(ConfirmReqString ,"");
  56. var InvalidConfirmRe = new RegExp(InvalidConfirmString ,"");
  57. var ValidConfirmRe = new RegExp(ValidConfirmString ,"");
  58. var BadPwdRe = new RegExp(BadPwdString ,"");
  59. var BadEmailRe = new RegExp(BadEmailString ,"");
  60. var RegDelayRe = new RegExp(RegDelayString ,"");
  61. var ValidPwdRe = new RegExp(ValidPwdString ,"");
  62. var AlreadyIdRe = new RegExp(AlreadyIdString ,"");
  63.  
  64. var link = document.createElement("link");
  65. link.type = "text/css";
  66. link.rel = "stylesheet";
  67. link.href = "/plugins/nickserv.css";
  68. document.head.appendChild(link);
  69.  
  70. var data = new kiwi.Vue({data: {themeName: ''}});
  71. data.themeName = kiwi.themes.currentTheme().name.toLowerCase();
  72.  
  73. kiwi.on('theme.change', function(event) {
  74. data.themeName = kiwi.themes.currentTheme().name.toLowerCase();
  75. console.log(data.themeName);
  76.  
  77. });
  78.  
  79. var nsregisterdialog = kiwi.Vue.extend({
  80.  
  81. data: function data() {
  82. return {
  83. accountInput:'',
  84. pwdInput: ''
  85. }
  86. },
  87.  
  88. computed: {
  89. themeName: function() {
  90. return data.themeName;
  91. },
  92. currentNick: function() {
  93. var net = kiwi.state.getActiveNetwork();
  94. return net.ircClient.user.nick;
  95. }
  96. },
  97.  
  98. methods: {
  99. onRegister: function () {
  100. kiwi.state.$emit('input.raw', '/NS register '+ this.pwdInput + ' ' + this.accountInput )
  101.  
  102. }
  103. },
  104.  
  105. template: '<div :class="[\'kiwi-\' + themeName + \'-simple-nick\', \'input-text\', \'input-text--focus\', \'input-text--reveal-value\']" id="nickserv-form" title="NickServ" style="text-align:center;"><p :class="[\'kiwi-\' + themeName + \'-simple-error\', \'kiwi-ns-register\']" id="validate">' + RegisterText + ' {{currentNick}}</p><input class="kiwi-ns-input" placeholder="Inserisci un indirizzo email valido" type="text" v-model="accountInput"><input class="kiwi-ns-input" placeholder="Inserisci la password" type="password" v-model="pwdInput"><div class="input-text-underline"><div class="input-text-underline-active"></div></div><button :class="[\'u-button\', \'u-button-primary\', \'u-submit\', \'kiwi-\' + themeName + \'-simple-start\', \'kiwi-ns-button\']" v-on:click="onRegister" >' + RegButton + '</button></div>',
  106. });
  107.  
  108. var nslogindialog = kiwi.Vue.extend({
  109.  
  110. data: function data() {
  111. return {
  112. accountInput:'',
  113. pwdInput: ''
  114. }
  115. },
  116.  
  117. computed: {
  118. themeName: function() {
  119. return data.themeName;
  120. }
  121. },
  122.  
  123. methods: {
  124. onIdentify: function () {
  125. kiwi.state.$emit('input.raw', '/NS identify '+ this.accountInput + ' ' + this.pwdInput )
  126. kiwi.state.$emit('input.raw', '/NICK '+ this.accountInput )
  127. var loginNick = this.accountInput;
  128. var http = new XMLHttpRequest();
  129. var url = 'https://webcpanel.simosnap.com/';
  130. var params = 'username='+this.accountInput+'&password='+this.pwdInput;
  131. http.open('POST', url, true);
  132.  
  133. //Send the proper header information along with the request
  134. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  135.  
  136. http.withCredentials = true;
  137. http.send(params);
  138.  
  139.  
  140. }
  141. },
  142.  
  143. template: '<div :class="[\'kiwi-\' + themeName + \'-simple-nick\', \'input-text\', \'input-text--focus\', \'input-text--reveal-value\']" id="nickserv-form" title="NickServ" style="text-align:center;"><p :class="[\'kiwi-\' + themeName + \'-simple-error\', \'kiwi-ns-login\']" id="validate">' + LoginText + '</p><input class="kiwi-ns-input" placeholder="Inserisci account NickServ" type="text" v-model="accountInput"><input class="kiwi-ns-input" placeholder="Inserisci la password" type="password" v-model="pwdInput"><div class="input-text-underline"><div class="input-text-underline-active"></div></div><button :class="[\'u-button\', \'u-button-primary\', \'u-submit\', \'kiwi-\' + themeName + \'-simple-start\', \'kiwi-ns-button\']" v-on:click="onIdentify" >' + IDButton + '</button></div>',
  144. });
  145.  
  146.  
  147. var nsdialog = kiwi.Vue.extend({
  148.  
  149. data: function data() {
  150. return {
  151. pwdInput: ''
  152. }
  153. },
  154.  
  155. computed: {
  156. themeName: function() {
  157. return data.themeName;
  158. }
  159. },
  160.  
  161. methods: {
  162. onIdentify: function () {
  163. kiwi.state.$emit('input.raw', '/NS identify '+ this.pwdInput )
  164. var loginNick = kiwi.state.getNetwork(1).nick;
  165. var http = new XMLHttpRequest();
  166. var url = 'https://webcpanel.simosnap.com/';
  167. var params = 'username='+loginNick+'&password='+this.pwdInput;
  168. http.open('POST', url, true);
  169.  
  170. //Send the proper header information along with the request
  171. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  172.  
  173. http.withCredentials = true;
  174. http.send(params);
  175.  
  176.  
  177. }
  178. },
  179.  
  180. template: '<div :class="[\'kiwi-\' + themeName + \'-simple-nick\', \'input-text\', \'input-text--focus\', \'input-text--reveal-value\']" id="nickserv-form" title="NickServ" style="text-align:center;"><p :class="[\'kiwi-\' + themeName + \'-simple-error\', \'kiwi-ns-error\']" id="validate">' + IDText + '</p><input class="kiwi-ns-input" placeholder="Inserisci la password" type="password" v-model="pwdInput"><div class="input-text-underline"><div class="input-text-underline-active"></div></div><button :class="[\'u-button\', \'u-button-primary\', \'u-submit\', \'kiwi-\' + themeName + \'-simple-start\', \'kiwi-ns-button\']" v-on:click="onIdentify" >' + IDButton + '</button></div>',
  181. });
  182.  
  183. var confirmdialog = kiwi.Vue.extend({
  184.  
  185. data: function data() {
  186. return {
  187. codeInput: ''
  188. }
  189. },
  190.  
  191. computed: {
  192. themeName: function() {
  193. return data.themeName;
  194. }
  195. },
  196.  
  197. methods: {
  198. onIdentify: function () {
  199. kiwi.state.$emit('input.raw', '/NS confirm '+ this.codeInput )
  200.  
  201. }
  202. },
  203.  
  204. template: '<div :class="[\'kiwi-\' + themeName + \'-simple-nick\', \'input-text\', \'input-text--focus\', \'input-text--reveal-value\']" id="nickserv-form" title="NickServ" style="text-align:center;"><p :class="[\'kiwi-\' + themeName + \'-simple-error\', \'kiwi-ns-error\']" id="validate">' + ConfirmReqText + '</p><input class="kiwi-ns-input" placeholder="Inserisci il codice di conferma" type="text" v-model="codeInput"><div class="input-text-underline"><div class="input-text-underline-active"></div></div><button :class="[\'u-button\', \'u-button-primary\', \'u-submit\', \'kiwi-\' + themeName + \'-simple-start\', \'kiwi-ns-button\']" v-on:click="onIdentify" >' + ConfirmButton + '</button></div>',
  205. });
  206.  
  207.  
  208. var services = kiwi.Vue.extend({
  209.  
  210. computed: {
  211. themeName: function() {
  212. return data.themeName;
  213. },
  214. hasr: function() {
  215. return data.nsNotify;
  216. }
  217. },
  218.  
  219. methods: {
  220. close: function close() {
  221. kiwi.state.$emit('active.component', null);
  222. }
  223. },
  224.  
  225. template: '<div title="NickServ" style="text-align:center;height:100%;width:100%;"><div class="kiwi-appsettings-title"><span>chiudi</span> <i @click="close" style="buttonStyle" class="fa fa-times" aria-hidden="true"></i></div> <iframe src="https://webcpanel.simosnap.com/nickserv/info" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0"></iframe></div>',
  226. });
  227.  
  228. kiwi.addView('IRC Services CP', services);
  229.  
  230. function registerFn() {
  231. kiwi.state.$emit('mediaviewer.show', {component: nsregisterdialog });
  232. }
  233.  
  234. function cpanelFn() {
  235. kiwi.showView('IRC Services CP');
  236. }
  237.  
  238. function logoutFn() {
  239. kiwi.state.$emit('input.raw', '/NS Logout' );
  240. }
  241.  
  242. function loginFn() {
  243. kiwi.state.$emit('mediaviewer.show', {component: nslogindialog });
  244. }
  245.  
  246.  
  247. var RegBtn = document.createElement('div');
  248. RegBtn.className = 'kiwi-statebrowser-appsettings';
  249. RegBtn.addEventListener("click", registerFn );
  250. RegBtn.innerHTML = 'Registra Account <i aria-hidden="true" class="fa fa-lock"></i>';
  251. kiwi.addUi('browser', RegBtn);
  252.  
  253. var loginBtn = document.createElement('a');
  254. loginBtn.innerHTML = '<i aria-hidden="true" class="fa fa-sign-in"></i><span>Login</span>';
  255. loginBtn.addEventListener("click", loginFn);
  256. kiwi.addUi('header_channel', loginBtn);
  257.  
  258. kiwi.once('network.connecting', function(event) {
  259.  
  260. var loginNick = event.network.nick;
  261. var loginPass = event.network.connection.password;
  262. //kiwi.addTab('server', 'IRC Services CP', services );
  263.  
  264. var http = new XMLHttpRequest();
  265. var url = 'https://webcpanel.simosnap.com/';
  266. var params = 'username='+loginNick+'&password='+loginPass;
  267. http.open('POST', url, true);
  268.  
  269. //Send the proper header information along with the request
  270. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  271.  
  272. http.withCredentials = true;
  273. http.send(params);
  274. });
  275.  
  276. kiwi.on('irc.mode', function(event, network) {
  277. //console.log(event);
  278. if ((event.nick == "NickServ") && (event.target == network.nick)) {
  279. setTimeout(function() {
  280. var net = kiwi.state.getActiveNetwork();
  281. console.log(net.ircClient.user.modes.has('r'));
  282. hasR = net.ircClient.user.modes.has('r');
  283.  
  284.  
  285.  
  286. if (hasR == true) {
  287. loginBtn.innerHTML = '<i aria-hidden="true" class="fa fa-sign-out"></i><span>Logout</span>';
  288. loginBtn.removeEventListener("click", loginFn);
  289. loginBtn.addEventListener("click", logoutFn);
  290. RegBtn.removeEventListener("click", registerFn );
  291. RegBtn.addEventListener("click", cpanelFn );
  292. RegBtn.innerHTML = 'IRC Services CP <i aria-hidden="true" class="fa fa-dashboard"></i>';
  293. //RegBtn.style.visibility="hidden";
  294. } else {
  295. loginBtn.innerHTML = '<i aria-hidden="true" class="fa fa-sign-in"></i><span>Login</span>';
  296. loginBtn.removeEventListener("click", logoutFn);
  297. loginBtn.addEventListener("click", loginFn);
  298. RegBtn.removeEventListener("click", cpanelFn );
  299. RegBtn.addEventListener("click", registerFn );
  300. RegBtn.innerHTML = 'Registra Account <i aria-hidden="true" class="fa fa-lock"></i>';
  301. //RegBtn.style.visibility="visible";
  302. var http = new XMLHttpRequest();
  303. var url = 'https://webcpanel.simosnap.com/logout';
  304. http.open('GET', url, true);
  305.  
  306. //Send the proper header information along with the request
  307. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  308.  
  309. http.withCredentials = true;
  310. http.send();
  311. }
  312.  
  313. }, 0);
  314. }
  315.  
  316. });
  317.  
  318. kiwi.on('irc.notice', function(event) {
  319.  
  320. if ((event.nick == 'NickServ') && (event.message.match(IDRe))) {
  321. kiwi.state.$emit('mediaviewer.show', {component: nsdialog })
  322. }
  323. if ((event.nick == 'NickServ') && (event.message.match(WPRe))) {
  324. var el = document.getElementById("validate")
  325. el.innerHTML = WPText ;
  326. }
  327. if ((event.nick == 'NickServ') && (event.message.match(ConfirmReqRe))) {
  328. kiwi.state.$emit('mediaviewer.show', {component: confirmdialog })
  329. }
  330.  
  331. if ((event.nick == 'NickServ') && (event.message.match(InvalidConfirmRe))) {
  332. var el = document.getElementById("validate")
  333. el.innerHTML = InvalidConfirmText ;
  334. }
  335.  
  336. if ((event.nick == 'NickServ') && (event.message.match(ENRe))) {
  337. kiwi.state.$emit('mediaviewer.hide')
  338. }
  339.  
  340. if ((event.nick == 'NickServ') && (event.message.match(LSRe))) {
  341. kiwi.state.$emit('mediaviewer.hide')
  342. }
  343.  
  344. if ((event.nick == 'NickServ') && (event.message.match(ValidConfirmRe))) {
  345. kiwi.state.$emit('mediaviewer.hide')
  346. }
  347.  
  348. if ((event.nick == 'NickServ') && (event.message.match(BadPwdRe))) {
  349. var el = document.getElementById("validate")
  350. el.innerHTML = BPText ;
  351. }
  352.  
  353.  
  354. if ((event.nick == 'NickServ') && (event.message.match(BadEmailRe))) {
  355. var el = document.getElementById("validate")
  356. el.innerHTML = event.message ;
  357. }
  358.  
  359.  
  360. if ((event.nick == 'NickServ') && (event.message.match(RegDelayRe))) {
  361. var el = document.getElementById("validate");
  362. el.innerHTML = event.message ;
  363. setTimeout(function() {
  364. kiwi.state.$emit('mediaviewer.hide');
  365. }, 2000);
  366. }
  367. if ((event.nick == 'NickServ') && (event.message.match(ValidPwdRe))) {
  368. var el = document.getElementById("validate");
  369. el.innerHTML = event.message ;
  370. setTimeout(function() {
  371. kiwi.state.$emit('mediaviewer.hide');
  372. }, 2000);
  373. }
  374.  
  375. if ((event.nick == 'NickServ') && (event.message.match(AlreadyIdRe))) {
  376. var el = document.getElementById("validate");
  377. el.innerHTML = event.message ;
  378. setTimeout(function() {
  379. kiwi.state.$emit('mediaviewer.hide');
  380. }, 2000);
  381. }
  382. });
  383.  
  384. kiwi.on('input.command.nick', function(event) {
  385. kiwi.state.$emit('mediaviewer.hide')
  386. });
  387.  
  388. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement