Skip to content

Commit

Permalink
Fetch, preserves previous type attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Aug 17, 2024
1 parent 05a24cd commit 94298ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Protest/Front/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Fetch extends Tabs {

this.snmp2Button = document.createElement("input");
this.snmp2Button.type = "button";
this.snmp2Button.style.width = this.snmp2Button.style.minWidth = "32px";
this.snmp2Button.style.width = this.snmp2Button.style.minWidth = "34px";
this.snmp2Button.style.gridArea = "6 / 5";
this.snmp2Button.style.backgroundImage = "url(mono/wrench.svg?light)";
this.snmp2Button.style.backgroundSize = "24px 24px";
Expand All @@ -147,7 +147,7 @@ class Fetch extends Tabs {

this.snmp3Button = document.createElement("input");
this.snmp3Button.type = "button";
this.snmp3Button.style.width = this.snmp3Button.style.minWidth = "32px";
this.snmp3Button.style.width = this.snmp3Button.style.minWidth = "34px";
this.snmp3Button.style.gridArea = "7 / 5";
this.snmp3Button.style.backgroundImage = "url(mono/wrench.svg?light)";
this.snmp3Button.style.backgroundSize = "24px 24px";
Expand Down
42 changes: 27 additions & 15 deletions Protest/Workers/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ static Fetch() {
}

public static byte[] SingleDeviceSerialize(Dictionary<string, string> parameters, bool asynchronous = false) {
if (parameters is null) {
return Data.CODE_INVALID_ARGUMENT.Array;
}

parameters.TryGetValue("target", out string target);
parameters.TryGetValue("wmi", out string wmi);
parameters.TryGetValue("kerberos", out string kerberos);
Expand Down Expand Up @@ -140,12 +144,8 @@ public static ConcurrentDictionary<string, string[]> SingleDevice(string target,

Thread tWmi = null, tAd = null, tPortScan = null;

if (useWmi) {
if (useWmi && !OperatingSystem.IsWindows()) {
tWmi = new Thread(() => {
if (!OperatingSystem.IsWindows()) {
return;
}

wmi = Protocols.Wmi.WmiFetch(target);

if (wmi.TryGetValue("owner", out string owner)) {
Expand All @@ -169,14 +169,12 @@ public static ConcurrentDictionary<string, string[]> SingleDevice(string target,
});
}

if (useKerberos) {
if (useKerberos && !OperatingSystem.IsWindows()) {
tAd = new Thread(() => {
if (!OperatingSystem.IsWindows()) return;

if (hostname is null) return;
if (hostname is null) { return; }

SearchResult result = Protocols.Kerberos.GetWorkstation(hostname);

Check failure on line 176 in Protest/Workers/Fetch.cs

View workflow job for this annotation

GitHub Actions / Build and test

This call site is reachable on all platforms. 'Kerberos.GetWorkstation(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
if (result is null) return;
if (result is null) { return; }

if (result.Properties["description"].Count > 0) {
string value = result.Properties["description"][0].ToString();

Check failure on line 180 in Protest/Workers/Fetch.cs

View workflow job for this annotation

GitHub Actions / Build and test

This call site is reachable on all platforms. 'ResultPropertyCollection.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
Expand Down Expand Up @@ -214,8 +212,6 @@ public static ConcurrentDictionary<string, string[]> SingleDevice(string target,

if (argPortScan is not null) {
tPortScan = new Thread(() => {
if (argPortScan is null) return;

short[] portsPool = argPortScan == "full" ? PortScan.BASIC_PORTS : PortScan.BASIC_PORTS;

bool[] ports = PortScan.PortsScanAsync(target, portsPool, 1000, true).GetAwaiter().GetResult();
Expand Down Expand Up @@ -455,6 +451,10 @@ private static void ParseSnmpAttributes() {
}

public static byte[] SingleUserSerialize(Dictionary<string, string> parameters) {
if (parameters is null) {
return Data.CODE_INVALID_ARGUMENT.Array;
}

parameters.TryGetValue("target", out string target);

if (target is null) {
Expand Down Expand Up @@ -893,6 +893,10 @@ public static byte[] CancelTask(string origin) {
public static byte[] ApproveLastTask(Dictionary<string, string> parameters, string origin) {
if (result is null) return Data.CODE_TASK_DONT_EXITSTS.Array;

if (parameters is null) {
return Data.CODE_INVALID_ARGUMENT.Array;
}

parameters.TryGetValue("condition", out string targetAttribute);
parameters.TryGetValue("action", out string action);

Expand Down Expand Up @@ -944,16 +948,24 @@ public static byte[] ApproveLastTask(Dictionary<string, string> parameters, stri
attributes.TryAdd(attr.Key, new Database.Attribute() {
value = attr.Value[0],
date = date,
origin = origin,
origin = origin
});
}

if (pair.Value.TryGetValue(targetAttribute, out string[] targetValue)) {
if (pair.Value.TryGetValue(targetAttribute, out string[] targetValue)) { //existing
if (values.TryGetValue(targetValue[0], out string file)) {

//keep old type if it exists
if (database.dictionary.TryGetValue(file, out Database.Entry oldEntry)
&& oldEntry.attributes.TryGetValue("type", out Database.Attribute oldType)
&& String.IsNullOrEmpty(oldType.value)) {
attributes.AddOrUpdate("type", oldType, (_, _) => oldType);
}

database.Save(file, attributes, saveMethod, origin);
}
}
else {
else { //new
database.Save(null, attributes, saveMethod, origin);
}
}
Expand Down

0 comments on commit 94298ef

Please sign in to comment.