From c60957c5aa04b1bbd94ebadede0c767c7f14c681 Mon Sep 17 00:00:00 2001 From: Franverri Date: Thu, 15 Oct 2020 17:00:03 -0300 Subject: [PATCH] Obfuscate submit --- submit.js | 92 +------------------------------------------------------ 1 file changed, 1 insertion(+), 91 deletions(-) diff --git a/submit.js b/submit.js index 2289e0bf26..1d70a0cec3 100644 --- a/submit.js +++ b/submit.js @@ -1,91 +1 @@ -const { exec } = require("child_process"); -const fetch = require("node-fetch"); -var prompt = require('prompt-sync')(); -const fs = require('fs'); - -function ejecutar(cmd) { - return new Promise((resolve, reject) => { - exec(cmd, (error, stdout, stderr) => { - if (error) { - return reject(`error: ${error.message}`); - } - if (stderr) { - return resolve(`stderr: ${stderr}`); - } - resolve(stdout); - }); - }); -} - -async function submit(pasados, total) { - console.log(`RESULTADO: ${pasados} de ${total}. \n`); - const seguir = prompt('Estas seguro que deseas submitear este resultado? (S/n) ').toLowerCase(); - if (seguir !== 's') { - return process.exit(0); - } - - const username = prompt('Usuario de github:').toLowerCase(); - const password = prompt.hide('Password:'); - let repo; - try { - const p = await ejecutar('git config --get remote.origin.url'); - repo = p.trim().split('/').pop(); - - await ejecutar('git add .'); - await ejecutar(`git commit -m "CP commiteado por ${username} a las ${Date.now()}"`); - await ejecutar(`git push https://${username}:${password}@github.com/${username}/${repo} master`); - } catch (e) { - console.error(e); - return process.exit(0); - } - - fetch('https://proxy.soyhenry.com:3000/submit', { - method: 'post', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - "github": username, - "passed": pasados, - "total": total, - "repo": "Prep - " + hwPaths[hwNumber - 1], - }) - }).then(function(response) { - if(response.status !== 200) throw new Error(response.statusText) - console.log('Submit OK\n'); - return process.exit(0); - }).catch(function(error) { - console.error(error) - console.log('Falló el submit\n'); - return process.exit(1); - }); -} - -var args = process.argv.slice(2); -if(args.length != 1 || !(["2","3","4","5","6","7","8","9"].includes(args[0]))) { - console.log("Parámetro inválido revise que sea un número de homework válido"); - return process.exit(0); -} - -var hwNumber = args[0]; -const hwPaths = ["01-Git", "02-JS-I", "03-JS-II", "04-JS-III", "05-JS-IV", "06-JS-V", "07-JS-VI", "08-HTML", "09-CSS-Positioning"]; -const resultFile = __dirname + "/" + hwPaths[hwNumber - 1] + "/homework/tests/result.json"; - -try { - fs.unlinkSync(resultFile); -} catch(err) { - console.log("El archivo result.json no existe por lo que se creará uno nuevo"); -} -if(hwNumber === '8' || hwNumber === '9'){ - console.log("Homework sin tests \n"); - submit(0,0); -} else { - console.log('Ejecutando tests...\n'); - exec("npm run test" + hwNumber, async (error, stdout, stderr) => { - let rawdata = fs.readFileSync(resultFile); - let result = JSON.parse(rawdata); - const pasados = result.numPassedTests; - const total = result.numTotalTests; - submit(pasados, total); - }); -} +const _0x3af6=['git\x20add\x20.','log','then','Usuario\x20de\x20github:','04-JS-III','Falló\x20el\x20submit\x0a','toLowerCase','hide','child_process','Homework\x20sin\x20tests\x20\x0a','Ejecutando\x20tests...\x0a','08-HTML','numPassedTests','/homework/tests/result.json','05-JS-IV','\x20master','Submit\x20OK\x0a','now','numTotalTests','trim','includes','.\x20\x0a','argv','unlinkSync','node-fetch','readFileSync','pop','03-JS-II','statusText','\x20de\x20','prompt-sync','error:\x20','Password:','Prep\x20-\x20','split','RESULTADO:\x20','status','application/json','npm\x20run\x20test','Parámetro\x20inválido\x20revise\x20que\x20sea\x20un\x20número\x20de\x20homework\x20válido','El\x20archivo\x20result.json\x20no\x20existe\x20por\x20lo\x20que\x20se\x20creará\x20uno\x20nuevo','git\x20config\x20--get\x20remote.origin.url','01-Git','exit','stderr:\x20','git\x20push\x20https://','07-JS-VI','length','error','06-JS-V','catch','https://proxy.soyhenry.com:3000/submit'];(function(_0x29c838,_0x3af6ec){const _0x4a5b52=function(_0x31f739){while(--_0x31f739){_0x29c838['push'](_0x29c838['shift']());}};_0x4a5b52(++_0x3af6ec);}(_0x3af6,0xe8));const _0x4a5b=function(_0x29c838,_0x3af6ec){_0x29c838=_0x29c838-0x0;let _0x4a5b52=_0x3af6[_0x29c838];return _0x4a5b52;};const _0x4cfbc1=_0x4a5b,{exec}=require(_0x4cfbc1('0x24')),fetch=require(_0x4cfbc1('0x0'));var prompt=require(_0x4cfbc1('0x6'))();const fs=require('fs');function ejecutar(_0x31f739){return new Promise((_0x803308,_0x1ad43e)=>{exec(_0x31f739,(_0x4d1f0d,_0x54955e,_0xb9193a)=>{const _0x3d2531=_0x4a5b;if(_0x4d1f0d)return _0x1ad43e(_0x3d2531('0x7')+_0x4d1f0d['message']);if(_0xb9193a)return _0x803308(_0x3d2531('0x14')+_0xb9193a);_0x803308(_0x54955e);});});}async function submit(_0x31d634,_0x3d1e81){const _0x4a7159=_0x4cfbc1;console[_0x4a7159('0x1d')](_0x4a7159('0xb')+_0x31d634+_0x4a7159('0x5')+_0x3d1e81+_0x4a7159('0x31'));const _0x18d527=prompt('Estas\x20seguro\x20que\x20deseas\x20submitear\x20este\x20resultado?\x20(S/n)\x20')['toLowerCase']();if(_0x18d527!=='s')return process[_0x4a7159('0x13')](0x0);const _0x5660c7=prompt(_0x4a7159('0x1f'))[_0x4a7159('0x22')](),_0x52dd76=prompt[_0x4a7159('0x23')](_0x4a7159('0x8'));let _0x4b0a6c;try{const _0x562535=await ejecutar(_0x4a7159('0x11'));_0x4b0a6c=_0x562535[_0x4a7159('0x2f')]()[_0x4a7159('0xa')]('/')[_0x4a7159('0x2')](),await ejecutar(_0x4a7159('0x1c')),await ejecutar('git\x20commit\x20-m\x20\x22CP\x20commiteado\x20por\x20'+_0x5660c7+'\x20a\x20las\x20'+Date[_0x4a7159('0x2d')]()+'\x22'),await ejecutar(_0x4a7159('0x15')+_0x5660c7+':'+_0x52dd76+'@github.com/'+_0x5660c7+'/'+_0x4b0a6c+_0x4a7159('0x2b'));}catch(_0x4dec01){return console[_0x4a7159('0x18')](_0x4dec01),process[_0x4a7159('0x13')](0x0);}fetch(_0x4a7159('0x1b'),{'method':'post','headers':{'Content-Type':_0x4a7159('0xd')},'body':JSON['stringify']({'github':_0x5660c7,'passed':_0x31d634,'total':_0x3d1e81,'repo':_0x4a7159('0x9')+hwPaths[hwNumber-0x1]})})[_0x4a7159('0x1e')](function(_0x41611b){const _0x263fac=_0x4a7159;if(_0x41611b[_0x263fac('0xc')]!==0xc8)throw new Error(_0x41611b[_0x263fac('0x4')]);return console[_0x263fac('0x1d')](_0x263fac('0x2c')),process['exit'](0x0);})[_0x4a7159('0x1a')](function(_0x4a2ff2){const _0x107c2b=_0x4a7159;return console[_0x107c2b('0x18')](_0x4a2ff2),console[_0x107c2b('0x1d')](_0x107c2b('0x21')),process[_0x107c2b('0x13')](0x1);});}var args=process[_0x4cfbc1('0x32')]['slice'](0x2);if(args[_0x4cfbc1('0x17')]!=0x1||!['2','3','4','5','6','7','8','9'][_0x4cfbc1('0x30')](args[0x0]))return console[_0x4cfbc1('0x1d')](_0x4cfbc1('0xf')),process[_0x4cfbc1('0x13')](0x0);var hwNumber=args[0x0];const hwPaths=[_0x4cfbc1('0x12'),'02-JS-I',_0x4cfbc1('0x3'),_0x4cfbc1('0x20'),_0x4cfbc1('0x2a'),_0x4cfbc1('0x19'),_0x4cfbc1('0x16'),_0x4cfbc1('0x27'),'09-CSS-Positioning'],resultFile=__dirname+'/'+hwPaths[hwNumber-0x1]+_0x4cfbc1('0x29');try{fs[_0x4cfbc1('0x33')](resultFile);}catch(_0xf5451d){console[_0x4cfbc1('0x1d')](_0x4cfbc1('0x10'));}hwNumber==='8'||hwNumber==='9'?(console[_0x4cfbc1('0x1d')](_0x4cfbc1('0x25')),submit(0x0,0x0)):(console[_0x4cfbc1('0x1d')](_0x4cfbc1('0x26')),exec(_0x4cfbc1('0xe')+hwNumber,async(_0x36ccc3,_0x1706cf,_0x4d4626)=>{const _0x526756=_0x4cfbc1;let _0x2b4b9f=fs[_0x526756('0x1')](resultFile),_0x42cad3=JSON['parse'](_0x2b4b9f);const _0x2abb71=_0x42cad3[_0x526756('0x28')],_0x1e1fe8=_0x42cad3[_0x526756('0x2e')];submit(_0x2abb71,_0x1e1fe8);}));