Compare commits

..

4 Commits

  1. 116
      DocStract/file.go
  2. 10
      DocStract/go.mod
  3. 6
      DocStract/go.sum
  4. 20
      DocStract/helpers.go
  5. 64
      DocStract/read.go
  6. 39
      Testdaten/rtcinfo/220816_rtcinfo.txt
  7. 116
      database/database.go
  8. 5
      database/go.mod
  9. 2
      database/go.sum
  10. 8
      domain/domain.go
  11. 3
      domain/go.mod
  12. 19
      go.mod
  13. 31
      go.sum
  14. BIN
      rtcinfo.msg
  15. 159
      rtcusertr.go
  16. 0
      rtcusertr.log

116
DocStract/file.go

@ -1,116 +0,0 @@
package docstract
import (
"errors"
"io/ioutil"
"strings"
)
//DocType is a wrapper for the type iota/enum
type DocType int
const (
//DocUnkown represents an unknown document type
DocUnkown = iota
//DocPDF represents a pdf document type
DocPDF
//DocX represents a microsoft docx document type
DocX
//DocXLSX represents microsoft excel doc
DocXLSX
//DocHTML represents an html document type
DocHTML
)
//DocStract stores the binary data for extracted files, as well as the type and filename metadata
type DocStract struct {
Type DocType
FileName *string
Bytes []byte
}
//SaveFile saves the file to the path, does not check if it's an unkown filetype only if it has a name
func (d *DocStract) SaveFile(path string) error {
if len(path) > 0 && path[len(path)-1] != '/' {
path += "/"
}
if d.FileName == nil {
return errors.New("document does not have a filename cannot save")
}
return ioutil.WriteFile(path+*(d.FileName), d.Bytes, 0644)
}
//sets name to nil if cannot dertermine name and type to unkown
func (d *DocStract) getName() {
blocks := strings.Split(string(d.Bytes), "\n")
nameBlock := blocks[len(blocks)-1]
chunks := strings.Split(nameBlock, ".")
nameChunk := 0
t := DocUnkown
switch len(chunks[0]) {
case 0: //pdf
t = DocPDF
nameChunk = 2
default: //html
switch {
case strings.Contains(chunks[0], "word"): //docx
nameChunk = 8
t = DocX
break
case strings.Contains(chunks[2], "worksheets"): //xlsx
t = DocXLSX
for i := 3; i < len(chunks); i++ {
if strings.Contains(StripSeperators(chunks[i]), "xlsx") {
nameChunk = i + 1
break
}
}
break
default: //html
t = DocHTML
}
}
name := strings.TrimSpace(chunks[nameChunk])
name = StripSeperators(name)
switch t {
case DocPDF:
name += ".pdf"
name = name[3:]
d.Type = DocPDF
case DocX:
name += ".docx"
name = name[3:]
d.Type = DocX
case DocXLSX:
name += ".xlsx"
head := 0
for i, b := range d.Bytes {
if i+1 < len(d.Bytes) && b == 'P' && d.Bytes[i+1] == 'K' {
head = i
break
}
}
name = name[3:]
d.Type = DocXLSX
d.Bytes = d.Bytes[head:]
case DocHTML:
name += ".html"
d.Type = DocHTML
}
d.FileName = &name
}

10
DocStract/go.mod

@ -1,10 +0,0 @@
module AUDIAG/rtcusertr/DocStract
go 1.18
require (
github.com/pkg/errors v0.9.1
github.com/richardlehane/mscfb v1.0.4
)
require github.com/richardlehane/msoleps v1.0.1 // indirect

6
DocStract/go.sum

@ -1,6 +0,0 @@
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=

20
DocStract/helpers.go

@ -1,20 +0,0 @@
package docstract
//StripSeperators removes all the random 0 bytes
func StripSeperators(s string) string {
iBytes := []byte(s)
oBytes := []byte{}
if len(iBytes) >= 3 {
offset := 0
if iBytes[0] == iBytes[2] && iBytes[0] == byte(0) {
offset = 1
}
for i := offset; i < len(iBytes); i += 2 {
oBytes = append(oBytes, iBytes[i])
}
}
return string(oBytes)
}

