-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,130 additions
and
1,045 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cert | ||
|
||
import ( | ||
"flag" | ||
|
||
"github.com/p4gefau1t/trojan-go/common" | ||
) | ||
|
||
type certOption struct { | ||
args *string | ||
common.OptionHandler | ||
} | ||
|
||
func (*certOption) Name() string { | ||
return "cert" | ||
} | ||
|
||
func (*certOption) Priority() int { | ||
return 10 | ||
} | ||
|
||
func (c *certOption) Handle() error { | ||
switch *c.args { | ||
case "request": | ||
RequestCertGuide() | ||
return nil | ||
case "renew": | ||
RenewCertGuide() | ||
return nil | ||
case "INVALID": | ||
return common.NewError("not specified") | ||
default: | ||
err := common.NewError("invalid args " + *c.args) | ||
logger.Error(err) | ||
return common.NewError("invalid args") | ||
} | ||
} | ||
|
||
func init() { | ||
common.RegisterOptionHandler(&certOption{ | ||
args: flag.String("cert", "INVALID", "Simple letsencrpyt cert acme client. Use \"-cert request\" to request a cert or \"-cert renew\" to renew a cert"), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package common | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func ConnectDatabase(driverName, username, password, ip string, port int, dbName string) (*sql.DB, error) { | ||
path := strings.Join([]string{username, ":", password, "@tcp(", ip, ":", fmt.Sprintf("%d", port), ")/", dbName, "?charset=utf8"}, "") | ||
return sql.Open(driverName, path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package common | ||
|
||
type OptionHandler interface { | ||
Name() string | ||
Handle() error | ||
Priority() int | ||
} | ||
|
||
var handlers map[string]OptionHandler = make(map[string]OptionHandler) | ||
|
||
func RegisterOptionHandler(h OptionHandler) { | ||
handlers[h.Name()] = h | ||
} | ||
|
||
func PopOptionHandler() (OptionHandler, error) { | ||
var maxHandler OptionHandler = nil | ||
for _, h := range handlers { | ||
if maxHandler == nil || maxHandler.Priority() < h.Priority() { | ||
maxHandler = h | ||
} | ||
} | ||
if maxHandler == nil { | ||
return nil, NewError("no option left") | ||
} | ||
delete(handlers, maxHandler.Name()) | ||
return maxHandler, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.