Package omschaub.stuffer.main

Source Code of omschaub.stuffer.main.Plugin

/*
* Created on Jun 13, 2004
*/
package omschaub.stuffer.main;


import omschaub.stuffer.containers.ClientBlockSet;
import omschaub.stuffer.containers.SetUtils;
/*import omschaub.stuffer.containers.TotalPeerContainer;
import omschaub.stuffer.containers.TotalPeerSetUtils;*/

import org.eclipse.swt.widgets.Display;
import org.gudy.azureus2.plugins.PluginConfig;
import org.gudy.azureus2.plugins.PluginException;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.UnloadablePlugin;
import org.gudy.azureus2.plugins.ipfilter.IPFilter;
import org.gudy.azureus2.plugins.ipfilter.IPRange;
import org.gudy.azureus2.plugins.ui.UIInstance;
import org.gudy.azureus2.plugins.ui.UIManager;
import org.gudy.azureus2.plugins.ui.UIManagerListener;
import org.gudy.azureus2.plugins.ui.model.BasicPluginConfigModel;
import org.gudy.azureus2.plugins.utils.UTTimer;
import org.gudy.azureus2.plugins.utils.UTTimerEvent;
import org.gudy.azureus2.plugins.utils.UTTimerEventPerformer;
import org.gudy.azureus2.pluginsimpl.local.ipfilter.IPFilterImpl;
import org.gudy.azureus2.ui.swt.plugins.UISWTInstance;
import org.gudy.azureus2.ui.swt.plugins.UISWTViewEventListener;



/**
* @author omschaub
*
* Stuffer -- Client Killer Plugin for Azureus
*
*/
public class Plugin implements UnloadablePlugin {

  //new API startup code
  UISWTInstance swtInstance = null;
  UISWTViewEventListener myView = null;
  private static Display display;

  //open up the Sets for use
  public static SetUtils table1_set;
  public static SetUtils table2_set;
  //public static TotalPeerSetUtils totalPeer_set;
  public static ClientBlockSet clientBlock_set;

  //publically used static holders
  public static int total_blocked, total_removed;
  public static boolean areRulesPaused;
  private static UTTimer timer;

  // THE plugin Interface
  PluginInterface pluginInterface;
  private static PluginInterface pi;

  //pluginconfig
  public static PluginConfig config_getter;

  //The main Tab1
  private static Tab1 MainTab1;

  //The main Tab2
  private static Tab2 MainTab2;
  private static Tab2Utilities tab2Utilities;
/*
  //The main Tab3
  private static Tab3 MainTab3;*/

  public void initialize(final PluginInterface pluginInterface) {
    this.pluginInterface = pluginInterface;
    pi=pluginInterface;
    UIManager  ui_manager = pluginInterface.getUIManager();
    BasicPluginConfigModel config_model = ui_manager.createBasicPluginConfigModel( "plugins", "plugin.stuffer");

    config_model.addBooleanParameter2("stuffer_military_time","stuffer.military.time",false);
    config_model.addBooleanParameter2("stuffer_auto_open","stuffer.auto.open",true);

    config_getter = pluginInterface.getPluginconfig();

    //initialize strings
    areRulesPaused = false;
    total_removed = 0;
    total_blocked = 0;

    //Setup of the main Set for holding all of the table data
    table1_set = new SetUtils();
    table1_set.SetUtilsforTable1();
    table2_set = new SetUtils();
    table2_set.SetUtilsforTable2();
    //totalPeer_set = new TotalPeerSetUtils();

    clientBlock_set = new ClientBlockSet();
    clientBlock_set.Initialize();
    FileUtilities.readClientList();

    BlockIPUtils.startMainClientCheck();

    purgeCheck();
    startPeerPurge();


      //new API initializer

      pluginInterface.getUIManager().addUIListener(new UIManagerListener() {
        public void UIAttached(UIInstance instance) {
        if (instance instanceof UISWTInstance) {
          swtInstance = (UISWTInstance)instance;
          myView = new View(pluginInterface);
          swtInstance.addView(UISWTInstance.VIEW_MAIN, View.VIEWID, myView);
          if(config_getter.getPluginBooleanParameter("stuffer_auto_open",true)){
            swtInstance.openMainView(View.VIEWID,myView,null);
            display = swtInstance.getDisplay();
          }
        }
        }

        public void UIDetached(UIInstance instance) {
        if (instance instanceof UISWTInstance) {
          swtInstance = null;
        }
        }
      });

      //initialize the tabs
      MainTab1 = new Tab1();
      MainTab2 = new Tab2();
      tab2Utilities = new Tab2Utilities();
    //      MainTab3 = new Tab3();

    }//End of Initialize



