Browse Source

Added configurations for login auth to make sure dev auth didnt trigger main auth.

Modified podcast edit to try to fix file adding.
tags/2.0.3
Teknikode 4 years ago
parent
commit
319cb1cba3

+ 20
- 6
Teknik/Areas/Podcast/Controllers/PodcastController.cs View File

@@ -217,28 +217,38 @@ namespace Teknik.Areas.Podcast.Controllers
{
if (User.IsInRole("Podcast"))
{
Models.Podcast podcast = db.Podcasts.Find(podcastId);
Models.Podcast podcast = db.Podcasts.Include("Files").Where(p => p.PodcastId == podcastId).FirstOrDefault();
if (podcast != null)
{
if (db.Podcasts.Where(p => p.Episode != episode).FirstOrDefault() == null)
if (db.Podcasts.Where(p => p.Episode != episode).FirstOrDefault() == null || podcast.Episode == episode)
{
podcast.Episode = episode;
podcast.Title = title;
podcast.Description = description;
podcast.DateEdited = DateTime.Now;
// Remove any files not in fileIds
List<string> fileIdList = fileIds.Split(',').ToList();
List<string> fileIdList = new List<string>();
if (!string.IsNullOrEmpty(fileIds))
{
fileIdList = fileIds.Split(',').ToList();
}
for (int i = 0; i < podcast.Files.Count; i++)
{
PodcastFile curFile = podcast.Files[i];
if (!fileIdList.Exists(id => id == curFile.PodcastFileId.ToString()))
{
if (System.IO.File.Exists(curFile.Path))
{
System.IO.File.Delete(curFile.Path);
}
db.PodcastFiles.Remove(curFile);
podcast.Files.Remove(curFile);
}
}
// Add any new files
List<PodcastFile> newFiles = SaveFiles(Request.Files, episode);
podcast.Files.AddRange(newFiles);

// Save podcast
db.Entry(podcast).State = EntityState.Modified;
db.SaveChanges();
@@ -284,9 +294,13 @@ namespace Teknik.Areas.Podcast.Controllers
{
if (User.IsInRole("Podcast"))
{
Models.Podcast podcast = db.Podcasts.Find(podcastId);
Models.Podcast podcast = db.Podcasts.Include("Files").Where(p => p.PodcastId == podcastId).FirstOrDefault();
if (podcast != null)
{
foreach (PodcastFile file in podcast.Files)
{
System.IO.File.Delete(file.Path);
}
db.Podcasts.Remove(podcast);
db.SaveChanges();
return Json(new { result = true });
@@ -402,9 +416,9 @@ namespace Teknik.Areas.Podcast.Controllers

if (files.Count > 0)
{
for (int i = 0; i < Request.Files.Count; i++)
for (int i = 0; i < files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
HttpPostedFileBase file = files[i];
int fileSize = file.ContentLength;
string fileName = file.FileName;

+ 1
- 0
Teknik/Areas/Podcast/PodcastAreaRegistration.cs View File

@@ -48,6 +48,7 @@ namespace Teknik.Areas.Podcast
// Register Script Bundles
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/podcast").Include(
"~/Scripts/bootbox/bootbox.min.js",
"~/Scripts/jquery.blockUI.js",
"~/Areas/Podcast/Scripts/Podcast.js"));
// Register Style Bundles
BundleTable.Bundles.Add(new StyleBundle("~/Content/podcast").Include(

+ 4
- 4
Teknik/Areas/Podcast/Scripts/Podcast.js View File

@@ -87,7 +87,7 @@
for (var i = 0; i < files.length; i++) {
var fileId = files[i].id;
var fileName = files[i].name;
$("#edit_podcast_cur_file_list").append(' \
$("#edit_podcast_cur_files").append(' \
<div class="alert alert-success uploaded_file_' + fileId + '"> \
<button type="button" class="close podcast_file_delete" id="' + fileId + '">&times;</button> \
' + fileName + ' \
@@ -96,7 +96,7 @@
fileList[i] = fileId;
linkEditFileDelete('.podcast_file_delete');
}
$("#edit_podcast_cur_files").val(fileList.toString());
$("#edit_podcast_cur_file_list").val(fileList.toString());
}
}
});
@@ -326,12 +326,12 @@ function linkEditFileDelete(selector) {
$(selector).click(function () {
var object = $(this);
podFile = object.attr('id');
allFiles = $("#edit_podcast_cur_files").val();
allFiles = $("#edit_podcast_cur_file_list").val();
var fileList = allFiles.split(',');
var index = fileList.indexOf(podFile);
if (index != -1) {
fileList.splice(index, 1);
$("#edit_podcast_cur_files").val(fileList.toString());
$("#edit_podcast_cur_file_list").val(fileList.toString());
}
$(".uploaded_file_" + podFile).remove();
return false;

+ 2
- 2
Teknik/Areas/Podcast/Views/Podcast/Main.cshtml View File

@@ -75,7 +75,7 @@
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="podcast_files"><h4>Add Podcasts</h4></label>
<label for="podcast_files"><h4>Podcast Files</h4></label>
<input id="podcast_files" name="podcast_files" type="file" placeholder="podcast.ogg" title="select the podcast file." multiple>
</div>
</div>
@@ -122,7 +122,7 @@
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_podcast_files"><h4>Add Podcasts</h4></label>
<label for="edit_podcast_files"><h4>Add Podcast Files</h4></label>
<input id="edit_podcast_files" name="edit_podcast_files" type="file" placeholder="podcast.ogg" title="select the podcast file." multiple>
</div>
</div>

+ 1
- 1
Teknik/Areas/Podcast/Views/Podcast/ViewPodcast.cshtml View File

@@ -59,7 +59,7 @@
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_podcast_files"><h4>Add Podcasts</h4></label>
<label for="edit_podcast_files"><h4>Add Podcast Files</h4></label>
<input id="edit_podcast_files" name="edit_podcast_files" type="file" placeholder="podcast.ogg" title="select the podcast file." multiple>
</div>
</div>

+ 8
- 1
Teknik/Areas/Profile/Controllers/ProfileController.cs View File

@@ -141,7 +141,14 @@ namespace Teknik.Areas.Profile.Controllers
authcookie.Name = "TeknikAuth";
authcookie.HttpOnly = true;
authcookie.Secure = true;
authcookie.Domain = string.Format(".{0}", Config.Host);
authcookie.Domain = string.Format(".{0}", Request.Url.Host.GetDomain());
if (Config.DevEnvironment)
{
authcookie.Domain = string.Format("dev.{0}", Request.Url.Host.GetDomain());
}
#if DEBUG
authcookie.Domain = Request.Url.Host.GetDomain();
#endif
Response.Cookies.Add(authcookie);

if (string.IsNullOrEmpty(model.ReturnUrl))

+ 3
- 0
Teknik/Configuration/Config.cs View File

@@ -13,6 +13,7 @@ namespace Teknik.Configuration
private JsonSerializerSettings _JsonSettings;

private bool _DevEnvironment;
private bool _Migrate;
private string _Title;
private string _Description;
private string _Author;
@@ -34,6 +35,7 @@ namespace Teknik.Configuration
private DatabaseConfig _DatabaseConfig;

public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
public bool Migrate { get { return _Migrate; } set { _Migrate = value; } }

// Site Information
public string Title { get { return _Title; } set { _Title = value; } }
@@ -91,6 +93,7 @@ namespace Teknik.Configuration
public void SetDefaults()
{
DevEnvironment = false;
Migrate = false;
Title = string.Empty;
Description = string.Empty;
Author = string.Empty;

+ 27
- 8
Teknik/Helpers/UrlExtensions.cs View File

@@ -29,18 +29,11 @@ namespace Teknik
{
string host = url.RequestContext.HttpContext.Request.Url.Authority;
string domain = host;
string domain = host.GetDomain();
string rightUrl = string.Empty;

// get current subdomain
string curSub = host.GetSubdomain();
var split = host.Split('.'); // split the host by '.'
if (split.Count() > 2)
{
int index = host.IndexOf('.') + 1;
if (index >= 0 && index < host.Length)
domain = host.Substring(index, (host.Length - index));
}

// Grab the sub from parameters if it exists
string subParam = url.RequestContext.HttpContext.Request.QueryString["sub"]; // A subdomain specified as a query parameter takes precedence over the hostname unless on dev
@@ -139,6 +132,32 @@ namespace Teknik
return subParam;
}

public static string GetDomain(this string host)
{
string domain = host;
var split = host.Split('.'); // split the host by '.'
if (split.Count() > 2)
{
int index = host.IndexOf('.') + 1;
if (index >= 0 && index < host.Length)
domain = host.Substring(index, (host.Length - index));
}
return domain;
}

public static string GetDomain(this Uri uri)
{
string domain = uri.Host;
var split = uri.Host.Split('.'); // split the host by '.'
if (split.Count() > 2)
{
int index = uri.Host.IndexOf('.') + 1;
if (index >= 0 && index < uri.Host.Length)
domain = uri.Host.Substring(index, (uri.Host.Length - index));
}
return domain;
}

public static string GetActive(this UrlHelper url, params string[] subs)
{
string curSub = url.GetSubdomain();

+ 265
- 262
Teknik/Migrations/Configuration.cs View File

@@ -22,306 +22,309 @@ namespace Teknik.Migrations

protected override void Seed(Models.TeknikEntities context)
{
// Pre-populate with the default stuff

/*
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;
systemUser.LastSeen = DateTime.Now;
systemUser.UserSettings = new Areas.Profile.Models.UserSettings();
systemUser.BlogSettings = new Areas.Profile.Models.BlogSettings();
systemUser.UploadSettings = new Areas.Profile.Models.UploadSettings();
context.Users.AddOrUpdate(systemUser);
context.SaveChanges();

Areas.Blog.Models.Blog systemBlog = new Areas.Blog.Models.Blog();
systemBlog.UserId = systemUser.UserId;
systemBlog.BlogId = config.BlogConfig.ServerBlogId;
context.Blogs.AddOrUpdate(systemBlog);
context.SaveChanges();

// Create roles and groups
Areas.Profile.Models.Role adminRole = new Areas.Profile.Models.Role();
adminRole.Name = "Admin";
adminRole.Description = "Allows complete access to user specific actions";
context.Roles.AddOrUpdate(adminRole);
if (config.Migrate)
{
// Pre-populate with the default stuff
// Create system blog
Areas.Profile.Models.User systemUser = new Areas.Profile.Models.User();
systemUser.Username = Constants.SERVERUSER;
systemUser.JoinDate = DateTime.Now;
systemUser.LastSeen = DateTime.Now;
systemUser.UserSettings = new Areas.Profile.Models.UserSettings();
systemUser.BlogSettings = new Areas.Profile.Models.BlogSettings();
systemUser.UploadSettings = new Areas.Profile.Models.UploadSettings();
context.Users.AddOrUpdate(systemUser);
context.SaveChanges();

Areas.Profile.Models.Role podcastRole = new Areas.Profile.Models.Role();
podcastRole.Name = "Podcast";
podcastRole.Description = "Allows create/edit/delete access to podcasts";
context.Roles.AddOrUpdate(podcastRole);
Areas.Blog.Models.Blog systemBlog = new Areas.Blog.Models.Blog();
systemBlog.UserId = systemUser.UserId;
systemBlog.BlogId = config.BlogConfig.ServerBlogId;
context.Blogs.AddOrUpdate(systemBlog);
context.SaveChanges();

Areas.Profile.Models.Group adminGroup = new Areas.Profile.Models.Group();
adminGroup.Name = "Administrators";
adminGroup.Description = "System Administrators with full access";
adminGroup.Roles = new List<Areas.Profile.Models.Role>();
adminGroup.Roles.Add(adminRole);
adminGroup.Roles.Add(podcastRole);
context.Groups.AddOrUpdate(adminGroup);
// Create roles and groups
Areas.Profile.Models.Role adminRole = new Areas.Profile.Models.Role();
adminRole.Name = "Admin";
adminRole.Description = "Allows complete access to user specific actions";
context.Roles.AddOrUpdate(adminRole);

Areas.Profile.Models.Group podcastGroup = new Areas.Profile.Models.Group();
podcastGroup.Name = "Podcast";
podcastGroup.Description = "Podcast team members";
podcastGroup.Roles = new List<Areas.Profile.Models.Role>();
podcastGroup.Roles.Add(podcastRole);
context.Groups.AddOrUpdate(podcastGroup);
Areas.Profile.Models.Role podcastRole = new Areas.Profile.Models.Role();
podcastRole.Name = "Podcast";
podcastRole.Description = "Allows create/edit/delete access to podcasts";
context.Roles.AddOrUpdate(podcastRole);

Areas.Profile.Models.Group memberGroup = new Areas.Profile.Models.Group();
memberGroup.Name = "Member";
memberGroup.Description = "The default member group with basic permissions";
context.Groups.AddOrUpdate(memberGroup);
Areas.Profile.Models.Group adminGroup = new Areas.Profile.Models.Group();
adminGroup.Name = "Administrators";
adminGroup.Description = "System Administrators with full access";
adminGroup.Roles = new List<Areas.Profile.Models.Role>();
adminGroup.Roles.Add(adminRole);
adminGroup.Roles.Add(podcastRole);
context.Groups.AddOrUpdate(adminGroup);

context.SaveChanges();
if (config.DatabaseConfig.Migrate && !config.DevEnvironment)
{
Areas.Profile.Models.Group podcastGroup = new Areas.Profile.Models.Group();
podcastGroup.Name = "Podcast";
podcastGroup.Description = "Podcast team members";
podcastGroup.Roles = new List<Areas.Profile.Models.Role>();
podcastGroup.Roles.Add(podcastRole);
context.Groups.AddOrUpdate(podcastGroup);

// Convert legacy MySQL DB to new MS SQL DB
MysqlDatabase db = new MysqlDatabase(config.DatabaseConfig);
db.MysqlErrorEvent += Db_MysqlErrorEvent;
config.DatabaseConfig.Migrate = false;
Config.Save(config);
Areas.Profile.Models.Group memberGroup = new Areas.Profile.Models.Group();
memberGroup.Name = "Member";
memberGroup.Description = "The default member group with basic permissions";
context.Groups.AddOrUpdate(memberGroup);

// Transfer transactions
var transRet = db.Query("SELECT * FROM `transactions`");
foreach (var tran in transRet)
{
switch (tran["trans_type"].ToString())
{
case "One-Time":
Areas.Transparency.Models.OneTime tr = new Areas.Transparency.Models.OneTime();
tr.DateSent = DateTime.Parse(tran["date_posted"].ToString());
tr.Amount = Double.Parse(tran["amount"].ToString());
tr.Currency = tran["currency"].ToString();
tr.Recipient = tran["recipient"].ToString();
tr.Reason = tran["reason"].ToString();
context.Transactions.AddOrUpdate(tr);
break;
case "Bill":
Areas.Transparency.Models.Bill bill = new Areas.Transparency.Models.Bill();
bill.DateSent = DateTime.Parse(tran["date_posted"].ToString());
bill.Amount = Double.Parse(tran["amount"].ToString());
bill.Currency = tran["currency"].ToString();
bill.Recipient = tran["recipient"].ToString();
bill.Reason = tran["reason"].ToString();
context.Transactions.AddOrUpdate(bill);
break;
case "Donation":
Areas.Transparency.Models.Donation don = new Areas.Transparency.Models.Donation();
don.DateSent = DateTime.Parse(tran["date_posted"].ToString());
don.Amount = Double.Parse(tran["amount"].ToString());
don.Currency = tran["currency"].ToString();
don.Sender = tran["sender"].ToString();
don.Reason = tran["reason"].ToString();
context.Transactions.AddOrUpdate(don);
break;
}
}
context.SaveChanges();
// Transfer Users and Blogs/Posts
Dictionary<int, int> userMapping = new Dictionary<int, int>();
Dictionary<int, int> postMapping = new Dictionary<int, int>();
var userRet = db.Query("SELECT * FROM `users`");
foreach (var user in userRet)

/*
if (config.DatabaseConfig.Migrate)
{
// Create User
Areas.Profile.Models.User newUser = new Areas.Profile.Models.User();
newUser.UserSettings = new Areas.Profile.Models.UserSettings();
newUser.BlogSettings = new Areas.Profile.Models.BlogSettings();
newUser.UploadSettings = new Areas.Profile.Models.UploadSettings();
newUser.TransferAccount = true;
newUser.Username = user["username"].ToString();
newUser.HashedPassword = user["password"].ToString();
newUser.JoinDate = DateTime.Parse(user["join_date"].ToString());
newUser.LastSeen = DateTime.Parse(user["join_date"].ToString());
newUser.UserSettings.About = user["about"].ToString();
newUser.UserSettings.Website = user["website"].ToString();
newUser.UserSettings.Quote = user["quote"].ToString();
newUser.BlogSettings.Title = user["blog_title"].ToString();
newUser.BlogSettings.Description = user["blog_desc"].ToString();
if (user["site_admin"].ToString() == "1")

// Convert legacy MySQL DB to new MS SQL DB
MysqlDatabase db = new MysqlDatabase(config.DatabaseConfig);
db.MysqlErrorEvent += Db_MysqlErrorEvent;
config.DatabaseConfig.Migrate = false;
Config.Save(config);

// Transfer transactions
var transRet = db.Query("SELECT * FROM `transactions`");
foreach (var tran in transRet)
{
newUser.Groups.Add(adminGroup);
switch (tran["trans_type"].ToString())
{
case "One-Time":
Areas.Transparency.Models.OneTime tr = new Areas.Transparency.Models.OneTime();
tr.DateSent = DateTime.Parse(tran["date_posted"].ToString());
tr.Amount = Double.Parse(tran["amount"].ToString());
tr.Currency = tran["currency"].ToString();
tr.Recipient = tran["recipient"].ToString();
tr.Reason = tran["reason"].ToString();
context.Transactions.AddOrUpdate(tr);
break;
case "Bill":
Areas.Transparency.Models.Bill bill = new Areas.Transparency.Models.Bill();
bill.DateSent = DateTime.Parse(tran["date_posted"].ToString());
bill.Amount = Double.Parse(tran["amount"].ToString());
bill.Currency = tran["currency"].ToString();
bill.Recipient = tran["recipient"].ToString();
bill.Reason = tran["reason"].ToString();
context.Transactions.AddOrUpdate(bill);
break;
case "Donation":
Areas.Transparency.Models.Donation don = new Areas.Transparency.Models.Donation();
don.DateSent = DateTime.Parse(tran["date_posted"].ToString());
don.Amount = Double.Parse(tran["amount"].ToString());
don.Currency = tran["currency"].ToString();
don.Sender = tran["sender"].ToString();
don.Reason = tran["reason"].ToString();
context.Transactions.AddOrUpdate(don);
break;
}
}
context.Users.AddOrUpdate(newUser);
context.SaveChanges();
string oldUsername = user["username"].ToString();
Areas.Profile.Models.User newUser = context.Users.Where(u => u.Username == oldUsername).FirstOrDefault();
if (newUser != null)
// Transfer Users and Blogs/Posts
Dictionary<int, int> userMapping = new Dictionary<int, int>();
Dictionary<int, int> postMapping = new Dictionary<int, int>();
var userRet = db.Query("SELECT * FROM `users`");
foreach (var user in userRet)
{
int oldUserId = Int32.Parse(user["id"].ToString());
int userId = newUser.UserId;
// Create User
Areas.Profile.Models.User newUser = new Areas.Profile.Models.User();
newUser.UserSettings = new Areas.Profile.Models.UserSettings();
newUser.BlogSettings = new Areas.Profile.Models.BlogSettings();
newUser.UploadSettings = new Areas.Profile.Models.UploadSettings();
newUser.TransferAccount = true;
newUser.Username = user["username"].ToString();
newUser.HashedPassword = user["password"].ToString();
newUser.JoinDate = DateTime.Parse(user["join_date"].ToString());
newUser.LastSeen = DateTime.Parse(user["join_date"].ToString());
newUser.UserSettings.About = user["about"].ToString();
newUser.UserSettings.Website = user["website"].ToString();
newUser.UserSettings.Quote = user["quote"].ToString();
newUser.BlogSettings.Title = user["blog_title"].ToString();
newUser.BlogSettings.Description = user["blog_desc"].ToString();
if (user["site_admin"].ToString() == "1")
{
newUser.Groups.Add(adminGroup);
}

userMapping.Add(oldUserId, userId);
}
// Create Blog for user
Areas.Blog.Models.Blog newBlog = new Areas.Blog.Models.Blog();
newBlog.UserId = userId;
context.Blogs.AddOrUpdate(newBlog);
context.SaveChanges();
int blogId = newBlog.BlogId;
context.Users.AddOrUpdate(newUser);
context.SaveChanges();
string oldUsername = user["username"].ToString();
Areas.Profile.Models.User newUser = context.Users.Where(u => u.Username == oldUsername).FirstOrDefault();
if (newUser != null)
{
int oldUserId = Int32.Parse(user["id"].ToString());
int userId = newUser.UserId;

// Transfer Blog Posts
var postRet = db.Query("SELECT * FROM `blog` WHERE `author_id` = {0}", new object[] { oldUserId });
if (postRet != null)
{
foreach (var post in postRet)
userMapping.Add(oldUserId, userId);
}
// Create Blog for user
Areas.Blog.Models.Blog newBlog = new Areas.Blog.Models.Blog();
newBlog.UserId = userId;
context.Blogs.AddOrUpdate(newBlog);
context.SaveChanges();
int blogId = newBlog.BlogId;

// Transfer Blog Posts
var postRet = db.Query("SELECT * FROM `blog` WHERE `author_id` = {0}", new object[] { oldUserId });
if (postRet != null)
{
// Create new Blog Post
Areas.Blog.Models.BlogPost newPost = new Areas.Blog.Models.BlogPost();
if (post["user_id"].ToString() == "0")
{
newPost.BlogId = config.BlogConfig.ServerBlogId;
newPost.System = true;
}
else
foreach (var post in postRet)
{
newPost.BlogId = blogId;
// Create new Blog Post
Areas.Blog.Models.BlogPost newPost = new Areas.Blog.Models.BlogPost();
if (post["user_id"].ToString() == "0")
{
newPost.BlogId = config.BlogConfig.ServerBlogId;
newPost.System = true;
}
else
{
newPost.BlogId = blogId;
}
newPost.DatePosted = DateTime.Parse(post["date_posted"].ToString());
DateTime publishDate = DateTime.Now;
DateTime.TryParse(post["date_published"].ToString(), out publishDate);
if (publishDate < newPost.DatePosted)
{
publishDate = newPost.DatePosted;
}
newPost.DatePublished = publishDate;
newPost.DateEdited = publishDate;
newPost.Published = (post["published"].ToString() == "True");
newPost.Title = post["title"].ToString();
newPost.Article = post["post"].ToString();
context.BlogPosts.AddOrUpdate(newPost);
context.SaveChanges();
postMapping.Add(Int32.Parse(post["id"].ToString()), newPost.BlogPostId);
}
newPost.DatePosted = DateTime.Parse(post["date_posted"].ToString());
DateTime publishDate = DateTime.Now;
DateTime.TryParse(post["date_published"].ToString(), out publishDate);
if (publishDate < newPost.DatePosted)
{
publishDate = newPost.DatePosted;
}
newPost.DatePublished = publishDate;
newPost.DateEdited = publishDate;
newPost.Published = (post["published"].ToString() == "True");
newPost.Title = post["title"].ToString();
newPost.Article = post["post"].ToString();
context.BlogPosts.AddOrUpdate(newPost);
context.SaveChanges();
postMapping.Add(Int32.Parse(post["id"].ToString()), newPost.BlogPostId);
}
}
}
// Transfer Blog Comments
var commentRet = db.Query("SELECT * FROM `comments` WHERE `service` = {0}", new object[] { "blog" });
foreach (var comment in commentRet)
{
int postId = Int32.Parse(comment["reply_id"].ToString());
int userId = Int32.Parse(comment["user_id"].ToString());
if (postMapping.ContainsKey(postId) && userMapping.ContainsKey(userId))
{
Areas.Blog.Models.BlogPostComment newComment = new Areas.Blog.Models.BlogPostComment();
newComment.BlogPostId = postMapping[postId];
newComment.UserId = userMapping[userId];
newComment.Article = comment["post"].ToString();
newComment.DatePosted = DateTime.Parse(comment["date_posted"].ToString());
newComment.DateEdited = DateTime.Parse(comment["date_posted"].ToString());
context.BlogComments.AddOrUpdate(newComment);
context.SaveChanges();
}
}
// Transfer Pastes
var pasteRet = db.Query("SELECT * FROM `paste`");
foreach (var paste in pasteRet)
{
string pass = paste["password"].ToString();
// If it's a password protected paste, we just skip it
if (string.IsNullOrEmpty(pass) || pass == "EMPTY")
// Transfer Blog Comments
var commentRet = db.Query("SELECT * FROM `comments` WHERE `service` = {0}", new object[] { "blog" });
foreach (var comment in commentRet)
{
string content = paste["code"].ToString();
string title = paste["title"].ToString();
DateTime posted = DateTime.Parse(paste["posted"].ToString());
int userId = Int32.Parse(paste["user_id"].ToString());
Areas.Paste.Models.Paste newPaste = PasteHelper.CreatePaste(content, title);
newPaste.DatePosted = posted;
newPaste.Url = paste["pid"].ToString();
if (userMapping.ContainsKey(userId) && userId != 0)
int postId = Int32.Parse(comment["reply_id"].ToString());
int userId = Int32.Parse(comment["user_id"].ToString());
if (postMapping.ContainsKey(postId) && userMapping.ContainsKey(userId))
{
newPaste.UserId = userMapping[userId];
Areas.Blog.Models.BlogPostComment newComment = new Areas.Blog.Models.BlogPostComment();
newComment.BlogPostId = postMapping[postId];
newComment.UserId = userMapping[userId];
newComment.Article = comment["post"].ToString();
newComment.DatePosted = DateTime.Parse(comment["date_posted"].ToString());
newComment.DateEdited = DateTime.Parse(comment["date_posted"].ToString());
context.BlogComments.AddOrUpdate(newComment);
context.SaveChanges();
}
context.Pastes.AddOrUpdate(newPaste);
context.SaveChanges();
}
}
// Transfer Uploads
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 = 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())))
{
continue;
}
// Download the old file and re-upload it
using (WebDownload client = new WebDownload(10000))

// Transfer Pastes
var pasteRet = db.Query("SELECT * FROM `paste`");
foreach (var paste in pasteRet)
{
byte[] fileData;
try
string pass = paste["password"].ToString();
// If it's a password protected paste, we just skip it
if (string.IsNullOrEmpty(pass) || pass == "EMPTY")
{
fileData = client.DownloadData(fullUrl);
string content = paste["code"].ToString();
string title = paste["title"].ToString();
DateTime posted = DateTime.Parse(paste["posted"].ToString());
int userId = Int32.Parse(paste["user_id"].ToString());
Areas.Paste.Models.Paste newPaste = PasteHelper.CreatePaste(content, title);
newPaste.DatePosted = posted;
newPaste.Url = paste["pid"].ToString();
if (userMapping.ContainsKey(userId) && userId != 0)
{
newPaste.UserId = userMapping[userId];
}
context.Pastes.AddOrUpdate(newPaste);
context.SaveChanges();
}
catch (Exception ex) {
}
// Transfer Uploads
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 = 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())))
{
continue;
}
try
// Download the old file and re-upload it
using (WebDownload client = new WebDownload(10000))
{
// 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)
byte[] fileData;
try
{
fileData = client.DownloadData(fullUrl);
}
catch (Exception ex) {
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.Entry(up).State = EntityState.Modified;
context.SaveChanges();
curFinished++;
}
catch (Exception ex) {
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.Entry(up).State = EntityState.Modified;
context.SaveChanges();
curFinished++;
}
catch (Exception ex) {
}
}
}
catch (Exception ex) {
}
}
catch (Exception ex) {
}
//}
*/
}
//}
*/
}

//private void Db_MysqlErrorEvent(object sender, string e)

Loading…
Cancel
Save