add readme
Some checks failed
Fetch new Pia Servers / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 15s
Some checks failed
Fetch new Pia Servers / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 15s
This commit is contained in:
parent
e8fb29a911
commit
92c6bcf3be
@ -46,6 +46,7 @@ jobs:
|
|||||||
git config --global user.email "liam@fascinated.cc"
|
git config --global user.email "liam@fascinated.cc"
|
||||||
git config --global user.name "Liam"
|
git config --global user.name "Liam"
|
||||||
git add servers.json
|
git add servers.json
|
||||||
git commit -m "Update PIA Servers"
|
git add readme.me
|
||||||
|
git commit -m "Scheduled update"
|
||||||
git push https://fascinated:${{ secrets.AUTH_TOKEN }}@git.fascinated.cc/Fascinated/PIA-Servers
|
git push https://fascinated:${{ secrets.AUTH_TOKEN }}@git.fascinated.cc/Fascinated/PIA-Servers
|
||||||
|
|
||||||
|
3880
servers.json
3880
servers.json
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
|||||||
package cc.fascinated.piaservers;
|
package cc.fascinated.piaservers;
|
||||||
|
|
||||||
import cc.fascinated.piaservers.pia.PiaManager;
|
import cc.fascinated.piaservers.pia.PiaManager;
|
||||||
|
import cc.fascinated.piaservers.readme.ReadMeManager;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
@ -13,5 +14,6 @@ public class Main {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new PiaManager();
|
new PiaManager();
|
||||||
|
new ReadMeManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ public class PiaManager {
|
|||||||
private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
|
private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
|
||||||
private static final String PIA_OPENVPN_CONFIGS_URL = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
|
private static final String PIA_OPENVPN_CONFIGS_URL = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
|
||||||
private static final long REMOVAL_THRESHOLD = TimeUnit.DAYS.toMicros(14); // 2 weeks
|
private static final long REMOVAL_THRESHOLD = TimeUnit.DAYS.toMicros(14); // 2 weeks
|
||||||
|
public static List<PiaServer> SERVERS = new ArrayList<>();
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public PiaManager() {
|
public PiaManager() {
|
||||||
@ -38,20 +39,20 @@ public class PiaManager {
|
|||||||
System.out.println("Found " + piaDomain.size() + " pia domains");
|
System.out.println("Found " + piaDomain.size() + " pia domains");
|
||||||
|
|
||||||
// Load the serversFile from the file
|
// Load the serversFile from the file
|
||||||
List<PiaServer> servers = Main.GSON.fromJson(Files.readString(serversFile.toPath()), new TypeToken<List<PiaServer>>() {}.getType());
|
SERVERS = Main.GSON.fromJson(Files.readString(serversFile.toPath()), new TypeToken<List<PiaServer>>() {}.getType());
|
||||||
if (servers == null) {
|
if (SERVERS == null) {
|
||||||
servers = new ArrayList<>();
|
SERVERS = new ArrayList<>();
|
||||||
}
|
}
|
||||||
List<PiaServer> toRemove = new ArrayList<>();
|
List<PiaServer> toRemove = new ArrayList<>();
|
||||||
|
|
||||||
System.out.println("Removing old servers...");
|
System.out.println("Removing old servers...");
|
||||||
// Get the servers that need to be removed
|
// Get the servers that need to be removed
|
||||||
for (PiaServer server : servers) {
|
for (PiaServer server : SERVERS) {
|
||||||
if (server.getLastSeen().getTime() < System.currentTimeMillis() - REMOVAL_THRESHOLD) {
|
if (server.getLastSeen().getTime() < System.currentTimeMillis() - REMOVAL_THRESHOLD) {
|
||||||
toRemove.add(server);
|
toRemove.add(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
servers.removeAll(toRemove); // Remove the servers
|
SERVERS.removeAll(toRemove); // Remove the servers
|
||||||
System.out.printf("Removed %s old servers\n", toRemove.size());
|
System.out.printf("Removed %s old servers\n", toRemove.size());
|
||||||
|
|
||||||
// Add the new servers to the list
|
// Add the new servers to the list
|
||||||
@ -59,12 +60,12 @@ public class PiaManager {
|
|||||||
InetAddress address = InetAddress.getByName(serverToken.getHostname());
|
InetAddress address = InetAddress.getByName(serverToken.getHostname());
|
||||||
|
|
||||||
// Add the server to the list
|
// Add the server to the list
|
||||||
servers.add(new PiaServer(address.getHostAddress(), serverToken.getRegion(), new Date()));
|
SERVERS.add(new PiaServer(address.getHostAddress(), serverToken.getRegion(), new Date()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the servers to the file
|
// Save the servers to the file
|
||||||
Files.writeString(serversFile.toPath(), Main.GSON.toJson(servers));
|
Files.writeString(serversFile.toPath(), Main.GSON.toJson(SERVERS));
|
||||||
System.out.printf("Wrote %s servers to the file\n", servers.size());
|
System.out.printf("Wrote %s servers to the file\n", SERVERS.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package cc.fascinated.piaservers.readme;
|
||||||
|
|
||||||
|
import cc.fascinated.piaservers.Main;
|
||||||
|
import cc.fascinated.piaservers.pia.PiaManager;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ReadMeManager {
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public ReadMeManager() {
|
||||||
|
InputStream readmeStream = Main.class.getResourceAsStream("/README.md");
|
||||||
|
if (readmeStream == null) {
|
||||||
|
System.out.println("Failed to find README.md");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File readmeFile = new File("README.md");
|
||||||
|
if (!readmeFile.exists()) {
|
||||||
|
readmeFile.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
String contents = new String(readmeStream.readAllBytes());
|
||||||
|
contents = contents.replace("{server_count}", String.valueOf(PiaManager.SERVERS.size()));
|
||||||
|
contents = contents.replace("{last_update}", new Date().toString().replaceAll(" ", "_"));
|
||||||
|
|
||||||
|
Files.write(readmeFile.toPath(), contents.getBytes());
|
||||||
|
}
|
||||||
|
}
|
5
src/main/resources/README.md
Normal file
5
src/main/resources/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# PIA Server List
|
||||||
|
|
||||||
|
![Servers](https://img.shields.io/badge/servers-{server_count}-brightgreen) ![Last update](https://img.shields.io/badge/{last_update}-brightgreen)
|
||||||
|
|
||||||
|
This is a list of the OpenVPN servers provided by Private Internet Access (PIA). The list is updated hourly.
|
Loading…
Reference in New Issue
Block a user