-
Notifications
You must be signed in to change notification settings - Fork 1
/
proxyManager.js
1 lines (1 loc) · 16.9 KB
/
proxyManager.js
1
!function(){"use strict";let e;const t=isNaN(location.port)||""===location.port?location.hostname:`${location.hostname}:${location.port}`;function n(){}async function o(){try{e&&(await g().catch(n),await fetch("./proxyCheckerBackground.php?uid="+e.user_id,{signal:AbortSignal.timeout(5e3)}).catch(n),await d().catch(n),await g().catch(n))}catch(e){w(e.message)}}let a,r="";async function c(){const e=await fetch("./embed.php?file=proxyChecker.txt",{signal:AbortSignal.timeout(5e3),mode:"cors"}).then((e=>e.text())).catch(n);if(r===e)return;if("string"!=typeof e)return;if(0===e.trim().length)return;r=e||"";const t=(e||"").split(/\r?\n/).slice(-1e3).map((e=>(e=(e=(e=(e=(e=(e=(e=e.replace(/\x1b\[[0-9;]*m/g,"")).replace(/port closed/gm,'<span class="text-red-400">port closed</span>')).replace(/port open/gm,'<span class="text-green-400">port open</span>')).replace(/not working/gm,'<span class="text-red-600">not working</span>')).replace(/dead/gm,'<span class="text-red-600">dead</span>')).replace(/(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}\b)\s+invalid/g,'$1 <span class="text-red-600">invalid</span>')).replace(/(\badd\b)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5})/g,'<span class="text-green-400">add</span> $2'),/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}/.test(e)&&(e=e.replace(/working.*/,(e=>e.includes("-1")?`<span class="text-orange-400">${e}</span>`:`<span class="text-green-400">${e}</span>`))),e=(e=(e=(e=(e=(e=(e=e.replace(/\[DELETED\]/,'<i class="fal fa-trash text-red-400"></i>')).replace(/\[SKIPPED\]/,'<i class="fal fa-forward text-silver"></i>')).replace(/\[RESPAWN\]/,'<i class="fa-solid fa-user-magnifying-glass text-magenta"></i>')).replace(/\[FILTER-PORT\]/,'<i class="fa-thin fa-filter-list text-berry"></i>')).replace(/\[CHECKER-PARALLEL\]/,'<i class="fa-thin fa-list-check text-polkador"></i>')).replace(/\[CHECKER\]/,'<i class="fa-thin fa-check-to-slot text-polkador"></i>')).replace(/\[SQLite\]/,'<i class="fa-thin fa-database text-polkador"></i>')))).join("<br/>"),o=document.getElementById("cpresult");o.innerHTML=t,o.scrollHeight>o.clientHeight&&a&&(o.scrollTop=o.scrollHeight-o.clientHeight);const c=document.querySelector("#nav-info"),i=await fetch("./status.json",{signal:AbortSignal.timeout(5e3),mode:"cors",cache:"no-cache"}).then((e=>e.json())).catch((()=>({})));i.untested&&i.untested>0&&(c.querySelector("#untested").innerText=parseInt(i.untested).toLocaleString()),i.all&&i.all>0&&(c.querySelector("#all-total").innerText=parseInt(i.all).toLocaleString()),i.dead&&i.dead>0&&(c.querySelector("#dead").innerText=parseInt(i.dead).toLocaleString()),i.working&&i.working>0&&(c.querySelector("#working").innerText=parseInt(i.working).toLocaleString())}function i(){const e=document.getElementById("cpresult");e.scrollIntoView({behavior:"smooth"}),setTimeout((()=>{window.scrollBy({top:-100,left:0,behavior:"smooth"})}),1e3)}async function s(){try{let e=l("user_config");return e||(await fetch("./info.php",{signal:AbortSignal.timeout(5e3),mode:"cors"}),e=l("user_config")),JSON.parse(atob(decodeURIComponent(e)))}catch(e){}}function l(e){const t=document.cookie.split("; ");for(let n=0;n<t.length;n++){const o=t[n].split("=");if(o[0]===e)return o[1]}return null}async function d(){const e=document.querySelector("span#status"),t=[document.getElementById("filter-ports"),document.getElementById("respawn-proxies"),document.getElementById("recheck")];return await fetch("./embed.php?file=status.txt",{signal:AbortSignal.timeout(5e3),mode:"cors"}).then((e=>e.text())).then((n=>n.trim().includes("idle")?(a=!1,t.forEach((e=>{e.classList.remove("disabled")})),e.setAttribute("class","inline-flex items-center rounded-md bg-red-50 px-2 py-1 text-xs font-medium text-red-700 ring-1 ring-inset ring-red-600/10"),e.innerHTML="IDLE",!1):(t.forEach((e=>{e.classList.contains("disabled")||e.classList.add("disabled")})),e.innerHTML=n.trim().toUpperCase(),e.setAttribute("class","inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-inset ring-green-600/20"),a=!0,!0))).catch((()=>!1))}s().then((e=>{})).catch((()=>{})).finally((()=>{!function(e){const t=window.location.href,n=new URL(t),o=n.protocol,a=n.hostname,r="72.10.160.171:24049";let c="# Check proxies immediately";c+=`\ncurl -X POST ${o}//${a}/proxyCheckerParallel.php\n -d "proxy=${r}"`,c+="\n# Check open ports",c+=`\ncurl -X POST ${o}//${a}/scanPorts.php\n -d "proxy=${r}`;const i=document.getElementById(e);i?i.textContent=c:console.error(`Element with id "${e}" not found.`)}("curl-command"),document.getElementById("proxyForm").addEventListener("submit",(function(e){e.preventDefault(),i();const t=new FormData(this);fetch("proxyCheckerParallel.php",{method:"POST",body:t}).then((e=>{if(!e.ok)throw new Error("Network response was not ok");return e.text()})).then((e=>{document.getElementById("result").innerHTML=`<p class="text-green-600 font-semibold">POST request successful!</p>\n <pre class="mt-2 bg-gray-100 p-2 rounded text-black whitespace-pre-wrap break-all">${e}</pre>`})).catch((e=>{console.error("Error:",e),document.getElementById("result").innerHTML=`<p class="text-red-600 font-semibold">Error: ${e.message}</p>`}))})),document.querySelector("textarea#proxy").addEventListener("change",(function(e){const t=e.target.value,n=encodeURI(t),o=document.getElementById("result-curl"),a=window.location.origin;o.innerHTML=`\n <div class="relative">\n <pre class="dark:bg-gray-800 dark:text-white whitespace-pre-wrap break-words p-4"><code class="dark:text-white">curl -X POST ${a}/proxyCheckerParallel.php \\\n\t -d "proxy=${n}"</code></pre>\n <button id="copyButton" class="absolute top-2 right-2 bg-blue-500 hover:bg-blue-600 text-white font-semibold py-1 px-2 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50">Copy</button>\n </div>\n `,document.getElementById("copyButton").addEventListener("click",(function(){const e=o.querySelector("code").innerText;navigator.clipboard.writeText(e).then((function(){console.log("Text copied to clipboard"),alert("Copied to clipboard")}),(function(e){console.error("Could not copy text: ",e)}))}))}))}));const p=1;function u(){const e=function(){const e="lastExecutionTime=",t=decodeURIComponent(document.cookie).split(";");for(let n=0;n<t.length;n++){let o=t[n];for(;" "===o.charAt(0);)o=o.substring(1);if(0===o.indexOf(e))return new Date(o.substring(18,o.length))}return null}(),t=new Date;(!e||t.getTime()-e.getTime()>=60*p*1e3)&&(fetch("./proxyWorkingBackground.php",{signal:AbortSignal.timeout(5e3),mode:"cors"}).catch((()=>{})),function(){const e=new Date;e.setTime(e.getTime()+60*p*1e3),document.cookie="lastExecutionTime="+e.toUTCString()+"; path="+location.pathname}())}class h{urlParams=new URLSearchParams(window.location.search);constructor(e,t){this.items=e,this.itemsPerPage=t,this.currentPage=parseInt(this.urlParams.get("page"))||1,this.totalPages=Math.ceil(this.items.length/this.itemsPerPage),this.proxyType=this.urlParams.get("type")||"all"}getPaginatedItems(){const e=(this.currentPage-1)*this.itemsPerPage,t=Math.min(e+this.itemsPerPage,this.items.length),n=this.items.slice(e,t);return"all"!==this.proxyType?n.filter((e=>{const t=e.split("|");if(t.length>3){if(t[3].split("-").includes(this.proxyType.toUpperCase()))return!0;if("https"===this.proxyType)return"true"===t[11]}else console.log("Invalid split data:",e);return!1})):n}getPaginationControls(){const e=[];return e.push({type:this.currentPage>1?"link":"disabled",label:"First",page:1}),e.push({type:this.currentPage>1?"link":"disabled",label:"Previous",page:this.currentPage-1}),e.push({type:this.currentPage<this.totalPages?"link":"disabled",label:"Next",page:this.currentPage+1}),e.push({type:this.currentPage<this.totalPages?"link":"disabled",label:"Last",page:this.totalPages}),e}getPaginationData(){return{items:this.getPaginatedItems(),pagination:this.getPaginationControls()}}}let m;async function g(){u();let t=await fetch("./embed.php?file=working.txt",{signal:AbortSignal.timeout(5e3),mode:"cors"}).then((e=>e.text())).catch((()=>""));if(0!==t.trim().length&&(!m||m!==t)){m=t;const n=document.getElementById("wproxy");n.innerHTML="";const o=m.split(/\r?\n/).filter((e=>""!==e.trim())),a=new h(o,30).getPaginationData();a.items.forEach((t=>{const o=document.createElement("tr"),a=t.split("|");a.forEach(((t,n)=>{const r=document.createElement("td");if(r.setAttribute("class","border-b border-slate-100 dark:border-slate-700 p-4 text-slate-500 dark:text-slate-400"),r.innerText=t,0===n||n>13||n>=7&&n<=9?"-"!==r.innerText&&(r.innerHTML+=`<button class="rounded-full ml-2 pcopy" data="${t}" title="copy ${t}"><i class="fa-duotone fa-copy"></i></button>`,0===n&&(r.innerHTML+=`<button class="rounded-full ml-2 recheck" data="${t}" title="re-check ${t}"><i class="fa-duotone fa-rotate-right"></i></button>`)):2===n&&t.length>6?r.innerText=function(e){const t=new Date(e);if(isNaN(t.getTime()))return e;const n=new Date-t,o=Math.floor(n/1e3),a=Math.floor(o/60),r=Math.floor(a/60),c=Math.floor(r/24),i=r%24,s=a%60,l=o%60;let d="";c>0&&(d+=c+" day"+(1===c?"":"s")+" ");i>0&&(d+=i+" hour"+(1===i?"":"s")+" ");s>0&&(d+=s+" minute"+(1===s?"":"s")+" ");l>0&&(d+=l+" second"+(1===l?"":"s")+" ");return d+="ago",d}(t):r.classList.add("text-center"),3===n){const e=[{text:"HTTP",className:"bg-blue-500 text-white",url:"?type=http"},{text:"SSL",className:"bg-green-500 text-white",url:"?type=https"},{text:"SOCKS4",className:"bg-yellow-500 text-black",url:"?type=socks4"},{text:"SOCKS5",className:"bg-red-500 text-white",url:"?type=socks5"}],t=r.innerText.split("-").filter(((e,t,n)=>n.indexOf(e)===t)).filter((e=>e.trim().length>0));"true"==a[11]&&t.push("SSL"),r.innerHTML="",t.forEach((t=>{e.forEach((e=>{if(t.trim()===e.text){const t=document.createElement("span"),n=document.createElement("a");n.href=e.url,n.textContent=e.text,t.className=`inline-block px-2 py-1 text-xs font-semibold rounded-full mr-2 ${e.className}`,t.appendChild(n),r.appendChild(t)}}))}))}(7===n||6===n||n>13&&n<=18)&&"-"===t.trim()&&(b("./geoIpBackground.php?proxy="+encodeURIComponent(a[0])+"&uid="+e.user_id),x()),o.appendChild(r)})),n.appendChild(o)}));document.getElementById("pagination-controls").innerHTML=a.pagination.map((e=>"link"===e.type?`<a href="?page=${e.page}" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">${e.label}</a>`:"disabled"===e.type?`<span class="px-4 py-2 bg-gray-500 text-gray-300 rounded cursor-not-allowed">${e.label}</span>`:void 0)).join(""),document.querySelectorAll(".pcopy").forEach((e=>{e.hasAttribute("aria-copy")||(e.addEventListener("click",(()=>{const t=e.getAttribute("data").trim();!function(e){try{if(navigator.clipboard)return navigator.clipboard.writeText(e).then((()=>!0)).catch((e=>(w("Error copying to clipboard:",e),!1)));if(window.clipboardData&&window.clipboardData.setData)return window.clipboardData.setData("Text",e);if(!document.queryCommandSupported||!document.queryCommandSupported("copy"))return w("Copying to clipboard not supported."),!1;{const t=document.createElement("textarea");t.textContent=e,t.style.position="fixed",document.body.appendChild(t),t.select();try{return document.execCommand("copy")}catch(e){return w("Copy to clipboard failed.",e),!1}finally{document.body.removeChild(t)}}}catch(e){return w("Error copying to clipboard:",e),!1}}(t),w(`${t} Copied`)})),e.setAttribute("aria-copy",e.getAttribute("data")))})),document.querySelectorAll(".recheck").forEach((e=>{e.hasAttribute("aria-copy")||(e.addEventListener("click",(()=>{const t=e.getAttribute("data").trim();fetch(`./proxyCheckerParallel.php?proxy=${t}`).then((()=>w(`Re-check ${t} requested`))),i()})),e.setAttribute("aria-copy",e.getAttribute("data")))}))}}const f=[];let y=!1;function x(){if(!y){y=!0;const e=f.shift();fetch(e,{signal:AbortSignal.timeout(5e3)}).catch((()=>{b(e)})).finally((()=>{y=!1,f.length>0&&x()}))}}function b(e){f.includes(e)||f.push(e)}function w(...e){const t=document.getElementById("snackbar");t.textContent=e.map((e=>e instanceof Error?`Error: ${e.message}`:"string"!=typeof e?JSON.stringify(e):e)).join(" "),t.classList.add("show"),setTimeout((function(){t.classList.remove("show")}),3e3)}async function k(){const e=await async function(){return await fetch("./info.php").then((e=>e.json())).catch((()=>({})))}(),t=document.querySelector("input[name=endpoint]"),n=document.querySelector("textarea[name=headers]"),o=document.querySelector("input[name=http]"),a=document.querySelector("input[name=socks4]"),r=document.querySelector("input[name=socks5]");let c,i;Object.prototype.hasOwnProperty.call(e,"endpoint")&&(t.value=e.endpoint),Object.prototype.hasOwnProperty.call(e,"headers")&&(n.value=e.headers.join("\n")),Object.prototype.hasOwnProperty.call(e,"type")&&e.type.split("|").map((e=>{document.querySelector(`input[name=${e}]`).checked=!0}));const s=e=>{e.preventDefault(),clearTimeout(c),c=setTimeout(E,1e3)};document.getElementById("submit-config").addEventListener("click",s),[t,n,o,a,r].forEach((e=>{e.addEventListener("change",s)}));const l=e=>{e.preventDefault(),clearTimeout(i),i=setTimeout((()=>async function(e){const t=async function(e){const t=`//${location.host}/proxyAdd.php`;try{const n=await fetch(t,{signal:AbortSignal.timeout(5e3),method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:`proxies=${encodeURIComponent(e)}`});if(n.ok){w(await n.text())}else w("Network response was not ok")}catch(e){w("There was a problem with your fetch operation: "+e.message)}},n=e.trim().split(/\r?\n/).filter((e=>e.match(/(?!0)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:(?!0)\d{2,5}/gim))),o=1e3,a=[];for(let e=0;e<n.length;e+=o)a.push(n.slice(e,e+o));for(const e of a)await t(e.join("\n"))}(document.getElementById("add_proxies").value)),1e3)};document.getElementById("add_proxies").addEventListener("change",l),document.getElementById("submit-new-proxies").addEventListener("click",l)}function E(){let e=document.querySelector("[name=http]").checked?"http":"";e+=document.querySelector("[name=socks5]").checked?"|socks5":"",e+=document.querySelector("[name=socks4]").checked?"|socks4":"",fetch("./info.php",{signal:AbortSignal.timeout(5e3),method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:{headers:document.querySelector("[name=headers]").value.trim().split(/\r?\n/),endpoint:document.querySelector("[name=endpoint]").value.trim(),type:e.trim()}})}).then((e=>(e.ok||w("Modify config error: Network response was not ok"),e.json()))).then((e=>{w("Modify config success"),console.log("response",e)})).catch((e=>{w("Modify config",e)}))}async function S(){function e(e,n){return"function"!=typeof n&&(n=(...e)=>{console.log(...e)}),fetch(`//${t}/data/login.php`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:new URLSearchParams({"g-recaptcha-response":e}).toString()}).then((e=>e.json())).then((e=>{if(e.success){const e=document.getElementById("recaptcha");e&&e.remove()}return e})).then(n)}window.send_token=e,window.recaptcha_execute=e;try{const o=await fetch(`//${t}/info.php`),a=await o.json(),r=a["captcha-site-key"],c=document.createElement("div");c.classList.add("g-recaptcha"),c.setAttribute("data-sitekey",a["captcha-v2-site-key"]),c.setAttribute("data-callback","send_token"),c.setAttribute("data-action","submit"),document.getElementById("recaptcha").appendChild(c),await(n=1e3,new Promise((e=>setTimeout(e,n))));const i=document.createElement("script");i.src="https://www.google.com/recaptcha/api.js",document.body.appendChild(i);const s=document.createElement("script");s.src="https://www.google.com/recaptcha/api.js?render="+r,s.onload=function(){grecaptcha.ready((()=>{return t=r,void grecaptcha.execute(t,{action:"submit"}).then(e);var t}))},document.body.appendChild(s)}catch(e){const t="failed obtain captcha site key "+e.message,n=document.createElement("div");n.className="fixed top-4 right-4 bg-red-500 text-white p-4 rounded-lg shadow-lg z-50 alert";const o=document.createElement("span");o.textContent=t,n.appendChild(o),document.getElementById("recaptcha").appendChild(n)}var n}S(),async function(){if(e=await s(),!e)return console.log("user null"),void location.reload();document.getElementById("start-proxy-check").addEventListener("click",(e=>{e.preventDefault(),w("proxy checking start..."),o()})),document.getElementById("filter-ports").addEventListener("click",(e=>{e.preventDefault(),w("Filter open ports requested"),fetch("./filterPortsBackground.php",{signal:AbortSignal.timeout(5e3)}).catch((e=>w(e.message)))})),document.getElementById("respawn-proxies").addEventListener("click",(e=>{e.preventDefault(),w("Proxy respawner requested"),fetch("./proxyRespawner.php",{signal:AbortSignal.timeout(5e3)}).catch((e=>w(e.message)))})),d();let t=setInterval((()=>{d()}),3e3);const n=document.getElementById("autoCheckProxy");["dev.webmanajemen.com","localhost","127.0.0.1"].some((e=>new RegExp(e).test(location.host)))?n.addEventListener("change",(e=>{if(clearInterval(t),n.checked){const e=()=>d().then((e=>{e||o()}));e().then((()=>{t=setInterval(e,3e3)}))}else t=setInterval((()=>{d()}),3e3)})):document.getElementById("autoCheckProxy-wrapper").remove(),c(),setInterval((()=>{c()}),3e3),g(),setInterval((()=>{g()}),5e3)}().then((e=>{k().then((e=>{})).catch(console.error)})).catch(console.error)}();