Replaced Pastebin with Privatebin.

This commit is contained in:
Christian P. MOMON 2021-04-07 17:19:57 +02:00
parent 7cc73c9a4e
commit 9526609196
8 changed files with 324 additions and 245 deletions

View File

@ -54,7 +54,7 @@ import org.april.hebdobot.bot.review.Review;
import org.april.hebdobot.cron.CronManager; import org.april.hebdobot.cron.CronManager;
import org.april.hebdobot.cron.CronSettings; import org.april.hebdobot.cron.CronSettings;
import org.april.hebdobot.identica.IdenticaSettings; import org.april.hebdobot.identica.IdenticaSettings;
import org.april.hebdobot.pastebin.PastebinSettings; import org.april.hebdobot.privatebin.PrivatebinSettings;
import org.april.hebdobot.twitter.TwitterClient; import org.april.hebdobot.twitter.TwitterClient;
import org.april.hebdobot.twitter.TwitterSettings; import org.april.hebdobot.twitter.TwitterSettings;
import org.april.hebdobot.util.Timekeeper; import org.april.hebdobot.util.Timekeeper;
@ -86,7 +86,7 @@ public class Hebdobot extends PircBot
private Review review; private Review review;
private Timekeeper timekeeper; private Timekeeper timekeeper;
private IdenticaSettings identicaSettings; private IdenticaSettings identicaSettings;
private PastebinSettings pastebinSettings; private PrivatebinSettings privatebinSettings;
private TwitterSettings twitterSettings; private TwitterSettings twitterSettings;
private CronSettings cronSettings; private CronSettings cronSettings;
private UserAliases aliases; private UserAliases aliases;
@ -130,7 +130,7 @@ public class Hebdobot extends PircBot
this.timekeeper = new Timekeeper(); this.timekeeper = new Timekeeper();
this.identicaSettings = new IdenticaSettings(); this.identicaSettings = new IdenticaSettings();
this.pastebinSettings = new PastebinSettings(); this.privatebinSettings = new PrivatebinSettings();
this.twitterSettings = new TwitterSettings(); this.twitterSettings = new TwitterSettings();
this.cronSettings = new CronSettings(); this.cronSettings = new CronSettings();
this.aliases = new UserAliases(); this.aliases = new UserAliases();
@ -221,13 +221,13 @@ public class Hebdobot extends PircBot
} }
/** /**
* Gets the pastebin settings. * Gets the privatebin settings.
* *
* @return the pastebin settings * @return the privatebin settings
*/ */
public PastebinSettings getPastebinSettings() public PrivatebinSettings getPrivatebinSettings()
{ {
return this.pastebinSettings; return this.privatebinSettings;
} }
public Review getReview() public Review getReview()

View File

