diff --git a/.build.number b/.build.number index 257f8bd..185a02f 100644 --- a/.build.number +++ b/.build.number @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sat Oct 08 12:44:09 CEST 2011 -build.number=47 +#Fri Oct 14 01:25:23 CEST 2011 +build.number=66 diff --git a/src/de/sockenklaus/XmlStats/Settings.java b/src/de/sockenklaus/XmlStats/Settings.java index 2114b23..b15fe36 100644 --- a/src/de/sockenklaus/XmlStats/Settings.java +++ b/src/de/sockenklaus/XmlStats/Settings.java @@ -36,15 +36,15 @@ public class Settings { private Settings(){ File f = new File(XmlStats.getInstance().getDataFolder(), configFilename); - conf = new Configuration(f); + this.conf = new Configuration(f); if(f.exists()){ - conf.load(); + this.conf.load(); } else { - conf.setProperty("options.webserver-enabled", true); - conf.setProperty("options.webserver-port", 9123); - conf.setProperty("options.verbose-enabled", true); - conf.save(); + this.conf.setProperty("options.webserver-enabled", true); + this.conf.setProperty("options.webserver-port", 9123); + this.conf.setProperty("options.verbose-enabled", true); + this.conf.save(); } } @@ -60,7 +60,7 @@ public class Settings { * @return the int */ public int getInt(String path){ - return conf.getInt(path, -1); + return this.conf.getInt(path, -1); } /** @@ -70,7 +70,7 @@ public class Settings { * @return the boolean */ public boolean getBoolean(String path){ - return conf.getBoolean(path, false); + return this.conf.getBoolean(path, false); } /** @@ -80,7 +80,7 @@ public class Settings { * @return the string */ public String getString(String path){ - return conf.getString(path, ""); + return this.conf.getString(path, ""); } /** @@ -90,7 +90,7 @@ public class Settings { * @param value the value */ public void setProperty(String path, Object value){ - conf.setProperty(path, value); + this.conf.setProperty(path, value); } /** diff --git a/src/de/sockenklaus/XmlStats/Webserver.java b/src/de/sockenklaus/XmlStats/Webserver.java index 0dacf13..9b4c000 100644 --- a/src/de/sockenklaus/XmlStats/Webserver.java +++ b/src/de/sockenklaus/XmlStats/Webserver.java @@ -19,9 +19,6 @@ import java.net.InetSocketAddress; import com.sun.net.httpserver.HttpServer; -import de.sockenklaus.XmlStats.Datasource.AchievementsDS; -import de.sockenklaus.XmlStats.Datasource.RegisterDS; -import de.sockenklaus.XmlStats.Datasource.StatsDS; import de.sockenklaus.XmlStats.XmlWorkers.*; // TODO: Auto-generated Javadoc diff --git a/src/de/sockenklaus/XmlStats/XSAuth.java b/src/de/sockenklaus/XmlStats/XSAuth.java new file mode 100644 index 0000000..6087121 --- /dev/null +++ b/src/de/sockenklaus/XmlStats/XSAuth.java @@ -0,0 +1,87 @@ +/** + * + */ +package de.sockenklaus.XmlStats; + +import java.io.File; +import java.util.ArrayList; + +import org.bukkit.util.config.Configuration; + +import de.sockenklaus.XmlStats.Exceptions.XmlStatsException; + +/** + * @author socrates + * + */ +public class XSAuth { + private static XSAuth instance; + + private File authKeyFile; + private Configuration authKeyConf; + private String currentKey; + private String pendingKey; + + private XSAuth(){ + this.authKeyFile = new File(XmlStats.getInstance().getDataFolder(), "auth_keys.yml"); + this.currentKey = ""; + + this.authKeyConf = new Configuration(this.authKeyFile); + if(this.authKeyFile.exists()){ + + this.authKeyConf.load(); + } + else { + this.authKeyConf.setProperty("keys", new ArrayList()); + this.authKeyConf.save(); + } + } + + public static XSAuth getInstance(){ + if(instance == null) instance = new XSAuth(); + return instance; + } + + public boolean whitelistHasKey(String key){ + if(this.authKeyConf.getList("keys") != null && this.authKeyConf.getList("keys").contains(key)) return true; + else return false; + } + + public void authAddKey(String key){ + } + + public void setCurrentKey(String currentKey){ + this.currentKey = currentKey; + } + + public String getCurrentKey(){ + return this.currentKey; + } + + /** + * @throws XmlStatsException + * + */ + public void addCurrentToWhitelist() throws XmlStatsException { + + if(whitelistHasKey(this.currentKey)){ + throw new XmlStatsException("Current key "+this.currentKey+" is already known to the whitelist."); + } + + else if(this.currentKey.equals(this.pendingKey)){ + throw new XmlStatsException("Current key "+this.currentKey+" is already awaiting clearance."); + } + else { + + } + + } + + /** + * + */ + public void remCurrentFromWhitelist() { + // TODO Auto-generated method stub + + } +} diff --git a/src/de/sockenklaus/XmlStats/XmlWorkers/AuthRegister.java b/src/de/sockenklaus/XmlStats/XmlWorkers/AuthRegister.java index ca4b3d5..3a1c5e7 100644 --- a/src/de/sockenklaus/XmlStats/XmlWorkers/AuthRegister.java +++ b/src/de/sockenklaus/XmlStats/XmlWorkers/AuthRegister.java @@ -10,6 +10,7 @@ import java.util.Map; import org.bukkit.util.config.Configuration; import org.w3c.dom.Element; +import de.sockenklaus.XmlStats.XSAuth; import de.sockenklaus.XmlStats.XmlStats; import de.sockenklaus.XmlStats.Exceptions.XmlStatsException; @@ -33,8 +34,20 @@ public class AuthRegister extends XmlWorker { */ @Override protected Element getXml(Map> parameters) throws XmlStatsException { - - if(parameters.containsKey("key")){ + XSAuth authmodule = XSAuth.getInstance(); + + if(authmodule.getCurrentKey().isEmpty()){ + XmlStats.LogWarn("auth_register: There should be a key, but acutally there is no..."); + throw new XmlStatsException("auth_register: There should be a key, but actually there is no..."); + } + else if (parameters.containsKey("delete") && parameters.get("delete").get(0).equals("true")){ + authmodule.remCurrentFromWhitelist(); + } + else { + authmodule.addCurrentToWhitelist(); + } + + /*if(parameters.containsKey("key")){ for (String key : parameters.get("key")){ XmlStats x_temp = XmlStats.getInstance(); File authKeyFile = new File(x_temp.getDataFolder(), this.authKeyFilename); @@ -45,13 +58,13 @@ public class AuthRegister extends XmlWorker { /* * Hier kann geschaut werden, ob der Key in der AuthKey steht * - */ + * return null; } else { /* * Datei existiert nicht, Key kann nicht existieren - */ + * File tempAuthKeyFile = new File(x_temp.getDataFolder(), this.tempAuthKeyFilname); Configuration tempAuthKeyConf = new Configuration(tempAuthKeyFile); @@ -60,7 +73,7 @@ public class AuthRegister extends XmlWorker { if(tempAuthKeyConf.getList("keys") != null && tempAuthKeyConf.getList("keys").contains(key)){ /* * Key existiert schon in auth_keys_tmp... mach was - */ + * return null; } else tempAuthKeyConf.setProperty("keys.key",key); @@ -69,18 +82,16 @@ public class AuthRegister extends XmlWorker { tempAuthKeyConf.setProperty("keys.key", key); /* * Key wurde in auth_keys_tmp eingetragen... jetzt reagieren. - */ + * return null; } tempAuthKeyConf.save(); } } - XmlStats.LogWarn("auth_register: There should be a key, but acutally there is no..."); - throw new XmlStatsException("auth_register: There should be a key, but actually there is no..."); } - else throw new XmlStatsException("No key given!"); + else throw new XmlStatsException("No key given!");*/ } diff --git a/src/de/sockenklaus/XmlStats/XmlWorkers/XmlWorker.java b/src/de/sockenklaus/XmlStats/XmlWorkers/XmlWorker.java index 7a47dbd..e016078 100644 --- a/src/de/sockenklaus/XmlStats/XmlWorkers/XmlWorker.java +++ b/src/de/sockenklaus/XmlStats/XmlWorkers/XmlWorker.java @@ -44,6 +44,7 @@ import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpExchange; +import de.sockenklaus.XmlStats.XSAuth; import de.sockenklaus.XmlStats.XmlStats; import de.sockenklaus.XmlStats.Datasource.Datasource; import de.sockenklaus.XmlStats.Exceptions.XmlStatsException; @@ -115,8 +116,14 @@ public abstract class XmlWorker implements HttpHandler { parameters = parseParameters(queryString); /* - * Create the XML doc stuff.... + * Check whether there is an auth key or not and set the currentKey */ + XSAuth authmodule = XSAuth.getInstance(); + if (parameters.containsKey("authkey") && !parameters.get("authkey").isEmpty()){ + authmodule.setCurrentKey(parameters.get("authkey").get(0)); + } + else authmodule.setCurrentKey(""); + /* * Actually create the XML