示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseRequestResponseLogging();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.ApplicationServices.GetService <LockManager>();
            app.ApplicationServices.GetService <IpUpdater>();
            app.ApplicationServices.GetService <CertificateUpdater>();
            CertificateStorage storage = (CertificateStorage)app.ApplicationServices.GetService <ICertificateStorage>();

            Program.Certificate         = storage.Certificate;
            storage.CertificateChanged += (s, e) =>
            {
                if (e != null)
                {
                    Program.Certificate = e;
                }
            };
        }
示例#2
0
 protected PiVoteAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
 {
     BotMethods         = botMethods;
     Client             = client;
     CertificateStorage = certificateStorage;
     EventArgs          = eventArgs;
 }
        public TallyAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
            : base(botMethods, client, certificateStorage, eventArgs)
        {
            if (eventArgs.Data.MessageArray.Length == 2)
            {
                int votingNumberTemp;

                if (int.TryParse(eventArgs.Data.MessageArray[1], out votingNumberTemp))
                {
                    if (votingNumberTemp >= 0)
                    {
                        votingNumber = votingNumberTemp;
                    }
                }
            }
        }
示例#4
0
 public void CheckUpdateCertificate()
 {
     Logger.LogTrace("Checking certificate validity");
     if (CertificateStorage.Certificate == null || CertificateStorage.Certificate.NotAfter - CertificateUpdaterConfig.RenewBeforeExpiry <= DateTime.Now)
     {
         Logger.LogInformation("Updating the certificate..");
         byte[] newCertificateBytes = Client.GetCertificateAsync().Result;
         CertificateStorage.Key = Client.LetsEncryptPemKey;
         X509Certificate2 newCertificate = new X509Certificate2(newCertificateBytes, LetsEncryptConfiguration.CertificatePassword);
         string           tempFile       = Path.GetTempFileName();
         File.WriteAllBytes(tempFile, newCertificateBytes);
         Logger.LogInformation($"Temporary certificate written to {tempFile}");
         var parent = new FileInfo(CertificateUpdaterConfig.FilePath).Directory;
         if (!parent.Exists)
         {
             parent.Create();
         }
         File.Move(tempFile, CertificateUpdaterConfig.FilePath, true);
         CertificateStorage.UpdateCertificateAsync(newCertificateBytes).Wait();
         Logger.LogInformation("Certificate updated.");
     }
 }
示例#5
0
        public override void Activate()
        {
            actionQueue        = new Queue <PiVoteAction>();
            certificateStorage = new CertificateStorage();

            if (!certificateStorage.TryLoadRoot("./root.pi-cert"))
            {
                throw new Exception("Cannot find root certificate file.");
            }

            client = new VotingClient(certificateStorage);

            var serverIpAddress  = Dns.GetHostEntry(PiVoteServerAddress).AddressList.First();
            var serverIpEndPoint = new IPEndPoint(serverIpAddress, PiVoteServerPort);

            client.Connect(serverIpEndPoint);

            BotMethods.AddCommand(new Commandlet(CommandListVotings, CommandListVotingsDescription, ListVotingsHandler, this));
            BotMethods.AddCommand(new Commandlet(CommandTally, CommandTallyDescription, TallyHandler, this));
            BotMethods.AddCommand(new Commandlet(CommandStatus, CommandStatusDescription, StatusHandler, this));

            base.Activate();
        }
 public ListVotingsAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
     : base(botMethods, client, certificateStorage, eventArgs)
 {
 }