private void ExecuteThread(object obj) { try { // Data CommandState state = (CommandState)obj; // Request Entity entity = state.Target; TunnelComponent tunnel = entity.Get <TunnelComponent>(); SearchRequestCommand cmdRequest = new SearchRequestCommand(entity, tunnel.Connection); string jsonData = cmdRequest.Execute(state.Data); if (string.IsNullOrEmpty(jsonData)) { return; } // Response entity = state.Source; tunnel = entity.Get <TunnelComponent>(); SearchResponseCommand cmdResponse = new SearchResponseCommand(entity, tunnel.Connection); HttpCode code = cmdResponse.Execute(state.Id, jsonData); if (code == HttpCode.Ok) { SearchListComponent download = entity.Get <SearchListComponent>(); download.Add(state.Target); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
// TODO: Eventually support multiple searches via a TreeView? // public void Search(string keyword, FileFilter filter = FileFilter.None) { if (MenuController.Entity == null) { return; } Clear(); Start(); try { // NOTE: No need to close the connection SearchRequestCommand command = new SearchRequestCommand(MenuController.Entity); command.Execute(keyword, filter); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void ListenState() { NetworkChannel channel = null; try { // Connect if (!Connected) { State = DemonState.Restart; Status = DemonStatus.Info; return; } // NOTE: No need to close the channel channel = new NetworkChannel(Connection); Status = DemonStatus.Success; // Request HttpRequest httpRequest; channel.Receive(out httpRequest); if (httpRequest == null) { Status = DemonStatus.Warning; return; } // TODO: Version check // // Message SessionComponent session = Owner.Get <SessionComponent>(); string decrypted = session.Decrypt(httpRequest.Data); JsonPacket jsonRequest = JsonPacket.Parse(decrypted); JsonMessage jsonRequestMessage = JsonMessage.Parse(jsonRequest.Message); JsonType jsonType = jsonRequestMessage.Type; switch (jsonType) { case JsonType.Ping: { PingResponseCommand command = new PingResponseCommand(Owner, Connection); command.Execute(httpRequest, jsonRequest); break; } case JsonType.Search: { JsonAction action = jsonRequestMessage.Action; switch (action) { case JsonAction.Request: { SearchRequestCommand command = new SearchRequestCommand(Owner, Connection); command.Execute(httpRequest, jsonRequest); break; } case JsonAction.Response: { SearchResponseCommand command = new SearchResponseCommand(Owner, Connection); List <FileComponent> list = command.Execute(httpRequest, jsonRequest); OnListAdded(list); break; } default: { channel.SendBadRequest(); break; } } break; } case JsonType.Browse: { BrowseResponseCommand command = new BrowseResponseCommand(Owner, Connection); command.Execute(httpRequest, jsonRequest); break; } case JsonType.Download: { // TODO // DownloadResponseCommand command = new DownloadResponseCommand(Owner, Connection); // { Handler = UploadEvent }; command.Execute(httpRequest, jsonRequest); break; } default: { channel.SendBadRequest(); State = DemonState.Restart; Status = DemonStatus.Info; return; } } } catch (Exception ex) { Console.WriteLine(ex.Message); Status = DemonStatus.Error; if (channel != null) { try { channel.SendInternalServerError(); } catch (Exception) { } } } }
public async Task <ICollection <LdapPacket> > Execute(SearchRequestCommand searchRequestCommand) { var searchRequest = searchRequestCommand.ProtocolOperation.Operation as SearchRequest; var dn = searchRequest.BaseObject.Value; var result = new List <LdapPacket>(); if (string.IsNullOrWhiteSpace(dn)) { result.Add(GetRootDSE(searchRequestCommand)); } else { // Ajouter des tests pour la recherche. // Ajouter des tests pour les contrôles. // Externaliser namingContexts // Externaliser subSchemaEntry. var record = await _ldapEntryQueryStore.Get(searchRequest.BaseObject.Value); if (record == null) { throw new LdapException(string.Format(Global.EntryDoesntExist, dn), LDAPResultCodes.NoSuchObject, searchRequest.BaseObject.Value); } var ldapEntries = await _ldapEntryQueryStore.Search(Build(searchRequest)); foreach (var ldapEntry in ldapEntries) { var searchResultEntry = new SearchResultEntry { ObjectName = new DEROctetString(ldapEntry.DistinguishedName) }; foreach (var attr in ldapEntry.Attributes) { if (!searchRequest.Attributes.Values.Any() || searchRequest.Attributes.Values.Any(v => v.Value == "*" || v.Value == attr.Name)) { var partialAttribute = new PartialAttribute { Type = new DEROctetString(attr.Name), Vals = new DERSet <DEROctetString> { Values = attr.Values.Select(s => new DEROctetString(s)).ToList() } }; searchResultEntry.PartialAttributes.Values.Add(partialAttribute); } } result.Add(new LdapPacket { MessageId = searchRequestCommand.MessageId, ProtocolOperation = new DERProtocolOperation { Operation = searchResultEntry } }); } } result.Add(new LdapPacket { MessageId = searchRequestCommand.MessageId, ProtocolOperation = new DERProtocolOperation { Operation = new SearchResultDone { Result = new LDAPResult { MatchedDN = searchRequest.BaseObject, ResultCode = new DEREnumerated <LDAPResultCodes> { Value = LDAPResultCodes.Success }, DiagnosticMessage = new DEROctetString("") } } } }); return(result); }
private LdapPacket GetRootDSE(SearchRequestCommand searchRequestCommand) { var searchRequest = searchRequestCommand.ProtocolOperation.Operation as SearchRequest; var resultEntry = new SearchResultEntry { ObjectName = new DEROctetString(string.Empty) }; resultEntry.PartialAttributes.Values.Add(new PartialAttribute { Type = new DEROctetString(LdapConstants.StandardAttributeTypeNames.VendorName), Vals = new DERSet <DEROctetString> { Values = new List <DEROctetString> { new DEROctetString(_options.VendorName) } } }); resultEntry.PartialAttributes.Values.Add(new PartialAttribute { Type = new DEROctetString(LdapConstants.StandardAttributeTypeNames.VendorVersion), Vals = new DERSet <DEROctetString> { Values = new List <DEROctetString> { new DEROctetString(_options.VendorVersion) } } }); resultEntry.PartialAttributes.Values.Add(new PartialAttribute { Type = new DEROctetString(LdapConstants.StandardAttributeTypeNames.NamingContexts), Vals = new DERSet <DEROctetString> { Values = _options.NamingContexts.Select(n => new DEROctetString(n)).ToList()// new List<DEROctetString> { new DEROctetString(namingContext) } } }); resultEntry.PartialAttributes.Values.Add(new PartialAttribute { Type = new DEROctetString(LdapConstants.StandardAttributeTypeNames.SupportedLDAPVersion), Vals = new DERSet <DEROctetString> { Values = new List <DEROctetString> { new DEROctetString(_options.SupportedLDAPVersion.ToString()) } } }); foreach (var authenticationHandler in _authenticationHandlers) { resultEntry.PartialAttributes.Values.Add(new PartialAttribute { Type = new DEROctetString(LdapConstants.StandardAttributeTypeNames.SupportedSASLMechanisms), Vals = new DERSet <DEROctetString> { Values = new List <DEROctetString> { new DEROctetString(Enum.GetName(typeof(BindRequestAuthenticationChoices), authenticationHandler.AuthChoice)) } } }); } resultEntry.PartialAttributes.Values.Add(new PartialAttribute { Type = new DEROctetString(LdapConstants.StandardAttributeTypeNames.SubschemaSubentry), Vals = new DERSet <DEROctetString> { Values = new List <DEROctetString> { new DEROctetString(_options.SubSchemaSubEntry) } } }); return(new LdapPacket { MessageId = searchRequestCommand.MessageId, ProtocolOperation = new DERProtocolOperation { Operation = resultEntry } }); }