configs │ │ configs.json // │ get.js │ index.js │ load.js │ parse-configs.js │ └───base // ovpn empty.file //
const body = ',,,3,4,6,8,9,6' const configs = parseConfigs(body) configs /* [{ "": 3, "": 4, "": 6 }, { "": 8, "": 9, "": 6 }] */
module.exports = body => body .replace(/[^#]+/, '') .replace(/#/, '') .replace(/\r\n/gi, ',') // .split(',') // .reduce((ctx, elem, index) => { if (index > 14) { // const key = ctx.name_tmp[ctx.config_name_index] ctx.config_tmp[key] = elem ctx.config_name_index++ if (ctx.config_name_index > 14) { ctx.configs.push(ctx.config_tmp) ctx.config_tmp = {} ctx.config_name_index = 0 } } else { // 14 : ping, , etc ctx.name_tmp.push(elem) } return ctx }, { name_tmp: [], config_name_index: 0, config_tmp: {}, configs: [] }).configs
const request = require('request') , fs = require('fs') , Base64 = require(`js-base64`).Base64 , parseConfigs = require('./parse-configs') module.exports = () => new Promise((resolve, reject) => { request(`http://130.158.6.57/api/iphone/`, (err, res, body) => { if (err || res.statusCode != 200) { return reject() } const configs = parseConfigs(body).map(config => { // base64, const decode_config = Base64.decode(config.OpenVPN_ConfigData_Base64) .replace(/dev tun/g, `dev tap`) , path = `${__dirname}/base/${config.HostName}.ovpn` fs.writeFileSync(path, decode_config) delete config.OpenVPN_ConfigData_Base64 config.path = path return config }) fs.writeFileSync(`${__dirname}/configs.json`, JSON.stringify(configs)) // resolve(configs.length) }) })
const fs = require('fs') , Base64 = require(`js-base64`).Base64 module.exports = ({ CountryLong = '-' , Ping = '-' , NumVpnSessions = '-' , Score = '-' , Speed = '-' , Uptime = '-' , TotalUsers = '-' , TotalTraffic = '-' }) => { try { // const configs = fs.readFileSync(`${__dirname}/configs.json`, { encoding: 'utf8' }) // , // , // return JSON.parse(configs) .filter(conf => (conf.CountryLong == CountryLong || CountryLong == '-') && (parseInt(conf.Ping) < parseInt(Ping) || Ping == '-') && (parseInt(conf.NumVpnSessions) > parseInt(NumVpnSessions) || NumVpnSessions == '-') && (parseInt(conf.Score) > parseInt(Score) || Score == '-') && (parseInt(conf.Speed) > parseInt(Speed) || Speed == '-') && (parseInt(conf.Uptime) > parseInt(Uptime) || Uptime == '-') && (parseInt(conf.TotalUsers) > parseInt(TotalUsers) || TotalUsers == '-') && (parseInt(conf.TotalTraffic) > parseInt(TotalTraffic) || TotalTraffic == '-') ) } catch (e) { return [] } }
module.exports = { load: require('./load'), get: require('./get') }
const Configs = require('./../../app/components/configs') Configs.load().then(length => { console.log(` : ${length}`) const search = Configs.get({ CountryLong: 'Japan' , Ping: 22 // 1-22 ms , NumVpnSessions: '-' // empty , Score: '-' // empty , Speed: 13311 // bit , Uptime: 3600000 // ms , TotalUsers: '-' // empty , TotalTraffic: '-' // empty }) console.log(` : ${search.length}`) }, () => { console.log(` `) })
Key | Type of | Description |
---|---|---|
Countrylong | String | Country VPN server |
Ping | Number | Information delivery time (in milliseconds) |
NumVpnSessions | Number | Active sessions |
Score | Number | Quality of connection |
Speed | Number | Connection speed (in bytes) |
Uptime | Number | Server uptime (in milliseconds) |
Totalusers | Number | Total connections while running |
TotalTraffic | Number | Total traffic on the server during operation (in bytes) |
Source: https://habr.com/ru/post/429432/
All Articles