Search in sources :

Example 1 with EventTrigger

use of org.havenapp.main.model.EventTrigger in project haven by guardianproject.

the class MonitorService method alert.

/**
 * Sends an alert according to type of connectivity
 */
public synchronized void alert(int alertType, String path) {
    Date now = new Date();
    boolean doNotification = false;
    if (mLastEvent == null) {
        mLastEvent = new Event();
        mLastEvent.save();
        doNotification = true;
    } else if (mPrefs.getNotificationTimeMs() == 0) {
        doNotification = true;
    } else if (mPrefs.getNotificationTimeMs() > 0 && mLastNotification != null) {
        // check if time window is within configured notification time window
        doNotification = ((now.getTime() - mLastNotification.getTime()) > mPrefs.getNotificationTimeMs());
    } else {
        doNotification = true;
    }
    EventTrigger eventTrigger = new EventTrigger();
    eventTrigger.setType(alertType);
    eventTrigger.setPath(path);
    mLastEvent.addEventTrigger(eventTrigger);
    // we don't need to resave the event, only the trigger
    eventTrigger.save();
    if (doNotification) {
        mLastNotification = new Date();
        /*
             * If SMS mode is on we send an SMS or Signal alert to the specified
             * number
             */
        StringBuilder alertMessage = new StringBuilder();
        alertMessage.append(getString(R.string.intrusion_detected, eventTrigger.getStringType(this)));
        if (mPrefs.getSignalUsername() != null) {
            // since this is a secure channel, we can add the Onion address
            if (mPrefs.getRemoteAccessActive() && (!TextUtils.isEmpty(mPrefs.getRemoteAccessOnion()))) {
                alertMessage.append(" http://").append(mPrefs.getRemoteAccessOnion()).append(':').append(WebServer.LOCAL_PORT);
            }
            SignalSender sender = SignalSender.getInstance(this, mPrefs.getSignalUsername());
            ArrayList<String> recips = new ArrayList<>();
            StringTokenizer st = new StringTokenizer(mPrefs.getSmsNumber(), ",");
            while (st.hasMoreTokens()) recips.add(st.nextToken());
            String attachment = null;
            if (eventTrigger.getType() == EventTrigger.CAMERA) {
                attachment = eventTrigger.getPath();
            } else if (eventTrigger.getType() == EventTrigger.MICROPHONE) {
                attachment = eventTrigger.getPath();
            } else if (eventTrigger.getType() == EventTrigger.CAMERA_VIDEO) {
                attachment = eventTrigger.getPath();
            }
            sender.sendMessage(recips, alertMessage.toString(), attachment);
        } else if (mPrefs.getSmsActivation()) {
            SmsManager manager = SmsManager.getDefault();
            StringTokenizer st = new StringTokenizer(mPrefs.getSmsNumber(), ",");
            while (st.hasMoreTokens()) manager.sendTextMessage(st.nextToken(), null, alertMessage.toString(), null, null);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) Event(org.havenapp.main.model.Event) Date(java.util.Date) EventTrigger(org.havenapp.main.model.EventTrigger) SmsManager(android.telephony.SmsManager)

Example 2 with EventTrigger

use of org.havenapp.main.model.EventTrigger in project haven by guardianproject.

the class WebServer method showEvent.

private void showEvent(Event event, StringBuffer page) {
    List<EventTrigger> triggers = event.getEventTriggers();
    page.append("<h1>Event: ").append(event.getStartTime().toLocaleString()).append("</h1><hr/>\n");
    for (EventTrigger eventTrigger : triggers) {
        String title = eventTrigger.getStringType(mContext);
        String desc = eventTrigger.getTriggerTime().toString();
        page.append("<b>");
        page.append(title).append("</b><br/>");
        page.append(desc).append("<br/>");
        String mediaPath = "/event/" + event.getId() + "/trigger/" + eventTrigger.getId();
        if (eventTrigger.getType() == EventTrigger.CAMERA) {
            page.append("<img src=\"").append(mediaPath).append("\" width=\"100%\"/>");
            page.append("<a href=\"").append(mediaPath).append("\">Download Media").append("</a>");
        } else if (eventTrigger.getType() == EventTrigger.MICROPHONE) {
            page.append("<audio src=\"").append(mediaPath).append("\"></audio>");
            page.append("<a href=\"").append(mediaPath).append("\">Download Media").append("</a>");
        }
        page.append("<hr/>");
    }
}
Also used : EventTrigger(org.havenapp.main.model.EventTrigger)

Example 3 with EventTrigger

use of org.havenapp.main.model.EventTrigger in project haven by guardianproject.

the class WebServer method serve.

@Override
public Response serve(IHTTPSession session) {
    StringBuffer page = new StringBuffer();
    Cookie cookie = null;
    if (mPassword != null) {
        // We have to use session.parseBody() to obtain POST data.
        // See https://github.com/NanoHttpd/nanohttpd/issues/427
        Map<String, String> content = new HashMap<>();
        Method method = session.getMethod();
        if (Method.PUT.equals(method) || Method.POST.equals(method))
            try {
                session.parseBody(content);
            } catch (IOException ioe) {
                Log.e(TAG, "unable to parse body of request", ioe);
            } catch (ResponseException re) {
                Log.e(TAG, "unable to parse body of request", re);
            }
        String inPassword = session.getParms().get("p");
        String inSid = session.getCookies().read("sid");
        if (inPassword != null && safeEquals(inPassword, mPassword)) {
            mSession = UUID.randomUUID().toString();
            cookie = new OnionCookie("sid", mSession, 100000);
            session.getCookies().set(cookie);
        } else if (inSid == null || mSession == null || (inSid != null && (!safeEquals(inSid, mSession)))) {
            showLogin(page);
            return newFixedLengthResponse(page.toString());
        }
    }
    Uri uri = Uri.parse(session.getUri());
    List<String> pathSegs = uri.getPathSegments();
    if (pathSegs.size() == 4 && pathSegs.get(2).equals("trigger")) {
        // long eventId = Long.parseLong(pathSegs.get(1));
        long eventTriggerId = Long.parseLong(pathSegs.get(3));
        EventTrigger eventTrigger = EventTrigger.findById(EventTrigger.class, eventTriggerId);
        try {
            File fileMedia = new File(eventTrigger.getPath());
            FileInputStream fis = new FileInputStream(fileMedia);
            return newChunkedResponse(Response.Status.OK, getMimeType(eventTrigger), fis);
        } catch (IOException ioe) {
            Log.e(TAG, "unable to return media file", ioe);
        }
    } else if (uri.getPath().startsWith("/feed")) {
    // do RSS feed
    } else {
        page.append("<html><head><title>").append(appTitle).append("</title>");
        page.append("<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=utf-8\" />");
        page.append("<meta name = \"viewport\" content = \"user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width\">");
        page.append("</head><body>");
        if (TextUtils.isEmpty(uri.getPath()) || uri.getPath().equals("/"))
            showEvents(page);
        else {
            try {
                if (pathSegs.size() == 2 && pathSegs.get(0).equals("event")) {
                    long eventId = Long.parseLong(pathSegs.get(1));
                    Event event = Event.findById(Event.class, eventId);
                    showEvent(event, page);
                }
            } catch (Exception e) {
                Log.e(TAG, "Something went wrong with parsing the path", e);
            }
        }
        page.append("</body></html>\n");
        Response response = newFixedLengthResponse(page.toString());
        session.getCookies().unloadQueue(response);
        return response;
    }
    Response response = newFixedLengthResponse(Response.Status.INTERNAL_ERROR, "text/plain", "Error");
    session.getCookies().unloadQueue(response);
    return response;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) Uri(android.net.Uri) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Event(org.havenapp.main.model.Event) File(java.io.File) EventTrigger(org.havenapp.main.model.EventTrigger)

Example 4 with EventTrigger

use of org.havenapp.main.model.EventTrigger in project haven by guardianproject.

the class EventActivity method generateLog.

private String generateLog() {
    StringBuilder mEventLog = new StringBuilder();
    setTitle("Event @ " + mEvent.getStartTime().toLocaleString());
    for (EventTrigger eventTrigger : mEvent.getEventTriggers()) {
        mEventLog.append("Event Triggered @ ").append(eventTrigger.getTriggerTime().toString()).append("\n");
        String sType = eventTrigger.getStringType(this);
        mEventLog.append("Event Type: ").append(sType);
        mEventLog.append("\n==========================\n");
    }
    return mEventLog.toString();
}
Also used : EventTrigger(org.havenapp.main.model.EventTrigger)

Example 5 with EventTrigger

use of org.havenapp.main.model.EventTrigger in project haven by guardianproject.

the class EventActivity method shareEvent.

private void shareEvent() {
    String title = "Phoneypot: " + mEvent.getStartTime().toLocaleString();
    // need to "send multiple" to get more than one attachment
    final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
    emailIntent.putExtra(Intent.EXTRA_TEXT, generateLog());
    // has to be an ArrayList
    ArrayList<Uri> uris = new ArrayList<>();
    // convert from paths to Android friendly Parcelable Uri's
    for (EventTrigger trigger : mEvent.getEventTriggers()) {
        File fileIn = new File(trigger.getPath());
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(emailIntent, getString(R.string.share_event_action)));
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) Uri(android.net.Uri) File(java.io.File) EventTrigger(org.havenapp.main.model.EventTrigger)

Aggregations

EventTrigger (org.havenapp.main.model.EventTrigger)7 File (java.io.File)3 Event (org.havenapp.main.model.Event)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ArrayList (java.util.ArrayList)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Toolbar (android.support.v7.widget.Toolbar)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 SmsManager (android.telephony.SmsManager)1 LayoutInflater (android.view.LayoutInflater)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 VideoView (android.widget.VideoView)1 SimpleWaveformView (com.github.derlio.waveform.SimpleWaveformView)1 SoundFile (com.github.derlio.waveform.soundfile.SoundFile)1