Skip to content

Commit

Permalink
Add .gitIgnore for gradle, Java etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantheleach committed Jan 14, 2020
1 parent 0f65fb0 commit 9f1fc7d
Show file tree
Hide file tree
Showing 9 changed files with 522 additions and 0 deletions.
137 changes: 137 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@

# Created by https://www.gitignore.io/api/java,gradle,intellij
# Edit at https://www.gitignore.io/?templates=java,gradle,intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/**/sonarlint/

# SonarQube Plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Gradle ###
.gradle
build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### Gradle Patch ###
**/build/

# End of https://www.gitignore.io/api/java,gradle,intellij
9 changes: 9 additions & 0 deletions takit-DNS-Gradle/src/main/java/org/takit/dns/Messages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.takit.dns;

public class Messages {
public static String PLUGIN_ENABLE = "[%s] Enabled.";
public static String PLUGIN_DISABLE = "[%s] Disabled.";
public static String IP_CHANGED = "[%s] Your IP has changed to %s.";
public static String DOMAIN_NOT_FOUND = "[%s] %s was not found.";
public static String HOST_NOT_FOUND = "[%s] %s was not found.";
}
33 changes: 33 additions & 0 deletions takit-DNS-Gradle/src/main/java/org/takit/dns/Security.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.takit.dns;

import java.security.MessageDigest;

public class Security {
private static String convertToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do {
if ((0 <= halfbyte) && (halfbyte <= 9))
buf.append((char) ('0' + halfbyte));
else
buf.append((char) ('a' + (halfbyte - 10)));
halfbyte = data[i] & 0x0F;
} while(two_halfs++ < 1);
}
return buf.toString();
}

public static String SHA1(String text) {
try {
MessageDigest md =MessageDigest.getInstance("SHA-1");
byte[] sha1hash = new byte[40];
md.update(text.getBytes("iso-8859-1"), 0, text.length());
sha1hash = md.digest();
return convertToHex(sha1hash);
}
catch ( Exception ignore ) {}
return "";
}
}
159 changes: 159 additions & 0 deletions takit-DNS-Gradle/src/main/java/org/takit/dns/TakitDNS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.takit.dns;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.takit.dns.services.Afraid;
import org.takit.dns.services.DnsExit;
import org.takit.dns.services.Dyn;
import org.takit.dns.services.NoIp;

public class TakitDNS extends JavaPlugin {
public static final String FREEDNS_AFRAID_ORG = "freedns.afraid.org";
public static final String DYNS_DNS = "dyn.com";
public static final String NO_IP = "no-ip.com";
public static final String DNS_EXIT = "dnsexit.com";

public static Logger log = Logger.getLogger("Minecraft");

private String username;
private String password;
private String domain;
private long interval;
private String host;

private static String pluginName;

public void onDisable() {
log.info(String.format(Messages.PLUGIN_DISABLE, getDescription().getName()));
}
public void onEnable() {
initConfig();

Runnable runnable = null;
host = host.toLowerCase();
if ( host.equals(FREEDNS_AFRAID_ORG) ) {
runnable = new Afraid(this, username, password, domain);
}
else if ( host.equals(DYNS_DNS) ) {
runnable = new Dyn(this, username, password, domain);
}
else if ( host.equals(NO_IP) ) {
runnable = new NoIp(this, username, password, domain);
}
else if ( host.equals(DNS_EXIT) ) {
runnable = new DnsExit(this, username, password, domain);
}
else {
log.log(Level.WARNING, String.format(
Messages.HOST_NOT_FOUND,
getDescription().getName(),
host
));
}

if ( runnable!=null ) {
this.getServer().getScheduler().scheduleAsyncRepeatingTask(
this,
runnable,
1,
(interval*20)*60
);
}

log.info(String.format(
Messages.PLUGIN_ENABLE,
getDescription().getName()
));
}


private void initConfig() {
pluginName = getDescription().getName();

File file = new File("plugins"+File.separator+"Takit"+File.separator+"dns.yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(file);

if ( !file.exists() ) {
config.set("dns.domain", "your-domain");
config.set("dns.username", "username");
config.set("dns.password", "password");
config.set("dns.interval", 10);
config.set("dns.host", "dns-service");
try {
config.save(file);
config.load(file);
}
catch ( Exception e ) {
e.printStackTrace();
}
}

domain = config.getString("dns.domain");
username = config.getString("dns.username");
password = config.getString("dns.password");
interval = config.getInt("dns.interval");
host = config.getString("dns.host");
}

public static String getIP() {
String ret = getURL("http://checkip.dyndns.com/");
if ( ret!=null ) {
ret = ret.substring(ret.indexOf("Current IP Address: ")+20, ret.indexOf("</body>"));
}
return ret;
}
public static String getURL(String url) {
try {
int needsAuthentication = url.indexOf("@");
if ( needsAuthentication>-1 ) {
int start = url.indexOf("://")+3;
int startOfPassword = url.indexOf(":", start);

final String username = url.substring(start, startOfPassword);
final String password = url.substring(startOfPassword+1, needsAuthentication);
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (username, password.toCharArray());
}
});

url = url.substring(0, start) + url.substring(needsAuthentication+1);
}

URL u = new URL(url);
URLConnection conn = u.openConnection();
conn.setRequestProperty("User-Agent", "org.takit.dns.TakitDNS/0.3.1");
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
Reader in = new InputStreamReader(bis);
StringWriter fileContents = new StringWriter();
for (int b; (b = in.read()) != -1;) {
fileContents.write(b);
}
bis.close();

return ((StringWriter)fileContents).getBuffer().toString();
}
catch ( Exception ignore ) {
log.log(Level.WARNING, String.format(
Messages.HOST_NOT_FOUND,
pluginName,
url
));
}

return null;
}
}
57 changes: 57 additions & 0 deletions takit-DNS-Gradle/src/main/java/org/takit/dns/services/Afraid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.takit.dns.services;

import org.takit.dns.Messages;
import org.takit.dns.Security;
import org.takit.dns.TakitDNS;

public class Afraid implements Runnable {
private TakitDNS plugin;
private String username;
private String password;
private String domain;

public Afraid(TakitDNS instance, String username, String password, String domain) {
this.plugin = instance;
this.username = username;
this.password = password;
this.domain = domain;
}
public void run() {
String currentIP = TakitDNS.getIP();
String file = TakitDNS.getURL(
"http://freedns.afraid.org/api/?action=getdyndns&sha=" +
Security.SHA1(username.toLowerCase()+"|"+password)
);
if ( file==null ) {
return;
}
String[] entries = file.split("\n");
String[] entry = null;
for ( int i=0; i<entries.length; ++i ) {
entry = entries[i].split("\\|");
if ( domain.equals(entry[0]) ) {
break;
}
else {
entry = null;
}
}
if ( entry==null ) {
TakitDNS.log.info(String.format(
Messages.DOMAIN_NOT_FOUND,
plugin.getDescription().getName(),
domain
));
return;
}

if ( !currentIP.equals(entry[1]) ) {
TakitDNS.getURL(entry[2]);
TakitDNS.log.info(String.format(
Messages.IP_CHANGED,
plugin.getDescription().getName(),
currentIP
));
}
}
}
Loading

0 comments on commit 9f1fc7d

Please sign in to comment.