dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

main.go (2919B)


      1 package main
      2 
      3 import (
      4 	"dkforest/pkg/actions"
      5 	"dkforest/pkg/config"
      6 	"dkforest/pkg/utils"
      7 	"embed"
      8 	_ "embed"
      9 	b64 "encoding/base64"
     10 	"fmt"
     11 	versionPkg "github.com/hashicorp/go-version"
     12 	_ "github.com/mattn/go-sqlite3"
     13 	cli "github.com/urfave/cli/v2"
     14 	"log"
     15 	"math/rand"
     16 	_ "net/http/pprof"
     17 	"os"
     18 	"strings"
     19 )
     20 
     21 // These variables are overwritten during the build process using ldflags
     22 // "version" is base64 encoded to make it harder for a hacker to change
     23 // the value by simply ctrl+f & replace the compiled binary file.
     24 var version = "MTAwMC4wLjAK" // Base64 encoded (`echo '1000.0.0' | base64`)
     25 var versionVoid = ""         // Useless, just to confuse hackers :)
     26 var sha = ""
     27 var development = "1"
     28 
     29 //go:embed 0_gpg_private_key
     30 var nullPrivateKey []byte
     31 
     32 //go:embed 0_gpg_public_key
     33 var nullPublicKey []byte
     34 
     35 //go:embed master_key
     36 var masterKey []byte
     37 
     38 //go:embed gist_password_salt
     39 var gistPasswordSalt []byte
     40 
     41 //go:embed room_password_salt
     42 var roomPasswordSalt []byte
     43 
     44 //go:embed migrations
     45 var migrationsFs embed.FS
     46 
     47 //go:embed locals
     48 var localsFs embed.FS
     49 
     50 // This is purely useless, the print will never happen. This is only to fuck with
     51 // hackers by adding useless strings in the final compiled binary file.
     52 func void(nothing string) {
     53 	if rand.Int() == -1 {
     54 		fmt.Println(nothing)
     55 	}
     56 }
     57 
     58 func main() {
     59 	void(versionVoid)
     60 	versionDecodedBytes, _ := b64.StdEncoding.DecodeString(version)
     61 	versionDecoded := strings.TrimSpace(string(versionDecodedBytes))
     62 	config.Global.AppVersion.Set(versionPkg.Must(versionPkg.NewVersion(versionDecoded)))
     63 	developmentFlag := utils.DoParseBool(development)
     64 	config.Development.Store(developmentFlag)
     65 	config.NullUserPrivateKey = string(nullPrivateKey)
     66 	config.NullUserPublicKey = string(nullPublicKey)
     67 	config.Global.MasterKey.Set(string(masterKey))
     68 	config.GistPasswordSalt = string(gistPasswordSalt)
     69 	config.RoomPasswordSalt = string(roomPasswordSalt)
     70 	config.MigrationsFs = migrationsFs
     71 	config.LocalsFs = localsFs
     72 
     73 	app := cli.App{}
     74 	app.Authors = []*cli.Author{
     75 		{Name: "n0tr1v", Email: "n0tr1v@protonmail.com"},
     76 	}
     77 	app.Name = "darkforest"
     78 	app.Usage = "Tor service"
     79 	app.Version = version
     80 	app.Flags = []cli.Flag{
     81 		&cli.StringFlag{
     82 			Name:    "host",
     83 			Value:   "127.0.0.1",
     84 			EnvVars: []string{"DKF_HOST"},
     85 		},
     86 		&cli.IntFlag{
     87 			Name:    "port",
     88 			Value:   8080,
     89 			EnvVars: []string{"DKF_PORT"},
     90 		},
     91 		&cli.BoolFlag{
     92 			Name:    "no-browser",
     93 			Usage:   "Do not open the browser automatically",
     94 			EnvVars: []string{"DKF_NO_BROWSER"},
     95 		},
     96 		&cli.StringFlag{
     97 			Name:    "cookie-domain",
     98 			EnvVars: []string{"DKF_COOKIE_DOMAIN"},
     99 		},
    100 		&cli.BoolFlag{
    101 			Name:    "cookie-secure",
    102 			EnvVars: []string{"DKF_COOKIE_SECURE"},
    103 		},
    104 	}
    105 	app.Commands = []*cli.Command{
    106 		{
    107 			Name:   "build-prohibited-passwords",
    108 			Action: actions.BuildProhibitedPasswords,
    109 		},
    110 	}
    111 	app.Action = actions.Start
    112 	if err := app.Run(os.Args); err != nil {
    113 		log.Fatal(err)
    114 	}
    115 }