   public void unload() throws PluginException {
     if (swtInstance == null || myView == null)
       return;

     swtInstance.removeViews(UISWTInstance.VIEW_MAIN, View.VIEWID);

     myView = null;
     }





  public static PluginInterface getPluginInterface(){
    return pi;
  }

  public static Tab1 getTab1(){
   return MainTab1;
  }

  public static Tab2 getTab2(){
    return MainTab2;
  }
/*
  public static Tab3 getTab3(){
    return MainTab3;
  }*/

  public static Tab2Utilities getTab2Utilities(){
    return tab2Utilities;
  }

  private synchronized void purgeCheck()
  {
    if(Plugin.getTab1() != null){
      Plugin.getTab1().setTimeNextLabel("Next Auto Purge: " +
          Utils.getNextRunTime((1000*60*config_getter.getPluginIntParameter("stuffer_time_interval",10)),
          Plugin.config_getter.getPluginBooleanParameter("stuffer_military_time",false)));
    }


    timer=pluginInterface.getUtilities().createTimer("stuffer_created_timer");
    timer.addPeriodicEvent(1000*60*config_getter.getPluginIntParameter("stuffer_time_interval",10),



      new UTTimerEventPerformer()

      {

      public void

      perform(

      UTTimerEvent ev2 )

      {

      try {
        if(Plugin.getTab1() != null){
          Plugin.getTab1().setTimeNextLabel("Next Auto Purge: " +
              Utils.getNextRunTime((1000*60*config_getter.getPluginIntParameter("stuffer_time_interval",10)),
              Plugin.config_getter.getPluginBooleanParameter("stuffer_military_time",false)));
        }




        if(!Plugin.config_getter.getPluginBooleanParameter("stuffer_noauto",false))
        {

          IPFilter ipf = new IPFilterImpl();
          IPRange[] ipr = ipf.getRanges();
          for(int i = 0; i < ipr.length; i++){
            if (ipr[i].getDescription().startsWith("Stuffer") || ipr[i].getDescription().startsWith("stuffer")){
              ipr[i].delete();
              if(Plugin.getTab1() != null)
                Plugin.getTab1().addElementPeer(ipr[i].getDescription(), ipr[i].getStartIP(), "Interval");

              total_removed++;
              if(Plugin.getTab1() != null)
                Plugin.getTab1().totalChange();
            }
          }
        }

      }catch(Exception f) {
        System.out.println("Error in scanning IPFilter list");
        f.printStackTrace();
      }

      }

      });

  }


  public static void resetTimer(){
    if(timer != null){
      timer.destroy();

    }

    if(Plugin.getTab1() != null){
      Plugin.getTab1().setTimeNextLabel("Next Auto Purge: "
          + Utils.getNextRunTime((1000*60*config_getter.getPluginIntParameter("stuffer_time_interval",10)),
          Plugin.config_getter.getPluginBooleanParameter("stuffer_military_time",false)));
    }


    timer=pi.getUtilities().createTimer("stuffer_created_timer");
    timer.addPeriodicEvent(1000 * 60 * config_getter.getPluginIntParameter("stuffer_time_interval",10),
    new UTTimerEventPerformer()

    {

    public void

    perform(

    UTTimerEvent ev2 )

    {

    try {
      if(Plugin.getTab1() != null){
        Plugin.getTab1().setTimeNextLabel("Next Auto Purge: "
            + Utils.getNextRunTime((1000*60*config_getter.getPluginIntParameter("stuffer_time_interval",10)),
            Plugin.config_getter.getPluginBooleanParameter("stuffer_military_time",false)));
      }


      if(!Plugin.config_getter.getPluginBooleanParameter("stuffer_noauto",false))
      {

        IPFilter ipf = new IPFilterImpl();
        IPRange[] ipr = ipf.getRanges();
        for(int i = 0; i < ipr.length; i++){
          if (ipr[i].getDescription().startsWith("Stuffer")|| ipr[i].getDescription().startsWith("stuffer")){
            ipr[i].delete();
            if(Plugin.getTab1() != null)
              Plugin.getTab1().addElementPeer(ipr[i].getDescription(), ipr[i].getStartIP(), "Interval");
            //System.out.println("Interval Deleting Stuffit IP Rule: " + ipr[i].getDescription() + "  " + ipr[i].getStartIP());
            total_removed++;
            if(Plugin.getTab1() != null)
              Plugin.getTab1().totalChange();
          }
        }
      }

    }catch(Exception f) {
      System.out.println("Error in scanning IPFilter list");
      f.printStackTrace();
    }

    }

    });
  }


  public static void manualPurge(){
    try {
        IPFilter ipf = new IPFilterImpl();
        IPRange[] ipr = ipf.getRanges();
        for(int i = 0; i < ipr.length; i++){
          if (ipr[i].getDescription().startsWith("Stuffer")|| ipr[i].getDescription().startsWith("stuffer")){
            ipr[i].delete();
            if(Plugin.getTab1() != null)
              Plugin.getTab1().addElementPeer(ipr[i].getDescription(), ipr[i].getStartIP(), "Manual");
            total_removed++;
            if(Plugin.getTab1() != null)
              Plugin.getTab1().totalChange();
          }
        }


    }catch(Exception f) {
      System.out.println("Error in scanning IPFilter list");
      f.printStackTrace();
    }
  }


  public static void startPeerPurge(){
     UTTimer peer_timer=pi.getUtilities().createTimer("stuffer_purge_timer");
     peer_timer.addPeriodicEvent(1000*6,
    new UTTimerEventPerformer()

    {

    public void

    perform(

    UTTimerEvent ev2 )

    {

    try {

    Utils.killConnectedPeers();


    /*//System.out.println("Peers in TotalPeerSet:  " + totalPeer_set.getSize());
    Runtime runTime = Runtime.getRuntime();
    float used = (runTime.totalMemory()-runTime.freeMemory())/1024/1024;
    float max = runTime.totalMemory() / 1024 / 1024;
    Tab3.setMemoryLabel(used, max);

    TotalPeerContainer[] tpc = Plugin.totalPeer_set.getAllTotalPeerContainers();
    for(int i = 0; i < tpc.length; i++){

      if(tpc[i].getTotalConnectionTime() > 5*60*1000 && tpc[i].getPercentDone() > 900){
        //System.out.println(tpc[i].getIP().getAsString() + " failed with " + tpc[i].getPercentDone());
      }
    }

    */

    }catch(Exception e){
      e.printStackTrace();
    }
    }

    });

  }


  /*  public static void startTPCRuleRun(){
    UTTimer peer_timer=pi.getUtilities().createTimer("stuffer_tpc_timer");
    peer_timer.addPeriodicEvent(1000*6,
     new UTTimerEventPerformer()

     {

     public void

     perform(

     UTTimerEvent ev2 )

     {

     try {

     Runtime runTime = Runtime.getRuntime();
     float used = (runTime.totalMemory()-runTime.freeMemory())/1024/1024;
     float max = runTime.totalMemory() / 1024 / 1024;
     MainTab3.setMemoryLabel(used, max);

     TotalPeerContainer[] tpc = Plugin.totalPeer_set.getAllTotalPeerContainers();
     for(int i = 0; i < tpc.length; i++){

       if(tpc[i].getTotalConnectionTime() > 5*60*1000 && tpc[i].getPercentDone() > 900){
         //System.out.println(tpc[i].getIP().getAsString() + " failed with " + tpc[i].getPercentDone());
       }
     }



     }catch(Exception e){
       e.printStackTrace();
     }
     }

     });

   }
*/

  public static Display getDisplay(){
    return display;
  }
  public static void setDisplay(Display new_display){
    display=new_display;
  }

  //EOF

}
TOP

Related Classes of omschaub.stuffer.main.Plugin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.