MCPcopy Index your code
hub / github.com/bettercap/bettercap / NewRestAPI

Function NewRestAPI

modules/api_rest/api_rest.go:45–159  ·  view source on GitHub ↗
(s *session.Session)

Source from the content-addressed store, hash-verified

43}
44
45func NewRestAPI(s *session.Session) *RestAPI {
46 mod := &RestAPI{
47 SessionModule: session.NewSessionModule("api.rest", s),
48 server: &http.Server{},
49 quit: make(chan bool),
50 useWebsocket: false,
51 allowOrigin: "*",
52 upgrader: websocket.Upgrader{
53 ReadBufferSize: 1024,
54 WriteBufferSize: 1024,
55 },
56 recClock: 1,
57 recording: false,
58 recTime: 0,
59 loading: false,
60 replaying: false,
61 recordFileName: "",
62 recordWait: &sync.WaitGroup{},
63 record: nil,
64 }
65
66 mod.State.Store("recording", &mod.recording)
67 mod.State.Store("rec_clock", &mod.recClock)
68 mod.State.Store("replaying", &mod.replaying)
69 mod.State.Store("loading", &mod.loading)
70 mod.State.Store("load_progress", 0)
71 mod.State.Store("rec_time", &mod.recTime)
72 mod.State.Store("rec_filename", &mod.recordFileName)
73 mod.State.Store("rec_frames", 0)
74 mod.State.Store("rec_cur_frame", 0)
75 mod.State.Store("rec_started", &mod.recStarted)
76 mod.State.Store("rec_stopped", &mod.recStopped)
77
78 mod.AddParam(session.NewStringParameter("api.rest.address",
79 "127.0.0.1",
80 session.IPv4Validator,
81 "Address to bind the API REST server to."))
82
83 mod.AddParam(session.NewIntParameter("api.rest.port",
84 "8081",
85 "Port to bind the API REST server to."))
86
87 mod.AddParam(session.NewStringParameter("api.rest.alloworigin",
88 mod.allowOrigin,
89 "",
90 "Value of the Access-Control-Allow-Origin header of the API server."))
91
92 mod.AddParam(session.NewStringParameter("api.rest.username",
93 "user",
94 "",
95 "API authentication username."))
96
97 mod.AddParam(session.NewStringParameter("api.rest.password",
98 "pass",
99 "",
100 "API authentication password."))
101
102 mod.AddParam(session.NewStringParameter("api.rest.certificate",

Callers 15

LoadModulesFunction · 0.92
TestNewRestAPIFunction · 0.85
TestIsTLSFunction · 0.85
TestStateStoreFunction · 0.85
TestParametersFunction · 0.85
TestDefaultValuesFunction · 0.85
TestRunningStateFunction · 0.85
TestRecordingStateFunction · 0.85
TestReplayingStateFunction · 0.85
TestConfigureErrorsFunction · 0.85
TestServerConfigurationFunction · 0.85
TestQuitChannelFunction · 0.85

Calls 14

StartMethod · 0.95
StopMethod · 0.95
stopRecordingMethod · 0.95
startRecordingMethod · 0.95
stopReplayMethod · 0.95
startReplayMethod · 0.95
NewSessionModuleFunction · 0.92
NewStringParameterFunction · 0.92
NewIntParameterFunction · 0.92
CertConfigToModuleFunction · 0.92
NewBoolParameterFunction · 0.92
NewModuleHandlerFunction · 0.92

Tested by 15

TestNewRestAPIFunction · 0.68
TestIsTLSFunction · 0.68
TestStateStoreFunction · 0.68
TestParametersFunction · 0.68
TestDefaultValuesFunction · 0.68
TestRunningStateFunction · 0.68
TestRecordingStateFunction · 0.68
TestReplayingStateFunction · 0.68
TestConfigureErrorsFunction · 0.68
TestServerConfigurationFunction · 0.68
TestQuitChannelFunction · 0.68
TestRecordWaitGroupFunction · 0.68