Fixed teh virus scan stream size not being big enough/matching the upload limit.tags/2.0.3
@@ -14,13 +14,20 @@ EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
Debug|x64 = Debug|x64 | |||
Release|Any CPU = Release|Any CPU | |||
Release|x64 = Release|x64 | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Debug|x64.ActiveCfg = Debug|x64 | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Debug|x64.Build.0 = Debug|x64 | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Debug|x64.Deploy.0 = Debug|x64 | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Release|x64.ActiveCfg = Release|x64 | |||
{B20317CD-76C6-4A7B-BCE1-E4BEF8E4F964}.Release|x64.Build.0 = Release|x64 | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE |
@@ -46,75 +46,83 @@ namespace Teknik.Areas.Upload.Controllers | |||
[AllowAnonymous] | |||
public ActionResult Upload(string fileType, string fileExt, string iv, int keySize, int blockSize, bool encrypt, bool saveKey, HttpPostedFileWrapper data, string key = null) | |||
{ | |||
if (Config.UploadConfig.UploadEnabled) | |||
try | |||
{ | |||
if (data.ContentLength <= Config.UploadConfig.MaxUploadSize) | |||
if (Config.UploadConfig.UploadEnabled) | |||
{ | |||
// convert file to bytes | |||
byte[] fileData = null; | |||
int contentLength = data.ContentLength; | |||
using (var binaryReader = new BinaryReader(data.InputStream)) | |||
if (data.ContentLength <= Config.UploadConfig.MaxUploadSize) | |||
{ | |||
fileData = binaryReader.ReadBytes(data.ContentLength); | |||
} | |||
// Scan the file to detect a virus | |||
if (Config.UploadConfig.VirusScanEnable) | |||
{ | |||
ClamClient clam = new ClamClient(Config.UploadConfig.ClamServer, Config.UploadConfig.ClamPort); | |||
ClamScanResult scanResult = clam.SendAndScanFile(fileData); | |||
switch (scanResult.Result) | |||
// convert file to bytes | |||
byte[] fileData = null; | |||
int contentLength = data.ContentLength; | |||
using (var binaryReader = new BinaryReader(data.InputStream)) | |||
{ | |||
case ClamScanResults.Clean: | |||
break; | |||
case ClamScanResults.VirusDetected: | |||
return Json(new { error = new { message = string.Format("Virus Detected: {0}. As per our <a href=\"{1}\">Terms of Service</a>, Viruses are not permited.", scanResult.InfectedFiles.First().VirusName, Url.SubRouteUrl("tos", "TOS.Index")) } }); | |||
case ClamScanResults.Error: | |||
break; | |||
case ClamScanResults.Unknown: | |||
break; | |||
fileData = binaryReader.ReadBytes(data.ContentLength); | |||
} | |||
} | |||
// if they want us to encrypt it, we do so here | |||
if (encrypt) | |||
{ | |||
// Generate key and iv if empty | |||
if (string.IsNullOrEmpty(key)) | |||
// Scan the file to detect a virus | |||
if (Config.UploadConfig.VirusScanEnable) | |||
{ | |||
key = Utility.RandomString(keySize / 8); | |||
ClamClient clam = new ClamClient(Config.UploadConfig.ClamServer, Config.UploadConfig.ClamPort); | |||
clam.MaxStreamSize = Config.UploadConfig.MaxUploadSize; | |||
ClamScanResult scanResult = clam.SendAndScanFile(fileData); | |||
switch (scanResult.Result) | |||
{ | |||
case ClamScanResults.Clean: | |||
break; | |||
case ClamScanResults.VirusDetected: | |||
return Json(new { error = new { message = string.Format("Virus Detected: {0}. As per our <a href=\"{1}\">Terms of Service</a>, Viruses are not permited.", scanResult.InfectedFiles.First().VirusName, Url.SubRouteUrl("tos", "TOS.Index")) } }); | |||
case ClamScanResults.Error: | |||
return Json(new { error = new { message = string.Format("Error scanning the file upload for viruses. {0}", scanResult.RawResult) } }); | |||
case ClamScanResults.Unknown: | |||
return Json(new { error = new { message = string.Format("Unknown result while scanning the file upload for viruses. {0}", scanResult.RawResult) } }); | |||
} | |||
} | |||
fileData = AES.Encrypt(fileData, key, iv); | |||
if (fileData == null || fileData.Length <= 0) | |||
// if they want us to encrypt it, we do so here | |||
if (encrypt) | |||
{ | |||
return Json(new { error = new { message = "Unable to encrypt file" } }); | |||
// Generate key and iv if empty | |||
if (string.IsNullOrEmpty(key)) | |||
{ | |||
key = Utility.RandomString(keySize / 8); | |||
} | |||
fileData = AES.Encrypt(fileData, key, iv); | |||
if (fileData == null || fileData.Length <= 0) | |||
{ | |||
return Json(new { error = new { message = "Unable to encrypt file" } }); | |||
} | |||
} | |||
} | |||
Models.Upload upload = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, (saveKey) ? key : null, keySize, blockSize); | |||
if (upload != null) | |||
{ | |||
if (User.Identity.IsAuthenticated) | |||
Models.Upload upload = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, (saveKey) ? key : null, keySize, blockSize); | |||
if (upload != null) | |||
{ | |||
Profile.Models.User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); | |||
if (user != null) | |||
if (User.Identity.IsAuthenticated) | |||
{ | |||
upload.UserId = user.UserId; | |||
db.Entry(upload).State = EntityState.Modified; | |||
db.SaveChanges(); | |||
Profile.Models.User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); | |||
if (user != null) | |||
{ | |||
upload.UserId = user.UserId; | |||
db.Entry(upload).State = EntityState.Modified; | |||
db.SaveChanges(); | |||
} | |||
} | |||
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url }), key = key } }, "text/plain"); | |||
} | |||
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url }), key = key } }, "text/plain"); | |||
return Json(new { error = new { message = "Unable to upload file" } }); | |||
} | |||
else | |||
{ | |||
return Json(new { error = new { message = "File Too Large" } }); | |||
} | |||
return Json(new { error = new { message = "Unable to upload file" } }); | |||
} | |||
else | |||
{ | |||
return Json(new { error = new { message = "File Too Large" } }); | |||
} | |||
return Json(new { error = new { message = "Uploads are disabled" } }); | |||
} | |||
catch (Exception ex) | |||
{ | |||
return Json(new { error = new { message = "Exception while uploading file: " + ex.Message } }); | |||
} | |||
return Json(new { error = new { message = "Uploads are disabled" } }); | |||
} | |||
// User did not supply key |
@@ -138,7 +138,7 @@ var dropZone = new Dropzone(document.body, { | |||
<div class="row"> \ | |||
<div class="col-sm-12 text-center"> \ | |||
<div class="progress" id="progress-' + fileID + '"> \ | |||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 0%">0%</div> \ | |||
<div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 0%">0%</div> \ | |||
</div> \ | |||
</div> \ | |||
</div> \ | |||
@@ -165,6 +165,8 @@ var dropZone = new Dropzone(document.body, { | |||
// An error occured | |||
$("#progress-" + fileID).children('.progress-bar').css('width', '100%'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-success'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-striped'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('active'); | |||
$("#progress-" + fileID).children('.progress-bar').addClass('progress-bar-danger'); | |||
$("#progress-" + fileID).children('.progress-bar').html('File Too Large'); | |||
} | |||
@@ -219,6 +221,8 @@ function encryptFile(file, callback) { | |||
// An error occured | |||
$("#progress-" + fileID).children('.progress-bar').css('width', '100%'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-success'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-striped'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('active'); | |||
$("#progress-" + fileID).children('.progress-bar').addClass('progress-bar-danger'); | |||
$("#progress-" + fileID).children('.progress-bar').html('Error Occured'); | |||
} | |||
@@ -281,10 +285,17 @@ function uploadFile(data, key, iv, filetype, fileExt, fileID, saveKey, serverSid | |||
} | |||
function uploadProgress(fileID, evt) { | |||
var serverSideEncrypt = $('#serverSideEncrypt').is(':checked'); | |||
if (evt.lengthComputable) { | |||
var percentComplete = Math.round(evt.loaded * 100 / evt.total); | |||
$('#progress-' + fileID).children('.progress-bar').css('width', (percentComplete * (2 / 5)) + 60 + '%'); | |||
$('#progress-' + fileID).children('.progress-bar').html(percentComplete + '% Uploaded'); | |||
if (serverSideEncrypt && percentComplete == 100) { | |||
$('#progress-' + fileID).children('.progress-bar').css('width', '100%'); | |||
$('#progress-' + fileID).children('.progress-bar').html('Encrypting'); | |||
} | |||
else { | |||
$('#progress-' + fileID).children('.progress-bar').css('width', (percentComplete * (2 / 5)) + 60 + '%'); | |||
$('#progress-' + fileID).children('.progress-bar').html(percentComplete + '% Uploaded'); | |||
} | |||
} | |||
} | |||
@@ -299,6 +310,8 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) { | |||
fullName = fullName + '#' + key; | |||
} | |||
$('#progress-' + fileID).children('.progress-bar').css('width', '100%'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-striped'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('active'); | |||
$('#progress-' + fileID).children('.progress-bar').html('Complete'); | |||
$('#upload-link-' + fileID).html('<p><a href="' + fullName + '" id="full-url-link-' + fileID + '" target="_blank" class="alert-link">' + fullName + '</a></p>'); | |||
var keyBtn = '<div class="col-sm-4 text-center" id="key-link-' + fileID + '"> \ | |||
@@ -333,6 +346,8 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) { | |||
{ | |||
$('#progress-' + fileID).children('.progress-bar').css('width', '100%'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-success'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-striped'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('active'); | |||
$("#progress-" + fileID).children('.progress-bar').addClass('progress-bar-danger'); | |||
$('#remove-link-' + fileID).text('Clear Upload'); | |||
if (obj.error != null) { | |||
@@ -347,6 +362,8 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) { | |||
function uploadFailed(fileID, evt) { | |||
$('#progress-' + fileID).children('.progress-bar').css('width', '100%'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-success'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-striped'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('active'); | |||
$("#progress-" + fileID).children('.progress-bar').addClass('progress-bar-danger'); | |||
$('#progress-' + fileID).children('.progress-bar').html('Upload Failed'); | |||
} | |||
@@ -354,6 +371,8 @@ function uploadFailed(fileID, evt) { | |||
function uploadCanceled(fileID, evt) { | |||
$('#progress-' + fileID).children('.progress-bar').css('width', '100%'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-success'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-striped'); | |||
$("#progress-" + fileID).children('.progress-bar').removeClass('active'); | |||
$("#progress-" + fileID).children('.progress-bar').addClass('progress-bar-warning'); | |||
$('#progress-' + fileID).children('.progress-bar').html('Upload Canceled'); | |||
} |
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices; | |||
[assembly: AssemblyConfiguration("")] | |||
[assembly: AssemblyCompany("Teknik")] | |||
[assembly: AssemblyProduct("Teknik")] | |||
[assembly: AssemblyCopyright("Copyright © 2015")] | |||
[assembly: AssemblyCopyright("Copyright © 2015 - 2016")] | |||
[assembly: AssemblyTrademark("")] | |||
[assembly: AssemblyCulture("")] | |||
@@ -33,6 +33,7 @@ | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<PlatformTarget>AnyCPU</PlatformTarget> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
<DebugType>pdbonly</DebugType> | |||
@@ -41,6 +42,7 @@ | |||
<DefineConstants>TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<PlatformTarget>AnyCPU</PlatformTarget> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL"> | |||
@@ -633,6 +635,24 @@ | |||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> | |||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | |||
<DebugSymbols>true</DebugSymbols> | |||
<OutputPath>bin\</OutputPath> | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<DebugType>full</DebugType> | |||
<PlatformTarget>AnyCPU</PlatformTarget> | |||
<ErrorReport>prompt</ErrorReport> | |||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | |||
<OutputPath>bin\</OutputPath> | |||
<DefineConstants>TRACE</DefineConstants> | |||
<Optimize>true</Optimize> | |||
<DebugType>pdbonly</DebugType> | |||
<PlatformTarget>AnyCPU</PlatformTarget> | |||
<ErrorReport>prompt</ErrorReport> | |||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |||
</PropertyGroup> | |||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | |||
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> | |||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" /> |
@@ -22,7 +22,7 @@ | |||
<forms domain=".teknik.io" protection="All" enableCrossAppRedirects="true" name="TeknikAuth" /> | |||
</authentication> | |||
<compilation debug="true" targetFramework="4.5.2" /> | |||
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" /> | |||
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" executionTimeout="3600" /> | |||
<pages buffer="true" enableViewState="false" /> | |||
</system.web> | |||
<system.webServer> | |||
@@ -95,9 +95,10 @@ | |||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> | |||
</providers> | |||
</entityFramework> | |||
<system.data> | |||
<system.data> | |||
<DbProviderFactories> | |||
<remove invariant="MySql.Data.MySqlClient" /> | |||
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> | |||
</DbProviderFactories> | |||
</system.data></configuration> | |||
</system.data> | |||
</configuration> |