// Path: app/src/main/java/it/skarafaz/mercury/model/event/SshCommandEnd.java
// public class SshCommandEnd {
//     private SshCommandStatus status;
// 
//     public SshCommandEnd(SshCommandStatus status) {
//         this.status = status;
//     }
// 
//     public SshCommandStatus getStatus() {
//         return status;
//     }
// }
// 
// Path: app/src/main/java/it/skarafaz/mercury/model/event/SshCommandStart.java
// public class SshCommandStart {
// }


import com.jcraft.jsch.*;
import it.skarafaz.mercury.model.event.SshCommandEnd;
import it.skarafaz.mercury.model.event.SshCommandStart;
import org.greenrobot.eventbus.EventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/*
 * Mercury-SSH
 * Copyright (C) 2019 Skarafaz
 *
 * This file is part of Mercury-SSH.
 *
 * Mercury-SSH is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Mercury-SSH is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Mercury-SSH.  If not, see <http://www.gnu.org/licenses/>.
 */

package it.skarafaz.mercury.ssh;



public abstract class SshCommand extends Thread {
    protected static final int TIMEOUT = 30000;
    private static final Logger logger = LoggerFactory.getLogger(SshCommand.class);
    protected JSch jsch;
    protected Session session;
    protected String host;
    protected Integer port;
    protected String user;
    protected String password;
    protected Boolean sudoNoPasswd;
    protected String shellPath;
    protected String sudoPath;
    protected String nohupPath;
    protected Boolean sudo;
    protected String cmd;
    protected Boolean confirm;

    public SshCommand() {
        this.jsch = new JSch();
    }

    @Override
    public void run() {
        if(beforeExecute()) {
            SshCommandStatus status = execute();
            afterExecute(status);
        }
    }

    protected boolean beforeExecute() {
// Path: app/src/main/java/it/skarafaz/mercury/model/event/SshCommandEnd.java
// public class SshCommandEnd {
//     private SshCommandStatus status;
// 
//     public SshCommandEnd(SshCommandStatus status) {
//         this.status = status;
//     }
// 
//     public SshCommandStatus getStatus() {
//         return status;
//     }
// }
// 
// Path: app/src/main/java/it/skarafaz/mercury/model/event/SshCommandStart.java
// public class SshCommandStart {
// }


// Path: app/src/main/java/it/skarafaz/mercury/ssh/SshCommand.java
import com.jcraft.jsch.*;
import it.skarafaz.mercury.model.event.SshCommandEnd;
import it.skarafaz.mercury.model.event.SshCommandStart;
import org.greenrobot.eventbus.EventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/*
 * Mercury-SSH
 * Copyright (C) 2019 Skarafaz
 *
 * This file is part of Mercury-SSH.
 *
 * Mercury-SSH is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Mercury-SSH is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Mercury-SSH.  If not, see <http://www.gnu.org/licenses/>.
 */

package it.skarafaz.mercury.ssh;



public abstract class SshCommand extends Thread {
    protected static final int TIMEOUT = 30000;
    private static final Logger logger = LoggerFactory.getLogger(SshCommand.class);
    protected JSch jsch;
    protected Session session;
    protected String host;
    protected Integer port;
    protected String user;
    protected String password;
    protected Boolean sudoNoPasswd;
    protected String shellPath;
    protected String sudoPath;
    protected String nohupPath;
    protected Boolean sudo;
    protected String cmd;
    protected Boolean confirm;

    public SshCommand() {
        this.jsch = new JSch();
    }

    @Override
    public void run() {
        if(beforeExecute()) {
            SshCommandStatus status = execute();
            afterExecute(status);
        }
    }

    protected boolean beforeExecute() {
        EventBus.getDefault().postSticky(new SshCommandStart());