const { Client } = require('ssh2');
const fs = require('fs');
const conn = new Client();

function exec(conn, cmd) {
  return new Promise((resolve, reject) => {
    conn.exec(cmd, (err, stream) => {
      if (err) return reject(err);
      let out = '', err2 = '';
      stream.on('data', d => out += d);
      stream.stderr.on('data', d => err2 += d);
      stream.on('close', () => resolve({ out: out.trim(), err: err2.trim() }));
    });
  });
}

conn.on('ready', async () => {
  console.log('✅ Connected\n');

  // Читаем текущий nginx конфиг для openclaw
  const conf = await exec(conn, 'cat /etc/nginx/sites-enabled/openclaw.mva154.duckdns.org');
  console.log('=== CURRENT NGINX CONF ===');
  console.log(conf.out);

  // Читаем app.py чтобы понять структуру
  const apppy = await exec(conn, 'head -50 /home/slin/enduro-trails/prototype/app.py');
  console.log('\n=== APP.PY HEAD ===');
  console.log(apppy.out);

  conn.end();
});
conn.on('error', err => { console.error('❌', err.message); process.exit(1); });
conn.connect({ host: '82.22.50.71', username: 'slin', password: 'motoZ@yaz2010', readyTimeout: 15000 });
