Compare commits
No commits in common. "release1.1" and "master" have entirely different histories.
release1.1
...
master
|
@ -0,0 +1,8 @@
|
||||||
|
<component name="ArtifactManager">
|
||||||
|
<artifact type="jar" name="dhaverdLogs">
|
||||||
|
<output-path>$PROJECT_DIR$/out/artifacts/dhaverdLogs</output-path>
|
||||||
|
<root id="archive" name="dhaverdLogs.jar">
|
||||||
|
<element id="module-output" name="dhaverd_logs" />
|
||||||
|
</root>
|
||||||
|
</artifact>
|
||||||
|
</component>
|
|
@ -1,12 +0,0 @@
|
||||||
<component name="ArtifactManager">
|
|
||||||
<artifact type="jar" name="proxy">
|
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/proxy</output-path>
|
|
||||||
<root id="archive" name="proxy.jar">
|
|
||||||
<element id="module-output" name="proxy" />
|
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/lib/dhaverdLogs.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/lib/json-simple-1.1.1.jar" path-in-jar="/" />
|
|
||||||
<element id="library" level="project" name="dhaverdLogs" />
|
|
||||||
<element id="library" level="project" name="json-simple-1.1.1" />
|
|
||||||
</root>
|
|
||||||
</artifact>
|
|
||||||
</component>
|
|
|
@ -1,9 +0,0 @@
|
||||||
<component name="libraryTable">
|
|
||||||
<library name="dhaverdLogs">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/dhaverdLogs.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</component>
|
|
|
@ -1,9 +0,0 @@
|
||||||
<component name="libraryTable">
|
|
||||||
<library name="json-simple-1.1.1">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/json-simple-1.1.1.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</component>
|
|
|
@ -2,7 +2,7 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/proxy.iml" filepath="$PROJECT_DIR$/proxy.iml" />
|
<module fileurl="file://$PROJECT_DIR$/dhaverd_logs.iml" filepath="$PROJECT_DIR$/dhaverd_logs.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -7,7 +7,5 @@
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="dhaverdLogs" level="project" />
|
|
||||||
<orderEntry type="library" name="json-simple-1.1.1" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,4 +0,0 @@
|
||||||
@echo off
|
|
||||||
cls
|
|
||||||
java -jar proxy.jar
|
|
||||||
exit
|
|
|
@ -1,4 +0,0 @@
|
||||||
@echo off
|
|
||||||
cls
|
|
||||||
start /B javaw -jar proxy.jar
|
|
||||||
exit
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"port" : "7458",
|
|
||||||
"proxyList" : [
|
|
||||||
"http://ideco.mcs.br/wpad.dat",
|
|
||||||
"http://proxy.mcs.br:8080/array.dll?Get.Routing.Script"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
[2023-03-16 12:02:03] [SystemTray] System tray launched
|
|
||||||
[2023-03-16 12:02:17] [Pregram] Exiting program
|
|
|
@ -1,2 +0,0 @@
|
||||||
[2023-03-16 12:02:50] [SystemTray] System tray launched
|
|
||||||
[2023-03-16 12:03:31] [Program] Exiting program
|
|
|
@ -1,6 +0,0 @@
|
||||||
[2023-03-16 12:17:43] [Config Loading] Port loaded: 7458
|
|
||||||
[2023-03-16 12:17:43] [BindSocket] Socket binded
|
|
||||||
[2023-03-16 12:17:43] [BindSocket] Local Socket Address: localhost/127.0.0.1:7458
|
|
||||||
[2023-03-16 12:17:43] [SystemTray] System tray launched
|
|
||||||
[2023-03-16 12:18:06] [Program] Closing server socket...
|
|
||||||
[2023-03-16 12:18:06] [Program] Exiting program
|
|
|
@ -1,6 +0,0 @@
|
||||||
[2023-03-16 12:19:34] [Config Loading] Port loaded: 7458
|
|
||||||
[2023-03-16 12:19:34] [BindSocket] Socket binded
|
|
||||||
[2023-03-16 12:19:34] [BindSocket] Local Socket Address: localhost/127.0.0.1:7458
|
|
||||||
[2023-03-16 12:19:35] [SystemTray] System tray launched
|
|
||||||
[2023-03-16 12:19:38] [Program] Closing server socket...
|
|
||||||
[2023-03-16 12:19:38] [Program] Exiting program
|
|
|
@ -1,6 +0,0 @@
|
||||||
[2023-03-16 12:33:27] [Config Loading] Port loaded: 7458
|
|
||||||
[2023-03-16 12:33:27] [BindSocket] Socket binded
|
|
||||||
[2023-03-16 12:33:27] [BindSocket] Local Socket Address: localhost/127.0.0.1:7458
|
|
||||||
[2023-03-16 12:33:27] [SystemTray] System tray launched
|
|
||||||
[2023-03-16 12:33:29] [Program] Closing server socket...
|
|
||||||
[2023-03-16 12:33:29] [Program] Exiting program
|
|
|
@ -1,7 +0,0 @@
|
||||||
[2023-03-29 17:02:36] [Config Loading] Port loaded: 7458
|
|
||||||
[2023-03-29 17:02:36] [BindSocket] Socket binded
|
|
||||||
[2023-03-29 17:02:36] [BindSocket] Local Socket Address: localhost/127.0.0.1:7458
|
|
||||||
[2023-03-29 17:02:36] [Config Loading] Proxy list loaded. Items count: 2
|
|
||||||
[Config Loading] Proxy list item: http://ideco.mcs.br/wpad.dat
|
|
||||||
[Config Loading] Proxy list item: http://proxy.mcs.br:8080/array.dll?Get.Routing.Script
|
|
||||||
[2023-03-29 17:02:37] [SystemTray] System tray launched
|
|
|
@ -1,7 +0,0 @@
|
||||||
[2023-03-29 17:04:54] [Config Loading] Port loaded: 7458
|
|
||||||
[2023-03-29 17:04:54] [BindSocket] Socket binded
|
|
||||||
[2023-03-29 17:04:54] [BindSocket] Local Socket Address: localhost/127.0.0.1:7458
|
|
||||||
[2023-03-29 17:04:54] [Config Loading] Proxy list loaded. Items count: 2
|
|
||||||
[Config Loading] Proxy list item: http://ideco.mcs.br/wpad.dat
|
|
||||||
[Config Loading] Proxy list item: http://proxy.mcs.br:8080/array.dll?Get.Routing.Script
|
|
||||||
[2023-03-29 17:04:55] [SystemTray] System tray launched
|
|
|
@ -1,7 +0,0 @@
|
||||||
[2023-03-29 17:05:52] [Config Loading] Port loaded: 7458
|
|
||||||
[2023-03-29 17:05:52] [BindSocket] Socket binded
|
|
||||||
[2023-03-29 17:05:52] [BindSocket] Local Socket Address: localhost/127.0.0.1:7458
|
|
||||||
[2023-03-29 17:05:52] [Config Loading] Proxy list loaded. Items count: 2
|
|
||||||
[Config Loading] Proxy list item: http://ideco.mcs.br/wpad.dat
|
|
||||||
[Config Loading] Proxy list item: http://proxy.mcs.br:8080/array.dll?Get.Routing.Script
|
|
||||||
[2023-03-29 17:05:52] [SystemTray] System tray launched
|
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.0 KiB |
|
@ -1,4 +0,0 @@
|
||||||
@echo off
|
|
||||||
cls
|
|
||||||
start /B javaw -jar proxy.jar
|
|
||||||
exit
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: Main
|
||||||
|
|
Binary file not shown.
|
@ -1,3 +0,0 @@
|
||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: org.proxy.Main
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,3 @@
|
||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: org.proxy.Main
|
Main-Class: Main
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
package org.dhaverdLogs;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.Period;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DhaverdLogs {
|
||||||
|
public static final String osSeparator = System.getProperty("file.separator");
|
||||||
|
public static final String indent = " ".repeat(22);
|
||||||
|
public static String fileName = "log.log";
|
||||||
|
public static String logDir = "";
|
||||||
|
|
||||||
|
public static void logCleaner(boolean deleteBySevenDays) throws IOException {
|
||||||
|
File dir = new File(logDir);
|
||||||
|
if (!dir.isDirectory()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File[] fileList = dir.listFiles();
|
||||||
|
assert fileList != null;
|
||||||
|
for (File file : fileList){
|
||||||
|
String fileName = file.getName();
|
||||||
|
if (!fileName.contains("gitignore") && file.getName() != getLogFile().getName()){
|
||||||
|
if (deleteBySevenDays){
|
||||||
|
String[] params = fileName.split("_");
|
||||||
|
String date = params[0];
|
||||||
|
date = date.replace('.', '-');
|
||||||
|
String time = params[1];
|
||||||
|
time = time.replace('-', ':');
|
||||||
|
String dateTime = date + "T" + time;
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
LocalDateTime logDateTime = LocalDateTime.parse(dateTime);
|
||||||
|
Duration duration = Duration.between(logDateTime, now);
|
||||||
|
long diff = Math.abs(duration.toDays());
|
||||||
|
if (diff > 7){
|
||||||
|
setLog("Log cleaner", "File " + file.getName() + " is deleted: " + file.delete(), true, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setLog("Log cleaner", "File " + file.getName() + " is deleted: " + file.delete(), true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void setLogName(String name){
|
||||||
|
String time = getCurrentTime();
|
||||||
|
time = time.replace("[", "");
|
||||||
|
time = time.replace("]", "");
|
||||||
|
time = time.replace("-", ".");
|
||||||
|
time = time.replace(":", "-");
|
||||||
|
time = time.replace(" ", "_");
|
||||||
|
fileName = time + name + ".log";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLogDir(String dir){
|
||||||
|
logDir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getLogFile(){
|
||||||
|
return new File(logDir + osSeparator + fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLog(String context, String text, boolean addTime, boolean addIndent) throws IOException {
|
||||||
|
File log = getLogFile();
|
||||||
|
String finalText = "";
|
||||||
|
if (addIndent){
|
||||||
|
finalText += indent;
|
||||||
|
}
|
||||||
|
if (addTime){
|
||||||
|
finalText += getCurrentTime();
|
||||||
|
}
|
||||||
|
finalText += "[" + context + "] ";
|
||||||
|
finalText += text;
|
||||||
|
finalText = finalText.replace("\n", "\n" + indent);
|
||||||
|
FileWriter writer = new FileWriter(log, true);
|
||||||
|
writer.write(finalText + "\r\n");
|
||||||
|
System.out.println(finalText);
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCurrentTime(){
|
||||||
|
String time;
|
||||||
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
time = "[" + dtf.format(now) + "] ";
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearFile(File file) throws IOException {
|
||||||
|
FileWriter writer = new FileWriter(file, false);
|
||||||
|
writer.write("");
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean deleteFile(File file){
|
||||||
|
return file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean exeptionActions(String logContext, Exception ex){
|
||||||
|
try{
|
||||||
|
setLog(logContext, "Ошибка!", false, false);
|
||||||
|
setLog(logContext, ex.getLocalizedMessage() + "\n" + ex.getMessage(), true, false);
|
||||||
|
for (StackTraceElement trace : ex.getStackTrace()){
|
||||||
|
setLog(logContext, trace.toString(), false, true);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException | IOException exc){
|
||||||
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,197 +0,0 @@
|
||||||
package org.proxy;
|
|
||||||
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static javax.swing.JOptionPane.showMessageDialog;
|
|
||||||
import static org.dhaverdLogs.DhaverdLogs.*;
|
|
||||||
import static org.proxy.loadConfig.getProxyList;
|
|
||||||
import static org.proxy.loadConfig.getSocketPort;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("linux");
|
|
||||||
public static ServerSocket serverSocket;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
serverSocket = new ServerSocket();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Main() throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, ParseException {
|
|
||||||
setLogDir("logs");
|
|
||||||
setLogName("startup");
|
|
||||||
bindSocket();
|
|
||||||
systemTray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void bindSocket() throws IOException, ParseException {
|
|
||||||
String context = "BindSocket";
|
|
||||||
InetAddress inetAddress = InetAddress.getByName("localhost");
|
|
||||||
int port = getSocketPort();
|
|
||||||
SocketAddress endPoint = new InetSocketAddress(inetAddress, port);
|
|
||||||
try {
|
|
||||||
serverSocket.bind(endPoint);
|
|
||||||
} catch (BindException e) {
|
|
||||||
showMessageDialog(null, "Приложение уже запущено");
|
|
||||||
exeptionActions(context, e);
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
setLog(context, "Socket binded", true, false);
|
|
||||||
setLog(context, "Local Socket Address: "+serverSocket.getLocalSocketAddress(), true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void systemTray() throws IOException, ParseException {
|
|
||||||
String context = "SystemTray";
|
|
||||||
if(! SystemTray.isSupported() ) {
|
|
||||||
setLog(context,"System tray is unsupported!", true, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Font trayFont;
|
|
||||||
if (isLinux){
|
|
||||||
trayFont = new Font("Tempora LGC Uni", Font.PLAIN, 16);
|
|
||||||
} else {
|
|
||||||
trayFont = new Font("Arial", Font.PLAIN, 12);
|
|
||||||
}
|
|
||||||
List<String> proxyList = getProxyList();
|
|
||||||
int counter = 1;
|
|
||||||
PopupMenu trayMenu = new PopupMenu();
|
|
||||||
for (String prox : proxyList){
|
|
||||||
MenuItem proxy = new MenuItem(prox);
|
|
||||||
counter++;
|
|
||||||
proxy.setFont(trayFont);
|
|
||||||
proxy.addActionListener(proxyListener(prox));
|
|
||||||
trayMenu.add(proxy);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
PopupMenu trayMenu = new PopupMenu();
|
|
||||||
MenuItem proxyOn = new MenuItem("Proxy On");
|
|
||||||
proxyOn.setFont(trayFont);
|
|
||||||
proxyOn.addActionListener(proxyOnListener());
|
|
||||||
MenuItem proxyOff = new MenuItem("Proxy Off");
|
|
||||||
proxyOff.setFont(trayFont);
|
|
||||||
proxyOff.addActionListener(proxyOffListener());
|
|
||||||
*/
|
|
||||||
MenuItem trayExit = new MenuItem("Exit");
|
|
||||||
trayExit.setFont(trayFont);
|
|
||||||
trayExit.addActionListener(trayExitListener());
|
|
||||||
/*
|
|
||||||
trayMenu.add(proxyOn);
|
|
||||||
trayMenu.add(proxyOff);
|
|
||||||
*/
|
|
||||||
trayMenu.add(trayExit);
|
|
||||||
Image icon;
|
|
||||||
if (isLinux){
|
|
||||||
icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon.png");
|
|
||||||
} else {
|
|
||||||
icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon.png");
|
|
||||||
}
|
|
||||||
TrayIcon trayIcon = new TrayIcon(icon, "Proxy", trayMenu);
|
|
||||||
if (isLinux){
|
|
||||||
trayIcon.setImageAutoSize(false);
|
|
||||||
} else {
|
|
||||||
trayIcon.setImageAutoSize(true);
|
|
||||||
}
|
|
||||||
SystemTray tray = SystemTray.getSystemTray();
|
|
||||||
try {
|
|
||||||
tray.add(trayIcon);
|
|
||||||
} catch (AWTException e) {
|
|
||||||
exeptionActions(context, e);
|
|
||||||
}
|
|
||||||
setLog(context,"System tray launched", true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ActionListener trayExitListener() {
|
|
||||||
ActionListener listener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
setLog("Program","Closing server socket...", true, false);
|
|
||||||
setLog( "Program","Exiting program", true, false);
|
|
||||||
serverSocket.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
exeptionActions("TrayExitListener", ex);
|
|
||||||
}
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ActionListener proxyOnListener() {
|
|
||||||
ActionListener listener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
setProxyOn();
|
|
||||||
} catch (IOException | InterruptedException ex) {
|
|
||||||
exeptionActions("ProxyOn", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ActionListener proxyListener(String proxyStr) {
|
|
||||||
ActionListener listener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
setProxy(proxyStr);
|
|
||||||
} catch (IOException | InterruptedException ex) {
|
|
||||||
exeptionActions("ProxyOn", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ActionListener proxyOffListener() {
|
|
||||||
ActionListener listener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
setProxyOff();
|
|
||||||
} catch (IOException | InterruptedException ex) {
|
|
||||||
exeptionActions("ProxyOff", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setProxy(String proxyStr) throws IOException, InterruptedException {
|
|
||||||
execute("reg delete \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /f");
|
|
||||||
execute("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /t REG_SZ /d \"" + proxyStr + "\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setProxyOn() throws IOException, InterruptedException {
|
|
||||||
execute("reg delete \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /f");
|
|
||||||
execute("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /t REG_SZ /d \"http://proxy.mcs.br:8080/array.dll?Get.Routing.Script\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setProxyOff() throws IOException, InterruptedException {
|
|
||||||
execute("reg delete \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /f");
|
|
||||||
execute("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /t REG_SZ /d \"http://ideco.mcs.br/wpad.dat\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute(String command) throws IOException, InterruptedException {
|
|
||||||
Process proc = Runtime.getRuntime().exec(command);
|
|
||||||
proc.waitFor();
|
|
||||||
proc.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package org.proxy;
|
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.dhaverdLogs.DhaverdLogs.setLog;
|
|
||||||
|
|
||||||
public class loadConfig {
|
|
||||||
|
|
||||||
public static JSONObject getJsonObjConfig() throws IOException, ParseException {
|
|
||||||
File config = getConfigFile();
|
|
||||||
FileReader reader = new FileReader(config);
|
|
||||||
Object obj = new JSONParser().parse(reader);
|
|
||||||
JSONObject jo = (JSONObject) obj;
|
|
||||||
reader.close();
|
|
||||||
return jo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getConfigFile() throws IOException {
|
|
||||||
File config = new File("config/config.json");
|
|
||||||
if (config.exists()) {
|
|
||||||
return config;
|
|
||||||
} else {
|
|
||||||
createConfig(config);
|
|
||||||
config = new File("config/config.json");
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void createConfig(File config) throws IOException {
|
|
||||||
String[] props = {
|
|
||||||
"{",
|
|
||||||
"\t\"port\" : \"7458\"",
|
|
||||||
"}"
|
|
||||||
};
|
|
||||||
FileWriter writer = new FileWriter(config, true);
|
|
||||||
for (int i = 0; i < props.length; i++){
|
|
||||||
writer.write(props[i]+"\n");
|
|
||||||
}
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getSocketPort() throws IOException, ParseException {
|
|
||||||
JSONObject jo = getJsonObjConfig();
|
|
||||||
String result = String.valueOf(jo.get("port"));
|
|
||||||
setLog("Config Loading", "Port loaded: " + result, true, false);
|
|
||||||
return Integer.parseInt(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getProxyList() throws IOException, ParseException {
|
|
||||||
JSONObject jo = getJsonObjConfig();
|
|
||||||
List<String> result = (List<String>) jo.get("proxyList");
|
|
||||||
setLog("Config Loading", "Proxy list loaded. Items count: " + result.size(), true, false);
|
|
||||||
for (String line : result) {
|
|
||||||
setLog("Config Loading", "Proxy list item: " + line, false, true);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue