Browse Source

Finished migration

tags/2.0.3
Teknikode 4 years ago
parent
commit
77e89e9af4

+ 3
- 4
Teknik/Areas/Profile/Controllers/ProfileController.cs View File

@@ -138,10 +138,9 @@ namespace Teknik.Areas.Profile.Controllers
db.SaveChanges();
}
HttpCookie authcookie = FormsAuthentication.GetAuthCookie(model.Username, model.RememberMe);
authcookie.Domain = string.Format(".{0}", Config.Host);
authcookie.HttpOnly = true;
authcookie.Secure = true;
Response.AppendCookie(authcookie);
authcookie.Name = ".TeknikAuth";
authcookie.Domain = "." + Config.Host;
Response.Cookies.Add(authcookie);

if (string.IsNullOrEmpty(model.ReturnUrl))
{

+ 33
- 0
Teknik/Helpers/WebClientExtension.cs View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;

namespace Teknik.Helpers
{
public class WebDownload : WebClient
{
/// <summary>
/// Time in milliseconds
/// </summary>
public int Timeout { get; set; }

public WebDownload() : this(60000) { }

public WebDownload(int timeout)
{
this.Timeout = timeout;
}

protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address);
if (request != null)
{
request.Timeout = this.Timeout;
}
return request;
}
}
}

+ 76
- 42
Teknik/Migrations/Configuration.cs View File

@@ -24,9 +24,9 @@ namespace Teknik.Migrations
{
// Pre-populate with the default stuff

// Create system blog
/*
Config config = Config.Load();
// Create system blog
Areas.Profile.Models.User systemUser = new Areas.Profile.Models.User();
systemUser.Username = Constants.SERVERUSER;
systemUser.JoinDate = DateTime.Now;
@@ -199,7 +199,6 @@ namespace Teknik.Migrations
}
}
}
// Transfer Blog Comments
var commentRet = db.Query("SELECT * FROM `comments` WHERE `service` = {0}", new object[] { "blog" });
foreach (var comment in commentRet)
@@ -243,56 +242,91 @@ namespace Teknik.Migrations
}
}
// Transfer Uploads
var uploadRet = db.Query("SELECT * FROM `uploads`");
foreach (var upload in uploadRet)
{
var uploadRet = db.Query("SELECT * FROM `uploads`");
var curUploads = context.Uploads.ToList();
if (curUploads == null)
curUploads = new List<Areas.Upload.Models.Upload>();
int curUpload = 0;
int curFinished = 0;
//int curDeleted = 0;
foreach (var upload in uploadRet)
{
curUpload++;
try {
string url = upload["url"].ToString();
Areas.Upload.Models.Upload upFound = context.Uploads.Where(u => u.Url == url).FirstOrDefault();
if (upFound == null)
//Areas.Upload.Models.Upload upFound = curUploads.Find(u => u.Url == url);
//if (upFound != null)
//{
// string subDir = upFound.FileName[0].ToString();
// string filePath = Path.Combine(config.UploadConfig.UploadDirectory, subDir, upFound.FileName);
// if (File.Exists(filePath))
// {
// continue;
// }
// else
// {
// curDeleted++;
// context.Uploads.Remove(upFound);
// context.SaveChanges();
// }
//}
string fileType = upload["type"].ToString();
int contentLength = Int32.Parse(upload["filesize"].ToString());
string deleteKey = upload["delete_key"].ToString();
int userId = Int32.Parse(upload["user_id"].ToString());
DateTime uploadDate = DateTime.Parse(upload["upload_date"].ToString());
string fullUrl = string.Format("https://u.teknik.io/{0}", url);
string fileExt = Path.GetExtension(fullUrl);
if (!File.Exists(Path.Combine("Z:\\Uploads_Old", upload["filename"].ToString())))
{
string fileType = upload["type"].ToString();
int contentLength = Int32.Parse(upload["filesize"].ToString());
string deleteKey = upload["delete_key"].ToString();
int userId = Int32.Parse(upload["user_id"].ToString());
DateTime uploadDate = DateTime.Parse(upload["upload_date"].ToString());
string fullUrl = string.Format("https://u.teknik.io/{0}", url);
string fileExt = Path.GetExtension(fullUrl);

// Download the old file and re-upload it
using (WebClient client = new WebClient())
continue;
}
// Download the old file and re-upload it
using (WebDownload client = new WebDownload(10000))
{
byte[] fileData;
try
{
try
{
byte[] fileData = client.DownloadData(fullUrl);
// Generate key and iv if empty
string key = Utility.RandomString(config.UploadConfig.KeySize / 8);
string iv = Utility.RandomString(config.UploadConfig.BlockSize / 8);
fileData = client.DownloadData(fullUrl);
}
catch (Exception ex) {
continue;
}
try
{
// Generate key and iv if empty
string key = Utility.RandomString(config.UploadConfig.KeySize / 8);
string iv = Utility.RandomString(config.UploadConfig.BlockSize / 8);

fileData = AES.Encrypt(fileData, key, iv);
if (fileData == null || fileData.Length <= 0)
{
continue;
}
Areas.Upload.Models.Upload up = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, key, config.UploadConfig.KeySize, config.UploadConfig.BlockSize);
if (userMapping.ContainsKey(userId))
up.UserId = userMapping[userId];
if (!string.IsNullOrEmpty(deleteKey))
up.DeleteKey = deleteKey;
up.Url = url;
context.Uploads.Add(up);
context.SaveChanges();
fileData = AES.Encrypt(fileData, key, iv);
if (fileData == null || fileData.Length <= 0)
{
continue;
}
catch { }
Areas.Upload.Models.Upload up = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, key, config.UploadConfig.KeySize, config.UploadConfig.BlockSize);
if (userMapping.ContainsKey(userId))
up.UserId = userMapping[userId];
if (!string.IsNullOrEmpty(deleteKey))
up.DeleteKey = deleteKey;
up.Url = url;
context.Entry(up).State = EntityState.Modified;
context.SaveChanges();
curFinished++;
}
catch (Exception ex) {
}
}
}
catch (Exception ex) {
}
}
*/
//}
*/
}

private void Db_MysqlErrorEvent(object sender, string e)
{
//throw new NotImplementedException();
}
//private void Db_MysqlErrorEvent(object sender, string e)
//{
// throw new NotImplementedException();
//}
}
}

+ 3
- 0
Teknik/Teknik.csproj View File

@@ -251,6 +251,9 @@
<Compile Include="Helpers\RSSFeedResult.cs" />
<Compile Include="Helpers\UrlExtensions.cs" />
<Compile Include="Helpers\Utility.cs" />
<Compile Include="Helpers\WebClientExtension.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\TeknikEntities.cs" />
<Compile Include="Areas\Profile\Models\User.cs" />

Loading…
Cancel
Save