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 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.PreferencesCategory;
  29. import com.dmdirc.config.prefs.PreferencesManager;
  30. import com.dmdirc.config.prefs.PreferencesSetting;
  31. import com.dmdirc.config.prefs.PreferencesType;
  32. import com.dmdirc.config.prefs.validator.PortValidator;
  33. import com.dmdirc.interfaces.ActionListener;
  34. import com.dmdirc.plugins.Plugin;
  35. import java.util.ArrayList;
  36. import java.util.List;
  37. /**
  38. * The Identd plugin answers ident requests from IRC servers.
  39. *
  40. * @author Shane
  41. */
  42. public class IdentdPlugin extends Plugin implements ActionListener {
  43. /** Array list to store all the servers in that need ident replies. */
  44. private final List<Server> servers = new ArrayList<Server>();
  45. /** The IdentdServer that we use. */
  46. private IdentdServer myServer;
  47. /**
  48. * Creates a new instance of IdentdPlugin.
  49. */
  50. public IdentdPlugin() {
  51. }
  52. /**
  53. * Called when the plugin is loaded.
  54. */
  55. @Override
  56. public void onLoad() {
  57. // Add action hooks
  58. ActionManager.addListener(this, CoreActionType.SERVER_CONNECTED, CoreActionType.SERVER_CONNECTING, CoreActionType.SERVER_CONNECTERROR);
  59. myServer = new IdentdServer(this);
  60. if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.alwaysOn")) {
  61. myServer.startServer();
  62. }
  63. }
  64. /**
  65. * Called when this plugin is unloaded.
  66. */
  67. @Override
  68. public void onUnload() {
  69. myServer.stopServer();
  70. servers.clear();
  71. ActionManager.removeListener(this);
  72. }
  73. /**
  74. * Process an event of the specified type.
  75. *
  76. * @param type The type of the event to process
  77. * @param format Format of messages that are about to be sent. (May be null)
  78. * @param arguments The arguments for the event
  79. */
  80. @Override
  81. public void processEvent(final ActionType type, final StringBuffer format, final Object... arguments) {
  82. if (type == CoreActionType.SERVER_CONNECTING) {
  83. synchronized (servers) {
  84. if (servers.isEmpty()) {
  85. myServer.startServer();
  86. }
  87. servers.add((Server) arguments[0]);
  88. }
  89. } else if (type == CoreActionType.SERVER_CONNECTED || type == CoreActionType.SERVER_CONNECTERROR) {
  90. synchronized (servers) {
  91. servers.remove(arguments[0]);
  92. if (servers.isEmpty() && !IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.alwaysOn")) {
  93. myServer.stopServer();
  94. }
  95. }
  96. }
  97. }
  98. /** {@inheritDoc} */
  99. @Override
  100. public void showConfig(final PreferencesManager manager) {
  101. final PreferencesCategory general = new PreferencesCategory("Identd",
  102. "General Identd Plugin config ('Lower' options take priority " +
  103. "over those above them)");
  104. final PreferencesCategory advanced = new PreferencesCategory("Advanced",
  105. "Advanced Identd Plugin config - Only edit these if you need " +
  106. "to/know what you are doing. Editing these could prevent " +
  107. "access to some servers. ('Lower' options take priority over " +
  108. "those above them)");
  109. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  110. getDomain(), "general.useUsername", "Use connection " +
  111. "username rather than system username", "If this is enabled," +
  112. " the username for the connection will be used rather than " +
  113. "'" + System.getProperty("user.name") + "'"));
  114. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  115. getDomain(), "general.useNickname", "Use connection " +
  116. "nickname rather than system username", "If this is enabled, " +
  117. "the nickname for the connection will be used rather than " +
  118. "'" + System.getProperty("user.name") + "'"));
  119. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  120. getDomain(), "general.useCustomName", "Use custom name" +
  121. " all the time", "If this is enabled, the name specified below" +
  122. " will be used all the time"));
  123. general.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  124. getDomain(), "general.customName", "Custom Name to use",
  125. "The custom name to use when 'Use Custom Name' is enabled"));
  126. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  127. getDomain(), "advanced.alwaysOn", "Always have ident " +
  128. "port open", "By default the identd only runs when there are " +
  129. "active connection attempts. This overrides that."));
  130. advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  131. new PortValidator(), getDomain(), "advanced.port",
  132. "What port should the identd listen on", "Default port is 113," +
  133. " this is probably useless if changed unless you port forward" +
  134. " ident to a different port"));
  135. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  136. getDomain(), "advanced.useCustomSystem", "Use custom OS",
  137. "By default the plugin uses 'UNIX' or 'WIN32' as the system " +
  138. "type, this can be overriden by enabling this."));
  139. advanced.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  140. getDomain(), "advanced.customSystem", "Custom OS to use",
  141. "The custom system to use when 'Use Custom System' is enabled"));
  142. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  143. getDomain(), "advanced.isHiddenUser", "Respond to ident" +
  144. " requests with HIDDEN-USER error", "By default the plugin will" +
  145. " give a USERID response, this can force an 'ERROR :" +
  146. " HIDDEN-USER' response instead."));
  147. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  148. getDomain(), "advanced.isNoUser", "Respond to ident" +
  149. " requests with NO-USER error", "By default the plugin will" +
  150. " give a USERID response, this can force an 'ERROR : NO-USER'" +
  151. " response instead. (Overrides HIDDEN-USER)"));
  152. manager.getCategory("Plugins").addSubCategory(general);
  153. general.addSubCategory(advanced);
  154. }
  155. }