1
0
Fork 0
Bsian 2019-12-28 03:12:22 +00:00
commit 9a47286889
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
3 changed files with 94 additions and 28 deletions

View File

@ -1,6 +1,5 @@
echo "Library of Code sp-us | Cloud Services" # This file builds the Go binaries. Hardcoded by LOC Engineering
echo "TypeScript & Go" go build -o dist/bin/storage src/go/storage/storage.go src/go/storage/dirsize.go
echo "Building TS files" file dist/bin/storage
yarn run build go build -o dist/bin/checkCertificate src/go/checkCertificate/checkCertificate.go
echo "Building Go files" file dist/bin/checkCertificate
go build -o dist/intervals/storage src/intervals/storage.go src/intervals/dirsize.go

View File

@ -0,0 +1,61 @@
import { Client } from '..';
export interface Certificate {
subject: {
commonName: string,
emailAddress: string
organizationName: string,
organizationalUnitName: string,
countryName: string,
},
issuer: {
commonName: string
emailAddress: null,
organizationName: string,
organizationalUnitName: string,
countryName: string,
},
extensions: {
keyUsage: '[ Not implemented by executable ]',
extendedKeyUsage: string[],
certificatePolicies: string[],
},
serial: string,
fingerPrint: string,
signatureAlgorithm: string,
publicKeyAlgorithm: string,
notBefore: Date,
notAfter: Date,
}
export default async function parseCertificate(client: Client, pathToCertificate: string): Promise<Certificate> {
const result = await client.util.exec(`${__dirname}/../bin/checkCertificate ${pathToCertificate}`);
const parsedObject = JSON.parse(result);
return {
subject: {
commonName: parsedObject.RawParse.Subject.CommonName,
emailAddress: parsedObject.AbstractParse.EmailAddress,
organizationName: parsedObject.RawParse.Subject.Organization[0],
organizationalUnitName: parsedObject.RawParse.Subject.OrganizationalUnit[0],
countryName: parsedObject.RawParse.Subject.Country[0],
},
issuer: {
commonName: parsedObject.RawParse.Issuer.CommonName,
emailAddress: null,
organizationName: parsedObject.RawParse.Issuer.Organization[0],
organizationalUnitName: parsedObject.RawParse.Issuer.OrganizationalUnit[0],
countryName: parsedObject.RawParse.Issuer.Country[0],
},
extensions: {
keyUsage: '[ Not implemented by executable ]',
extendedKeyUsage: parsedObject.AbstractParse.ExtendedKeyUsage,
certificatePolicies: parsedObject.AbstractParse.PolicyIdentifiers,
},
serial: parsedObject.AbstractParse.SerialNumber,
fingerPrint: parsedObject.AbstractParse.FingerPrint,
signatureAlgorithm: parsedObject.AbstractParse.SignatureAlgorithm,
publicKeyAlgorithm: parsedObject.AbstractParse.PublicKeyAlgorithm,
notBefore: new Date(parsedObject.RawParse.NotBefore),
notAfter: new Date(parsedObject.RawParse.NotAfter),
};
}

View File

@ -9,8 +9,8 @@ import (
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
"io/ioutil" "io/ioutil"
"time" "strings"
"strings" "time"
) )
// Collection the MongoDB Account collection // Collection the MongoDB Account collection
@ -39,6 +39,7 @@ func HandleError(e error, serv int) {
} }
func main() { func main() {
var status bool
type Config struct { type Config struct {
MongoDB string `json:"mongoURL"` MongoDB string `json:"mongoURL"`
} }
@ -52,11 +53,11 @@ func main() {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = client.Connect(ctx) err = client.Connect(ctx)
HandleError(err, 1) HandleError(err, 1)
err = client.Ping(context.TODO(), nil) err = client.Ping(context.TODO(), nil)
fmt.Printf("Connected to MongoDB [GO]\n") fmt.Printf("Connected to MongoDB [GO]\n")
HandleError(err, 1) HandleError(err, 1)
Collection = client.Database("cloudservices").Collection("accounts") Collection = client.Database("cloudservices").Collection("accounts")
RedisClient = redis.NewClient(&redis.Options{ RedisClient = redis.NewClient(&redis.Options{
Addr: "localhost:6379", Addr: "localhost:6379",
@ -64,36 +65,41 @@ func main() {
DB: 0, DB: 0,
}) })
_, err = RedisClient.Ping().Result() _, err = RedisClient.Ping().Result()
fmt.Printf("Connected to Redis [GO]\n") fmt.Printf("Connected to Redis [GO]\n")
HandleError(err, 1) HandleError(err, 1)
status = false
for { for {
fmt.Printf("Calling handler func [GO]\n") fmt.Printf("Calling handler func [GO]\n")
handler() if status == false {
time.Sleep(1000000 * time.Millisecond) handler(&status)
} time.Sleep(1000000 * time.Millisecond)
}
}
} }
func handler() { func handler(status* bool) {
*status = true
cur, err := Collection.Find(context.TODO(), bson.D{}) cur, err := Collection.Find(context.TODO(), bson.D{})
HandleError(err, 0) HandleError(err, 0)
for cur.Next(context.TODO()) { for cur.Next(context.TODO()) {
go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String()) go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String())
fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String()) fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String())
time.Sleep(600000 * time.Millisecond) time.Sleep(600000 * time.Millisecond)
} }
*status = false
} }
func checkAccountSizeAndUpdate(username string, id string) { func checkAccountSizeAndUpdate(username string, id string) {
var size float64 = 0 var size float64 = 0
var userHomeDirectory string = strings.Replace(strings.Join([]string{"/home/", string(username)}, ""), "\"", "", -1) var userHomeDirectory string = strings.Replace(strings.Join([]string{"/home/", string(username)}, ""), "\"", "", -1)
fmt.Println(userHomeDirectory) fmt.Println(userHomeDirectory)
sizeHome := DirSize(&userHomeDirectory) sizeHome := DirSize(&userHomeDirectory)
size += sizeHome size += sizeHome
sizeMail := DirSize(&userHomeDirectory) sizeMail := DirSize(&userHomeDirectory)
size += sizeMail size += sizeMail
RedisClient.Set("storage"+"-"+string(id), size, 0) RedisClient.Set("storage"+"-"+string(id), size, 0)
fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f\n", string(username), string(id), size) fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f\n", string(username), string(id), size)
} }