- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
const express = require('express')
const app = express()
const port = 3000;
const bodyparser = require("body-parser")
const applications = 2341;
const https = require('https');
const util = require('util');
var sha1 = require("sha1");
const secret = '123афкуф';
const connection = require("./mysql")
var log4js = require("log4js");
var logger = log4js.getLogger();
function generatePassword(len){
if(len > 10) len = 10;
len = len * (-1);
return Math.random().toString(36).slice(len);
}
app.listen(port, () => {
logger.info(`VK Auth is started!`)
})
let net = require("net");
app.get('/', (req, res) => {
var code = req.query['code'];
var state = req.query['state'];
var computer = req.query['computer'];
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
res.sendFile(__dirname + "/index.html");
console.log(`https://oauth.vk.com/access_token?client_id=${applications}client_secret=${secret}&code=${code}&redirect_uri=http://31.25.243.145:3000/?computer=${computer}`)
https.get(`https://oauth.vk.com/access_token?client_id=${applications}&client_secret=${secret}&code=${code}&redirect_uri=http://31.25.243.145:3000/?computer=${computer}`, (res) =>
{
res.on("data", (data) => {
data = data.toString('utf8');
let obj = JSON.parse(data)
if(obj.error == undefined)
{ connection.query("SELECT idvk FROM whitelist WHERE idvk = ?", [obj.user_id] ,(err,result1) => {
if(err)
{
return logger.main.error(err)
}
if(result1.length === 0)
{
//socket.write("Auth|accessdenied")
}
else {
connection.query("SELECT AccessToken FROM users WHERE VK = ?",[obj.user_id],(err, result,row) => {
if (err) {
logger.main.error(err)
}
if (result.length === 0) {
connection.query("INSERT INTO users(ipaddress,profileid,hwid,AccessToken,RegTime,VK,nickname,token,Auth) VALUES (?,?,?,?,NOW(),?,?,?,?)",[ip.substr(7),0,computer,obj.access_token,obj.user_id,"",sha1(generatePassword(10)),1], (err,res) => {
if (err) {
return console.log(err);
}
console.log( ip.substr(7) + " успешно зарегистрирован!")
})
}
else {
// Обновляем access токен если аккаунт есть, но токен недействителен
connection.query("UPDATE users SET AccessToken = ?, Auth = ? WHERE VK = ?", [obj.access_token,1,obj.user_id], (err,res) => {
if(err) {
return logger.main.error(err);
}
console.log(ip.substr(7) + " : токен обновлен")
})
}
})
}
})
}
else {
//socket.write("ERRORAUTH")
}
})
})
})
app.use(bodyparser.urlencoded({extended: false}));
app.post('/', (req, res) => {
})
Авторизация ВКонтакте для лаунчера, вместо пыхи, решил использовать ноду)