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

Finished migration

This commit is contained in:
Uncled1023 2016-02-01 23:26:04 -08:00
parent 886b36cbf1
commit 77e89e9af4
4 changed files with 115 additions and 46 deletions

View File

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

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;
}
}
}

View File

@ -24,9 +24,9 @@ namespace Teknik.Migrations
{ {
// Pre-populate with the default stuff // Pre-populate with the default stuff
// Create system blog
/* /*
Config config = Config.Load(); Config config = Config.Load();
// Create system blog
Areas.Profile.Models.User systemUser = new Areas.Profile.Models.User(); Areas.Profile.Models.User systemUser = new Areas.Profile.Models.User();
systemUser.Username = Constants.SERVERUSER; systemUser.Username = Constants.SERVERUSER;
systemUser.JoinDate = DateTime.Now; systemUser.JoinDate = DateTime.Now;
@ -199,7 +199,6 @@ namespace Teknik.Migrations
} }
} }
} }
// Transfer Blog Comments // Transfer Blog Comments
var commentRet = db.Query("SELECT * FROM `comments` WHERE `service` = {0}", new object[] { "blog" }); var commentRet = db.Query("SELECT * FROM `comments` WHERE `service` = {0}", new object[] { "blog" });
foreach (var comment in commentRet) foreach (var comment in commentRet)
@ -243,56 +242,91 @@ namespace Teknik.Migrations
} }
} }
// Transfer Uploads // Transfer Uploads
var uploadRet = db.Query("SELECT * FROM `uploads`"); var uploadRet = db.Query("SELECT * FROM `uploads`");
foreach (var upload in uploadRet) 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(); string url = upload["url"].ToString();
Areas.Upload.Models.Upload upFound = context.Uploads.Where(u => u.Url == url).FirstOrDefault(); //Areas.Upload.Models.Upload upFound = curUploads.Find(u => u.Url == url);
if (upFound == null) //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(); continue;
int contentLength = Int32.Parse(upload["filesize"].ToString()); }
string deleteKey = upload["delete_key"].ToString(); // Download the old file and re-upload it
int userId = Int32.Parse(upload["user_id"].ToString()); using (WebDownload client = new WebDownload(10000))
DateTime uploadDate = DateTime.Parse(upload["upload_date"].ToString()); {
string fullUrl = string.Format("https://u.teknik.io/{0}", url); byte[] fileData;
string fileExt = Path.GetExtension(fullUrl); try
// Download the old file and re-upload it
using (WebClient client = new WebClient())
{ {
try fileData = client.DownloadData(fullUrl);
{ }
byte[] fileData = client.DownloadData(fullUrl); catch (Exception ex) {
// Generate key and iv if empty continue;
string key = Utility.RandomString(config.UploadConfig.KeySize / 8); }
string iv = Utility.RandomString(config.UploadConfig.BlockSize / 8); 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); fileData = AES.Encrypt(fileData, key, iv);
if (fileData == null || fileData.Length <= 0) if (fileData == null || fileData.Length <= 0)
{ {
continue; 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();
} }
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) //private void Db_MysqlErrorEvent(object sender, string e)
{ //{
//throw new NotImplementedException(); // throw new NotImplementedException();
} //}
} }
} }

View File

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