├── .dockerignore ├── .gitattributes ├── .github └── workflows │ ├── ci.yml │ ├── codeql-analysis.yml │ └── release.yml ├── .gitignore ├── LICENSE ├── dpp.opentakrouter.Tests ├── UnitTest1.cs └── dpp.opentakrouter.Tests.csproj ├── dpp.opentakrouter ├── ClientRepository.cs ├── Controllers │ ├── EventsController.cs │ ├── HealthcheckController.cs │ ├── HomeController.cs │ └── MartiController.cs ├── DataPackageRepository.cs ├── DatabaseContext.cs ├── Dockerfile ├── IClientRepository.cs ├── IDataPackageRepository.cs ├── IDatabaseContext.cs ├── IMessageRepository.cs ├── IRouter.cs ├── MessageRepository.cs ├── Models │ ├── Client.cs │ ├── DataPackage.cs │ ├── ErrorViewModel.cs │ └── StoredMessage.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Router.cs ├── TakPeerConfig.cs ├── TakServerConfig.cs ├── TakService.cs ├── TakTcpPeer.cs ├── TakTcpServer.cs ├── TakTcpSession.cs ├── TakTlsServer.cs ├── TakTlsSession.cs ├── TakWsServer.cs ├── TakWsSession.cs ├── TakWssServer.cs ├── TakWssSession.cs ├── Views │ ├── Home │ │ ├── Clients.cshtml │ │ ├── DataPackages.cshtml │ │ ├── Index.cshtml │ │ └── Map.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ ├── _MainNavigation.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml ├── WebConfig.cs ├── WebService.cs ├── dpp.opentakrouter.csproj ├── libman.json ├── opentakrouter.json └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ └── js │ └── site.js ├── opentakrouter.sln ├── readme.md └── scripts ├── build-linux.sh └── release.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Setup .NET 18 | uses: actions/setup-dotnet@v1 19 | with: 20 | dotnet-version: 6.0.x 21 | 22 | - name: Restore dependencies 23 | run: dotnet restore 24 | 25 | - name: Build 26 | run: dotnet build dpp.opentakrouter -r linux-x64 27 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '35 21 * * 0' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'csharp' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v1 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v1 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v1 71 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v1 18 | with: 19 | dotnet-version: '6.0.x' 20 | 21 | - name: Release 22 | run: scripts/release.sh 23 | shell: bash 24 | 25 | - name: Upload binaries to release 26 | uses: svenstaro/upload-release-action@v2 27 | with: 28 | repo_token: ${{ secrets.GITHUB_TOKEN }} 29 | file: dist/* 30 | tag: ${{ github.ref }} 31 | overwrite: true 32 | file_glob: true 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | 365 | # dist 366 | dist/ 367 | 368 | # client libraries 369 | dpp.opentakrouter/wwwroot/lib/ 370 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 darkplusplus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /dpp.opentakrouter.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace dpp.opentakrouter.Tests 4 | { 5 | public class UnitTest1 6 | { 7 | [Fact] 8 | public void Test1() 9 | { 10 | 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dpp.opentakrouter.Tests/dpp.opentakrouter.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | all 15 | 16 | 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | all 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dpp.opentakrouter/ClientRepository.cs: -------------------------------------------------------------------------------- 1 | using dpp.opentakrouter.Models; 2 | using SQLite; 3 | using System.Collections.Generic; 4 | 5 | namespace dpp.opentakrouter 6 | { 7 | public class ClientRepository : IClientRepository 8 | { 9 | private readonly IDatabaseContext _context; 10 | private readonly SQLiteConnection _db; 11 | 12 | public ClientRepository(IDatabaseContext context) 13 | { 14 | _context = context; 15 | _db = _context.Database; 16 | _db.CreateTable(); 17 | } 18 | 19 | public int Add(Client c) 20 | { 21 | return _db.Insert(c); 22 | } 23 | 24 | public int Delete(string q) 25 | { 26 | var c = Get(q); 27 | return _db.Delete(c); 28 | } 29 | 30 | public Client Get(string callsign) 31 | { 32 | return _db.Table().Where(c => c.Callsign == callsign).FirstOrDefault(); 33 | } 34 | 35 | public IEnumerable Search(string query = "") 36 | { 37 | // TODO: clean up how client data is enumerated 38 | return _db.Table().Where(c => c.Callsign == c.Callsign); 39 | } 40 | 41 | public int Update(Client c) 42 | { 43 | return _db.Update(c); 44 | } 45 | 46 | public int Upsert(Client c) 47 | { 48 | var e = Get(c.Callsign); 49 | if (e is null) 50 | { 51 | return Add(c); 52 | } 53 | 54 | return Update(e); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Controllers/EventsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using System.IO; 5 | using System.Net.Mime; 6 | 7 | namespace dpp.opentakrouter.Controllers 8 | { 9 | [ApiController] 10 | [Route("[controller]")] 11 | public class EventsController : ControllerBase 12 | { 13 | private readonly ILogger _logger; 14 | private readonly IRouter _router; 15 | 16 | public EventsController(ILogger logger, IRouter router) 17 | { 18 | _logger = logger; 19 | _router = router; 20 | } 21 | 22 | [Route("/api/events")] 23 | [HttpPost] 24 | [Consumes(MediaTypeNames.Application.Xml)] 25 | [ProducesResponseType(StatusCodes.Status200OK)] 26 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 27 | public IActionResult SubmitEvent() 28 | { 29 | try 30 | { 31 | using (var sr = new StreamReader(Request.BodyReader.AsStream())) 32 | { 33 | var data = sr.ReadToEnd(); 34 | var evt = cot.Event.Parse(data); 35 | _router.Send(evt, null); 36 | } 37 | } 38 | catch 39 | { 40 | return BadRequest(); 41 | } 42 | 43 | return Ok(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/Controllers/HealthcheckController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System.Collections.Generic; 4 | 5 | namespace dpp.opentakrouter.Controllers 6 | { 7 | [ApiController] 8 | [Route("[controller]")] 9 | public class HealthcheckController : ControllerBase 10 | { 11 | private readonly ILogger _logger; 12 | 13 | public HealthcheckController(ILogger logger) 14 | { 15 | _logger = logger; 16 | } 17 | 18 | [HttpGet] 19 | public object Get() 20 | { 21 | return new Dictionary() 22 | { 23 | { "status", "ok" }, 24 | }; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using dpp.opentakrouter.Models; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.Extensions.Logging; 6 | using System.Diagnostics; 7 | using System.Linq; 8 | 9 | namespace dpp.opentakrouter.Controllers 10 | { 11 | [ApiExplorerSettings(IgnoreApi = true)] 12 | public class HomeController : Controller 13 | { 14 | private readonly ILogger _logger; 15 | private readonly IClientRepository _clients; 16 | private readonly IMessageRepository _messages; 17 | private readonly IDataPackageRepository _datapackages; 18 | private readonly IConfiguration _configuration; 19 | 20 | public HomeController(ILogger logger, IDataPackageRepository datapackages, IClientRepository clients, IMessageRepository messages, IConfiguration configuration) 21 | { 22 | _logger = logger; 23 | _clients = clients; 24 | _messages = messages; 25 | _datapackages = datapackages; 26 | _configuration = configuration; 27 | } 28 | 29 | [Route("/")] 30 | [HttpGet] 31 | public IActionResult Index() 32 | { 33 | return View(); 34 | } 35 | 36 | [Route("/map")] 37 | [HttpGet] 38 | public IActionResult Map() 39 | { 40 | ViewData.Add("ws-port", _configuration["server:websockets:port"] ?? "5000"); 41 | return View(); 42 | } 43 | 44 | [Route("/clients")] 45 | [HttpGet] 46 | public IActionResult Clients() 47 | { 48 | ViewData.Add("clients", _clients.Search().OrderBy(c => c.LastSeen)); 49 | 50 | return View(); 51 | } 52 | 53 | [Route("/datapackages")] 54 | [HttpGet] 55 | public IActionResult DataPackages() 56 | { 57 | ViewData.Add("datapackages", _datapackages.Search().OrderBy(dp => dp.SubmissionDateTime)); 58 | 59 | return View(); 60 | } 61 | 62 | 63 | [HttpGet] 64 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 65 | public IActionResult Error() 66 | { 67 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Controllers/MartiController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Net; 7 | using System.Reflection; 8 | 9 | namespace dpp.opentakrouter.Controllers 10 | { 11 | [ApiController] 12 | [Route("[controller]")] 13 | public class MartiController : ControllerBase 14 | { 15 | private readonly ILogger _logger; 16 | private readonly IConfiguration _configuration; 17 | private readonly IDataPackageRepository _datapackages; 18 | 19 | private readonly string _endpoint = "localhost"; 20 | private readonly int _port = 8080; 21 | 22 | public MartiController(ILogger logger, IConfiguration configuration, IDataPackageRepository datapackages) 23 | { 24 | _logger = logger; 25 | _configuration = configuration; 26 | _datapackages = datapackages; 27 | 28 | _endpoint = _configuration.GetValue("server:web:endpoint", Dns.GetHostName()); 29 | _port = _configuration.GetValue("server:web:port", 8080); 30 | } 31 | 32 | [Route("/Marti/api/clientEndPoints")] 33 | [HttpGet] 34 | public object ClientEndpoints() 35 | { 36 | // TODO: Figure out mgmt context to keep track of client endpoints 37 | /* 38 | var endpoint = new Dictionary() 39 | { 40 | { "lastEventTime", "2020-01-31T15:30:00.000Z" }, 41 | { "lastStatus", "Connected" }, 42 | { "uid", "asdf" }, 43 | { "callsign": "GOOSE" }, 44 | } 45 | */ 46 | 47 | return new Dictionary() 48 | { 49 | { "Matcher", "com.bbn.marti.remote.ClientEndpoint" }, 50 | { "BaseUrl", "" }, 51 | { "ServerConnectionString", _configuration.GetValue("server:public_endpoint", "") }, 52 | { "NotificationId", "" }, 53 | { "type", "com.bbn.marti.remote.ClientEndpoint" }, 54 | { "data", new List() }, 55 | }; 56 | } 57 | 58 | [Route("/Marti/api/version")] 59 | [HttpGet] 60 | public string Version() 61 | { 62 | var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); 63 | return $"opentakrouter-{version}"; 64 | } 65 | 66 | [Route("/Marti/api/version/config")] 67 | [HttpGet] 68 | public object VersionConfig() 69 | { 70 | var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); 71 | var hostname = _configuration.GetValue("server:endpoint", Dns.GetHostName()); 72 | var node_id = _configuration.GetValue("server:id", Dns.GetHostName()); 73 | 74 | return new Dictionary() 75 | { 76 | { "version", "2" }, 77 | { "type", "ServerConfig" }, 78 | { "data", new Dictionary(){ 79 | { "version", $"opentakrouter-{version}" }, 80 | { "api", "2" }, 81 | { "hostname", hostname }, 82 | }}, 83 | { "nodeId", node_id }, 84 | }; 85 | } 86 | 87 | [Route("/Marti/sync/search")] 88 | [HttpGet] 89 | public object SearchDatapackages(string keywords = "", string tool = "") 90 | { 91 | if (string.IsNullOrEmpty(tool)) 92 | { 93 | // TODO: add logic for `tool` param to control package privacy 94 | } 95 | 96 | List> packages = new(); 97 | foreach (var dp in _datapackages.Search(keywords)) 98 | { 99 | packages.Add(new Dictionary() 100 | { 101 | { "UID", dp.UID }, 102 | { "Name", dp.Name }, 103 | { "Hash", dp.Hash }, 104 | { "PrimaryKey", dp.PrimaryKey }, 105 | { "SubmissionDateTime", $"{dp.SubmissionDateTime.ToUniversalTime():u}" }, 106 | { "SubmissionUser", dp.SubmissionUser }, 107 | { "CreatorUid", dp.CreatorUid }, 108 | { "Keywords", dp.Keywords }, 109 | { "MIMEType", dp.MIMEType }, 110 | { "Size", dp.Size }, 111 | { "Visibility", dp.IsPrivate ? "private" : "public" } 112 | }); 113 | } 114 | 115 | return new Dictionary() 116 | { 117 | { "resultCount", packages.Count }, 118 | { "results", packages } 119 | }; 120 | } 121 | 122 | [Route("/Marti/sync/content")] 123 | [HttpGet] 124 | public IActionResult GetDatapackage(string hash) 125 | { 126 | try 127 | { 128 | var dp = _datapackages.Get(hash); 129 | 130 | return new FileContentResult(dp.Content, dp.MIMEType) 131 | { 132 | FileDownloadName = dp.UID 133 | }; 134 | } 135 | catch 136 | { 137 | return NotFound(); 138 | } 139 | } 140 | 141 | [Route("/Marti/sync/missionupload")] 142 | [HttpPost, DisableRequestSizeLimit] 143 | public IActionResult UploadDatapackage(string hash, string filename, string creatorUid, string keywords = "missionpackage", string visibility = "private") 144 | { 145 | try 146 | { 147 | var user = Request.Headers.ContainsKey("X-USER") 148 | ? Request.Headers["X-USER"].ToString() 149 | : "Anonymous"; 150 | 151 | var file = Request.Form.Files[0]; 152 | 153 | _datapackages.Add(file, hash, filename, user, creatorUid, keywords, visibility); 154 | } 155 | catch (Exception e) 156 | { 157 | return StatusCode(500, $"{e.Message}"); 158 | } 159 | 160 | return Ok($"https://{_endpoint}:{_port}/Marti/sync/content?hash={hash}"); 161 | } 162 | 163 | [Route("/Marti/api/sync/metadata/{hash}/tool")] 164 | [HttpPut] 165 | public IActionResult UpdateDatapackageMetadata(string hash) 166 | { 167 | try 168 | { 169 | var dp = _datapackages.Get(hash); 170 | dp.IsPrivate = !Request.Body.ToString().Contains("public"); 171 | _datapackages.Update(dp); 172 | 173 | return Ok($"https://{_endpoint}:{_port}/Marti/sync/content?hash={hash}"); 174 | } 175 | catch 176 | { 177 | return NotFound(); 178 | } 179 | } 180 | 181 | [Route("/Marti/sync/missionquery")] 182 | [HttpGet] 183 | public IActionResult DatapackageExists(string hash) 184 | { 185 | try 186 | { 187 | var dp = _datapackages.Get(hash); 188 | if (dp is null) 189 | { 190 | return NotFound(); 191 | } 192 | 193 | 194 | 195 | return Ok($"https://{_endpoint}:{_port}/Marti/sync/content?hash={hash}"); 196 | } 197 | catch 198 | { 199 | return NotFound(); 200 | } 201 | 202 | } 203 | 204 | [Route("/Marti/TracksKML")] 205 | [HttpPost] 206 | public string TracksKml() 207 | { 208 | // TODO: Implement TracksKML (/Marti/TracksKML) 209 | return ""; 210 | } 211 | 212 | [Route("/Marti/ExportMissionKML")] 213 | [HttpPost] 214 | public string MissionKml() 215 | { 216 | // TODO: Implement this MissionKml (/Marti/ExportMissionKML) 217 | return ""; 218 | } 219 | 220 | [Route("/Marti/vcm")] 221 | [HttpPost] 222 | public string UploadVideo() 223 | { 224 | // TODO: Implement this UploadVideo (/Marti/vcm) 225 | return ""; 226 | } 227 | 228 | [Route("/Marti/vcm")] 229 | [HttpGet] 230 | public string ListVideos() 231 | { 232 | // TODO: Implement this ListVideos (/Marti/vcm) 233 | return ""; 234 | } 235 | } 236 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/DataPackageRepository.cs: -------------------------------------------------------------------------------- 1 | using dpp.opentakrouter.Models; 2 | using Microsoft.AspNetCore.Http; 3 | using SQLite; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | 8 | namespace dpp.opentakrouter 9 | { 10 | public class DataPackageRepository : IDataPackageRepository 11 | { 12 | private readonly IDatabaseContext _context; 13 | private readonly SQLiteConnection _db; 14 | 15 | public DataPackageRepository(IDatabaseContext context) 16 | { 17 | _context = context; 18 | _db = _context.Database; 19 | _db.CreateTable(); 20 | } 21 | 22 | public int Add(DataPackage datapackage) 23 | { 24 | return _db.Insert(datapackage); 25 | } 26 | 27 | public int Add(IFormFile file, string hash, string filename, string submissionUser = "Anonymous", string creatorUid = "Anonymous", string keywords = "missionpackage", string visibility = "private") 28 | { 29 | // TODO: compute the SHA256 hash if it's null 30 | 31 | var name = Path.GetFileNameWithoutExtension(file.FileName); 32 | var isPrivate = visibility.Equals("private"); 33 | 34 | byte[] content; 35 | using (var ms = new MemoryStream()) 36 | { 37 | file.CopyTo(ms); 38 | content = ms.ToArray(); 39 | } 40 | 41 | var dp = new DataPackage() 42 | { 43 | UID = filename, 44 | Name = name, 45 | Hash = hash, 46 | SubmissionDateTime = DateTime.Now, 47 | SubmissionUser = submissionUser, 48 | CreatorUid = creatorUid, 49 | Keywords = keywords, 50 | MIMEType = file.ContentType, 51 | Size = file.Length, 52 | IsPrivate = isPrivate, 53 | Content = content, 54 | }; 55 | 56 | return Add(dp); 57 | } 58 | 59 | public int Delete(string hash) 60 | { 61 | return _db.Table().Where(dp => dp.Hash == hash).Delete(); 62 | } 63 | 64 | public DataPackage Get(string hash) 65 | { 66 | return _db.Table().Where(dp => dp.Hash == hash).First(); 67 | } 68 | 69 | public IEnumerable Search(string keywords = "") 70 | { 71 | return _db.Table().Where(dp => dp.Keywords.Contains(keywords)); 72 | } 73 | 74 | public int Update(DataPackage dp) 75 | { 76 | return _db.Update(dp); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /dpp.opentakrouter/DatabaseContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using SQLite; 3 | using System; 4 | using System.IO; 5 | 6 | namespace dpp.opentakrouter 7 | { 8 | public class DatabaseContext : IDatabaseContext 9 | { 10 | public SQLiteConnection Database { get; set; } 11 | private readonly IConfiguration _configuration; 12 | 13 | public DatabaseContext(IConfiguration configuration) 14 | { 15 | _configuration = configuration; 16 | 17 | var dataDir = Environment.ExpandEnvironmentVariables( 18 | _configuration.GetValue("server:data", System.AppContext.BaseDirectory) 19 | ); 20 | var dbPath = Path.Combine(dataDir, "opentakrouter.db"); 21 | var options = new SQLiteConnectionString( 22 | dbPath, 23 | SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.FullMutex, 24 | true, 25 | null, null, null, null); 26 | 27 | Database = new SQLiteConnection(options); 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Dockerfile: -------------------------------------------------------------------------------- 1 | #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base 4 | WORKDIR /app 5 | 6 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build 7 | WORKDIR /src 8 | COPY ["dpp.opentakrouter/dpp.opentakrouter.csproj", "dpp.opentakrouter/"] 9 | RUN dotnet restore "dpp.opentakrouter/dpp.opentakrouter.csproj" 10 | COPY . . 11 | WORKDIR "/src/dpp.opentakrouter" 12 | RUN dotnet build "dpp.opentakrouter.csproj" -c Release -o /app/build --self-contained --runtime linux-64 13 | 14 | FROM build AS publish 15 | RUN dotnet publish "dpp.opentakrouter.csproj" -c Release -o /app/publish --self-contained --runtime linux-64 16 | 17 | FROM base AS final 18 | WORKDIR /app 19 | COPY --from=publish /app/publish . 20 | ENTRYPOINT ["dotnet", "opentakrouter.dll"] -------------------------------------------------------------------------------- /dpp.opentakrouter/IClientRepository.cs: -------------------------------------------------------------------------------- 1 | using dpp.opentakrouter.Models; 2 | using System.Collections.Generic; 3 | 4 | namespace dpp.opentakrouter 5 | { 6 | public interface IClientRepository 7 | { 8 | public IEnumerable Search(string query = ""); 9 | public Client Get(string callsign); 10 | public int Add(Client c); 11 | public int Update(Client c); 12 | public int Delete(string c); 13 | public int Upsert(Client c); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dpp.opentakrouter/IDataPackageRepository.cs: -------------------------------------------------------------------------------- 1 | using dpp.opentakrouter.Models; 2 | using Microsoft.AspNetCore.Http; 3 | using System.Collections.Generic; 4 | 5 | namespace dpp.opentakrouter 6 | { 7 | public interface IDataPackageRepository 8 | { 9 | public IEnumerable Search(string keywords = ""); 10 | public DataPackage Get(string hash); 11 | public int Add(DataPackage dp); 12 | public int Add(IFormFile file, string hash, string filename, string submissionUser = "Anonymous", string creatorUid = "Anonymous", string keywords = "missionpackage", string visibility = "private"); 13 | public int Update(DataPackage dp); 14 | public int Delete(string hash); 15 | } 16 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/IDatabaseContext.cs: -------------------------------------------------------------------------------- 1 | using SQLite; 2 | 3 | namespace dpp.opentakrouter 4 | { 5 | public interface IDatabaseContext 6 | { 7 | public SQLiteConnection Database { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /dpp.opentakrouter/IMessageRepository.cs: -------------------------------------------------------------------------------- 1 | using dpp.opentakrouter.Models; 2 | using System.Collections.Generic; 3 | 4 | namespace dpp.opentakrouter 5 | { 6 | public interface IMessageRepository 7 | { 8 | public IEnumerable Search(string keywords = ""); 9 | public StoredMessage Get(string UID); 10 | public int Add(StoredMessage msg); 11 | 12 | public int Upsert(StoredMessage msg); 13 | public int Update(StoredMessage msg); 14 | public int Delete(string UID); 15 | public int EvictExpired(); 16 | IEnumerable GetActive(); 17 | } 18 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/IRouter.cs: -------------------------------------------------------------------------------- 1 | using dpp.cot; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dpp.opentakrouter 6 | { 7 | public interface IRouter 8 | { 9 | public event EventHandler RaiseRoutedEvent; 10 | public void Send(Event e, byte[] data); 11 | IEnumerable GetActiveEvents(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dpp.opentakrouter/MessageRepository.cs: -------------------------------------------------------------------------------- 1 | using dpp.opentakrouter.Models; 2 | using SQLite; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace dpp.opentakrouter 7 | { 8 | public class MessageRepository : IMessageRepository 9 | { 10 | private readonly IDatabaseContext _context; 11 | private readonly SQLiteConnection _db; 12 | 13 | public MessageRepository(IDatabaseContext context) 14 | { 15 | _context = context; 16 | _db = _context.Database; 17 | _db.CreateTable(); 18 | 19 | EvictExpired(); 20 | } 21 | 22 | public int Add(StoredMessage msg) 23 | { 24 | _db.BeginTransaction(); 25 | var r = _db.Insert(msg); 26 | _db.Commit(); 27 | 28 | return r; 29 | } 30 | 31 | public int Delete(string q) 32 | { 33 | var m = Get(q); 34 | return _db.Delete(m); 35 | } 36 | 37 | public StoredMessage Get(string UID) 38 | { 39 | return _db.Table().Where(m => m.Uid == UID).FirstOrDefault(); 40 | } 41 | 42 | public IEnumerable Search(string query) 43 | { 44 | return _db.Table().Where(m => m.Data.Contains(query)); 45 | } 46 | 47 | public int Update(StoredMessage msg) 48 | { 49 | _db.BeginTransaction(); 50 | var r = _db.Update(msg); 51 | _db.Commit(); 52 | 53 | return r; 54 | } 55 | 56 | public int Upsert(StoredMessage m) 57 | { 58 | var e = Get(m.Uid); 59 | if (e is null) 60 | { 61 | return Add(m); 62 | } 63 | 64 | return Update(e); 65 | } 66 | 67 | public int EvictExpired() 68 | { 69 | return _db.Table().Where(m => m.Expiration < DateTime.Now).Delete(); 70 | } 71 | 72 | public IEnumerable GetActive() 73 | { 74 | return _db.Table().Where(m => m.Expiration >= DateTime.Now); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Models/Client.cs: -------------------------------------------------------------------------------- 1 | using SQLite; 2 | using System; 3 | 4 | namespace dpp.opentakrouter.Models 5 | { 6 | public class Client 7 | { 8 | [PrimaryKey, AutoIncrement] 9 | public int PrimaryKey { get; set; } 10 | public string Callsign { get; set; } 11 | public DateTime LastSeen { get; set; } 12 | public string Device { get; set; } 13 | public string Platform { get; set; } 14 | public string Version { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Models/DataPackage.cs: -------------------------------------------------------------------------------- 1 | using SQLite; 2 | using System; 3 | 4 | namespace dpp.opentakrouter.Models 5 | { 6 | public class DataPackage 7 | { 8 | [PrimaryKey, AutoIncrement] 9 | public int PrimaryKey { get; set; } 10 | public string UID { get; set; } 11 | public string Name { get; set; } 12 | public string Hash { get; set; } 13 | public DateTime SubmissionDateTime { get; set; } = DateTime.Now; 14 | public string SubmissionUser { get; set; } 15 | public string CreatorUid { get; set; } 16 | public string Keywords { get; set; } 17 | public string MIMEType { get; set; } 18 | public long Size { get; set; } 19 | public bool IsPrivate { get; set; } 20 | 21 | public byte[] Content { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace dpp.opentakrouter.Models 2 | { 3 | public class ErrorViewModel 4 | { 5 | public string RequestId { get; set; } 6 | 7 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Models/StoredMessage.cs: -------------------------------------------------------------------------------- 1 | using SQLite; 2 | using System; 3 | 4 | namespace dpp.opentakrouter.Models 5 | { 6 | public class StoredMessage 7 | { 8 | [PrimaryKey, AutoIncrement] 9 | public int PrimaryKey { get; set; } 10 | 11 | [Indexed] 12 | public string Uid { get; set; } 13 | public string Data { get; set; } 14 | public DateTime Timestamp { get; set; } = DateTime.Now; 15 | 16 | [Indexed] 17 | public DateTime Expiration { get; set; } = DateTime.Now.AddMinutes(5); 18 | 19 | [Ignore] 20 | public bool IsExpired { get { return DateTime.Now > Expiration; } } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Hosting; 5 | using Microsoft.Extensions.Logging; 6 | using Serilog; 7 | using Serilog.Events; 8 | using System; 9 | using System.Diagnostics; 10 | using System.IO; 11 | using System.Net; 12 | 13 | namespace dpp.opentakrouter 14 | { 15 | class Program 16 | { 17 | static IHostBuilder Initialize(string[] args) 18 | { 19 | var configuration = new ConfigurationBuilder() 20 | .SetBasePath(AppContext.BaseDirectory) 21 | .AddEnvironmentVariables() 22 | .AddCommandLine(args) 23 | .AddJsonFile("opentakrouter.json", optional: true) 24 | .Build(); 25 | 26 | var dataDir = Path.GetFullPath( 27 | configuration.GetValue("server:data", 28 | Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)) 29 | ); 30 | 31 | var logFile = Path.Combine(dataDir, "opentakrouter.log"); 32 | var flushInterval = new TimeSpan(0, 0, 1); 33 | 34 | Log.Logger = new LoggerConfiguration() 35 | .MinimumLevel.Debug() 36 | .MinimumLevel.Override("Microsoft", LogEventLevel.Information) 37 | .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) 38 | .Enrich.FromLogContext() 39 | .WriteTo.Console() 40 | .WriteTo.File( 41 | logFile, 42 | flushToDiskInterval: flushInterval, 43 | rollingInterval: RollingInterval.Day) 44 | .CreateBootstrapLogger(); 45 | 46 | return Host.CreateDefaultBuilder(args) 47 | .ConfigureAppConfiguration((context, builder) => 48 | { 49 | builder.Sources.Clear(); 50 | builder.AddConfiguration(configuration); 51 | }) 52 | .UseSerilog((context, services, configuration) => configuration 53 | .ReadFrom.Configuration(context.Configuration) 54 | .ReadFrom.Services(services) 55 | .MinimumLevel.Debug() 56 | .MinimumLevel.Override("Microsoft", LogEventLevel.Information) 57 | .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) 58 | .Enrich.FromLogContext() 59 | .WriteTo.Console() 60 | .WriteTo.File( 61 | logFile, 62 | flushToDiskInterval: flushInterval, 63 | rollingInterval: RollingInterval.Day)) 64 | .ConfigureServices((context, services) => 65 | { 66 | services.AddScoped(); 67 | services.AddScoped(); 68 | services.AddScoped(); 69 | services.AddScoped(); 70 | services.AddSingleton(); 71 | services.AddHostedService(); 72 | }) 73 | .ConfigureWebHostDefaults(builder => 74 | { 75 | builder.UseContentRoot(dataDir); 76 | builder.ConfigureKestrel((context, serverOptions) => 77 | { 78 | var apiConfig = configuration.GetSection("server:api").Get(); 79 | if (apiConfig is not null && apiConfig.Enabled) 80 | { 81 | if (apiConfig.Ssl) 82 | { 83 | serverOptions.Listen(IPAddress.Any, apiConfig.Port ?? 8443, listenOptions => 84 | { 85 | listenOptions.UseConnectionLogging(); 86 | listenOptions.UseHttps( 87 | apiConfig.Cert, 88 | apiConfig.Passphrase 89 | ); 90 | }); 91 | } 92 | else 93 | { 94 | serverOptions.Listen(IPAddress.Any, apiConfig.Port ?? 8080, listenOptions => 95 | { 96 | listenOptions.UseConnectionLogging(); 97 | }); 98 | } 99 | } 100 | }); 101 | builder.UseStartup(); 102 | }) 103 | .UseWindowsService() 104 | .UseSystemd(); 105 | 106 | } 107 | static async System.Threading.Tasks.Task Main(string[] args) 108 | { 109 | if (Environment.OSVersion.Platform == PlatformID.Win32NT) 110 | { 111 | if (Console.LargestWindowWidth != 0) 112 | { 113 | 114 | } 115 | } 116 | 117 | 118 | var hostBuilder = Initialize(args); 119 | 120 | await hostBuilder 121 | .Build() 122 | .RunAsync(); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "dpp.opentakrouter": { 4 | "commandName": "Project", 5 | "applicationUrl": "http://localhost:8080" 6 | }, 7 | "Docker": { 8 | "commandName": "Docker", 9 | "applicationUrl": "http://localhost:8080" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/Router.cs: -------------------------------------------------------------------------------- 1 | using dpp.cot; 2 | using dpp.opentakrouter.Models; 3 | using Microsoft.Extensions.Configuration; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace dpp.opentakrouter 8 | { 9 | public class Router : IRouter 10 | { 11 | private readonly IConfiguration _configuration; 12 | private readonly IClientRepository _clients; 13 | private readonly IMessageRepository _messages; 14 | 15 | private readonly bool _persistMessages; 16 | 17 | public Router(IConfiguration configuration, IClientRepository clients, IMessageRepository messages) 18 | { 19 | _configuration = configuration; 20 | _clients = clients; 21 | _messages = messages; 22 | 23 | _persistMessages = _configuration.GetValue("server:persist_messages", true); 24 | } 25 | 26 | public event EventHandler RaiseRoutedEvent; 27 | 28 | public IEnumerable GetActiveEvents() 29 | { 30 | List results = new(); 31 | 32 | foreach (var evt in _messages.GetActive()) 33 | { 34 | results.Add(Event.Parse(evt.Data)); 35 | } 36 | 37 | return results; 38 | } 39 | 40 | public void Send(Event e, byte[] data) 41 | { 42 | data ??= (new Message() { Event = e }).ToXmlBytes(); 43 | 44 | if (e.IsA(CotPredicates.t_ping)) 45 | { 46 | _clients.Upsert(new Client() 47 | { 48 | Callsign = e.Detail.Contact?.Callsign ?? "Unknown", 49 | LastSeen = e.Time, 50 | Device = e.Detail.Takv?.Device ?? "Unknown", 51 | Platform = e.Detail.Takv?.Platform ?? "Unknown", 52 | Version = e.Detail.Takv?.Version ?? "Unknown" 53 | }); 54 | 55 | return; 56 | } 57 | 58 | if (_persistMessages) 59 | { 60 | _messages.Upsert(new Models.StoredMessage() 61 | { 62 | Uid = e.Uid, 63 | Data = e.ToXmlString(), 64 | Timestamp = e.Time, 65 | Expiration = e.Stale 66 | }); 67 | } 68 | 69 | OnRaiseRoutedEvent(new RoutedEventArgs(e, data)); 70 | } 71 | 72 | protected virtual void OnRaiseRoutedEvent(RoutedEventArgs e) 73 | { 74 | RaiseRoutedEvent?.Invoke(this, e); 75 | } 76 | } 77 | 78 | public class RoutedEventArgs : EventArgs 79 | { 80 | public Event Event { get; set; } 81 | public byte[] Data { get; set; } 82 | public RoutedEventArgs(Event e, byte[] data) 83 | { 84 | Event = e; 85 | Data = data ?? (new Message() { Event = e }).ToXmlBytes(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakPeerConfig.cs: -------------------------------------------------------------------------------- 1 | namespace dpp.opentakrouter 2 | { 3 | public class TakPeerConfig 4 | { 5 | public string Name { get; set; } 6 | public string Address { get; set; } 7 | public int Port { get; set; } 8 | public bool Ssl { get; set; } = false; 9 | public string Mode { get; set; } = "duplex"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakServerConfig.cs: -------------------------------------------------------------------------------- 1 | namespace dpp.opentakrouter 2 | { 3 | public class TakServerConfig 4 | { 5 | public bool Enabled { get; set; } = false; 6 | public int Port { get; set; } 7 | public string Cert { get; set; } = ""; 8 | public string Passphrase { get; set; } = ""; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Microsoft.Extensions.Hosting; 3 | using NetCoreServer; 4 | using Serilog; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Net; 9 | using System.Net.Sockets; 10 | using System.Security.Authentication; 11 | using System.Security.Cryptography.X509Certificates; 12 | using System.Threading; 13 | using System.Threading.Tasks; 14 | 15 | namespace dpp.opentakrouter 16 | { 17 | public class TakService : IHostedService, IDisposable 18 | { 19 | private TakTcpServer _tcpServer = null; 20 | private TakTlsServer _tlsServer = null; 21 | private TakWsServer _wsServer = null; 22 | private TakWssServer _wssServer = null; 23 | private readonly List _tcpClients; 24 | private readonly IRouter router; 25 | private readonly IConfiguration configuration; 26 | public TakService(IConfiguration configuration, IRouter router) 27 | { 28 | this.configuration = configuration; 29 | this.router = router; 30 | _tcpClients = new List(); 31 | } 32 | 33 | public Task StartAsync(CancellationToken cancellationToken) 34 | { 35 | try 36 | { 37 | var tcpServerConfig = configuration.GetSection("server:tak:tcp").Get(); 38 | if (tcpServerConfig is not null && tcpServerConfig.Enabled) 39 | { 40 | _tcpServer = new TakTcpServer( 41 | IPAddress.Any, 42 | tcpServerConfig.Port, 43 | router: router); 44 | _tcpServer.Start(); 45 | Log.Information($"server=tak-tcp state=started port={tcpServerConfig.Port}"); 46 | } 47 | else 48 | { 49 | Log.Information("server=tak-tcp state=skipped"); 50 | } 51 | 52 | var tlsServerConfig = configuration.GetSection("server:tak:tls").Get(); 53 | if (tlsServerConfig is not null && tlsServerConfig.Enabled) 54 | { 55 | var sslContext = new SslContext(SslProtocols.Tls12, new X509Certificate( 56 | tlsServerConfig.Cert, 57 | tlsServerConfig.Passphrase) 58 | ); 59 | 60 | _tlsServer = new TakTlsServer( 61 | sslContext, 62 | IPAddress.Any, 63 | tlsServerConfig.Port, 64 | router: router); 65 | _tlsServer.Start(); 66 | Log.Information($"server=tak-ssl state=started port={tlsServerConfig.Port}"); 67 | } 68 | else 69 | { 70 | Log.Information("server=tak-ssl state=skipped"); 71 | } 72 | 73 | var websocketConfig = configuration.GetSection("server:websockets").Get(); 74 | if (websocketConfig is not null && websocketConfig.Enabled) 75 | { 76 | var port = websocketConfig.Port ?? 5500; 77 | if (websocketConfig.Ssl) 78 | { 79 | var sslContext = new SslContext(SslProtocols.Tls12, new X509Certificate( 80 | websocketConfig.Cert, 81 | websocketConfig.Passphrase) 82 | ); 83 | 84 | _wssServer = new TakWssServer(sslContext, IPAddress.Any, port, router); 85 | _wssServer.Start(); 86 | Log.Information($"server=wss state=started port={port}"); 87 | } 88 | else 89 | { 90 | _wsServer = new TakWsServer(IPAddress.Any, port, router); 91 | _wsServer.Start(); 92 | Log.Information($"server=ws state=started port={port}"); 93 | } 94 | } 95 | else 96 | { 97 | Log.Information("server=ws state=skipped"); 98 | Log.Information("server=wss state=skipped"); 99 | } 100 | 101 | var peerConfigs = configuration.GetSection("server:peers").Get>(); 102 | if (peerConfigs is not null) 103 | { 104 | foreach (var peerConfig in peerConfigs) 105 | { 106 | if (peerConfig.Ssl) 107 | { 108 | throw new NotImplementedException("Federation of SSL peers is not implemented yet"); 109 | } 110 | else 111 | { 112 | try 113 | { 114 | var address = Dns.GetHostEntry(peerConfig.Address) 115 | .AddressList.First(addr => addr.AddressFamily == AddressFamily.InterNetwork) 116 | .ToString(); 117 | 118 | var mode = (TakTcpPeer.Mode)Enum.Parse(typeof(TakTcpPeer.Mode), peerConfig.Mode, true); 119 | var client = new TakTcpPeer( 120 | peerConfig.Name, 121 | address, 122 | peerConfig.Port, 123 | router: router, 124 | mode: mode 125 | ); 126 | _tcpClients.Add(client); 127 | } 128 | catch (Exception e) 129 | { 130 | Log.Error($"peer={peerConfig.Name} error=true message=\"{e.Message}\""); 131 | continue; 132 | } 133 | } 134 | } 135 | 136 | foreach (var client in _tcpClients) 137 | { 138 | client.Connect(); 139 | } 140 | } 141 | } 142 | catch (Exception e) 143 | { 144 | Log.Error($"state=error error=true message=\"{e.Message}\""); 145 | System.Environment.Exit(2); 146 | } 147 | 148 | return Task.CompletedTask; 149 | } 150 | 151 | public Task StopAsync(CancellationToken cancellationToken) 152 | { 153 | Log.Information("state=stopping"); 154 | if (_tcpServer is not null) 155 | { 156 | _tcpServer.Stop(); 157 | } 158 | 159 | if (_tlsServer is not null) 160 | { 161 | _tlsServer.Stop(); 162 | } 163 | 164 | if (_wsServer is not null) 165 | { 166 | _tcpServer.Stop(); 167 | } 168 | 169 | if (_wssServer is not null) 170 | { 171 | _tlsServer.Stop(); 172 | } 173 | 174 | if (_tcpClients is not null) 175 | { 176 | foreach (var client in _tcpClients) 177 | { 178 | client.DisconnectAndStop(); 179 | } 180 | } 181 | 182 | return Task.CompletedTask; 183 | } 184 | 185 | public void Dispose() => GC.SuppressFinalize(this); 186 | } 187 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/TakTcpPeer.cs: -------------------------------------------------------------------------------- 1 | using dpp.cot; 2 | using Serilog; 3 | using System; 4 | using System.Net.Sockets; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Threading; 8 | using TcpClient = NetCoreServer.TcpClient; 9 | 10 | namespace dpp.opentakrouter 11 | { 12 | public class TakTcpPeer : TcpClient 13 | { 14 | public enum Mode 15 | { 16 | Receive, 17 | Transmit, 18 | Duplex 19 | } 20 | 21 | private readonly IRouter _router; 22 | private readonly Mode _clientMode; 23 | private readonly int _initialBackoff = 3000; 24 | private readonly int _maxBackoff = 300000; 25 | private int _backoff; 26 | private bool _stop; 27 | private readonly string _name; 28 | 29 | public TakTcpPeer(string name, string address, int port, IRouter router, Mode mode = Mode.Duplex, int minBackoff = 3000, int maxBackoff = 300000) : base(address, port) 30 | { 31 | _stop = false; 32 | _name = name; 33 | _clientMode = mode; 34 | _initialBackoff = minBackoff; 35 | _maxBackoff = maxBackoff; 36 | _backoff = _initialBackoff; 37 | 38 | _router = router; 39 | _router.RaiseRoutedEvent += OnRoutedEvent; 40 | } 41 | 42 | protected void OnRoutedEvent(object sender, RoutedEventArgs e) 43 | { 44 | if (_clientMode == Mode.Transmit || _clientMode == Mode.Duplex) 45 | { 46 | _ = Send(e.Data); 47 | } 48 | } 49 | 50 | protected override void OnConnecting() 51 | { 52 | Log.Information($"peer={_name} state=connecting"); 53 | } 54 | 55 | protected override void OnConnected() 56 | { 57 | Log.Information($"peer={_name} state=connected"); 58 | _backoff = _initialBackoff; 59 | 60 | foreach (var evt in _router.GetActiveEvents()) 61 | { 62 | SendAsync(evt.ToXmlString()); 63 | } 64 | } 65 | 66 | protected override void OnDisconnected() 67 | { 68 | Log.Information($"peer={_name} state=reconnecting backoff={_backoff}"); 69 | Thread.Sleep(_backoff); 70 | _backoff = Math.Clamp((int)Math.Round(_backoff * Math.E), _initialBackoff, _maxBackoff); 71 | 72 | if (!_stop) 73 | { 74 | ConnectAsync(); 75 | } 76 | } 77 | 78 | public void DisconnectAndStop() 79 | { 80 | _stop = true; 81 | DisconnectAsync(); 82 | while (IsConnected) 83 | { 84 | Thread.Yield(); 85 | } 86 | } 87 | 88 | protected override void OnError(SocketError error) 89 | { 90 | Log.Error($"peer={_name} error=true message=\"{error}\""); 91 | } 92 | 93 | protected override void OnReceived(byte[] buffer, long offset, long size) 94 | { 95 | if (_clientMode == Mode.Receive || _clientMode == Mode.Duplex) 96 | { 97 | try 98 | { 99 | var data = Encoding.UTF8.GetString(buffer); 100 | 101 | foreach (Match match in Regex.Matches(data, @"")) 102 | { 103 | try 104 | { 105 | var evt = Event.Parse(match.Value); 106 | Log.Information($"peer={_name} event=cot uid={evt.Uid} type={evt.Type}"); 107 | if (evt.IsA(CotPredicates.t_ping)) 108 | { 109 | SendAsync(Event.Pong(evt).ToXmlString()); 110 | return; 111 | } 112 | 113 | _router.Send(evt, buffer); 114 | } 115 | catch (OverflowException) 116 | { 117 | Log.Error($"peer={_name} type=unknown error=true forwarded=false message=\"Overflow error. Receiving too much data.\""); 118 | } 119 | catch (Exception e) 120 | { 121 | Log.Error($"peer={_name} type=unknown error=true forwarded=false message=\"{e.Message}\""); 122 | } 123 | } 124 | } 125 | catch (Exception e) 126 | { 127 | Log.Error($"peer={_name} type=unknown error=true forwarded=false message=\"{e.Message}\""); 128 | } 129 | } 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakTcpServer.cs: -------------------------------------------------------------------------------- 1 | using NetCoreServer; 2 | using Serilog; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace dpp.opentakrouter 7 | { 8 | public class TakTcpServer : TcpServer 9 | { 10 | public IRouter Router; 11 | 12 | public TakTcpServer(IPAddress address, int port, IRouter router) : base(address, port) 13 | { 14 | this.Router = router; 15 | this.Router.RaiseRoutedEvent += OnRoutedEvent; 16 | } 17 | 18 | protected override TcpSession CreateSession() 19 | { 20 | return new TakTcpSession(this); 21 | } 22 | 23 | protected void OnRoutedEvent(object sender, RoutedEventArgs e) 24 | { 25 | _ = this.Multicast(e.Data); 26 | } 27 | 28 | protected override void OnError(SocketError error) 29 | { 30 | Log.Error($"server=tak-tcp error=true message=\"{error}\""); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakTcpSession.cs: -------------------------------------------------------------------------------- 1 | using dpp.cot; 2 | using NetCoreServer; 3 | using Serilog; 4 | using System; 5 | using System.Net.Sockets; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace dpp.opentakrouter 10 | { 11 | public class TakTcpSession : TcpSession 12 | { 13 | private readonly IRouter _router; 14 | private const string _component = "tak-tcp"; 15 | public TakTcpSession(TakTcpServer server) : base(server) 16 | { 17 | _router = server.Router; 18 | } 19 | protected override void OnConnected() 20 | { 21 | Log.Information($"server=tak-tcp endpoint={Socket.RemoteEndPoint} session={Id} state=connected"); 22 | foreach (var evt in _router.GetActiveEvents()) 23 | { 24 | SendAsync(evt.ToXmlString()); 25 | } 26 | } 27 | 28 | protected override void OnDisconnected() 29 | { 30 | Log.Information($"server=tak-tcp session={Id} state=disconnected"); 31 | } 32 | protected override void OnReceived(byte[] buffer, long offset, long size) 33 | { 34 | try 35 | { 36 | var data = Encoding.UTF8.GetString(buffer); 37 | 38 | foreach (Match match in Regex.Matches(data, @"")) 39 | { 40 | try 41 | { 42 | var evt = Event.Parse(match.Value); 43 | Log.Information($"server={_component} endpoint={Socket.RemoteEndPoint} session={Id} event=cot uid={evt.Uid} type={evt.Type}"); 44 | if (evt.IsA(CotPredicates.t_ping)) 45 | { 46 | SendAsync(Event.Pong(evt).ToXmlString()); 47 | return; 48 | } 49 | 50 | _router.Send(evt, buffer); 51 | } 52 | catch (OverflowException) 53 | { 54 | Log.Error($"server={_component} endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"Overflow error. Receiving too much data.\""); 55 | 56 | // TODO: no real backoff control. kill connection? 57 | } 58 | catch (Exception e) 59 | { 60 | Log.Error($"server={_component} endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 61 | } 62 | } 63 | } 64 | catch (Exception e) 65 | { 66 | Log.Error($"server={_component} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 67 | } 68 | } 69 | 70 | protected override void OnError(SocketError error) 71 | { 72 | Log.Error($"server=tak-tcp endpoint={Socket.RemoteEndPoint} session={Id} error=true message=\"{error}\""); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakTlsServer.cs: -------------------------------------------------------------------------------- 1 | using NetCoreServer; 2 | using Serilog; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace dpp.opentakrouter 7 | { 8 | public class TakTlsServer : SslServer 9 | { 10 | public IRouter Router; 11 | 12 | public TakTlsServer(SslContext context, IPAddress address, int port, IRouter router) : base(context, address, port) 13 | { 14 | this.Router = router; 15 | this.Router.RaiseRoutedEvent += OnRoutedEvent; 16 | } 17 | 18 | protected override SslSession CreateSession() 19 | { 20 | return new TakTlsSession(this); 21 | } 22 | 23 | protected void OnRoutedEvent(object sender, RoutedEventArgs e) 24 | { 25 | _ = this.Multicast(e.Data); 26 | } 27 | 28 | protected override void OnError(SocketError error) 29 | { 30 | Log.Error($"server=tak-ssl error=true message=\"{error}\""); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakTlsSession.cs: -------------------------------------------------------------------------------- 1 | using dpp.cot; 2 | using NetCoreServer; 3 | using Serilog; 4 | using System; 5 | using System.Net.Sockets; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace dpp.opentakrouter 10 | { 11 | public class TakTlsSession : SslSession 12 | { 13 | private readonly IRouter _router; 14 | private const string _component = "tak-ssl"; 15 | public TakTlsSession(TakTlsServer server) : base(server) 16 | { 17 | _router = server.Router; 18 | } 19 | protected override void OnConnected() 20 | { 21 | Log.Information($"server=tak-ssl endpoint={Socket.RemoteEndPoint} session={Id} state=connected"); 22 | foreach (var evt in _router.GetActiveEvents()) 23 | { 24 | Send(evt.ToXmlString()); 25 | } 26 | } 27 | 28 | protected override void OnDisconnected() 29 | { 30 | Log.Information($"server=tak-ssl session={Id} state=disconnected"); 31 | } 32 | 33 | protected override void OnReceived(byte[] buffer, long offset, long size) 34 | { 35 | try 36 | { 37 | var data = Encoding.UTF8.GetString(buffer); 38 | 39 | foreach (Match match in Regex.Matches(data, @"")) 40 | { 41 | try 42 | { 43 | var evt = Event.Parse(match.Value); 44 | Log.Information($"server={_component} endpoint={Socket.RemoteEndPoint} session={Id} event=cot uid={evt.Uid} type={evt.Type}"); 45 | if (evt.IsA(CotPredicates.t_ping)) 46 | { 47 | SendAsync(Event.Pong(evt).ToXmlString()); 48 | return; 49 | } 50 | 51 | _router.Send(evt, buffer); 52 | } 53 | catch (OverflowException) 54 | { 55 | Log.Error($"server={_component} endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"Overflow error. Receiving too much data.\""); 56 | 57 | // TODO: no real backoff control. kill connection? 58 | } 59 | catch (Exception e) 60 | { 61 | Log.Error($"server={_component} endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 62 | } 63 | } 64 | } 65 | catch (Exception e) 66 | { 67 | Log.Error($"server={_component} endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 68 | } 69 | } 70 | 71 | protected override void OnError(SocketError error) 72 | { 73 | Log.Error($"server=tak-ssl endpoint={Socket.RemoteEndPoint} session={Id} error=true message=\"{error}\""); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakWsServer.cs: -------------------------------------------------------------------------------- 1 | using NetCoreServer; 2 | using Serilog; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace dpp.opentakrouter 7 | { 8 | public class TakWsServer : WsServer 9 | { 10 | public IRouter Router; 11 | 12 | public TakWsServer(IPAddress address, int port, IRouter router) : base(address, port) 13 | { 14 | this.Router = router; 15 | this.Router.RaiseRoutedEvent += OnRoutedEvent; 16 | } 17 | 18 | protected override WsSession CreateSession() 19 | { 20 | return new TakWsSession(this); 21 | } 22 | 23 | protected void OnRoutedEvent(object sender, RoutedEventArgs e) 24 | { 25 | // TODO: can websockets be raw data (i.e. protobuf), or should they just be the xml event? 26 | var xml = e.Event.ToXmlString(); 27 | _ = this.MulticastText(xml); 28 | } 29 | 30 | protected override void OnError(SocketError error) 31 | { 32 | Log.Error($"server=ws error=true message=\"{error}\""); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakWsSession.cs: -------------------------------------------------------------------------------- 1 | using dpp.cot; 2 | using NetCoreServer; 3 | using Serilog; 4 | using System; 5 | using System.Net.Sockets; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace dpp.opentakrouter 10 | { 11 | public class TakWsSession : WsSession 12 | { 13 | private readonly IRouter _router; 14 | public TakWsSession(TakWsServer server) : base(server) 15 | { 16 | _router = server.Router; 17 | } 18 | public override void OnWsConnected(HttpRequest request) 19 | { 20 | Log.Information($"server=ws endpoint={Socket.RemoteEndPoint} session={Id} state=connected"); 21 | foreach (var evt in _router.GetActiveEvents()) 22 | { 23 | SendTextAsync(evt.ToXmlString()); 24 | } 25 | } 26 | 27 | public override void OnWsDisconnected() 28 | { 29 | Log.Information($"server=ws session={Id} state=disconnected"); 30 | } 31 | 32 | public override void OnWsReceived(byte[] buffer, long offset, long size) 33 | { 34 | try 35 | { 36 | var data = Encoding.UTF8.GetString(buffer); 37 | 38 | foreach (Match match in Regex.Matches(data, @"")) 39 | { 40 | try 41 | { 42 | var evt = Event.Parse(match.Value); 43 | Log.Information($"server=ws endpoint={Socket.RemoteEndPoint} session={Id} event=cot uid={evt.Uid} type={evt.Type}"); 44 | _router.Send(evt, null); 45 | } 46 | catch (Exception e) 47 | { 48 | Log.Error($"server=ws endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 49 | } 50 | } 51 | } 52 | catch (Exception e) 53 | { 54 | Log.Error($"server=ws endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 55 | } 56 | } 57 | 58 | protected override void OnError(SocketError error) 59 | { 60 | Log.Error($"server=ws endpoint={Socket.RemoteEndPoint} session={Id} error=true message=\"{error}\""); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakWssServer.cs: -------------------------------------------------------------------------------- 1 | using NetCoreServer; 2 | using Serilog; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace dpp.opentakrouter 7 | { 8 | public class TakWssServer : WssServer 9 | { 10 | public IRouter Router; 11 | 12 | public TakWssServer(SslContext context, IPAddress address, int port, IRouter router) : base(context, address, port) 13 | { 14 | this.Router = router; 15 | this.Router.RaiseRoutedEvent += OnRoutedEvent; 16 | } 17 | 18 | protected override WssSession CreateSession() 19 | { 20 | return new TakWssSession(this); 21 | } 22 | 23 | protected void OnRoutedEvent(object sender, RoutedEventArgs e) 24 | { 25 | // TODO: can websockets be raw data (i.e. protobuf), or should they just be the xml event? 26 | var xml = e.Event.ToXmlString(); 27 | _ = this.MulticastText(xml); 28 | } 29 | 30 | protected override void OnError(SocketError error) 31 | { 32 | Log.Error($"server=wss id=server error=true message=\"{error}\""); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dpp.opentakrouter/TakWssSession.cs: -------------------------------------------------------------------------------- 1 | using dpp.cot; 2 | using NetCoreServer; 3 | using Serilog; 4 | using System; 5 | using System.Net.Sockets; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace dpp.opentakrouter 10 | { 11 | public class TakWssSession : WssSession 12 | { 13 | private readonly IRouter _router; 14 | public TakWssSession(TakWssServer server) : base(server) 15 | { 16 | _router = server.Router; 17 | } 18 | public override void OnWsConnected(HttpRequest request) 19 | { 20 | Log.Information($"server=wss endpoint={Socket.RemoteEndPoint} session={Id} state=connected"); 21 | foreach (var evt in _router.GetActiveEvents()) 22 | { 23 | SendTextAsync(evt.ToXmlString()); 24 | } 25 | } 26 | 27 | public override void OnWsDisconnected() 28 | { 29 | Log.Information($"server=wss session={Id} state=disconnected"); 30 | } 31 | 32 | public override void OnWsReceived(byte[] buffer, long offset, long size) 33 | { 34 | try 35 | { 36 | var data = Encoding.UTF8.GetString(buffer); 37 | 38 | foreach (Match match in Regex.Matches(data, @"")) 39 | { 40 | try 41 | { 42 | var evt = Event.Parse(match.Value); 43 | Log.Information($"server=wss endpoint={Socket.RemoteEndPoint} session={Id} event=cot uid={evt.Uid} type={evt.Type}"); 44 | _router.Send(evt, null); 45 | } 46 | catch (Exception e) 47 | { 48 | Log.Error($"server=wss endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 49 | } 50 | } 51 | } 52 | catch (Exception e) 53 | { 54 | Log.Error($"server=wss endpoint={Socket.RemoteEndPoint} session={Id} type=unknown error=true forwarded=false message=\"{e.Message}\""); 55 | } 56 | } 57 | 58 | protected override void OnError(SocketError error) 59 | { 60 | Log.Error($"server=wss endpoint={Socket.RemoteEndPoint} session={Id} error=true message=\"{error}\""); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Home/Clients.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Clients"; 3 | } 4 | 5 |
6 |
7 |
8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | @foreach (var client in ViewData["clients"] as IEnumerable) 22 | { 23 | 24 | 25 | 26 | 27 | 28 | 29 | 37 | 38 | } 39 | 40 |
CallsignDevicePlatformVersionLastSeen
@client.Callsign@client.Device@client.Platform@client.Version@client.LastSeen.ToUniversalTime().ToString("u") 30 | 31 | 36 |
41 |
42 |
43 |
44 |
45 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Home/DataPackages.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Data Packages"; 3 | } 4 | 5 |
6 |
7 | 8 |
9 |
10 | 11 | 12 | 13 | 16 | 19 | 22 | 25 | 28 | 31 | 32 | 33 | 34 | @foreach (var package in ViewData["datapackages"] as IEnumerable) 35 | { 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 56 | 57 | } 58 | 59 |
14 | Id 15 | 17 | Name 18 | 20 | Timestamp 21 | 23 | Uploader 24 | 26 | Size 27 | 29 | 30 |
@package.UID@package.Name@package.SubmissionDateTime.ToUniversalTime().ToString("u")@package.SubmissionUser@package.Size 44 | 45 | 46 | 47 | Download 48 | 49 | 50 | 55 |
60 |
61 |
62 |
63 |
64 | 65 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | 4 | var devicesCount = 12; 5 | var usersCount = 34; 6 | var datapackagesCount = 56; 7 | var eventsCount = 78; 8 | } 9 | 10 |
11 | 62 |
63 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Home/Map.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Map"; 3 | } 4 | @section Styles { 5 | 6 | 9 | } 10 | 11 |
12 |
13 |
14 | 15 | @section Scripts { 16 | 17 | 18 | 90 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - OpenTakRouter 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | @await RenderSectionAsync("Styles", required: false) 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 |
26 | 27 |
28 |
29 |

@ViewData["Title"]

30 |
31 |
32 | 33 | 34 |
35 | 36 | 37 |
38 |
39 | @RenderBody() 40 |
41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | @await RenderSectionAsync("Scripts", required: false) 62 | 63 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Shared/_MainNavigation.cshtml: -------------------------------------------------------------------------------- 1 |  2 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using dpp.opentakrouter 2 | @using dpp.opentakrouter.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /dpp.opentakrouter/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /dpp.opentakrouter/WebConfig.cs: -------------------------------------------------------------------------------- 1 | namespace dpp.opentakrouter 2 | { 3 | public class WebConfig 4 | { 5 | public bool Enabled { get; set; } = true; 6 | public int? Port { get; set; } 7 | public bool Swagger { get; set; } = true; 8 | public bool Ssl { get; set; } = false; 9 | public string Cert { get; set; } = ""; 10 | public string Passphrase { get; set; } = ""; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /dpp.opentakrouter/WebService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.OpenApi.Models; 5 | using Serilog; 6 | 7 | namespace dpp.opentakrouter 8 | { 9 | public class WebService 10 | { 11 | public IConfiguration Configuration { get; } 12 | public WebService(IConfiguration configuration) 13 | { 14 | Configuration = configuration; 15 | } 16 | 17 | // This method gets called by the runtime. Use this method to add services to the container. 18 | public void ConfigureServices(IServiceCollection services) 19 | { 20 | services.AddControllersWithViews(); 21 | services.AddSwaggerGen(c => 22 | { 23 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "OpenTakRouter", Version = "v1" }); 24 | }); 25 | } 26 | 27 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 28 | public void Configure(IApplicationBuilder app) 29 | { 30 | var apiConfig = Configuration.GetSection("server:api").Get(); 31 | if (apiConfig is not null) 32 | { 33 | if (apiConfig.Swagger) 34 | { 35 | app.UseSwagger(); 36 | app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "OpenTakRouter v1")); 37 | } 38 | 39 | if (apiConfig.Ssl) 40 | { 41 | app.UseHttpsRedirection(); 42 | } 43 | } 44 | 45 | app.UseStaticFiles(); 46 | app.UseSerilogRequestLogging(options => 47 | { 48 | options.MessageTemplate = "server=web endpoint={RemoteIpAddress} method={RequestMethod} req={RequestPath} status={StatusCode} ms={Elapsed}"; 49 | options.EnrichDiagnosticContext = (diagnosticContext, httpContext) => 50 | { 51 | diagnosticContext.Set("RemoteIpAddress", httpContext.Connection.RemoteIpAddress); 52 | }; 53 | }); 54 | app.UseRouting(); 55 | app.UseAuthorization(); 56 | app.UseEndpoints(endpoints => 57 | { 58 | endpoints.MapControllers(); 59 | }); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /dpp.opentakrouter/dpp.opentakrouter.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net6.0 6 | 1.0.16 7 | 1.0.16.0 8 | 9 | win-x64;linux-x64;linux-arm64 10 | opentakrouter 11 | Linux 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | PreserveNewest 38 | 39 | 40 | 41 | 42 | 43 | PreserveNewest 44 | true 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /dpp.opentakrouter/libman.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "defaultProvider": "cdnjs", 4 | "libraries": [ 5 | { 6 | "library": "jquery@3.6.0", 7 | "destination": "wwwroot/lib/jquery/" 8 | }, 9 | { 10 | "library": "bootstrap@5.1.3", 11 | "destination": "wwwroot/lib/bootstrap/" 12 | }, 13 | { 14 | "library": "admin-lte@3.2.0", 15 | "destination": "wwwroot/lib/admin-lte/" 16 | }, 17 | { 18 | "library": "font-awesome@6.1.1", 19 | "destination": "wwwroot/lib/font-awesome/" 20 | }, 21 | { 22 | "provider": "jsdelivr", 23 | "library": "@fontsource/source-sans-pro@4.5.6", 24 | "destination": "wwwroot/lib/fontsource" 25 | }, 26 | { 27 | "library": "leaflet@1.7.1", 28 | "destination": "wwwroot/lib/leaflet/" 29 | }, 30 | { 31 | "provider": "jsdelivr", 32 | "library": "milsymbol@2.0.0", 33 | "destination": "wwwroot/lib/milsymbol/" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /dpp.opentakrouter/opentakrouter.json: -------------------------------------------------------------------------------- 1 | { 2 | "AllowedHosts": "*", 3 | "server": { 4 | // the data directory where the database file is located. 5 | // defaults to the executable location. 6 | //"data": "%appdata%/opentakrouter", 7 | 8 | // persist messages to the local database. on by default. 9 | // in extreme cases this may increase throughput slightly. 10 | "persist_messages": true, 11 | 12 | // set the server name. this is used for api/federation functionality. 13 | // defaults to the hostname. 14 | //"name": "" 15 | 16 | // the api interface configuration 17 | "api": { 18 | "port": 8080, 19 | "swagger": true, 20 | 21 | "ssl": false, 22 | "cert": "server.p12", 23 | "passphrase": "atakatak" 24 | }, 25 | "websockets": { 26 | "enabled": true, 27 | "port": 5000, 28 | 29 | "ssl": false, 30 | "cert": "server.p12", 31 | "passphrase": "atakatak" 32 | }, 33 | 34 | // the tak protocol configurations 35 | "tak": { 36 | "tcp": { 37 | "enabled": true, 38 | "port": 58087 39 | }, 40 | "tls": { 41 | "enabled": false, 42 | "port": 58089, 43 | "cert": "server.p12", 44 | "passphrase": "atakatak" 45 | } 46 | }, 47 | "peers": [ 48 | ] 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dpp.opentakrouter/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | for details on configuring this project to bundle and minify static web assets. */ 3 | 4 | a.navbar-brand { 5 | white-space: normal; 6 | text-align: center; 7 | word-break: break-all; 8 | } 9 | 10 | /* Provide sufficient contrast against white background */ 11 | a { 12 | color: #0366d6; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link { 22 | color: #fff; 23 | background-color: #1b6ec2; 24 | border-color: #1861ac; 25 | } 26 | 27 | /* Sticky footer styles 28 | -------------------------------------------------- */ 29 | html { 30 | font-size: 14px; 31 | } 32 | @media (min-width: 768px) { 33 | html { 34 | font-size: 16px; 35 | } 36 | } 37 | 38 | .border-top { 39 | border-top: 1px solid #e5e5e5; 40 | } 41 | .border-bottom { 42 | border-bottom: 1px solid #e5e5e5; 43 | } 44 | 45 | .box-shadow { 46 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); 47 | } 48 | 49 | button.accept-policy { 50 | font-size: 1rem; 51 | line-height: inherit; 52 | } 53 | 54 | /* Sticky footer styles 55 | -------------------------------------------------- */ 56 | html { 57 | position: relative; 58 | min-height: 100%; 59 | } 60 | 61 | body { 62 | /* Margin bottom by footer height */ 63 | margin-bottom: 60px; 64 | } 65 | .footer { 66 | position: absolute; 67 | bottom: 0; 68 | width: 100%; 69 | white-space: nowrap; 70 | line-height: 60px; /* Vertically center the text there */ 71 | } 72 | -------------------------------------------------------------------------------- /dpp.opentakrouter/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darkplusplus/opentakrouter/b361860fad1ad0a913331a555f651f95fe6cf6c6/dpp.opentakrouter/wwwroot/favicon.ico -------------------------------------------------------------------------------- /dpp.opentakrouter/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /opentakrouter.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.6.30114.105 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dpp.opentakrouter", "dpp.opentakrouter\dpp.opentakrouter.csproj", "{73115B5B-9E47-4D60-A3F8-5F92F55D15EA}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dpp.opentakrouter.Tests", "dpp.opentakrouter.Tests\dpp.opentakrouter.Tests.csproj", "{248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{60D76D5C-4BB5-4AEB-A30B-E3C6139DBC8C}" 11 | ProjectSection(SolutionItems) = preProject 12 | .gitignore = .gitignore 13 | readme.md = readme.md 14 | EndProjectSection 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Debug|x64 = Debug|x64 20 | Debug|x86 = Debug|x86 21 | Release|Any CPU = Release|Any CPU 22 | Release|x64 = Release|x64 23 | Release|x86 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Debug|x64.ActiveCfg = Debug|Any CPU 29 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Debug|x64.Build.0 = Debug|Any CPU 30 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Debug|x86.ActiveCfg = Debug|Any CPU 31 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Debug|x86.Build.0 = Debug|Any CPU 32 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Release|x64.ActiveCfg = Release|Any CPU 35 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Release|x64.Build.0 = Release|Any CPU 36 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Release|x86.ActiveCfg = Release|Any CPU 37 | {73115B5B-9E47-4D60-A3F8-5F92F55D15EA}.Release|x86.Build.0 = Release|Any CPU 38 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Debug|x64.ActiveCfg = Debug|Any CPU 41 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Debug|x64.Build.0 = Debug|Any CPU 42 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Debug|x86.ActiveCfg = Debug|Any CPU 43 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Debug|x86.Build.0 = Debug|Any CPU 44 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Release|x64.ActiveCfg = Release|Any CPU 47 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Release|x64.Build.0 = Release|Any CPU 48 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Release|x86.ActiveCfg = Release|Any CPU 49 | {248DE885-E6F6-4981-A9D3-AF2BC76CB0C0}.Release|x86.Build.0 = Release|Any CPU 50 | EndGlobalSection 51 | GlobalSection(SolutionProperties) = preSolution 52 | HideSolutionNode = FALSE 53 | EndGlobalSection 54 | GlobalSection(ExtensibilityGlobals) = postSolution 55 | SolutionGuid = {5BD31DF3-5404-48BF-A94D-5D8F32045D5A} 56 | EndGlobalSection 57 | EndGlobal 58 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # OpenTakRouter [![ci](https://github.com/darkplusplus/opentakrouter/actions/workflows/ci.yml/badge.svg)](https://github.com/darkplusplus/opentakrouter/actions/workflows/ci.yml) 2 | 3 | An opensource router of cursor-on-target messages with support for [ATAK](https://github.com/deptofdefense/AndroidTacticalAssaultKit-CIV). 4 | 5 | ## Features 6 | 7 | - Cross platform emphasizing ease of use. 8 | - Support for both TCP and SSL server modes. 9 | - Datapackages server. 10 | - Live map of current POI. 11 | - Basic federation capabilities (non-ssl for now). 12 | - More to come! 13 | 14 | You can track our current roadmap here: https://github.com/darkplusplus/opentakrouter/projects/1 15 | 16 | ## Quickstart 17 | 18 | 1. Go grab the latest release zip or tarball. 19 | 2. Unarchive to your directory of choice. 20 | 3. Review `opentakrouter.json` to see the default configuration. 21 | 4. Run `opentakrouter`. 22 | 5. Browse to http://localhost:8080 to see the admin pages. 23 | 6. Connect your EUD to your host on port `58087`. 24 | 25 | 26 | ## Want to run this on AWS? 27 | 28 | We have a shortcut to get you online quickly at https://github.com/darkplusplus/opentakrouter-ops. 29 | -------------------------------------------------------------------------------- /scripts/build-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | VERSION=`git branch --show-current` 5 | HASH=`git rev-parse --short HEAD` 6 | 7 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 8 | DIST_DIR="$SCRIPT_DIR/../dist" 9 | 10 | mkdir -p $DIST_DIR 11 | 12 | # linux 13 | dotnet publish dpp.opentakrouter -c Release -r linux-x64 --self-contained=true -p:PublishSingleFile=true 14 | pushd ./dpp.opentakrouter/bin/Release/net5.0/linux-x64/publish/ 15 | tar -czvf $DIST_DIR/opentakrouter-$VERSION-$HASH.tar.gz . 16 | popd 17 | -------------------------------------------------------------------------------- /scripts/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [[ -z "$CI" ]]; then 5 | echo "Sorry, but this assumes running in a Github Action" 1>&2 6 | exit 1 7 | fi 8 | 9 | VERSION=$GITHUB_REF_NAME 10 | 11 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 12 | DIST_DIR="$SCRIPT_DIR/../dist" 13 | 14 | mkdir -p $DIST_DIR 15 | 16 | dotnet clean 17 | 18 | # win10-x64 19 | ARCH=win10-x64 20 | dotnet publish dpp.opentakrouter -c Release -r $ARCH --self-contained=true -p:PublishSingleFile=true 21 | pushd ./dpp.opentakrouter/bin/Release/net5.0/$ARCH/publish/ 22 | zip -r $DIST_DIR/opentakrouter-$VERSION-$ARCH.zip . 23 | popd 24 | 25 | # linux-x64 26 | ARCH=linux-x64 27 | dotnet publish dpp.opentakrouter -c Release -r $ARCH --self-contained=true -p:PublishSingleFile=true 28 | pushd ./dpp.opentakrouter/bin/Release/net5.0/$ARCH/publish/ 29 | tar -czvf $DIST_DIR/opentakrouter-$VERSION-$ARCH.tar.gz . 30 | popd 31 | 32 | # linux-arm64 33 | ARCH=linux-arm64 34 | dotnet publish dpp.opentakrouter -c Release -r $ARCH --self-contained=true -p:PublishSingleFile=true 35 | pushd ./dpp.opentakrouter/bin/Release/net5.0/$ARCH/publish/ 36 | tar -czvf $DIST_DIR/opentakrouter-$VERSION-$ARCH.tar.gz . 37 | popd 38 | --------------------------------------------------------------------------------