You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IdentdPlugin.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.identd;
  23. import com.dmdirc.Server;
  24. import com.dmdirc.actions.ActionManager;
  25. import com.dmdirc.actions.CoreActionType;
  26. import com.dmdirc.actions.interfaces.ActionType;
  27. import com.dmdirc.config.IdentityManager;
  28. import com.dmdirc.config.prefs.PluginPreferencesCategory;
  29. import com.dmdirc.config.prefs.PreferencesCategory;
  30. import com.dmdirc.config.prefs.PreferencesManager;
  31. import com.dmdirc.config.prefs.PreferencesSetting;
  32. import com.dmdirc.config.prefs.PreferencesType;
  33. import com.dmdirc.config.prefs.validator.PortValidator;
  34. import com.dmdirc.interfaces.ActionListener;
  35. import com.dmdirc.plugins.Plugin;
  36. import java.util.ArrayList;
  37. import java.util.List;
  38. /**
  39. * The Identd plugin answers ident requests from IRC servers.
  40. *
  41. * @author Shane
  42. */
  43. public class IdentdPlugin extends Plugin implements ActionListener {
  44. /** Array list to store all the servers in that need ident replies. */
  45. private final List<Server> servers = new ArrayList<Server>();
  46. /** The IdentdServer that we use. */
  47. private IdentdServer myServer;
  48. /**
  49. * Creates a new instance of IdentdPlugin.
  50. */
  51. public IdentdPlugin() {
  52. }
  53. /**
  54. * Called when the plugin is loaded.
  55. */
  56. @Override
  57. public void onLoad() {
  58. // Add action hooks
  59. ActionManager.addListener(this, CoreActionType.SERVER_CONNECTED, CoreActionType.SERVER_CONNECTING, CoreActionType.SERVER_CONNECTERROR);
  60. myServer = new IdentdServer(this);
  61. if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.alwaysOn")) {
  62. myServer.startServer();
  63. }
  64. }
  65. /**
  66. * Called when this plugin is unloaded.
  67. */
  68. @Override
  69. public void onUnload() {
  70. myServer.stopServer();
  71. servers.clear();
  72. ActionManager.removeListener(this);
  73. }
  74. /**
  75. * Process an event of the specified type.
  76. *
  77. * @param type The type of the event to process
  78. * @param format Format of messages that are about to be sent. (May be null)
  79. * @param arguments The arguments for the event
  80. */
  81. @Override
  82. public void processEvent(final ActionType type, final StringBuffer format, final Object... arguments) {
  83. if (type == CoreActionType.SERVER_CONNECTING) {
  84. synchronized (servers) {
  85. if (servers.isEmpty()) {
  86. myServer.startServer();
  87. }
  88. servers.add((Server) arguments[0]);
  89. }
  90. } else if (type == CoreActionType.SERVER_CONNECTED || type == CoreActionType.SERVER_CONNECTERROR) {
  91. synchronized (servers) {
  92. servers.remove(arguments[0]);
  93. if (servers.isEmpty() && !IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.alwaysOn")) {
  94. myServer.stopServer();
  95. }
  96. }
  97. }
  98. }
  99. /** {@inheritDoc} */
  100. @Override
  101. public void showConfig(final PreferencesManager manager) {
  102. final PreferencesCategory general = new PluginPreferencesCategory(getPluginInfo(), "Identd",
  103. "General Identd Plugin config ('Lower' options take priority " +
  104. "over those above them)");
  105. final PreferencesCategory advanced = new PluginPreferencesCategory(getPluginInfo(), "Advanced",
  106. "Advanced Identd Plugin config - Only edit these if you need " +
  107. "to/know what you are doing. Editing these could prevent " +
  108. "access to some servers. ('Lower' options take priority over " +
  109. "those above them)");
  110. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  111. getDomain(), "general.useUsername", "Use connection " +
  112. "username rather than system username", "If this is enabled," +
  113. " the username for the connection will be used rather than " +
  114. "'" + System.getProperty("user.name") + "'"));
  115. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  116. getDomain(), "general.useNickname", "Use connection " +
  117. "nickname rather than system username", "If this is enabled, " +
  118. "the nickname for the connection will be used rather than " +
  119. "'" + System.getProperty("user.name") + "'"));
  120. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  121. getDomain(), "general.useCustomName", "Use custom name" +
  122. " all the time", "If this is enabled, the name specified below" +
  123. " will be used all the time"));
  124. general.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  125. getDomain(), "general.customName", "Custom Name to use",
  126. "The custom name to use when 'Use Custom Name' is enabled"));
  127. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  128. getDomain(), "advanced.alwaysOn", "Always have ident " +
  129. "port open", "By default the identd only runs when there are " +
  130. "active connection attempts. This overrides that."));
  131. advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  132. new PortValidator(), getDomain(), "advanced.port",
  133. "What port should the identd listen on", "Default port is 113," +
  134. " this is probably useless if changed unless you port forward" +
  135. " ident to a different port"));
  136. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  137. getDomain(), "advanced.useCustomSystem", "Use custom OS",
  138. "By default the plugin uses 'UNIX' or 'WIN32' as the system " +
  139. "type, this can be overriden by enabling this."));
  140. advanced.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  141. getDomain(), "advanced.customSystem", "Custom OS to use",
  142. "The custom system to use when 'Use Custom System' is enabled"));
  143. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  144. getDomain(), "advanced.isHiddenUser", "Respond to ident" +
  145. " requests with HIDDEN-USER error", "By default the plugin will" +
  146. " give a USERID response, this can force an 'ERROR :" +
  147. " HIDDEN-USER' response instead."));
  148. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  149. getDomain(), "advanced.isNoUser", "Respond to ident" +
  150. " requests with NO-USER error", "By default the plugin will" +
  151. " give a USERID response, this can force an 'ERROR : NO-USER'" +
  152. " response instead. (Overrides HIDDEN-USER)"));
  153. manager.getCategory("Plugins").addSubCategory(general);
  154. general.addSubCategory(advanced);
  155. }
  156. }