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 _Migrate;
private bool _UseCdn;
private string _DbConnection;
private string _Title;
private string _Description;
private string _Author;
@ -56,6 +57,8 @@ namespace Teknik.Configuration
public bool Migrate { get { return _Migrate; } set { _Migrate = value; } }
public bool UseCdn { get { return _UseCdn; } set { _UseCdn = value; } }
public string DbConnection { get { return _DbConnection; } set { _DbConnection = value; } }
// Site Information
public string Title { get { return _Title; } set { _Title = 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.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 =>
{
@ -111,10 +111,10 @@ namespace Teknik.IdentityServer
})
.AddOperationalStore(options =>
options.ConfigureDbContext = builder =>
builder.UseSqlServer(Configuration.GetConnectionString("TeknikAuthEntities"), sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))
builder.UseSqlServer(config.DbConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))
.AddConfigurationStore(options =>
options.ConfigureDbContext = builder =>
builder.UseSqlServer(Configuration.GetConnectionString("TeknikAuthEntities"), sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))
builder.UseSqlServer(config.DbConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly)))
.AddAspNetIdentity<ApplicationUser>()
.AddRedirectUriValidator<TeknikRedirectUriValidator>()
.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",
"Logging": {
"LogLevel": {

View File

@ -19,6 +19,9 @@ namespace Teknik.ServiceWorker
[Option('m', "migrate", Default = false, Required = false, HelpText = "Migrate everything")]
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
[Option(HelpText = "Prints all messages to standard output.")]
public bool Verbose { get; set; }

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Teknik.Areas.Paste.Models;
using Teknik.Areas.Stats.Models;
using Teknik.Areas.Upload.Models;
using Teknik.Areas.Users.Models;
@ -48,7 +49,7 @@ namespace Teknik.ServiceWorker
Output(string.Format("[{0}] Started Server Maintenance Process.", DateTime.Now));
var optionsBuilder = new DbContextOptionsBuilder<TeknikEntities>();
optionsBuilder.UseSqlServer("Data Source=blog.db");
optionsBuilder.UseSqlServer(config.DbConnection);
using (TeknikEntities db = new TeknikEntities(optionsBuilder.Options))
{
@ -64,6 +65,11 @@ namespace Teknik.ServiceWorker
// Run the overall migration calls
TeknikMigration.RunMigration(db, config);
}
if (options.Expire)
{
ProcessExpirations(config, db);
}
}
Output(string.Format("[{0}] Finished Server Maintenance Process.", DateTime.Now));
@ -208,6 +214,23 @@ namespace Teknik.ServiceWorker
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)
{
Console.WriteLine(message);

View File

@ -99,9 +99,9 @@
<br />
This can be one of the following:
<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>
</td>
@ -148,20 +148,6 @@
Specify a password to encrypt and lock the paste with.
</td>
</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>
<td>
<code>doNotTrack</code>

View File

@ -77,15 +77,12 @@
</div>
<br />
<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>
The maximum file size per upload is <b>@StringHelper.GetBytesReadable(maxUploadSize)</b>
</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 class="text-center">
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 Startup(IConfiguration configuration, IHostingEnvironment env)
public Startup(IHostingEnvironment env)
{
Configuration = configuration;
Environment = env;
}
public IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; }
// 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
services.AddDbContext<TeknikEntities>(options => options
.UseLazyLoadingProxies()
.UseSqlServer(Configuration.GetConnectionString("TeknikEntities")), ServiceLifetime.Transient);
.UseSqlServer(config.DbConnection), ServiceLifetime.Transient);
// Cookie Policies
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": {
"LogLevel": {
"Default": "Warning"