64
DocStract/read.go

@ -1,64 +0,0 @@
package docstract
import (
"bytes"
"strings"
"sync"
"github.com/pkg/errors"
"github.com/richardlehane/mscfb"
)
//Extract takes a .msg files binary data and returns an array of attachments and a count of how many files were extracted
func Extract(data []byte) (*[]*DocStract, int, error) {
reader := bytes.NewReader(data)
doc, err := mscfb.New(reader)
if err != nil {
return nil, 0, errors.Wrap(err, "creating reader")
}
files := []*DocStract{}
{ // Get all the attachments seperated to parse
attachment := false
file := 0
for entry, err := doc.Next(); err == nil; entry, err = doc.Next() {
if strings.Contains(entry.Name, "attach") {
files = append(files, &DocStract{})
attachment = true
continue
}
if attachment && strings.Contains(entry.Name, "properties") {
attachment = false
file++
continue
}
if attachment {
buf := make([]byte, entry.Size)
i, _ := entry.Read(buf)
if i > 0 {
files[file].Bytes = append(files[file].Bytes, buf[:i]...)
}
}
}
}
{ //Determine FileType and FileName
wait := sync.WaitGroup{}
for _, doc := range files {
wait.Add(1)
go func(d *DocStract) {
d.getName()
wait.Done()
}(doc)
}
wait.Wait()
}
return &files, len(files), nil
}

39
Testdaten/rtcinfo/220816_rtcinfo.txt

