Add PolyProv
Dynamic configuration for Polycom (VVX?) phones.
This commit is contained in:
parent
4fb88d6cbb
commit
eff2dda7a4
73
PolyProv/Controllers/ConfigController.cs
Normal file
73
PolyProv/Controllers/ConfigController.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PhoneToolMX.Data;
|
||||
using PhoneToolMX.Models;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PolyProv.Controllers
|
||||
{
|
||||
public class ConfigController : Controller
|
||||
{
|
||||
private PTMXContext _ctx;
|
||||
private static Regex userConf = new Regex("^([0-9a-fA-F]{12})-user$");
|
||||
private static Regex initConf = new Regex("^([0-9a-fA-F]{12})$");
|
||||
private static Regex sipConf = new Regex("^([0-9a-fA-F]{12})-sip$");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Phone" /> by its MAC Address.
|
||||
/// </summary>
|
||||
/// <param name="addr">The MAC address of the phone</param>
|
||||
/// <returns>The <see cref="Phone"/> with the given MAC, or null if none was found</returns>
|
||||
private Phone? GetByMacStr(string addr)
|
||||
{
|
||||
if (!PhysicalAddress.TryParse(addr, out var parsed)) return null;
|
||||
return _ctx.Phones
|
||||
.Include(m => m.Extensions)
|
||||
.Include(m => m.Model)
|
||||
.FirstOrDefault(p => p.MacAddress.Equals(parsed));
|
||||
}
|
||||
|
||||
public ConfigController(PTMXContext context)
|
||||
{
|
||||
_ctx = context;
|
||||
}
|
||||
|
||||
[HttpGet("{param}.cfg")]
|
||||
public IActionResult GetConfig(string param)
|
||||
{
|
||||
return param switch
|
||||
{
|
||||
_ when initConf.Match(param) is { Success: true } match => InitSettings(match.Groups[1].Value),
|
||||
_ when userConf.Match(param) is { Success: true } match => PhoneSettings(match.Groups[1].Value),
|
||||
_ when sipConf.Match(param) is { Success: true } match => SipSettings(match.Groups[1].Value),
|
||||
_ => NotFound(),
|
||||
};
|
||||
}
|
||||
|
||||
public IActionResult InitSettings(string addr)
|
||||
{
|
||||
var phone = GetByMacStr(addr);
|
||||
return phone != null ? View("Init", phone) : NotFound();
|
||||
}
|
||||
|
||||
public IActionResult PhoneSettings(string addr)
|
||||
{
|
||||
var phone = GetByMacStr(addr);
|
||||
return phone != null ? View("Phone", phone) : NotFound();
|
||||
}
|
||||
|
||||
public IActionResult SipSettings(string addr)
|
||||
{
|
||||
var phone = GetByMacStr(addr);
|
||||
return phone != null ? View("Sip", phone) : NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("000000000000-directory.xml")]
|
||||
public IActionResult ExtDirectory()
|
||||
{
|
||||
var extensions = _ctx.Extensions.Where(x => x.Listed == true);
|
||||
return View("Directory", extensions.ToList());
|
||||
}
|
||||
}
|
||||
}
|
8
PolyProv/Models/ErrorViewModel.cs
Normal file
8
PolyProv/Models/ErrorViewModel.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace PolyProv.Models;
|
||||
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
31
PolyProv/PolyProv.csproj
Normal file
31
PolyProv/PolyProv.csproj
Normal file
|
@ -0,0 +1,31 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PhoneToolMX.Models\PhoneToolMX.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.22" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="Views\Shared\Error.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Views\Shared\_Layout.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Views\Shared\_ValidationScriptsPartial.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Views\Home\Index.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Views\Home\Privacy.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="wwwroot\js\site.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
35
PolyProv/Program.cs
Normal file
35
PolyProv/Program.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using PhoneToolMX.Data;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddDbContext<PTMXContext>(
|
||||
options => options.UseNpgsql(builder.Configuration.GetConnectionString("DbConnection"),
|
||||
b => b.MigrationsAssembly("PhoneToolMX.Models")));
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
|
||||
if (!builder.Environment.IsDevelopment()) {
|
||||
builder.Host.UseSystemd();
|
||||
}
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment()) {
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{action}",
|
||||
defaults: new { controller = "Config" });
|
||||
|
||||
app.Run();
|
28
PolyProv/Properties/launchSettings.json
Normal file
28
PolyProv/Properties/launchSettings.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:44863",
|
||||
"sslPort": 44352
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"PolyProv": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7041;http://localhost:5082",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
PolyProv/Views/Config/Directory.cshtml
Normal file
15
PolyProv/Views/Config/Directory.cshtml
Normal file
|
@ -0,0 +1,15 @@
|
|||
@model IList<PhoneToolMX.Models.Extension>
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<directory>
|
||||
<item_list>
|
||||
@foreach (var ext in Model) {
|
||||
<item>
|
||||
<lb>@ext.DirectoryName</lb>
|
||||
<ct>@ext.ExtId</ct>
|
||||
</item>
|
||||
}
|
||||
</item_list>
|
||||
</directory>
|
13
PolyProv/Views/Config/Init.cshtml
Normal file
13
PolyProv/Views/Config/Init.cshtml
Normal file
|
@ -0,0 +1,13 @@
|
|||
@model PhoneToolMX.Models.Phone
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<?xml version="1.0" standalone="yes"?>
|
||||
<!-- $Revision: 1.14 $ $Date: 2005/07/27 18:43:30 $ -->
|
||||
<APPLICATION
|
||||
APP_FILE_PATH="sip.ld"
|
||||
CONFIG_FILES="@Model.MacAddress.ToString().ToLower().Replace(":", "")-user.cfg, @Model.MacAddress.ToString().ToLower().Replace(":", "")-sip.cfg, polyconf.cfg"
|
||||
MISC_FILES=""
|
||||
LOG_FILE_DIRECTORY="logs/"
|
||||
OVERRIDES_DIRECTORY=""
|
||||
CONTACTS_DIRECTORY=""/>
|
17
PolyProv/Views/Config/Phone.cshtml
Normal file
17
PolyProv/Views/Config/Phone.cshtml
Normal file
|
@ -0,0 +1,17 @@
|
|||
@model PhoneToolMX.Models.Phone
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!-- Registration info -->
|
||||
<userinfo>
|
||||
@{ var extensions = Model.Extensions.ToList(); }
|
||||
@for (var i = 0; i < extensions.Count; i++) {
|
||||
<reg
|
||||
@($"reg.{i + 1}").displayName="@extensions[i].DirectoryName"
|
||||
@($"reg.{i + 1}").address="@extensions[i].ExtId"
|
||||
@($"reg.{i + 1}").type="private"
|
||||
@($"reg.{i + 1}").auth.userId="@extensions[i].ExtId"
|
||||
@($"reg.{i + 1}").auth.password="@(extensions[i].Password)" />
|
||||
}
|
||||
</userinfo>
|
12
PolyProv/Views/Config/Sip.cshtml
Normal file
12
PolyProv/Views/Config/Sip.cshtml
Normal file
|
@ -0,0 +1,12 @@
|
|||
@using PhoneToolMX.Models
|
||||
@model Phone
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<?xml version="1.0" standalone="yes"?>
|
||||
<localcfg>
|
||||
@for (var i = 0; i < Model.Extensions.Count; i++) {
|
||||
<server @($"voIpProt.server.{i + 1}").address="172.20.42.254"/>
|
||||
}
|
||||
<digitmap dialplan.digitmap="[1-4]xxx|*xx|[5-9]1xxxxxxxxxx|#[5-9]1xxxxxxxxxx|9011x.T|0xxxxxxxxx|9444[3-4]"/>
|
||||
</localcfg>
|
9
PolyProv/appsettings.json
Normal file
9
PolyProv/appsettings.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
15
ptmx-asp.sln
15
ptmx-asp.sln
|
@ -7,10 +7,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhoneToolMX", "PhoneToolMX\
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhoneToolMX.Models", "PhoneToolMX.Models\PhoneToolMX.Models.csproj", "{84FB1CE2-A4B6-4251-9427-8AEB175D6874}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyProv", "PolyProv\PolyProv.csproj", "{18199094-90AE-4C58-BE9E-65D486ECCC38}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -20,9 +23,21 @@ Global
|
|||
{130DD8E2-5E99-47A9-8B30-2FF54A0DA89D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{130DD8E2-5E99-47A9-8B30-2FF54A0DA89D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{130DD8E2-5E99-47A9-8B30-2FF54A0DA89D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{130DD8E2-5E99-47A9-8B30-2FF54A0DA89D}.Release|x64.ActiveCfg = Release|x64
|
||||
{130DD8E2-5E99-47A9-8B30-2FF54A0DA89D}.Release|x64.Build.0 = Release|x64
|
||||
{130DD8E2-5E99-47A9-8B30-2FF54A0DA89D}.Release|x64.Deploy.0 = Release|x64
|
||||
{84FB1CE2-A4B6-4251-9427-8AEB175D6874}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{84FB1CE2-A4B6-4251-9427-8AEB175D6874}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{84FB1CE2-A4B6-4251-9427-8AEB175D6874}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{84FB1CE2-A4B6-4251-9427-8AEB175D6874}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{84FB1CE2-A4B6-4251-9427-8AEB175D6874}.Release|x64.ActiveCfg = Release|x64
|
||||
{84FB1CE2-A4B6-4251-9427-8AEB175D6874}.Release|x64.Build.0 = Release|x64
|
||||
{84FB1CE2-A4B6-4251-9427-8AEB175D6874}.Release|x64.Deploy.0 = Release|x64
|
||||
{18199094-90AE-4C58-BE9E-65D486ECCC38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{18199094-90AE-4C58-BE9E-65D486ECCC38}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{18199094-90AE-4C58-BE9E-65D486ECCC38}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{18199094-90AE-4C58-BE9E-65D486ECCC38}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{18199094-90AE-4C58-BE9E-65D486ECCC38}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{18199094-90AE-4C58-BE9E-65D486ECCC38}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Loading…
Reference in a new issue