@@ -95,16 +95,22 @@ static class Action{
9595 public String name ;
9696 public String description ;
9797 public OnClickListener listener ;
98+ public ActionEnabler enabler ;
9899
99- public Action (String name , String description , int resourceId , OnClickListener listener ){
100+ public Action (String name , String description , int resourceId , OnClickListener listener , ActionEnabler enabler ){
100101 this .resourceId = resourceId ;
101102 this .name = name ;
102103 this .description = description ;
103104 this .listener = listener ;
105+ this .enabler = enabler ;
104106 }
105107
106108 public Action (String name , String description , OnClickListener listener ){
107- this (name , description , R .drawable .action_plugin , listener );
109+ this (name , description , R .drawable .action_plugin , listener , null );
110+ }
111+
112+ public interface ActionEnabler {
113+ boolean isEnabled ();
108114 }
109115 }
110116
@@ -138,11 +144,11 @@ public View getView(int position, View convertView, ViewGroup parent){
138144 if (getSharedPreferences ("THEME" , 0 ).getBoolean ("isDark" , false ))
139145 row .setBackgroundResource (R .drawable .card_background_dark );
140146 holder = new ActionHolder ();
141- holder .icon = (ImageView ) ( row != null ? row .findViewById (R .id .actionIcon ) : null );
142- holder .name = (TextView ) ( row != null ? row .findViewById (R .id .itemName ) : null );
143- holder .description = (TextView ) ( row != null ? row .findViewById (R .id .itemDescription ) : null );
144- holder .activity = (ProgressBar ) ( row != null ? row .findViewById (R .id .itemActivity ) : null );
145- if ( row != null ) row .setTag (holder );
147+ holder .icon = (ImageView ) row .findViewById (R .id .actionIcon );
148+ holder .name = (TextView ) row .findViewById (R .id .itemName );
149+ holder .description = (TextView ) row .findViewById (R .id .itemDescription );
150+ holder .activity = (ProgressBar ) row .findViewById (R .id .itemActivity );
151+ row .setTag (holder );
146152
147153 } else holder = (ActionHolder ) row .getTag ();
148154
@@ -152,7 +158,8 @@ public View getView(int position, View convertView, ViewGroup parent){
152158 holder .name .setText (action .name );
153159 holder .description .setText (action .description );
154160
155- if (row != null ) row .setOnClickListener (action .listener );
161+ row .setOnClickListener (action .listener );
162+ row .setEnabled (action .enabler == null || action .enabler .isEnabled ());
156163
157164 return row ;
158165 }
@@ -442,7 +449,7 @@ public void onClick(View v) {
442449 );
443450 overridePendingTransition (R .anim .fadeout , R .anim .fadein );
444451 }
445- }));
452+ }, null ));
446453
447454 mActions .add (new Action
448455 (
@@ -452,7 +459,7 @@ public void onClick(View v) {
452459 new OnClickListener (){
453460 @ Override
454461 public void onClick (View v ){
455- if (System .checkNetworking (MITM .this ) == false )
462+ if (! System .checkNetworking (MITM .this ))
456463 return ;
457464
458465 setStoppedState ();
@@ -467,7 +474,7 @@ public void onClick(View v){
467474 );
468475 overridePendingTransition (R .anim .fadeout , R .anim .fadein );
469476 }
470- }));
477+ }, null ));
471478
472479
473480 mActions .add (new Action
@@ -478,7 +485,7 @@ public void onClick(View v){
478485 new OnClickListener () {
479486 @ Override
480487 public void onClick (View v ) {
481- if (System .checkNetworking (MITM .this ) == false )
488+ if (! System .checkNetworking (MITM .this ))
482489 return ;
483490
484491 setStoppedState ();
@@ -493,7 +500,7 @@ public void onClick(View v) {
493500 );
494501 overridePendingTransition (R .anim .fadeout , R .anim .fadein );
495502 }
496- }));
503+ }, null ));
497504
498505 mActions .add (new Action
499506 (
@@ -503,7 +510,7 @@ public void onClick(View v) {
503510 new OnClickListener (){
504511 @ Override
505512 public void onClick (View v ){
506- if ( System .checkNetworking (MITM .this ) == false )
513+ if (! System .checkNetworking (MITM .this ))
507514 return ;
508515
509516 setStoppedState ();
@@ -518,7 +525,7 @@ public void onClick(View v){
518525 );
519526 overridePendingTransition (R .anim .fadeout , R .anim .fadein );
520527 }
521- }));
528+ }, null ));
522529
523530 mActions .add (new Action
524531 (
@@ -528,19 +535,21 @@ public void onClick(View v){
528535 new OnClickListener (){
529536 @ Override
530537 public void onClick (View v ){
531- if ( System .checkNetworking (MITM .this ) == false )
538+ if (! System .checkNetworking (MITM .this ))
532539 return ;
533540
534541 final ProgressBar activity = (ProgressBar ) v .findViewById (R .id .itemActivity );
535542
536543 if (activity .getVisibility () == View .INVISIBLE ){
537- if (System .getCurrentTarget ().getType () != Target .Type .ENDPOINT )
544+ if (System .getCurrentTarget ().getType () != Target .Type .ENDPOINT ) {
538545 new ErrorDialog (getString (R .string .error ), getString (R .string .mitm_connection_kill_error ), MITM .this ).show ();
539-
540- else {
546+ } else if (!System .getNetwork ().haveGateway () && !System .getNetwork ().isTetheringEnabled ()) {
547+ new ErrorDialog (getString (R .string .error ), "Connection killer requires a gateway or active Tethering" , MITM .this ).show ();
548+ } else {
541549 setStoppedState ();
542550
543551 try {
552+ if (System .getNetwork ().haveGateway ()) {
544553 mConnectionKillerProcess = System .getTools ().arpSpoof .spoof (System .getCurrentTarget (), new ArpSpoof .ArpSpoofReceiver () {
545554
546555 @ Override
@@ -560,6 +569,10 @@ public void run() {
560569 });
561570 }
562571 });
572+ } else {
573+ mConnectionKillerProcess = null ;
574+ System .setForwarding (false );
575+ }
563576
564577 activity .setVisibility (View .VISIBLE );
565578
@@ -575,10 +588,19 @@ public void run() {
575588 mConnectionKillerProcess = null ;
576589 }
577590
591+ if (!System .getNetwork ().haveGateway () && System .getNetwork ().isTetheringEnabled ()) {
592+ System .setForwarding (true );
593+ }
594+
578595 activity .setVisibility (View .INVISIBLE );
579596 }
580597 }
581- }));
598+ }, new Action .ActionEnabler () {
599+ @ Override
600+ public boolean isEnabled () {
601+ return System .getNetwork ().haveGateway () || System .getNetwork ().isTetheringEnabled ();
602+ }
603+ }));
582604
583605 mActions .add (new Action
584606 (
@@ -643,7 +665,7 @@ public void onError(String error, int resId){
643665 } else
644666 setStoppedState ();
645667 }
646- }));
668+ }, null ));
647669
648670 mActions .add (new Action
649671 (
@@ -745,7 +767,7 @@ public void onError(String error, int resId){
745767 setStoppedState ();
746768 }
747769 }
748- }));
770+ }, null ));
749771
750772 mActions .add (new Action
751773 (
@@ -825,7 +847,7 @@ public void onError(String error, int resId){
825847 } else
826848 setStoppedState ();
827849 }
828- }));
850+ }, null ));
829851
830852 mActions .add (new Action
831853 (
@@ -835,7 +857,7 @@ public void onError(String error, int resId){
835857 new OnClickListener (){
836858 @ Override
837859 public void onClick (View v ){
838- if (System .checkNetworking (MITM .this ) == false )
860+ if (! System .checkNetworking (MITM .this ))
839861 return ;
840862
841863 final ProgressBar activity = (ProgressBar ) v .findViewById (R .id .itemActivity );
@@ -912,7 +934,7 @@ public void onError(String error, int resId){
912934 setStoppedState ();
913935 }
914936 }
915- }));
937+ }, null ));
916938
917939 mActions .add (new Action
918940 (
@@ -921,7 +943,7 @@ public void onError(String error, int resId){
921943 new OnClickListener (){
922944 @ Override
923945 public void onClick (View v ){
924- if (System .checkNetworking (MITM .this ) == false )
946+ if (! System .checkNetworking (MITM .this ))
925947 return ;
926948
927949 final ProgressBar activity = (ProgressBar ) v .findViewById (R .id .itemActivity );
0 commit comments