@ -1,4 +1,4 @@
Von: extern.stefan.renatscher@audi.de <g6dt7ew@islcl011.in.audi.vwg> sERVUS Von: extern.stefan.renatscher@audi.de <g6dt7ew@islcl011.in.audi.vwg>
Gesendet: Dienstag, 16. August 2022 22:04 Gesendet: Dienstag, 16. August 2022 22:04
An: Spar, Georg (I/BT-O75); dbjyt0u@islcl011.in.audi.vwg; g6dt7ew@islcl011.in.audi.vwg An: Spar, Georg (I/BT-O75); dbjyt0u@islcl011.in.audi.vwg; g6dt7ew@islcl011.in.audi.vwg
Betreff: rtcinfo Betreff: rtcinfo
@ -29,38 +29,11 @@ iclcx638: Laurenje 10 start vred-13.3
### ###
Format: Master[: allocated client 1 [[allocated client 2] [...]]] Format: Master[: allocated client 1 [[allocated client 2] [...]]]
cae-lsf-BT: iclcx001 iclcx002 iclcx003 iclcx004 cae-lsf-BT: iclcx001 iclcx002 iclcx003 iclcx004
cae-lsf-ED: iclcx438 iclcx439 iclcx440 iclcx441 iclcx442 iclcx443 iclcx444 iclcx445 iclcx446 iclcx447 iclcx458 cae-lsf-ED: iclcx438 iclcx439 iclcx440 iclcx441 iclcx442 iclcx443 iclcx444 iclcx445 iclcx446 iclcx447 iclcx458 iclcx459 iclcx460 iclcx461 iclcx462 iclcx463 iclcx464 iclcx465 iclcx466 iclcx467 iclcx473 iclcx474 iclcx475 iclcx476 iclcx477 iclcx498 iclcx509 iclcx510 iclcx511 iclcx512 iclcx513
iclcx459 iclcx460 iclcx461 iclcx462 iclcx463 iclcx464 iclcx465 iclcx466 iclcx467 iclcx473 iclcx474 iclcx475 cae-lsf-EK: iclcx206 iclcx207 iclcx208 iclcx209 iclcx210 iclcx211 iclcx212 iclcx213 iclcx214 iclcx215 iclcx216 iclcx217 iclcx218 iclcx219 iclcx220 iclcx221 iclcx222 iclcx223 iclcx224 iclcx225 iclcx226 iclcx227 iclcx228 iclcx229 iclcx230 iclcx231 iclcx232 iclcx233 iclcx234 iclcx235 iclcx236 iclcx237 iclcx238 iclcx239 iclcx240 iclcx241 iclcx242 iclcx243 iclcx244 iclcx245 iclcx246 iclcx247 iclcx248 iclcx249 iclcx250 iclcx251 iclcx252 iclcx253 iclcx254 iclcx255 iclcx256 iclcx257 iclcx258 iclcx259 iclcx260 iclcx261 iclcx262 iclcx263 iclcx264 iclcx265 iclcx266 iclcx267 iclcx268 iclcx269 iclcx270 iclcx271 iclcx272 iclcx273 iclcx274 iclcx275 iclcx276 iclcx277 iclcx278 iclcx279 iclcx280 iclcx281 iclcx282 iclcx283 iclcx284 iclcx285 iclcx286 iclcx287 iclcx288 iclcx289 iclcx290 iclcx291
iclcx476 iclcx477 iclcx498 iclcx509 iclcx510 iclcx511 iclcx512 iclcx513 cae-lsf-GQ: iclcx292 iclcx293 iclcx294 iclcx295 iclcx296 iclcx297 iclcx298 iclcx299 iclcx300 iclcx301 iclcx302 iclcx303 iclcx304 iclcx305 iclcx306 iclcx307 iclcx308 iclcx309 iclcx310 iclcx311 iclcx312 iclcx313 iclcx314 iclcx315 iclcx316 iclcx317 iclcx318 iclcx319 iclcx320 iclcx321 iclcx322 iclcx323 iclcx324 iclcx325 iclcx326 iclcx327
cae-lsf-EK: iclcx206 iclcx207 iclcx208 iclcx209 iclcx210 iclcx211 iclcx212 iclcx213 iclcx214 iclcx215 iclcx216 cae-lsf
iclcx217 iclcx218 iclcx219 iclcx220 iclcx221 iclcx222 iclcx223 iclcx224 iclcx225 iclcx226 iclcx227 iclcx228 cae-lsf-PG: iclcx005 iclcx006 iclcx007 iclcx008 iclcx009 iclcx010 iclcx011 iclcx012 iclcx013 iclcx014 iclcx015 iclcx016 iclcx017 iclcx018 iclcx019 iclcx020 iclcx021 iclcx022 iclcx023 iclcx024 iclcx025 iclcx026 iclcx027 iclcx028 iclcx029 iclcx030 iclcx031 iclcx032 iclcx033 iclcx034 iclcx035 iclcx036 iclcx037 iclcx038 iclcx039 iclcx040 iclcx041 iclcx042 iclcx043 iclcx044 iclcx045 iclcx046 iclcx047 iclcx048 iclcx049 iclcx050 iclcx051 iclcx052 iclcx054 iclcx055 iclcx056 iclcx057 iclcx058 iclcx060 iclcx061 iclcx062 iclcx063 iclcx064 iclcx065 iclcx066 iclcx067 iclcx068 iclcx069 iclcx070 iclcx071 iclcx072 iclcx073 iclcx074 iclcx075 iclcx076 iclcx077 iclcx078 iclcx079 iclcx080 iclcx081 iclcx082 iclcx083 iclcx084 iclcx085 iclcx086 iclcx087 iclcx088 iclcx089 iclcx090 iclcx091 iclcx092 iclcx093 iclcx094 iclcx095 iclcx096 iclcx097 iclcx098 iclcx099 iclcx100 iclcx101 iclcx102 iclcx103 iclcx104 iclcx105 iclcx106 iclcx107 iclcx108 iclcx109 iclcx110 iclcx111 iclcx112 iclcx113 iclcx114 iclcx115 iclcx116 iclcx117 iclcx118 iclcx119 iclcx120 iclcx121 iclcx122 iclcx123 iclcx124 iclcx125 iclcx126 iclcx127 iclcx128 iclcx129 iclcx130 iclcx131 iclcx132 iclcx133 iclcx134 iclcx135 iclcx136 iclcx137 iclcx138 iclcx139 iclcx140 iclcx141 iclcx142 iclcx143 iclcx144 iclcx145 iclcx146 iclcx147 iclcx148 iclcx149 iclcx150 iclcx151 iclcx152 iclcx153 iclcx154 iclcx155 iclcx156 iclcx157 iclcx158 iclcx159 iclcx160 iclcx161 iclcx162 iclcx163 iclcx164 iclcx165 iclcx166 iclcx167 iclcx168 iclcx169 iclcx170 iclcx171 iclcx172 iclcx173 iclcx174 iclcx175 iclcx176 iclcx177 iclcx178 iclcx179 iclcx180 iclcx181 iclcx182 iclcx183 iclcx184 iclcx185 iclcx186 iclcx187 iclcx188 iclcx189 iclcx190 iclcx191 iclcx192 iclcx193 iclcx194 iclcx195 iclcx196 iclcx197 iclcx198 iclcx199 iclcx200 iclcx201 iclcx202 iclcx203 iclcx204 iclcx205
iclcx229 iclcx230 iclcx231 iclcx232 iclcx233 iclcx234 iclcx235 iclcx236 iclcx237 iclcx238 iclcx239 iclcx240
iclcx241 iclcx242 iclcx243 iclcx244 iclcx245 iclcx246 iclcx247 iclcx248 iclcx249 iclcx250 iclcx251 iclcx252
iclcx253 iclcx254 iclcx255 iclcx256 iclcx257 iclcx258 iclcx259 iclcx260 iclcx261 iclcx262 iclcx263 iclcx264
iclcx265 iclcx266 iclcx267 iclcx268 iclcx269 iclcx270 iclcx271 iclcx272 iclcx273 iclcx274 iclcx275 iclcx276
iclcx277 iclcx278 iclcx279 iclcx280 iclcx281 iclcx282 iclcx283 iclcx284 iclcx285 iclcx286 iclcx287 iclcx288
iclcx289 iclcx290 iclcx291
cae-lsf-GQ: iclcx292 iclcx293 iclcx294 iclcx295 iclcx296 iclcx297 iclcx298 iclcx299 iclcx300 iclcx301
iclcx302 iclcx303 iclcx304 iclcx305 iclcx306 iclcx307 iclcx308 iclcx309 iclcx310 iclcx311 iclcx312 iclcx313
iclcx314 iclcx315 iclcx316 iclcx317 iclcx318 iclcx319 iclcx320 iclcx321 iclcx322 iclcx323 iclcx324 iclcx325
iclcx326 iclcx327 cae-lsf
cae-lsf-PG: iclcx005 iclcx006 iclcx007 iclcx008 iclcx009 iclcx010 iclcx011 iclcx012 iclcx013 iclcx014 iclcx015
iclcx016 iclcx017 iclcx018 iclcx019 iclcx020 iclcx021 iclcx022 iclcx023 iclcx024 iclcx025 iclcx026 iclcx027
iclcx028 iclcx029 iclcx030 iclcx031 iclcx032 iclcx033 iclcx034 iclcx035 iclcx036 iclcx037 iclcx038 iclcx039
iclcx040 iclcx041 iclcx042 iclcx043 iclcx044 iclcx045 iclcx046 iclcx047 iclcx048 iclcx049 iclcx050 iclcx051
iclcx052 iclcx054 iclcx055 iclcx056 iclcx057 iclcx058 iclcx060 iclcx061 iclcx062 iclcx063 iclcx064 iclcx065
iclcx066 iclcx067 iclcx068 iclcx069 iclcx070 iclcx071 iclcx072 iclcx073 iclcx074 iclcx075 iclcx076 iclcx077
iclcx078 iclcx079 iclcx080 iclcx081 iclcx082 iclcx083 iclcx084 iclcx085 iclcx086 iclcx087 iclcx088 iclcx089
iclcx090 iclcx091 iclcx092 iclcx093 iclcx094 iclcx095 iclcx096 iclcx097 iclcx098 iclcx099 iclcx100 iclcx101
iclcx102 iclcx103 iclcx104 iclcx105 iclcx106 iclcx107 iclcx108 iclcx109 iclcx110 iclcx111 iclcx112 iclcx113
iclcx114 iclcx115 iclcx116 iclcx117 iclcx118 iclcx119 iclcx120 iclcx121 iclcx122 iclcx123 iclcx124 iclcx125
iclcx126 iclcx127 iclcx128 iclcx129 iclcx130 iclcx131 iclcx132 iclcx133 iclcx134 iclcx135 iclcx136 iclcx137
iclcx138 iclcx139 iclcx140 iclcx141 iclcx142 iclcx143 iclcx144 iclcx145 iclcx146 iclcx147 iclcx148 iclcx149
iclcx150 iclcx151 iclcx152 iclcx153 iclcx154 iclcx155 iclcx156 iclcx157 iclcx158 iclcx159 iclcx160 iclcx161
iclcx162 iclcx163 iclcx164 iclcx165 iclcx166 iclcx167 iclcx168 iclcx169 iclcx170 iclcx171 iclcx172 iclcx173
iclcx174 iclcx175 iclcx176 iclcx177 iclcx178 iclcx179 iclcx180 iclcx181 iclcx182 iclcx183 iclcx184 iclcx185
iclcx186 iclcx187 iclcx188 iclcx189 iclcx190 iclcx191 iclcx192 iclcx193 iclcx194 iclcx195 iclcx196 iclcx197
iclcx198 iclcx199 iclcx200 iclcx201 iclcx202 iclcx203 iclcx204 iclcx205
iclcx601 iclcx601
iclcx602 iclcx602
iclcx603 iclcx603

116
database/database.go

@ -0,0 +1,116 @@
package database
import (
"database/sql"
"log"
"gitlab.dedyn.io/AUDIAG/rtcusertr/domain"
_ "github.com/go-sql-driver/mysql"
)
var (
dbConnection = "rtcusertrdbuser:hurtz3585@tcp(ubodroid-1:3306)/rtcusertrdb"
dbType = "mysql"
)
// Tool Funktionen
func CreateKnoten(knoten domain.KnotenE) (resKnoten domain.KnotenE, err error) {
conn, err := sql.Open(dbType, dbConnection)
if err != nil {
log.Println("Error while connecting DB: ", err)
}
log.Println("Verbindung hergestellt")
log.Println("Name = ", knoten.Fachbereich)
defer conn.Close()
res, err := conn.Exec("INSERT INTO knoten VALUES(?,?,?,?)", knoten.Id, knoten.Fachbereich, knoten.Anzahl, knoten.Tag)
if err != nil {
log.Println("Error while executing insert statement", err)
}
lastId, err := res.LastInsertId()
knoten.Id = uint(lastId)
resKnoten = knoten
return resKnoten, err
}
func DeleteKnoten(knotenId uint) (result, err error) {
conn, err := sql.Open(dbType, dbConnection)
if err != nil {
log.Println("Error while connecting DB: ", err)
}
log.Println("DB Verbindung hergestellt")
defer conn.Close()
_, err = conn.Exec("DELETE FROM knoten WHERE id = ?", knotenId)
if err != nil {
log.Fatal("Error while executing DELETE statement", err)
}
return result, err
}
func ShowKnoten() (knotenArray []domain.KnotenE, err error) {
conn, err := sql.Open(dbType, dbConnection)
if err != nil {
log.Println("Error while connecting DB: ", err)
}
log.Println("DB Verbindung hergestellt")
defer conn.Close()
results, err := conn.Query("SELECT * FROM knoten")
if err != nil {
log.Fatal("Error while executing SELECt statement", err)
}
var knoten domain.KnotenE
for results.Next() {
err = results.Scan(&knoten.Id, &knoten.Fachbereich, &knoten.Anzahl, &knoten.Tag)
if err != nil {
log.Fatal("Error: ", err)
}
knotenArray = append(knotenArray, knoten)
}
return knotenArray, err
}
func GetKnoten(id uint) (knoten domain.KnotenE, err error) {
conn, err := sql.Open(dbType, dbConnection)
if err != nil {
log.Println("Error while connecting DB: ", err)
}
log.Println("DB Verbindung hergestellt")
defer conn.Close()
results, err := conn.Query("SELECT * FROM knoten WHERE id=?", id)
if err != nil {
log.Fatal("Error while executing SELECt statement", err)
}
for results.Next() {
err = results.Scan(&knoten.Id, &knoten.Fachbereich, &knoten.Anzahl, &knoten.Tag)
if err != nil {
log.Fatal("Error: ", err)
}
}
return knoten, err
}
func UpdateKnoten(knoten domain.KnotenE) (resKnoten domain.KnotenE, err error) {
conn, err := sql.Open(dbType, dbConnection)
if err != nil {
log.Println("Error while connecting DB: ", err)
}
log.Println("Verbindung hergestellt")
log.Println("Name = ", knoten.Fachbereich)
defer conn.Close()
_, err = conn.Exec("UPDATE knoten SET fachbereich=?, anzahl=?, tag=? WHERE id=?", knoten.Fachbereich, knoten.Anzahl, knoten.Tag, knoten.Id)
if err != nil {
log.Println("Error while executing insert statement", err)
}
resKnoten = knoten
return resKnoten, err
}

