Skip to content

Commit

Permalink
Refactored codebase. (Velocidex#45)
Browse files Browse the repository at this point in the history
Moved config protobuf into config directory. Added a server_vql tag
to prevent server plugins from building in client context.
  • Loading branch information
scudette authored Aug 13, 2019
1 parent 36117b1 commit 274faf9
Show file tree
Hide file tree
Showing 117 changed files with 2,742 additions and 2,623 deletions.
9 changes: 0 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ package actions
import (
"context"

api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto"
)

type ClientAction interface {
Run(config *api_proto.Config,
Run(config *config_proto.Config,
ctx context.Context,
args *crypto_proto.GrrMessage,
output chan<- *crypto_proto.GrrMessage)
Expand Down
8 changes: 4 additions & 4 deletions actions/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import (
"runtime"
"strings"

"github.com/Showmax/go-fqdn"
fqdn "github.com/Showmax/go-fqdn"
"github.com/shirou/gopsutil/host"
actions_proto "www.velocidex.com/golang/velociraptor/actions/proto"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto"
"www.velocidex.com/golang/velociraptor/responder"
)

type GetHostname struct{}

func (self *GetHostname) Run(
config *api_proto.Config,
config *config_proto.Config,
ctx context.Context,
msg *crypto_proto.GrrMessage,
output chan<- *crypto_proto.GrrMessage) {
Expand All @@ -55,7 +55,7 @@ func (self *GetHostname) Run(
type GetPlatformInfo struct{}

func (self *GetPlatformInfo) Run(
config *api_proto.Config,
config *config_proto.Config,
ctx context.Context,
msg *crypto_proto.GrrMessage,
output chan<- *crypto_proto.GrrMessage) {
Expand Down
4 changes: 2 additions & 2 deletions actions/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
assert "github.com/stretchr/testify/assert"
"www.velocidex.com/golang/velociraptor/actions"
actions_proto "www.velocidex.com/golang/velociraptor/actions/proto"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
"www.velocidex.com/golang/velociraptor/config"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto"
"www.velocidex.com/golang/velociraptor/responder"
)

func GetResponsesFromAction(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
action actions.ClientAction,
ctx context.Context,
args *crypto_proto.GrrMessage) []*crypto_proto.GrrMessage {
Expand Down
6 changes: 3 additions & 3 deletions actions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
"context"

actions_proto "www.velocidex.com/golang/velociraptor/actions/proto"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config "www.velocidex.com/golang/velociraptor/config"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto"
"www.velocidex.com/golang/velociraptor/responder"
)

type GetClientInfo struct{}

func (self *GetClientInfo) Run(
config *api_proto.Config,
config *config_proto.Config,
ctx context.Context,
args *crypto_proto.GrrMessage,
output chan<- *crypto_proto.GrrMessage) {
Expand All @@ -47,7 +47,7 @@ func (self *GetClientInfo) Run(
type UpdateForeman struct{}

func (self *UpdateForeman) Run(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
ctx context.Context,
msg *crypto_proto.GrrMessage,
output chan<- *crypto_proto.GrrMessage) {
Expand Down
4 changes: 2 additions & 2 deletions actions/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"sync"

actions_proto "www.velocidex.com/golang/velociraptor/actions/proto"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto"
"www.velocidex.com/golang/velociraptor/logging"
"www.velocidex.com/golang/velociraptor/responder"
Expand Down Expand Up @@ -91,7 +91,7 @@ func NewEventTable(
type UpdateEventTable struct{}

func (self *UpdateEventTable) Run(
config *api_proto.Config,
config *config_proto.Config,
ctx context.Context,
msg *crypto_proto.GrrMessage,
output chan<- *crypto_proto.GrrMessage) {
Expand Down
8 changes: 4 additions & 4 deletions actions/vql.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

humanize "github.com/dustin/go-humanize"
actions_proto "www.velocidex.com/golang/velociraptor/actions/proto"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
artifacts "www.velocidex.com/golang/velociraptor/artifacts"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto"
"www.velocidex.com/golang/velociraptor/logging"
"www.velocidex.com/golang/velociraptor/responder"
Expand All @@ -38,7 +38,7 @@ import (
)

type LogWriter struct {
config_obj *api_proto.Config
config_obj *config_proto.Config
responder *responder.Responder
}

Expand All @@ -54,7 +54,7 @@ func (self *LogWriter) Write(b []byte) (int, error) {
type VQLClientAction struct{}

func (self *VQLClientAction) Run(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
ctx context.Context,
msg *crypto_proto.GrrMessage,
output chan<- *crypto_proto.GrrMessage) {
Expand All @@ -69,7 +69,7 @@ func (self *VQLClientAction) Run(
}

func (self *VQLClientAction) StartQuery(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
ctx context.Context,
responder *responder.Responder,
arg *actions_proto.VQLCollectorArgs) {
Expand Down
7 changes: 4 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
"www.velocidex.com/golang/velociraptor/artifacts"
artifacts_proto "www.velocidex.com/golang/velociraptor/artifacts/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/constants"
"www.velocidex.com/golang/velociraptor/datastore"
"www.velocidex.com/golang/velociraptor/flows"
Expand All @@ -50,7 +51,7 @@ import (
)

type ApiServer struct {
config *api_proto.Config
config *config_proto.Config
server_obj *server.Server
ca_pool *x509.CertPool
}
Expand Down Expand Up @@ -624,7 +625,7 @@ func (self *ApiServer) SetClientMonitoringState(
return in, err
}

func StartServer(config_obj *api_proto.Config, server_obj *server.Server) error {
func StartServer(config_obj *config_proto.Config, server_obj *server.Server) error {
bind_addr := config_obj.API.BindAddress
switch config_obj.API.BindScheme {
case "tcp":
Expand Down Expand Up @@ -678,7 +679,7 @@ func StartServer(config_obj *api_proto.Config, server_obj *server.Server) error
return nil
}

func StartMonitoringService(config_obj *api_proto.Config) {
func StartMonitoringService(config_obj *config_proto.Config) {
bind_addr := fmt.Sprintf("%s:%d",
config_obj.Monitoring.BindAddress,
config_obj.Monitoring.BindPort)
Expand Down
7 changes: 4 additions & 3 deletions api/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
"www.velocidex.com/golang/velociraptor/artifacts"
artifacts_proto "www.velocidex.com/golang/velociraptor/artifacts/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/constants"
file_store "www.velocidex.com/golang/velociraptor/file_store"
)
Expand Down Expand Up @@ -61,7 +62,7 @@ reports:
)

func getArtifactFile(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
name string) (string, error) {

repository, err := artifacts.GetGlobalRepository(config_obj)
Expand Down Expand Up @@ -92,7 +93,7 @@ func getArtifactFile(
return artifact.Raw, nil
}

func setArtifactFile(config_obj *api_proto.Config,
func setArtifactFile(config_obj *config_proto.Config,
in *api_proto.SetArtifactRequest) (
*artifacts_proto.Artifact, error) {

Expand Down Expand Up @@ -153,7 +154,7 @@ func setArtifactFile(config_obj *api_proto.Config,
}

func searchArtifact(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
terms []string,
artifact_type string,
number_of_results uint64) (
Expand Down
6 changes: 3 additions & 3 deletions api/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"net/http"
"time"

api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/gui/assets"
)

func install_static_assets(config_obj *api_proto.Config, mux *http.ServeMux) {
func install_static_assets(config_obj *config_proto.Config, mux *http.ServeMux) {
dir := "/static/"
mux.Handle(dir, http.FileServer(assets.HTTP))
mux.Handle("/favicon.png",
Expand All @@ -39,7 +39,7 @@ func install_static_assets(config_obj *api_proto.Config, mux *http.ServeMux) {
}

func GetTemplateHandler(
config_obj *api_proto.Config, template_name string) (http.Handler, error) {
config_obj *config_proto.Config, template_name string) (http.Handler, error) {
data, err := assets.ReadFile(template_name)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions api/assets_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
"net/http"
"time"

api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/logging"
)

func install_static_assets(config_obj *api_proto.Config, mux *http.ServeMux) {
func install_static_assets(config_obj *config_proto.Config, mux *http.ServeMux) {
logging.GetLogger(config_obj, &logging.FrontendComponent).
Info("GUI will serve files from directory gui/static")
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(
Expand All @@ -44,7 +44,7 @@ func install_static_assets(config_obj *api_proto.Config, mux *http.ServeMux) {
http.StatusMovedPermanently))
}

func GetTemplateHandler(config_obj *api_proto.Config,
func GetTemplateHandler(config_obj *config_proto.Config,
template_name string) (http.Handler, error) {
tmpl, err := template.ParseFiles("gui" + template_name)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/constants"
"www.velocidex.com/golang/velociraptor/logging"
users "www.velocidex.com/golang/velociraptor/users"
)

Expand All @@ -36,7 +36,7 @@ var (
)

func checkUserCredentialsHandler(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
parent http.Handler) http.Handler {

// We are supposed to do the oauth thing.
Expand Down Expand Up @@ -81,21 +81,21 @@ func checkUserCredentialsHandler(

// Need to call logging after auth so it can access
// the USER value in the context.
logging.GetLoggingHandler(config_obj)(parent).ServeHTTP(
GetLoggingHandler(config_obj)(parent).ServeHTTP(
w, r.WithContext(ctx))
})
}

// TODO: Implement this properly.
func IsUserApprovedForClient(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
md *metadata.MD,
client_id string) bool {
return true
}

func getClientApprovalForUser(
config *api_proto.Config,
config *config_proto.Config,
md *metadata.MD,
client_id string) *api_proto.ApprovalList {
result := api_proto.ApprovalList{
Expand Down Expand Up @@ -138,7 +138,7 @@ func GetGRPCUserInfo(ctx context.Context) *api_proto.VelociraptorUser {
return result
}

func NewDefaultUserObject(config_obj *api_proto.Config) *api_proto.ApiGrrUser {
func NewDefaultUserObject(config_obj *config_proto.Config) *api_proto.ApiGrrUser {
result := &api_proto.ApiGrrUser{
InterfaceTraits: &api_proto.ApiGrrUserInterfaceTraits{
CronJobsNavItemEnabled: true,
Expand Down
6 changes: 3 additions & 3 deletions api/client_monitoring.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package api

import (
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/constants"
"www.velocidex.com/golang/velociraptor/datastore"
flows_proto "www.velocidex.com/golang/velociraptor/flows/proto"
"www.velocidex.com/golang/velociraptor/services"
)

func getClientMonitoringState(config_obj *api_proto.Config) (
func getClientMonitoringState(config_obj *config_proto.Config) (
*flows_proto.ArtifactCollectorArgs, error) {
db, err := datastore.GetDB(config_obj)
if err != nil {
Expand All @@ -25,7 +25,7 @@ func getClientMonitoringState(config_obj *api_proto.Config) (
}

func setClientMonitoringState(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
args *flows_proto.ArtifactCollectorArgs) error {
return services.UpdateClientEventTable(config_obj, args)
}
5 changes: 3 additions & 2 deletions api/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import (

actions_proto "www.velocidex.com/golang/velociraptor/actions/proto"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/constants"
"www.velocidex.com/golang/velociraptor/datastore"
"www.velocidex.com/golang/velociraptor/server"
urns "www.velocidex.com/golang/velociraptor/urns"
)

func GetApiClient(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
server_obj *server.Server,
client_id string, detailed bool) (
*api_proto.ApiClient, error) {
Expand Down Expand Up @@ -122,7 +123,7 @@ func GetApiClient(
}

func LabelClients(
config_obj *api_proto.Config,
config_obj *config_proto.Config,
in *api_proto.LabelClientsRequest) (*api_proto.APIResponse, error) {
db, err := datastore.GetDB(config_obj)
if err != nil {
Expand Down
Loading

0 comments on commit 274faf9

Please sign in to comment.