Skip to content

Commit

Permalink
1.31.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-timcu committed Jul 4, 2024
1 parent 253a34a commit a6fde1d
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ aikido-*-extension-php-*.so
.vscode/settings.json
src/extension/ndDb2pJ5Px
*.deb
package/deb/opt/aikido/aikido-1.30.0*
package/deb/opt/aikido/aikido-1.31.0*
src/agent/aikido_config.json
2 changes: 1 addition & 1 deletion include/php_aikido.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern zend_module_entry aikido_module_entry;
# define phpext_aikido_ptr &aikido_module_entry

# define PHP_AIKIDO_VERSION "1.30.0"
# define PHP_AIKIDO_VERSION "1.31.0"

# if defined(ZTS) && defined(COMPILE_DL_AIKIDO)
ZEND_TSRMLS_CACHE_EXTERN()
Expand Down
2 changes: 1 addition & 1 deletion package/deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: aikido-firewall-php
Version: 1.30.0
Version: 1.31.0
Section: base
Priority: optional
Architecture: all
Expand Down
2 changes: 1 addition & 1 deletion package/deb/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="1.30.0"
VERSION="1.31.0"

declare -A php_api_versions

Expand Down
2 changes: 1 addition & 1 deletion package/rpm/aikido.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: aikido-php-firewall
Version: 1.30.0
Version: 1.31.0
Release: 1
Summary: Aikido PHP extension and agent

Expand Down
2 changes: 1 addition & 1 deletion rpm_build_and_install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rm -rf ~/rpmbuild
rpmdev-setuptree

VERSION="1.30.0"
VERSION="1.31.0"

mkdir -p ~/rpmbuild/SOURCES/aikido-php-firewall-$VERSION
cp -rf package/rpm/etc ~/rpmbuild/SOURCES/aikido-php-firewall-$VERSION/
Expand Down
2 changes: 1 addition & 1 deletion rpm_uninstall.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rpm -e aikido-php-firewall-1.30.0-1.x86_64
rpm -e aikido-php-firewall-1.31.0-1.x86_64
2 changes: 1 addition & 1 deletion src/agent/globals/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package globals

const (
Version = "1.30.0"
Version = "1.31.0"
ConfigFilePath = "/opt/aikido/config.json"
DevConfigFilePath = "/opt/aikido/config-dev.json"
LogFilePath = "/var/log/aikido/aikido.log"
Expand Down
49 changes: 29 additions & 20 deletions src/lib/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,53 @@ import (
"context"
"fmt"
"main/log"
"net"
"os"
"sync"
"time"

"main/ipc/protos"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/grpclog"
)

const socketPath = "/run/aikido.sock"

var conn *grpc.ClientConn
var rootCtx = context.Background()
var mainCtx, mainCxl = context.WithCancel(rootCtx)

func unixDialer(ctx context.Context, addr string) (net.Conn, error) {
var d net.Dialer
log.Debugf("Unix dialer called: %v %v", ctx, addr)
return d.DialContext(ctx, "unix", addr)
}
var client protos.AikidoClient
var mu sync.Mutex

func Init() {
mu.Lock()
defer mu.Unlock()

var err error
conn, err = grpc.Dial(
socketPath,
"unix://"+socketPath,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithContextDialer(unixDialer),
)
if err != nil {
panic(fmt.Sprintf("did not connect: %v", err))
}

client = protos.NewAikidoClient(conn)

log.Debug("Initialized gRPC client!")
}

func Uninit() {
mainCxl()
mu.Lock()
defer mu.Unlock()

conn.Close()
}

func OnReceiveToken() {
client := protos.NewAikidoClient(conn)
mu.Lock()
defer mu.Unlock()

log.Infof("Client: %v", client)

token := os.Getenv("AIKIDO_TOKEN")
Expand All @@ -57,7 +60,7 @@ func OnReceiveToken() {
}
log.Info("Sending token: ", token)

ctx, cancel := context.WithTimeout(mainCtx, 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

_, err := client.OnReceiveToken(ctx, &protos.Token{Token: token})
Expand All @@ -68,7 +71,9 @@ func OnReceiveToken() {
}

func OnReceiveLogLevel() {
client := protos.NewAikidoClient(conn)
mu.Lock()
defer mu.Unlock()

log.Infof("Client: %v", client)

log_level := os.Getenv("AIKIDO_LOG_LEVEL")
Expand All @@ -78,9 +83,8 @@ func OnReceiveLogLevel() {
}
log.Info("Sending log level: ", log_level)

ctx, cancel := context.WithTimeout(mainCtx, 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

_, err := client.OnReceiveLogLevel(ctx, &protos.LogLevel{LogLevel: log_level})
if err != nil {
log.Debugf("Could not send log level %v: %v", log_level, err)
Expand All @@ -89,13 +93,18 @@ func OnReceiveLogLevel() {
}

func OnReceiveDomain(domain string) {
client := protos.NewAikidoClient(conn)
mu.Lock()
defer mu.Unlock()

log.Infof("Client: %v", client)

ctx, cancel := context.WithTimeout(mainCtx, 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

log.Infof("Ctx: %v", ctx)
// Setup gRPC logging to a file
grpclog.SetLoggerV2(grpclog.NewLoggerV2(log.Logger.Writer(), log.Logger.Writer(), log.Logger.Writer()))

log.Infof("Client: %v", client)

_, err := client.OnReceiveDomain(ctx, &protos.Domain{Domain: domain})
if err != nil {
Expand Down

0 comments on commit a6fde1d

Please sign in to comment.