@ -33,8 +33,7 @@ import org.april.hebdobot.bot.stats.ReviewData;
import org.april.hebdobot.bot.stats.ReviewDatas; import org.april.hebdobot.bot.stats.ReviewDatas;
import org.april.hebdobot.bot.stats.ReviewDatasFile; import org.april.hebdobot.bot.stats.ReviewDatasFile;
import org.april.hebdobot.bot.stats.ReviewStatsReporter; import org.april.hebdobot.bot.stats.ReviewStatsReporter;
import org.april.hebdobot.pastebin.PastebinClient; import org.april.hebdobot.privatebin.PrivatebinClient;
import org.april.hebdobot.pastebin.Private;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -115,14 +114,14 @@ public class FinishReviewHook extends Hook
// Pastebin the review text. // Pastebin the review text.
String pastebinUrl; String pastebinUrl;
if (bot.getPastebinSettings().isValid()) if (bot.getPrivatebinSettings().isValid())
{ {
logger.info("Pastebin the review."); logger.info("Pastebin the review.");
try try
{ {
PastebinClient pastebinClient = new PastebinClient(bot.getPastebinSettings().getApiKey()); PrivatebinClient pastebinClient = new PrivatebinClient(bot.getPrivatebinSettings());
pastebinUrl = pastebinClient.paste(reviewText, "Revue APRIL " + date, Private.UNLISTED); pastebinUrl = pastebinClient.paste(reviewText);
} }
catch (final Exception exception) catch (final Exception exception)
{ {

View File

@ -55,7 +55,7 @@ public class StatusHook extends Hook
} }
bot.sendMessage(sender, " Alias settings : " + (bot.getAliases().size())); bot.sendMessage(sender, " Alias settings : " + (bot.getAliases().size()));
bot.sendMessage(sender, " Identica settings : " + (bot.getIdenticaSettings().isValid())); bot.sendMessage(sender, " Identica settings : " + (bot.getIdenticaSettings().isValid()));
bot.sendMessage(sender, " Pastebin settings : " + (bot.getPastebinSettings().isValid())); bot.sendMessage(sender, " Pastebin settings : " + bot.getPrivatebinSettings().toString());
bot.sendMessage(sender, " Twitter settings : " + (bot.getTwitterSettings().isValid())); bot.sendMessage(sender, " Twitter settings : " + (bot.getTwitterSettings().isValid()));
bot.sendMessage(sender, " Cron settings : " + (bot.getCronSettings().size())); bot.sendMessage(sender, " Cron settings : " + (bot.getCronSettings().size()));
bot.sendMessage(sender, " Review Wait Time : " + (bot.getReviewWaitTime())); bot.sendMessage(sender, " Review Wait Time : " + (bot.getReviewWaitTime()));

View File

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org> * Copyright (C) 2017-2021 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr> * Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
* *
* This file is part of (April) Hebdobot. * This file is part of (April) Hebdobot.
@ -209,7 +209,7 @@ public class HebdobotCLI
// //
logger.info("Bot configuring…"); logger.info("Bot configuring…");
bot.getPastebinSettings().setApiKey(config.getPastebinApiKey()); bot.getPrivatebinSettings().setServerUrl(config.getPrivatebinUrl());
bot.getIdenticaSettings().setApiKey(config.getIdenticaApiKey()); bot.getIdenticaSettings().setApiKey(config.getIdenticaApiKey());
bot.getIdenticaSettings().setApiSecret(config.getIdenticaApiSecret()); bot.getIdenticaSettings().setApiSecret(config.getIdenticaApiSecret());
bot.getTwitterSettings().setConsumerKey(config.getTwitterConsumerKey()); bot.getTwitterSettings().setConsumerKey(config.getTwitterConsumerKey());

View File

@ -21,6 +21,8 @@ package org.april.hebdobot.cli;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Properties; import java.util.Properties;
@ -332,30 +334,23 @@ public class HebdobotConfigFile extends Properties
} }
/** /**
* Gets the pastebin api key. * Gets the private bin url.
* *
* @return the pastebin api key * @return the private bin url
*/ */
public String getPastebinApiKey() public URL getPrivatebinUrl()
{ {
String result; URL result;
result = getProperty("pastebin.apiKey"); try
{
// String value = getProperty("privatebin.url");
return result; result = new URL(value);
} }
catch (MalformedURLException exception)
/**
* Gets the name.
*
* @return the name
*/
public String getPrivateBinUrl()
{ {
String result; result = null;
}
result = getProperty("privatebin.url");
// //
return result; return result;

View File

@ -30,7 +30,6 @@ import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.zip.Deflater; import java.util.zip.Deflater;
@ -48,23 +47,21 @@ import javax.net.ssl.HttpsURLConnection;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;
import org.april.hebdobot.HebdobotException;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
/** /**
* The Class PastebinClient. * The Class PastebinClient.
*/ */
public class PrivatebinClient public class PrivatebinClient extends PrivatebinSettings
{ {
private String serverUrl; private static final Logger logger = LoggerFactory.getLogger(PrivatebinClient.class);
private Compression compression;
/** /**
* Instantiates a new privatebin client. * Instantiates a new privatebin client.
@ -72,95 +69,54 @@ public class PrivatebinClient
* @param serverUrl * @param serverUrl
* the server url * the server url
*/ */
public PrivatebinClient(final String serverUrl) public PrivatebinClient(final PrivatebinSettings settings)
{ {
this.serverUrl = serverUrl; super(settings);
this.compression = Compression.ZLIB; }
/**
* Instantiates a new privatebin client.
*
* @param url
* the url
*/
public PrivatebinClient(final URL url)
{
super();
setServerUrl(url);
} }
/** /**
* Paste. * Paste.
* *
* @param serverUrl * @param text
* the server url * the text
* @param expirationDate * @param settings
* the expiration * the settings
* @param burnAfterReading
* the burn after reading
* @param openDiscussion
* the open discussion
* @return the string * @return the string
* @throws HebdobotException
* the hebdobot exception
* @throws PrivatebinException * @throws PrivatebinException
* the privatebin exception
*/ */
public String paste(final String text, final Expiration expiration, final Formatter formatter, final BurnAfterReading burnAfterReading, public String paste(final String text) throws PrivatebinException
final OpenDiscussion openDiscussion) throws PrivatebinException
{ {
String result; String result;
result = null; result = null;
try try
{
if (expiration == null)
{
throw new IllegalArgumentException("Null parameter expiration.");
}
else if (formatter == null)
{
throw new IllegalArgumentException("Null parameter formatter.");
}
else if (burnAfterReading == null)
{
throw new IllegalArgumentException("Null parameter burn after reading.");
}
else if (openDiscussion == null)
{
throw new IllegalArgumentException("Null parameter open discussion.");
}
else
{ {
// Note: the following code is based on: // Note: the following code is based on:
// https://github.com/PrivateBin/PrivateBin/wiki/API // https://github.com/PrivateBin/PrivateBin/wiki/API
// https://github.com/kkingsley-BF/PrivateBin-Groovy/blob/master/Paste.groovy // https://github.com/kkingsley-BF/PrivateBin-Groovy/blob/master/Paste.groovy
// Optional parameters
// ===================
// Location of local file to attach, leave quotes empty for no
// file
String localAttachmentFilename = "";
// Paste attachment name, leave quotes empty for no file
String pasteAttachmentFilename = "";
// Read file contents into paste, leave quotes empty no no file
String plaintextFileLocation = "";
// Set paste password, leave quotes empty for no password
String userPastePassword = "";
//
// Generate password.
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(192);
String randomPassword = Base64.getEncoder().encodeToString(keyGen.generateKey().getEncoded());
String customPassword = randomPassword + userPastePassword;
// Generate IV.
byte[] cipherIVBytes = new byte[16];
new Random().nextBytes(cipherIVBytes);
String cipherIVEncoded = Base64.getEncoder().encodeToString(cipherIVBytes);
// Generate salt.
byte[] kdfSaltBytes = new byte[8];
new Random().nextBytes(kdfSaltBytes);
String kdfSaltEncoded = Base64.getEncoder().encodeToString(kdfSaltBytes);
// Build message to encrypt. // Build message to encrypt.
String pasteData = "{\"paste\":\"" + text + "\"}"; JSONObject pasteDataJson = new JSONObject();
pasteDataJson.put("paste", text);
String pasteData = pasteDataJson.toJSONString();
logger.debug("pasteData={}", pasteData);
// Compression. // Compression.
byte[] pasteDataBytes; byte[] pasteDataBytes;
if (StringUtils.equals(this.compression.toString(), "zlib")) if (this.compression == Compression.ZLIB)
{ {
Deflater zipDeflater = new Deflater(); Deflater zipDeflater = new Deflater();
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
@ -184,6 +140,22 @@ public class PrivatebinClient
pasteDataBytes = pasteData.getBytes(); pasteDataBytes = pasteData.getBytes();
} }
// Generate password.
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(192);
String randomPassword = Base64.getEncoder().encodeToString(keyGen.generateKey().getEncoded());
String customPassword = randomPassword + this.password;
// Generate IV.
byte[] cipherIVBytes = new byte[16];
new Random().nextBytes(cipherIVBytes);
String cipherIVEncoded = Base64.getEncoder().encodeToString(cipherIVBytes);
// Generate salt.
byte[] kdfSaltBytes = new byte[8];
new Random().nextBytes(kdfSaltBytes);
String kdfSaltEncoded = Base64.getEncoder().encodeToString(kdfSaltBytes);
// Generate secret key for cipher. // Generate secret key for cipher.
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
KeySpec passwordBasedEncryptionKeySpec = new PBEKeySpec(customPassword.toCharArray(), kdfSaltBytes, 100000, 256); KeySpec passwordBasedEncryptionKeySpec = new PBEKeySpec(customPassword.toCharArray(), kdfSaltBytes, 100000, 256);
@ -198,12 +170,12 @@ public class PrivatebinClient
gcmTagString.append("100000,256,128,"); gcmTagString.append("100000,256,128,");
gcmTagString.append("\"").append("aes").append("\"").append(","); gcmTagString.append("\"").append("aes").append("\"").append(",");
gcmTagString.append("\"").append("gcm").append("\"").append(","); gcmTagString.append("\"").append("gcm").append("\"").append(",");
gcmTagString.append("\"").append(this.compression).append("\""); gcmTagString.append("\"").append(this.compression.toString()).append("\"");
gcmTagString.append("]"); gcmTagString.append("]");
gcmTagString.append(","); gcmTagString.append(",");
gcmTagString.append("\"").append(formatter).append("\"").append(","); gcmTagString.append("\"").append(this.formatter.toString()).append("\"").append(",");
gcmTagString.append(openDiscussion).append(","); gcmTagString.append(this.openDiscussion.toString()).append(",");
gcmTagString.append(burnAfterReading); gcmTagString.append(this.burnAfterReading.toString());
gcmTagString.append("]"); gcmTagString.append("]");
byte[] gcmBytes = gcmTagString.toString().getBytes(); byte[] gcmBytes = gcmTagString.toString().getBytes();
@ -216,6 +188,7 @@ public class PrivatebinClient
cipher.updateAAD(gcmBytes); cipher.updateAAD(gcmBytes);
byte[] cipherTextBytes = cipher.doFinal(pasteDataBytes); byte[] cipherTextBytes = cipher.doFinal(pasteDataBytes);
String cipherText = Base64.getEncoder().encodeToString(cipherTextBytes); String cipherText = Base64.getEncoder().encodeToString(cipherTextBytes);
logger.debug("cipherText={}", cipherText);
// Create POST payload. // Create POST payload.
StringList payload = new StringList(); StringList payload = new StringList();
@ -223,25 +196,24 @@ public class PrivatebinClient
payload.append("\"v\":2,"); payload.append("\"v\":2,");
payload.append("\"adata\":").append(gcmTagString.toString()).append(","); payload.append("\"adata\":").append(gcmTagString.toString()).append(",");
payload.append("\"ct\":\"").append(cipherText).append("\","); payload.append("\"ct\":\"").append(cipherText).append("\",");
payload.append("\"meta\":{\"expire\":\"").append(expiration).append("\"}"); payload.append("\"meta\":{\"expire\":\"").append(this.expiration).append("\"}");
payload.append("}"); payload.append("}");
logger.debug("PAYLOAD={}", payload.toString());
// POST Request. // POST Request.
HttpsURLConnection pasteRequest = (HttpsURLConnection) new URL(this.serverUrl).openConnection(); HttpsURLConnection pasteRequest = (HttpsURLConnection) this.serverUrl.openConnection();
pasteRequest.setRequestMethod("POST"); pasteRequest.setRequestMethod("POST");
pasteRequest.setDoOutput(true); pasteRequest.setDoOutput(true);
pasteRequest.setRequestProperty("X-Requested-With", "JSONHttpRequest"); pasteRequest.setRequestProperty("X-Requested-With", "JSONHttpRequest");
pasteRequest.getOutputStream().write(payload.toString().getBytes()); pasteRequest.getOutputStream().write(payload.toString().getBytes());
System.out.println("PAYLOAD=" + payload.toString());
// Server response. // Server response.
int responseCode = pasteRequest.getResponseCode(); int responseCode = pasteRequest.getResponseCode();
System.out.println("Server response: " + responseCode); logger.debug("Server response: {}", responseCode);
if (responseCode == 200) if (responseCode == 200)
{ {
String out = IOUtils.toString(pasteRequest.getInputStream(), "UTF-8"); String out = IOUtils.toString(pasteRequest.getInputStream(), "UTF-8");
System.out.println("===> " + out); logger.debug("===> {}", out);
JSONObject parser = (JSONObject) new JSONParser().parse(out); JSONObject parser = (JSONObject) new JSONParser().parse(out);
String status = parser.get("status").toString(); String status = parser.get("status").toString();
@ -252,23 +224,25 @@ public class PrivatebinClient
String deleteToken = parser.get("deletetoken").toString(); String deleteToken = parser.get("deletetoken").toString();
String finalURL = this.serverUrl + pasteURL + "#" + Base58.encode(randomPassword.getBytes()); String finalURL = this.serverUrl + pasteURL + "#" + Base58.encode(randomPassword.getBytes());
String deleteURL = this.serverUrl + pasteURL + "&deletetoken=" + deleteToken; String deleteURL = this.serverUrl + pasteURL + "&deletetoken=" + deleteToken;
System.out.println("SUCESS"); logger.info("Pastebin SUCESS");
System.out.println("Paste URL: " + finalURL); logger.debug("Paste URL: {}", finalURL);
System.out.println("Delete URL: " + deleteURL); logger.debug("Delete URL: {}", deleteURL);
result = finalURL;
} }
else else
{ {
String output = parser.get("message").toString(); String output = parser.get("message").toString();
System.out.println("message=" + output); logger.warn("message={}", output);
throw new PrivatebinException(out); throw new PrivatebinException(out);
} }
} }
} }
}
catch (BadPaddingException | IllegalBlockSizeException | InvalidAlgorithmParameterException | InvalidKeyException | InvalidKeySpecException catch (BadPaddingException | IllegalBlockSizeException | InvalidAlgorithmParameterException | InvalidKeyException | InvalidKeySpecException
| NoSuchAlgorithmException | NoSuchPaddingException | ParseException | UnsupportedEncodingException | NoSuchAlgorithmException | NoSuchPaddingException | ParseException | UnsupportedEncodingException |
| ClientProtocolException exception)
ClientProtocolException exception)
{ {
exception.printStackTrace();
throw new PrivatebinException(exception); throw new PrivatebinException(exception);
} }
catch (IOException exception) catch (IOException exception)
@ -280,22 +254,4 @@ public class PrivatebinClient
// //
return result; return result;
} }
/**
* Sets the parameter.
*
* @param params
* the params
* @param name
* the name
* @param value
* the value
*/
private static void setParameter(final List<NameValuePair> params, final String name, final String value)
{
if (value != null)
{
params.add(new BasicNameValuePair(name, value));
}
}
} }

