First commit
This commit is contained in:
commit
c85dd2845f
|
@ -0,0 +1,486 @@
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from `dotnet new gitignore`
|
||||||
|
|
||||||
|
# dotenv files
|
||||||
|
.env
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# Tye
|
||||||
|
.tye/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.tlog
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||||
|
*.vbp
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||||
|
*.dsw
|
||||||
|
*.dsp
|
||||||
|
|
||||||
|
# Visual Studio 6 technical files
|
||||||
|
*.ncb
|
||||||
|
*.aps
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# Visual Studio History (VSHistory) files
|
||||||
|
.vshistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
# VS Code files for those working on multiple tools
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Windows Installer files from build outputs
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
*.sln.iml
|
||||||
|
.idea
|
||||||
|
|
||||||
|
##
|
||||||
|
## Visual studio for Mac
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
# globs
|
||||||
|
Makefile.in
|
||||||
|
*.userprefs
|
||||||
|
*.usertasks
|
||||||
|
config.make
|
||||||
|
config.status
|
||||||
|
aclocal.m4
|
||||||
|
install-sh
|
||||||
|
autom4te.cache/
|
||||||
|
*.tar.gz
|
||||||
|
tarballs/
|
||||||
|
test-results/
|
||||||
|
|
||||||
|
# Mac bundle stuff
|
||||||
|
*.dmg
|
||||||
|
*.app
|
||||||
|
|
||||||
|
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
# Vim temporary swap files
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
data/
|
|
@ -0,0 +1,10 @@
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
when:
|
||||||
|
event: push
|
||||||
|
branch: master
|
||||||
|
commands:
|
||||||
|
- apt update -y
|
||||||
|
- apt install -y make zip tar
|
||||||
|
- make test
|
|
@ -0,0 +1,13 @@
|
||||||
|
steps:
|
||||||
|
- name: deploy
|
||||||
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
branch: master
|
||||||
|
commands:
|
||||||
|
- apt update -y
|
||||||
|
- apt install -y make zip tar
|
||||||
|
- dotnet workload install wasm-tools
|
||||||
|
- bash publish.sh
|
||||||
|
volumes:
|
||||||
|
- /mnt/20TB/Artifacts:/deploy_dir
|
|
@ -0,0 +1,675 @@
|
||||||
|
# GNU GENERAL PUBLIC LICENSE
|
||||||
|
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||||
|
<https://fsf.org/>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies of this
|
||||||
|
license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
## Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom
|
||||||
|
to share and change all versions of a program--to make sure it remains
|
||||||
|
free software for all its users. We, the Free Software Foundation, use
|
||||||
|
the GNU General Public License for most of our software; it applies
|
||||||
|
also to any other work released this way by its authors. You can apply
|
||||||
|
it to your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you
|
||||||
|
have certain responsibilities if you distribute copies of the
|
||||||
|
software, or if you modify it: responsibilities to respect the freedom
|
||||||
|
of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the
|
||||||
|
manufacturer can do so. This is fundamentally incompatible with the
|
||||||
|
aim of protecting users' freedom to change the software. The
|
||||||
|
systematic pattern of such abuse occurs in the area of products for
|
||||||
|
individuals to use, which is precisely where it is most unacceptable.
|
||||||
|
Therefore, we have designed this version of the GPL to prohibit the
|
||||||
|
practice for those products. If such problems arise substantially in
|
||||||
|
other domains, we stand ready to extend this provision to those
|
||||||
|
domains in future versions of the GPL, as needed to protect the
|
||||||
|
freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish
|
||||||
|
to avoid the special danger that patents applied to a free program
|
||||||
|
could make it effectively proprietary. To prevent this, the GPL
|
||||||
|
assures that patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
## TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
### 0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds
|
||||||
|
of works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of
|
||||||
|
an exact copy. The resulting work is called a "modified version" of
|
||||||
|
the earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user
|
||||||
|
through a computer network, with no transfer of a copy, is not
|
||||||
|
conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices" to
|
||||||
|
the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
### 1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. "Object code" means any non-source form of
|
||||||
|
a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users can
|
||||||
|
regenerate automatically from other parts of the Corresponding Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that same
|
||||||
|
work.
|
||||||
|
|
||||||
|
### 2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not convey,
|
||||||
|
without conditions so long as your license otherwise remains in force.
|
||||||
|
You may convey covered works to others for the sole purpose of having
|
||||||
|
them make modifications exclusively for you, or provide you with
|
||||||
|
facilities for running those works, provided that you comply with the
|
||||||
|
terms of this License in conveying all material for which you do not
|
||||||
|
control copyright. Those thus making or running the covered works for
|
||||||
|
you must do so exclusively on your behalf, under your direction and
|
||||||
|
control, on terms that prohibit them from making any copies of your
|
||||||
|
copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under the
|
||||||
|
conditions stated below. Sublicensing is not allowed; section 10 makes
|
||||||
|
it unnecessary.
|
||||||
|
|
||||||
|
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such
|
||||||
|
circumvention is effected by exercising rights under this License with
|
||||||
|
respect to the covered work, and you disclaim any intention to limit
|
||||||
|
operation or modification of the work as a means of enforcing, against
|
||||||
|
the work's users, your or third parties' legal rights to forbid
|
||||||
|
circumvention of technological measures.
|
||||||
|
|
||||||
|
### 4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
### 5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
- a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
- b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under
|
||||||
|
section 7. This requirement modifies the requirement in section 4
|
||||||
|
to "keep intact all notices".
|
||||||
|
- c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
- d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
### 6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms of
|
||||||
|
sections 4 and 5, provided that you also convey the machine-readable
|
||||||
|
Corresponding Source under the terms of this License, in one of these
|
||||||
|
ways:
|
||||||
|
|
||||||
|
- a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
- b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the Corresponding
|
||||||
|
Source from a network server at no charge.
|
||||||
|
- c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
- d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
- e) Convey the object code using peer-to-peer transmission,
|
||||||
|
provided you inform other peers where the object code and
|
||||||
|
Corresponding Source of the work are being offered to the general
|
||||||
|
public at no charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal,
|
||||||
|
family, or household purposes, or (2) anything designed or sold for
|
||||||
|
incorporation into a dwelling. In determining whether a product is a
|
||||||
|
consumer product, doubtful cases shall be resolved in favor of
|
||||||
|
coverage. For a particular product received by a particular user,
|
||||||
|
"normally used" refers to a typical or common use of that class of
|
||||||
|
product, regardless of the status of the particular user or of the way
|
||||||
|
in which the particular user actually uses, or expects or is expected
|
||||||
|
to use, the product. A product is a consumer product regardless of
|
||||||
|
whether the product has substantial commercial, industrial or
|
||||||
|
non-consumer uses, unless such uses represent the only significant
|
||||||
|
mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to
|
||||||
|
install and execute modified versions of a covered work in that User
|
||||||
|
Product from a modified version of its Corresponding Source. The
|
||||||
|
information must suffice to ensure that the continued functioning of
|
||||||
|
the modified object code is in no case prevented or interfered with
|
||||||
|
solely because modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or
|
||||||
|
updates for a work that has been modified or installed by the
|
||||||
|
recipient, or for the User Product in which it has been modified or
|
||||||
|
installed. Access to a network may be denied when the modification
|
||||||
|
itself materially and adversely affects the operation of the network
|
||||||
|
or violates the rules and protocols for communication across the
|
||||||
|
network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
### 7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders
|
||||||
|
of that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
- a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
- b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
- c) Prohibiting misrepresentation of the origin of that material,
|
||||||
|
or requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
- d) Limiting the use for publicity purposes of names of licensors
|
||||||
|
or authors of the material; or
|
||||||
|
- e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
- f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions
|
||||||
|
of it) with contractual assumptions of liability to the recipient,
|
||||||
|
for any liability that these contractual assumptions directly
|
||||||
|
impose on those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions; the
|
||||||
|
above requirements apply either way.
|
||||||
|
|
||||||
|
### 8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your license
|
||||||
|
from a particular copyright holder is reinstated (a) provisionally,
|
||||||
|
unless and until the copyright holder explicitly and finally
|
||||||
|
terminates your license, and (b) permanently, if the copyright holder
|
||||||
|
fails to notify you of the violation by some reasonable means prior to
|
||||||
|
60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
### 9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or run
|
||||||
|
a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
### 10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
### 11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims owned
|
||||||
|
or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within the
|
||||||
|
scope of its coverage, prohibits the exercise of, or is conditioned on
|
||||||
|
the non-exercise of one or more of the rights that are specifically
|
||||||
|
granted under this License. You may not convey a covered work if you
|
||||||
|
are a party to an arrangement with a third party that is in the
|
||||||
|
business of distributing software, under which you make payment to the
|
||||||
|
third party based on the extent of your activity of conveying the
|
||||||
|
work, and under which the third party grants, to any of the parties
|
||||||
|
who would receive the covered work from you, a discriminatory patent
|
||||||
|
license (a) in connection with copies of the covered work conveyed by
|
||||||
|
you (or copies made from those copies), or (b) primarily for and in
|
||||||
|
connection with specific products or compilations that contain the
|
||||||
|
covered work, unless you entered into that arrangement, or that patent
|
||||||
|
license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
### 12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under
|
||||||
|
this License and any other pertinent obligations, then as a
|
||||||
|
consequence you may not convey it at all. For example, if you agree to
|
||||||
|
terms that obligate you to collect a royalty for further conveying
|
||||||
|
from those to whom you convey the Program, the only way you could
|
||||||
|
satisfy both those terms and this License would be to refrain entirely
|
||||||
|
from conveying the Program.
|
||||||
|
|
||||||
|
### 13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
### 14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in
|
||||||
|
detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies that a certain numbered version of the GNU General Public
|
||||||
|
License "or any later version" applies to it, you have the option of
|
||||||
|
following the terms and conditions either of that numbered version or
|
||||||
|
of any later version published by the Free Software Foundation. If the
|
||||||
|
Program does not specify a version number of the GNU General Public
|
||||||
|
License, you may choose any version ever published by the Free
|
||||||
|
Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future versions
|
||||||
|
of the GNU General Public License can be used, that proxy's public
|
||||||
|
statement of acceptance of a version permanently authorizes you to
|
||||||
|
choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
### 15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||||
|
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
||||||
|
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
|
||||||
|
CORRECTION.
|
||||||
|
|
||||||
|
### 16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
|
||||||
|
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
||||||
|
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
|
||||||
|
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
|
||||||
|
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
||||||
|
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
|
||||||
|
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
### 17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
## How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these
|
||||||
|
terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest to
|
||||||
|
attach them to the start of each source file to most effectively state
|
||||||
|
the exclusion of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper
|
||||||
|
mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands \`show w' and \`show c' should show the
|
||||||
|
appropriate parts of the General Public License. Of course, your
|
||||||
|
program's commands might be different; for a GUI interface, you would
|
||||||
|
use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. For more information on this, and how to apply and follow
|
||||||
|
the GNU GPL, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your
|
||||||
|
program into proprietary programs. If your program is a subroutine
|
||||||
|
library, you may consider it more useful to permit linking proprietary
|
||||||
|
applications with the library. If this is what you want to do, use the
|
||||||
|
GNU Lesser General Public License instead of this License. But first,
|
||||||
|
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,56 @@
|
||||||
|
all: linux-server linux-client win-server win-client mac-server mac-client
|
||||||
|
win-server: obj/server-windows/x86 obj/server-windows/x64 obj/server-windows/arm64
|
||||||
|
win-client: obj/client-windows/x86 obj/client-windows/x64 obj/client-windows/arm64
|
||||||
|
mac-server: obj/server-mac/x64 obj/server-mac/arm64
|
||||||
|
mac-client: obj/client-mac/x64 obj/client-mac/arm64
|
||||||
|
linux-server: obj/server-linux/x64 obj/server-linux/arm obj/server-linux/arm64
|
||||||
|
linux-client: obj/client-linux/x64 obj/client-linux/arm obj/client-linux/arm64
|
||||||
|
|
||||||
|
blazor:
|
||||||
|
mkdir -p obj/wwwroot
|
||||||
|
cd TessesDedupWeb && dotnet publish -o ../obj/ -c Release
|
||||||
|
|
||||||
|
obj/server-linux/%: blazor
|
||||||
|
rm -rf $@/data/wwwroot || true
|
||||||
|
mkdir -p $@ || true && cd "TessesDedupServer" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r linux-$(notdir $@)
|
||||||
|
mkdir -p $@/data/
|
||||||
|
cp -r obj/wwwroot $@/data/wwwroot
|
||||||
|
mkdir -p publish/server
|
||||||
|
cd $@ && tar cvzf ../../../publish/server/tessesbackup-linux-server-$(notdir $@).tar.gz .
|
||||||
|
|
||||||
|
obj/client-linux/%:
|
||||||
|
mkdir -p $@ || true && cd "TessesDedupClient" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r linux-$(notdir $@)
|
||||||
|
mkdir -p publish/client
|
||||||
|
cd $@ && tar cvzf ../../../publish/client/tessesbackup-linux-client-$(notdir $@).tar.gz .
|
||||||
|
|
||||||
|
|
||||||
|
obj/server-mac/%: blazor
|
||||||
|
rm -rf $@/data/wwwroot || true
|
||||||
|
mkdir -p $@ || true && cd "TessesDedupServer" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r osx-$(notdir $@)
|
||||||
|
mkdir -p $@/data/
|
||||||
|
cp -r obj/wwwroot $@/data/wwwroot
|
||||||
|
mkdir -p publish/server
|
||||||
|
cd $@ && tar cvzf ../../../publish/server/tessesbackup-macos-server-$(notdir $@).tar.gz .
|
||||||
|
|
||||||
|
obj/client-mac/%:
|
||||||
|
mkdir -p $@ || true && cd "TessesDedupClient" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r osx-$(notdir $@)
|
||||||
|
mkdir -p publish/client
|
||||||
|
cd $@ && tar cvzf ../../../publish/client/tessesbackup-macos-client-$(notdir $@).tar.gz .
|
||||||
|
|
||||||
|
obj/server-windows/%: blazor
|
||||||
|
rm -rf $@/data/wwwroot || true
|
||||||
|
mkdir -p $@ || true && cd "TessesDedupServer" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r win-$(notdir $@)
|
||||||
|
mkdir -p $@/data/
|
||||||
|
cp -r obj/wwwroot $@/data/wwwroot
|
||||||
|
mkdir -p publish/server
|
||||||
|
cd $@ && zip -r ../data.zip . && mv ../data.zip ../../../publish/server/tessesbackup-windows-server-$(notdir $@).zip
|
||||||
|
|
||||||
|
obj/client-windows/%:
|
||||||
|
mkdir -p $@ || true && cd "TessesDedupClient" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r win-$(notdir $@)
|
||||||
|
mkdir -p publish/client
|
||||||
|
cd $@ && zip -r ../data.zip . && mv ../data.zip ../../../publish/client/tessesbackup-windows-client-$(notdir $@).zip
|
||||||
|
|
||||||
|
test:
|
||||||
|
cd TessesDedupWeb && dotnet build
|
||||||
|
cd TessesDedupServer && dotnet build
|
||||||
|
cd TessesDedupClient && dotnet build
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Tesses Backup
|
||||||
|
|
||||||
|
> I am too lazy right now to properly do this
|
||||||
|
|
||||||
|
> TODO: make this GPLv3 compliant
|
||||||
|
|
||||||
|
## Installing Linux (Client) (assumes x86_64)
|
||||||
|
```bash
|
||||||
|
$ wget "https://downloads.tesses.net/artifacts/tesses50/tesses-backup/latest/client/tessesbackup-linux-client-x64.tar.gz"
|
||||||
|
$ tar xvzf "tessesbackup-linux-client-x64.tar.gz"
|
||||||
|
$ ./TessesDedupClient --help
|
||||||
|
$ echo "export PATH=\"\$PATH:$PWD\"" >> ~/.bashrc
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installing Linux (Server) (assumes x86_64)
|
||||||
|
```bash
|
||||||
|
$ wget "https://downloads.tesses.net/artifacts/tesses50/tesses-backup/latest/server/tessesbackup-linux-server-x64.tar.gz"
|
||||||
|
$ tar xvzf "tessesbackup-linux-server-x64.tar.gz"
|
||||||
|
$ ./TessesDedupServer
|
||||||
|
```
|
|
@ -0,0 +1,34 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
namespace TessesDedup
|
||||||
|
{
|
||||||
|
public class AccessKey
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public long Id {get;set;}
|
||||||
|
[JsonIgnore]
|
||||||
|
public string Key {get;set;}="";
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public long UserId {get;set;}
|
||||||
|
|
||||||
|
[JsonProperty("device_name")]
|
||||||
|
public string DeviceName {get;set;}="";
|
||||||
|
|
||||||
|
[JsonProperty("creation_date")]
|
||||||
|
public DateTime CreationDate {get;set;}
|
||||||
|
|
||||||
|
public void NewKey()
|
||||||
|
{
|
||||||
|
byte[] bytes=new byte[32];
|
||||||
|
using(var rnd = RandomNumberGenerator.Create())
|
||||||
|
rnd.GetBytes(bytes);
|
||||||
|
Key = Convert.ToBase64String(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
namespace TessesDedup
|
||||||
|
{
|
||||||
|
public class Account
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public long Id {get;set;}
|
||||||
|
|
||||||
|
[JsonProperty("username")]
|
||||||
|
public string Username {get;set;}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public string PasswordHash {get;set;}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public string PasswordSalt {get;set;}
|
||||||
|
|
||||||
|
public void NewSalt()
|
||||||
|
{
|
||||||
|
byte[] bytes=new byte[64];
|
||||||
|
using(var rnd = RandomNumberGenerator.Create())
|
||||||
|
rnd.GetBytes(bytes);
|
||||||
|
PasswordSalt = Convert.ToBase64String(bytes);
|
||||||
|
}
|
||||||
|
public string GetPasswordHash(string password)
|
||||||
|
{
|
||||||
|
string pass = $"{password}{PasswordSalt}";
|
||||||
|
using(var sha256Managed = SHA512.Create())
|
||||||
|
{
|
||||||
|
return Convert.ToBase64String(sha256Managed.ComputeHash(Encoding.UTF8.GetBytes(pass)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool PasswordCorrect(string password)
|
||||||
|
{
|
||||||
|
string hash=GetPasswordHash(password);
|
||||||
|
|
||||||
|
return PasswordHash == hash ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Tesses.VirtualFilesystem;
|
||||||
|
|
||||||
|
namespace TessesDedup
|
||||||
|
{
|
||||||
|
public class Backup
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public long Id {get;set;}
|
||||||
|
[JsonProperty("account_id")]
|
||||||
|
public long AccountId {get;set;}
|
||||||
|
[JsonProperty("root")]
|
||||||
|
public FilesystemEntry Root {get;set;}
|
||||||
|
[JsonProperty("device_name")]
|
||||||
|
public string DeviceName {get;set;}="";
|
||||||
|
[JsonProperty("tag")]
|
||||||
|
public string Tag {get;set;}="";
|
||||||
|
[JsonProperty("creation_date")]
|
||||||
|
|
||||||
|
public DateTime CreationDate {get;set;}
|
||||||
|
|
||||||
|
|
||||||
|
public Backup WithoutRoot()
|
||||||
|
{
|
||||||
|
Backup b=new Backup();
|
||||||
|
b.AccountId = AccountId;
|
||||||
|
b.Id = Id;
|
||||||
|
b.CreationDate = CreationDate;
|
||||||
|
b.DeviceName = DeviceName;
|
||||||
|
b.Tag = Tag;
|
||||||
|
b.Root=null;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Backup WithoutHashes()
|
||||||
|
{
|
||||||
|
Backup b=new Backup();
|
||||||
|
b.AccountId = AccountId;
|
||||||
|
b.Id = Id;
|
||||||
|
b.CreationDate = CreationDate;
|
||||||
|
b.DeviceName = DeviceName;
|
||||||
|
b.Tag = Tag;
|
||||||
|
b.Root=Root.WithoutHashes();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public FilesystemEntry GetEntryFromPath(UnixPath path)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(path.Path == "/") return Root;
|
||||||
|
|
||||||
|
var gefp=GetEntryFromPath(path.Parent);
|
||||||
|
|
||||||
|
if(gefp.Type != FilesystemEntryType.Dir) throw new DirectoryNotFoundException(path.Parent.Path);
|
||||||
|
|
||||||
|
foreach(var item in gefp.Entries)
|
||||||
|
{
|
||||||
|
if(item.Name == path.Name)
|
||||||
|
{
|
||||||
|
switch(item.Type)
|
||||||
|
{
|
||||||
|
case FilesystemEntryType.Dir:
|
||||||
|
case FilesystemEntryType.File:
|
||||||
|
return item;
|
||||||
|
case FilesystemEntryType.Symlink:
|
||||||
|
{
|
||||||
|
if(item.PointsTo.StartsWith("/"))
|
||||||
|
{
|
||||||
|
UnixPath _path = path.Parent;
|
||||||
|
foreach(var _item in item.PointsTo.Split('/'))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(_item == "..")
|
||||||
|
{
|
||||||
|
_path = _path.Parent;
|
||||||
|
}
|
||||||
|
else if(_item != ".")
|
||||||
|
{
|
||||||
|
_path /= _item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GetEntryFromPath(_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UnixPath _path = Special.Root;
|
||||||
|
foreach(var _item in item.PointsTo.Split('/'))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(_item == "..")
|
||||||
|
{
|
||||||
|
_path = _path.Parent;
|
||||||
|
}
|
||||||
|
else if(_item != ".")
|
||||||
|
{
|
||||||
|
_path /= _item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GetEntryFromPath(_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new FileNotFoundException(path.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,724 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LiteDB;
|
||||||
|
using Tesses.VirtualFilesystem;
|
||||||
|
using Tesses.VirtualFilesystem.Extensions;
|
||||||
|
using Tesses.WebServer;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace TessesDedup
|
||||||
|
{
|
||||||
|
|
||||||
|
public class Dedup
|
||||||
|
{
|
||||||
|
public class HttpDirectoryServer : Server
|
||||||
|
{
|
||||||
|
Dedup dedup;
|
||||||
|
public HttpDirectoryServer(Dedup dedup)
|
||||||
|
{
|
||||||
|
this.dedup=dedup;
|
||||||
|
}
|
||||||
|
public override async Task GetAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if (!ctx.RequestHeaders.TryGetFirst("Authorization", out var value)){
|
||||||
|
ctx.ResponseHeaders.Add("WWW-Authenticate", "Basic realm=\"Webdav realm\"");
|
||||||
|
ctx.StatusCode = 401;
|
||||||
|
await ctx.SendTextAsync("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string[] array = value.Split(' ');
|
||||||
|
string[] array2 = Encoding.UTF8.GetString(Convert.FromBase64String(array[1])).Split(new char[1] { ':' }, 2);
|
||||||
|
string usern = array2[0];
|
||||||
|
Account user=null;
|
||||||
|
|
||||||
|
bool accessKeyMode=false;
|
||||||
|
if(usern == "$access_key")
|
||||||
|
accessKeyMode=true;
|
||||||
|
else
|
||||||
|
|
||||||
|
using(var db = dedup.Database)
|
||||||
|
{
|
||||||
|
|
||||||
|
user = db.Accounts.FindOne(e=>e.Username == usern );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(user == null && !accessKeyMode) {
|
||||||
|
ctx.ResponseHeaders.Add("WWW-Authenticate", "Basic realm=\"Webdav realm\"");
|
||||||
|
ctx.StatusCode = 401;
|
||||||
|
await ctx.SendTextAsync("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!accessKeyMode && !user.PasswordCorrect(array2[1])) {
|
||||||
|
ctx.ResponseHeaders.Add("WWW-Authenticate", "Basic realm=\"Webdav realm\"");
|
||||||
|
ctx.StatusCode = 401;
|
||||||
|
await ctx.SendTextAsync("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(accessKeyMode)
|
||||||
|
{
|
||||||
|
using(var db = dedup.Database)
|
||||||
|
{
|
||||||
|
string key = array2[1];
|
||||||
|
var ak = db.AccessKeys.FindOne(e=>e.Key == key);
|
||||||
|
if(ak != null)
|
||||||
|
{
|
||||||
|
user = db.Accounts.FindOne(e=>e.Id == ak.UserId);
|
||||||
|
if(user == null)
|
||||||
|
{
|
||||||
|
ctx.ResponseHeaders.Add("WWW-Authenticate", "Basic realm=\"Webdav realm\"");
|
||||||
|
ctx.StatusCode = 401;
|
||||||
|
await ctx.SendTextAsync("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ctx.ResponseHeaders.Add("WWW-Authenticate", "Basic realm=\"Webdav realm\"");
|
||||||
|
ctx.StatusCode = 401;
|
||||||
|
await ctx.SendTextAsync("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder builder=new StringBuilder($"<!DOCTYPE html><html><head><title>Index of {HttpUtility.HtmlEncode(HttpUtility.UrlDecode(ctx.UrlPath))}</title></head><body><h1>Index of {HttpUtility.HtmlEncode(HttpUtility.UrlDecode(ctx.UrlPath))}</h1><hr><pre><a href=\"../\">../</a>\n");
|
||||||
|
bool isDir=true;
|
||||||
|
|
||||||
|
void Insert(string path,bool isDir=true)
|
||||||
|
{
|
||||||
|
builder.Append($"<a href=\"{HttpUtility.UrlPathEncode(path)}\">{HttpUtility.HtmlEncode(Path.GetFileName(path.TrimEnd('/')))}{(isDir?"/":"")}</a>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx.UrlPath == "/")
|
||||||
|
{
|
||||||
|
|
||||||
|
List<string> deviceNames = new List<string>();
|
||||||
|
using(var db = dedup.Database)
|
||||||
|
foreach(var item in db.Backups.Find(e=>e.AccountId == user.Id))
|
||||||
|
{
|
||||||
|
if(!deviceNames.Contains(item.DeviceName))
|
||||||
|
deviceNames.Add(item.DeviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(var dev in deviceNames)
|
||||||
|
{
|
||||||
|
Insert($"{dev}/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string[] path = ctx.UrlPath.Split(new char[]{'/'},StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if(path.Length == 1)
|
||||||
|
{
|
||||||
|
List<string> backups = new List<string>();
|
||||||
|
using(var db = dedup.Database)
|
||||||
|
foreach(var item in db.Backups.Find(e=>e.AccountId == user.Id))
|
||||||
|
{
|
||||||
|
string backupName = $"{item.Tag} ({item.CreationDate.ToString("yyyyMMdd_HHmmss")})";
|
||||||
|
if(item.DeviceName == path[0] && !backups.Contains(backupName))
|
||||||
|
{
|
||||||
|
backups.Add(backupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(var dev in backups)
|
||||||
|
{
|
||||||
|
Insert($"{dev}/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var name = HttpUtility.UrlDecode(path[1]);
|
||||||
|
|
||||||
|
using(var db = dedup.Database)
|
||||||
|
foreach(var item in db.Backups.Find(e=>e.AccountId == user.Id))
|
||||||
|
{
|
||||||
|
string backupName = $"{item.Tag} ({item.CreationDate.ToString("yyyyMMdd_HHmmss")})";
|
||||||
|
if(item.DeviceName == path[0] && name == backupName)
|
||||||
|
{
|
||||||
|
UnixPath upath = Special.Root;
|
||||||
|
for(int i = 2;i<path.Length;i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
upath /= HttpUtility.UrlDecode(path[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var p = item.GetEntryFromPath(upath);
|
||||||
|
if(p.Type == FilesystemEntryType.Dir)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach(var item2 in p.Entries)
|
||||||
|
{
|
||||||
|
|
||||||
|
var _p =item2.Type == FilesystemEntryType.Symlink ? item.GetEntryFromPath(upath / item2.Name) : item2;
|
||||||
|
Insert(_p.Type == FilesystemEntryType.Dir ? $"{item2.Name}/" : item2.Name,_p.Type == FilesystemEntryType.Dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(p.Type == FilesystemEntryType.File)
|
||||||
|
{
|
||||||
|
await ctx.SendStreamAsync(dedup.Storage.OpenRead(p),HeyRed.Mime.MimeTypesMap.GetMimeType(upath.Name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
goto dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
await ctx.SendNotFoundAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dir:
|
||||||
|
|
||||||
|
if(isDir)
|
||||||
|
{
|
||||||
|
builder.Append("</pre><hr></body></html>");
|
||||||
|
await ctx.SendTextAsync(builder.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IServer Server {get;}
|
||||||
|
public DedupStorage Storage {get;}
|
||||||
|
public DatabaseHandler Database => new DatabaseHandler(_db());
|
||||||
|
|
||||||
|
private Func<ILiteDatabase> _db;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class DatabaseHandler : IDisposable
|
||||||
|
{
|
||||||
|
public ILiteCollection<Backup> Backups => Database.GetCollection<Backup>("backups");
|
||||||
|
|
||||||
|
public ILiteCollection<Account> Accounts => Database.GetCollection<Account>("accounts");
|
||||||
|
|
||||||
|
public ILiteCollection<AccessKey> AccessKeys=>Database.GetCollection<AccessKey>("accesskeys");
|
||||||
|
public ILiteDatabase Database {get;}
|
||||||
|
public DatabaseHandler(ILiteDatabase db)
|
||||||
|
{
|
||||||
|
Database = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Database.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RouteServer routeServer;
|
||||||
|
IVirtualFilesystem fs;
|
||||||
|
public Dedup(IServer www,IVirtualFilesystem storage,Func<ILiteDatabase> db)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
fs = storage;
|
||||||
|
Storage = new DedupStorage(storage);
|
||||||
|
|
||||||
|
MountableServer mnt=new MountableServer(www);
|
||||||
|
HttpDirectoryServer webdav=new HttpDirectoryServer(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mnt.Mount("/data/",webdav);
|
||||||
|
routeServer=new RouteServer(mnt);
|
||||||
|
Server = routeServer;
|
||||||
|
|
||||||
|
routeServer.Add("/api/v1/Block",HasBlockAsync,"HEAD");
|
||||||
|
|
||||||
|
routeServer.Add("/api/v1/Block",PutBlockAsync,"PUT");
|
||||||
|
|
||||||
|
routeServer.Add("/api/v1/Backup",GetBackupAsync,"GET");
|
||||||
|
routeServer.Add("/api/v1/Backup",PutBackupAsync,"PUT");
|
||||||
|
|
||||||
|
routeServer.Add("/api/v1/Login",LoginAsync,"POST");
|
||||||
|
routeServer.Add("/api/v1/Logout",LogoutAsync,"POST");
|
||||||
|
routeServer.Add("/api/v1/Download",DownloadAsync,"GET");
|
||||||
|
routeServer.Add("/api/v1/Download",DownloadAsync,"HEAD");
|
||||||
|
|
||||||
|
routeServer.Add("/api/v1/AccessKey",AccessKeyAsync,"GET");
|
||||||
|
routeServer.Add("/api/v1/AccessKey",AccessKeyDeleteAsync,"DELETE");
|
||||||
|
|
||||||
|
routeServer.Add("/api/v1/Registered",RegisteredAsync,"GET");
|
||||||
|
|
||||||
|
routeServer.Add("/api/v1/Stats",StatsAsync,"GET");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AccessKeyDeleteAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
string key = GetAuthorizationKey(ctx);
|
||||||
|
|
||||||
|
using(var db = Database){
|
||||||
|
var ak=db.AccessKeys.FindOne(e=>e.Key == key);
|
||||||
|
if(ctx.QueryParams.TryGetFirstInt64("id",out var id))
|
||||||
|
{
|
||||||
|
var item=db.AccessKeys.FindById(id);
|
||||||
|
if(item != null && item.UserId == ak.UserId)
|
||||||
|
{
|
||||||
|
if(item.Id != ak.Id)
|
||||||
|
{
|
||||||
|
db.AccessKeys.Delete(id);
|
||||||
|
await ctx.SendJsonAsync(new{success=true,reason="Success, it got deleted"});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await ctx.SendJsonAsync(new{success=false,reason="Cannot delete this accesskey, must use Logout"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ctx.SendJsonAsync(new{success=false,reason="Either accesskey does not exist or it is not yours"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AccessKeyAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
|
||||||
|
string key = GetAuthorizationKey(ctx);
|
||||||
|
|
||||||
|
using(var db = Database)
|
||||||
|
{
|
||||||
|
var ak=db.AccessKeys.FindOne(e=>e.Key == key);
|
||||||
|
await ctx.SendJsonAsync(db.AccessKeys.Find(e=>e.UserId == ak.UserId && e.Id != ak.Id).ToList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BytesToUnited(long sz)
|
||||||
|
{
|
||||||
|
if(sz == 1) return "1 byte";
|
||||||
|
if(sz < 1024) return $"{sz} bytes";
|
||||||
|
if(sz < Math.Pow(1024,2)) return $"{sz / 1024} kiB";
|
||||||
|
if(sz < Math.Pow(1024,3)) return $"{sz / (int)Math.Pow(1024,2)} MiB";
|
||||||
|
if(sz < Math.Pow(1024,4)) return $"{sz / (long)Math.Pow(1024,3)} GiB";
|
||||||
|
return $"{sz / (long)Math.Pow(1024,4)} TiB";
|
||||||
|
}
|
||||||
|
private async Task StatsAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
long blocks = 0;
|
||||||
|
await foreach(var dir in fs.EnumerateDirectoriesAsync(Special.Root))
|
||||||
|
{
|
||||||
|
await foreach(var dir2 in fs.EnumerateDirectoriesAsync(dir))
|
||||||
|
{
|
||||||
|
await foreach(var file in fs.EnumerateFilesAsync(dir2))
|
||||||
|
{
|
||||||
|
blocks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
long bytes = blocks*DedupStorage.BlockLength;
|
||||||
|
using(var db = Database)
|
||||||
|
await ctx.SendJsonAsync(new{blocks,bytes,backups=db.Backups.Count(),label=BytesToUnited(bytes)});
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Registered()
|
||||||
|
{
|
||||||
|
using(var db = Database)
|
||||||
|
return db.Accounts.FindById(1) != null && !fs.FileExists(Special.Root/"ResetPassword.txt");
|
||||||
|
}
|
||||||
|
private async Task RegisteredAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
await ctx.SendJsonAsync(Registered());
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DownloadAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
if(ctx.QueryParams.TryGetFirstInt64("id",out var id) && ctx.QueryParams.TryGetFirst("path",out var path))
|
||||||
|
{
|
||||||
|
UnixPath upath = path;
|
||||||
|
Backup bkp;
|
||||||
|
using(var db = Database)
|
||||||
|
bkp=db.Backups.FindById(id);
|
||||||
|
if(bkp != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var ent=bkp.GetEntryFromPath(upath);
|
||||||
|
ctx.WithFileName(ent.Name,true);
|
||||||
|
await ctx.SendStreamAsync(Storage.OpenRead(ent),HeyRed.Mime.MimeTypesMap.GetMimeType(ent.Name));
|
||||||
|
}catch(DirectoryNotFoundException)
|
||||||
|
{
|
||||||
|
ctx.StatusCode = 404;
|
||||||
|
await ctx.SendTextAsync($"Could not find directory {upath.Parent.Path}\r\n","text/plain");
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
ctx.StatusCode = 404;
|
||||||
|
await ctx.SendTextAsync($"Could not find file {upath.Path}\r\n","text/plain");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ctx.StatusCode=404;
|
||||||
|
await ctx.SendTextAsync("Backup not found\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LogoutAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(!ctx.RequestHeaders.ContainsKey("Content-Type"))
|
||||||
|
ctx.RequestHeaders.Add("Content-Type","application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
ctx.ParseBody();
|
||||||
|
var key = GetAuthorizationKey(ctx);
|
||||||
|
if(!string.IsNullOrWhiteSpace(key))
|
||||||
|
{
|
||||||
|
|
||||||
|
using(var db = Database){
|
||||||
|
var item = db.AccessKeys.FindOne(e=>e.Key ==key);
|
||||||
|
if(item != null)
|
||||||
|
db.AccessKeys.Delete(item.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.StatusCode = 204;
|
||||||
|
await ctx.WriteHeadersAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoginAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(!ctx.RequestHeaders.ContainsKey("Content-Type"))
|
||||||
|
ctx.RequestHeaders.Add("Content-Type","application/x-www-form-urlencoded");
|
||||||
|
ctx.ParseBody();
|
||||||
|
if(ctx.QueryParams.TryGetFirst("username",out var username) && ctx.QueryParams.TryGetFirst("password",out var password) && ctx.QueryParams.TryGetFirst("device_name",out var device_name))
|
||||||
|
{
|
||||||
|
if(Registered())
|
||||||
|
{
|
||||||
|
Account user;
|
||||||
|
using(var db = Database)
|
||||||
|
user=db.Accounts.FindOne(e=>e.Username == username);
|
||||||
|
if(user != null)
|
||||||
|
{
|
||||||
|
if(user.PasswordCorrect(password))
|
||||||
|
{
|
||||||
|
AccessKey ak = new AccessKey();
|
||||||
|
ak.NewKey();
|
||||||
|
ak.Id = 0;
|
||||||
|
ak.UserId = user.Id;
|
||||||
|
ak.DeviceName = device_name;
|
||||||
|
ak.CreationDate=DateTime.Now;
|
||||||
|
using(var db = Database)
|
||||||
|
db.AccessKeys.Insert(ak);
|
||||||
|
|
||||||
|
await ctx.SendJsonAsync(new{success=true, key=ak.Key});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ctx.SendJsonAsync(new {success=false});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ctx.SendJsonAsync(new {success=false});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(await fs.FileExistsAsync(Special.Root/"ResetPassword.txt")) await fs.DeleteFileAsync(Special.Root/"ResetPassword.txt");
|
||||||
|
Account user;
|
||||||
|
using(var db = Database)
|
||||||
|
user = db.Accounts.FindById(1);
|
||||||
|
if(user != null)
|
||||||
|
{
|
||||||
|
user.Username = username;
|
||||||
|
user.NewSalt();
|
||||||
|
|
||||||
|
user.PasswordHash=user.GetPasswordHash(password);
|
||||||
|
user.Username = username;
|
||||||
|
using(var db = Database)
|
||||||
|
db.Accounts.Update(user);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Account acnt = new Account();
|
||||||
|
acnt.Id = 1;
|
||||||
|
acnt.NewSalt();
|
||||||
|
acnt.PasswordHash=acnt.GetPasswordHash(password);
|
||||||
|
acnt.Username = username;
|
||||||
|
using(var db = Database)
|
||||||
|
db.Accounts.Insert(acnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
AccessKey ak = new AccessKey();
|
||||||
|
ak.NewKey();
|
||||||
|
ak.Id = 0;
|
||||||
|
ak.UserId = 1;
|
||||||
|
ak.DeviceName = device_name;
|
||||||
|
using(var db = Database)
|
||||||
|
db.AccessKeys.Insert(ak);
|
||||||
|
|
||||||
|
await ctx.SendJsonAsync(new{success=true, key=ak.Key});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task PutBackupAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
var item = await ctx.ReadJsonAsync<Backup>();
|
||||||
|
item.Id = 0;
|
||||||
|
string key = GetAuthorizationKey(ctx);
|
||||||
|
AccessKey ak;
|
||||||
|
using(var db = Database)
|
||||||
|
ak=db.AccessKeys.FindOne(e=>e.Key == key);
|
||||||
|
item.AccountId = ak.UserId;
|
||||||
|
item.DeviceName = ak.DeviceName;
|
||||||
|
using(var db = Database)
|
||||||
|
db.Backups.Insert(item);
|
||||||
|
ctx.StatusCode=204;
|
||||||
|
await ctx.WriteHeadersAsync();
|
||||||
|
}
|
||||||
|
private string GetAuthorizationKey(ServerContext ctx)
|
||||||
|
{
|
||||||
|
string key="";
|
||||||
|
if(ctx.RequestHeaders.TryGetFirst("Authorization",out var auth))
|
||||||
|
{
|
||||||
|
if(auth.StartsWith("Bearer "))
|
||||||
|
{
|
||||||
|
key = auth.Substring(7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(ctx.RequestHeaders.TryGetFirst("X-Access-Key",out var ak))
|
||||||
|
{
|
||||||
|
key = ak;
|
||||||
|
}
|
||||||
|
if(ctx.QueryParams.TryGetFirst("access_key",out var access_key))
|
||||||
|
{
|
||||||
|
key=access_key;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
private long GetAccountId(ServerContext ctx)
|
||||||
|
{
|
||||||
|
string key = GetAuthorizationKey(ctx);
|
||||||
|
|
||||||
|
using(var db = Database)
|
||||||
|
{
|
||||||
|
var ak=db.AccessKeys.FindOne(e=>e.Key == key);
|
||||||
|
if(ak != null) return ak.UserId;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task GetBackupAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
|
||||||
|
bool noHashes=ctx.QueryParams.GetFirstBoolean("noHashes");
|
||||||
|
|
||||||
|
if(ctx.QueryParams.TryGetFirstInt64("id",out var id))
|
||||||
|
{
|
||||||
|
Backup item;
|
||||||
|
using(var db = Database)
|
||||||
|
item = db.Backups.FindById(id);
|
||||||
|
if(item != null)
|
||||||
|
|
||||||
|
await ctx.SendJsonAsync(noHashes ? item.WithoutHashes() : item);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ctx.StatusCode=404;
|
||||||
|
await ctx.SendNotFoundAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<Backup> backups=new List<Backup>();
|
||||||
|
using(var db = Database)
|
||||||
|
foreach(var item in db.Backups.FindAll())
|
||||||
|
{
|
||||||
|
backups.Add(item.WithoutRoot());
|
||||||
|
}
|
||||||
|
await ctx.SendJsonAsync(backups);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task PutBlockAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
var vals=await ctx.ReadBytesAsync();
|
||||||
|
await ctx.SendTextAsync(Storage.WriteBlock(vals),"text/plain");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HasBlockAsync(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(await Unauthenticated(ctx)) return;
|
||||||
|
if(ctx.QueryParams.TryGetFirst("hash",out var hash))
|
||||||
|
{
|
||||||
|
ctx.StatusCode = Storage.HasBlock(hash) ? 200 : 404;
|
||||||
|
await ctx.WriteHeadersAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private async Task<bool> Unauthenticated(ServerContext ctx)
|
||||||
|
{
|
||||||
|
if(GetAccountId(ctx) == -1)
|
||||||
|
{
|
||||||
|
ctx.StatusCode = 401;
|
||||||
|
await ctx.SendTextAsync("Unauthorized use /api/v1/Login to Authenticate\r\nand use access_key query param or Authorization: Bearer YOURKEY on this endpoint\r\n","text/plain");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DedupStorage
|
||||||
|
{
|
||||||
|
private class DedupStream : Stream
|
||||||
|
{
|
||||||
|
private DedupStorage dedupStorage;
|
||||||
|
private FilesystemEntry fsE;
|
||||||
|
|
||||||
|
public DedupStream(DedupStorage dedupStorage, FilesystemEntry fsE)
|
||||||
|
{
|
||||||
|
this.dedupStorage = dedupStorage;
|
||||||
|
this.fsE = fsE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanRead => true;
|
||||||
|
|
||||||
|
public override bool CanSeek => true;
|
||||||
|
|
||||||
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
|
public override long Length => fsE.Length;
|
||||||
|
|
||||||
|
public override long Position { get;set; }
|
||||||
|
|
||||||
|
public override void Flush()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Read(byte[] buffer, int offset, int count)
|
||||||
|
{
|
||||||
|
int total_read = Math.Min(count,buffer.Length-offset);
|
||||||
|
long end = Position + total_read;
|
||||||
|
if(end > Length) {end = Length; total_read = (int)(Length-Position);}
|
||||||
|
|
||||||
|
int read = 0;
|
||||||
|
while(Position < end)
|
||||||
|
{
|
||||||
|
//get current hash for Position
|
||||||
|
int currentFile = (int)(Position / BlockLength);
|
||||||
|
|
||||||
|
//get current offset (in file) for Position
|
||||||
|
int fileOffset = (int)(Position % BlockLength);
|
||||||
|
|
||||||
|
int toReadFromFile = BlockLength - fileOffset;
|
||||||
|
|
||||||
|
toReadFromFile = Math.Min(total_read-read,toReadFromFile);
|
||||||
|
|
||||||
|
var blk=dedupStorage.ReadBlock(fsE.Hashes[currentFile]);
|
||||||
|
Array.Copy(blk,fileOffset,buffer,offset+read,toReadFromFile);
|
||||||
|
read+=toReadFromFile;
|
||||||
|
Position+=toReadFromFile;
|
||||||
|
}
|
||||||
|
return read;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override long Seek(long offset, SeekOrigin origin)
|
||||||
|
{
|
||||||
|
switch(origin)
|
||||||
|
{
|
||||||
|
case SeekOrigin.Begin:
|
||||||
|
Position = offset;
|
||||||
|
break;
|
||||||
|
case SeekOrigin.Current:
|
||||||
|
Position += offset;
|
||||||
|
break;
|
||||||
|
case SeekOrigin.End:
|
||||||
|
Position = Length - offset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetLength(long value)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(byte[] buffer, int offset, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Stream OpenRead(FilesystemEntry fsE)
|
||||||
|
{
|
||||||
|
return new DedupStream(this,fsE);
|
||||||
|
}
|
||||||
|
public DedupStorage(IVirtualFilesystem fs)
|
||||||
|
{
|
||||||
|
this.vfs = fs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public const int BlockReadSize = 1024;
|
||||||
|
public const int BlockReads=4096;
|
||||||
|
public const int BlockLength = BlockReadSize*BlockReads;
|
||||||
|
IVirtualFilesystem vfs;
|
||||||
|
public UnixPath GetHashPath(string hash)
|
||||||
|
{
|
||||||
|
if(hash.Length != 128) return Special.Root;
|
||||||
|
string hashSlice1 = hash.Substring(0,2);
|
||||||
|
string hashSlice2 = hash.Substring(2,2);
|
||||||
|
string hashRest = hash.Substring(4,124);
|
||||||
|
return Special.Root / hashSlice1 / hashSlice2 / hashRest;
|
||||||
|
}
|
||||||
|
Mutex mtx=new Mutex();
|
||||||
|
public bool HasBlock(string hash)
|
||||||
|
{
|
||||||
|
if(hash.Length != 128) return false;
|
||||||
|
|
||||||
|
return vfs.FileExists(GetHashPath(hash));
|
||||||
|
}
|
||||||
|
internal static string Sha512Hash(byte[] data)
|
||||||
|
{
|
||||||
|
using(var sha512=SHA512.Create())
|
||||||
|
{
|
||||||
|
sha512.Initialize();
|
||||||
|
byte[] hash=sha512.ComputeHash(data);
|
||||||
|
return BitConverter.ToString(hash).ToLower().Replace("-","");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string WriteBlock(byte[] data)
|
||||||
|
{
|
||||||
|
if(data.Length != BlockLength)
|
||||||
|
mtx.WaitOne();
|
||||||
|
string hash=Sha512Hash(data);
|
||||||
|
if(!HasBlock(hash))
|
||||||
|
{
|
||||||
|
string hashSlice1 = hash.Substring(0,2);
|
||||||
|
string hashSlice2 = hash.Substring(2,2);
|
||||||
|
vfs.CreateDirectory(Special.Root / hashSlice1);
|
||||||
|
vfs.CreateDirectory(Special.Root / hashSlice1 / hashSlice2);
|
||||||
|
vfs.WriteAllBytes(GetHashPath(hash),data);
|
||||||
|
}
|
||||||
|
mtx.ReleaseMutex();
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ReadBlock(string hash)
|
||||||
|
{
|
||||||
|
if(HasBlock(hash))
|
||||||
|
{
|
||||||
|
return vfs.ReadAllBytes(GetHashPath(hash));
|
||||||
|
}
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,404 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LiteDB;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using ShellProgressBar;
|
||||||
|
using Tesses.VirtualFilesystem;
|
||||||
|
using Tesses.VirtualFilesystem.Extensions;
|
||||||
|
using Tesses.WebServer;
|
||||||
|
using System.Net;
|
||||||
|
namespace TessesDedup
|
||||||
|
{
|
||||||
|
public class DedupClient : IDisposable
|
||||||
|
{
|
||||||
|
HttpClient clt;
|
||||||
|
string url;
|
||||||
|
bool ownClient;
|
||||||
|
public bool ShowProgress {get;set;}
|
||||||
|
public DedupClient(HttpClient client, string url,bool ownClient=true,bool showProgress=true)
|
||||||
|
{
|
||||||
|
ShowProgress = showProgress;
|
||||||
|
this.clt = client;
|
||||||
|
this.url = url.TrimEnd('/');
|
||||||
|
this.ownClient = ownClient;
|
||||||
|
}
|
||||||
|
public DedupClient(string url,bool showProgress=true) : this(new HttpClient(),url,true,showProgress)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public async Task LogoutAsync(string key)
|
||||||
|
{
|
||||||
|
Dictionary<string,string> dictionary= new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "key", key }
|
||||||
|
};
|
||||||
|
|
||||||
|
FormUrlEncodedContent formUrlEncodedContent=new FormUrlEncodedContent(dictionary);
|
||||||
|
using(var resp=await clt.PostAsync($"{url}/api/v1/Logout",formUrlEncodedContent))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<LoginResult> LoginAsync(string username,string password, string device_name)
|
||||||
|
{
|
||||||
|
Dictionary<string,string> dictionary= new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "username", username },
|
||||||
|
{ "password", password },
|
||||||
|
{ "device_name", device_name }
|
||||||
|
};
|
||||||
|
|
||||||
|
FormUrlEncodedContent formUrlEncodedContent=new FormUrlEncodedContent(dictionary);
|
||||||
|
using(var resp=await clt.PostAsync($"{url}/api/v1/Login",formUrlEncodedContent))
|
||||||
|
{
|
||||||
|
if(resp.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<LoginResult>(await resp.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new LoginResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task<int> ReadAsync(Stream strm, byte[] buffer,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
Array.Clear(buffer,0,buffer.Length);
|
||||||
|
int totalRead = 0;
|
||||||
|
while(totalRead < buffer.Length)
|
||||||
|
{
|
||||||
|
int read = Math.Min(buffer.Length-totalRead,DedupStorage.BlockReadSize);
|
||||||
|
if(read == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
read=await strm.ReadAsync(buffer,totalRead,read,token);
|
||||||
|
if(token.IsCancellationRequested) return 0;
|
||||||
|
if(read == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
totalRead+=read;
|
||||||
|
}
|
||||||
|
return totalRead;
|
||||||
|
}
|
||||||
|
private async Task<bool> HasBlockAsync(string authkey,string hash,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
HttpRequestMessage request=new HttpRequestMessage(HttpMethod.Head,$"{url}/api/v1/Block?hash={hash}");
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer",authkey);
|
||||||
|
using(var req=await clt.SendAsync(request,token))
|
||||||
|
return req.StatusCode == System.Net.HttpStatusCode.OK;
|
||||||
|
}
|
||||||
|
private async Task WriteBlockAsync(string authkey,string hash,byte[] buffer,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
HttpRequestMessage request=new HttpRequestMessage(HttpMethod.Put,$"{url}/api/v1/Block");
|
||||||
|
request.Content = new ByteArrayContent(buffer);
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer",authkey);
|
||||||
|
using(var req=await clt.SendAsync(request,token))
|
||||||
|
{
|
||||||
|
if(req.StatusCode == System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
string server_hash=await req.Content.ReadAsStringAsync();
|
||||||
|
if(server_hash != hash)
|
||||||
|
throw new BackupFailedException(server_hash,hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<bool> BackupAsync(string authkey, IVirtualFilesystem fs,string tag,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
var dt = DateTime.Now;
|
||||||
|
var fse=await BackupPathAsync(authkey,fs,Special.Root,token);
|
||||||
|
if(token.IsCancellationRequested) return false;
|
||||||
|
Backup bkp=new Backup();
|
||||||
|
bkp.Id = 0;
|
||||||
|
bkp.Tag = tag;
|
||||||
|
bkp.CreationDate = dt;
|
||||||
|
bkp.Root = fse;
|
||||||
|
|
||||||
|
await WriteBackupAsync(authkey,bkp,token);
|
||||||
|
if(token.IsCancellationRequested) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task WriteBackupAsync(string authkey, Backup bkp,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
var str=JsonConvert.SerializeObject(bkp);
|
||||||
|
HttpRequestMessage request=new HttpRequestMessage(HttpMethod.Put,$"{url}/api/v1/Backup");
|
||||||
|
request.Content = new StringContent(str,Encoding.UTF8,"application/json");
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer",authkey);
|
||||||
|
|
||||||
|
using(var c=await clt.SendAsync(request,token))
|
||||||
|
{
|
||||||
|
c.EnsureSuccessStatusCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<FilesystemEntry> BackupPathAsync(string authkey,IVirtualFilesystem fs,UnixPath path,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
if(await fs.SymlinkExistsAsync(path))
|
||||||
|
{
|
||||||
|
return new FilesystemEntry(){Name = path.Name, Type = FilesystemEntryType.Symlink, PointsTo = (await fs.ReadLinkAsync(path,token)).Path};
|
||||||
|
}
|
||||||
|
else if(await fs.DirectoryExistsAsync(path))
|
||||||
|
{
|
||||||
|
FilesystemEntry entry=new FilesystemEntry();
|
||||||
|
entry.Name = path.Name;
|
||||||
|
entry.Type = FilesystemEntryType.Dir;
|
||||||
|
await foreach(var ent in fs.EnumerateFileSystemEntriesAsync(path))
|
||||||
|
{
|
||||||
|
if(token.IsCancellationRequested) return entry;
|
||||||
|
entry.Entries.Add(await BackupPathAsync(authkey,fs,ent,token));
|
||||||
|
}
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
else if(await fs.FileExistsAsync(path))
|
||||||
|
{
|
||||||
|
FilesystemEntry entry = new FilesystemEntry();
|
||||||
|
entry.Name = path.Name;
|
||||||
|
entry.Type = FilesystemEntryType.File;
|
||||||
|
entry.Length = 0;
|
||||||
|
entry.Hashes=new List<string>();
|
||||||
|
|
||||||
|
using(var strm = await fs.OpenReadAsync(path))
|
||||||
|
{
|
||||||
|
if(strm.CanSeek) entry.Length = strm.Length;
|
||||||
|
await foreach(var hash in BackupFileAsync($"/{string.Join("/",path.Parts)}",authkey,strm,(len)=>entry.Length=len,token))
|
||||||
|
{
|
||||||
|
if(token.IsCancellationRequested) return entry;
|
||||||
|
entry.Hashes.Add(hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new FilesystemEntry(){Length=0, Type = FilesystemEntryType.File};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async IAsyncEnumerable<Backup> ListBackupsAsync(string authkey)
|
||||||
|
{
|
||||||
|
HttpRequestMessage request=new HttpRequestMessage(HttpMethod.Get,$"{url}/api/v1/Backup");
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer",authkey);
|
||||||
|
var resp=await clt.SendAsync(request);
|
||||||
|
resp.EnsureSuccessStatusCode();
|
||||||
|
foreach(var item in JsonConvert.DeserializeObject<List<Backup>>(await resp.Content.ReadAsStringAsync()))
|
||||||
|
{
|
||||||
|
if(item != null) yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<Backup> GetBackup(string authkey,long id,bool noHashes=true)
|
||||||
|
{
|
||||||
|
HttpRequestMessage request=new HttpRequestMessage(HttpMethod.Get,$"{url}/api/v1/Backup?id={id}&noHashes={noHashes}");
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer",authkey);
|
||||||
|
var resp=await clt.SendAsync(request);
|
||||||
|
resp.EnsureSuccessStatusCode();
|
||||||
|
var bkp=JsonConvert.DeserializeObject<Backup>(await resp.Content.ReadAsStringAsync());
|
||||||
|
return bkp;
|
||||||
|
}
|
||||||
|
private async Task RestoreAsync(string key,long id,FilesystemEntry entry,UnixPath srcPath,IVirtualFilesystem fs,UnixPath destPath,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
if(entry.Type == FilesystemEntryType.Dir)
|
||||||
|
{
|
||||||
|
await fs.CreateDirectoryAsync(destPath,token);
|
||||||
|
foreach(var ent in entry.Entries)
|
||||||
|
{
|
||||||
|
if(token.IsCancellationRequested) return;
|
||||||
|
await RestoreAsync(key,id,ent,srcPath/ent.Name,fs,destPath/ent.Name,token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(entry.Type == FilesystemEntryType.File)
|
||||||
|
{
|
||||||
|
|
||||||
|
using(var file = await fs.OpenAsync(destPath,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None))
|
||||||
|
{
|
||||||
|
ProgressBar bar=null;
|
||||||
|
IProgress<double> p=null;
|
||||||
|
if(ShowProgress && file.CanSeek)
|
||||||
|
{
|
||||||
|
var options = new ProgressBarOptions
|
||||||
|
{
|
||||||
|
ProgressCharacter = '─',
|
||||||
|
ProgressBarOnBottom = true
|
||||||
|
};
|
||||||
|
bar=new ProgressBar(10000,$"Restoring file {destPath.Path}");
|
||||||
|
p = bar.AsProgress<double>();
|
||||||
|
}else if(ShowProgress)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Stream is not seekable");
|
||||||
|
}
|
||||||
|
|
||||||
|
await RestoreFileAsync(key,id,srcPath.Path,file,new Progress<long>(e=>{
|
||||||
|
if(ShowProgress && file.CanSeek)
|
||||||
|
{
|
||||||
|
try{p.Report((double)e/(double)file.Length);}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_=ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}),token);
|
||||||
|
|
||||||
|
if(ShowProgress && file.CanSeek)
|
||||||
|
{
|
||||||
|
bar.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(entry.Type == FilesystemEntryType.Symlink) {
|
||||||
|
await fs.CreateSymlinkAsync(new UnixPath(entry.PointsTo),destPath,token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RestoreAsync(string key,long id,UnixPath srcPath,IVirtualFilesystem fs,UnixPath destPath,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
var bkp=await GetBackup(key,id);
|
||||||
|
await RestoreAsync(key,id,bkp.GetEntryFromPath(srcPath),srcPath,fs,destPath,token);
|
||||||
|
}
|
||||||
|
private async Task RestoreFileAsync(string key,long id, string path,Stream strm,IProgress<long> progress=null,CancellationToken token=default)
|
||||||
|
{
|
||||||
|
var _path = $"{url}/api/v1/Download?id={id}&access_key={WebUtility.UrlEncode(key)}&id={id}&path={WebUtility.UrlEncode(path)}";
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
long offset=0;
|
||||||
|
|
||||||
|
HttpRequestMessage requestMessage=new HttpRequestMessage(HttpMethod.Get,_path);
|
||||||
|
|
||||||
|
if(strm.CanSeek && strm.Length > 0)
|
||||||
|
{
|
||||||
|
strm.Position = strm.Length;
|
||||||
|
offset=strm.Position;
|
||||||
|
|
||||||
|
requestMessage.Headers.Range=new System.Net.Http.Headers.RangeHeaderValue(strm.Length,null);
|
||||||
|
}
|
||||||
|
if(token.IsCancellationRequested) return;
|
||||||
|
using(var req = await clt.SendAsync(requestMessage,token))
|
||||||
|
{
|
||||||
|
if(token.IsCancellationRequested) return;
|
||||||
|
if(req.StatusCode == System.Net.HttpStatusCode.RequestedRangeNotSatisfiable) return;
|
||||||
|
req.EnsureSuccessStatusCode();
|
||||||
|
int read = 0;
|
||||||
|
using(var srcStrm = await req.Content.ReadAsStreamAsync())
|
||||||
|
do {
|
||||||
|
read = await srcStrm.ReadAsync(buffer,0,buffer.Length,token);
|
||||||
|
if(token.IsCancellationRequested) return;
|
||||||
|
await strm.WriteAsync(buffer,0,read,token);
|
||||||
|
if(token.IsCancellationRequested) return;
|
||||||
|
offset += read;
|
||||||
|
progress?.Report(offset);
|
||||||
|
} while(read > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private async IAsyncEnumerable<string> BackupFileAsync(string name,string authkey,Stream file,Action<long> length,[EnumeratorCancellation]CancellationToken token=default)
|
||||||
|
{
|
||||||
|
if(file.CanSeek && file.Length == 0) yield break;
|
||||||
|
byte[] buffer = new byte[DedupStorage.BlockLength];
|
||||||
|
int read=0;
|
||||||
|
long totalLength=0;
|
||||||
|
ProgressBar bar=null;
|
||||||
|
IProgress<double> p=null;
|
||||||
|
if(ShowProgress && file.CanSeek)
|
||||||
|
{
|
||||||
|
var options = new ProgressBarOptions
|
||||||
|
{
|
||||||
|
ProgressCharacter = '─',
|
||||||
|
ProgressBarOnBottom = true
|
||||||
|
};
|
||||||
|
bar=new ProgressBar(10000,$"Backing up file {name}");
|
||||||
|
p = bar.AsProgress<double>();
|
||||||
|
}
|
||||||
|
else if(ShowProgress)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Stream is not seekable");
|
||||||
|
}
|
||||||
|
do{
|
||||||
|
read=await ReadAsync(file,buffer,token);
|
||||||
|
if(read == 0) yield break;
|
||||||
|
if(token.IsCancellationRequested) yield break;
|
||||||
|
string hash=DedupStorage.Sha512Hash(buffer);
|
||||||
|
yield return hash;
|
||||||
|
if(!await HasBlockAsync(authkey,hash,token))
|
||||||
|
{
|
||||||
|
await WriteBlockAsync(authkey,hash,buffer,token);
|
||||||
|
if(token.IsCancellationRequested) yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalLength += read;
|
||||||
|
|
||||||
|
if(ShowProgress)
|
||||||
|
{
|
||||||
|
if(file.CanSeek)
|
||||||
|
{
|
||||||
|
double progress = totalLength / (double)file.Length;
|
||||||
|
p?.Report(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} while(read == buffer.Length);
|
||||||
|
|
||||||
|
if(ShowProgress)
|
||||||
|
bar.Dispose();
|
||||||
|
|
||||||
|
if(!file.CanSeek)
|
||||||
|
length(totalLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if(ownClient)
|
||||||
|
this.clt.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
internal class BackupFailedException : Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public BackupFailedException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public BackupFailedException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public BackupFailedException(string server_hash, string hash) : base($"The server hash \"{server_hash}\" does not match client hash \"{hash}\"")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public BackupFailedException(string message, Exception innerException) : base(message, innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BackupFailedException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class LoginResult
|
||||||
|
{
|
||||||
|
[JsonProperty("success")]
|
||||||
|
public bool Success {get;set;}=false;
|
||||||
|
|
||||||
|
[JsonProperty("key")]
|
||||||
|
public string Key {get;set;}="";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Tesses.VirtualFilesystem;
|
||||||
|
using Zio;
|
||||||
|
|
||||||
|
namespace TessesDedup
|
||||||
|
{
|
||||||
|
public class FilesystemEntry
|
||||||
|
{
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name {get;set;}="";
|
||||||
|
|
||||||
|
[JsonProperty("type")]
|
||||||
|
[JsonConverter(typeof(StringEnumConverter),typeof(CamelCaseNamingStrategy))]
|
||||||
|
|
||||||
|
public FilesystemEntryType Type {get;set;} = FilesystemEntryType.Dir;
|
||||||
|
|
||||||
|
[JsonProperty("entries")]
|
||||||
|
public List<FilesystemEntry> Entries {get;set;}=new List<FilesystemEntry>();
|
||||||
|
|
||||||
|
[JsonProperty("hashes")]
|
||||||
|
public List<string> Hashes {get;set;}=new List<string>();
|
||||||
|
[JsonProperty("length")]
|
||||||
|
public long Length {get;set;}
|
||||||
|
|
||||||
|
[JsonProperty("points_to")]
|
||||||
|
public string PointsTo {get;set;}
|
||||||
|
|
||||||
|
public FilesystemEntry WithoutHashes()
|
||||||
|
{
|
||||||
|
if(Type == FilesystemEntryType.Dir)
|
||||||
|
{
|
||||||
|
FilesystemEntry ent=new FilesystemEntry();
|
||||||
|
ent.Name = Name;
|
||||||
|
ent.Type = FilesystemEntryType.Dir;
|
||||||
|
foreach(var item in Entries)
|
||||||
|
{
|
||||||
|
ent.Entries.Add(item.WithoutHashes());
|
||||||
|
}
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
else if(Type == FilesystemEntryType.File)
|
||||||
|
{
|
||||||
|
FilesystemEntry ent=new FilesystemEntry();
|
||||||
|
ent.Length = Length;
|
||||||
|
ent.Name = Name;
|
||||||
|
ent.Type = FilesystemEntryType.File;
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum FilesystemEntryType
|
||||||
|
{
|
||||||
|
Dir,
|
||||||
|
File,
|
||||||
|
|
||||||
|
Symlink
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<LangVersion>8.0</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
|
<PackageReference Include="Tesses.VirtualFilesystem" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Tesses.VirtualFilesystem.Base" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Tesses.VirtualFilesystem.Zio" Version="1.0.1" />
|
||||||
|
<PackageReference Include="LiteDb" Version="5.0.21" />
|
||||||
|
<PackageReference Include="Tesses.VirtualFilesystem.Extensions" Version="1.0.0" />
|
||||||
|
|
||||||
|
<PackageReference Include="Tesses.WebServer" Version="1.0.4.3" />
|
||||||
|
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
|
||||||
|
<PackageReference Include="Zio" Version="0.19.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,617 @@
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Net;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Tesses.VirtualFilesystem;
|
||||||
|
using Tesses.VirtualFilesystem.Filesystems;
|
||||||
|
using TessesDedup;
|
||||||
|
|
||||||
|
string verb = "";
|
||||||
|
List<KeyValuePair<string,string>> newArgs=new List<KeyValuePair<string, string>>();
|
||||||
|
List<string> positionalArguments =new List<string>();
|
||||||
|
|
||||||
|
string endpoint = Environment.GetEnvironmentVariable("TBKP_ENDPOINT") ?? "";
|
||||||
|
string accessKey = Environment.GetEnvironmentVariable("TBKP_ACCESS_KEY") ?? "";
|
||||||
|
bool env_set = !string.IsNullOrWhiteSpace(endpoint) && !string.IsNullOrWhiteSpace(accessKey);
|
||||||
|
string GetLoginPath()
|
||||||
|
{
|
||||||
|
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData,Environment.SpecialFolderOption.Create),"tbkp_login.json");
|
||||||
|
}
|
||||||
|
if(!env_set)
|
||||||
|
{
|
||||||
|
string conf = GetLoginPath();
|
||||||
|
if(File.Exists(conf))
|
||||||
|
{
|
||||||
|
var res=JsonConvert.DeserializeObject<LoginConf>(File.ReadAllText(conf));
|
||||||
|
if(res != null)
|
||||||
|
{
|
||||||
|
endpoint = res.Endpoint;
|
||||||
|
accessKey = res.AccessKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IEnumerable<string> GetArgsViaKey(string key)
|
||||||
|
{
|
||||||
|
foreach(var item in newArgs)
|
||||||
|
{
|
||||||
|
if(item.Key == key)
|
||||||
|
yield return item.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryGetFirst(string key,out string val)
|
||||||
|
{
|
||||||
|
foreach(var item in GetArgsViaKey(key))
|
||||||
|
{
|
||||||
|
val = item;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
val="";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetOrAsk(string prompt,bool password,params string[] keys)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach(var item in keys)
|
||||||
|
{
|
||||||
|
if(TryGetFirst(item,out var str))
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
if(password)
|
||||||
|
{
|
||||||
|
string res = ReadLine.ReadPassword($"{prompt}: ");
|
||||||
|
if(!string.IsNullOrWhiteSpace(res))
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
string res = ReadLine.Read($"{prompt}: ");
|
||||||
|
if(!string.IsNullOrWhiteSpace(res))
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string GetOrAskWithDefault(string prompt,string defaultValue,params string[] keys)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach(var item in keys)
|
||||||
|
{
|
||||||
|
if(TryGetFirst(item,out var str))
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
|
||||||
|
ReadLine.AddHistory(new string[]{defaultValue});
|
||||||
|
string res = ReadLine.Read($"{prompt}: ");
|
||||||
|
if(!string.IsNullOrWhiteSpace(res))
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args.Length > 0)
|
||||||
|
{
|
||||||
|
if(args[0] == "--help")
|
||||||
|
{
|
||||||
|
PrintHelp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
verb = args[0];
|
||||||
|
bool mustBePositionalArgs=false;
|
||||||
|
for(int i = 1;i<args.Length;i++)
|
||||||
|
{
|
||||||
|
if(!mustBePositionalArgs && args[i] == "--")
|
||||||
|
{
|
||||||
|
mustBePositionalArgs = true;
|
||||||
|
}else
|
||||||
|
if(!mustBePositionalArgs && args[i].StartsWith('-'))
|
||||||
|
{
|
||||||
|
string key= args[i].TrimStart('-');
|
||||||
|
if(key == "help")
|
||||||
|
{
|
||||||
|
PrintHelp(verb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(i+1<args.Length)
|
||||||
|
{
|
||||||
|
string value = args[i+1];
|
||||||
|
i++;
|
||||||
|
newArgs.Add(new KeyValuePair<string, string>(key,value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
positionalArguments.Add(args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PrintHelp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintHelp(string? page=null)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(page))
|
||||||
|
{
|
||||||
|
Console.WriteLine("tbkp");
|
||||||
|
Console.WriteLine("VERBS:");
|
||||||
|
Console.WriteLine("\tlogin\tLogin to backup server");
|
||||||
|
Console.WriteLine("\tlogout\tLogout from backup server");
|
||||||
|
Console.WriteLine("\tmount\tMount backups to filesystem");
|
||||||
|
Console.WriteLine("\tunmount\tUnmount backups to filesystem");
|
||||||
|
Console.WriteLine("\tbackup\tCreate backup");
|
||||||
|
Console.WriteLine("\tbackupex\tCreate backup with multiple mounts uses Zio C# Library: https://github.com/xoofx/zio");
|
||||||
|
Console.WriteLine("\trestore\tRestore backup with optional subentry");
|
||||||
|
Console.WriteLine("\tlist\tList backups");
|
||||||
|
Console.WriteLine("TIPS:");
|
||||||
|
Console.WriteLine("\tFlags always require a value (except for --help) so if you want to set a boolean to true type --flagName true or --flagName false for false");
|
||||||
|
Console.WriteLine("\tSet environment variables TBKP_ENDPOINT and TBKP_ACCESS_KEY whereever configuration is unavailable");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch(page)
|
||||||
|
{
|
||||||
|
case "login":
|
||||||
|
Console.WriteLine("tbkp login [options]");
|
||||||
|
Console.WriteLine("FLAGS:");
|
||||||
|
Console.WriteLine("-u,--user\tUsername");
|
||||||
|
Console.WriteLine("-p,--pass\tPassword");
|
||||||
|
Console.WriteLine("-e,--url\tThe Url to the server");
|
||||||
|
Console.WriteLine("-d,--deviceName\tThe Device Name");
|
||||||
|
Console.WriteLine("-a,--justAccessKey true\tusing --justAccessKey true will print created access key to console and wont save to file");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("NOTE: If the flags are not set (other than --justAccessKey true), we will ask for credentials");
|
||||||
|
break;
|
||||||
|
case "logout":
|
||||||
|
Console.WriteLine("tbkp logout");
|
||||||
|
Console.WriteLine("This is a verb without flags or arguments");
|
||||||
|
break;
|
||||||
|
case "mount":
|
||||||
|
Console.WriteLine("tbkp mount [path]");
|
||||||
|
Console.WriteLine("ARGS:");
|
||||||
|
Console.WriteLine("path (optional):\tMount to this path on your computer");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine($"NOTE: If path is not specified, \"{DefaultTBKP()}\" will be assumed");
|
||||||
|
Console.WriteLine("NOTE: httpdirfs is required, debian: sudo apt install httpdirfs, others: https://github.com/fangfufu/httpdirfs");
|
||||||
|
break;
|
||||||
|
case "unmount":
|
||||||
|
Console.WriteLine("tbkp unmount [path]");
|
||||||
|
Console.WriteLine("ARGS:");
|
||||||
|
Console.WriteLine("path (optional):\tunmount from this path on your computer");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine($"NOTE: If path is not specified, \"{DefaultTBKP()}\" will be assumed");
|
||||||
|
break;
|
||||||
|
case "backup":
|
||||||
|
Console.WriteLine("tbkp backup [options] path");
|
||||||
|
Console.WriteLine("ARGS:");
|
||||||
|
Console.WriteLine("path (optional):\tfolder to backup (defaults to current directory)");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("FLAGS:");
|
||||||
|
Console.WriteLine("-t, --tag:\tTag of backup (defaults to \"default\")");
|
||||||
|
Console.WriteLine("-s,--silent true\tusing --silent true will disable progress");
|
||||||
|
break;
|
||||||
|
case "backupex":
|
||||||
|
Console.WriteLine("tbkp backupex [options] root");
|
||||||
|
Console.WriteLine("ARGS:");
|
||||||
|
Console.WriteLine("root (optional):\troot folder to backup");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("FLAGS:");
|
||||||
|
Console.WriteLine("-t, --tag:\tTag of backup (defaults to \"default\")");
|
||||||
|
Console.WriteLine("-v, --volume:\tMount folders in backup like bind mounts in docker, -v /Path/On/Host:/Path/In/Backup");
|
||||||
|
Console.WriteLine("-s,--silent true\tusing --silent true will disable progress");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("NOTE: On windows using -v command you must replace C:\\YourPath\\ with \\con\\C\\YourPath\\ due to the colon");
|
||||||
|
Console.WriteLine("NOTE: On windows using -v command you can use / rather than \\ except for the \\con\\ part");
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
Console.WriteLine("tbkp list [options] /path/to/dir");
|
||||||
|
Console.WriteLine("ARGS:");
|
||||||
|
Console.WriteLine("/path/to/dir (optional):\tfolder to enumerate in backup");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("FLAGS:");
|
||||||
|
Console.WriteLine("-b, --backupId\t: The backup number (without this, it lists the backups)");
|
||||||
|
break;
|
||||||
|
case "restore":
|
||||||
|
Console.WriteLine("tbkp list [options] /path/to/output");
|
||||||
|
Console.WriteLine("ARGS:");
|
||||||
|
Console.WriteLine("/path/to/output:\tthe path to restore to, for files this will be the filename, for directory this will be the folder that contains the folder in backup's files");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("FLAGS:");
|
||||||
|
Console.WriteLine("-b, --backupId\t: The backup number");
|
||||||
|
Console.WriteLine("-p, --path\t: The path inside backup (defaults to / and can be file, but if file the /path/to/output must not be a directory)");
|
||||||
|
Console.WriteLine("-s,--silent true\tusing --silent true will disable progress");
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mount(string path)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
MountIntern(path);
|
||||||
|
|
||||||
|
}
|
||||||
|
void Mount2()
|
||||||
|
{
|
||||||
|
string p = DefaultTBKP();
|
||||||
|
string file = Path.Combine(p,"readme.txt");
|
||||||
|
if(File.Exists(file))
|
||||||
|
{
|
||||||
|
MountIntern(p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Already mounted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void MountIntern(string path)
|
||||||
|
{
|
||||||
|
using(Process p = new Process())
|
||||||
|
{
|
||||||
|
p.StartInfo.FileName = Find("httpdirfs");
|
||||||
|
p.StartInfo.ArgumentList.Add("-o");
|
||||||
|
p.StartInfo.ArgumentList.Add("nonempty");
|
||||||
|
p.StartInfo.ArgumentList.Add("-u");
|
||||||
|
p.StartInfo.ArgumentList.Add("$access_key");
|
||||||
|
p.StartInfo.ArgumentList.Add("-p");
|
||||||
|
p.StartInfo.ArgumentList.Add(accessKey);
|
||||||
|
p.StartInfo.ArgumentList.Add($"{endpoint.TrimEnd('/')}/data/");
|
||||||
|
p.StartInfo.ArgumentList.Add(path);
|
||||||
|
|
||||||
|
p.StartInfo.UseShellExecute = false;
|
||||||
|
p.StartInfo.RedirectStandardOutput=true;
|
||||||
|
p.StartInfo.RedirectStandardError=true;
|
||||||
|
|
||||||
|
p.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Unmount2()
|
||||||
|
{
|
||||||
|
string p = DefaultTBKP();
|
||||||
|
string file = Path.Combine(p,"readme.txt");
|
||||||
|
if(File.Exists(file))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Filesystem not mounted");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Umount(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Umount(string path)
|
||||||
|
{
|
||||||
|
using(Process p = new Process())
|
||||||
|
{
|
||||||
|
p.StartInfo.FileName = Find(Environment.OSVersion.Platform == PlatformID.Win32NT ? "mountvol" : "umount");
|
||||||
|
if(Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||||
|
{
|
||||||
|
p.StartInfo.ArgumentList.Add(path);
|
||||||
|
p.StartInfo.ArgumentList.Add("/d");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p.StartInfo.ArgumentList.Add(path);
|
||||||
|
}
|
||||||
|
if(p.Start()) {
|
||||||
|
p.WaitForExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string Find(string v)
|
||||||
|
{
|
||||||
|
string[] path = (Environment.GetEnvironmentVariable("PATH") ?? "").Split(Path.PathSeparator);
|
||||||
|
string[] pathext = (Environment.GetEnvironmentVariable("PATHEXT") ?? "").Split(Path.PathSeparator);
|
||||||
|
foreach(var dir in path)
|
||||||
|
{
|
||||||
|
string _vp = Path.Combine(dir,v);
|
||||||
|
if(File.Exists(_vp)) return _vp;
|
||||||
|
foreach(var ext in pathext)
|
||||||
|
{
|
||||||
|
string p=$"{_vp}{ext}";
|
||||||
|
if(File.Exists(p)) return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
string DefaultTBKP()
|
||||||
|
{
|
||||||
|
var dir= Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments,Environment.SpecialFolderOption.Create),"Tesses Backups");
|
||||||
|
if(!Directory.Exists(dir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
File.WriteAllText(Path.Combine(dir,"readme.txt"),"Don't Delete this file, unless you delete the folder it is in.\nAlso don't put any files in this directory as the tool mounts here\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (verb)
|
||||||
|
{
|
||||||
|
case "login":
|
||||||
|
{
|
||||||
|
if(env_set) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("ERROR: TBKP_ENDPOINT and TBKP_ACCESS_KEY are set");
|
||||||
|
Console.ResetColor();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string url=GetOrAsk("Endpoint (Server Url)",false,"url","e");
|
||||||
|
string username=GetOrAsk("Username",false,"user","u");
|
||||||
|
string password=GetOrAsk("Password",true,"pass","p");
|
||||||
|
string deviceName=GetOrAskWithDefault("Device Name (press up for hostname)",Dns.GetHostName(),"deviceName","d");
|
||||||
|
|
||||||
|
using DedupClient client=new DedupClient(url);
|
||||||
|
var res=await client.LoginAsync(username,password,deviceName);
|
||||||
|
|
||||||
|
if(res.Success)
|
||||||
|
{
|
||||||
|
if((TryGetFirst("justAccessKey",out var akV) || TryGetFirst("a",out akV)) && akV == "true")
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Your access key is: {res.Key}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoginConf conf = new LoginConf();
|
||||||
|
conf.AccessKey = res.Key;
|
||||||
|
conf.Endpoint = url;
|
||||||
|
File.WriteAllText(GetLoginPath(),JsonConvert.SerializeObject(conf));
|
||||||
|
Console.WriteLine("Logged in successfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Can't login, invalid password or something like that");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "logout":
|
||||||
|
{
|
||||||
|
using DedupClient client=new DedupClient(endpoint);
|
||||||
|
await client.LogoutAsync(endpoint);
|
||||||
|
if(!env_set)
|
||||||
|
{
|
||||||
|
File.Delete(GetLoginPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "mount":
|
||||||
|
{
|
||||||
|
if(positionalArguments.Count > 0)
|
||||||
|
{
|
||||||
|
Mount(positionalArguments[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Mount2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "unmount":
|
||||||
|
{
|
||||||
|
if(positionalArguments.Count > 0)
|
||||||
|
{
|
||||||
|
Umount(positionalArguments[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Unmount2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "restore":
|
||||||
|
{
|
||||||
|
bool silent = false;
|
||||||
|
|
||||||
|
if(TryGetFirst("s",out var sltStr) || TryGetFirst("silent",out sltStr))
|
||||||
|
{
|
||||||
|
silent = sltStr=="true";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(positionalArguments.Count > 0)
|
||||||
|
{
|
||||||
|
if((TryGetFirst("backupId",out var backupId) || TryGetFirst("b",out backupId)) && long.TryParse(backupId,out var id))
|
||||||
|
{
|
||||||
|
string path = "/";
|
||||||
|
if(TryGetFirst("p",out var p) || TryGetFirst("path",out p))
|
||||||
|
path = p;
|
||||||
|
|
||||||
|
//we need to restore backup
|
||||||
|
// public async Task RestoreAsync(string key,long id,UnixPath srcPath,IVirtualFilesystem fs,UnixPath destPath,CancellationToken token=default)
|
||||||
|
|
||||||
|
using var ddc = new DedupClient(endpoint,!silent);
|
||||||
|
LocalFileSystem fs = new LocalFileSystem();
|
||||||
|
await ddc.RestoreAsync(accessKey,id,new UnixPath(path),fs,UnixPath.FromLocal(Path.GetFullPath(positionalArguments[0])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
{
|
||||||
|
if(positionalArguments.Count > 0)
|
||||||
|
{
|
||||||
|
if((TryGetFirst("backupId",out var backupId) || TryGetFirst("b",out backupId)) && long.TryParse(backupId,out var id))
|
||||||
|
{
|
||||||
|
using DedupClient client = new DedupClient(endpoint);
|
||||||
|
var bkp=await client.GetBackup(accessKey,id);
|
||||||
|
foreach(var item in bkp.GetEntryFromPath(new UnixPath(positionalArguments[0])).Entries)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{item.Type.ToString().ToUpper()}] {item.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Use \"--backupId n\" from this list in the square brackets");
|
||||||
|
using DedupClient client = new DedupClient(endpoint);
|
||||||
|
await foreach(var item in client.ListBackupsAsync(accessKey))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{item.Id}] {item.DeviceName} - {item.Tag} ({item.CreationDate.ToString("G")})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((TryGetFirst("backupId",out var backupId) || TryGetFirst("b",out backupId)) && long.TryParse(backupId,out var id))
|
||||||
|
{
|
||||||
|
|
||||||
|
using DedupClient client = new DedupClient(endpoint);
|
||||||
|
var bkp=await client.GetBackup(accessKey,id);
|
||||||
|
foreach(var item in bkp.Root.Entries)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{item.Type.ToString().ToUpper()}] {item.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using DedupClient client = new DedupClient(endpoint);
|
||||||
|
await foreach(var item in client.ListBackupsAsync(accessKey))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{item.Id}] {item.DeviceName} - {item.Tag} ({item.CreationDate.ToString("G")})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "backup":
|
||||||
|
{
|
||||||
|
bool silent = false;
|
||||||
|
|
||||||
|
if(TryGetFirst("s",out var sltStr) || TryGetFirst("silent",out sltStr))
|
||||||
|
{
|
||||||
|
silent = sltStr=="true";
|
||||||
|
}
|
||||||
|
string tag="default";
|
||||||
|
if(TryGetFirst("t",out var t) || TryGetFirst("tag",out t))
|
||||||
|
{
|
||||||
|
tag = t;
|
||||||
|
}
|
||||||
|
UnixPath path = Special.CurDir;
|
||||||
|
if(positionalArguments.Count > 0)
|
||||||
|
{
|
||||||
|
path = new UnixPath(Path.GetFullPath(positionalArguments[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalFileSystem fs=new LocalFileSystem();
|
||||||
|
|
||||||
|
|
||||||
|
DedupClient client=new DedupClient(endpoint,!silent);
|
||||||
|
await client.BackupAsync(accessKey,fs.GetSubdirFilesystem(path),tag);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "backupex":
|
||||||
|
{
|
||||||
|
bool silent = false;
|
||||||
|
|
||||||
|
if(TryGetFirst("s",out var sltStr) || TryGetFirst("silent",out sltStr))
|
||||||
|
{
|
||||||
|
silent = sltStr=="true";
|
||||||
|
}
|
||||||
|
string tag="default";
|
||||||
|
if(TryGetFirst("t",out var t) || TryGetFirst("tag",out t))
|
||||||
|
{
|
||||||
|
tag = t;
|
||||||
|
}
|
||||||
|
LocalFileSystem fs=new LocalFileSystem();
|
||||||
|
ZioMountableWrapper wrapper;
|
||||||
|
if(positionalArguments.Count > 0)
|
||||||
|
{
|
||||||
|
var p = new UnixPath(Path.GetFullPath(positionalArguments[0]));
|
||||||
|
wrapper=ZioMountableWrapper.Create(fs.GetSubdirFilesystem(p),true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wrapper=ZioMountableWrapper.Create(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(var bind in GetArgsViaKey("v"))
|
||||||
|
{
|
||||||
|
var _bind=bind.Split(new char[]{':'});
|
||||||
|
|
||||||
|
|
||||||
|
if(_bind.Length == 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(_bind[0].StartsWith("\\con\\"))
|
||||||
|
{
|
||||||
|
string[] path=_bind[0].Replace("\\con\\","").Split(new char[]{'\\'},2,StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
_bind[0] = $"{path[0]}:\\";
|
||||||
|
if(path.Length > 1)
|
||||||
|
{
|
||||||
|
_bind[0] += path[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wrapper.Mount(UnixPath.FromLocal(_bind[1]),fs.GetSubdirFilesystem(new UnixPath(UnixPath.FromLocal(_bind[0]))));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(var bind in GetArgsViaKey("volume"))
|
||||||
|
{
|
||||||
|
var _bind=bind.Split(new char[]{':'});
|
||||||
|
|
||||||
|
|
||||||
|
if(_bind.Length == 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(_bind[0].StartsWith("\\con\\"))
|
||||||
|
{
|
||||||
|
string[] path=_bind[0].Replace("\\con\\","").Split(new char[]{'\\'},2,StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
_bind[0] = $"{path[0]}:\\";
|
||||||
|
if(path.Length > 1)
|
||||||
|
{
|
||||||
|
_bind[0] += path[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wrapper.Mount(UnixPath.FromLocal(_bind[1]),fs.GetSubdirFilesystem(new UnixPath(UnixPath.FromLocal(_bind[0]))));
|
||||||
|
}
|
||||||
|
|
||||||
|
// \con\C\Users\
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using DedupClient client=new DedupClient(endpoint,!silent);
|
||||||
|
await client.BackupAsync(accessKey,wrapper,tag);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
internal class LoginConf
|
||||||
|
{
|
||||||
|
[JsonProperty("endpoint")]
|
||||||
|
public string Endpoint {get;set;}="";
|
||||||
|
[JsonProperty("access_key")]
|
||||||
|
public string AccessKey {get;set;}="";
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ReadLine" Version="2.0.1" />
|
||||||
|
<PackageReference Include="Tesses.VirtualFilesystem" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Tesses.VirtualFilesystem.Local" Version="1.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TessesDedup\TessesDedup.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,14 @@
|
||||||
|
using TessesDedup;
|
||||||
|
using Tesses.WebServer;
|
||||||
|
using Tesses.VirtualFilesystem.Filesystems;
|
||||||
|
using Tesses.VirtualFilesystem;
|
||||||
|
using LiteDB;
|
||||||
|
|
||||||
|
Directory.CreateDirectory("data/storage");
|
||||||
|
Directory.CreateDirectory("data/wwwroot");
|
||||||
|
|
||||||
|
LocalFileSystem fs = new LocalFileSystem();
|
||||||
|
|
||||||
|
|
||||||
|
Dedup dedup = new Dedup(new StaticServer("data/wwwroot"){ RedirectToRootInsteadOfNotFound=true},fs.GetSubdirFilesystem(Special.CurDir / "data" / "storage"),()=>new LiteDatabase("data/backups.db"));
|
||||||
|
dedup.Server.StartServer(3255);
|
|
@ -0,0 +1,18 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TessesDedup\TessesDedup.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Tesses.Virtualfilesystem.Local" Version="1.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<Router AppAssembly="@typeof(App).Assembly">
|
||||||
|
<Found Context="routeData">
|
||||||
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||||
|
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||||
|
</Found>
|
||||||
|
<NotFound>
|
||||||
|
<PageTitle>Not found</PageTitle>
|
||||||
|
<LayoutView Layout="@typeof(MainLayout)">
|
||||||
|
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||||
|
</LayoutView>
|
||||||
|
</NotFound>
|
||||||
|
</Router>
|
|
@ -0,0 +1,55 @@
|
||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
<nav class="left drawer l">
|
||||||
|
<header>
|
||||||
|
<nav>
|
||||||
|
<h6>Tesses Dedup</h6>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<NavLink href="/" Match="NavLinkMatch.All">
|
||||||
|
<i>home</i>
|
||||||
|
<div>Home</div>
|
||||||
|
</NavLink>
|
||||||
|
<NavLink href="/backups">
|
||||||
|
<i>backup</i>
|
||||||
|
<div>Backups</div>
|
||||||
|
</NavLink>
|
||||||
|
<NavLink href="/access_keys">
|
||||||
|
<i>key</i>
|
||||||
|
<div>Access Keys</div>
|
||||||
|
</NavLink>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<nav class="left m">
|
||||||
|
|
||||||
|
<NavLink href="/" Match="NavLinkMatch.All">
|
||||||
|
<i>home</i>
|
||||||
|
<div>Home</div>
|
||||||
|
</NavLink>
|
||||||
|
<NavLink href="/backups">
|
||||||
|
<i>backup</i>
|
||||||
|
<div>Backups</div>
|
||||||
|
</NavLink>
|
||||||
|
<NavLink href="/access_keys">
|
||||||
|
<i>key</i>
|
||||||
|
<div>Access Keys</div>
|
||||||
|
</NavLink>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<nav class="bottom s">
|
||||||
|
<NavLink href="/" Match="NavLinkMatch.All">
|
||||||
|
<i>home</i>
|
||||||
|
|
||||||
|
</NavLink>
|
||||||
|
<NavLink href="/backups">
|
||||||
|
<i>backup</i>
|
||||||
|
|
||||||
|
</NavLink>
|
||||||
|
<NavLink href="/access_keys">
|
||||||
|
<i>key</i>
|
||||||
|
</NavLink>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="responsive">
|
||||||
|
@Body
|
||||||
|
</main>
|
|
@ -0,0 +1,98 @@
|
||||||
|
@page "/access_keys"
|
||||||
|
@inject DedupClient Client;
|
||||||
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
|
||||||
|
@inject IJSRuntime jsRt;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<div class="row padding">
|
||||||
|
<div class="max">
|
||||||
|
<h6 class="small">This Browser</h6>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<a class="button" href="/access_keys/new"><i>add</i> New Access Key</a> <a class="button" href="/access_keys/edit"><i>edit</i> Edit</a> <button @onclick="async()=>await LogoutAsync()"><i>logout</i> Logout</button>
|
||||||
|
</div>
|
||||||
|
@if(Ready)
|
||||||
|
{
|
||||||
|
@foreach(var item in Items)
|
||||||
|
{
|
||||||
|
|
||||||
|
<div class="divider"></div>
|
||||||
|
|
||||||
|
<div class="row padding">
|
||||||
|
<div class="max">
|
||||||
|
<h6 class="small">@item.DeviceName</h6>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<label>@item.Created.Humanize() <button @onclick="async()=>await DeleteAsync(item)"><i>delete</i> Delete</button></label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</article>
|
||||||
|
|
||||||
|
|
||||||
|
@code {
|
||||||
|
public List<AccessKey> Items {get;set;}=new List<AccessKey>();
|
||||||
|
|
||||||
|
public bool Ready {get;set;}=false;
|
||||||
|
|
||||||
|
string token="";
|
||||||
|
|
||||||
|
public async Task LogoutAsync()
|
||||||
|
{
|
||||||
|
if(!await jsRt.InvokeAsync<bool>("confirm","Are you sure you want to to logout?")) return;
|
||||||
|
|
||||||
|
try{
|
||||||
|
await Client.LogoutAsync(token);
|
||||||
|
}catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
_=ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
await localStorage.RemoveItemAsync("token");
|
||||||
|
Items.Clear();
|
||||||
|
StateHasChanged();
|
||||||
|
}catch(Exception ex)
|
||||||
|
{
|
||||||
|
_=ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(AccessKey ak)
|
||||||
|
{
|
||||||
|
if(!await jsRt.InvokeAsync<bool>("confirm",$"Are you sure you want to delete the access key {ak.DeviceName} created {ak.Created.Humanize()}?")) return;
|
||||||
|
|
||||||
|
var res=await Client.AccessKeyDeleteAsync(token,ak.Id);
|
||||||
|
|
||||||
|
if(res.Success)
|
||||||
|
{
|
||||||
|
Items.Remove(ak);
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var _token = await localStorage.GetItemAsStringAsync("token");
|
||||||
|
if(!string.IsNullOrWhiteSpace(_token))
|
||||||
|
{
|
||||||
|
token = _token;
|
||||||
|
Items.Clear();
|
||||||
|
try{
|
||||||
|
await foreach(var item in Client.GetAccessKeysAsync(_token))
|
||||||
|
{
|
||||||
|
Items.Add(item);
|
||||||
|
}
|
||||||
|
}catch(Exception ex){_=ex;}
|
||||||
|
Ready=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,144 @@
|
||||||
|
@page "/backups/{id:long}"
|
||||||
|
@inject NavigationManager NavManager;
|
||||||
|
@inject DedupClient Client;
|
||||||
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
|
||||||
|
|
||||||
|
@if(IsReady)
|
||||||
|
{
|
||||||
|
if(IsDir)
|
||||||
|
{
|
||||||
|
if(ParentPath == "/backups")
|
||||||
|
{
|
||||||
|
<a href="/backups">Up</a> <span>@Path</span>
|
||||||
|
}else{
|
||||||
|
<a @onclick="()=>Navmgr(ParentPath)">Up</a> <span>@Path</span>
|
||||||
|
}
|
||||||
|
<hr>
|
||||||
|
foreach(var item in Entries)
|
||||||
|
{
|
||||||
|
if(item.PointsTo.StartsWith("/api/v1/Download"))
|
||||||
|
{
|
||||||
|
<a class="row padding surface-container" target="_blank" href="@item.PointsTo">
|
||||||
|
<i>@item.Type</i>
|
||||||
|
<div class="max">
|
||||||
|
<h6 class="small">@item.Name</h6>
|
||||||
|
</div>
|
||||||
|
<label></label>
|
||||||
|
</a>
|
||||||
|
}else{
|
||||||
|
<a class="row padding surface-container" @onclick="()=>Navmgr(item.PointsTo)">
|
||||||
|
<i>@item.Type</i>
|
||||||
|
<div class="max">
|
||||||
|
<h6 class="small">@item.Name</h6>
|
||||||
|
</div>
|
||||||
|
<label></label>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public long Id {get;set;}
|
||||||
|
|
||||||
|
|
||||||
|
public string Path {get;set;}="";
|
||||||
|
|
||||||
|
public bool IsReady {get;set;}=false;
|
||||||
|
|
||||||
|
public bool IsDir {get;set;}=false;
|
||||||
|
|
||||||
|
public string Url {get;set;}="";
|
||||||
|
|
||||||
|
public string ParentPath {get;set;}="";
|
||||||
|
|
||||||
|
public List<FilesystemEntry> Entries {get;set;}=new List<FilesystemEntry>();
|
||||||
|
string token="";
|
||||||
|
|
||||||
|
public void HandlePage(string path)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(!string.IsNullOrWhiteSpace(path))
|
||||||
|
{
|
||||||
|
UnixPath unixPath = path;
|
||||||
|
|
||||||
|
var p=bkp.GetEntryFromPath(unixPath);
|
||||||
|
if(unixPath.Path == "/" || unixPath.Path.Length == 0)
|
||||||
|
ParentPath="/backups";
|
||||||
|
else
|
||||||
|
ParentPath = $"/backups/{Id}?path={WebUtility.UrlEncode(unixPath.Parent.Path)}";
|
||||||
|
|
||||||
|
if(p.Type == "dir")
|
||||||
|
{
|
||||||
|
IsDir=true;
|
||||||
|
foreach(var item in p.Entries)
|
||||||
|
{
|
||||||
|
FilesystemEntry ent = new FilesystemEntry();
|
||||||
|
ent.Name = item.Name;
|
||||||
|
if(item.Type == "dir")
|
||||||
|
{
|
||||||
|
ent.PointsTo = $"/backups/{Id}?path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
|
||||||
|
ent.Type = "folder";
|
||||||
|
}
|
||||||
|
else if(item.Type == "file")
|
||||||
|
{
|
||||||
|
ent.PointsTo = $"/api/v1/Download?access_key={WebUtility.UrlEncode(token)}&id={Id}&path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
|
||||||
|
ent.Type = "draft";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var follow = bkp.GetEntryFromPath(unixPath/item.Name);
|
||||||
|
if(follow.Type == "dir")
|
||||||
|
{
|
||||||
|
ent.PointsTo = $"/backups/{Id}?path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ent.PointsTo = $"/api/v1/Download?access_key={WebUtility.UrlEncode(token)}&id={Id}&path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
|
||||||
|
}
|
||||||
|
ent.Type = "link";
|
||||||
|
}
|
||||||
|
Entries.Add(ent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
IsReady=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Backup bkp=new Backup();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void Navmgr(string _url)
|
||||||
|
{
|
||||||
|
Entries.Clear();
|
||||||
|
IsReady=false;
|
||||||
|
NavManager.NavigateTo(_url);
|
||||||
|
var url=NavManager.ToAbsoluteUri(_url);
|
||||||
|
if(QueryHelpers.ParseQuery(url.Query).TryGetValue("path",out var value))
|
||||||
|
{
|
||||||
|
string? path = value;
|
||||||
|
if(!string.IsNullOrWhiteSpace(path))
|
||||||
|
{
|
||||||
|
HandlePage(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var _token = await localStorage.GetItemAsStringAsync("token");
|
||||||
|
if(!string.IsNullOrWhiteSpace(_token))
|
||||||
|
{
|
||||||
|
token = _token;
|
||||||
|
bkp = await Client.GetBackupAsync(token,Id);
|
||||||
|
Navmgr(NavManager.Uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
@page "/backups"
|
||||||
|
@inject DedupClient Client;
|
||||||
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
|
||||||
|
|
||||||
|
@if(Ready)
|
||||||
|
{
|
||||||
|
var i = 0;
|
||||||
|
<article>
|
||||||
|
@foreach(var item in Items)
|
||||||
|
{
|
||||||
|
|
||||||
|
@if(i > 0)
|
||||||
|
{
|
||||||
|
<div class="divider"></div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<a class="row padding" href="/backups/@item.Id?path=/">
|
||||||
|
<div class="max">
|
||||||
|
<h6 class="small">@item.DeviceName</h6>
|
||||||
|
<div>@item.Tag</div>
|
||||||
|
</div>
|
||||||
|
<label>@item.CreationDate.Humanize()</label>
|
||||||
|
</a>
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
</article>
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
public bool Ready {get;set;}=false;
|
||||||
|
|
||||||
|
public List<Backup> Items {get;set;}=new List<Backup>();
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var loggedIn = await localStorage.ContainKeyAsync("token");
|
||||||
|
if(loggedIn)
|
||||||
|
{
|
||||||
|
var token=await localStorage.GetItemAsStringAsync("token");
|
||||||
|
await foreach(var item in Client.GetBackupsAsync(token ?? ""))
|
||||||
|
{
|
||||||
|
Items.Add(item);
|
||||||
|
}
|
||||||
|
Ready=true;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
@page "/access_keys/edit"
|
||||||
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
|
||||||
|
@inject IJSRuntime jsRt;
|
||||||
|
@inject HttpClient client;
|
||||||
|
|
||||||
|
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="_AccessKey">
|
||||||
|
<label>Access Key</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary class="none">
|
||||||
|
<article class="round primary no-elevate">
|
||||||
|
<nav>
|
||||||
|
<div class="max">Mount backups (Read only, Linux)</div>
|
||||||
|
<i>expand_more</i>
|
||||||
|
</nav>
|
||||||
|
</article>
|
||||||
|
</summary>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Install</h2>
|
||||||
|
<code>
|
||||||
|
$ sudo apt install httpdirfs
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Mount</h2>
|
||||||
|
<code>
|
||||||
|
$ mkdir "~/BackupsMount"<br>
|
||||||
|
$ httpdirfs -u "\$access_key" -p "@_AccessKey" "@WebUrl" "~/BackupsMount"
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Unmount</h2>
|
||||||
|
<code>
|
||||||
|
$ umount "~/BackupsMount"
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Unmount (if busy and you are impatient)</h2>
|
||||||
|
<code>
|
||||||
|
$ umount -l "~/BackupsMount"
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<button @onclick="async()=>await SaveAsync()"><i>save</i> Save</button>
|
||||||
|
<a href="/access_keys" class="button">Done</a>
|
||||||
|
@code {
|
||||||
|
public string _AccessKey {get;set;}="";
|
||||||
|
|
||||||
|
public string WebUrl => $"{(client.BaseAddress?.ToString() ?? "").TrimEnd('/')}/data/";
|
||||||
|
|
||||||
|
public async Task SaveAsync()
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(_AccessKey))
|
||||||
|
{
|
||||||
|
if(await localStorage.ContainKeyAsync("token"))
|
||||||
|
await localStorage.RemoveItemAsync("token");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
await localStorage.SetItemAsStringAsync("token",_AccessKey);
|
||||||
|
}
|
||||||
|
await jsRt.InvokeVoidAsync("alert","Saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
_AccessKey = await localStorage.GetItemAsStringAsync("token") ?? "";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,176 @@
|
||||||
|
@page "/"
|
||||||
|
@inject DedupClient Client;
|
||||||
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
|
||||||
|
@inject IJSRuntime jsRt;
|
||||||
|
<div id="sb_error" class="snackbar error">@Error</div>
|
||||||
|
|
||||||
|
@if(Ready)
|
||||||
|
{
|
||||||
|
@if(LoggedIn)
|
||||||
|
{
|
||||||
|
<h2>Backups: @Stats.Backups</h2>
|
||||||
|
<h2>Blocks: @Stats.Blocks</h2>
|
||||||
|
<h2>Size: @Stats.Label</h2>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<details>
|
||||||
|
<summary class="none">
|
||||||
|
<article class="round primary no-elevate">
|
||||||
|
<nav>
|
||||||
|
<div class="max">Mount backups (Read only, Linux)</div>
|
||||||
|
<i>expand_more</i>
|
||||||
|
</nav>
|
||||||
|
</article>
|
||||||
|
</summary>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Install</h2>
|
||||||
|
<code>
|
||||||
|
$ sudo apt install httpdirfs
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Mount</h2>
|
||||||
|
<code>
|
||||||
|
$ mkdir "~/BackupsMount"<br>
|
||||||
|
$ httpdirfs -u "\$access_key" -p "@_AccessKey" "@Client.DataPath" "~/BackupsMount"
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Unmount</h2>
|
||||||
|
<code>
|
||||||
|
$ umount "~/BackupsMount"
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
<article class="round border">
|
||||||
|
<h2>To Unmount (if busy and you are impatient)</h2>
|
||||||
|
<code>
|
||||||
|
$ umount -l "~/BackupsMount"
|
||||||
|
</code>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</details>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@if(Registered)
|
||||||
|
{
|
||||||
|
<h1>Login</h1>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="Username">
|
||||||
|
<label>Username</label>
|
||||||
|
</div>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="password" @bind-value="Password">
|
||||||
|
<label>Password</label>
|
||||||
|
</div>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="DeviceName">
|
||||||
|
<label>Device Name</label>
|
||||||
|
</div>
|
||||||
|
<button @onclick="LoginAsync">Login</button>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<h1>Register</h1>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="Username">
|
||||||
|
<label>Username</label>
|
||||||
|
</div>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="password" @bind-value="Password">
|
||||||
|
<label>Password</label>
|
||||||
|
</div>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="password" @bind-value="ConfirmPassword">
|
||||||
|
<label>Confirm Password</label>
|
||||||
|
</div>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="DeviceName">
|
||||||
|
<label>Device Name</label>
|
||||||
|
</div>
|
||||||
|
<button @onclick="RegisterAsync">Register</button>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@code {
|
||||||
|
public async Task SplashErrorAsync(string error)
|
||||||
|
{
|
||||||
|
Error = error;
|
||||||
|
await jsRt.InvokeVoidAsync("ui","#sb_error");
|
||||||
|
}
|
||||||
|
public Stats Stats {get;set;}=new Stats();
|
||||||
|
public bool Ready {get;set;}=false;
|
||||||
|
public bool Registered {get;set;}=false;
|
||||||
|
|
||||||
|
public bool LoggedIn {get;set;}=false;
|
||||||
|
|
||||||
|
|
||||||
|
public string Username {get;set;}="";
|
||||||
|
public string Password {get;set;}="";
|
||||||
|
|
||||||
|
public string ConfirmPassword {get;set;}="";
|
||||||
|
|
||||||
|
public string Error {get;set;}="";
|
||||||
|
|
||||||
|
public string DeviceName {get;set;}="Browser";
|
||||||
|
|
||||||
|
public string _AccessKey {get;set;}="";
|
||||||
|
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
LoggedIn = await localStorage.ContainKeyAsync("token");
|
||||||
|
if(LoggedIn)
|
||||||
|
{
|
||||||
|
var token=await localStorage.GetItemAsStringAsync("token");
|
||||||
|
try{
|
||||||
|
_AccessKey = token ?? "";
|
||||||
|
Stats = await Client.GetStatsAsync(_AccessKey);
|
||||||
|
}catch(System.Net.Http.HttpRequestException ex)
|
||||||
|
{
|
||||||
|
_=ex;
|
||||||
|
LoggedIn=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Registered = await Client.IsRegisteredAsync();
|
||||||
|
Ready = true;
|
||||||
|
}
|
||||||
|
public async Task LoginAsync()
|
||||||
|
{
|
||||||
|
var res=await Client.LoginAsync(Username,Password,DeviceName);
|
||||||
|
if(res.Success)
|
||||||
|
{
|
||||||
|
await localStorage.SetItemAsStringAsync("token",res.Key);
|
||||||
|
Registered=true;
|
||||||
|
LoggedIn=true;
|
||||||
|
_AccessKey = res.Key;
|
||||||
|
Stats = await Client.GetStatsAsync(res.Key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await SplashErrorAsync("Incorrect username or password");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task RegisterAsync()
|
||||||
|
{
|
||||||
|
if(Password != ConfirmPassword)
|
||||||
|
{
|
||||||
|
await SplashErrorAsync("Passwords do not match");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var res=await Client.LoginAsync(Username,Password,DeviceName);
|
||||||
|
if(res.Success)
|
||||||
|
{
|
||||||
|
await localStorage.SetItemAsStringAsync("token",res.Key);
|
||||||
|
Stats = await Client.GetStatsAsync(res.Key);
|
||||||
|
Registered=true;
|
||||||
|
LoggedIn=true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await SplashErrorAsync("Incorrect username or password");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
@page "/access_keys/new"
|
||||||
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
|
||||||
|
@inject DedupClient Client;
|
||||||
|
@inject IJSRuntime jsRt;
|
||||||
|
|
||||||
|
<div id="sb_error" class="snackbar error">Incorrect username or password</div>
|
||||||
|
|
||||||
|
<p>Note: you won't be able to access the key again, unless you have access to the database.</p>
|
||||||
|
|
||||||
|
<h1>Create access key</h1>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="Username">
|
||||||
|
<label>Username</label>
|
||||||
|
</div>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="password" @bind-value="Password">
|
||||||
|
<label>Password</label>
|
||||||
|
</div>
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="DeviceName">
|
||||||
|
<label>Device Name</label>
|
||||||
|
</div>
|
||||||
|
<button @onclick="LoginAsync">Login</button>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="field label border">
|
||||||
|
<input type="text" @bind-value="_AccessKey" readonly>
|
||||||
|
<label>Access Key</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a href="/access_keys" class="button">Done</a>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
public string Username {get;set;}="";
|
||||||
|
public string Password {get;set;}="";
|
||||||
|
|
||||||
|
public string DeviceName {get;set;}=$"New Access Key {DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}";
|
||||||
|
|
||||||
|
public string _AccessKey {get;set;}="";
|
||||||
|
|
||||||
|
public async Task LoginAsync()
|
||||||
|
{
|
||||||
|
var res=await Client.LoginAsync(Username,Password,DeviceName);
|
||||||
|
if(res.Success)
|
||||||
|
{
|
||||||
|
_AccessKey=res.Key;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await jsRt.InvokeVoidAsync("ui","#sb_error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
using Blazored.LocalStorage;
|
||||||
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
|
using TessesDedupWeb;
|
||||||
|
|
||||||
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||||
|
builder.RootComponents.Add<App>("#app");
|
||||||
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||||
|
HttpClient client = new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) };
|
||||||
|
builder.Services.AddScoped(sp => client );
|
||||||
|
builder.Services.AddBlazoredLocalStorage();
|
||||||
|
|
||||||
|
builder.Services.AddScoped(sp=>new DedupClient(client));
|
||||||
|
|
||||||
|
await builder.Build().RunAsync();
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"iisSettings": {
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:35148",
|
||||||
|
"sslPort": 44359
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||||
|
"applicationUrl": "http://localhost:5286",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||||
|
"applicationUrl": "https://localhost:7166;http://localhost:5286",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,263 @@
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using TessesDedupWeb;
|
||||||
|
using Tesses.VirtualFilesystem;
|
||||||
|
public class DedupClient
|
||||||
|
{
|
||||||
|
public DedupClient(HttpClient client)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string DataPath=>$"{(client.BaseAddress?.ToString() ?? "").TrimEnd('/')}/data/";
|
||||||
|
HttpClient client;
|
||||||
|
|
||||||
|
public async Task<bool> IsRegisteredAsync()
|
||||||
|
{
|
||||||
|
return await client.GetStringAsync("/api/v1/Registered") == "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Stats> GetStatsAsync(string key)
|
||||||
|
{
|
||||||
|
//"blocks":0,"bytes":0,"backups":0,"label":"0 bytes"
|
||||||
|
|
||||||
|
|
||||||
|
var res= await client.GetFromJsonAsync<Stats>($"/api/v1/Stats?access_key={WebUtility.UrlEncode(key)}");
|
||||||
|
if(res != null) return res;
|
||||||
|
|
||||||
|
return new Stats();
|
||||||
|
|
||||||
|
}
|
||||||
|
public async Task LogoutAsync(string key)
|
||||||
|
{
|
||||||
|
Dictionary<string,string> dictionary= new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "access_key", key }
|
||||||
|
};
|
||||||
|
|
||||||
|
FormUrlEncodedContent formUrlEncodedContent=new FormUrlEncodedContent(dictionary);
|
||||||
|
using(var resp=await client.PostAsync("/api/v1/Logout",formUrlEncodedContent))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<AccessKeyDeleteReason> AccessKeyDeleteAsync(string key, long id)
|
||||||
|
{
|
||||||
|
var res= await client.DeleteFromJsonAsync<AccessKeyDeleteReason>($"/api/v1/AccessKey?id={id}&access_key={WebUtility.UrlEncode(key)}");
|
||||||
|
return res ?? new AccessKeyDeleteReason();
|
||||||
|
}
|
||||||
|
public async IAsyncEnumerable<AccessKey> GetAccessKeysAsync(string key)
|
||||||
|
{
|
||||||
|
var res= await client.GetFromJsonAsync<List<AccessKey>>($"/api/v1/AccessKey?access_key={WebUtility.UrlEncode(key)}");
|
||||||
|
if(res != null) {
|
||||||
|
foreach(var item in res)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<Backup> GetBackupAsync(string key,long id)
|
||||||
|
{
|
||||||
|
var res= await client.GetFromJsonAsync<Backup>($"/api/v1/Backup?id={id}&access_key={WebUtility.UrlEncode(key)}&noHashes=true");
|
||||||
|
return res ?? new Backup();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async IAsyncEnumerable<Backup> GetBackupsAsync(string key)
|
||||||
|
{
|
||||||
|
var res= await client.GetFromJsonAsync<List<Backup>>($"/api/v1/Backup?access_key={WebUtility.UrlEncode(key)}");
|
||||||
|
if(res != null) {
|
||||||
|
foreach(var item in res)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public async Task<LoginResult> LoginAsync(string username,string password, string device_name)
|
||||||
|
{
|
||||||
|
Dictionary<string,string> dictionary= new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "username", username },
|
||||||
|
{ "password", password },
|
||||||
|
{ "device_name", device_name }
|
||||||
|
};
|
||||||
|
|
||||||
|
FormUrlEncodedContent formUrlEncodedContent=new FormUrlEncodedContent(dictionary);
|
||||||
|
using(var resp=await client.PostAsync("/api/v1/Login",formUrlEncodedContent))
|
||||||
|
{
|
||||||
|
if(resp.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return await resp.Content.ReadFromJsonAsync<LoginResult>() ?? new LoginResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new LoginResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AccessKeyDeleteReason
|
||||||
|
{
|
||||||
|
[JsonPropertyName("success")]
|
||||||
|
public bool Success {get;set;}=false;
|
||||||
|
[JsonPropertyName("reason")]
|
||||||
|
public string Reason {get;set;}="The response was null";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AccessKey
|
||||||
|
{
|
||||||
|
[JsonPropertyName("creation_date")]
|
||||||
|
public DateTime Created {get;set;}
|
||||||
|
[JsonPropertyName("id")]
|
||||||
|
public long Id {get;set;}
|
||||||
|
|
||||||
|
|
||||||
|
[JsonPropertyName("device_name")]
|
||||||
|
public string DeviceName {get;set;}="";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Stats
|
||||||
|
{
|
||||||
|
[JsonPropertyName("blocks")]
|
||||||
|
public long Blocks {get;set;}=0;
|
||||||
|
|
||||||
|
[JsonPropertyName("bytes")]
|
||||||
|
public long Bytes {get;set;}=0;
|
||||||
|
|
||||||
|
[JsonPropertyName("backups")]
|
||||||
|
public long Backups {get;set;}=0;
|
||||||
|
|
||||||
|
[JsonPropertyName("label")]
|
||||||
|
public string Label {get;set;}="";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LoginResult
|
||||||
|
{
|
||||||
|
[JsonPropertyName("success")]
|
||||||
|
public bool Success {get;set;}=false;
|
||||||
|
|
||||||
|
[JsonPropertyName("key")]
|
||||||
|
public string Key {get;set;}="";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Backup
|
||||||
|
{
|
||||||
|
[JsonPropertyName("id")]
|
||||||
|
public long Id {get;set;}
|
||||||
|
[JsonPropertyName("account_id")]
|
||||||
|
public long AccountId {get;set;}
|
||||||
|
[JsonPropertyName("root")]
|
||||||
|
public FilesystemEntry? Root {get;set;}
|
||||||
|
[JsonPropertyName("device_name")]
|
||||||
|
public string DeviceName {get;set;}="";
|
||||||
|
[JsonPropertyName("tag")]
|
||||||
|
public string Tag {get;set;}="";
|
||||||
|
[JsonPropertyName("creation_date")]
|
||||||
|
|
||||||
|
public DateTime CreationDate {get;set;}
|
||||||
|
|
||||||
|
|
||||||
|
public Backup WithoutRoot()
|
||||||
|
{
|
||||||
|
Backup b=new Backup();
|
||||||
|
b.AccountId = AccountId;
|
||||||
|
b.Id = Id;
|
||||||
|
b.CreationDate = CreationDate;
|
||||||
|
b.DeviceName = DeviceName;
|
||||||
|
b.Tag = Tag;
|
||||||
|
b.Root=null;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilesystemEntry GetEntryFromPath(UnixPath path)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(path.Path == "/" || path.Path.Length == 0) return Root ?? new FilesystemEntry();
|
||||||
|
|
||||||
|
var gefp=GetEntryFromPath(path.Parent);
|
||||||
|
|
||||||
|
if(gefp.Type != "dir") throw new DirectoryNotFoundException(path.Parent.Path);
|
||||||
|
|
||||||
|
foreach(var item in gefp.Entries)
|
||||||
|
{
|
||||||
|
if(item.Name == path.Name)
|
||||||
|
{
|
||||||
|
switch(item.Type)
|
||||||
|
{
|
||||||
|
case "dir":
|
||||||
|
case "file":
|
||||||
|
return item;
|
||||||
|
case "symlink":
|
||||||
|
{
|
||||||
|
if(item.PointsTo.StartsWith("/"))
|
||||||
|
{
|
||||||
|
UnixPath _path = path.Parent;
|
||||||
|
foreach(var _item in item.PointsTo.Split('/'))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(_item == "..")
|
||||||
|
{
|
||||||
|
_path = _path.Parent;
|
||||||
|
}
|
||||||
|
else if(_item != ".")
|
||||||
|
{
|
||||||
|
_path /= _item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GetEntryFromPath(_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UnixPath _path = Special.Root;
|
||||||
|
foreach(var _item in item.PointsTo.Split('/'))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(_item == "..")
|
||||||
|
{
|
||||||
|
_path = _path.Parent;
|
||||||
|
}
|
||||||
|
else if(_item != ".")
|
||||||
|
{
|
||||||
|
_path /= _item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GetEntryFromPath(_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new FileNotFoundException(path.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FilesystemEntry
|
||||||
|
{
|
||||||
|
[JsonPropertyName("name")]
|
||||||
|
public string Name {get;set;}="";
|
||||||
|
|
||||||
|
[JsonPropertyName("type")]
|
||||||
|
|
||||||
|
|
||||||
|
public string Type {get;set;}="";
|
||||||
|
|
||||||
|
[JsonPropertyName("entries")]
|
||||||
|
public List<FilesystemEntry> Entries {get;set;}=new List<FilesystemEntry>();
|
||||||
|
|
||||||
|
[JsonPropertyName("hashes")]
|
||||||
|
public List<string> Hashes {get;set;}=new List<string>();
|
||||||
|
[JsonPropertyName("length")]
|
||||||
|
public long Length {get;set;}
|
||||||
|
|
||||||
|
[JsonPropertyName("points_to")]
|
||||||
|
public string PointsTo {get;set;}="";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
|
||||||
|
<PackageReference Include="Humanizer" Version="2.14.1" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Tesses.VirtualFilesystem.Base" Version="1.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,11 @@
|
||||||
|
@using System.Net.Http
|
||||||
|
@using System.Net.Http.Json
|
||||||
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
|
@using Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||||
|
@using Microsoft.JSInterop
|
||||||
|
@using TessesDedupWeb
|
||||||
|
@using Humanizer
|
||||||
|
@using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
@using System.Net
|
||||||
|
@using Tesses.VirtualFilesystem;
|
|
@ -0,0 +1,32 @@
|
||||||
|
h1:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#blazor-error-ui {
|
||||||
|
background: lightyellow;
|
||||||
|
bottom: 0;
|
||||||
|
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
|
||||||
|
display: none;
|
||||||
|
left: 0;
|
||||||
|
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#blazor-error-ui .dismiss {
|
||||||
|
cursor: pointer;
|
||||||
|
position: absolute;
|
||||||
|
right: 0.75rem;
|
||||||
|
top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blazor-error-boundary {
|
||||||
|
background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
|
||||||
|
padding: 1rem 1rem 1rem 3.7rem;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blazor-error-boundary::after {
|
||||||
|
content: "An error has occurred."
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,27 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Tesses Dedup</title>
|
||||||
|
<base href="/" />
|
||||||
|
<link rel="stylesheet" href="css/app.css">
|
||||||
|
<link href="css/beer.min.css" rel="stylesheet" />
|
||||||
|
|
||||||
|
<!-- If you add any scoped CSS files, uncomment the following to load them
|
||||||
|
<link href="TessesDedupWeb.styles.css" rel="stylesheet" /> -->
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app">Loading...</div>
|
||||||
|
|
||||||
|
<div id="blazor-error-ui">
|
||||||
|
An unhandled error has occurred.
|
||||||
|
<a href="" class="reload">Reload</a> or <a href="/access_keys">Logout</a>
|
||||||
|
<a class="dismiss">🗙</a>
|
||||||
|
</div>
|
||||||
|
<script src="_framework/blazor.webassembly.js"></script>
|
||||||
|
<script src="js/beer.min.js" type="module"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue