import android.content.Context;\r
import android.util.Log;\r
import android.os.AsyncTask;\r
+import android.widget.TextView;\r
\r
import com.jcraft.jsch.JSch;\r
import com.jcraft.jsch.JSchException;\r
// in this project, we supposed we use fixed host, username, password\r
private String host;\r
private String username;\r
- private String password;\r
+ public String password;\r
+ private List<String> result_lines = new ArrayList<String>();\r
\r
// host, username, password initialize\r
@Override\r
protected void onPreExecute() {\r
super.onPreExecute();\r
-\r
host = ConfigActivity.ROUTERIP;\r
username = ConfigActivity.ROUTERUSER;\r
password = ConfigActivity.RPWD;\r
+\r
+\r
+\r
+\r
+ }\r
+\r
+ public void updatePassword(String newPass){\r
+ password = newPass;\r
}\r
\r
/* \r
}\r
}\r
\r
- // send a command\r
+ // send a command 1523610518\r
public void runCommand(String command) throws JSchException, IOException {\r
\r
if (!session.isConnected())\r
// get output from a command\r
private List<String> getChannelOutput(Channel channel) throws IOException {\r
\r
- byte[] buffer = new byte[1024];\r
+ byte[] buffer = new byte[2048];\r
List<String> output_lines = new ArrayList<String>();\r
try {\r
InputStream in = channel.getInputStream();\r
String line = new String();\r
while (true) {\r
while (in.available() > 0) {\r
- int i = in.read(buffer, 0, 1024);\r
+ int i = in.read(buffer, 0, 2048);\r
if (i < 0) {\r
break;\r
}\r
@Override\r
protected List<String> doInBackground(String... params) {\r
\r
- List<String> result_lines = new ArrayList<String>();\r
+ List<String> output = new ArrayList<String>();\r
String cmd;\r
\r
if(params[0].substring(0,3).equals("-ch")) { // ./change_default_pw.sh -ch <password>\r
return null;\r
}\r
cmd = MainActivity.DEF_REGISTER_DEVICE_SCRIPT + " " + params[0];\r
+ System.out.println(cmd);\r
runCommand(cmd);\r
ce.setCommand(cmd);\r
ce.connect();\r
result_lines = getChannelOutput(ce);\r
+ //output = getChannelOutput(ce);\r
} catch (Exception e) {\r
}\r
channel.disconnect();\r
\r
// only this block return meaningful value, which should be the names of devices.\r
- return result_lines;\r
- } else {\r
+ return output;\r
+ } else if(params[0].substring(0,3).equals("cat")) {\r
+ cmd = params[0];\r
+ }\r
+ else if(params[0].substring(0,4).equals("echo")) {\r
+ cmd = params[0];\r
+ }\r
+ else {\r
Log.d("SSH PARAM ERROR", "Wrong parameter used.");\r
return null;\r
}\r
Log.d("SSH CONNECTION CLOSE", "open failed.");\r
return null;\r
}\r
+ System.out.println(cmd);\r
runCommand(cmd);\r
ce.setCommand(cmd);\r
ce.connect();\r
+ result_lines = getChannelOutput(ce);\r
} catch (Exception e) {\r
} // done\r
\r
return null;\r
}\r
\r
+ public List<String> getResultLines() {\r
+ return result_lines;\r
+ }\r
+\r
/*\r
@Override\r
protected onPostExecute(Void param) {\r