<commit_before>#!/usr/bin/node
const fs = require('fs');
const { spawn, spawnSync } = require('child_process');

const supervisor = spawn('/usr/bin/supervisord', ['--nodaemon']);
let nginx_available = false;
supervisor.stdout.on('data', (data) => {
  console.log(data.toString());
  const i = data.indexOf('nginx entered RUNNING state')
  if (i >= 0) {
    console.log('***** can request cert by nginx now *****');
    nginx_available = true;
  }
});
supervisor.on('close', (code) => {
  console.log(`supervisord exited with code ${code}`);
});
// fs.watch('/etc/nginx/conf.d', (eventType, filename) => {
//   console.log(`event type is: ${eventType}`);
//   if (filename) {
//     console.log(`filename provided: ${filename}`);
//   } else {
//     console.log('filename not provided');
//   }
//   const nginx_cfg = spawn('service', ['nginx', 'reload']);
// });
// need place into supervisord?
let ret = spawnSync('vpnserver', ['start']);
for (let j = 0; j < process.argv.length; j++) {
  console.log(j + ' -> ' + (process.argv[j]));
}
// first two are node and script name
const paras = process.argv.slice(2)
if (paras.length == 0) {
  return console.log('please input domain name for fully functional !!!')
}
const domain = paras[0];
const user = paras[1] || 'freego';
const pass = paras[2] || "<PASSWORD>";
const key = paras[3] || "freego2018";
const email = paras[4] || `${user}@${domain}`;
if (!fs.existsSync(`/etc/letsencrypt/live/${domain}`)) {
  // letsencrypt certonly --standalone --agree-tos --preferred-challenges http-01 --email $em -d $dn
  // ret = spawnSync('letsencrypt', ['certonly', '--standalone', '--agree-tos', '--email', email, '-d', domain]);
  (function req_cert(){
    if(nginx_available){
      ret = spawnSync('/script/reqcert.js', [domain, email]);
      const std_out = ret.stdout.toString();
      const std_err = ret.stderr.toString();
      if (std_out.indexOf('Congratulations!') < 0) {
        console.log('request certificate failed')
        console.log(std_out)
        console.log(std_err)
        return;
      }
      console.log(std_out)
      start_service()
    } else {
      setTimeout(req_cert, 100)
      console.log('wait for nginx ready...')
    }
  })()
} else {
  ret = spawnSync('letsencrypt', ['renew']);
  console.log(ret.stdout.toString())
  start_service()
}
function start_service() {
  const cert = `/etc/letsencrypt/live/${domain}/fullchain.pem`;
  const privkey = `/etc/letsencrypt/live/${domain}/privkey.pem`;

  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/CMD', 'ServerPasswordSet', '<PASSWORD>']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/CMD', 'ListenerDelete', '443']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/adminhub:DEFAULT', '/CMD', 'SecureNatEnable']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/adminhub:DEFAULT',
    '/CMD', 'UserCreate', user, '/GROUP:none', '/REALNAME:none', '/NOTE:none']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/adminhub:DEFAULT',
    '/CMD', 'UserPasswordSet', user, `/PASSWORD:${pass}`, '/REALNAME:none', '/NOTE:none']);<commit_msg>tesging<commit_after>#!/usr/bin/node
const fs = require('fs');
const { spawn, spawnSync } = require('child_process');

const supervisor = spawn('/usr/bin/supervisord', ['--nodaemon']);
let nginx_available = false;
supervisor.stdout.on('data', (data) => {
  console.log(data.toString());
  const i = data.indexOf('nginx entered RUNNING state')
  if (i >= 0) {
    console.log('***** can request cert by nginx now *****');
    nginx_available = true;
  }
});
supervisor.on('close', (code) => {
  console.log(`supervisord exited with code ${code}`);
});
// fs.watch('/etc/nginx/conf.d', (eventType, filename) => {
//   console.log(`event type is: ${eventType}`);
//   if (filename) {
//     console.log(`filename provided: ${filename}`);
//   } else {
//     console.log('filename not provided');
//   }
//   const nginx_cfg = spawn('service', ['nginx', 'reload']);
// });
// need place into supervisord?

for (let j = 0; j < process.argv.length; j++) {
  console.log(j + ' -> ' + (process.argv[j]));
}
// first two are node and script name
const paras = process.argv.slice(2)
if (paras.length == 0) {
  return console.log('please input domain name for fully functional !!!')
}
const domain = paras[0];
const user = paras[1] || 'freego';
const pass = paras[2] || "<PASSWORD>";
const key = paras[3] || "freego2018";
const email = paras[4] || `${user}@${domain}`;
if (!fs.existsSync(`/etc/letsencrypt/live/${domain}`)) {
  // letsencrypt certonly --standalone --agree-tos --preferred-challenges http-01 --email $em -d $dn
  // let ret = spawnSync('letsencrypt', ['certonly', '--standalone', '--agree-tos', '--email', email, '-d', domain]);
  (function req_cert(){
    if(nginx_available){
      const ret = spawnSync('/script/reqcert.js', [domain, email]);
      const std_out = ret.stdout.toString();
      const std_err = ret.stderr.toString();
      if (std_out.indexOf('Congratulations!') < 0) {
        console.log('request certificate failed')
        console.log(std_out)
        console.log(std_err)
        return;
      }
      console.log(std_out)
      start_service()
    } else {
      setTimeout(req_cert, 100)
      console.log('wait for nginx ready...')
    }
  })()
} else {
  const ret = spawnSync('letsencrypt', ['renew']);
  console.log(ret.stdout.toString())
  start_service()
}
function start_service() {
  const cert = `/etc/letsencrypt/live/${domain}/fullchain.pem`;
  const privkey = `/etc/letsencrypt/live/${domain}/privkey.pem`;
  let ret = spawnSync('vpnserver', ['start'])
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/CMD', 'ServerPasswordSet', '<PASSWORD>']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/CMD', 'ListenerDelete', '443']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/adminhub:DEFAULT', '/CMD', 'SecureNatEnable']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/adminhub:DEFAULT',
    '/CMD', 'UserCreate', user, '/GROUP:none', '/REALNAME:none', '/NOTE:none']);
  ret = spawnSync('vpncmd', ['localhost:992', '/SERVER', '/PASSWORD:<PASSWORD>', '/adminhub:DEFAULT',
    '/CMD', 'UserPasswordSet', user, `/PASSWORD:${pass}`, '/REALNAME:none', '/NOTE:none']);
{'fraction_non_alphanumeric': 0.21802641802641803, 'fraction_numerical': 0.0114996114996115, 'mean_word_length': 4.051805337519623, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2679694', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2150, 'n_words': 470}