Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
security improvements; export lol accounts for ori migration
Browse files Browse the repository at this point in the history
  • Loading branch information
dvtate committed Dec 20, 2023
1 parent cd22bbe commit e34ac8e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions user_export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require('fs');
const Teemo = require('teemojs');
const teemo = new Teemo(`${fs.readFileSync(`${process.env.HOME}/.corki/riot_key`)}`.trim());

const lolAcctsToGet = [];

fs.readdirSync(`${process.env.HOME}/.corki/users`).forEach(discUid => {
let json;
try {
json = fs.readFileSync(`${process.env.HOME}/.corki/users/${discUid}/lol.json`).toString();
} catch(e) {
console.error('no lol.json for user id ' + discUid );
return;
}
let o;
try {
o = JSON.parse(json);
} catch (e) {
console.error('invalid json for user id ' + discUid + ': "' + json + '"');
process.exit(1);
}
o.accounts.forEach(a => { a.discordUserId = discUid; });
lolAcctsToGet.push(...o.accounts);
});

const regions = ['BR1','EUN1','EUW1','JP1','KR','LA1','LA2','OC1','PH2','RU','SG2','TH2','TR1','TW2','VN2'];

console.log('fetching data for %d lol accounts', lolAcctsToGet.length,'...');
Promise.all(lolAcctsToGet.map(async a => {
const r = await teemo.get(a.server, 'summoner.getByPUUID', a.puuid);
const rn = await teemo.get(a.server, 'summoner.getBySummonerName', r.name);
if (rn.puuid === r.puuid)
return [a.discordUserId, a.server, r.name];
console.log('region change');
// They changed regions
for (const s of regions) {
if (s == a.server)
continue;
const rn = await teemo.get(s, 'summoner.getBySummonerName', r.name);
if (rn.puuid === r.puuid)
return [a.discordUserId, s, r.name];
}
console.log("couldn't find account:", a);
return null; // account must be deleted or sth...
})).then(l => {
l = l.filter(Boolean);
console.log(l);
fs.writeFileSync('lol_accounts_list.json', JSON.stringify(l));
});
10 changes: 10 additions & 0 deletions web/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ app.use((err, req, res, next) =>
error: err.message,
})
);
const querystring = require('querystring');
app.use((req, res, next) => {
if (req.path === "/") return next();
const bodyString = JSON.stringify(req.body) || '';
const qs = querystring.stringify(req.query);
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress || req.ip;
console.log('corki:web', `${req.method} ${req.path}${qs ? '?' + qs : ''} body=${bodyString.length > 2 ? bodyString.length.toString() + " bytes" : "∅"} (${ip})`);
next();
});


app.use("/resources", express.static(path.join(__dirname, "resources")));
app.use('/', require("./pages/home")); // /
Expand Down

0 comments on commit e34ac8e

Please sign in to comment.