5
database/go.mod

@ -0,0 +1,5 @@
module database.go
go 1.18
require github.com/go-sql-driver/mysql v1.6.0 // indirect

2
database/go.sum

@ -0,0 +1,2 @@
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

8
domain/domain.go

@ -0,0 +1,8 @@
package domain
type KnotenE struct {
Id uint `json:"id"`
Fachbereich string `json:"fachbereich"`
Anzahl int `json:"anzahl"`
Tag string `json:"tag"`
}

3
domain/go.mod

@ -0,0 +1,3 @@
module domain.go
go 1.18

19
go.mod

@ -1,18 +1,19 @@
module rtcusertr.go module gitlab.dedyn.io/g.spar/rtcusertr
go 1.18 go 1.18
require ( require (
AUDIAG/rtcusertr/DocStract v0.0.0-00010101000000-000000000000 github.com/gorilla/mux v1.8.0
github.com/sirupsen/logrus v1.4.2 github.com/sirupsen/logrus v1.9.0
gitlab.dedyn.io/AUDIAG/rtcusertr/database v0.0.0-00010101000000-000000000000
gitlab.dedyn.io/AUDIAG/rtcusertr/domain v0.0.0-00010101000000-000000000000
) )
require ( require (
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.1 // indirect
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
) )
replace AUDIAG/rtcusertr/DocStract => ./DocStract replace gitlab.dedyn.io/AUDIAG/rtcusertr/database => ./database
replace gitlab.dedyn.io/AUDIAG/rtcusertr/domain => ./domain

31
go.sum

@ -1,19 +1,20 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 h1:fqTvyMIIj+HRzMmnzr9NtpHP6uVpvB5fkHcgPDC4nu8=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

BIN
rtcinfo.msg

Binary file not shown.

159
rtcusertr.go

@ -1,12 +1,18 @@
package main package main
import ( import (
docstract "AUDIAG/rtcusertr/DocStract" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"net/http"
"os" "os"
"strings" "strconv"
"gitlab.dedyn.io/AUDIAG/rtcusertr/database"
"gitlab.dedyn.io/AUDIAG/rtcusertr/domain"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -21,40 +27,149 @@ type Master struct {
} }
func main() { func main() {
path, _ := os.Getwd()
pathTo := path + "Testdaten/rtcinfo"
pathFiles, _ := ioutil.ReadDir(pathTo)
for _, file := range pathFiles { fmt.Println("This is rtcusertrd!!!")
if file.Name()[len(file.Name())-4:] != ".txt" { logFile, err := os.OpenFile("rtcusertr.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
continue if err != nil {
logrus.Fatal(err)
}
defer logFile.Close()
logrus.SetOutput(logFile)
logrus.SetLevel(logrus.InfoLevel)
r := mux.NewRouter()
r.HandleFunc("/api/kn", createKnotenEHandler).Methods("POST", "OPTIONS")
r.HandleFunc("/api/kn/{id:[0-9]+}", deleteKnotenEHandler).Methods("DELETE", "OPTIONS")
r.HandleFunc("/api/kn", showKnotenEHandler).Methods("GET", "OPTIONS")
r.HandleFunc("/api/kn/{id:[0-9]+}", getKnotenEHandler).Methods("GET", "OPTIONS")
r.HandleFunc("/api/kn/{id:[0-9]+}", updateKnotenEHandler).Methods("PUT", "OPTIONS")
http.Handle("/", r)
r.Use(mux.CORSMethodMiddleware(r))
http.ListenAndServe(":8081", r)
logrus.Info("running on localhost, Port 8081")
}
func createKnotenEHandler(writer http.ResponseWriter, req *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
if req.Method == http.MethodOptions {
return
} }
logrus.Infof("reading %s", file.Name()) body, err := ioutil.ReadAll(req.Body)
if err != nil {
writer.WriteHeader(http.StatusBadRequest)
}
var knoten domain.KnotenE
json.Unmarshal(body, &knoten)
logrus.Println("Name= ", knoten.Fachbereich)
logrus.Info("creating new Knoten-Eintrag", knoten.Fachbereich)
res, err := database.CreateKnoten(knoten)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
}
b, err := json.Marshal(res)
if err != nil {
logrus.Fatal("Error: ", err)
}
location := fmt.Sprintf("%s/%d", req.URL.String(), res.Id)
writer.Header().Set("Location:", location)
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusCreated)
writer.Write(b)
}
data, err := ioutil.ReadFile(file.Name()) func deleteKnotenEHandler(writer http.ResponseWriter, req *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
if req.Method == http.MethodOptions {
return
}
knotenId, _ := strconv.ParseUint(mux.Vars(req)["id"], 10, 0)
logrus.Info("Deleting tool with ID", knotenId)
_, err := database.DeleteKnoten(uint(knotenId))
if err != nil {
logrus.Fatal("Error: Delete could not be executed", err)
}
writer.WriteHeader(http.StatusNoContent)
}
func showKnotenEHandler(writer http.ResponseWriter, req *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
if req.Method == http.MethodOptions {
return
}
res, err := database.ShowKnoten()
if err != nil { if err != nil {
panic(err) logrus.Fatal("Error: Knoteneintrag can't be shown ", err)
writer.WriteHeader(http.StatusInternalServerError)
} }
files, count, err := docstract.Extract(data) b, err := json.Marshal(res)
if err != nil { if err != nil {
panic(err) logrus.Fatal("Error: ", err)
} }
fmt.Println("Found ", count, " files") location := req.URL.String()
writer.Header().Set("Location:", location)
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
writer.Write(b)
}
for i, document := range *files { func getKnotenEHandler(writer http.ResponseWriter, req *http.Request) {
if !strings.Contains(*document.FileName, ".") { writer.Header().Set("Access-Control-Allow-Origin", "*")
s := fmt.Sprintf("%d.txt", i) if req.Method == http.MethodOptions {
document.FileName = &s return
}
knotenId, _ := strconv.ParseUint(mux.Vars(req)["id"], 10, 0)
res, err := database.GetKnoten(uint(knotenId))
if err != nil {
logrus.Fatal("Error: Knoteneintrag can't be shown ", err)
writer.WriteHeader(http.StatusInternalServerError)
} }
if err := document.SaveFile(""); err != nil { b, err := json.Marshal(res)
logrus.Warn(err) if err != nil {
} else { logrus.Fatal("Error: ", err)
logrus.Infof("Saved file %s", *document.FileName)
} }
location := req.URL.String()
writer.Header().Set("Location:", location)
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
writer.Write(b)
}
func updateKnotenEHandler(writer http.ResponseWriter, req *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
if req.Method == http.MethodOptions {
return
} }
body, err := ioutil.ReadAll(req.Body)
if err != nil {
writer.WriteHeader(http.StatusBadRequest)
}
var knoten domain.KnotenE
json.Unmarshal(body, &knoten)
logrus.Println("Name = ", knoten.Fachbereich)
logrus.Info("updating Knoteneintrag", knoten.Fachbereich)
res, err := database.UpdateKnoten(knoten)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
} }
b, err := json.Marshal(res)
if err != nil {
log.Fatal("Error: ", err)
}
location := fmt.Sprintf("%s/%d", req.URL.String(), res.Id)
writer.Header().Set("Location:", location)
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
writer.Write(b)
} }

0
rtcusertr.log

Loading…
Cancel
Save