mirror of
				https://github.com/boringproxy/boringproxy.git
				synced 2025-02-25 18:55:29 -06:00 
			
		
		
		
	Add db-dir to specify where to save boringproxy_db.json
This commit is contained in:
		| @@ -46,6 +46,7 @@ func Listen() { | ||||
| 	flagSet := flag.NewFlagSet(os.Args[0], flag.ExitOnError) | ||||
| 	newAdminDomain := flagSet.String("admin-domain", "", "Admin Domain") | ||||
| 	sshServerPort := flagSet.Int("ssh-server-port", 22, "SSH Server Port") | ||||
| 	dbDir := flagSet.String("db-dir", "", "Database file directory") | ||||
| 	certDir := flagSet.String("cert-dir", "", "TLS cert directory") | ||||
| 	printLogin := flagSet.Bool("print-login", false, "Prints admin login information") | ||||
| 	httpPort := flagSet.Int("http-port", 80, "HTTP (insecure) port") | ||||
| @@ -61,7 +62,7 @@ func Listen() { | ||||
|  | ||||
| 	log.Println("Starting up") | ||||
|  | ||||
| 	db, err := NewDatabase() | ||||
| 	db, err := NewDatabase(*dbDir) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										12
									
								
								database.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								database.go
									
									
									
									
									
								
							| @@ -10,6 +10,8 @@ import ( | ||||
| 	"github.com/takingnames/namedrop-go" | ||||
| ) | ||||
|  | ||||
| var DBFolderPath string | ||||
|  | ||||
| type Database struct { | ||||
| 	AdminDomain string                         `json:"admin_domain"` | ||||
| 	Tokens      map[string]TokenData           `json:"tokens"` | ||||
| @@ -60,11 +62,13 @@ type Tunnel struct { | ||||
| 	AuthPassword string `json:"auth_password"` | ||||
| } | ||||
|  | ||||
| func NewDatabase() (*Database, error) { | ||||
| func NewDatabase(path string) (*Database, error) { | ||||
|  | ||||
| 	dbJson, err := ioutil.ReadFile("boringproxy_db.json") | ||||
| 	DBFolderPath = path | ||||
|  | ||||
| 	dbJson, err := ioutil.ReadFile(DBFolderPath + "boringproxy_db.json") | ||||
| 	if err != nil { | ||||
| 		log.Println("failed reading boringproxy_db.json") | ||||
| 		log.Printf("failed reading %sboringproxy_db.json\n", DBFolderPath) | ||||
| 		dbJson = []byte("{}") | ||||
| 	} | ||||
|  | ||||
| @@ -319,5 +323,5 @@ func (d *Database) DeleteUser(username string) { | ||||
| } | ||||
|  | ||||
| func (d *Database) persist() { | ||||
| 	saveJson(d, "boringproxy_db.json") | ||||
| 	saveJson(d, DBFolderPath+"boringproxy_db.json") | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user