diff --git a/projects/Infrastructure/Extensions/HelperExtensions.cs b/projects/Infrastructure/Extensions/HelperExtensions.cs index 3f9e99b3..4b743355 100644 --- a/projects/Infrastructure/Extensions/HelperExtensions.cs +++ b/projects/Infrastructure/Extensions/HelperExtensions.cs @@ -1,12 +1,15 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; using System.Reflection; using System.Runtime.InteropServices; +using System.Security.Cryptography; +using System.Text; namespace Infrastructure.Extensions { @@ -34,6 +37,27 @@ namespace Infrastructure.Extensions .FirstOrDefault(); } + public static string MacEncrypt(this Helper helper, string value) + { + using var des = new DESCryptoServiceProvider(); + var inputByteArray = Encoding.Default.GetBytes(value); + using MD5 md5 = MD5.Create(); + byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(value)); + var md5Key = BitConverter.ToString(hash).Replace("-", string.Empty, StringComparison.Ordinal).ToLower(CultureInfo.InvariantCulture); + des.Key = Encoding.ASCII.GetBytes(md5Key.Substring(0, 8)); + des.IV = Encoding.ASCII.GetBytes(md5Key.Substring(0, 8)); + using var ms = new MemoryStream(); + using var cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write); + cs.Write(inputByteArray, 0, inputByteArray.Length); + cs.FlushFinalBlock(); + var ret = new StringBuilder(); + foreach (var item in ms.ToArray()) + { + ret.AppendFormat("{0:X2}", item); + } + return ret.ToString(); + } + public static List GetLocalIPList(this Helper helper) { var ipList = new List(); diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index fa2edcf9..2d256407 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -1,4 +1,4 @@ -using Infrastructure.Application.Services.Settings; +using Infrastructure.Application.Services.Settings; using Infrastructure.Data; using Infrastructure.Events; using Infrastructure.Extensions; @@ -20,7 +20,6 @@ using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Versioning; -using Microsoft.AspNetCore.ResponseCompression; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; diff --git a/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs b/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs index 85c569d5..11b80bbd 100644 --- a/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs +++ b/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs @@ -30,9 +30,11 @@ namespace IoT.Shared.Services private readonly IHostApplicationLifetime _lifetime; private readonly IServiceProvider _applicationServices; private readonly ILogger _logger; + private string _mac; public IoTNodeClient(IHostApplicationLifetime lifetime, IServiceProvider applicationServices, ILogger logger) { + this._mac = Helper.Instance.GetMacAddress(); this._lifetime = lifetime; this._applicationServices = applicationServices; this._logger = logger; @@ -64,6 +66,12 @@ namespace IoT.Shared.Services public void Connect() { + var code = GetSetting("code"); + if (code != Helper.Instance.MacEncrypt(this._mac)) + { + this._logger.LogError($"err: code {code} does not match mac {_mac}"); + return; + } var enable = GetSetting("notify:enabled"); if (enable == "true") { diff --git a/projects/IoTCenter/Controllers/HomeController.cs b/projects/IoTCenter/Controllers/HomeController.cs index 2ae88a0c..da5bec6e 100644 --- a/projects/IoTCenter/Controllers/HomeController.cs +++ b/projects/IoTCenter/Controllers/HomeController.cs @@ -1,5 +1,6 @@ -using Application.Domain.Entities; +using Application.Domain.Entities; using Infrastructure.Data; +using Infrastructure.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; @@ -53,5 +54,15 @@ namespace IoTCenter.Controllers { return View(); } + +#if DEBUG + + [Route("/license")] + public IActionResult License(string mac) + { + return Content(Helper.Instance.MacEncrypt(mac)); + } + +#endif } } \ No newline at end of file diff --git a/projects/IoTNode/Areas/Admin/Controllers/HomeController.cs b/projects/IoTNode/Areas/Admin/Controllers/HomeController.cs index 3cf2d26b..e02a8653 100644 --- a/projects/IoTNode/Areas/Admin/Controllers/HomeController.cs +++ b/projects/IoTNode/Areas/Admin/Controllers/HomeController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace IoTNode.Areas.Admin.Controllers diff --git a/projects/IoTNode/DbConfig.cs b/projects/IoTNode/DbConfig.cs index 96ad881b..09f2556c 100644 --- a/projects/IoTNode/DbConfig.cs +++ b/projects/IoTNode/DbConfig.cs @@ -4,21 +4,25 @@ using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Security; using IoT.Shared; +using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; -using System.Linq; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using System; +using System.Collections.Generic; +using System.Linq; namespace IoTNode { public class DbConfig : IDbConfig { + private readonly IWebHostEnvironment _env; private readonly IConfiguration _cfg; private readonly IEncryptionService _encryptionService; - public DbConfig(IConfiguration cfg, IEncryptionService encryptionService) + public DbConfig(IWebHostEnvironment env, IConfiguration cfg, IEncryptionService encryptionService) { + this._env = env; this._cfg = cfg; this._encryptionService = encryptionService; } @@ -76,23 +80,28 @@ namespace IoTNode var macAddress = Helper.Instance.GetMacAddress(); set.Add(new Setting { Name = "sn", Value = macAddress, Type = SettingType.Text }); set.Add(new Setting { Name = "id", Value = macAddress.Md5(), Type = SettingType.Text }); - set.Add(new Setting { Name = "code", Value = "根据id生成的授权码", Type = SettingType.Text }); + set.Add(new Setting + { + Name = "code", + Value = this._env.IsDevelopment() ? Helper.Instance.MacEncrypt(Helper.Instance.GetMacAddress()) : "根据id生成的授权码", + Type = SettingType.Text + }); // var host = this._cfg.GetValue("seed:host", "localhost"); var stream = this._cfg.GetValue("seed:stream", "localhost"); var delay = this._cfg.GetValue("seed:delay", "100"); - set.Add(new Setting { Name = "debug", Value = "false" }); - set.Add(new Setting { Name = "notify:enabled", Value = "true" }); - set.Add(new Setting { Name = "notify:host", Value = $"http://{host}/IoTCenter" }); - set.Add(new Setting { Name = "timer.seconds", Value = "180" }); - set.Add(new Setting { Name = "onvif.timer", Value = "1" }); - set.Add(new Setting { Name = "onvif.speed", Value = "0.2" }); - set.Add(new Setting { Name = "camera.usr", Value = "admin" }); - set.Add(new Setting { Name = "camera.pwd", Value = "dsideal123" }); - set.Add(new Setting { Name = "stream.rtmp", Value = stream }); - set.Add(new Setting { Name = "ffmpeg.args", Value = " -y -threads {0} -rtsp_transport tcp -use_wallclock_as_timestamps 1 -stimeout 3000000 -i \"{1}\" -fflags +genpts -c copy -f flv \"{2}\"" }); - set.Add(new Setting { Name = "fbee.writelist", Value = "" }); - set.Add(new Setting { Name = "camera.writelist", Value = "" }); + set.Add(new Setting { Name = "debug", Value = "false", Type = SettingType.Text }); + set.Add(new Setting { Name = "notify:enabled", Value = "true", Type = SettingType.Text }); + set.Add(new Setting { Name = "notify:host", Value = $"http://{host}/IoTCenter", Type = SettingType.Text }); + set.Add(new Setting { Name = "timer.seconds", Value = "180", Type = SettingType.Text }); + set.Add(new Setting { Name = "onvif.timer", Value = "1", Type = SettingType.Text }); + set.Add(new Setting { Name = "onvif.speed", Value = "0.2", Type = SettingType.Text }); + set.Add(new Setting { Name = "camera.usr", Value = "admin", Type = SettingType.Text }); + set.Add(new Setting { Name = "camera.pwd", Value = "dsideal123", Type = SettingType.Text }); + set.Add(new Setting { Name = "stream.rtmp", Value = stream, Type = SettingType.Text }); + set.Add(new Setting { Name = "ffmpeg.args", Value = " -y -threads {0} -rtsp_transport tcp -use_wallclock_as_timestamps 1 -stimeout 3000000 -i \"{1}\" -fflags +genpts -c copy -f flv \"{2}\"", Type = SettingType.Text }); + set.Add(new Setting { Name = "fbee.writelist", Value = "", Type = SettingType.Text }); + set.Add(new Setting { Name = "camera.writelist", Value = "", Type = SettingType.Text }); set.Add(new Setting { Name = "delay", Value = delay, Type = SettingType.Text }); db.SaveChanges(); diff --git a/projects/IoTNode/Services/IoTNodeEventHandler.cs b/projects/IoTNode/Services/IoTNodeEventHandler.cs index 34b7db1a..2b8466a3 100644 --- a/projects/IoTNode/Services/IoTNodeEventHandler.cs +++ b/projects/IoTNode/Services/IoTNodeEventHandler.cs @@ -66,7 +66,12 @@ namespace IoTNode.Services this._onvifService.StopPushToServer(); this._onvifService.StartPushToServer(); } - else if (message.Data.Name == "organ") + else if (message.Data.Name == "notify:host") + { + this._ioTNodeClient.Close(); + this._ioTNodeClient.Connect(); + } + else if (message.Data.Name == "code") { this._ioTNodeClient.Close(); this._ioTNodeClient.Connect(); diff --git a/projects/IoTNode/Startup.cs b/projects/IoTNode/Startup.cs index 1c3a78e2..01dd7c26 100644 --- a/projects/IoTNode/Startup.cs +++ b/projects/IoTNode/Startup.cs @@ -14,14 +14,10 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System; -using System.Globalization; using System.IO; using System.Linq; -using System.Security.Cryptography; -using System.Text; namespace IoTNode { @@ -29,25 +25,6 @@ namespace IoTNode { public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env) { - var mac = Helper.Instance.GetMacAddress(); - var license = DESEncrypt(mac); - var list = new string[] { license }; - if (!env.IsDevelopment()) - { - if (!File.Exists(license)) - { - var message = $"error:does not exists licenese file: {license}"; - Console.WriteLine(message); - throw new Exception(message); - } - list = File.ReadAllText("license").Split(','); - } - if (!list.Contains(license)) - { - var message = $"error:does not contain licenese which match mac address {mac}"; - Console.WriteLine(message); - throw new Exception(message); - } } public override void ConfigureServices(IServiceCollection services) @@ -141,26 +118,5 @@ namespace IoTNode } return result; } - - public static string DESEncrypt(string value) - { - using var des = new DESCryptoServiceProvider(); - var inputByteArray = Encoding.Default.GetBytes(value); - using MD5 md5 = MD5.Create(); - byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(value)); - var md5Key = BitConverter.ToString(hash).Replace("-", string.Empty, StringComparison.Ordinal).ToLower(CultureInfo.InvariantCulture); - des.Key = Encoding.ASCII.GetBytes(md5Key.Substring(0, 8)); - des.IV = Encoding.ASCII.GetBytes(md5Key.Substring(0, 8)); - using var ms = new MemoryStream(); - using var cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write); - cs.Write(inputByteArray, 0, inputByteArray.Length); - cs.FlushFinalBlock(); - var ret = new StringBuilder(); - foreach (var item in ms.ToArray()) - { - ret.AppendFormat("{0:X2}", item); - } - return ret.ToString(); - } } } \ No newline at end of file diff --git a/projects/IoTNode/Version.cs b/projects/IoTNode/Version.cs index bb6381a7..64a68a43 100644 --- a/projects/IoTNode/Version.cs +++ b/projects/IoTNode/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.20092701")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.20092702")] \ No newline at end of file diff --git a/projects/Version.cs b/projects/Version.cs index bb6381a7..64a68a43 100644 --- a/projects/Version.cs +++ b/projects/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.20092701")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.20092702")] \ No newline at end of file diff --git a/publish/build.ps1 b/publish/build.ps1 index d8cff958..a256a551 100644 --- a/publish/build.ps1 +++ b/publish/build.ps1 @@ -1,5 +1,11 @@ -Remove-Item ./dist/* -recurse -force - +if(Test-Path dist) +{ + Remove-Item ./dist/* -recurse -force +} +else +{ + mkdir ./dist; +} Copy-Item ./src/* ./dist -recurse -Exclude @('.gitignore','start-dev.cmd','docker-compose.override.yml','nginx.development.conf') Remove-Item ./dist/linux-x64/publish/docker/log/* -recurse -force diff --git a/publish/src/linux-arm64/publish/apps/srs/conf/srs.conf b/publish/src/linux-arm64/publish/apps/srs/conf/srs.conf index c98803f9..925822bb 100644 --- a/publish/src/linux-arm64/publish/apps/srs/conf/srs.conf +++ b/publish/src/linux-arm64/publish/apps/srs/conf/srs.conf @@ -3,16 +3,7 @@ max_connections 1000; srs_log_tank file; srs_log_file ./objs/log/srs.log; daemon off; -http_api { - enabled on; - listen 1985; - raw_api { - enabled on; - allow_reload on; - allow_query on; - allow_update on; - } -} + http_server { enabled on; listen 8080; @@ -53,13 +44,5 @@ vhost __defaultVhost__ { hls_m3u8_file [app]/[stream].m3u8; hls_ts_file [app]/[stream]-[seq].ts; } - dvr { - enabled on; - dvr_apply none; - dvr_path ./objs/nginx/html/video/[app].[stream].[timestamp].mp4; - } - http_hooks { - enabled on; - on_dvr http://localhost:8002/api/v1/Srs/OnDvr; - } + } diff --git a/publish/src/linux-arm64/publish/apps/srs/objs/srs b/publish/src/linux-arm64/publish/apps/srs/objs/srs index 79138100..6782df7f 100644 Binary files a/publish/src/linux-arm64/publish/apps/srs/objs/srs and b/publish/src/linux-arm64/publish/apps/srs/objs/srs differ diff --git a/tools/srs/docker-compose-ubuntu12arm.yml b/tools/srs/docker-compose-ubuntu12arm.yml index dd099fbe..911e272a 100644 --- a/tools/srs/docker-compose-ubuntu12arm.yml +++ b/tools/srs/docker-compose-ubuntu12arm.yml @@ -11,7 +11,7 @@ services: &&apt-get upgrade -y &&apt-get install -y git &&rm -rf /root/srs/ - &&git clone -b 4.0release https://gitee.com/winlinvip/srs.oschina.git srs + &&git clone -b 3.0release https://gitee.com/winlinvip/srs.oschina.git srs &&cd srs/trunk && git remote set-url origin https://github.com/ossrs/srs.git && git pull