Exemple #1
0
        private bool signUp()
        {
            WorkerInformation wi = new WorkerInformation(Configuration.WorkerName,
                                                         Dns.GetHostAddresses(Dns.GetHostName()).Select(ip => ip.ToString()).ToArray());

            return((Configuration.WorkerId = apiClient.SignUp(wi)) != Guid.Empty);
        }
Exemple #2
0
        private void GridViewWorker_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (GridViewWorker.CurrentRow == null)
            {
                MessageBox.Show("Ничего не выбрано",
                                "Внимание",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            WorkerInformation information = new WorkerInformation();

            information.tbName.Text        = GridViewWorker.CurrentRow.Cells[0].Value.ToString().Split(' ')[0] + " " + GridViewWorker.CurrentRow.Cells[0].Value.ToString().Split(' ')[2];
            information.tbSurname.Text     = GridViewWorker.CurrentRow.Cells[0].Value.ToString().Split(' ')[1];
            information.tbPhone.Text       = GridViewWorker.CurrentRow.Cells[1].Value.ToString();
            information.tbExperience.Text  = GridViewWorker.CurrentRow.Cells[2].Value.ToString();
            information.DateBirthday.Value = DateTime.Parse(GridViewWorker.CurrentRow.Cells[3].Value.ToString());
            information.labelSex.Text      = $" ({GridViewWorker.CurrentRow.Cells[4].Value.ToString()})";
            information.tbStreet.Text      = GridViewWorker.CurrentRow.Cells[5].Value.ToString().Split(',')[0];
            information.tbHome.Text        = GridViewWorker.CurrentRow.Cells[5].Value.ToString().Split(',')[1];
            information.tbFlat.Text        = GridViewWorker.CurrentRow.Cells[5].Value.ToString().Split(',')[2];
            information.lastDate           = DateTime.Parse(GridViewWorker.CurrentRow.Cells[3].Value.ToString());
            information.oldWorker          = GridViewWorker.CurrentRow.Cells[0].Value.ToString();
            information.ShowDialog();
        }
        public async Task AddWorker(WorkerInformation workerInformation)
        {
            var worker = _mapper.Map <Worker>(workerInformation);
            await _context.AddAsync(worker);

            await _context.SaveChangesAsync();
        }
Exemple #4
0
        public WorkerInformation information()
        {
            var information = new WorkerInformation();

            information.isActive = true;
            return(information);
        }
Exemple #5
0
        public UpdateWorkerStatus UpdateWorker(Guid id, WorkerInformation worker)
        {
            string endpoint = buildEndpoint("workers", id.ToString());

            var responseMessage = client.PutAsync(
                endpoint, new { worker }.AsJson(skipNull: true)).Result;

            logger.Debug("Worker update request was send {0}",
                         responseMessage.StatusCode == HttpStatusCode.NoContent ?
                         "successfully" : "failed");

            if (responseMessage.StatusCode != HttpStatusCode.NoContent)
            {
                if (responseMessage.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Error("Worker update failed. Status code: NotFound. Worker id {0} is incorrect. Error message: {1}",
                                 id, responseMessage.Content?.ReadAsStringAsync()?.Result);

                    return(UpdateWorkerStatus.LoginIncorrect);
                }
                else
                {
                    logger.Error("Worker update failed. Status code: {0}. Error message: {1}",
                                 responseMessage.StatusCode, responseMessage.Content?.ReadAsStringAsync()?.Result);

                    return(UpdateWorkerStatus.Failed);
                }
            }
            else
            {
                return(UpdateWorkerStatus.Ok);
            }
        }
Exemple #6
0
        public Guid SignUp(WorkerInformation worker)
        {
            string endpoint = buildEndpoint("workers");

            worker.ApiType          = GetApiType();
            worker.ApiVersion       = GetVersion();
            worker.WebhookSupported = GetWebhookSupported();

            var responseMessage = client.PostAsync(
                endpoint, new { worker }.AsJson(skipNull: true)).Result;

            logger.Debug("Sign up request was send {0}",
                         responseMessage.StatusCode == HttpStatusCode.Created ?
                         "successfully" : "failed");

            if (responseMessage.StatusCode != HttpStatusCode.Created)
            {
                logger.Error("Sign up failed. Status code: {0}. Error message: {1}",
                             responseMessage.StatusCode,
                             responseMessage.Content?.ReadAsStringAsync()?.Result);

                return(Guid.Empty);
            }

            return(new Guid(
                       JObject.Parse(
                           responseMessage.Content.ReadAsStringAsync().Result
                           )["id"].Value <string>()));
        }
        public async Task EditWorker(WorkerInformation workerInformation)
        {
            var worker = _mapper.Map <Worker>(workerInformation);

            _context.Update(worker);

            await _context.SaveChangesAsync();
        }
Exemple #8
0
        public static Mock <IAsyncWorker> MockPreviousWorker(WorkerInformation workerInformation)
        {
            var previousWorkerMock = Utils.CreateMock <IAsyncWorker>();

            previousWorkerMock.Setup(x => x.Scan(workerInformation)).Returns(Task.FromResult(MockScanResults()));

            return(previousWorkerMock);
        }
        public async Task <List <ScanResult> > Scan(WorkerInformation workerInformation)
        {
            var dnsReponse = await _LookupClient.QueryAsync(workerInformation.Hostname, QueryType.CAA);

            var caa             = new CaaReponse(dnsReponse);
            var previousResults = await this._PreviousWorker.Scan(workerInformation);

            previousResults.Add(caa.ParseReponse());

            return(previousResults);
        }
        public async Task <List <ScanResult> > Scan(WorkerInformation workerInformation)
        {
            var dnsReponse = await _LookupClient.QueryAsync($"_dmarc.{workerInformation.Hostname}", QueryType.TXT);

            var dmarc           = new DmarcResponse(dnsReponse);
            var previousResults = await this._PreviousWorker.Scan(workerInformation);

            previousResults.Add(dmarc.ParseReponse());

            return(previousResults);
        }
Exemple #11
0
        public async Task <List <ScanResult> > Scan(WorkerInformation workerInformation)
        {
            var txtDnsReponse = await _LookupClient.QueryAsync(workerInformation.Hostname, QueryType.TXT);

            var spfDnsResponse = await _LookupClient.QueryAsync(workerInformation.Hostname, QueryType.SPF);

            var spf             = new SpfResponse(txtDnsReponse, spfDnsResponse);
            var previousResults = await this._PreviousWorker.Scan(workerInformation);

            previousResults.Add(spf.ParseReponse());

            return(previousResults);
        }
        public async Task <List <ScanResult> > ScanDns(WorkerInformation workerInformation)
        {
            var baseWorker   = new BaseWorker();
            var mxWorker     = new MxWorker(baseWorker, this.LookupClient);
            var dkimWorker   = new DkimWorker(mxWorker, this.LookupClient, this.Settings);
            var caaWorker    = new CaaWorker(dkimWorker, this.LookupClient);
            var spfWorker    = new SpfWorker(caaWorker, this.LookupClient);
            var dnssecWorker = new DnssecWorker(spfWorker, this.LookupClient);
            var dmarcWorker  = new DmarcWorker(dnssecWorker, this.LookupClient);

            var scanResults = await dmarcWorker.Scan(workerInformation);

            return(scanResults);
        }
Exemple #13
0
        public void Test_CaaWorker_Scan_Records()
        {
            // Arrange
            var workerInformation = new WorkerInformation()
            {
                Hostname = "http://www.google.com"
            };
            var resourceRecord = new ResourceRecordInfo(DnsString.FromResponseQueryString(workerInformation.Hostname), ResourceRecordType.CAA, QueryClass.IN, 0, 0);

            var dnsRecords = new List <DnsResourceRecord>()
            {
                new CaaRecord(resourceRecord, 0, "issuewild", "pki.googl"),
                new CaaRecord(resourceRecord, 0, "issue", "letsencrypt.org"),
                new CaaRecord(resourceRecord, 0, "issuewild", "sslcerts.com"),
                new CaaRecord(resourceRecord, 0, "issue", "freecerts.com"),
            };

            var dnsResponse = new Mock <IDnsQueryResponse>();

            dnsResponse.Setup(x => x.Answers).Returns(dnsRecords);

            var lookupClientMock = new Mock <ILookupClient>(MockBehavior.Strict);

            lookupClientMock.Setup(x => x.QueryAsync(workerInformation.Hostname, QueryType.CAA, QueryClass.IN, null, default)).Returns(Task.FromResult(dnsResponse.Object));
            var previousWorkerMock = new Mock <IAsyncWorker>(MockBehavior.Strict);

            previousWorkerMock.Setup(x => x.Scan(workerInformation)).Returns(Task.FromResult(new List <ScanResult>()));

            var service = new CaaWorker(previousWorkerMock.Object, lookupClientMock.Object);

            // Act
            var rawCaaRecords = service.Scan(workerInformation);

            rawCaaRecords.Wait();

            // Assert
            var records = rawCaaRecords.Result;

            Assert.IsInstanceOfType(records.Single(), typeof(ParsedCaaResponse));
            var caaRecord = records.Single() as ParsedCaaResponse;

            Assert.IsTrue(caaRecord.HasCaaRecords);
            Assert.AreEqual(2, caaRecord.IssueCas.Count);
            Assert.AreEqual("letsencrypt.org", caaRecord.IssueCas[0]);
            Assert.AreEqual("freecerts.com", caaRecord.IssueCas[1]);
            Assert.AreEqual(2, caaRecord.IssueWildCas.Count);
            Assert.AreEqual("pki.googl", caaRecord.IssueWildCas[0]);
            Assert.AreEqual("sslcerts.com", caaRecord.IssueWildCas[1]);
        }
        public void OnApplicationCreated(WorkerInformation workerInfo)
        {
            var message = new StreamingMessage
            {
                RpcLog = new RpcLog
                {
                    EventId     = nameof(OnApplicationCreated),
                    Level       = RpcLog.Types.Level.Debug,
                    LogCategory = RpcLog.Types.RpcLogCategory.System,
                    Message     = JsonSerializer.Serialize(workerInfo, SerializerOptions)
                }
            };

            _outputChannel.TryWrite(message);
        }
Exemple #15
0
        public async Task <JsonResult> Get(string domain)
        {
            var workerInformation = new WorkerInformation()
            {
                Hostname = domain
            };
            var scanResults = await ScannerFacade.ScanDns(workerInformation);

            var scanResultsViewModel = new ScanResultViewModel()
            {
                Date = DateTime.Now, Domain = domain, Results = scanResults
            };

            return(new JsonResult(scanResultsViewModel, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Include
            }));
        }
        public WorkerInformation ConnectToTarget(string url)
        {
            Connection connection        = CreateConnection(url);
            var        workerInformation = new WorkerInformation()
            {
                Hostname = url
            };

            try
            {
                var info = connection.LoadCertificates();
                workerInformation.Certificate = info.Certificate;
                workerInformation.Chain       = info.Chain;
            } catch (SocketException ex) {
                Logger.Error(ex, $"Cannot connect to {url}.");
            }

            return(workerInformation);
        }
        public async Task <List <ScanResult> > Scan(WorkerInformation workerInformation)
        {
            var dkimResponse = new DkimResponse();

            foreach (var selector in this.Settings.DkimSelectors.Distinct())
            {
                var queryType  = QueryType.TXT;
                var dnsReponse = await _LookupClient.QueryAsync($"{selector}.{workerInformation.Hostname}", queryType);

                if (!dnsReponse.Answers.TxtRecords().Any())
                {
                    queryType  = QueryType.CNAME;
                    dnsReponse = await _LookupClient.QueryAsync($"{selector}.{workerInformation.Hostname}", queryType);
                }

                dkimResponse.AddResponse(selector, dnsReponse, queryType);
            }

            var previousResults = await this._PreviousWorker.Scan(workerInformation);

            previousResults.Add(dkimResponse.ParseReponse());

            return(previousResults);
        }
Exemple #18
0
        public void Test_CaaWorker_Scan_NoRecords()
        {
            // Arrange
            var workerInformation = new WorkerInformation()
            {
                Hostname = "http://www.google.com"
            };

            var dnsResponse = new Mock <IDnsQueryResponse>();

            dnsResponse.Setup(x => x.Answers).Returns(new List <DnsResourceRecord>());

            var lookupClientMock = new Mock <ILookupClient>(MockBehavior.Strict);

            lookupClientMock.Setup(x => x.QueryAsync(workerInformation.Hostname, QueryType.CAA, QueryClass.IN, null, default)).Returns(Task.FromResult(dnsResponse.Object));
            var previousWorkerMock = new Mock <IAsyncWorker>(MockBehavior.Strict);

            previousWorkerMock.Setup(x => x.Scan(workerInformation)).Returns(Task.FromResult(new List <ScanResult>()));

            var service = new CaaWorker(previousWorkerMock.Object, lookupClientMock.Object);

            // Act
            var rawCaaRecords = service.Scan(workerInformation);

            rawCaaRecords.Wait();

            // Assert
            var records = rawCaaRecords.Result;

            Assert.IsInstanceOfType(records.Single(), typeof(ParsedCaaResponse));
            var caaRecord = records.Single() as ParsedCaaResponse;

            Assert.IsFalse(caaRecord.HasCaaRecords);
            Assert.AreEqual(0, caaRecord.IssueCas.Count);
            Assert.AreEqual(0, caaRecord.IssueWildCas.Count);
        }
        public async Task <List <ScanResult> > Scan(WorkerInformation workerInformation)
        {
            var previousResults = await this._PreviousWorker.Scan(workerInformation);

            if (workerInformation.Certificate == null)
            {
                return(previousResults);
            }

            var          cert     = DotNetUtilities.FromX509Certificate(workerInformation.Certificate);
            var          issuer   = DotNetUtilities.FromX509Certificate(workerInformation.Issuer);
            var          ocsp     = CreateOcsp(cert, issuer);
            var          uris     = ocsp.GetOcspUris();
            OcspResponse response = new OcspResponse()
            {
                Status = OcspRevocationStatus.Unknown
            };

            response = await SendOcspRequests(ocsp, uris, response);

            previousResults.Add(response);

            return(previousResults);
        }
 public async Task EditWorker(WorkerInformation workerInformation)
 {
     await _repository.EditWorker(workerInformation);
 }
 public async Task AddWorker(WorkerInformation workerInformation)
 {
     await _repository.AddWorker(workerInformation);
 }
 public Task <List <ScanResult> > Scan(WorkerInformation workerInformation)
 {
     return(Task.FromResult(new List <ScanResult>()));
 }
Exemple #23
0
 public void AddWeigher(Guid truckId, WorkerInformation weigher)
 {
     currentGINProcess.AddWeigher(truckId, weigher);
 }
Exemple #24
0
 public void AddLoader(Guid truckId, WorkerInformation loader)
 {
     currentGINProcess.AddLoader(truckId, loader);
 }
Exemple #25
0
 public void ValidateWorker(WorkerInformation worker)
 {
     currentGINProcess.ValidateWorker(worker);
 }
        public async Task <IActionResult> EditWorker(WorkerInformation workerInformation)
        {
            await _service.EditWorker(workerInformation);

            return(Ok());
        }
Exemple #27
0
        public async Task <IActionResult> EditWorker(WorkerInformation workerInformation)
        {
            await _service.EditWorker(workerInformation);

            return(Ok("Nastąpiła zmiana w pracowniku"));
        }
Exemple #28
0
        public async Task <IActionResult> AddWorker(WorkerInformation workerInformation)
        {
            await _service.AddWorker(workerInformation);

            return(Ok("Pomyślnie dodano pracownika"));
        }