|
1 | 1 | package org.csploit.android.services.receivers; |
2 | 2 |
|
3 | 3 | import android.app.Activity; |
| 4 | +import android.app.NotificationManager; |
4 | 5 | import android.content.Context; |
5 | 6 | import android.content.Intent; |
6 | 7 | import android.content.IntentFilter; |
| 8 | +import android.content.SharedPreferences; |
| 9 | +import android.support.v4.app.NotificationCompat; |
| 10 | +import android.support.v4.content.ContextCompat; |
7 | 11 | import android.widget.Toast; |
8 | 12 |
|
9 | 13 | import org.csploit.android.R; |
10 | 14 | import org.csploit.android.core.ManagedReceiver; |
| 15 | +import org.csploit.android.core.System; |
11 | 16 | import org.csploit.android.services.MsfRpcdService; |
12 | 17 |
|
13 | 18 | /** |
14 | 19 | * Receive and manage intents from the MsfRpcd service |
15 | 20 | */ |
16 | 21 | public class MsfRpcdServiceReceiver extends ManagedReceiver { |
17 | 22 |
|
| 23 | + final int MSF_NOTIFICATION = 1337; |
18 | 24 | private final IntentFilter filter; |
19 | 25 |
|
20 | 26 | public MsfRpcdServiceReceiver() { |
@@ -47,6 +53,12 @@ public void run() { |
47 | 53 | } else { |
48 | 54 | showToastForStatus(context, status); |
49 | 55 | } |
| 56 | + |
| 57 | + SharedPreferences myPrefs = System.getSettings(); |
| 58 | + if (myPrefs.getBoolean("MSF_NOTIFICATIONS", true)) { |
| 59 | + updateNotificationForStatus(context, status); |
| 60 | + } |
| 61 | + |
50 | 62 | } |
51 | 63 |
|
52 | 64 | private void showToastForStatus(Context context, MsfRpcdService.Status status) { |
@@ -74,4 +86,47 @@ private void showToastForStatus(Context context, MsfRpcdService.Status status) { |
74 | 86 | break; |
75 | 87 | } |
76 | 88 | } |
| 89 | + |
| 90 | + private void updateNotificationForStatus(Context context, MsfRpcdService.Status status) { |
| 91 | + NotificationCompat.Builder mBuilder = |
| 92 | + new NotificationCompat.Builder(context) |
| 93 | + .setSmallIcon(R.drawable.exploit_msf) |
| 94 | + .setContentTitle("MetaSploit RPCD Status"); |
| 95 | + mBuilder.setProgress(0, 0, false); |
| 96 | + switch (status) { |
| 97 | + case STARTING: |
| 98 | + mBuilder.setContentText(context.getResources().getText(R.string.rpcd_starting)); |
| 99 | + mBuilder.setProgress(0, 0, true); |
| 100 | + mBuilder.setColor(ContextCompat.getColor(context, R.color.selectable_blue)); |
| 101 | + break; |
| 102 | + case CONNECTED: |
| 103 | + mBuilder.setContentText(context.getResources().getText(R.string.connected_msf)); |
| 104 | + mBuilder.setColor(ContextCompat.getColor(context, R.color.green)); |
| 105 | + break; |
| 106 | + case DISCONNECTED: |
| 107 | + mBuilder.setContentText(context.getResources().getText(R.string.msfrpc_disconnected)); |
| 108 | + mBuilder.setColor(ContextCompat.getColor(context, R.color.purple)); |
| 109 | + break; |
| 110 | + case STOPPED: |
| 111 | + mBuilder.setContentText(context.getResources().getText(R.string.rpcd_stopped)); |
| 112 | + mBuilder.setColor(ContextCompat.getColor(context, R.color.purple)); |
| 113 | + break; |
| 114 | + case KILLED: |
| 115 | + mBuilder.setContentText(context.getResources().getText(R.string.msfrpcd_killed)); |
| 116 | + mBuilder.setColor(ContextCompat.getColor(context, R.color.purple)); |
| 117 | + break; |
| 118 | + case START_FAILED: |
| 119 | + mBuilder.setContentText(context.getResources().getText(R.string.msfrcd_start_failed)); |
| 120 | + mBuilder.setColor(ContextCompat.getColor(context, R.color.red)); |
| 121 | + break; |
| 122 | + case CONNECTION_FAILED: |
| 123 | + mBuilder.setContentText(context.getResources().getText(R.string.msf_connection_failed)); |
| 124 | + mBuilder.setColor(ContextCompat.getColor(context, R.color.red)); |
| 125 | + break; |
| 126 | + } |
| 127 | + |
| 128 | + NotificationManager mNotificationManager = |
| 129 | + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
| 130 | + mNotificationManager.notify(MSF_NOTIFICATION, mBuilder.build()); |
| 131 | + } |
77 | 132 | } |
0 commit comments