View File

@ -18,17 +18,20 @@
*/ */
package org.april.hebdobot.privatebin; package org.april.hebdobot.privatebin;
import org.apache.commons.lang3.StringUtils; import java.net.URL;
/** /**
* The Class PrivatebinSettings * The Class PrivatebinSettings
*/ */
public class PrivatebinSettings public class PrivatebinSettings
{ {
private String serverUrl; protected URL serverUrl;
private String expirationDate; protected Compression compression;
private String burnAfterReading; protected Expiration expiration;
private String openDiscussion; protected BurnAfterReading burnAfterReading;
protected OpenDiscussion openDiscussion;
protected Formatter formatter;
protected String password;
/** /**
* Instantiates a new Privatebin settings. * Instantiates a new Privatebin settings.
@ -36,27 +39,62 @@ public class PrivatebinSettings
public PrivatebinSettings() public PrivatebinSettings()
{ {
this.serverUrl = null; this.serverUrl = null;
this.expirationDate = null; this.compression = Compression.ZLIB;
this.burnAfterReading = null; this.expiration = Expiration.DAY_1;
this.openDiscussion = null; this.burnAfterReading = BurnAfterReading.OFF;
this.openDiscussion = OpenDiscussion.OFF;
this.formatter = Formatter.PLAINTEXT;
this.password = "";
} }
public String getBurnAfterReading() /**
* Instantiates a new privatebin settings.
*
* @param settings
* the settings
*/
public PrivatebinSettings(final PrivatebinSettings settings)
{
this.serverUrl = settings.serverUrl;
this.compression = settings.compression;
this.expiration = settings.expiration;
this.burnAfterReading = settings.burnAfterReading;
this.openDiscussion = settings.openDiscussion;
this.formatter = settings.formatter;
this.password = settings.password;
}
public BurnAfterReading getBurnAfterReading()
{ {
return this.burnAfterReading; return this.burnAfterReading;
} }
public String getExpirationDate() public Compression getCompression()
{ {
return this.expirationDate; return this.compression;
} }
public String getOpenDiscussion() public Expiration getExpiration()
{
return this.expiration;
}
public Formatter getFormatter()
{
return this.formatter;
}
public OpenDiscussion getOpenDiscussion()
{ {
return this.openDiscussion; return this.openDiscussion;
} }
public String getServerUrl() public String getPassword()
{
return this.password;
}
public URL getServerUrl()
{ {
return this.serverUrl; return this.serverUrl;
} }
@ -70,10 +108,15 @@ public class PrivatebinSettings
{ {
boolean result; boolean result;
if ((StringUtils.isBlank(this.serverUrl)) || (StringUtils.containsOnly(this.serverUrl, 'X'))) if (this.serverUrl == null)
{ {
result = false; result = false;
} }
else if ((this.burnAfterReading == BurnAfterReading.ON) && (this.openDiscussion == OpenDiscussion.ON))
{
// Burn after reading cannot be active if opendiscussion is.
result = false;
}
else else
{ {
result = true; result = true;
@ -83,23 +126,78 @@ public class PrivatebinSettings
return result; return result;
} }
public void setBurnAfterReading(final String burnAfterReading) public void setBurnAfterReading(final BurnAfterReading burnAfterReading)
{
if (burnAfterReading != null)
{ {
this.burnAfterReading = burnAfterReading; this.burnAfterReading = burnAfterReading;
} }
public void setExpirationDate(final String expirationDate)
{
this.expirationDate = expirationDate;
} }
public void setOpenDiscussion(final String openDiscussion) public void setCompression(final Compression compression)
{
if (compression != null)
{
this.compression = compression;
}
}
public void setExpiration(final Expiration expiration)
{
if (expiration != null)
{
this.expiration = expiration;
}
}
public void setFormatter(final Formatter formatter)
{
if (formatter != null)
{
this.formatter = formatter;
}
}
public void setOpenDiscussion(final OpenDiscussion openDiscussion)
{
if (openDiscussion != null)
{ {
this.openDiscussion = openDiscussion; this.openDiscussion = openDiscussion;
} }
}
public void setServerUrl(final String serverUrl) public void setPassword(final String password)
{
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
public void setServerUrl(final URL serverUrl)
{ {
this.serverUrl = serverUrl; this.serverUrl = serverUrl;
} }
/**
* To string.
*
* @return the string
*/
@Override
public String toString()
{
String result;
result = String.format("valid=%b, url=%s, formatter=%s, compression=%s, expiration=%s, burnafterreading=%s, opendiscussion=%s, password=%s",
isValid(), this.serverUrl, this.formatter, this.compression, this.expiration, this.burnAfterReading, this.openDiscussion,
this.password);
//
return result;
}
} }

View File

@ -18,6 +18,11 @@
*/ */
package org.april.hebdobot.privatebin; package org.april.hebdobot.privatebin;
import java.io.File;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.BasicConfigurator;
import org.junit.Test; import org.junit.Test;
/** /**
@ -34,13 +39,39 @@ public class PrivatebinClientTest
@Test @Test
public void testPaste00() throws Exception public void testPaste00() throws Exception
{ {
PrivatebinClient client = new PrivatebinClient("https://cpaste.org/"); PrivatebinClient client = new PrivatebinClient(new URL("https://cpaste.org/"));
// PrivatebinClient client = new // PrivatebinClient client = new
// PrivatebinClient("https://paste.chapril.org/"); // PrivatebinClient("https://paste.chapril.org/");
String text = "This is a test."; String text = "This is a test.\ntoto";
String result = client.paste(text, Expiration.MINUTE_5, Formatter.PLAINTEXT, BurnAfterReading.OFF, OpenDiscussion.OFF); client.setExpiration(Expiration.MINUTE_5);
String result = client.paste(text);
System.out.println("result:" + result);
}
/**
* Test paste 01.
*
* @throws Exception
* the exception
*/
@Test
public void testPaste01() throws Exception
{
BasicConfigurator.configure();
PrivatebinClient client = new PrivatebinClient(new URL("https://cpaste.org/"));
// PrivatebinClient client = new
// PrivatebinClient("https://paste.chapril.org/");
// String text = FileUtils.readFileToString(new
// File("./test/org/april/hebdobot/privatebin/20210305-log-irc-revue-hebdomadaire.txt"));
String text = FileUtils.readFileToString(new File("./test/org/april/hebdobot/privatebin/20210319-log-irc-revue-hebdomadaire.txt"));
client.setExpiration(Expiration.MINUTE_5);
String result = client.paste(text);
System.out.println("result:" + result); System.out.println("result:" + result);
} }