1.0.0.20092702

Former-commit-id: 500690543698f1e389c256b5498129d55d835d65
Former-commit-id: 70969fbb82d051cd597aaa01b132d4942e2afc9c
TSXN
wanggang 5 years ago
parent 9dd95708ad
commit 85c3d0e05a

@ -1,12 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
namespace Infrastructure.Extensions namespace Infrastructure.Extensions
{ {
@ -34,6 +37,27 @@ namespace Infrastructure.Extensions
.FirstOrDefault(); .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<IPAddress> GetLocalIPList(this Helper helper) public static List<IPAddress> GetLocalIPList(this Helper helper)
{ {
var ipList = new List<IPAddress>(); var ipList = new List<IPAddress>();

@ -1,4 +1,4 @@
using Infrastructure.Application.Services.Settings; using Infrastructure.Application.Services.Settings;
using Infrastructure.Data; using Infrastructure.Data;
using Infrastructure.Events; using Infrastructure.Events;
using Infrastructure.Extensions; using Infrastructure.Extensions;
@ -20,7 +20,6 @@ using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

@ -30,9 +30,11 @@ namespace IoT.Shared.Services
private readonly IHostApplicationLifetime _lifetime; private readonly IHostApplicationLifetime _lifetime;
private readonly IServiceProvider _applicationServices; private readonly IServiceProvider _applicationServices;
private readonly ILogger<IoTNodeClient> _logger; private readonly ILogger<IoTNodeClient> _logger;
private string _mac;
public IoTNodeClient(IHostApplicationLifetime lifetime, IServiceProvider applicationServices, ILogger<IoTNodeClient> logger) public IoTNodeClient(IHostApplicationLifetime lifetime, IServiceProvider applicationServices, ILogger<IoTNodeClient> logger)
{ {
this._mac = Helper.Instance.GetMacAddress();
this._lifetime = lifetime; this._lifetime = lifetime;
this._applicationServices = applicationServices; this._applicationServices = applicationServices;
this._logger = logger; this._logger = logger;
@ -64,6 +66,12 @@ namespace IoT.Shared.Services
public void Connect() 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"); var enable = GetSetting("notify:enabled");
if (enable == "true") if (enable == "true")
{ {

@ -1,5 +1,6 @@
using Application.Domain.Entities; using Application.Domain.Entities;
using Infrastructure.Data; using Infrastructure.Data;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
@ -53,5 +54,15 @@ namespace IoTCenter.Controllers
{ {
return View(); return View();
} }
#if DEBUG
[Route("/license")]
public IActionResult License(string mac)
{
return Content(Helper.Instance.MacEncrypt(mac));
}
#endif
} }
} }

@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace IoTNode.Areas.Admin.Controllers namespace IoTNode.Areas.Admin.Controllers

@ -4,21 +4,25 @@ using Infrastructure.Data;
using Infrastructure.Extensions; using Infrastructure.Extensions;
using Infrastructure.Security; using Infrastructure.Security;
using IoT.Shared; using IoT.Shared;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System; using System;
using System.Collections.Generic;
using System.Linq;
namespace IoTNode namespace IoTNode
{ {
public class DbConfig : IDbConfig public class DbConfig : IDbConfig
{ {
private readonly IWebHostEnvironment _env;
private readonly IConfiguration _cfg; private readonly IConfiguration _cfg;
private readonly IEncryptionService _encryptionService; 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._cfg = cfg;
this._encryptionService = encryptionService; this._encryptionService = encryptionService;
} }
@ -76,23 +80,28 @@ namespace IoTNode
var macAddress = Helper.Instance.GetMacAddress(); var macAddress = Helper.Instance.GetMacAddress();
set.Add(new Setting { Name = "sn", Value = macAddress, Type = SettingType.Text }); 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 = "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 host = this._cfg.GetValue("seed:host", "localhost");
var stream = this._cfg.GetValue("seed:stream", "localhost"); var stream = this._cfg.GetValue("seed:stream", "localhost");
var delay = this._cfg.GetValue("seed:delay", "100"); var delay = this._cfg.GetValue("seed:delay", "100");
set.Add(new Setting { Name = "debug", Value = "false" }); set.Add(new Setting { Name = "debug", Value = "false", Type = SettingType.Text });
set.Add(new Setting { Name = "notify:enabled", Value = "true" }); set.Add(new Setting { Name = "notify:enabled", Value = "true", Type = SettingType.Text });
set.Add(new Setting { Name = "notify:host", Value = $"http://{host}/IoTCenter" }); set.Add(new Setting { Name = "notify:host", Value = $"http://{host}/IoTCenter", Type = SettingType.Text });
set.Add(new Setting { Name = "timer.seconds", Value = "180" }); set.Add(new Setting { Name = "timer.seconds", Value = "180", Type = SettingType.Text });
set.Add(new Setting { Name = "onvif.timer", Value = "1" }); set.Add(new Setting { Name = "onvif.timer", Value = "1", Type = SettingType.Text });
set.Add(new Setting { Name = "onvif.speed", Value = "0.2" }); set.Add(new Setting { Name = "onvif.speed", Value = "0.2", Type = SettingType.Text });
set.Add(new Setting { Name = "camera.usr", Value = "admin" }); set.Add(new Setting { Name = "camera.usr", Value = "admin", Type = SettingType.Text });
set.Add(new Setting { Name = "camera.pwd", Value = "dsideal123" }); set.Add(new Setting { Name = "camera.pwd", Value = "dsideal123", Type = SettingType.Text });
set.Add(new Setting { Name = "stream.rtmp", Value = stream }); 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}\"" }); 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 = "" }); set.Add(new Setting { Name = "fbee.writelist", Value = "", Type = SettingType.Text });
set.Add(new Setting { Name = "camera.writelist", Value = "" }); set.Add(new Setting { Name = "camera.writelist", Value = "", Type = SettingType.Text });
set.Add(new Setting { Name = "delay", Value = delay, Type = SettingType.Text }); set.Add(new Setting { Name = "delay", Value = delay, Type = SettingType.Text });
db.SaveChanges(); db.SaveChanges();

@ -66,7 +66,12 @@ namespace IoTNode.Services
this._onvifService.StopPushToServer(); this._onvifService.StopPushToServer();
this._onvifService.StartPushToServer(); 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.Close();
this._ioTNodeClient.Connect(); this._ioTNodeClient.Connect();

@ -14,14 +14,10 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace IoTNode namespace IoTNode
{ {
@ -29,25 +25,6 @@ namespace IoTNode
{ {
public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env) 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) public override void ConfigureServices(IServiceCollection services)
@ -141,26 +118,5 @@ namespace IoTNode
} }
return result; 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();
}
} }
} }

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.20092701")] [assembly: AssemblyInformationalVersion("1.0.0.20092702")]

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.20092701")] [assembly: AssemblyInformationalVersion("1.0.0.20092702")]

@ -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') 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 Remove-Item ./dist/linux-x64/publish/docker/log/* -recurse -force

@ -3,16 +3,7 @@ max_connections 1000;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/log/srs.log; srs_log_file ./objs/log/srs.log;
daemon off; daemon off;
http_api {
enabled on;
listen 1985;
raw_api {
enabled on;
allow_reload on;
allow_query on;
allow_update on;
}
}
http_server { http_server {
enabled on; enabled on;
listen 8080; listen 8080;
@ -53,13 +44,5 @@ vhost __defaultVhost__ {
hls_m3u8_file [app]/[stream].m3u8; hls_m3u8_file [app]/[stream].m3u8;
hls_ts_file [app]/[stream]-[seq].ts; 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;
}
} }

@ -11,7 +11,7 @@ services:
&&apt-get upgrade -y &&apt-get upgrade -y
&&apt-get install -y git &&apt-get install -y git
&&rm -rf /root/srs/ &&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 &&cd srs/trunk
&& git remote set-url origin https://github.com/ossrs/srs.git && git remote set-url origin https://github.com/ossrs/srs.git
&& git pull && git pull

Loading…
Cancel
Save