Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UninstallPackage.cs
1using System;
3using System.IO;
4using System.Threading.Tasks;
5using Waher.Content;
10
12{
14 {
15 public UninstallPackage()
16 : base("/UninstallPackage")
17 {
18 }
19
20 public override bool HandlesSubPaths => false;
21 public override bool UserSessions => true;
22 public bool AllowsPOST => true;
23
24 public async Task POST(HttpRequest Request, HttpResponse Response)
25 {
26 Gateway.AssertUserAuthenticated(Request, "Admin.Software.Upload");
27
28 if (!Request.HasData)
29 {
30 await Response.SendResponse(new BadRequestException());
31 return;
32 }
33
34 ContentResponse Content = await Request.DecodeDataAsync();
35 if (Content.HasError || !(Content.Decoded is Dictionary<string, object> Obj) ||
36 !Obj.TryGetValue("package", out object Value) || !(Value is string FileName))
37 {
38 await Response.SendResponse(new BadRequestException());
39 return;
40 }
41
42 string FullFileName = Path.Combine(XmppServerModule.PackagesFolder, FileName);
43 if (!File.Exists(FullFileName))
44 {
45 await Response.SendResponse(new NotFoundException("Package file not found."));
46 return;
47 }
48
49 Package Package = await Provisioning.ProvisioningComponent.GetPackage(FileName);
50 if (Package is null)
51 {
52 await Response.SendResponse(new NotFoundException("Package not found."));
53 return;
54 }
55
57 {
58 await Response.SendResponse(new BadRequestException("Reserved package."));
59 return;
60 }
61
62 if (Package.Installed == DateTime.MinValue)
63 {
64 await Response.SendResponse(new BadRequestException("Package not installed."));
65 return;
66 }
67
68 byte[] Key = Package.AesKey;
69
70 Package.Installed = DateTime.MinValue;
71 Package.PublicKey = null;
72 Package.AesKey = null;
73
74 await Database.Update(Package);
75 await XmppServerModule.Instance.UninstallSoftware(Package.FileName, Key);
76 }
77 }
78}
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
Definition: Gateway.cs:3868
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
Definition: HttpRequest.cs:22
bool HasData
If the request has data.
Definition: HttpRequest.cs:113
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:139
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:1211
Identity of the IoT Broker package.
Definition: BrokerPackage.cs:7
const string FileName
IoTBroker.package
Contains information about a software package.
Definition: Package.cs:21
DateTime Installed
When package was installed (if installed).
Definition: Package.cs:97
CaseInsensitiveString FileName
Filename of package.
Definition: Package.cs:43
byte[] AesKey
Symmetric cipher used to encrypt package file.
Definition: Package.cs:61
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
bool AllowsPOST
If the POST method is allowed.
Service Module hosting the XMPP broker and its components.
POST Interface for HTTP resources.