dkforest

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

config.go (6058B)


      1 package config
      2 
      3 import (
      4 	"dkforest/pkg/utils/rwmtx"
      5 	"embed"
      6 	wallet1 "github.com/monero-ecosystem/go-monero-rpc-client/wallet"
      7 	"net"
      8 	"sync"
      9 	"time"
     10 
     11 	"dkforest/pkg/atom"
     12 	"dkforest/pkg/ratecounter"
     13 	version "github.com/hashicorp/go-version"
     14 )
     15 
     16 const (
     17 	GogsURL                = "http://127.0.0.1:3000"
     18 	DbFileName             = "dkf.db"
     19 	AppDirName             = ".dkf"
     20 	MaxUserFileUploadSize  = 30 << 20  // 30 MB
     21 	MaxUserTotalUploadSize = 100 << 20 // 100 MB
     22 	MaxAvatarFormSize      = 1 << 20   // 1 MB
     23 	MaxAvatarSize          = 300 << 10 // 300 KB
     24 
     25 	// MaxFileSizeBeforeDownload files that are bigger than this limit will trigger
     26 	// a file download instead of simple in-browser rendering
     27 	MaxFileSizeBeforeDownload = 1 << 20 // 1 MB
     28 )
     29 
     30 // DefaultMasterKey Should be overwritten using ldflags
     31 var DefaultMasterKey = "Ucn%1fw%bPz3<Ir}lJD6H!X+fP47j]c2"
     32 var GistPasswordSalt = "gist_pa$$word_$alt_tdjfPAgjyNdor"
     33 var RoomPasswordSalt = "room_pa$$word_$alt_OYvUwmNPVTdsw"
     34 
     35 const (
     36 	DkfOnion     = "http://dkforestseeaaq2dqz2uflmlsybvnq2irzn4ygyvu53oazyorednviid.onion"
     37 	DkfGitOnion  = "http://git.dkforestseeaaq2dqz2uflmlsybvnq2irzn4ygyvu53oazyorednviid.onion"
     38 	I2pGitOnion  = "http://git.dkforest4gwaceahf4te3vs7ycddtbpf2lucocxdzhphezikdgnq.b32.i2p"
     39 	DkfGit1Onion = "http://yylovpz7taca7jfrub3wltxabzzjp34fngj5lpwl6eo47ekt5cxs6mid.onion"
     40 	DreadOnion   = "http://dreadytofatroptsdj6io7l3xptbet6onoyno2yv7jicoxknyazubrad.onion"
     41 	BhcOnion     = "http://blkhatjxlrvc5aevqzz5t6kxldayog6jlx5h7glnu44euzongl4fh5ad.onion"
     42 	CryptbbOnion = "http://cryptbbtg65gibadeeo2awe3j7s6evg7eklserehqr4w4e2bis5tebid.onion"
     43 	DnmxOnion    = "http://hxuzjtocnzvv5g2rtg2bhwkcbupmk7rclb6lly3fo4tvqkk5oyrv3nid.onion"
     44 	WhonixOnion  = "http://dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion"
     45 	AgeUrl       = "https://github.com/FiloSottile/age"
     46 )
     47 
     48 const (
     49 	RootAdminID           = 1
     50 	GeneralRoomID         = 1
     51 	AnnouncementsRoomName = "announcements"
     52 )
     53 
     54 const PowDifficulty = 7
     55 
     56 const EditMessageTimeLimit = 2 * time.Minute
     57 
     58 const NullUsername = "0"
     59 
     60 var NullUserPrivateKey string
     61 var NullUserPublicKey string
     62 
     63 // Global ...
     64 var Global = NewGlobalConf()
     65 var (
     66 	Development = atom.NewBool(true) // either or not the instance is running in development mode
     67 
     68 	IsFirstUse               = atom.NewBool(true)  // either or not we need to set up root account
     69 	MaybeAuthEnabled         = atom.NewBool(true)  // either or not unauthenticated users can access the "maybe auth" pages
     70 	ForumEnabled             = atom.NewBool(true)  // either or not people can use the forum features
     71 	SilentSelfKick           = atom.NewBool(true)  // either or not self kick are silent
     72 	SignupEnabled            = atom.NewBool(true)  // either or not people can sign up
     73 	PowEnabled               = atom.NewBool(false) // either or not pow is enabled to signup
     74 	PokerWithdrawEnabled     = atom.NewBool(true)  // either or not poker withdraw is enabled
     75 	SignupFakeEnabled        = atom.NewBool(true)  // either or not signup is faked to be enabled
     76 	ProtectHome              = atom.NewBool(true)  // enable "dynamic login url" to prevent ddos on the login page
     77 	HomeUsersList            = atom.NewBool(true)  // either or not to display the online users on the login page
     78 	ForceLoginCaptcha        = atom.NewBool(true)  // either or not people are forced to complete captcha at login
     79 	DownloadsEnabled         = atom.NewBool(true)  // either or not people can download files
     80 	MaintenanceAtom          = atom.NewBool(false) // people are redirected to a maintenance page
     81 	CaptchaDifficulty        = atom.NewInt64(1)    // captcha difficulty
     82 	SignupPageLoad           = atom.NewInt64(0)
     83 	SignupFailed             = atom.NewInt64(0)
     84 	SignupSucceed            = atom.NewInt64(0)
     85 	BHCCaptchaFailed         = atom.NewInt64(0)
     86 	BHCCaptchaSuccess        = atom.NewInt64(0)
     87 	BHCCaptchaGenerated      = atom.NewInt64(0)
     88 	CaptchaRequiredGenerated = atom.NewInt64(0)
     89 	CaptchaRequiredSuccess   = atom.NewInt64(0)
     90 	CaptchaRequiredFailed    = atom.NewInt64(0)
     91 	MoneroPrice              = atom.NewFloat64(0)
     92 
     93 	RpsCounter         = ratecounter.NewRateCounter()
     94 	RejectedReqCounter = ratecounter.NewRateCounter()
     95 )
     96 
     97 var MigrationsFs embed.FS
     98 var LocalsFs embed.FS
     99 
    100 var once sync.Once
    101 var instance wallet1.Client
    102 
    103 func Xmr() wallet1.Client {
    104 	once.Do(func() {
    105 		instance = wallet1.New(wallet1.Config{
    106 			Address: "http://127.0.0.1:6061/json_rpc",
    107 		})
    108 	})
    109 	return instance
    110 }
    111 
    112 type ConnManager struct {
    113 	sync.RWMutex
    114 	m           map[net.Conn]int64
    115 	CircuitIDCh chan int64
    116 }
    117 
    118 func NewConnManager() *ConnManager {
    119 	m := new(ConnManager)
    120 	m.m = make(map[net.Conn]int64)
    121 	m.CircuitIDCh = make(chan int64, 1000)
    122 	return m
    123 }
    124 
    125 func (m *ConnManager) Set(key net.Conn, val int64) {
    126 	m.Lock()
    127 	m.m[key] = val
    128 	m.Unlock()
    129 }
    130 
    131 func (m *ConnManager) Get(key net.Conn) int64 {
    132 	m.RLock()
    133 	val, found := m.m[key]
    134 	if !found {
    135 		m.RUnlock()
    136 		return 0
    137 	}
    138 	m.RUnlock()
    139 	return val
    140 }
    141 
    142 func (m *ConnManager) Delete(key net.Conn) {
    143 	m.Lock()
    144 	delete(m.m, key)
    145 	m.Unlock()
    146 }
    147 
    148 func (m *ConnManager) Close(key net.Conn) {
    149 	circuitID := m.Get(key)
    150 	m.CloseCircuit(circuitID)
    151 }
    152 
    153 func (m *ConnManager) CloseCircuit(circuitID int64) {
    154 	select {
    155 	case m.CircuitIDCh <- circuitID:
    156 	default:
    157 	}
    158 }
    159 
    160 var ConnMap = NewConnManager()
    161 
    162 // GlobalConf ...
    163 type GlobalConf struct {
    164 	AppVersion           rwmtx.RWMtx[*version.Version]
    165 	ProjectPath          rwmtx.RWMtx[string] // project path
    166 	ProjectLocalsPath    rwmtx.RWMtx[string] // directory where we keep custom translation files
    167 	ProjectHTMLPath      rwmtx.RWMtx[string]
    168 	ProjectMemesPath     rwmtx.RWMtx[string]
    169 	ProjectUploadsPath   rwmtx.RWMtx[string]
    170 	ProjectFiledropPath  rwmtx.RWMtx[string]
    171 	ProjectDownloadsPath rwmtx.RWMtx[string]
    172 	Sha                  rwmtx.RWMtx[string]
    173 	MasterKey            rwmtx.RWMtx[string]
    174 	CookieSecure         rwmtx.RWMtx[bool]
    175 	CookieDomain         rwmtx.RWMtx[string]
    176 	BaseURL              rwmtx.RWMtx[string] // (http://127.0.0.1:8080)
    177 }
    178 
    179 // NewGlobalConf ...
    180 func NewGlobalConf() *GlobalConf {
    181 	c := new(GlobalConf)
    182 	c.MasterKey.Set(DefaultMasterKey)
    183 	return c
    184 }