new: new api.rest.alloworigin parameter to customize the Access-Control-Allow-Origin header of the server.

This commit is contained in:
evilsocket 2018-09-29 02:10:46 +02:00
parent 2b117e14d6
commit 8f7f6545b1
2 changed files with 18 additions and 10 deletions

View file

@ -22,6 +22,7 @@ type RestAPI struct {
password string
certFile string
keyFile string
allowOrigin string
useWebsocket bool
upgrader websocket.Upgrader
quit chan bool
@ -33,6 +34,7 @@ func NewRestAPI(s *session.Session) *RestAPI {
server: &http.Server{},
quit: make(chan bool),
useWebsocket: false,
allowOrigin: "*",
upgrader: websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
@ -48,6 +50,10 @@ func NewRestAPI(s *session.Session) *RestAPI {
"8081",
"Port to bind the API REST server to."))
api.AddParam(session.NewIntParameter("api.rest.alloworigin",
api.allowOrigin,
"Value of the Access-Control-Allow-Origin header of the API server."))
api.AddParam(session.NewStringParameter("api.rest.username",
"",
"",
@ -124,6 +130,8 @@ func (api *RestAPI) Configure() error {
return err
} else if err, port = api.IntParam("api.rest.port"); err != nil {
return err
} else if err, api.allowOrigin = api.StringParam("api.rest.alloworigin"); err != nil {
return err
} else if err, api.certFile = api.StringParam("api.rest.certificate"); err != nil {
return err
} else if api.certFile, err = core.ExpandPath(api.certFile); err != nil {