Commit 2b89d2b4 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parents
Pipeline #48 canceled with stages
const {Client} = require('pg')
let _ = require('lodash')
const fs = require('fs');
const shellExec = require('shell-exec')
const cron = require('node-cron');
let moment = require('moment-timezone')
const connectionString = 'postgresql://ibs:secretpassword@51.91.150.227:5432/IBSng'
const client = new Client({
connectionString: connectionString,
})
let arr = []
async function refresh() {
await client.connect()
let res = await client.query('select * from users As u,normal_users As n,user_attrs AS att where u.user_id=n.user_id and att.user_id=u.user_id and group_id=1')
for (let i = 0; i < res.rows.length; i++) {
arr.push(res.rows[i].normal_username + ' : EAP ' + '"' + res.rows[i].normal_password + '"')
}
res = await client.query('select * from users As u,normal_users As n where u.user_id=n.user_id and group_id=2 and not EXISTS (select user_id from user_attrs As att where att.user_id=u.user_id)')
for (let i = 0; i < res.rows.length; i++) {
arr.push(res.rows[i].normal_username + ' : EAP ' + '"' + res.rows[i].normal_password + '"')
}
res = await client.query('select * from users As u,normal_users As n,user_attrs AS att where u.user_id=n.user_id and att.user_id=u.user_id and group_id=2 ')
for (let i = 0; i < res.rows.length; i++) {
if (res.rows[i].attr_name !== 'first_login')
continue
if (canAdd(res.rows[i].attr_value))
arr.push(res.rows[i].normal_username + ' : EAP ' + '"' + res.rows[i].normal_password + '"')
}
arr = _.uniq(arr);
let last = '78.47.222.24.sslip.io : RSA "privkey.pem"' + '\n'
for (let i = 0; i < arr.length; i++)
last += arr[i] + '\n'
await createfile(last)
await execLast()
console.log(last)
await client.end()
}
cron.schedule(' */30 * * * * *', () => {
return refresh()
});
function createfile(data) {
return new Promise(function (resolve, reject) {
fs.writeFile('/etc/ipsec.secrets', data, 'utf8', function (err) {
if (err) reject(err);
else resolve(data);
});
});
}
async function execLast() {
let d = await shellExec('ipsec secrets')
return true
}
function canAdd(end) {
end = moment.unix(end).utc()
//2019-05-25T05:34:27+04:30
var now = moment(moment().tz('Asia/Tehran').format());
end = moment.duration(now.diff(moment(end).tz('Asia/Tehran')));
let curent = parseInt(end.asMinutes())
let base = 129600
return curent < base;
}
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const sequelize = new Sequelize('IBSng', 'ibs', '', {
define: {
charset: 'utf8',
collate: 'utf8_general_ci'
},
host: '116.202.13.132' ,
dialect: 'postgres',
logging: false,
});
async function getAllUser() {
let q = ` select * from normal_users where user_id=1517`
let data = await sequelize.query(
q,
{type: sequelize.QueryTypes.SELECT}
)
return data
}
module.exports =
{
getAllUser: getAllUser
}
{
"name": "ikve2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.15",
"moment-timezone": "^0.5.27",
"node-telegram-bot-api": "^0.40.0",
"pg": "^7.18.1",
"pg-hstore": "^2.3.3",
"sequelize": "^5.21.4",
"shell-exec": "^1.0.2",
"node-cron": "^2.0.3"
}
}
{
"apps": [
{
"name": "app",
"script": "./app.js",
"merge_logs": true,
"log_date_format": "HH:mm"
},
{
"name": "socket",
"script": "./socket.js",
"merge_logs": true,
"log_date_format": "HH:mm"
}
]
}
let moment = require('moment-timezone')
console.log('"salam"')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment