1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

- Added Expiration parsing to the Service Worker.

- Moved Db Connection settings to the main config form.
This commit is contained in:
Uncled1023 2019-01-21 00:29:10 -08:00
parent 9bbb9a8ffa
commit 1d5d85b661
9 changed files with 41 additions and 37 deletions

View File

@ -22,6 +22,7 @@ namespace Teknik.Configuration
private bool _DevEnvironment; private bool _DevEnvironment;
private bool _Migrate; private bool _Migrate;
private bool _UseCdn; private bool _UseCdn;
private string _DbConnection;
private string _Title; private string _Title;
private string _Description; private string _Description;
private string _Author; private string _Author;
@ -56,6 +57,8 @@ namespace Teknik.Configuration
public bool Migrate { get { return _Migrate; } set { _Migrate = value; } } public bool Migrate { get { return _Migrate; } set { _Migrate = value; } }
public bool UseCdn { get { return _UseCdn; } set { _UseCdn = value; } } public bool UseCdn { get { return _UseCdn; } set { _UseCdn = value; } }
public string DbConnection { get { return _DbConnection; } set { _DbConnection = value; } }
// Site Information // Site Information
public string Title { get { return _Title; } set { _Title = value; } } public string Title { get { return _Title; } set { _Title = value; } }
public string Description { get { return _Description; } set { _Description = value; } } public string Description { get { return _Description; } set { _Description = value; } }

View File

@ -83,7 +83,7 @@ namespace Teknik.IdentityServer
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddDbContext<ApplicationDbContext>(builder => services.AddDbContext<ApplicationDbContext>(builder =>
builder.UseSqlServer(Configuration.GetConnectionString("TeknikAuthEntities"), sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly))); builder.UseSqlServer(config.DbConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)));
services.AddIdentity<ApplicationUser, IdentityRole>(options => services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{ {
@ -111,10 +111,10 @@ namespace Teknik.IdentityServer
}) })
.AddOperationalStore(options => .AddOperationalStore(options =>
options.ConfigureDbContext = builder => options.ConfigureDbContext = builder =>
builder.UseSqlServer(Configuration.GetConnectionString("TeknikAuthEntities"), sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly))) builder.UseSqlServer(config.DbConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))
.AddConfigurationStore(options => .AddConfigurationStore(options =>
options.ConfigureDbContext = builder => options.ConfigureDbContext = builder =>
builder.UseSqlServer(Configuration.GetConnectionString("TeknikAuthEntities"), sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly))) builder.UseSqlServer(config.DbConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))
.AddAspNetIdentity<ApplicationUser>() .AddAspNetIdentity<ApplicationUser>()
.AddRedirectUriValidator<TeknikRedirectUriValidator>() .AddRedirectUriValidator<TeknikRedirectUriValidator>()
.AddDeveloperSigningCredential(); .AddDeveloperSigningCredential();

View File

@ -1,7 +1,4 @@
{ {
"ConnectionStrings": {
"TeknikAuthEntities": "Server=(localdb)\\mssqllocaldb;Database=aspnet-TeknikCore-BE9563D1-0DFB-4141-903C-287B23FF22C7;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"server.urls": "http://localhost:5060", "server.urls": "http://localhost:5060",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

View File

@ -19,6 +19,9 @@ namespace Teknik.ServiceWorker
[Option('m', "migrate", Default = false, Required = false, HelpText = "Migrate everything")] [Option('m', "migrate", Default = false, Required = false, HelpText = "Migrate everything")]
public bool Migrate { get; set; } public bool Migrate { get; set; }
[Option('e', "expire", Default = false, Required = false, HelpText = "Process Expirations")]
public bool Expire { get; set; }
// Omitting long name, default --verbose // Omitting long name, default --verbose
[Option(HelpText = "Prints all messages to standard output.")] [Option(HelpText = "Prints all messages to standard output.")]
public bool Verbose { get; set; } public bool Verbose { get; set; }

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Teknik.Areas.Paste.Models;
using Teknik.Areas.Stats.Models; using Teknik.Areas.Stats.Models;
using Teknik.Areas.Upload.Models; using Teknik.Areas.Upload.Models;
using Teknik.Areas.Users.Models; using Teknik.Areas.Users.Models;
@ -48,7 +49,7 @@ namespace Teknik.ServiceWorker
Output(string.Format("[{0}] Started Server Maintenance Process.", DateTime.Now)); Output(string.Format("[{0}] Started Server Maintenance Process.", DateTime.Now));
var optionsBuilder = new DbContextOptionsBuilder<TeknikEntities>(); var optionsBuilder = new DbContextOptionsBuilder<TeknikEntities>();
optionsBuilder.UseSqlServer("Data Source=blog.db"); optionsBuilder.UseSqlServer(config.DbConnection);
using (TeknikEntities db = new TeknikEntities(optionsBuilder.Options)) using (TeknikEntities db = new TeknikEntities(optionsBuilder.Options))
{ {
@ -64,6 +65,11 @@ namespace Teknik.ServiceWorker
// Run the overall migration calls // Run the overall migration calls
TeknikMigration.RunMigration(db, config); TeknikMigration.RunMigration(db, config);
} }
if (options.Expire)
{
ProcessExpirations(config, db);
}
} }
Output(string.Format("[{0}] Finished Server Maintenance Process.", DateTime.Now)); Output(string.Format("[{0}] Finished Server Maintenance Process.", DateTime.Now));
@ -208,6 +214,23 @@ namespace Teknik.ServiceWorker
return virusDetected; return virusDetected;
} }
public static void ProcessExpirations(Config config, TeknikEntities db)
{
Output(string.Format("[{0}] Starting processing expirations.", DateTime.Now));
var curDate = DateTime.Now;
// Process uploads
List<Upload> uploads = db.Uploads.Where(u => u.ExpireDate != null && u.ExpireDate < curDate).ToList();
db.RemoveRange(uploads);
db.SaveChanges();
// Process Pastes
List<Paste> pastes = db.Pastes.Where(p => p.ExpireDate != null && p.ExpireDate < curDate).ToList();
db.RemoveRange(pastes);
db.SaveChanges();
}
public static void Output(string message) public static void Output(string message)
{ {
Console.WriteLine(message); Console.WriteLine(message);

View File

@ -99,9 +99,9 @@
<br /> <br />
This can be one of the following: This can be one of the following:
<select name="format" class="selectpicker"> <select name="format" class="selectpicker">
@foreach (var format in HighlightHelper.Languages) @foreach (var format in HighlightHelper.Languages.GroupBy(l => l.Value).ToList())
{ {
<option value="@(format.Key)">@(format.Key)</option> <!option value="@(format?.FirstOrDefault().Key)">@(format?.Key)</!option>
} }
</select> </select>
</td> </td>
@ -148,20 +148,6 @@
Specify a password to encrypt and lock the paste with. Specify a password to encrypt and lock the paste with.
</td> </td>
</tr> </tr>
<tr>
<td>
<code>hide</code>
</td>
<td>
<code>bool</code>
</td>
<td>
<var>false</var>
</td>
<td>
If the paste should be visible in the most recent pastes list.
</td>
</tr>
<tr> <tr>
<td> <td>
<code>doNotTrack</code> <code>doNotTrack</code>

View File

@ -77,15 +77,12 @@
</div> </div>
<br /> <br />
<div class="well text-center"> <div class="well text-center">
<p>
Each file is encrypted on upload using an AES-256-CTR cipher.
</p>
<p>
To view the file decrypted, you must use the direct Teknik link in a javascript enabled browser.
</p>
<p> <p>
The maximum file size per upload is <b>@StringHelper.GetBytesReadable(maxUploadSize)</b> The maximum file size per upload is <b>@StringHelper.GetBytesReadable(maxUploadSize)</b>
</p> </p>
<p>
Each file is encrypted after upload using an AES-256-CTR cipher. You can encrypt it within your browser for extra security by setting the option <strong>Encrypt in Browser</strong> in the options pane.
</p>
</div> </div>
<div class="text-center"> <div class="text-center">
Useful Tools: <a href="@Url.SubRouteUrl("help", "Help.Tools")">Upload Scripts and Utilities</a> Useful Tools: <a href="@Url.SubRouteUrl("help", "Help.Tools")">Upload Scripts and Utilities</a>

View File

@ -44,13 +44,11 @@ namespace Teknik
{ {
public class Startup public class Startup
{ {
public Startup(IConfiguration configuration, IHostingEnvironment env) public Startup(IHostingEnvironment env)
{ {
Configuration = configuration;
Environment = env; Environment = env;
} }
public IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; } public IHostingEnvironment Environment { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
@ -87,7 +85,7 @@ namespace Teknik
// Create the Database Context // Create the Database Context
services.AddDbContext<TeknikEntities>(options => options services.AddDbContext<TeknikEntities>(options => options
.UseLazyLoadingProxies() .UseLazyLoadingProxies()
.UseSqlServer(Configuration.GetConnectionString("TeknikEntities")), ServiceLifetime.Transient); .UseSqlServer(config.DbConnection), ServiceLifetime.Transient);
// Cookie Policies // Cookie Policies
services.Configure<CookiePolicyOptions>(options => services.Configure<CookiePolicyOptions>(options =>

View File

@ -1,7 +1,4 @@
{ {
"ConnectionStrings": {
"TeknikEntities": "Server=(localdb)\\mssqllocaldb;Database=aspnet-TeknikCore-BE9563D1-0DFB-4141-903C-287B23FF22C7;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"