mirror of
https://github.com/tuxdotrs/trok.git
synced 2026-09-19 15:09:03 +05:30
Compare commits
5 Commits
v0.0.4
...
6c13858d46
| Author | SHA1 | Date | |
|---|---|---|---|
|
6c13858d46
|
|||
|
ad3792139d
|
|||
|
c1ba1e55d0
|
|||
|
a616409ee0
|
|||
|
3cceda5835
|
@@ -90,7 +90,7 @@ trok = {
|
|||||||
inputs.trok.nixosModules.default
|
inputs.trok.nixosModules.default
|
||||||
];
|
];
|
||||||
|
|
||||||
tux.services.trok = {
|
services.trok = {
|
||||||
enable = true;
|
enable = true;
|
||||||
host = "0.0.0.0";
|
host = "0.0.0.0";
|
||||||
port = 1337;
|
port = 1337;
|
||||||
|
|||||||
46
flake.nix
46
flake.nix
@@ -2,28 +2,32 @@
|
|||||||
description = "Simple tunneler in Go that exposes local ports to the internet";
|
description = "Simple tunneler in Go that exposes local ports to the internet";
|
||||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
|
||||||
outputs = {
|
outputs =
|
||||||
self,
|
{
|
||||||
nixpkgs,
|
self,
|
||||||
}: let
|
nixpkgs,
|
||||||
systems = [
|
}:
|
||||||
"x86_64-linux"
|
let
|
||||||
"aarch64-linux"
|
systems = [
|
||||||
"x86_64-darwin"
|
"x86_64-linux"
|
||||||
"aarch64-darwin"
|
"aarch64-linux"
|
||||||
];
|
"x86_64-darwin"
|
||||||
|
"aarch64-darwin"
|
||||||
|
];
|
||||||
|
|
||||||
forAllSystems = function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system});
|
forAllSystems =
|
||||||
in {
|
function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system});
|
||||||
packages = forAllSystems (pkgs: rec {
|
in
|
||||||
default = trok;
|
{
|
||||||
trok = pkgs.callPackage ./default.nix {};
|
packages = forAllSystems (pkgs: rec {
|
||||||
});
|
default = trok;
|
||||||
|
trok = pkgs.callPackage ./package.nix { };
|
||||||
|
});
|
||||||
|
|
||||||
nixosModules.default = ./module.nix;
|
nixosModules.default = ./module.nix;
|
||||||
|
|
||||||
devShells = forAllSystems (pkgs: {
|
devShells = forAllSystems (pkgs: {
|
||||||
default = pkgs.callPackage ./shell.nix {};
|
default = pkgs.callPackage ./shell.nix { };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type Trok struct {
|
|||||||
|
|
||||||
func (t *Trok) Init(addr string) error {
|
func (t *Trok) Init(addr string) error {
|
||||||
t.publicConns = make(map[string]Conn)
|
t.publicConns = make(map[string]Conn)
|
||||||
t.webServer = NewTrokWeb(":443")
|
t.webServer = NewTrokWeb(":1338")
|
||||||
err := t.controlServer.Init(addr, "Controller")
|
err := t.controlServer.Init(addr, "Controller")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/tuxdotrs/trok/internal/web"
|
"github.com/tuxdotrs/trok/internal/web"
|
||||||
"golang.org/x/crypto/acme/autocert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TrokWeb struct {
|
type TrokWeb struct {
|
||||||
@@ -36,29 +34,7 @@ func (t *TrokWeb) Start() {
|
|||||||
Browse: true,
|
Browse: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
cfg := t.GetTLSCert()
|
log.Panic().Err(t.app.Listen(t.addr)).Msg("unable to start trok webserver")
|
||||||
|
|
||||||
ln, err := tls.Listen("tcp", t.addr, cfg)
|
|
||||||
if err != nil {
|
|
||||||
log.Panic().Msgf("unable to start trok webserver: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.app.Listener(ln)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TrokWeb) GetTLSCert() *tls.Config {
|
|
||||||
m := &autocert.Manager{
|
|
||||||
Prompt: autocert.AcceptTOS,
|
|
||||||
HostPolicy: autocert.HostWhitelist("trok.cloud"),
|
|
||||||
Cache: autocert.DirCache("./certs"),
|
|
||||||
}
|
|
||||||
|
|
||||||
return &tls.Config{
|
|
||||||
GetCertificate: m.GetCertificate,
|
|
||||||
NextProtos: []string{
|
|
||||||
"http/1.1", "acme-tls/1",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrokWeb) Stop() {
|
func (t *TrokWeb) Stop() {
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib; let
|
with lib; let
|
||||||
cfg = config.tux.services.trok;
|
cfg = config.services.trok;
|
||||||
in {
|
in {
|
||||||
options.tux.services.trok = {
|
options.services.trok = {
|
||||||
enable = mkEnableOption "Enable trok";
|
enable = mkEnableOption "Enable trok";
|
||||||
|
|
||||||
host = mkOption {
|
host = mkOption {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ buildGoModule {
|
|||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
license = lib.licenses.mit;
|
license = lib.licenses.mit;
|
||||||
maintainers = with lib.maintainers; [tuxdotrs];
|
maintainers = with lib.maintainers; [ tuxdotrs ];
|
||||||
mainProgram = "trok";
|
mainProgram = "trok";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user