Guest User

Untitled

a guest
Feb 6th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 KB | None | 0 0
  1. echo 'value of a variable string named cmd' | xclip -selection clipboard
  2.  
  3. String a="echo '";
  4. String c="' | xclip -selection clipboard";
  5. String cmd=a+clip+b;
  6. channelSsh.setCommand(cmd);
  7.  
  8. package com.quickclip.panky.quickclip;
  9.  
  10. import android.app.Activity;
  11. import android.content.ClipData;
  12. import android.content.ClipboardManager;
  13. import android.content.Context;
  14. import android.os.AsyncTask;
  15. import android.support.v7.app.AppCompatActivity;
  16. import android.os.Bundle;
  17. import android.view.View;
  18. import android.view.WindowManager;
  19. import android.widget.Button;
  20. import android.widget.EditText;
  21. import android.widget.TextView;
  22.  
  23. import com.jcraft.jsch.ChannelExec;
  24. import com.jcraft.jsch.JSch;
  25. import com.jcraft.jsch.Session;
  26.  
  27. import java.io.ByteArrayOutputStream;
  28. import java.util.Properties;
  29.  
  30. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  31.  
  32. EditText e1;
  33. Button b1,b2,b3;
  34. TextView t1,t2;
  35. Activity activity = this;
  36. static int flag=2,time=3000;
  37. static ClipData clip=null;
  38. String output;
  39.  
  40. @Override
  41. protected void onCreate(Bundle savedInstanceState) {
  42. super.onCreate(savedInstanceState);
  43. setContentView(R.layout.activity_main);
  44.  
  45. e1 = (EditText) findViewById(R.id.editText);
  46. t1 = (TextView) findViewById(R.id.textView);
  47. t2 = (TextView) findViewById(R.id.textView3);
  48. b1 = (Button) findViewById(R.id.button1);
  49. b2 = (Button) findViewById(R.id.button2);
  50. b3 = (Button) findViewById(R.id.button3);
  51.  
  52. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
  53.  
  54. b1.setOnClickListener(new View.OnClickListener() {
  55. @Override
  56. public void onClick(View view) {
  57. CopyMethod();
  58. }
  59. });
  60.  
  61. b2.setOnClickListener(new View.OnClickListener() {
  62. @Override
  63. public void onClick(View view) {
  64. VolDown();
  65. }
  66. });
  67.  
  68. b3.setOnClickListener(new View.OnClickListener() {
  69. @Override
  70. public void onClick(View view) {
  71. CopyPace();
  72. }
  73. });
  74.  
  75. Runnable myRunnable = new Runnable() {
  76. @Override
  77. public void run() {
  78. while (true) {
  79. if (flag % 2 == 0) {
  80. try {
  81. Thread.sleep(time);
  82. } catch (InterruptedException e) {
  83. e.printStackTrace();
  84. }
  85. } else if (flag % 2 != 0) {
  86. try {
  87. Thread.sleep(800);
  88. } catch (InterruptedException e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. activity.runOnUiThread(new Runnable() {
  93. public void run() {
  94. CopyMethod();
  95. flag += 1;
  96. }
  97. });
  98. }
  99. }
  100. };
  101.  
  102. Thread myThread = new Thread(myRunnable);
  103. myThread.start();
  104. }
  105.  
  106. public void VolDown(View view) {VolDown();}
  107. public void CopyPace(View view) {CopyPace();}
  108. public void ManCopy(View view) {CopyMethod();}
  109.  
  110. public void VolDown() {
  111. ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
  112. ClipData clip = ClipData.newPlainText("Copied Text","decrease volume");
  113. clipboard.setPrimaryClip(clip);
  114. }
  115.  
  116. public void CopyPace() {
  117. if(time==5000) time=2000;
  118. else if(time<5000) time+=1000;
  119. t1.setText("Automatically Sending in: "+(time/1000)+" sec");
  120. }
  121.  
  122. public void CopyMethod() {
  123. ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
  124. ClipData clip = ClipData.newPlainText("Copied Text", (CharSequence) e1.getText().toString());
  125. clipboard.setPrimaryClip(clip);
  126.  
  127. new AsyncTask<Integer, Void, Void>(){
  128. @Override
  129. protected Void doInBackground(Integer... params) {
  130. try {
  131. output=executeRemoteCommand();
  132. t2.setText(output);
  133. } catch (Exception e) {
  134. e.printStackTrace();
  135. }
  136. return null;
  137. }
  138. }.execute(1);
  139.  
  140. e1.setText("");
  141. }
  142.  
  143. public static String executeRemoteCommand()
  144. throws Exception {
  145. String username="pi";
  146. String password="10<,mmXLSQ";
  147. String hostname="192.168.43.41";
  148. int port=22;
  149. String a="echo '",c="' | xclip -selection clipboard";
  150.  
  151. JSch jsch = new JSch();
  152. Session session = jsch.getSession(username, hostname, port);
  153. session.setPassword(password);
  154.  
  155. // Avoid asking for key confirmation
  156. Properties prop = new Properties();
  157. prop.put("StrictHostKeyChecking", "no");
  158. session.setConfig(prop);
  159.  
  160. session.connect();
  161.  
  162. // SSH Channel
  163. ChannelExec channelSsh = (ChannelExec)
  164. session.openChannel("shell");
  165. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  166. channelSsh.setOutputStream(baos);
  167.  
  168. // Execute command
  169. String cmd=a+clip+c;
  170. channelSsh.setCommand(cmd);
  171. channelSsh.connect();
  172. channelSsh.disconnect();
  173.  
  174. return baos.toString();
  175. }
  176.  
  177. @Override
  178. public void onClick(View view) {CopyMethod();VolDown();CopyPace();}
  179. }
  180.  
  181. <?xml version="1.0" encoding="utf-8"?>
  182. <android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  183. xmlns:tools="http://schemas.android.com/tools"
  184. android:layout_width="match_parent"
  185. android:layout_height="match_parent"
  186. tools:context="com.quickclip.panky.quickclip.MainActivity">
  187.  
  188. <EditText
  189. android:id="@+id/editText"
  190. android:layout_width="fill_parent"
  191. android:layout_height="wrap_content"
  192. android:layout_alignParentTop="true"
  193. android:layout_centerHorizontal="true"
  194. android:layout_marginTop="30dp"
  195. android:ems="100"
  196. android:inputType="textAutoCorrect" />
  197.  
  198. <Button
  199. android:id="@+id/button1"
  200. android:layout_width="wrap_content"
  201. android:layout_height="wrap_content"
  202. android:layout_alignParentEnd="true"
  203. android:layout_below="@+id/editText"
  204. android:text="Send it Now"
  205. android:onClick="ManCopy"/>
  206.  
  207. <Button
  208. android:id="@+id/button2"
  209. android:layout_width="wrap_content"
  210. android:layout_height="wrap_content"
  211. android:layout_alignParentStart="true"
  212. android:layout_below="@+id/editText"
  213. android:text="Volume Down"
  214. android:onClick="VolDown"/>
  215.  
  216. <Button
  217. android:id="@+id/button3"
  218. android:layout_width="wrap_content"
  219. android:layout_height="wrap_content"
  220. android:layout_below="@+id/editText"
  221. android:layout_centerHorizontal="true"
  222. android:text="Switch Pace"
  223. android:onClick="CopyPace"/>
  224.  
  225. <TextView
  226. android:id="@+id/textView"
  227. android:layout_width="wrap_content"
  228. android:layout_height="wrap_content"
  229. android:layout_below="@+id/button"
  230. android:layout_centerHorizontal="true"
  231. android:textSize="20dp"
  232. android:layout_marginTop="130dp"
  233. android:text="Automatically Sending in: 3 sec" />
  234.  
  235. <TextView
  236. android:id="@+id/textView2"
  237. android:layout_width="wrap_content"
  238. android:layout_height="wrap_content"
  239. android:layout_below="@+id/textView"
  240. android:layout_centerHorizontal="true"
  241. android:textSize="20dp"
  242. android:text="Speak/Type in this time" />
  243.  
  244. <TextView
  245. android:id="@+id/textView3"
  246. android:layout_width="wrap_content"
  247. android:layout_height="wrap_content"
  248. android:layout_below="@+id/textView2"
  249. android:layout_centerHorizontal="true"
  250. android:textSize="20dp"
  251. android:text="Connecting to SSH" />
  252.  
  253. </android.widget.RelativeLayout>
Add Comment
Please, Sign In to add comment