Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21364a3f63 | |||
| a0cafa3e62 | |||
|
|
d348e26b49 | ||
|
|
e0080fb1a0 | ||
|
|
40f63bdeeb | ||
|
|
5a247576c4 | ||
|
|
ae8d5bff1d | ||
|
|
3ad2a810f8 | ||
|
|
de9d723416 | ||
|
|
1c93b9fc0e |
68
.clangformat
68
.clangformat
@@ -1,68 +0,0 @@
|
|||||||
---
|
|
||||||
#BasedOnStyle: WebKit
|
|
||||||
TabWidth: '4'
|
|
||||||
IndentWidth: '4'
|
|
||||||
UseTab: 'Always'
|
|
||||||
AlignOperands: 'true'
|
|
||||||
AlignAfterOpenBracket: 'Align'
|
|
||||||
AlignConsecutiveAssignments: 'true'
|
|
||||||
AlignConsecutiveDeclarations: 'true'
|
|
||||||
AlignEscapedNewlines: 'Left'
|
|
||||||
AlignTrailingComments: 'true'
|
|
||||||
AllowAllParametersOfDeclarationOnNextLine: 'true'
|
|
||||||
AllowShortBlocksOnASingleLine: 'false'
|
|
||||||
AllowShortCaseLabelsOnASingleLine: 'false'
|
|
||||||
AllowShortFunctionsOnASingleLine: 'All'
|
|
||||||
AllowShortIfStatementsOnASingleLine: 'false'
|
|
||||||
AllowShortLoopsOnASingleLine: 'false'
|
|
||||||
AlwaysBreakAfterReturnType: 'None'
|
|
||||||
AlwaysBreakTemplateDeclarations: 'true'
|
|
||||||
AlwaysBreakBeforeMultilineStrings: 'false'
|
|
||||||
BinPackArguments: 'false'
|
|
||||||
BinPackParameters: 'false'
|
|
||||||
BreakBeforeBraces: 'Custom'
|
|
||||||
BraceWrapping:
|
|
||||||
AfterEnum: 'true'
|
|
||||||
AfterClass: 'true'
|
|
||||||
AfterControlStatement: 'true'
|
|
||||||
AfterStruct: 'true'
|
|
||||||
AfterFunction: 'true'
|
|
||||||
AfterNamespace: 'true'
|
|
||||||
AfterUnion: 'true'
|
|
||||||
AfterExternBlock: 'true'
|
|
||||||
BeforeCatch: 'true'
|
|
||||||
BeforeElse: 'true'
|
|
||||||
SplitEmptyRecord: 'false'
|
|
||||||
SplitEmptyNamespace: 'false'
|
|
||||||
SplitEmptyFunction: 'false'
|
|
||||||
BreakBeforeBinaryOperators: 'true'
|
|
||||||
BreakBeforeTernaryOperators: 'false'
|
|
||||||
BreakConstructorInitializersBeforeComma: 'false'
|
|
||||||
BreakBeforeInheritanceComma: 'false'
|
|
||||||
BreakStringLiterals: 'true'
|
|
||||||
ColumnLimit: '140'
|
|
||||||
CompactNamespaces: 'false'
|
|
||||||
Cpp11BracedListStyle: 'true'
|
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
|
|
||||||
DerivePointerAlignment: 'false'
|
|
||||||
IndentCaseLabels: 'true'
|
|
||||||
IndentPPDirectives: 'AfterHash'
|
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: 'true'
|
|
||||||
Language: 'Java'
|
|
||||||
NamespaceIndentation: 'All'
|
|
||||||
PointerAlignment: 'Right'
|
|
||||||
ReflowComments: 'true'
|
|
||||||
SortIncludes: 'true'
|
|
||||||
SortUsingDeclarations: 'true'
|
|
||||||
SpaceAfterCStyleCast: 'false'
|
|
||||||
SpaceAfterTemplateKeyword: 'false'
|
|
||||||
SpaceBeforeAssignmentOperators: 'true'
|
|
||||||
SpaceBeforeParens: ControlStatements
|
|
||||||
SpaceInEmptyParentheses: 'false'
|
|
||||||
SpacesInAngles: 'false'
|
|
||||||
SpacesInCStyleCastParentheses: 'false'
|
|
||||||
SpacesInContainerLiterals: 'false'
|
|
||||||
SpacesInParentheses: 'false'
|
|
||||||
SpacesInSquareBrackets: 'false'
|
|
||||||
Standard: 'Auto'
|
|
||||||
...
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
sudo: false
|
|
||||||
dist: trusty
|
|
||||||
language: java
|
|
||||||
jdk:
|
|
||||||
- oraclejdk8
|
|
||||||
91
Minecraft-SSHD-Bukkit/pom.xml
Normal file
91
Minecraft-SSHD-Bukkit/pom.xml
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ryanmichela</groupId>
|
||||||
|
<artifactId>sshd</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Minecraft-SSHD-Bukkit</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<!-- License: This module extends bukkit which is GPL v2 -->
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GPL2</name>
|
||||||
|
<url>http://www.gnu.org/licenses/gpl-2.0.html</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.19.4-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Build -->
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<targetPath>.</targetPath>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>${basedir}/src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
<include>config.yml</include>
|
||||||
|
<include>motd.txt</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.name}-${project.version}</finalName>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- Compile plugin -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<showDeprecation>true</showDeprecation>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -61,7 +61,8 @@ import java.security.SecureRandom;
|
|||||||
* @author Damien Miller
|
* @author Damien Miller
|
||||||
* @version 0.2
|
* @version 0.2
|
||||||
*/
|
*/
|
||||||
public class BCrypt {
|
public class BCrypt
|
||||||
|
{
|
||||||
// BCrypt parameters
|
// BCrypt parameters
|
||||||
private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;
|
private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;
|
||||||
private static final int BCRYPT_SALT_LEN = 16;
|
private static final int BCRYPT_SALT_LEN = 16;
|
||||||
@@ -383,8 +384,8 @@ public class BCrypt {
|
|||||||
* @return base64-encoded string
|
* @return base64-encoded string
|
||||||
* @exception IllegalArgumentException if the length is invalid
|
* @exception IllegalArgumentException if the length is invalid
|
||||||
*/
|
*/
|
||||||
private static String encode_base64(byte d[], int len)
|
private static String encode_base64(byte d[], int len) throws IllegalArgumentException
|
||||||
throws IllegalArgumentException {
|
{
|
||||||
int off = 0;
|
int off = 0;
|
||||||
StringBuffer rs = new StringBuffer();
|
StringBuffer rs = new StringBuffer();
|
||||||
int c1, c2;
|
int c1, c2;
|
||||||
@@ -392,19 +393,23 @@ public class BCrypt {
|
|||||||
if (len <= 0 || len > d.length)
|
if (len <= 0 || len > d.length)
|
||||||
throw new IllegalArgumentException ("Invalid len");
|
throw new IllegalArgumentException ("Invalid len");
|
||||||
|
|
||||||
while (off < len) {
|
while (off < len)
|
||||||
|
{
|
||||||
c1 = d[off++] & 0xff;
|
c1 = d[off++] & 0xff;
|
||||||
rs.append(base64_code[(c1 >> 2) & 0x3f]);
|
rs.append(base64_code[(c1 >> 2) & 0x3f]);
|
||||||
c1 = (c1 & 0x03) << 4;
|
c1 = (c1 & 0x03) << 4;
|
||||||
if (off >= len) {
|
if (off >= len)
|
||||||
|
{
|
||||||
rs.append(base64_code[c1 & 0x3f]);
|
rs.append(base64_code[c1 & 0x3f]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
c2 = d[off++] & 0xff;
|
c2 = d[off++] & 0xff;
|
||||||
c1 |= (c2 >> 4) & 0x0f;
|
c1 |= (c2 >> 4) & 0x0f;
|
||||||
rs.append(base64_code[c1 & 0x3f]);
|
rs.append(base64_code[c1 & 0x3f]);
|
||||||
c1 = (c2 & 0x0f) << 2;
|
c1 = (c2 & 0x0f) << 2;
|
||||||
if (off >= len) {
|
if (off >= len)
|
||||||
|
{
|
||||||
rs.append(base64_code[c1 & 0x3f]);
|
rs.append(base64_code[c1 & 0x3f]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -422,9 +427,11 @@ public class BCrypt {
|
|||||||
* @param x the base64-encoded value
|
* @param x the base64-encoded value
|
||||||
* @return the decoded value of x
|
* @return the decoded value of x
|
||||||
*/
|
*/
|
||||||
private static byte char64(char x) {
|
private static byte char64(char x)
|
||||||
|
{
|
||||||
if ((int)x < 0 || (int)x > index_64.length)
|
if ((int)x < 0 || (int)x > index_64.length)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return index_64[(int)x];
|
return index_64[(int)x];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,8 +444,8 @@ public class BCrypt {
|
|||||||
* @return an array containing the decoded bytes
|
* @return an array containing the decoded bytes
|
||||||
* @throws IllegalArgumentException if maxolen is invalid
|
* @throws IllegalArgumentException if maxolen is invalid
|
||||||
*/
|
*/
|
||||||
private static byte[] decode_base64(String s, int maxolen)
|
private static byte[] decode_base64(String s, int maxolen) throws IllegalArgumentException
|
||||||
throws IllegalArgumentException {
|
{
|
||||||
StringBuffer rs = new StringBuffer();
|
StringBuffer rs = new StringBuffer();
|
||||||
int off = 0, slen = s.length(), olen = 0;
|
int off = 0, slen = s.length(), olen = 0;
|
||||||
byte ret[];
|
byte ret[];
|
||||||
@@ -447,7 +454,8 @@ public class BCrypt {
|
|||||||
if (maxolen <= 0)
|
if (maxolen <= 0)
|
||||||
throw new IllegalArgumentException ("Invalid maxolen");
|
throw new IllegalArgumentException ("Invalid maxolen");
|
||||||
|
|
||||||
while (off < slen - 1 && olen < maxolen) {
|
while (off < slen - 1 && olen < maxolen)
|
||||||
|
{
|
||||||
c1 = char64(s.charAt(off++));
|
c1 = char64(s.charAt(off++));
|
||||||
c2 = char64(s.charAt(off++));
|
c2 = char64(s.charAt(off++));
|
||||||
if (c1 == -1 || c2 == -1)
|
if (c1 == -1 || c2 == -1)
|
||||||
@@ -475,6 +483,7 @@ public class BCrypt {
|
|||||||
ret = new byte[olen];
|
ret = new byte[olen];
|
||||||
for (off = 0; off < olen; off++)
|
for (off = 0; off < olen; off++)
|
||||||
ret[off] = (byte)rs.charAt(off);
|
ret[off] = (byte)rs.charAt(off);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,11 +493,13 @@ public class BCrypt {
|
|||||||
* @param lr an array containing the two 32-bit half blocks
|
* @param lr an array containing the two 32-bit half blocks
|
||||||
* @param off the position in the array of the blocks
|
* @param off the position in the array of the blocks
|
||||||
*/
|
*/
|
||||||
private final void encipher(int lr[], int off) {
|
private final void encipher(int lr[], int off)
|
||||||
|
{
|
||||||
int i, n, l = lr[off], r = lr[off + 1];
|
int i, n, l = lr[off], r = lr[off + 1];
|
||||||
|
|
||||||
l ^= P[0];
|
l ^= P[0];
|
||||||
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) {
|
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;)
|
||||||
|
{
|
||||||
// Feistel substitution on left word
|
// Feistel substitution on left word
|
||||||
n = S[(l >> 24) & 0xff];
|
n = S[(l >> 24) & 0xff];
|
||||||
n += S[0x100 | ((l >> 16) & 0xff)];
|
n += S[0x100 | ((l >> 16) & 0xff)];
|
||||||
@@ -514,12 +525,14 @@ public class BCrypt {
|
|||||||
* current offset into data
|
* current offset into data
|
||||||
* @return the next word of material from data
|
* @return the next word of material from data
|
||||||
*/
|
*/
|
||||||
private static int streamtoword(byte data[], int offp[]) {
|
private static int streamtoword(byte data[], int offp[])
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
int word = 0;
|
int word = 0;
|
||||||
int off = offp[0];
|
int off = offp[0];
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
word = (word << 8) | (data[off] & 0xff);
|
word = (word << 8) | (data[off] & 0xff);
|
||||||
off = (off + 1) % data.length;
|
off = (off + 1) % data.length;
|
||||||
}
|
}
|
||||||
@@ -531,7 +544,8 @@ public class BCrypt {
|
|||||||
/**
|
/**
|
||||||
* Initialise the Blowfish key schedule
|
* Initialise the Blowfish key schedule
|
||||||
*/
|
*/
|
||||||
private void init_key() {
|
private void init_key()
|
||||||
|
{
|
||||||
P = (int[])P_orig.clone();
|
P = (int[])P_orig.clone();
|
||||||
S = (int[])S_orig.clone();
|
S = (int[])S_orig.clone();
|
||||||
}
|
}
|
||||||
@@ -540,7 +554,8 @@ public class BCrypt {
|
|||||||
* Key the Blowfish cipher
|
* Key the Blowfish cipher
|
||||||
* @param key an array containing the key
|
* @param key an array containing the key
|
||||||
*/
|
*/
|
||||||
private void key(byte key[]) {
|
private void key(byte key[])
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
int koffp[] = { 0 };
|
int koffp[] = { 0 };
|
||||||
int lr[] = { 0, 0 };
|
int lr[] = { 0, 0 };
|
||||||
@@ -549,13 +564,15 @@ public class BCrypt {
|
|||||||
for (i = 0; i < plen; i++)
|
for (i = 0; i < plen; i++)
|
||||||
P[i] = P[i] ^ streamtoword(key, koffp);
|
P[i] = P[i] ^ streamtoword(key, koffp);
|
||||||
|
|
||||||
for (i = 0; i < plen; i += 2) {
|
for (i = 0; i < plen; i += 2)
|
||||||
|
{
|
||||||
encipher(lr, 0);
|
encipher(lr, 0);
|
||||||
P[i] = lr[0];
|
P[i] = lr[0];
|
||||||
P[i + 1] = lr[1];
|
P[i + 1] = lr[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < slen; i += 2) {
|
for (i = 0; i < slen; i += 2)
|
||||||
|
{
|
||||||
encipher(lr, 0);
|
encipher(lr, 0);
|
||||||
S[i] = lr[0];
|
S[i] = lr[0];
|
||||||
S[i + 1] = lr[1];
|
S[i + 1] = lr[1];
|
||||||
@@ -569,7 +586,8 @@ public class BCrypt {
|
|||||||
* @param data salt information
|
* @param data salt information
|
||||||
* @param key password information
|
* @param key password information
|
||||||
*/
|
*/
|
||||||
private void ekskey(byte data[], byte key[]) {
|
private void ekskey(byte data[], byte key[])
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
int koffp[] = { 0 }, doffp[] = { 0 };
|
int koffp[] = { 0 }, doffp[] = { 0 };
|
||||||
int lr[] = { 0, 0 };
|
int lr[] = { 0, 0 };
|
||||||
@@ -578,7 +596,8 @@ public class BCrypt {
|
|||||||
for (i = 0; i < plen; i++)
|
for (i = 0; i < plen; i++)
|
||||||
P[i] = P[i] ^ streamtoword(key, koffp);
|
P[i] = P[i] ^ streamtoword(key, koffp);
|
||||||
|
|
||||||
for (i = 0; i < plen; i += 2) {
|
for (i = 0; i < plen; i += 2)
|
||||||
|
{
|
||||||
lr[0] ^= streamtoword(data, doffp);
|
lr[0] ^= streamtoword(data, doffp);
|
||||||
lr[1] ^= streamtoword(data, doffp);
|
lr[1] ^= streamtoword(data, doffp);
|
||||||
encipher(lr, 0);
|
encipher(lr, 0);
|
||||||
@@ -586,7 +605,8 @@ public class BCrypt {
|
|||||||
P[i + 1] = lr[1];
|
P[i + 1] = lr[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < slen; i += 2) {
|
for (i = 0; i < slen; i += 2)
|
||||||
|
{
|
||||||
lr[0] ^= streamtoword(data, doffp);
|
lr[0] ^= streamtoword(data, doffp);
|
||||||
lr[1] ^= streamtoword(data, doffp);
|
lr[1] ^= streamtoword(data, doffp);
|
||||||
encipher(lr, 0);
|
encipher(lr, 0);
|
||||||
@@ -604,7 +624,8 @@ public class BCrypt {
|
|||||||
* of rounds of hashing to apply
|
* of rounds of hashing to apply
|
||||||
* @return an array containing the binary hashed password
|
* @return an array containing the binary hashed password
|
||||||
*/
|
*/
|
||||||
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
|
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds)
|
||||||
|
{
|
||||||
int rounds, i, j;
|
int rounds, i, j;
|
||||||
int cdata[] = (int[])bf_crypt_ciphertext.clone();
|
int cdata[] = (int[])bf_crypt_ciphertext.clone();
|
||||||
int clen = cdata.length;
|
int clen = cdata.length;
|
||||||
@@ -612,24 +633,28 @@ public class BCrypt {
|
|||||||
|
|
||||||
if (log_rounds < 4 || log_rounds > 31)
|
if (log_rounds < 4 || log_rounds > 31)
|
||||||
throw new IllegalArgumentException ("Bad number of rounds");
|
throw new IllegalArgumentException ("Bad number of rounds");
|
||||||
|
|
||||||
rounds = 1 << log_rounds;
|
rounds = 1 << log_rounds;
|
||||||
if (salt.length != BCRYPT_SALT_LEN)
|
if (salt.length != BCRYPT_SALT_LEN)
|
||||||
throw new IllegalArgumentException ("Bad salt length");
|
throw new IllegalArgumentException ("Bad salt length");
|
||||||
|
|
||||||
init_key();
|
init_key();
|
||||||
ekskey(salt, password);
|
ekskey(salt, password);
|
||||||
for (i = 0; i < rounds; i++) {
|
for (i = 0; i < rounds; i++)
|
||||||
|
{
|
||||||
key(password);
|
key(password);
|
||||||
key(salt);
|
key(salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 64; i++) {
|
for (i = 0; i < 64; i++)
|
||||||
|
{
|
||||||
for (j = 0; j < (clen >> 1); j++)
|
for (j = 0; j < (clen >> 1); j++)
|
||||||
encipher(cdata, j << 1);
|
encipher(cdata, j << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = new byte[clen * 4];
|
ret = new byte[clen * 4];
|
||||||
for (i = 0, j = 0; i < clen; i++) {
|
for (i = 0, j = 0; i < clen; i++)
|
||||||
|
{
|
||||||
ret[j++] = (byte)((cdata[i] >> 24) & 0xff);
|
ret[j++] = (byte)((cdata[i] >> 24) & 0xff);
|
||||||
ret[j++] = (byte)((cdata[i] >> 16) & 0xff);
|
ret[j++] = (byte)((cdata[i] >> 16) & 0xff);
|
||||||
ret[j++] = (byte)((cdata[i] >> 8) & 0xff);
|
ret[j++] = (byte)((cdata[i] >> 8) & 0xff);
|
||||||
@@ -645,7 +670,8 @@ public class BCrypt {
|
|||||||
* using BCrypt.gensalt)
|
* using BCrypt.gensalt)
|
||||||
* @return the hashed password
|
* @return the hashed password
|
||||||
*/
|
*/
|
||||||
public static String hashpw(String password, String salt) {
|
public static String hashpw(String password, String salt)
|
||||||
|
{
|
||||||
BCrypt B;
|
BCrypt B;
|
||||||
String real_salt;
|
String real_salt;
|
||||||
byte passwordb[], saltb[], hashed[];
|
byte passwordb[], saltb[], hashed[];
|
||||||
@@ -655,9 +681,11 @@ public class BCrypt {
|
|||||||
|
|
||||||
if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
|
if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
|
||||||
throw new IllegalArgumentException ("Invalid salt version");
|
throw new IllegalArgumentException ("Invalid salt version");
|
||||||
|
|
||||||
if (salt.charAt(2) == '$')
|
if (salt.charAt(2) == '$')
|
||||||
off = 3;
|
off = 3;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
minor = salt.charAt(2);
|
minor = salt.charAt(2);
|
||||||
if (minor != 'a' || salt.charAt(3) != '$')
|
if (minor != 'a' || salt.charAt(3) != '$')
|
||||||
throw new IllegalArgumentException ("Invalid salt revision");
|
throw new IllegalArgumentException ("Invalid salt revision");
|
||||||
@@ -670,9 +698,12 @@ public class BCrypt {
|
|||||||
rounds = Integer.parseInt(salt.substring(off, off + 2));
|
rounds = Integer.parseInt(salt.substring(off, off + 2));
|
||||||
|
|
||||||
real_salt = salt.substring(off + 3, off + 25);
|
real_salt = salt.substring(off + 3, off + 25);
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
|
passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
|
||||||
} catch (UnsupportedEncodingException uee) {
|
}
|
||||||
|
catch (UnsupportedEncodingException uee)
|
||||||
|
{
|
||||||
throw new AssertionError("UTF-8 is not supported");
|
throw new AssertionError("UTF-8 is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,14 +715,17 @@ public class BCrypt {
|
|||||||
rs.append("$2");
|
rs.append("$2");
|
||||||
if (minor >= 'a')
|
if (minor >= 'a')
|
||||||
rs.append(minor);
|
rs.append(minor);
|
||||||
|
|
||||||
rs.append("$");
|
rs.append("$");
|
||||||
if (rounds < 10)
|
if (rounds < 10)
|
||||||
rs.append("0");
|
rs.append("0");
|
||||||
|
|
||||||
rs.append(Integer.toString(rounds));
|
rs.append(Integer.toString(rounds));
|
||||||
rs.append("$");
|
rs.append("$");
|
||||||
rs.append(encode_base64(saltb, saltb.length));
|
rs.append(encode_base64(saltb, saltb.length));
|
||||||
rs.append(encode_base64(hashed,
|
rs.append(encode_base64(hashed,
|
||||||
bf_crypt_ciphertext.length * 4 - 1));
|
bf_crypt_ciphertext.length * 4 - 1));
|
||||||
|
|
||||||
return rs.toString();
|
return rs.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,7 +737,8 @@ public class BCrypt {
|
|||||||
* @param random an instance of SecureRandom to use
|
* @param random an instance of SecureRandom to use
|
||||||
* @return an encoded salt value
|
* @return an encoded salt value
|
||||||
*/
|
*/
|
||||||
public static String gensalt(int log_rounds, SecureRandom random) {
|
public static String gensalt(int log_rounds, SecureRandom random)
|
||||||
|
{
|
||||||
StringBuffer rs = new StringBuffer();
|
StringBuffer rs = new StringBuffer();
|
||||||
byte rnd[] = new byte[BCRYPT_SALT_LEN];
|
byte rnd[] = new byte[BCRYPT_SALT_LEN];
|
||||||
|
|
||||||
@@ -712,6 +747,7 @@ public class BCrypt {
|
|||||||
rs.append("$2a$");
|
rs.append("$2a$");
|
||||||
if (log_rounds < 10)
|
if (log_rounds < 10)
|
||||||
rs.append("0");
|
rs.append("0");
|
||||||
|
|
||||||
rs.append(Integer.toString(log_rounds));
|
rs.append(Integer.toString(log_rounds));
|
||||||
rs.append("$");
|
rs.append("$");
|
||||||
rs.append(encode_base64(rnd, rnd.length));
|
rs.append(encode_base64(rnd, rnd.length));
|
||||||
@@ -725,7 +761,8 @@ public class BCrypt {
|
|||||||
* 2**log_rounds.
|
* 2**log_rounds.
|
||||||
* @return an encoded salt value
|
* @return an encoded salt value
|
||||||
*/
|
*/
|
||||||
public static String gensalt(int log_rounds) {
|
public static String gensalt(int log_rounds)
|
||||||
|
{
|
||||||
return gensalt(log_rounds, new SecureRandom());
|
return gensalt(log_rounds, new SecureRandom());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -735,7 +772,8 @@ public class BCrypt {
|
|||||||
* rounds to apply
|
* rounds to apply
|
||||||
* @return an encoded salt value
|
* @return an encoded salt value
|
||||||
*/
|
*/
|
||||||
public static String gensalt() {
|
public static String gensalt()
|
||||||
|
{
|
||||||
return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
|
return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -746,7 +784,8 @@ public class BCrypt {
|
|||||||
* @param hashed the previously-hashed password
|
* @param hashed the previously-hashed password
|
||||||
* @return true if the passwords match, false otherwise
|
* @return true if the passwords match, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean checkpw(String plaintext, String hashed) {
|
public static boolean checkpw(String plaintext, String hashed)
|
||||||
|
{
|
||||||
return (hashed.compareTo(hashpw(plaintext, hashed)) == 0);
|
return (hashed.compareTo(hashpw(plaintext, hashed)) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,19 +11,19 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class ConfigPasswordAuthenticator implements PasswordAuthenticator {
|
public class ConfigPasswordAuthenticator implements PasswordAuthenticator
|
||||||
|
{
|
||||||
private Map<String, Integer> FailCounts = new HashMap<String, Integer>();
|
private Map<String, Integer> FailCounts = new HashMap<String, Integer>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean authenticate(String username, String password, ServerSession ss)
|
public boolean authenticate(String username, String password, ServerSession ss)
|
||||||
{
|
{
|
||||||
// Depending on our hash type, we have to try and figure out what we're doing.
|
// Depending on our hash type, we have to try and figure out what we're doing.
|
||||||
String HashType = SshdPlugin.GetInstance().PasswordType;
|
String HashType = SshdPlugin.instance.getConfig().getString("PasswordType");
|
||||||
String ConfigHash = SshdPlugin.GetInstance().config.configNode.getNode("Credentials", username.trim(), "password").getString();
|
String ConfigHash = SshdPlugin.instance.getConfig().getString("Credentials." + username.trim() + ".password");
|
||||||
|
|
||||||
if (ConfigHash == null)
|
if (ConfigHash == null)
|
||||||
SshdPlugin.GetInstance().logger.warn("Config has no such user: " + username);
|
SshdPlugin.instance.getLogger().warning("Config has no such user: " + username);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -69,8 +69,8 @@ public class ConfigPasswordAuthenticator implements PasswordAuthenticator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SshdPlugin.GetInstance().logger.info("Failed login for " + username + " using " + HashType + "-based password authentication.");
|
SshdPlugin.instance.getLogger().info("Failed login for " + username + " using " + HashType + "-based password authentication.");
|
||||||
Integer tries = SshdPlugin.GetInstance().LoginRetries;
|
Integer tries = SshdPlugin.instance.getConfig().getInt("LoginRetries", 3);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -83,7 +83,7 @@ public class ConfigPasswordAuthenticator implements PasswordAuthenticator {
|
|||||||
if (this.FailCounts.get(username) >= tries)
|
if (this.FailCounts.get(username) >= tries)
|
||||||
{
|
{
|
||||||
this.FailCounts.put(username, 0);
|
this.FailCounts.put(username, 0);
|
||||||
SshdPlugin.GetInstance().logger.info("Too many failures for " + username + ", disconnecting.");
|
SshdPlugin.instance.getLogger().info("Too many failures for " + username + ", disconnecting.");
|
||||||
ss.close(true);
|
ss.close(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import org.apache.sshd.server.command.CommandFactory;
|
|||||||
import org.apache.sshd.server.channel.ChannelSession;
|
import org.apache.sshd.server.channel.ChannelSession;
|
||||||
import org.apache.sshd.server.Environment;
|
import org.apache.sshd.server.Environment;
|
||||||
import org.apache.sshd.server.ExitCallback;
|
import org.apache.sshd.server.ExitCallback;
|
||||||
import org.spongepowered.api.Sponge;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -14,39 +14,45 @@ import java.io.OutputStream;
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class ConsoleCommandFactory implements CommandFactory {
|
public class ConsoleCommandFactory implements CommandFactory
|
||||||
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Command createCommand(ChannelSession cs, String command) {
|
public Command createCommand(ChannelSession cs, String command)
|
||||||
|
{
|
||||||
return new ConsoleCommand(command);
|
return new ConsoleCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConsoleCommand implements Command {
|
public class ConsoleCommand implements Command
|
||||||
|
{
|
||||||
private String command;
|
private String command;
|
||||||
|
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
private OutputStream err;
|
private OutputStream err;
|
||||||
private ExitCallback callback;
|
private ExitCallback callback;
|
||||||
|
|
||||||
public ConsoleCommand(String command) {
|
public ConsoleCommand(String command)
|
||||||
|
{
|
||||||
this.command = command;
|
this.command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInputStream(InputStream in) {
|
public void setInputStream(InputStream in)
|
||||||
|
{
|
||||||
this.in = in;
|
this.in = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOutputStream(OutputStream out) {
|
public void setOutputStream(OutputStream out)
|
||||||
|
{
|
||||||
this.out = out;
|
this.out = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setErrorStream(OutputStream err) {
|
public void setErrorStream(OutputStream err)
|
||||||
|
{
|
||||||
this.err = err;
|
this.err = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExitCallback(ExitCallback callback) {
|
public void setExitCallback(ExitCallback callback)
|
||||||
|
{
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,16 +61,15 @@ public class ConsoleCommandFactory implements CommandFactory {
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger
|
SshdPlugin.instance.getLogger()
|
||||||
.info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
|
.info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||||
Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.error("Error processing command from SSH -" + e.getMessage());
|
SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
callback.onExit(0);
|
callback.onExit(0);
|
||||||
}
|
}
|
||||||
@@ -4,17 +4,25 @@ package com.ryanmichela.sshd;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.ryanmichela.sshd.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.fusesource.jansi.Ansi;
|
import org.fusesource.jansi.Ansi;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
public class ConsoleLogFormatter
|
public class ConsoleLogFormatter extends Formatter {
|
||||||
{
|
|
||||||
private static final Map<ChatColor, String> replacements = new EnumMap<ChatColor, String>(ChatColor.class);
|
private SimpleDateFormat dateFormat;
|
||||||
|
private static final Map<ChatColor, String> replacements = new EnumMap<ChatColor, String>(ChatColor.class);
|
||||||
|
|
||||||
|
public ConsoleLogFormatter() {
|
||||||
|
this.dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
public static String ColorizeString(String str)
|
public static String ColorizeString(String str)
|
||||||
{
|
{
|
||||||
@@ -58,5 +66,43 @@ public class ConsoleLogFormatter
|
|||||||
result += Ansi.ansi().reset().toString();
|
result += Ansi.ansi().reset().toString();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String format(LogRecord logrecord)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("org.bukkit.craftbukkit.command.ColouredConsoleSender");
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException ignored)
|
||||||
|
{
|
||||||
|
// MEANS WE'RE ON PAPER/TACO/OTHER SHIT
|
||||||
|
colorize(logrecord);
|
||||||
|
}
|
||||||
|
StringBuilder stringbuilder = new StringBuilder();
|
||||||
|
|
||||||
|
stringbuilder.append(" [");
|
||||||
|
stringbuilder.append(this.dateFormat.format(logrecord.getMillis())).append(" ");
|
||||||
|
|
||||||
|
stringbuilder.append(logrecord.getLevel().getName()).append("]: ");
|
||||||
|
stringbuilder.append(this.formatMessage(logrecord));
|
||||||
|
stringbuilder.append('\n');
|
||||||
|
Throwable throwable = logrecord.getThrown();
|
||||||
|
|
||||||
|
if (throwable != null)
|
||||||
|
{
|
||||||
|
StringWriter stringwriter = new StringWriter();
|
||||||
|
|
||||||
|
throwable.printStackTrace(new PrintWriter(stringwriter));
|
||||||
|
stringbuilder.append(stringwriter.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringbuilder.toString().replace("\n", "\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void colorize(LogRecord logrecord)
|
||||||
|
{
|
||||||
|
String result = ColorizeString(logrecord.getMessage());
|
||||||
|
logrecord.setMessage(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,10 +140,10 @@ class Cryptography
|
|||||||
private static byte[] FromHex(String hex) throws NoSuchAlgorithmException
|
private static byte[] FromHex(String hex) throws NoSuchAlgorithmException
|
||||||
{
|
{
|
||||||
byte[] bytes = new byte[hex.length() / 2];
|
byte[] bytes = new byte[hex.length() / 2];
|
||||||
|
|
||||||
for (int i = 0; i < bytes.length; i++)
|
for (int i = 0; i < bytes.length; i++)
|
||||||
{
|
|
||||||
bytes[i] = (byte)Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
|
bytes[i] = (byte)Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
|
||||||
}
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +152,7 @@ class Cryptography
|
|||||||
BigInteger bi = new BigInteger(1, array);
|
BigInteger bi = new BigInteger(1, array);
|
||||||
String hex = bi.toString(16);
|
String hex = bi.toString(16);
|
||||||
int paddingLength = (array.length * 2) - hex.length();
|
int paddingLength = (array.length * 2) - hex.length();
|
||||||
|
|
||||||
if (paddingLength > 0)
|
if (paddingLength > 0)
|
||||||
return String.format("%0" + paddingLength + "d", 0) + hex;
|
return String.format("%0" + paddingLength + "d", 0) + hex;
|
||||||
else
|
else
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import jline.console.ConsoleReader;
|
||||||
|
import org.apache.sshd.common.SshException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Ryan Michela
|
||||||
|
*/
|
||||||
|
public class FlushyStreamHandler extends StreamHandler
|
||||||
|
{
|
||||||
|
private ConsoleReader reader;
|
||||||
|
|
||||||
|
public FlushyStreamHandler(OutputStream out, Formatter formatter, ConsoleReader reader)
|
||||||
|
{
|
||||||
|
super(out, formatter);
|
||||||
|
this.reader = reader;
|
||||||
|
setLevel(Level.INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void publish(LogRecord record)
|
||||||
|
{
|
||||||
|
record.setMessage(record.getMessage().replace("\n", "\n\r"));
|
||||||
|
super.publish(record);
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void flush()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader.print(ConsoleReader.RESET_LINE + "");
|
||||||
|
reader.flush();
|
||||||
|
super.flush();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader.drawLine();
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
reader.getCursorBuffer().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.flush();
|
||||||
|
super.flush();
|
||||||
|
}
|
||||||
|
catch (SshException ex)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(FlushyStreamHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.Cryptography;
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
|
||||||
|
class MkpasswdCommand implements CommandExecutor
|
||||||
|
{
|
||||||
|
// Because Spigot's failed syntax API is really less than ideal (you should be required to add a
|
||||||
|
// SendSyntax function override), we're just always going to return true even for syntax failures
|
||||||
|
// as we will handle the syntax message internally. This also lets us send the messages more
|
||||||
|
// securely to the client without people knowing we're using the command. This prevents password
|
||||||
|
// or hash leakages from the user to other connected users. Plus this syntax will show how
|
||||||
|
// to both use the command and what hashes we support which is important for people who don't
|
||||||
|
// know how to RTFM. - Justin
|
||||||
|
private void SendSyntax(CommandSender sender, boolean invalid)
|
||||||
|
{
|
||||||
|
if (invalid)
|
||||||
|
sender.sendMessage("\u00A7cInvalid Syntax\u00A7r");
|
||||||
|
sender.sendMessage("\u00A7a/mkpasswd <help|hash> <password>\u00A7r");
|
||||||
|
sender.sendMessage("\u00A79Supported Hashes: SHA256, PBKDF2, BCRYPT, PLAIN\u00A7r");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
||||||
|
{
|
||||||
|
String algoritm, password;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Stupid bukkit, we have to concatenate the arguments together if they're using
|
||||||
|
// spaces in their passwords otherwise it won't be as strong as it should be.
|
||||||
|
algoritm = args[0];
|
||||||
|
password = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||||
|
if (password.trim().isEmpty()) // Shortcut to the catch statement below.
|
||||||
|
throw new ArrayIndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
catch (ArrayIndexOutOfBoundsException e)
|
||||||
|
{
|
||||||
|
// ignore it.
|
||||||
|
this.SendSyntax(sender, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasperm = (sender instanceof Player) ? ((Player)sender).hasPermission("sshd.mkpasswd") : true;
|
||||||
|
|
||||||
|
if (hasperm)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String hash = "";
|
||||||
|
// Dumb but whatever. Some people are really dense.
|
||||||
|
if (algoritm.equalsIgnoreCase("PLAIN"))
|
||||||
|
{
|
||||||
|
// I mean c'mon...
|
||||||
|
sender.sendMessage("\u00A79Your Hash: \u00A7cIt's literally your unhashed password.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (algoritm.equalsIgnoreCase("pbkdf2"))
|
||||||
|
hash = Cryptography.PBKDF2_HashPassword(password);
|
||||||
|
else if (algoritm.equalsIgnoreCase("bcrypt"))
|
||||||
|
hash = Cryptography.BCrypt_HashPassword(password);
|
||||||
|
else if (algoritm.equalsIgnoreCase("sha256"))
|
||||||
|
hash = Cryptography.SHA256_HashPassword(password);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.SendSyntax(sender, !algoritm.equalsIgnoreCase("help"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextComponent msg = new TextComponent("\u00A79Your Hash: " + hash + "\u00A7r");
|
||||||
|
msg.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, hash));
|
||||||
|
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to copy the hash!").create()));
|
||||||
|
|
||||||
|
sender.spigot().sendMessage(msg);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// We're console, just print the stack trace.
|
||||||
|
e.printStackTrace();
|
||||||
|
sender.sendMessage("\u00A7cAn error occured. Please check console for details.\u00A7r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sender.sendMessage("\u00A7cPermission Denied.\u00A7r");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
|
||||||
|
public class PermissionUtil
|
||||||
|
{
|
||||||
|
public static Optional<String> GetCredential(String username, String credential)
|
||||||
|
{
|
||||||
|
String Default = SshdPlugin.instance.getConfig().getString("Credentials.$default." + credential);
|
||||||
|
String cred = SshdPlugin.instance.getConfig().getString("Credentials." + username + "." + credential, Default);
|
||||||
|
|
||||||
|
if (cred == null)
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
else if (cred.isEmpty())
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
else
|
||||||
|
return Optional.of(cred);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -26,7 +26,7 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator
|
|||||||
{
|
{
|
||||||
byte[] keyBytes = key.getEncoded();
|
byte[] keyBytes = key.getEncoded();
|
||||||
File keyFile = new File(authorizedKeysDir, username);
|
File keyFile = new File(authorizedKeysDir, username);
|
||||||
Integer tries = SshdPlugin.GetInstance().LoginRetries;
|
Integer tries = SshdPlugin.instance.getConfig().getInt("LoginRetries", 3);
|
||||||
|
|
||||||
if (keyFile.exists())
|
if (keyFile.exists())
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.info(
|
SshdPlugin.instance.getLogger().info(
|
||||||
username + " failed authentication via SSH session using key file " + keyFile.getAbsolutePath());
|
username + " failed authentication via SSH session using key file " + keyFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator
|
|||||||
if (this.FailCounts.get(username) >= tries)
|
if (this.FailCounts.get(username) >= tries)
|
||||||
{
|
{
|
||||||
this.FailCounts.put(username, 0);
|
this.FailCounts.put(username, 0);
|
||||||
SshdPlugin.GetInstance().logger.info("Too many failures for " + username + ", disconnecting.");
|
SshdPlugin.instance.getLogger().info("Too many failures for " + username + ", disconnecting.");
|
||||||
session.close(true);
|
session.close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,12 +67,13 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.error("Failed to process public key " + keyFile.getAbsolutePath() + " " + e.getMessage());
|
e.printStackTrace();
|
||||||
|
SshdPlugin.instance.getLogger().severe("Failed to process public key " + keyFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.error("Could not locate public key for " + username
|
SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username
|
||||||
+ ". Make sure the user's key is named the same as their user name "
|
+ ". Make sure the user's key is named the same as their user name "
|
||||||
+ "without a file extension.");
|
+ "without a file extension.");
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Ryan Michela
|
||||||
|
*/
|
||||||
|
public class ReflectionUtil {
|
||||||
|
|
||||||
|
public static void setProtectedValue(Object o, String field, Object newValue)
|
||||||
|
{
|
||||||
|
setProtectedValue(o.getClass(), o, field, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setProtectedValue(Class c, String field, Object newValue)
|
||||||
|
{
|
||||||
|
setProtectedValue(c, null, field, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setProtectedValue(Class c, Object o, String field, Object newValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
Field f = c.getDeclaredField(field);
|
||||||
|
|
||||||
|
f.setAccessible(true);
|
||||||
|
|
||||||
|
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||||
|
modifiersField.setAccessible(true);
|
||||||
|
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
||||||
|
|
||||||
|
f.set(o, newValue);
|
||||||
|
}
|
||||||
|
catch (NoSuchFieldException | IllegalAccessException ex)
|
||||||
|
{
|
||||||
|
System.out.println("*** " + c.getName() + ":" + ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getProtectedValue(Object obj, String fieldName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class c = obj.getClass();
|
||||||
|
while (c != Object.class)
|
||||||
|
{
|
||||||
|
Field[] fields = c.getDeclaredFields();
|
||||||
|
for (Field f : fields)
|
||||||
|
{
|
||||||
|
if (f.getName() == fieldName)
|
||||||
|
{
|
||||||
|
f.setAccessible(true);
|
||||||
|
return (T) f.get(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c = c.getSuperclass();
|
||||||
|
}
|
||||||
|
System.out.println("*** " + obj.getClass().getName() + ":No such field");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("*** " + obj.getClass().getName() + ":" + ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getProtectedValue(Class c, String field)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Field f = c.getDeclaredField(field);
|
||||||
|
f.setAccessible(true);
|
||||||
|
return (T) f.get(c);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("*** " + c.getName() + ":" + ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object invokeProtectedMethod(Class c, String method, Object... args)
|
||||||
|
{
|
||||||
|
return invokeProtectedMethod(c, null, method, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object invokeProtectedMethod(Object o, String method, Object... args)
|
||||||
|
{
|
||||||
|
return invokeProtectedMethod(o.getClass(), o, method, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object invokeProtectedMethod(Class c, Object o, String method, Object... args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class[] pTypes = new Class[args.length];
|
||||||
|
for (int i = 0; i < args.length; i++)
|
||||||
|
{
|
||||||
|
if (args[i] instanceof Integer)
|
||||||
|
pTypes[i] = int.class;
|
||||||
|
else
|
||||||
|
pTypes[i] = args[i].getClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
Method m = c.getDeclaredMethod(method, pTypes);
|
||||||
|
m.setAccessible(true);
|
||||||
|
return m.invoke(o, args);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("*** " + c.getName() + "." + method + "(): " + ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.jline.ConsoleShellFactory;
|
||||||
|
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
|
||||||
|
import org.apache.sshd.common.session.helpers.AbstractSession;
|
||||||
|
import org.apache.sshd.contrib.server.subsystem.sftp.SimpleAccessControlSftpEventListener;
|
||||||
|
import org.apache.sshd.server.SshServer;
|
||||||
|
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
||||||
|
import org.apache.sshd.server.session.ServerSession;
|
||||||
|
import org.apache.sshd.sftp.server.SftpSubsystemFactory;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Ryan Michela
|
||||||
|
*/
|
||||||
|
public class SshdPlugin extends JavaPlugin
|
||||||
|
{
|
||||||
|
private SshServer sshd;
|
||||||
|
public static SshdPlugin instance;
|
||||||
|
|
||||||
|
public static List<ConfigurationSection> GetSections(ConfigurationSection source)
|
||||||
|
{
|
||||||
|
if (source == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<ConfigurationSection> nodes = new ArrayList<ConfigurationSection>();
|
||||||
|
for (String key : source.getKeys(false))
|
||||||
|
{
|
||||||
|
if (source.isConfigurationSection(key))
|
||||||
|
nodes.add(source.getConfigurationSection(key));
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onLoad()
|
||||||
|
{
|
||||||
|
saveDefaultConfig();
|
||||||
|
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
|
||||||
|
if (!authorizedKeys.exists())
|
||||||
|
authorizedKeys.mkdirs();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File motd = new File(getDataFolder(), "motd.txt");
|
||||||
|
if (!motd.exists())
|
||||||
|
{
|
||||||
|
InputStream link = (getClass().getResourceAsStream("/motd.txt"));
|
||||||
|
Files.copy(link, motd.getAbsoluteFile().toPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't go any lower than INFO or SSHD will cause a stack overflow exception.
|
||||||
|
// SSHD will log that it wrote bites to the output stream, which writes
|
||||||
|
// bytes to the output stream - ad nauseaum.
|
||||||
|
getLogger().setLevel(Level.INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onEnable()
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
sshd = SshServer.setUpDefaultServer();
|
||||||
|
sshd.setPort(getConfig().getInt("Port", 1025));
|
||||||
|
String host = getConfig().getString("ListenAddress", "all");
|
||||||
|
sshd.setHost(host.equals("all") ? null : host);
|
||||||
|
|
||||||
|
File hostKey = new File(getDataFolder(), "hostkey");
|
||||||
|
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
|
||||||
|
|
||||||
|
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey.toPath()));
|
||||||
|
sshd.setShellFactory(new ConsoleShellFactory());
|
||||||
|
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
|
||||||
|
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
|
||||||
|
|
||||||
|
if (getConfig().getBoolean("EnableSFTP", false))
|
||||||
|
{
|
||||||
|
// Handle access control for SFTP.
|
||||||
|
SftpSubsystemFactory.Builder builder = new SftpSubsystemFactory.Builder();
|
||||||
|
builder.addSftpEventListener(new SimpleAccessControlSftpEventListener()
|
||||||
|
{
|
||||||
|
protected boolean isAccessAllowed(ServerSession session, String remote, Path localpath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ConfigurationSection UsernameNamespace = getConfig().getConfigurationSection("Credentials." + session.getUsername() + ".sftp");
|
||||||
|
|
||||||
|
// They don't have SFTP enabled so deny them.
|
||||||
|
if (UsernameNamespace == null || !UsernameNamespace.getBoolean("enabled"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
List<ConfigurationSection> rules = GetSections(UsernameNamespace.getConfigurationSection("rules"));
|
||||||
|
if (rules != null)
|
||||||
|
{
|
||||||
|
for (ConfigurationSection path : rules)
|
||||||
|
{
|
||||||
|
// Check if the requesting path matches
|
||||||
|
if (localpath.toString().matches(path.getName()))
|
||||||
|
{
|
||||||
|
// Check if they have read permissions
|
||||||
|
if (path.getBoolean("readable"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
getLogger().info(String.format("Denied %s read access to \"%s\" matching rule \"%s\"", session.getUsername(), localpath.toString(), path.getName()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UsernameNamespace.getString("default").equalsIgnoreCase("allow");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
// Automatically deny.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isModificationAllowed(ServerSession session, String remote, Path localpath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boolean defaultbool = getConfig().getBoolean("Credentials.$default.sftp.enabled", false);
|
||||||
|
ConfigurationSection UsernameNamespace = getConfig().getConfigurationSection("Credentials." + session.getUsername() + ".sftp");
|
||||||
|
|
||||||
|
// They don't have SFTP enabled so deny them.
|
||||||
|
if (UsernameNamespace == null || !UsernameNamespace.getBoolean("enabled", defaultbool))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check a list of files against a path trying to be accessed.
|
||||||
|
List<ConfigurationSection> rules = GetSections(UsernameNamespace.getConfigurationSection("rules"));
|
||||||
|
if (rules != null)
|
||||||
|
{
|
||||||
|
for (ConfigurationSection path : rules)
|
||||||
|
{
|
||||||
|
// Check if the requesting path matches
|
||||||
|
if (localpath.toString().matches(path.getName()))
|
||||||
|
{
|
||||||
|
// Check if they have read permissions
|
||||||
|
if (path.getBoolean("writeable"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
getLogger().info(String.format("Denied %s modifications to \"%s\" matching rule \"%s\"", session.getUsername(), localpath.toString(), path.getName()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UsernameNamespace.getString("default", "deny").equalsIgnoreCase("allow");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
// Automatically deny.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sshd.setSubsystemFactories(Collections.singletonList(builder.build()));
|
||||||
|
sshd.setFileSystemFactory(new VirtualFileSystemFactory(FileSystems.getDefault().getPath(getDataFolder().getAbsolutePath()).getParent().getParent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getCommand("mkpasswd").setExecutor(new MkpasswdCommand());
|
||||||
|
|
||||||
|
sshd.setCommandFactory(new ConsoleCommandFactory());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sshd.start();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
getLogger().log(Level.SEVERE, "Failed to start SSH server! ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Terminate any active sessions
|
||||||
|
for (AbstractSession as : sshd.getActiveSessions())
|
||||||
|
as.close(true);
|
||||||
|
// Pass "true" to stop immediately!
|
||||||
|
sshd.stop(true);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.core.Appender;
|
||||||
|
import org.apache.logging.log4j.core.ErrorHandler;
|
||||||
|
import org.apache.logging.log4j.core.Layout;
|
||||||
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.StreamHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2014 Ryan Michela
|
||||||
|
*/
|
||||||
|
public class StreamHandlerAppender implements Appender
|
||||||
|
{
|
||||||
|
|
||||||
|
private StreamHandler streamHandler;
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
public StreamHandlerAppender(StreamHandler streamHandler)
|
||||||
|
{
|
||||||
|
this.streamHandler = streamHandler;
|
||||||
|
uuid = UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void append(LogEvent logEvent)
|
||||||
|
{
|
||||||
|
java.util.logging.Level level;
|
||||||
|
|
||||||
|
if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.DEBUG))
|
||||||
|
level = java.util.logging.Level.FINE;
|
||||||
|
else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.INFO))
|
||||||
|
level = java.util.logging.Level.INFO;
|
||||||
|
else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.WARN))
|
||||||
|
level = java.util.logging.Level.WARNING;
|
||||||
|
else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.ERROR))
|
||||||
|
level = java.util.logging.Level.SEVERE;
|
||||||
|
else
|
||||||
|
level = java.util.logging.Level.INFO;
|
||||||
|
|
||||||
|
|
||||||
|
String message = logEvent.getMessage().getFormattedMessage();
|
||||||
|
LogRecord logRecord = new LogRecord(level, message);
|
||||||
|
streamHandler.publish(logRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "StreamHandlerAppender:" + uuid.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Layout<? extends Serializable> getLayout()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean ignoreExceptions()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ErrorHandler getHandler()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHandler(ErrorHandler errorHandler)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public State getState() {
|
||||||
|
// Todo: i am not sure what is this
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
// Todo: i am not sure what is this
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStarted()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStopped()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,11 @@ import java.util.concurrent.ExecutionException;
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public abstract class Waitable<T> implements Runnable {
|
public abstract class Waitable<T> implements Runnable
|
||||||
|
{
|
||||||
|
|
||||||
private enum Status {
|
private enum Status
|
||||||
|
{
|
||||||
WAITING,
|
WAITING,
|
||||||
RUNNING,
|
RUNNING,
|
||||||
FINISHED,
|
FINISHED,
|
||||||
@@ -17,19 +19,28 @@ public abstract class Waitable<T> implements Runnable {
|
|||||||
T value = null;
|
T value = null;
|
||||||
Status status = Status.WAITING;
|
Status status = Status.WAITING;
|
||||||
|
|
||||||
public final void run() {
|
public final void run()
|
||||||
synchronized (this) {
|
{
|
||||||
if (status != Status.WAITING) {
|
synchronized (this)
|
||||||
|
{
|
||||||
|
if (status != Status.WAITING)
|
||||||
throw new IllegalStateException("Invalid state " + status);
|
throw new IllegalStateException("Invalid state " + status);
|
||||||
}
|
|
||||||
status = Status.RUNNING;
|
status = Status.RUNNING;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
|
try
|
||||||
|
{
|
||||||
value = evaluate();
|
value = evaluate();
|
||||||
} catch (Throwable t) {
|
}
|
||||||
|
catch (Throwable t)
|
||||||
|
{
|
||||||
this.t = t;
|
this.t = t;
|
||||||
} finally {
|
}
|
||||||
synchronized (this) {
|
finally
|
||||||
|
{
|
||||||
|
synchronized (this)
|
||||||
|
{
|
||||||
status = Status.FINISHED;
|
status = Status.FINISHED;
|
||||||
this.notifyAll();
|
this.notifyAll();
|
||||||
}
|
}
|
||||||
@@ -38,13 +49,14 @@ public abstract class Waitable<T> implements Runnable {
|
|||||||
|
|
||||||
protected abstract T evaluate();
|
protected abstract T evaluate();
|
||||||
|
|
||||||
public synchronized T get() throws InterruptedException, ExecutionException {
|
public synchronized T get() throws InterruptedException, ExecutionException
|
||||||
while (status != Status.FINISHED) {
|
{
|
||||||
|
while (status != Status.FINISHED)
|
||||||
this.wait();
|
this.wait();
|
||||||
}
|
|
||||||
if (t != null) {
|
if (t != null)
|
||||||
throw new ExecutionException(t);
|
throw new ExecutionException(t);
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
package com.ryanmichela.sshd.implementations.commandsenders;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||||
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.jline.ConsoleShellFactory;
|
||||||
|
import com.ryanmichela.sshd.ConsoleLogFormatter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class SSHDCommandSender implements ConsoleCommandSender, CommandSender
|
||||||
|
{
|
||||||
|
private final PermissibleBase perm = new PermissibleBase(this);
|
||||||
|
private final SSHDConversationTracker conversationTracker = new SSHDConversationTracker();
|
||||||
|
// Set by the upstream allocating function
|
||||||
|
public ConsoleShellFactory.ConsoleShell console;
|
||||||
|
|
||||||
|
public void sendMessage(String message)
|
||||||
|
{
|
||||||
|
this.sendRawMessage(message + "\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRawMessage(String message)
|
||||||
|
{
|
||||||
|
// What the fuck does this code even do? Are we sending to one client or all of them?
|
||||||
|
if (this.console.ConsoleReader == null)
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.console.ConsoleReader.println(ConsoleLogFormatter.ColorizeString(message).replace("\n", "\n\r"));
|
||||||
|
this.console.ConsoleReader.print(this.console.ConsoleReader.RESET_LINE + "");
|
||||||
|
this.console.ConsoleReader.flush();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.console.ConsoleReader.drawLine();
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
this.console.ConsoleReader.getCursorBuffer().clear();
|
||||||
|
}
|
||||||
|
this.console.ConsoleReader.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error sending message to SSHDCommandSender", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRawMessage(UUID uuid, String s) {
|
||||||
|
sendRawMessage(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String[] messages)
|
||||||
|
{
|
||||||
|
Arrays.asList(messages).forEach(this::sendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(UUID uuid, String s) {
|
||||||
|
sendMessage(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(UUID uuid, String... strings) {
|
||||||
|
sendMessage(strings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "SSHD Console";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOp()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOp(boolean value)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Cannot change operator status of server console");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean beginConversation(Conversation conversation)
|
||||||
|
{
|
||||||
|
return this.conversationTracker.beginConversation(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abandonConversation(Conversation conversation)
|
||||||
|
{
|
||||||
|
this.conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details)
|
||||||
|
{
|
||||||
|
this.conversationTracker.abandonConversation(conversation, details);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void acceptConversationInput(String input)
|
||||||
|
{
|
||||||
|
this.conversationTracker.acceptConversationInput(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConversing()
|
||||||
|
{
|
||||||
|
return this.conversationTracker.isConversing();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermissionSet(String name)
|
||||||
|
{
|
||||||
|
return this.perm.isPermissionSet(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermissionSet(Permission perm)
|
||||||
|
{
|
||||||
|
return this.perm.isPermissionSet(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(String name)
|
||||||
|
{
|
||||||
|
return this.perm.hasPermission(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(Permission perm)
|
||||||
|
{
|
||||||
|
return this.perm.hasPermission(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value)
|
||||||
|
{
|
||||||
|
return this.perm.addAttachment(plugin, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin)
|
||||||
|
{
|
||||||
|
return this.perm.addAttachment(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks)
|
||||||
|
{
|
||||||
|
return this.perm.addAttachment(plugin, name, value, ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, int ticks)
|
||||||
|
{
|
||||||
|
return this.perm.addAttachment(plugin, ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAttachment(PermissionAttachment attachment)
|
||||||
|
{
|
||||||
|
this.perm.removeAttachment(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recalculatePermissions()
|
||||||
|
{
|
||||||
|
this.perm.recalculatePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<PermissionAttachmentInfo> getEffectivePermissions()
|
||||||
|
{
|
||||||
|
return this.perm.getEffectivePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayer()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server getServer()
|
||||||
|
{
|
||||||
|
return Bukkit.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSender.Spigot spigot()
|
||||||
|
{
|
||||||
|
return ((CommandSender)this).spigot();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package com.ryanmichela.sshd.implementations.commandsenders;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class SSHDConversationTracker
|
||||||
|
{
|
||||||
|
private LinkedList<Conversation> conversationQueue = new LinkedList<>();
|
||||||
|
|
||||||
|
synchronized boolean beginConversation(Conversation conversation)
|
||||||
|
{
|
||||||
|
if (!this.conversationQueue.contains(conversation))
|
||||||
|
{
|
||||||
|
this.conversationQueue.addLast(conversation);
|
||||||
|
if (this.conversationQueue.getFirst() == conversation)
|
||||||
|
{
|
||||||
|
conversation.begin();
|
||||||
|
conversation.outputNextPrompt();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void abandonConversation(Conversation conversation, ConversationAbandonedEvent details)
|
||||||
|
{
|
||||||
|
if (!this.conversationQueue.isEmpty())
|
||||||
|
{
|
||||||
|
if (this.conversationQueue.getFirst() == conversation)
|
||||||
|
conversation.abandon(details);
|
||||||
|
|
||||||
|
if (this.conversationQueue.contains(conversation))
|
||||||
|
this.conversationQueue.remove(conversation);
|
||||||
|
|
||||||
|
if (!this.conversationQueue.isEmpty())
|
||||||
|
this.conversationQueue.getFirst().outputNextPrompt();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void abandonAllConversations()
|
||||||
|
{
|
||||||
|
LinkedList<Conversation> oldQueue = this.conversationQueue;
|
||||||
|
this.conversationQueue = new LinkedList<>();
|
||||||
|
|
||||||
|
for (Conversation conversation : oldQueue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
conversation.abandon(new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||||
|
}
|
||||||
|
catch (Throwable var5)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Unexpected exception while abandoning a conversation", var5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void acceptConversationInput(String input)
|
||||||
|
{
|
||||||
|
if (this.isConversing())
|
||||||
|
{
|
||||||
|
Conversation conversation = this.conversationQueue.getFirst();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
conversation.acceptInput(input);
|
||||||
|
}
|
||||||
|
catch (Throwable var4)
|
||||||
|
{
|
||||||
|
conversation.getContext().getPlugin().getLogger().log(Level.WARNING, String.format("Plugin %s generated an exception whilst handling conversation input", conversation.getContext().getPlugin().getDescription().getFullName()), var4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized boolean isConversing()
|
||||||
|
{
|
||||||
|
return !this.conversationQueue.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isConversingModaly()
|
||||||
|
{
|
||||||
|
return this.isConversing() && this.conversationQueue.getFirst().isModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd.jline;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.ReflectionUtil;
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
import com.ryanmichela.sshd.Waitable;
|
||||||
import jline.console.completer.Completer;
|
import jline.console.completer.Completer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.spongepowered.api.Sponge;
|
import org.bukkit.command.CommandMap;
|
||||||
import org.spongepowered.api.scheduler.SpongeExecutorService;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@@ -15,50 +17,38 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class ConsoleCommandCompleter implements Completer
|
public class ConsoleCommandCompleter implements Completer
|
||||||
{
|
{
|
||||||
private SpongeExecutorService MinecraftExecutor;
|
|
||||||
|
|
||||||
public ConsoleCommandCompleter()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
this.MinecraftExecutor = Sponge.getScheduler().createSyncExecutor(SshdPlugin.GetInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates)
|
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates)
|
||||||
{
|
{
|
||||||
Waitable<List<String>> waitable = new Waitable<List<String>>()
|
Waitable<List<String>> waitable = new Waitable<List<String>>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected List<String> evaluate()
|
protected List<String> evaluate()
|
||||||
{
|
{
|
||||||
return Sponge.getCommandManager().getSuggestions(Sponge.getServer().getConsole(), buffer, null);
|
CommandMap commandMap = ReflectionUtil.getProtectedValue(Bukkit.getServer(), "commandMap");
|
||||||
|
return commandMap.tabComplete(Bukkit.getServer().getConsoleSender(), buffer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.MinecraftExecutor.execute(waitable);
|
Bukkit.getScheduler().runTask(SshdPlugin.instance, waitable);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<String> offers = waitable.get();
|
List<String> offers = waitable.get();
|
||||||
if (offers == null)
|
if (offers == null)
|
||||||
{
|
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
|
||||||
candidates.addAll(offers);
|
candidates.addAll(offers);
|
||||||
|
|
||||||
final int lastSpace = buffer.lastIndexOf(' ');
|
final int lastSpace = buffer.lastIndexOf(' ');
|
||||||
if (lastSpace == -1)
|
if (lastSpace == -1)
|
||||||
{
|
|
||||||
return cursor - buffer.length();
|
return cursor - buffer.length();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return cursor - (buffer.length() - lastSpace - 1);
|
return cursor - (buffer.length() - lastSpace - 1);
|
||||||
}
|
}
|
||||||
}
|
catch (ExecutionException e)
|
||||||
catch (ExecutionException e)
|
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.warn("Unhandled exception when tab completing", e);
|
SshdPlugin.instance.getLogger().log(Level.WARNING, "Unhandled exception when tab completing", e);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,16 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd.jline;
|
||||||
|
|
||||||
import com.ryanmichela.sshd.ConsoleCommandCompleter;
|
import com.ryanmichela.sshd.*;
|
||||||
import com.ryanmichela.sshd.ConsoleLogFormatter;
|
import com.ryanmichela.sshd.implementations.commandsenders.SSHDCommandSender;
|
||||||
import com.ryanmichela.sshd.FlushyOutputStream;
|
|
||||||
import com.ryanmichela.sshd.SshTerminal;
|
|
||||||
import com.ryanmichela.sshd.SshdPlugin;
|
|
||||||
import com.ryanmichela.sshd.StreamHandlerAppender;
|
|
||||||
import com.ryanmichela.sshd.implementations.SSHDCommandSender;
|
|
||||||
import com.ryanmichela.sshd.ConsoleLogFormatter;
|
|
||||||
import jline.console.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.core.Logger;
|
import org.apache.logging.log4j.core.Logger;
|
||||||
import org.apache.sshd.common.Factory;
|
|
||||||
import org.apache.sshd.server.shell.ShellFactory;
|
import org.apache.sshd.server.shell.ShellFactory;
|
||||||
import org.apache.sshd.server.command.Command;
|
import org.apache.sshd.server.command.Command;
|
||||||
import org.apache.sshd.server.channel.ChannelSession;
|
import org.apache.sshd.server.channel.ChannelSession;
|
||||||
import org.apache.sshd.server.Environment;
|
import org.apache.sshd.server.Environment;
|
||||||
import org.apache.sshd.server.ExitCallback;
|
import org.apache.sshd.server.ExitCallback;
|
||||||
import org.spongepowered.api.MinecraftVersion;
|
import org.bukkit.Bukkit;
|
||||||
import org.spongepowered.api.Platform;
|
|
||||||
import org.spongepowered.api.Sponge;
|
|
||||||
import org.spongepowered.api.command.CommandManager;
|
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
|
||||||
import org.spongepowered.api.scheduler.SpongeExecutorService;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -32,17 +20,21 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.StringTokenizer;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.StreamHandler;
|
import java.util.logging.StreamHandler;
|
||||||
|
|
||||||
public class ConsoleShellFactory implements ShellFactory {
|
public class ConsoleShellFactory implements ShellFactory
|
||||||
|
{
|
||||||
|
|
||||||
public Command createShell(ChannelSession cs) {
|
public Command createShell(ChannelSession cs)
|
||||||
|
{
|
||||||
return new ConsoleShell();
|
return new ConsoleShell();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConsoleShell implements Command, Runnable {
|
public class ConsoleShell implements Command, Runnable
|
||||||
|
{
|
||||||
|
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
@@ -56,35 +48,43 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
public ConsoleReader ConsoleReader;
|
public ConsoleReader ConsoleReader;
|
||||||
public SSHDCommandSender SshdCommandSender;
|
public SSHDCommandSender SshdCommandSender;
|
||||||
|
|
||||||
public InputStream getIn() {
|
public InputStream getIn()
|
||||||
|
{
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutputStream getOut() {
|
public OutputStream getOut()
|
||||||
|
{
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutputStream getErr() {
|
public OutputStream getErr()
|
||||||
|
{
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Environment getEnvironment() {
|
public Environment getEnvironment()
|
||||||
|
{
|
||||||
return environment;
|
return environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInputStream(InputStream in) {
|
public void setInputStream(InputStream in)
|
||||||
|
{
|
||||||
this.in = in;
|
this.in = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOutputStream(OutputStream out) {
|
public void setOutputStream(OutputStream out)
|
||||||
|
{
|
||||||
this.out = out;
|
this.out = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setErrorStream(OutputStream err) {
|
public void setErrorStream(OutputStream err)
|
||||||
|
{
|
||||||
this.err = err;
|
this.err = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExitCallback(ExitCallback callback) {
|
public void setExitCallback(ExitCallback callback)
|
||||||
|
{
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,23 +93,36 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
String username = env.getEnv().get(Environment.ENV_USER);
|
||||||
|
Optional<String> optcred = PermissionUtil.GetCredential(username, "console");
|
||||||
|
// They don't have access.
|
||||||
|
if (optcred.isPresent() && !optcred.get().contains("R"))
|
||||||
|
{
|
||||||
|
cs.close(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SshdPlugin.instance.getLogger().warning("There is no $default pseudo-user under credential, allowing unrestricted access...");
|
||||||
|
|
||||||
this.ConsoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
|
this.ConsoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
|
||||||
this.ConsoleReader.setExpandEvents(true);
|
this.ConsoleReader.setExpandEvents(true);
|
||||||
this.ConsoleReader.addCompleter(new ConsoleCommandCompleter());
|
this.ConsoleReader.addCompleter(new ConsoleCommandCompleter());
|
||||||
|
|
||||||
this.streamHandlerAppender = new StreamHandlerAppender(this.ConsoleReader);
|
StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), this.ConsoleReader);
|
||||||
|
this.streamHandlerAppender = new StreamHandlerAppender(streamHandler);
|
||||||
|
|
||||||
((Logger)LogManager.getRootLogger()).addAppender(this.streamHandlerAppender);
|
((Logger)LogManager.getRootLogger()).addAppender(this.streamHandlerAppender);
|
||||||
|
|
||||||
this.environment = env;
|
this.environment = env;
|
||||||
this.Username = env.getEnv().get(Environment.ENV_USER);
|
this.Username = username;
|
||||||
this.SshdCommandSender = new SSHDCommandSender();
|
this.SshdCommandSender = new SSHDCommandSender();
|
||||||
this.SshdCommandSender.console = this;
|
this.SshdCommandSender.console = this;
|
||||||
thread = new Thread(this, "SSHD ConsoleShell " + this.Username);
|
thread = new Thread(this, "SSHD ConsoleShell " + username);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
e.printStackTrace();
|
||||||
throw new IOException("Error starting shell", e);
|
throw new IOException("Error starting shell", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,15 +134,11 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get the sponge command manager so we can execute commands.
|
if (!SshdPlugin.instance.getConfig().getString("Mode", "DEFAULT").equals("RPC"))
|
||||||
CommandManager CmdManager = Sponge.getCommandManager();
|
|
||||||
SpongeExecutorService MinecraftExecutor = Sponge.getScheduler().createSyncExecutor(SshdPlugin.GetInstance());
|
|
||||||
// Print the SSHD motd.
|
|
||||||
if (!SshdPlugin.GetInstance().Mode.equals("RPC"))
|
|
||||||
printPreamble(this.ConsoleReader);
|
printPreamble(this.ConsoleReader);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
String command = this.ConsoleReader.readLine("\r> ", null);
|
String command = this.ConsoleReader.readLine("\r>", null);
|
||||||
// The user sent CTRL+D to close the shell, terminate the session.
|
// The user sent CTRL+D to close the shell, terminate the session.
|
||||||
if (command == null)
|
if (command == null)
|
||||||
break;
|
break;
|
||||||
@@ -149,14 +158,19 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
}
|
}
|
||||||
// Hide the mkpasswd command input from other users.
|
// Hide the mkpasswd command input from other users.
|
||||||
Boolean mkpasswd = command.split(" ")[0].equals("mkpasswd");
|
Boolean mkpasswd = command.split(" ")[0].equals("mkpasswd");
|
||||||
|
Optional<String> optcred = PermissionUtil.GetCredential(this.Username, "console");
|
||||||
|
|
||||||
MinecraftExecutor.submit(() ->
|
if (optcred.isPresent() && !optcred.get().contains("W"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTask(
|
||||||
|
SshdPlugin.instance, () ->
|
||||||
{
|
{
|
||||||
if (SshdPlugin.GetInstance().Mode.equals("RPC") && command.startsWith("rpc"))
|
if (SshdPlugin.instance.getConfig().getString("Mode", "DEFAULT").equals("RPC") && command.startsWith("rpc"))
|
||||||
{
|
{
|
||||||
// NO ECHO NO PREAMBLE AND SHIT
|
// NO ECHO NO PREAMBLE AND SHIT
|
||||||
String cmd = command.substring("rpc".length() + 1, command.length());
|
String cmd = command.substring("rpc".length() + 1, command.length());
|
||||||
CmdManager.process(this.SshdCommandSender, cmd);
|
Bukkit.dispatchCommand(this.SshdCommandSender, cmd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -165,31 +179,46 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
// our plugin and the connected client.
|
// our plugin and the connected client.
|
||||||
if (!mkpasswd)
|
if (!mkpasswd)
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.info("<" + this.Username + "> " + command);
|
SshdPlugin.instance.getLogger().info("<" + this.Username + "> " + command);
|
||||||
CmdManager.process(Sponge.getServer().getConsole(), command);
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CmdManager.process(this.SshdCommandSender, command);
|
Bukkit.dispatchCommand(this.SshdCommandSender, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.error("Error processing command from SSH", e);
|
e.printStackTrace();
|
||||||
|
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error processing command from SSH", e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.info(this.Username + " disconnected from SSH.");
|
SshdPlugin.instance.getLogger().log(Level.INFO, this.Username + " disconnected from SSH.");
|
||||||
callback.onExit(0);
|
callback.onExit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String GetHostname()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return InetAddress.getLocalHost().getHostName();
|
||||||
|
}
|
||||||
|
catch (UnknownHostException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
SshdPlugin.instance.getLogger().log(Level.INFO, "The above stacktrace can be ignored, you likely have a misconfigured system hosts file.");
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void printPreamble(ConsoleReader cr) throws IOException
|
private void printPreamble(ConsoleReader cr) throws IOException
|
||||||
{
|
{
|
||||||
File f = new File(SshdPlugin.GetInstance().ConfigDir.toFile(), "motd.txt");
|
File f = new File(SshdPlugin.instance.getDataFolder(), "motd.txt");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BufferedReader br = new BufferedReader(new FileReader(f));
|
BufferedReader br = new BufferedReader(new FileReader(f));
|
||||||
@@ -200,26 +229,17 @@ public class ConsoleShellFactory implements ShellFactory {
|
|||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
catch (FileNotFoundException e)
|
||||||
{
|
{
|
||||||
SshdPlugin.GetInstance().logger.warn("Could not open " + f + ": File does not exist.");
|
e.printStackTrace();
|
||||||
|
SshdPlugin.instance.getLogger().log(Level.WARNING, "Could not open " + f + ": File does not exist.");
|
||||||
// Not showing the SSH motd is not a fatal failure, let the session continue.
|
// Not showing the SSH motd is not a fatal failure, let the session continue.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doesn't really guarantee our actual system hostname but
|
// Doesn't really guarantee our actual system hostname but
|
||||||
// it's better than not having one at all.
|
// it's better than not having one at all.
|
||||||
Platform p = Sponge.getPlatform();
|
cr.println("Connected to: " + this.GetHostname() + " (" + Bukkit.getServer().getName() + ")\r");
|
||||||
MinecraftVersion mv = p.getMinecraftVersion();
|
cr.println(ConsoleLogFormatter.ColorizeString(Bukkit.getServer().getMotd()).replaceAll("\n", "\r\n"));
|
||||||
PluginContainer pc = p.getContainer(Platform.Component.API);
|
|
||||||
String str = String.format(
|
|
||||||
"Connected to: %s -- Minecraft %s (%s %s)",
|
|
||||||
InetAddress.getLocalHost().getHostName(),
|
|
||||||
mv.getName(),
|
|
||||||
pc.getName(),
|
|
||||||
pc.getVersion().orElse("<Unknown>"));
|
|
||||||
|
|
||||||
cr.println(str + "\r");
|
|
||||||
cr.println(ConsoleLogFormatter.ColorizeString(Sponge.getServer().getMotd().toPlain()).replaceAll("\n", "\r\n"));
|
|
||||||
cr.println("\r");
|
cr.println("\r");
|
||||||
cr.println("Type 'exit' or CTRL+D to exit the shell." + "\r");
|
cr.println("Type 'exit' to exit the shell." + "\r");
|
||||||
cr.println("===============================================" + "\r");
|
cr.println("===============================================" + "\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd.jline;
|
||||||
|
|
||||||
import jline.TerminalSupport;
|
import jline.TerminalSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class SshTerminal extends TerminalSupport {
|
public class SshTerminal extends TerminalSupport
|
||||||
|
{
|
||||||
protected SshTerminal() {
|
public SshTerminal()
|
||||||
|
{
|
||||||
super(true);
|
super(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws Exception {
|
public void init() throws Exception
|
||||||
|
{
|
||||||
setAnsiSupported(true);
|
setAnsiSupported(true);
|
||||||
setEchoEnabled(true);
|
setEchoEnabled(true);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,350 @@
|
|||||||
|
package org.slf4j.impl;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
import org.slf4j.ILoggerFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.Marker;
|
||||||
|
import org.slf4j.helpers.FormattingTuple;
|
||||||
|
import org.slf4j.helpers.MessageFormatter;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Ryan Michela
|
||||||
|
*/
|
||||||
|
public class PluginSlf4jFactory implements ILoggerFactory {
|
||||||
|
@Override
|
||||||
|
public Logger getLogger(String name) {
|
||||||
|
return new PluginSlf4jAdapter(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PluginSlf4jAdapter implements Logger {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private boolean isEnabled(Level level) {
|
||||||
|
return SshdPlugin.instance != null && SshdPlugin.instance.getLogger().isLoggable(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(Level level, String s, Object[] objects) {
|
||||||
|
if (SshdPlugin.instance != null && isEnabled(level)) {
|
||||||
|
FormattingTuple ft = MessageFormatter.arrayFormat(s, objects);
|
||||||
|
SshdPlugin.instance.getLogger().log(level, ft.getMessage(), ft.getThrowable());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(Level level, String s, Throwable throwable) {
|
||||||
|
if (SshdPlugin.instance != null && isEnabled(level)) {
|
||||||
|
SshdPlugin.instance.getLogger().log(level, s, throwable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginSlf4jAdapter(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTraceEnabled() {
|
||||||
|
return isEnabled(Level.FINEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(String s) {
|
||||||
|
trace(s, new Object[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(String s, Object o) {
|
||||||
|
trace(s, new Object[]{o});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(String s, Object o, Object o1) {
|
||||||
|
trace(s, new Object[]{o, o1});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(String s, Object[] objects) {
|
||||||
|
log(Level.FINEST, s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(String s, Throwable throwable) {
|
||||||
|
log(Level.FINEST, s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTraceEnabled(Marker marker) {
|
||||||
|
return isTraceEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(Marker marker, String s) {
|
||||||
|
trace(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(Marker marker, String s, Object o) {
|
||||||
|
trace(s, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(Marker marker, String s, Object o, Object o1) {
|
||||||
|
trace(s, o, o1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(Marker marker, String s, Object[] objects) {
|
||||||
|
trace(s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void trace(Marker marker, String s, Throwable throwable) {
|
||||||
|
trace(s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebugEnabled() {
|
||||||
|
return isEnabled(Level.FINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String s) {
|
||||||
|
debug(s, new Object[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String s, Object o) {
|
||||||
|
debug(s, new Object[]{o});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String s, Object o, Object o1) {
|
||||||
|
debug(s, new Object[]{o, o1});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String s, Object[] objects) {
|
||||||
|
log(Level.FINE, s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String s, Throwable throwable) {
|
||||||
|
log(Level.FINE, s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebugEnabled(Marker marker) {
|
||||||
|
return isDebugEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(Marker marker, String s) {
|
||||||
|
debug(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(Marker marker, String s, Object o) {
|
||||||
|
debug(s, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(Marker marker, String s, Object o, Object o1) {
|
||||||
|
debug(s, o, o1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(Marker marker, String s, Object[] objects) {
|
||||||
|
debug(s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(Marker marker, String s, Throwable throwable) {
|
||||||
|
debug(s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInfoEnabled() {
|
||||||
|
return isEnabled(Level.INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String s) {
|
||||||
|
info(s, new Object[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String s, Object o) {
|
||||||
|
info(s, new Object[]{o});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String s, Object o, Object o1) {
|
||||||
|
info(s, new Object[]{o, o1});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String s, Object[] objects) {
|
||||||
|
log(Level.INFO, s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String s, Throwable throwable) {
|
||||||
|
log(Level.INFO, s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInfoEnabled(Marker marker) {
|
||||||
|
return isInfoEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(Marker marker, String s) {
|
||||||
|
info(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(Marker marker, String s, Object o) {
|
||||||
|
info(s, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(Marker marker, String s, Object o, Object o1) {
|
||||||
|
info(s, o, o1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(Marker marker, String s, Object[] objects) {
|
||||||
|
info(s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(Marker marker, String s, Throwable throwable) {
|
||||||
|
info(s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWarnEnabled() {
|
||||||
|
return isEnabled(Level.WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String s) {
|
||||||
|
warn(s, new Object[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String s, Object o) {
|
||||||
|
warn(s, new Object[]{o});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String s, Object o, Object o1) {
|
||||||
|
warn(s, new Object[]{o, o1});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String s, Object[] objects) {
|
||||||
|
log(Level.WARNING, s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String s, Throwable throwable) {
|
||||||
|
log(Level.WARNING, s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWarnEnabled(Marker marker) {
|
||||||
|
return isWarnEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(Marker marker, String s) {
|
||||||
|
warn(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(Marker marker, String s, Object o) {
|
||||||
|
warn(s, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(Marker marker, String s, Object o, Object o1) {
|
||||||
|
warn(s, o, o1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(Marker marker, String s, Object[] objects) {
|
||||||
|
warn(s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(Marker marker, String s, Throwable throwable) {
|
||||||
|
warn(s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isErrorEnabled() {
|
||||||
|
return isEnabled(Level.SEVERE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String s) {
|
||||||
|
error(s, new Object[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String s, Object o) {
|
||||||
|
error(s, new Object[]{o});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String s, Object o, Object o1) {
|
||||||
|
error(s, new Object[]{o, o1});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String s, Object[] objects) {
|
||||||
|
log(Level.SEVERE, s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String s, Throwable throwable) {
|
||||||
|
log(Level.SEVERE, s, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isErrorEnabled(Marker marker) {
|
||||||
|
return isErrorEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(Marker marker, String s) {
|
||||||
|
error(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(Marker marker, String s, Object o) {
|
||||||
|
error(s, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(Marker marker, String s, Object o, Object o1) {
|
||||||
|
error(s, o, o1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(Marker marker, String s, Object[] objects) {
|
||||||
|
error(s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(Marker marker, String s, Throwable throwable) {
|
||||||
|
error(s, throwable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2004-2011 QOS.ch
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.slf4j.impl;
|
||||||
|
|
||||||
|
import org.slf4j.ILoggerFactory;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.slf4j.spi.LoggerFactoryBinder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The binding of {@link LoggerFactory} class with an actual instance of
|
||||||
|
* {@link ILoggerFactory} is performed using information returned by this class.
|
||||||
|
*
|
||||||
|
* @author Ceki Gülcü
|
||||||
|
*/
|
||||||
|
public class StaticLoggerBinder implements LoggerFactoryBinder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The unique instance of this class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the singleton of this class.
|
||||||
|
*
|
||||||
|
* @return the StaticLoggerBinder singleton
|
||||||
|
*/
|
||||||
|
public static final StaticLoggerBinder getSingleton() {
|
||||||
|
return SINGLETON;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declare the version of the SLF4J API this implementation is compiled against.
|
||||||
|
* The value of this field is usually modified with each release.
|
||||||
|
*/
|
||||||
|
// to avoid constant folding by the compiler, this field must *not* be final
|
||||||
|
public static String REQUESTED_API_VERSION = "1.6.99"; // !final
|
||||||
|
|
||||||
|
|
||||||
|
private static final String loggerFactoryClassStr = PluginSlf4jFactory.class.getName();
|
||||||
|
|
||||||
|
/** The ILoggerFactory instance returned by the {@link #getLoggerFactory} method
|
||||||
|
* should always be the same object
|
||||||
|
*/
|
||||||
|
private final ILoggerFactory loggerFactory;
|
||||||
|
|
||||||
|
private StaticLoggerBinder() {
|
||||||
|
// Note: JCL gets substituted at build time by an appropriate Ant task
|
||||||
|
loggerFactory = new PluginSlf4jFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILoggerFactory getLoggerFactory() {
|
||||||
|
return loggerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLoggerFactoryClassStr() {
|
||||||
|
return loggerFactoryClassStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
87
Minecraft-SSHD-Bukkit/src/main/resources/config.yml
Normal file
87
Minecraft-SSHD-Bukkit/src/main/resources/config.yml
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# The IP addresses(s) the SSH server will listen on. Use a comma separated list for multiple addresses.
|
||||||
|
# Leave as "all" for all addresses.
|
||||||
|
ListenAddress: all
|
||||||
|
# The port the SSH server will listen on. Note that anything *below* 1024 will require you to run
|
||||||
|
# the whole minecraft server with elevated privileges (NOT RECOMMENDED).
|
||||||
|
Port: 1025
|
||||||
|
|
||||||
|
# Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC
|
||||||
|
Mode: DEFAULT
|
||||||
|
|
||||||
|
# Enable built-in SFTP server or not. You'll be able to connect and upload/download files via SFTP protocol.
|
||||||
|
# Might be useful for testing purposes as well , i. e. docker containers.
|
||||||
|
EnableSFTP: true
|
||||||
|
|
||||||
|
# Number of times a person can fail to use an SSH key or enter a password
|
||||||
|
# before it terminates the connection.
|
||||||
|
LoginRetries: 3
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
# By default, only public key authentication is enabled. This is the most secure mode.
|
||||||
|
# To authorize a user to login with their public key, install their key using the
|
||||||
|
# OpenSSH authorized_keys file format in the authorized_users directory. Name the key
|
||||||
|
# file with the user's username and no extension. Note: If you want to let a user have
|
||||||
|
# many keys, you can append the keys to their file in authorized_users.
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
# For less secure username and password based authentication, complete the sections below.
|
||||||
|
|
||||||
|
# Type of hashing to use for the passwords below.
|
||||||
|
# Options are: PLAIN (insecure), bcrypt, pbkdf2, sha256
|
||||||
|
#
|
||||||
|
# You can use the console/in-game command `/mkpasswd [hash] PASSWORD` to
|
||||||
|
# generate a password hash string then copy it for your passwords below.
|
||||||
|
# You can also use `/mkpasswd help` to see what algorithms are supported.
|
||||||
|
PasswordType: bcrypt
|
||||||
|
|
||||||
|
# Associate each username with a password hash (or the password if the PasswordType is set to PLAIN)
|
||||||
|
Credentials:
|
||||||
|
# The defaults for any user who does not have a specific section.
|
||||||
|
# Specific user permissions override the $default pseudo-user.
|
||||||
|
$default:
|
||||||
|
# Whether they can read or write to the console
|
||||||
|
console: RW
|
||||||
|
# SFTP access for anyone.
|
||||||
|
sftp:
|
||||||
|
# Whether sftp is allowed at all.
|
||||||
|
enabled: true
|
||||||
|
# Whether to allow or deny by default
|
||||||
|
default: allow
|
||||||
|
# specific rules for directories
|
||||||
|
rules:
|
||||||
|
# Deny the SSHD config folder by default as an example.
|
||||||
|
"*SSHD/*":
|
||||||
|
readable: false
|
||||||
|
writeable: false
|
||||||
|
|
||||||
|
# Username (should match SSH key if using key-based authentication)
|
||||||
|
justasic:
|
||||||
|
# Password hash from /mkpasswd command
|
||||||
|
password: $2a$10$Oqk83FrypRrMF35EDeoQDuidJOQEWBE0joEQ7MJFi/Oeg26wQ3fm2
|
||||||
|
# Whether they can read, write, or have read/write permissions to console.
|
||||||
|
console: RW
|
||||||
|
# SFTP access for this user.
|
||||||
|
sftp:
|
||||||
|
# Whether SFTP is enabled for this user.
|
||||||
|
enabled: true
|
||||||
|
# Whether to deny access by default or allow access by default
|
||||||
|
default: allow
|
||||||
|
# Rules regarding their SFTP access.
|
||||||
|
# These rules are relative to the server root.
|
||||||
|
# This acts as a chroot for the server root.
|
||||||
|
# Each path can be an absolute path or a regular expression.
|
||||||
|
rules:
|
||||||
|
"/path/to/file":
|
||||||
|
# Whether the user can read the file over SFTP
|
||||||
|
readable: true
|
||||||
|
# Whether the user can write/modify the file over SFTP
|
||||||
|
writeable: true
|
||||||
|
"/path/to/regex/*":
|
||||||
|
readable: true
|
||||||
|
writeable: false
|
||||||
|
"/path/to/directory/":
|
||||||
|
readable: false
|
||||||
|
writeable: true
|
||||||
|
"/another/example/path":
|
||||||
|
readable: false
|
||||||
|
writeable: false
|
||||||
9
Minecraft-SSHD-Bukkit/src/main/resources/plugin.yml
Normal file
9
Minecraft-SSHD-Bukkit/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
name: SSHD
|
||||||
|
version: ${project.version}
|
||||||
|
author: Ryan Michela, Haarolean, toxuin, Justin Crawford, Zachery Coleman
|
||||||
|
main: com.ryanmichela.sshd.SshdPlugin
|
||||||
|
load: STARTUP
|
||||||
|
commands:
|
||||||
|
mkpasswd:
|
||||||
|
description: Make a SSHD password hash
|
||||||
|
usage: /mkpasswd <hash|help> <password>
|
||||||
11
README.md
11
README.md
@@ -1,15 +1,13 @@
|
|||||||
Minecraft-SSHD (Sponge Edition!)
|
Minecraft-SSHD
|
||||||
===========
|
===========
|
||||||
|
|
||||||
[](https://travis-ci.org/Justasic/Minecraft-SSHD)
|
|
||||||
[](https://github.com/Justasic/Minecraft-SSHD/releases/latest)
|
|
||||||
[](https://github.com/Justasic/Minecraft-SSHD/blob/master/LICENSE)
|
[](https://github.com/Justasic/Minecraft-SSHD/blob/master/LICENSE)
|
||||||
|
|
||||||
<img align="left" width="140" height="140" src="docs/ssh_logo.png?raw=true" hspace="5" vspace="5" alt="diskover"><br/>
|
<img align="left" width="140" height="140" src="docs/ssh_logo.png?raw=true" hspace="5" vspace="5" alt="diskover"><br/>
|
||||||
|
|
||||||
**Have you ever wished you could remotely access your server's admin console without having to setup a complex remote access system? Now you can with Minecraft-SSHD!**
|
**Have you ever wished you could remotely access your server's admin console without having to setup a complex remote access system? Now you can with Minecraft-SSHD!**
|
||||||
|
|
||||||
Minecraft-SSHD securely exposes your Sponge admin console and the server filesystem using the SSH protocol - the same protocol that serves as the secure foundation for nearly all remote server administration.<br/>
|
Minecraft-SSHD securely exposes your Minecraft admin console and the server filesystem using the SSH protocol - the same protocol that serves as the secure foundation for nearly all remote server administration.<br/>
|
||||||
|
|
||||||
- Compatible with all ssh clients, regardless of operating system.
|
- Compatible with all ssh clients, regardless of operating system.
|
||||||
- Remotely view your server log in real-time.
|
- Remotely view your server log in real-time.
|
||||||
@@ -22,7 +20,7 @@ Minecraft-SSHD securely exposes your Sponge admin console and the server filesys
|
|||||||
|
|
||||||
### Why should I use Minecraft-SSHD?
|
### Why should I use Minecraft-SSHD?
|
||||||
|
|
||||||
- You are in a shared hosting environment that only gives you access to the log files.
|
- You are in a shared hosting environment that only gives you access to the - log files.
|
||||||
- You want to share access to your server console, but don't want to give anybody access to the machine its running on.
|
- You want to share access to your server console, but don't want to give anybody access to the machine its running on.
|
||||||
- You always wanted to use RCON, but want to see the server log as well.
|
- You always wanted to use RCON, but want to see the server log as well.
|
||||||
- You are tired of running your server in a GNU screen or tmux session.
|
- You are tired of running your server in a GNU screen or tmux session.
|
||||||
@@ -98,3 +96,6 @@ Minecraft-SSHD uses cryptographic certificates or a secure username and password
|
|||||||
|
|
||||||
## Source Code
|
## Source Code
|
||||||
[Get the source on GitHub](https://github.com/Justasic/Minecraft-SSHD "Source Code")
|
[Get the source on GitHub](https://github.com/Justasic/Minecraft-SSHD "Source Code")
|
||||||
|
|
||||||
|
## Our Discord
|
||||||
|
https://discord.gg/DtrJFn
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="minecraft" name="Minecraft">
|
|
||||||
<configuration>
|
|
||||||
<autoDetectTypes>
|
|
||||||
<platformType>SPONGE</platformType>
|
|
||||||
</autoDetectTypes>
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-core:2.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-mina:2.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-common:2.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-sftp:2.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.i2p.crypto:eddsa:0.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.mina:mina-core:2.1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.28" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-jdk14:1.7.28" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: jline:jline:2.12.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-core:2.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.10" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:spongeapi:7.1.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.errorprone:error_prone_annotations:2.0.15" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.commons:commons-lang3:3.5" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:3.0.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.inject:guice:4.1.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.inject:javax.inject:1" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: aopalliance:aopalliance:1.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.ben-manes.caffeine:caffeine:2.5.4" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.ben-manes.caffeine:guava:2.5.4" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:plugin-meta:0.4.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-hocon:3.6" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-core:3.6" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.checkerframework:checker-qual:2.4.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.typesafe:config:1.3.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-gson:3.6" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-yaml:3.6" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.flowpowered:flow-math:1.0.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.flowpowered:flow-noise:1.0.1-SNAPSHOT" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:5.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: pl.project13.maven:git-commit-id-plugin:maven-plugin:3.0.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-artifact:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-inject-plexus:1.4.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-inject-bean:1.4.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-guice:noaop:2.1.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-core:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-settings:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-settings-builder:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-repository-metadata:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-model-builder:3.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.maven:maven-aether-provider:3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-impl:1.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-spi:1.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-api:1.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-util:1.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-interpolation:1.14" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-utils:2.0.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-classworlds:2.2.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-component-annotations:1.5.5" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-sec-dispatcher:1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-cipher:1.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-build-api:0.0.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.9.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: joda-time:joda-time:2.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.eclipse.jgit:org.eclipse.jgit:5.2.2.201904231744-r" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.54" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.jcraft:jzlib:1.1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.googlecode.javaewah:JavaEWAH:1.1.6" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
166
pom.xml
166
pom.xml
@@ -1,53 +1,72 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<groupId>com.ryanmichela</groupId>
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<artifactId>sshd</artifactId>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<description>Minecraft-SSHD: The SSH daemon for Minecraft servers.</description>
|
||||||
|
<modules>
|
||||||
|
<module>Minecraft-SSHD-Bukkit</module>
|
||||||
|
</modules>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
<url>https://git.limework.net/Limework/Minecraft-SSHD/</url>
|
||||||
|
|
||||||
<groupId>com.ryanmichela</groupId>
|
<properties>
|
||||||
<artifactId>sshd</artifactId>
|
<java.version>1.8</java.version>
|
||||||
<version>2.0.0</version>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<packaging>jar</packaging>
|
</properties>
|
||||||
<name>Sponge-SSHD</name>
|
|
||||||
<description>Sponge port for Minecraft-SSHD. SSH for your minecraft server!</description>
|
|
||||||
<url>https://github.com/Justasic/Minecraft-SSHD/</url>
|
|
||||||
|
|
||||||
<properties>
|
<!-- Repositories -->
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<repositories>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<repository>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<id>spigot-repo</id>
|
||||||
</properties>
|
<url>https://hub.spigotmc.org/nexus/content/groups/public</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<repositories>
|
<!-- License -->
|
||||||
<repository>
|
<licenses>
|
||||||
<id>sponge</id>
|
<license>
|
||||||
<url>https://repo.spongepowered.org/maven</url>
|
<name>Apache-2.0</name>
|
||||||
</repository>
|
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||||
</repositories>
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
<dependencies>
|
<!-- Dependencies -->
|
||||||
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.sshd</groupId>
|
<groupId>org.apache.sshd</groupId>
|
||||||
<artifactId>sshd-core</artifactId>
|
<artifactId>sshd-core</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.9.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.sshd</groupId>
|
||||||
|
<artifactId>sshd-mina</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.sshd</groupId>
|
<groupId>org.apache.sshd</groupId>
|
||||||
<artifactId>sshd-mina</artifactId>
|
<artifactId>sshd-contrib</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.9.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.sshd</groupId>
|
<groupId>org.apache.sshd</groupId>
|
||||||
<artifactId>sshd-common</artifactId>
|
<artifactId>sshd-common</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.9.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.sshd</groupId>
|
<groupId>org.apache.sshd</groupId>
|
||||||
<artifactId>sshd-sftp</artifactId>
|
<artifactId>sshd-sftp</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.9.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -55,83 +74,52 @@
|
|||||||
<artifactId>eddsa</artifactId>
|
<artifactId>eddsa</artifactId>
|
||||||
<version>0.3.0</version>
|
<version>0.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.mina</groupId>
|
||||||
|
<artifactId>mina-core</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>2.0.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
|
<version>2.0.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jline</groupId>
|
<groupId>jline</groupId>
|
||||||
<artifactId>jline</artifactId>
|
<artifactId>jline</artifactId>
|
||||||
<version>2.12.1</version>
|
<version>2.14.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.20.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-api</artifactId>
|
<artifactId>log4j-api</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.20.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- include Sponge API -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>spongeapi</artifactId>
|
|
||||||
<version>7.1.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<dependency>
|
||||||
<!-- Set our default goal to be clean and build a package -->
|
<groupId>commons-codec</groupId>
|
||||||
<defaultGoal>clean package</defaultGoal>
|
<artifactId>commons-codec</artifactId>
|
||||||
<!-- Include our git hash in the final name -->
|
<version>1.15</version>
|
||||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<resources>
|
<packaging>pom</packaging>
|
||||||
<resource>
|
|
||||||
<targetPath>.</targetPath>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
<directory>${basedir}/src/main/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>motd.txt</include>
|
|
||||||
</includes>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
|
|
||||||
<!-- Plugins -->
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<version>3.1.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
|
||||||
<appendAssemblyId>false</appendAssemblyId>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- Compile plugin -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.7.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
<showDeprecation>true</showDeprecation>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,222 +0,0 @@
|
|||||||
package com.ryanmichela.sshd;
|
|
||||||
// The below code was taken from md_5's BungeeCord project - Justin
|
|
||||||
/*
|
|
||||||
Copyright (c) 2012, md_5. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
Redistributions of source code must retain the above copyright notice, this
|
|
||||||
list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
The name of the author may not be used to endorse or promote products derived
|
|
||||||
from this software without specific prior written permission.
|
|
||||||
|
|
||||||
You may not use the software for commercial software hosting services without
|
|
||||||
written permission from the author.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simplistic enumeration of all supported color values for chat.
|
|
||||||
*/
|
|
||||||
public enum ChatColor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Represents black.
|
|
||||||
*/
|
|
||||||
BLACK( '0', "black" ),
|
|
||||||
/**
|
|
||||||
* Represents dark blue.
|
|
||||||
*/
|
|
||||||
DARK_BLUE( '1', "dark_blue" ),
|
|
||||||
/**
|
|
||||||
* Represents dark green.
|
|
||||||
*/
|
|
||||||
DARK_GREEN( '2', "dark_green" ),
|
|
||||||
/**
|
|
||||||
* Represents dark blue (aqua).
|
|
||||||
*/
|
|
||||||
DARK_AQUA( '3', "dark_aqua" ),
|
|
||||||
/**
|
|
||||||
* Represents dark red.
|
|
||||||
*/
|
|
||||||
DARK_RED( '4', "dark_red" ),
|
|
||||||
/**
|
|
||||||
* Represents dark purple.
|
|
||||||
*/
|
|
||||||
DARK_PURPLE( '5', "dark_purple" ),
|
|
||||||
/**
|
|
||||||
* Represents gold.
|
|
||||||
*/
|
|
||||||
GOLD( '6', "gold" ),
|
|
||||||
/**
|
|
||||||
* Represents gray.
|
|
||||||
*/
|
|
||||||
GRAY( '7', "gray" ),
|
|
||||||
/**
|
|
||||||
* Represents dark gray.
|
|
||||||
*/
|
|
||||||
DARK_GRAY( '8', "dark_gray" ),
|
|
||||||
/**
|
|
||||||
* Represents blue.
|
|
||||||
*/
|
|
||||||
BLUE( '9', "blue" ),
|
|
||||||
/**
|
|
||||||
* Represents green.
|
|
||||||
*/
|
|
||||||
GREEN( 'a', "green" ),
|
|
||||||
/**
|
|
||||||
* Represents aqua.
|
|
||||||
*/
|
|
||||||
AQUA( 'b', "aqua" ),
|
|
||||||
/**
|
|
||||||
* Represents red.
|
|
||||||
*/
|
|
||||||
RED( 'c', "red" ),
|
|
||||||
/**
|
|
||||||
* Represents light purple.
|
|
||||||
*/
|
|
||||||
LIGHT_PURPLE( 'd', "light_purple" ),
|
|
||||||
/**
|
|
||||||
* Represents yellow.
|
|
||||||
*/
|
|
||||||
YELLOW( 'e', "yellow" ),
|
|
||||||
/**
|
|
||||||
* Represents white.
|
|
||||||
*/
|
|
||||||
WHITE( 'f', "white" ),
|
|
||||||
/**
|
|
||||||
* Represents magical characters that change around randomly.
|
|
||||||
*/
|
|
||||||
MAGIC( 'k', "obfuscated" ),
|
|
||||||
/**
|
|
||||||
* Makes the text bold.
|
|
||||||
*/
|
|
||||||
BOLD( 'l', "bold" ),
|
|
||||||
/**
|
|
||||||
* Makes a line appear through the text.
|
|
||||||
*/
|
|
||||||
STRIKETHROUGH( 'm', "strikethrough" ),
|
|
||||||
/**
|
|
||||||
* Makes the text appear underlined.
|
|
||||||
*/
|
|
||||||
UNDERLINE( 'n', "underline" ),
|
|
||||||
/**
|
|
||||||
* Makes the text italic.
|
|
||||||
*/
|
|
||||||
ITALIC( 'o', "italic" ),
|
|
||||||
/**
|
|
||||||
* Resets all previous chat colors or formats.
|
|
||||||
*/
|
|
||||||
RESET( 'r', "reset" );
|
|
||||||
/**
|
|
||||||
* The special character which prefixes all chat colour codes. Use this if
|
|
||||||
* you need to dynamically convert colour codes from your custom format.
|
|
||||||
*/
|
|
||||||
public static final char COLOR_CHAR = '\u00A7';
|
|
||||||
public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRr";
|
|
||||||
/**
|
|
||||||
* Pattern to remove all colour codes.
|
|
||||||
*/
|
|
||||||
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile( "(?i)" + String.valueOf( COLOR_CHAR ) + "[0-9A-FK-OR]" );
|
|
||||||
/**
|
|
||||||
* Colour instances keyed by their active character.
|
|
||||||
*/
|
|
||||||
private static final Map<Character, ChatColor> BY_CHAR = new HashMap<Character, ChatColor>();
|
|
||||||
/**
|
|
||||||
* The code appended to {@link #COLOR_CHAR} to make usable colour.
|
|
||||||
*/
|
|
||||||
private final char code;
|
|
||||||
/**
|
|
||||||
* This colour's colour char prefixed by the {@link #COLOR_CHAR}.
|
|
||||||
*/
|
|
||||||
private final String toString;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
public String getName() { return this.name; }
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
for ( ChatColor colour : values() )
|
|
||||||
{
|
|
||||||
BY_CHAR.put( colour.code, colour );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ChatColor(char code, String name)
|
|
||||||
{
|
|
||||||
this.code = code;
|
|
||||||
this.name = name;
|
|
||||||
this.toString = new String( new char[]
|
|
||||||
{
|
|
||||||
COLOR_CHAR, code
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return toString;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strips the given message of all color codes
|
|
||||||
*
|
|
||||||
* @param input String to strip of color
|
|
||||||
* @return A copy of the input string, without any coloring
|
|
||||||
*/
|
|
||||||
public static String stripColor(final String input)
|
|
||||||
{
|
|
||||||
if ( input == null )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return STRIP_COLOR_PATTERN.matcher( input ).replaceAll( "" );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
|
|
||||||
{
|
|
||||||
char[] b = textToTranslate.toCharArray();
|
|
||||||
for ( int i = 0; i < b.length - 1; i++ )
|
|
||||||
{
|
|
||||||
if ( b[i] == altColorChar && ALL_CODES.indexOf( b[i + 1] ) > -1 )
|
|
||||||
{
|
|
||||||
b[i] = ChatColor.COLOR_CHAR;
|
|
||||||
b[i + 1] = Character.toLowerCase( b[i + 1] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new String( b );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the colour represented by the specified code.
|
|
||||||
*
|
|
||||||
* @param code the code to search for
|
|
||||||
* @return the mapped colour, or null if non exists
|
|
||||||
*/
|
|
||||||
public static ChatColor getByChar(char code)
|
|
||||||
{
|
|
||||||
return BY_CHAR.get( code );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
package com.ryanmichela.sshd;
|
|
||||||
|
|
||||||
/*
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
*/
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import com.ryanmichela.sshd.Cryptography;
|
|
||||||
import com.ryanmichela.sshd.SshdPlugin;
|
|
||||||
|
|
||||||
import org.spongepowered.api.Sponge;
|
|
||||||
import org.spongepowered.api.command.CommandException;
|
|
||||||
import org.spongepowered.api.command.CommandResult;
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
|
||||||
import org.spongepowered.api.command.args.CommandContext;
|
|
||||||
import org.spongepowered.api.command.args.GenericArguments;
|
|
||||||
import org.spongepowered.api.command.spec.CommandExecutor;
|
|
||||||
import org.spongepowered.api.command.spec.CommandSpec;
|
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
|
||||||
import org.spongepowered.api.event.command.TabCompleteEvent;
|
|
||||||
import org.spongepowered.api.text.Text;
|
|
||||||
|
|
||||||
public class MkpasswdCommand implements CommandExecutor
|
|
||||||
{
|
|
||||||
private static CommandSpec cmdspec;
|
|
||||||
public static void BuildCommand()
|
|
||||||
{
|
|
||||||
CommandSpec pbkdf2 = CommandSpec.builder()
|
|
||||||
.description(Text.of("PBKDF2 hashed password"))
|
|
||||||
.permission("sshd.mkpasswd.pbkdf2")
|
|
||||||
.arguments(GenericArguments.remainingJoinedStrings(Text.of("password")))
|
|
||||||
.executor((CommandSource source, CommandContext args) -> {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
source.sendMessage(Text.of("\u00A79Your Hash: " + Cryptography.PBKDF2_HashPassword(args.<String>getOne("password").get())));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return CommandResult.success();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CommandSpec bcrypt = CommandSpec.builder()
|
|
||||||
.description(Text.of("BCrypt hashed password"))
|
|
||||||
.permission("sshd.mkpasswd.bcrypt")
|
|
||||||
.arguments(GenericArguments.remainingJoinedStrings(Text.of("password")))
|
|
||||||
.executor((CommandSource source, CommandContext args) -> {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
source.sendMessage(Text.of("\u00A79Your Hash: " + Cryptography.BCrypt_HashPassword(args.<String>getOne("password").get())));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return CommandResult.success();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CommandSpec sha256 = CommandSpec.builder()
|
|
||||||
.description(Text.of("SHA256 hashed password"))
|
|
||||||
.permission("sshd.mkpasswd.sha256")
|
|
||||||
.arguments(GenericArguments.remainingJoinedStrings(Text.of("password")))
|
|
||||||
.executor((CommandSource source, CommandContext args) -> {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
source.sendMessage(Text.of("\u00A79Your Hash: " + Cryptography.SHA256_HashPassword(args.<String>getOne("password").get())));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return CommandResult.success();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// The plain text "encryption" method
|
|
||||||
CommandSpec plain = CommandSpec.builder()
|
|
||||||
.description(Text.of("Plain text password (insecure)"))
|
|
||||||
.permission("sshd.mkpasswd.plain")
|
|
||||||
.arguments(GenericArguments.remainingJoinedStrings(Text.of("password")))
|
|
||||||
.executor((CommandSource source, CommandContext args) -> {
|
|
||||||
source.sendMessage(Text.of("\u00A79Your Hash: \u00A7cIt's literally your unhashed password."));
|
|
||||||
return CommandResult.success();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// the root "mkpasswd" command
|
|
||||||
cmdspec = CommandSpec.builder()
|
|
||||||
.description(Text.of("Create an SSHd password using hashes"))
|
|
||||||
.extendedDescription(Text.of("Supported Hashes: SHA256, PBKDF2, BCRYPT, PLAIN"))
|
|
||||||
.permission("sshd.mkpasswd")
|
|
||||||
.child(plain, "plain")
|
|
||||||
.child(sha256, "sha256")
|
|
||||||
.child(bcrypt, "bcrypt")
|
|
||||||
.child(pbkdf2, "pbkdf2")
|
|
||||||
.executor(new MkpasswdCommand())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// Register our command with Sponge.
|
|
||||||
Sponge.getCommandManager().register(SshdPlugin.GetInstance(), cmdspec, "mkpasswd");
|
|
||||||
}
|
|
||||||
|
|
||||||
// so sponge needed this, still figuring out the sponge API ~ Zach
|
|
||||||
@Override
|
|
||||||
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException
|
|
||||||
{
|
|
||||||
// This command doesn't do anything.
|
|
||||||
src.sendMessage(Text.of("\u00A7a/mkpasswd <hash> <password...>\u00A7r"));
|
|
||||||
src.sendMessage(Text.of("\u00A79Supported Hashes: SHA256, PBKDF2, BCRYPT, PLAIN\u00A7r"));
|
|
||||||
return CommandResult.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
package com.ryanmichela.sshd;
|
|
||||||
|
|
||||||
import com.ryanmichela.sshd.utils.Config;
|
|
||||||
import org.spongepowered.api.Sponge;
|
|
||||||
import org.spongepowered.api.command.spec.CommandSpec;
|
|
||||||
import org.spongepowered.api.config.DefaultConfig;
|
|
||||||
import org.spongepowered.api.config.ConfigDir;
|
|
||||||
import org.spongepowered.api.plugin.Plugin;
|
|
||||||
import org.spongepowered.api.event.Listener;
|
|
||||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
|
||||||
|
|
||||||
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
|
|
||||||
import org.apache.sshd.server.SshServer;
|
|
||||||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
|
||||||
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
|
|
||||||
|
|
||||||
import com.ryanmichela.sshd.ConsoleShellFactory;
|
|
||||||
import com.ryanmichela.sshd.MkpasswdCommand;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.FileSystems;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.spongepowered.api.text.Text;
|
|
||||||
|
|
||||||
@Plugin(
|
|
||||||
id = "sshd",
|
|
||||||
name = "Minecraft-SSHD",
|
|
||||||
version = "1.3.7",
|
|
||||||
description = "Sponge port for Minecraft-SSHD. SSH for your minecraft server!",
|
|
||||||
authors={"Justin Crawford", "Zachery Coleman"}
|
|
||||||
)
|
|
||||||
public class SshdPlugin
|
|
||||||
{
|
|
||||||
String ListenAddress = "";
|
|
||||||
Integer Port = 1025;
|
|
||||||
String Mode = "";
|
|
||||||
Boolean EnableSFTP = true;
|
|
||||||
Integer LoginRetries = 3;
|
|
||||||
String PasswordType = "";
|
|
||||||
// Credentials
|
|
||||||
|
|
||||||
private SshServer sshd;
|
|
||||||
private static SshdPlugin instance;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public Logger logger;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@DefaultConfig(sharedRoot = false)
|
|
||||||
public Path DefaultConfig;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@ConfigDir(sharedRoot = false)
|
|
||||||
public Path ConfigDir;
|
|
||||||
|
|
||||||
public Config config;
|
|
||||||
|
|
||||||
@Listener
|
|
||||||
public void onServerStart(GameStartedServerEvent event)
|
|
||||||
{
|
|
||||||
instance = this;
|
|
||||||
// Parse our config
|
|
||||||
config = new Config();
|
|
||||||
config.setup();
|
|
||||||
|
|
||||||
// Make sure our authorized_keys folder exists
|
|
||||||
File authorizedKeys = new File(this.ConfigDir.toFile(), "authorized_keys");
|
|
||||||
if (!authorizedKeys.exists())
|
|
||||||
authorizedKeys.mkdirs();
|
|
||||||
|
|
||||||
// Now include it in our dealio here
|
|
||||||
this.Mode = config.configNode.getNode("Mode").getString();
|
|
||||||
this.PasswordType = config.configNode.getNode("PasswordType").getString();
|
|
||||||
this.ListenAddress = config.configNode.getNode("ListenAddress").getString();
|
|
||||||
this.Port = config.configNode.getNode("Port").getInt();
|
|
||||||
this.LoginRetries = config.configNode.getNode("LoginRetries").getInt();
|
|
||||||
this.EnableSFTP = config.configNode.getNode("EnableSFTP").getBoolean();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File motd = new File(this.ConfigDir.toFile(), "motd.txt");
|
|
||||||
if (!motd.exists())
|
|
||||||
{
|
|
||||||
InputStream link = (getClass().getResourceAsStream("/motd.txt"));
|
|
||||||
Files.copy(link, motd.getAbsoluteFile().toPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sshd = SshServer.setUpDefaultServer();
|
|
||||||
sshd.setPort(this.Port);
|
|
||||||
sshd.setHost(this.ListenAddress.equals("all") ? null : this.ListenAddress);
|
|
||||||
|
|
||||||
File hostKey = new File(this.ConfigDir.toFile(), "hostkey");
|
|
||||||
|
|
||||||
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey.toPath()));
|
|
||||||
sshd.setShellFactory(new ConsoleShellFactory());
|
|
||||||
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
|
|
||||||
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
|
|
||||||
|
|
||||||
if (this.EnableSFTP)
|
|
||||||
{
|
|
||||||
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
|
|
||||||
sshd.setFileSystemFactory(new VirtualFileSystemFactory(this.ConfigDir.getParent().getParent()));
|
|
||||||
}
|
|
||||||
|
|
||||||
MkpasswdCommand.BuildCommand();
|
|
||||||
|
|
||||||
sshd.setCommandFactory(new ConsoleCommandFactory());
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sshd.start();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
logger.error("Failed to start SSH server! ", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Loaded Minecraft-SSHD.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SshdPlugin GetInstance()
|
|
||||||
{
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger GetLogger()
|
|
||||||
{
|
|
||||||
return this.logger;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
package com.ryanmichela.sshd;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Level;
|
|
||||||
import org.apache.logging.log4j.core.Appender;
|
|
||||||
import org.apache.logging.log4j.core.ErrorHandler;
|
|
||||||
import org.apache.logging.log4j.core.Layout;
|
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
|
||||||
import org.apache.logging.log4j.core.layout.PatternLayout;
|
|
||||||
|
|
||||||
import jline.console.ConsoleReader;
|
|
||||||
import org.apache.sshd.common.SshException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2014 Ryan Michela
|
|
||||||
*/
|
|
||||||
public class StreamHandlerAppender implements Appender
|
|
||||||
{
|
|
||||||
private ConsoleReader console;
|
|
||||||
private UUID uuid;
|
|
||||||
private PatternLayout MinecraftLayout = PatternLayout.newBuilder().withPattern("%highlightError{[%d{HH:mm:ss} %level] [%logger]: %minecraftFormatting{%msg}%xEx}").build();
|
|
||||||
private PatternLayout MojangLayout = PatternLayout.newBuilder().withPattern("%highlightError{[%d{HH:mm:ss} %level]: %minecraftFormatting{%msg}%xEx}").build();
|
|
||||||
|
|
||||||
public StreamHandlerAppender(ConsoleReader console)
|
|
||||||
{
|
|
||||||
this.console = console;
|
|
||||||
uuid = UUID.randomUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void append(LogEvent logEvent)
|
|
||||||
{
|
|
||||||
if (logEvent.getLevel() == Level.DEBUG || logEvent.getLevel() == Level.TRACE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Delete the jline's `> ` character
|
|
||||||
this.console.print(ConsoleReader.BACKSPACE + "" + ConsoleReader.BACKSPACE);
|
|
||||||
// Print our message
|
|
||||||
if (logEvent.getLoggerName().matches("net\\.minecraft\\..*|com\\.mojang\\..*"))
|
|
||||||
this.console.println(ConsoleLogFormatter.ColorizeString(this.MojangLayout.toSerializable(logEvent)).replaceAll("\n", "\r\n") + "\r");
|
|
||||||
else
|
|
||||||
this.console.println(ConsoleLogFormatter.ColorizeString(this.MinecraftLayout.toSerializable(logEvent)).replaceAll("\n", "\r\n") + "\r");
|
|
||||||
// Reset the console (colors, formatting, etc)
|
|
||||||
this.console.print(ConsoleReader.RESET_LINE + "");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Attempt to draw new console line
|
|
||||||
this.console.drawLine();
|
|
||||||
}
|
|
||||||
catch (Throwable ex)
|
|
||||||
{
|
|
||||||
this.console.getCursorBuffer().clear();
|
|
||||||
}
|
|
||||||
// Push it to the end user.
|
|
||||||
this.console.flush();
|
|
||||||
}
|
|
||||||
catch (SshException ex)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "StreamHandlerAppender:" + uuid.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Layout<? extends Serializable> getLayout() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean ignoreExceptions() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ErrorHandler getHandler() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHandler(ErrorHandler errorHandler) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStarted() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStopped() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
package com.ryanmichela.sshd.implementations;
|
|
||||||
|
|
||||||
import com.ryanmichela.sshd.SshdPlugin;
|
|
||||||
import com.ryanmichela.sshd.ConsoleShellFactory;
|
|
||||||
import com.ryanmichela.sshd.ConsoleLogFormatter;
|
|
||||||
import org.spongepowered.api.command.source.ConsoleSource;
|
|
||||||
import org.checkerframework.checker.nullness.Opt;
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
|
||||||
import org.spongepowered.api.text.Text;
|
|
||||||
import org.spongepowered.api.text.channel.MessageChannel;
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectReference;
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
|
||||||
import org.spongepowered.api.util.Tristate;
|
|
||||||
import jline.console.ConsoleReader;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
// This is gonna be a mess.
|
|
||||||
public class SSHDCommandSender implements ConsoleSource
|
|
||||||
{
|
|
||||||
private MessageChannel mc = MessageChannel.TO_CONSOLE;
|
|
||||||
private Subject subjectDelegate;
|
|
||||||
// Set by the upstream allocating function
|
|
||||||
public ConsoleShellFactory.ConsoleShell console;
|
|
||||||
private UUID uuid = UUID.randomUUID();
|
|
||||||
|
|
||||||
// This is an override for Sponge to work with the SSH consoles.
|
|
||||||
@Override
|
|
||||||
public void sendMessage(Text message)
|
|
||||||
{
|
|
||||||
this.sendRawMessage(message.toPlain());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Back port from Spigot/BungeeCord-style API calls.
|
|
||||||
public void sendMessage(String message)
|
|
||||||
{
|
|
||||||
this.sendRawMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendRawMessage(String message)
|
|
||||||
{
|
|
||||||
// What the fuck does this code even do? Are we sending to one client or all of them?
|
|
||||||
if (this.console.ConsoleReader == null)
|
|
||||||
return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.console.ConsoleReader.print(ConsoleReader.BACKSPACE + "" + ConsoleReader.BACKSPACE);
|
|
||||||
this.console.ConsoleReader.println(ConsoleLogFormatter.ColorizeString(message).replaceAll("\n", "\n\r") + "\r");
|
|
||||||
this.console.ConsoleReader.print(ConsoleReader.RESET_LINE + "");
|
|
||||||
this.console.ConsoleReader.flush();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.console.ConsoleReader.drawLine();
|
|
||||||
}
|
|
||||||
catch (Throwable ex)
|
|
||||||
{
|
|
||||||
this.console.ConsoleReader.getCursorBuffer().clear();
|
|
||||||
}
|
|
||||||
this.console.ConsoleReader.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
SshdPlugin.GetInstance().logger.error("Error sending message to SSHDCommandSender", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(String[] messages)
|
|
||||||
{
|
|
||||||
Arrays.asList(messages).forEach(this::sendMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageChannel getMessageChannel()
|
|
||||||
{
|
|
||||||
return mc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageChannel(MessageChannel channel)
|
|
||||||
{
|
|
||||||
mc = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return "SSHD Console";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIdentifier() {
|
|
||||||
return uuid.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Context> getActiveContexts()
|
|
||||||
{
|
|
||||||
// No clue what any of this does but sponge needs it to work with this class. - Justin
|
|
||||||
Set<Context> set = new HashSet<Context>();
|
|
||||||
set.add(new Context(Context.USER_KEY, "SSHD"));
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSubjectDataPersisted()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChildOf(Set<Context> contexts, SubjectReference parent)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubjectData getTransientSubjectData()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubjectData getSubjectData()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tristate getPermissionValue(Set<Context> contexts, String permission)
|
|
||||||
{
|
|
||||||
// We're allowed to view all permissions.
|
|
||||||
return Tristate.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SubjectReference> getParents(Set<Context> contexts)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getOption(Set<Context> contexts, String key)
|
|
||||||
{
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubjectCollection getContainingCollection()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<CommandSource> getCommandSource()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return Optional.of(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubjectReference asSubjectReference()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package com.ryanmichela.sshd.utils;
|
|
||||||
|
|
||||||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
|
||||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
|
||||||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
|
||||||
import org.spongepowered.api.config.DefaultConfig;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.ryanmichela.sshd.SshdPlugin;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class Config
|
|
||||||
{
|
|
||||||
// Give us a config!
|
|
||||||
@Inject
|
|
||||||
@DefaultConfig(sharedRoot = false)
|
|
||||||
// idk what to do with this one.
|
|
||||||
private ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(SshdPlugin.GetInstance().DefaultConfig).build();
|
|
||||||
|
|
||||||
public CommentedConfigurationNode configNode;
|
|
||||||
|
|
||||||
public void setup()
|
|
||||||
{
|
|
||||||
// I'm not sure if this will even work, the sponge config API is confusing.
|
|
||||||
if (!Files.exists(SshdPlugin.GetInstance().DefaultConfig))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Files.createFile(SshdPlugin.GetInstance().DefaultConfig);
|
|
||||||
this.load();
|
|
||||||
this.populate();
|
|
||||||
this.save();
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
configNode = this.configLoader.load();
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.configLoader.save(this.configNode);
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void populate()
|
|
||||||
{
|
|
||||||
this.configNode.getNode("ListenAddress").setValue("all").setComment
|
|
||||||
("The IP addresses(s) the SSH server will listen on. Use a comma separated list for multiple addresses.\n" +
|
|
||||||
"Leave as \"all\" for all addresses.");
|
|
||||||
this.configNode.getNode("Port").setValue("1025").setComment(
|
|
||||||
"The port the SSH server will listen on. Note that anything above 1024 will require you to run\n" +
|
|
||||||
"the whole minecraft server with elevated privileges, this is not recommended and you should\n" +
|
|
||||||
"use iptables to route packets from a lower port.");
|
|
||||||
this.configNode.getNode("Mode").setValue("DEFAULT").setComment("Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC");
|
|
||||||
this.configNode.getNode("EnableSFTP").setValue("true").setComment(
|
|
||||||
"Enable built-in SFTP server or not. You'll be able to connect and upload/download files via SFTP protocol.\n" +
|
|
||||||
"Might be useful for testing purposes as well , i. e. docker containers.");
|
|
||||||
this.configNode.getNode("LoginRetries").setValue("3").setComment(
|
|
||||||
"Number of times a person can fail to use an SSH key or enter a password\n" +
|
|
||||||
"before it terminates the connection.");
|
|
||||||
|
|
||||||
this.configNode.getNode("PasswordType").setValue("bcrypt").setComment
|
|
||||||
("########################################################################################\n" +
|
|
||||||
"By default, only public key authentication is enabled. This is the most secure mode.\n" +
|
|
||||||
"To authorize a user to login with their public key, install their key using the\n" +
|
|
||||||
"OpenSSH authorized_keys file format in the authorized_users directory. Name the key\n" +
|
|
||||||
"file with the user's username and no extension. Note: If you want to let a user have\n" +
|
|
||||||
"many keys, you can append the keys to their file in authorized_users.\n" +
|
|
||||||
"########################################################################################\n" +
|
|
||||||
"For less secure username and password based authentication, complete the sections below.\n" +
|
|
||||||
"\n" +
|
|
||||||
"Type of hashing to use for the passwords below.\n" +
|
|
||||||
"Options are: PLAIN (insecure), bcrypt, pbkdf2, sha256\n" +
|
|
||||||
"\n" +
|
|
||||||
"You can use the console/in-game command `/mkpasswd [hash] PASSWORD` to\n" +
|
|
||||||
"generate a password hash string then copy it for your passwords below.\n" +
|
|
||||||
"You can also use `/mkpasswd help` to see what algorithms are supported.");
|
|
||||||
|
|
||||||
this.configNode.getNode("Credentials").setComment("Associate each username with a password hash (or the password if the PasswordType is set to PLAIN)");
|
|
||||||
this.configNode.getNode("Credentials", "user1", "password").setValue("MySecretPassword");
|
|
||||||
this.configNode.getNode("Credentials", "user2", "password").setValue("MyBestFriendsPassword");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
# The IP addresses(s) the SSH server will listen on. Use a comma separated list for multiple addresses.
|
|
||||||
# Leave as "all" for all addresses.
|
|
||||||
ListenAddress: all
|
|
||||||
# The port the SSH server will listen on. Note that anything above 1024 will require you to run
|
|
||||||
# the whole minecraft server with elevated privileges, this is not recommended and you should
|
|
||||||
# use iptables to route packets from a lower port.
|
|
||||||
Port: 1025
|
|
||||||
|
|
||||||
# Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC
|
|
||||||
Mode: DEFAULT
|
|
||||||
|
|
||||||
# Enable built-in SFTP server or not. You'll be able to connect and upload/download files via SFTP protocol.
|
|
||||||
# Might be useful for testing purposes as well , i. e. docker containers.
|
|
||||||
EnableSFTP: true
|
|
||||||
|
|
||||||
# Number of times a person can fail to use an SSH key or enter a password
|
|
||||||
# before it terminates the connection.
|
|
||||||
LoginRetries: 3
|
|
||||||
|
|
||||||
########################################################################################
|
|
||||||
# By default, only public key authentication is enabled. This is the most secure mode.
|
|
||||||
# To authorize a user to login with their public key, install their key using the
|
|
||||||
# OpenSSH authorized_keys file format in the authorized_users directory. Name the key
|
|
||||||
# file with the user's username and no extension. Note: If you want to let a user have
|
|
||||||
# many keys, you can append the keys to their file in authorized_users.
|
|
||||||
########################################################################################
|
|
||||||
|
|
||||||
# For less secure username and password based authentication, complete the sections below.
|
|
||||||
|
|
||||||
# Type of hashing to use for the passwords below.
|
|
||||||
# Options are: PLAIN (insecure), bcrypt, pbkdf2, sha256
|
|
||||||
#
|
|
||||||
# You can use the console/in-game command `/mkpasswd [hash] PASSWORD` to
|
|
||||||
# generate a password hash string then copy it for your passwords below.
|
|
||||||
# You can also use `/mkpasswd help` to see what algorithms are supported.
|
|
||||||
PasswordType: bcrypt
|
|
||||||
|
|
||||||
# Associate each username with a password hash (or the password if the PasswordType is set to PLAIN)
|
|
||||||
Credentials:
|
|
||||||
# user1: password1
|
|
||||||
# user2: password2
|
|
||||||
Reference in New Issue
Block a user