File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "io/ioutil"
5
+ "log"
6
+ "os"
7
+ "path/filepath"
8
+ )
9
+
10
+ type File struct {
11
+ Path string
12
+ Key string
13
+ Content string
14
+ }
15
+
16
+ func (f * File ) Read () {
17
+ content , err := ioutil .ReadFile (f .Path )
18
+ if err != nil {
19
+ log .Printf ("[-] Could not read file %s\n " , f .Path )
20
+ f .Content = ""
21
+ } else {
22
+ f .Content = string (content )
23
+ }
24
+ }
25
+
26
+ func (f * File ) Process () {
27
+ processContent (f .Key , f .Content )
28
+ }
29
+
30
+ func (f * File ) Delete () {
31
+ os .Remove (f .Path )
32
+ }
33
+
34
+ func scrapeFiles () {
35
+ if conf .LocalPath == "" {
36
+ return
37
+ }
38
+
39
+ var files []* File
40
+
41
+ log .Println ("[+] Checking for local pastes." )
42
+
43
+ filepath .Walk (conf .LocalPath , func (path string , info os.FileInfo , err error ) error {
44
+ if err != nil {
45
+ log .Printf ("[-] Error reading %s: %s\n " , conf .LocalPath , err .Error ())
46
+ return nil
47
+ }
48
+
49
+ if info .IsDir () {
50
+ log .Printf ("[+] Skipping directory %s\n " , path )
51
+ return nil
52
+ }
53
+
54
+ files = append (files , & File {Path : path , Key : filepath .Base (path )})
55
+
56
+ return nil
57
+ })
58
+
59
+ for i := range files {
60
+ f := files [i ]
61
+ f .Read ()
62
+ f .Process ()
63
+ f .Delete ()
64
+ }
65
+ }
You can’t perform that action at this time.
0 commit comments