<commit_before>package it.ksuploader.main;

import it.ksuploader.dialogs.NotificationDialog;
import it.ksuploader.utils.Environment;
import it.sauronsoftware.ftp4j.FTPAbortedException;
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.FTPDataTransferException;
import it.sauronsoftware.ftp4j.FTPException;
import it.sauronsoftware.ftp4j.FTPIllegalReplyException;

import java.awt.AWTException;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class FtpUploader {
	private static FTPClient ftpClient;
	private String link;
	private String filePath;
	private NotificationDialog notificationDialog;

	// Per gli screen parziali
	public FtpUploader(Rectangle r) {
		try {

			Rectangle screenRect = new Rectangle(0, 0, 0, 0);
			for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
				screenRect = screenRect.union(gd.getDefaultConfiguration().getBounds());
			}

			BufferedImage img = new Robot().createScreenCapture(screenRect).getSubimage(r.x, r.y, r.width, r.height);

			String fileName = System.currentTimeMillis() / 1000 + "" + new Random().nextInt(999);
			File toWrite = new File(new Environment().getTempDir() + "/" + fileName + ".png");
			ImageIO.write(img, "png", toWrite);

			if (Main.config.isSaveEnabled()) {
				ImageIO.write(img, "png", new File(Main.config.getSaveDir() + "/" + System.currentTimeMillis() / 1000
						+ fileName + ".png"));
				Main.myLog("[Uploader] Screen saved");
			}

			this.filePath = toWrite.getPath();

		} catch (AWTException | IOException ex) {
			ex.printStackTrace();
			Main.myErr(Arrays.toString(ex.getStackTrace()).replace(",", "\n"));
		}
	}

	// Per gli screen completi
	public FtpUploader(BufferedImage bi) {

		try {

			BufferedImage img = bi;

			String fileName = System.currentTimeMillis() / 1000 + "" + new Random().nextInt(999);
			File toWrite = new File(new Environment().getTempDir() + "/" + fileName + ".png");
			ImageIO.write(img, "png", toWrite);

			if (Main.config.isSaveEnabled()) {
				ImageIO.write(img, "png", new File(Main.config.getSaveDir() + "/" + System.currentTimeMillis() / 1000
						+ fileName + ".png"));
				Main.myLog("[Uploader] Screen saved");
			}

			this.filePath = toWrite.getPath();
		} catch (IOException ex) {
			ex.printStackTrace();
			Main.myErr(Arrays.toString(ex.getStackTrace()).replace(",", "\n"));
		}
	}

	// Per i file
	public FtpUploader(String filePath) {

		this.filePath = filePath;
	}

	public boolean send(String type) {

		ftpClient = new FTPClient();
		notificationDialog = new NotificationDialog();

		if (Main.config.getFtpesEnabled()) {

			try {

				// Setting up tls connection
				TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() {
					public X509Certificate[] getAcceptedIssuers() {
						return null;
					}

					public void checkClientTrusted(X509Certificate[] certs, String authType) {
					}

					public void checkServerTrusted(X509Certificate[] certs, String authType) {
					}
				} };

				SSLContext sslContext = null;

				sslContext = SSLContext.getInstance("TLS");
				sslContext.init(null, trustManager, new SecureRandom());

				SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
				ftpClient.setSSLSocketFactory(sslSocketFactory);
				ftpClient.setSecurity(FTPClient.SECURITY_FTPES);

			} catch (NoSuchAlgorithmException | KeyManagementException e) {

				e.printStackTrace();
				notificationDialog.show("Connection error", "Unable to connect to the server via ftpes");<commit_msg>Accept all certificates or only defaults<commit_after>package it.ksuploader.main;

import it.ksuploader.dialogs.NotificationDialog;
import it.ksuploader.utils.Environment;
import it.sauronsoftware.ftp4j.FTPAbortedException;
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.FTPDataTransferException;
import it.sauronsoftware.ftp4j.FTPException;
import it.sauronsoftware.ftp4j.FTPIllegalReplyException;

import java.awt.AWTException;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class FtpUploader {
	private static FTPClient ftpClient;
	private String link;
	private String filePath;
	private NotificationDialog notificationDialog;

	// Per gli screen parziali
	public FtpUploader(Rectangle r) {
		try {

			Rectangle screenRect = new Rectangle(0, 0, 0, 0);
			for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
				screenRect = screenRect.union(gd.getDefaultConfiguration().getBounds());
			}

			BufferedImage img = new Robot().createScreenCapture(screenRect).getSubimage(r.x, r.y, r.width, r.height);

			String fileName = System.currentTimeMillis() / 1000 + "" + new Random().nextInt(999);
			File toWrite = new File(new Environment().getTempDir() + "/" + fileName + ".png");
			ImageIO.write(img, "png", toWrite);

			if (Main.config.isSaveEnabled()) {
				ImageIO.write(img, "png", new File(Main.config.getSaveDir() + "/" + System.currentTimeMillis() / 1000
						+ fileName + ".png"));
				Main.myLog("[Uploader] Screen saved");
			}

			this.filePath = toWrite.getPath();

		} catch (AWTException | IOException ex) {
			ex.printStackTrace();
			Main.myErr(Arrays.toString(ex.getStackTrace()).replace(",", "\n"));
		}
	}

	// Per gli screen completi
	public FtpUploader(BufferedImage bi) {

		try {

			BufferedImage img = bi;

			String fileName = System.currentTimeMillis() / 1000 + "" + new Random().nextInt(999);
			File toWrite = new File(new Environment().getTempDir() + "/" + fileName + ".png");
			ImageIO.write(img, "png", toWrite);

			if (Main.config.isSaveEnabled()) {
				ImageIO.write(img, "png", new File(Main.config.getSaveDir() + "/" + System.currentTimeMillis() / 1000
						+ fileName + ".png"));
				Main.myLog("[Uploader] Screen saved");
			}

			this.filePath = toWrite.getPath();
		} catch (IOException ex) {
			ex.printStackTrace();
			Main.myErr(Arrays.toString(ex.getStackTrace()).replace(",", "\n"));
		}
	}

	// Per i file
	public FtpUploader(String filePath) {

		this.filePath = filePath;
	}

	public boolean send(String type) {

		ftpClient = new FTPClient();
		notificationDialog = new NotificationDialog();

		if (Main.config.getFtpesEnabled()) {

			try {

				// Setting up tls connection
				if (Main.config.isAcceptAllCertificates()) {

					TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() {
						public X509Certificate[] getAcceptedIssuers() {
							return null;
						}

						public void checkClientTrusted(X509Certificate[] certs, String authType) {
						}

						public void checkServerTrusted(X509Certificate[] certs, String authType) {
						}
					} };

					SSLContext sslContext = null;

					sslContext = SSLContext.getInstance("TLS");
					sslContext.init(null, trustManager, new SecureRandom());

					SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
					ftpClient.setSSLSocketFactory(sslSocketFactory);
				} else {
					ftpClient.setSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
				}

				ftpClient.setSecurity(FTPClient.SECURITY_FTPES);

			} catch (NoSuchAlgorithmException | KeyManagementException e) {

				e.printStackTrace();
				notificationDialog.show("Connection error", "Unable to connect to the server via ftpes");
{'fraction_non_alphanumeric': 0.12567132116004295, 'fraction_numerical': 0.011695906432748537, 'mean_word_length': 4.4628422425032594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4215147', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2567, 'n_words': 531}