Compare commits

..

2 Commits

7 changed files with 51 additions and 18 deletions

View File

@ -43,7 +43,8 @@ public class HEInfoProvider implements ASInfoProvider {
return getIPv4Subnets(inputStream);
}
} else {
throw new RuntimeException("Unable to get info about AS" + as);
SystemLogger.error("Unable to get info about AS" + as, CTX);
return Collections.emptyList();
}
}
}

View File

@ -39,7 +39,8 @@ public class RIPEInfoProvider implements ASInfoProvider {
return getIPv4Subnets(inputStream);
}
} else {
throw new RuntimeException("Unable to get info about AS" + as);
SystemLogger.error("Unable to get info about AS" + as, CTX);
return Collections.emptyList();
}
}
}

View File

@ -15,7 +15,6 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
/**
@ -94,7 +93,7 @@ public class TDNSAPI implements Closeable {
private long soaSerial;
@JSONProperty(required = false)
@Getter
private Instant expiry;
private Date expiry;
@JSONProperty(required = false)
@Getter
private boolean isExpired;
@ -106,7 +105,7 @@ public class TDNSAPI implements Closeable {
private boolean disabled;
@JSONProperty
@Getter
private Instant lastModified;
private Date lastModified;
}
/**

View File

@ -2,6 +2,7 @@ package ru.kirillius.pf.sdn.web.RPC;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import ru.kirillius.json.DefaultPropertySerializer;
import ru.kirillius.json.JSONUtility;
import ru.kirillius.json.rpc.Annotations.JRPCArgument;
@ -88,7 +89,8 @@ public class SubscriptionManager implements RPC {
@JRPCArgument(name = "subnets") JSONArray subnets,
@JRPCArgument(name = "addresses") JSONArray addresses,
@JRPCArgument(name = "storage") String storage,
@JRPCArgument(name = "subscribe") boolean subscribe) throws IOException {
@JRPCArgument(name = "subscribe") boolean subscribe,
@JRPCArgument(name = "append") boolean append) throws IOException {
var repositoryConfig = findLocalRepo(storage);
var directory = new File(repositoryConfig.getSource());
if (!directory.exists()) {
@ -96,25 +98,43 @@ public class SubscriptionManager implements RPC {
}
var domainList = new ArrayList<String>();
var targetFile = new File(directory, name + ".json");
var bundle = new NetworkResourceBundle();
domains.forEach(d->domainList.add(d.toString()));
if (append) {
if (targetFile.exists()) {
try (var stream = new FileInputStream(targetFile)) {
var json = new JSONObject(new JSONTokener(stream));
bundle.add(
JSONUtility.deserializeStructure(json, NetworkResourceBundle.class)
);
}
}
}
try (var writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, name + ".json"))))) {
domains.forEach(d -> domainList.add(d.toString()));
try (var writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile)))) {
var merged = JSONUtility.deserializeCollection(subnets, IPv4Subnet.class, null).collect(Collectors.toList());
addresses.forEach(address -> {
merged.add(new IPv4Subnet(address.toString(), 32));
});
//noinspection rawtypes
@SuppressWarnings("unchecked")
var asnList = (List<Integer>) JSONUtility.deserializeCollection(ASN, Integer.class, (Class) DefaultPropertySerializer.class).toList();
writer.write(JSONUtility.serializeStructure(
NetworkResourceBundle.builder()
.ASN(asnList)
.subnets(merged)
.domains(domainList)
.description(description)
.build()
).toString(2));
bundle.add(NetworkResourceBundle.builder()
.ASN(asnList)
.subnets(merged)
.domains(domainList)
.description(description)
.build());
writer.write(JSONUtility.serializeStructure(bundle).toString(2));
}
if (subscribe) {
var subscribedResources = context.getConfig().getSubscribedResources();

View File

@ -92,7 +92,7 @@
<dependency>
<groupId>ru.kirillius</groupId>
<artifactId>json-rpc-servlet</artifactId>
<version>2.1.5.0</version>
<version>2.1.4.0</version>
</dependency>
</dependencies>

View File

@ -53,6 +53,12 @@ function renderSubscriptionList() {
}).join('');
const html = `
<div class="select-all-container" style="margin-bottom: 10px;">
<label>
<input type="checkbox" id="select-all-checkbox">
Выделить все
</label>
</div>
<ul class="subscription-list">${listHtml}</ul>
<button id="save-subscriptions-btn" class="btn-primary" style="width: 250px; margin-top: 30px;">Сохранить</button>
<div id="subscription-status-message" class="error-message" style="display: none;"></div>
@ -63,6 +69,11 @@ function renderSubscriptionList() {
}
function attachEventHandlers() {
$('#select-all-checkbox').on('change', function() {
const isChecked = $(this).is(':checked');
$('.subscription-checkbox').prop('checked', isChecked);
});
$('#save-subscriptions-btn').on('click', async function () {
const $btn = $(this);
const $message = $('#subscription-status-message');

View File

@ -308,7 +308,8 @@ function handleAdd() {
selectedSubnets,
selectedAddresses,
storage,
true
true,
false
).then(() => {
setStatus('Ресурсы успешно добавлены.', 'success');
}).catch(error => {