Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.provectus.colectaservlaunch;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.res.AssetManager;
- import android.net.Uri;
- import android.os.Bundle;
- import android.util.Log;
- public class ColectaservlaunchActivity extends Activity {
- /** Called when the activity is first created. */
- // File Copy
- private void copyFileOrDir(String path) {
- AssetManager assetManager = this.getAssets();
- String assets[] = null;
- try {
- assets = assetManager.list(path);
- if (assets.length == 0) {
- copyFile(path);
- } else {
- String fullPath = "/data/data/" + this.getPackageName() + "/" + path;
- File dir = new File(fullPath);
- if (!dir.exists())
- dir.mkdir();
- for (int i = 0; i < assets.length; ++i) {
- copyFileOrDir(path + "/" + assets[i]);
- }
- }
- } catch (IOException ex) {
- Log.e("tag", "I/O Exception", ex);
- }
- }
- private void copyFile(String filename) {
- AssetManager assetManager = this.getAssets();
- InputStream in = null;
- OutputStream out = null;
- try {
- in = assetManager.open(filename);
- String newFileName = "/data/data/" + this.getPackageName() + "/" + filename;
- out = new FileOutputStream(newFileName);
- byte[] buffer = new byte[1024];
- int read;
- while ((read = in.read(buffer)) != -1) {
- out.write(buffer, 0, read);
- }
- in.close();
- in = null;
- out.flush();
- out.close();
- out = null;
- } catch (Exception e) {
- Log.e("tag", e.getMessage());
- }
- }
- void execCommandLine(String command)
- {
- Runtime runtime = Runtime.getRuntime();
- Process proc = null;
- OutputStreamWriter osw = null;
- try
- {
- proc = runtime.exec("su");
- osw = new OutputStreamWriter(proc.getOutputStream());
- osw.write(command);
- osw.flush();
- osw.close();
- }
- catch (IOException ex)
- {
- Log.e("execCommandLine()", "Command resulted in an IO Exception: " + command);
- return;
- }
- finally
- {
- if (osw != null)
- {
- try
- {
- osw.close();
- }
- catch (IOException e){}
- }
- }
- try
- {
- proc.waitFor();
- }
- catch (InterruptedException e){}
- if (proc.exitValue() != 0)
- {
- Log.e("execCommandLine()", "Command returned error: " + command + "\n Exit code: " + proc.exitValue());
- }
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- copyFileOrDir("scripts");
- execCommandLine("chmod 755 /data/data/com.provectus.colectaservlaunch/scripts/apache_start");
- execCommandLine("chmod 755 /data/data/com.provectus.colectaservlaunch/scripts/apache_stop");
- execCommandLine("chmod 755 /data/data/com.provectus.colectaservlaunch/scripts/ssh_start");
- execCommandLine("chmod 755 /data/data/com.provectus.colectaservlaunch/scripts/ssh_stop");
- execCommandLine("/data/data/com.provectus.colectaservlaunch/scripts/apache_start");
- execCommandLine("/data/data/com.provectus.colectaservlaunch/scripts/ssh_start");
- Uri uriUrl = Uri.parse("http://127.0.0.1/collectaservicos/login.php");
- Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
- startActivity(launchBrowser);
- finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement