Showing
1 changed file
with
57 additions
and
9 deletions
1 | package main | 1 | package main |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "fmt" | ||
5 | "io" | 4 | "io" |
5 | + "io/ioutil" | ||
6 | "net/http" | 6 | "net/http" |
7 | - "os" | ||
8 | - "strings" | ||
9 | 7 | ||
10 | - "github.com/google/uuid" | 8 | + "github.com/jmoiron/sqlx" |
11 | ) | 9 | ) |
12 | 10 | ||
13 | func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) { | 11 | func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) { |
... | @@ -22,11 +20,7 @@ func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) { | ... | @@ -22,11 +20,7 @@ func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) { |
22 | 20 | ||
23 | defer form.Close() | 21 | defer form.Close() |
24 | 22 | ||
25 | - dir := fmt.Sprintf("data/%d", userNo) | 23 | + file, err := ioutil.TempFile("", "db") |
26 | - os.MkdirAll(dir, 0644) | ||
27 | - | ||
28 | - name := strings.Replace(uuid.New().String(), "-", "", -1) | ||
29 | - file, err := os.Create(fmt.Sprintf("%s/%s", dir, name)) | ||
30 | if err != nil { | 24 | if err != nil { |
31 | WriteError(w, http.StatusInternalServerError, "Unknown error") | 25 | WriteError(w, http.StatusInternalServerError, "Unknown error") |
32 | return | 26 | return |
... | @@ -39,5 +33,59 @@ func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) { | ... | @@ -39,5 +33,59 @@ func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) { |
39 | return | 33 | return |
40 | } | 34 | } |
41 | 35 | ||
36 | + db, err := sqlx.Connect("sqlite3", file.Name()) | ||
37 | + if err != nil { | ||
38 | + WriteError(w, http.StatusInternalServerError, "Could not open db file") | ||
39 | + return | ||
40 | + } | ||
41 | + defer db.Close() | ||
42 | + | ||
43 | + tx, err := app.db.Beginx() | ||
44 | + if err != nil { | ||
45 | + WriteError(w, http.StatusInternalServerError, "Unknown error") | ||
46 | + return | ||
47 | + } | ||
48 | + | ||
49 | + res, _ := tx.Exec("INSERT INTO extractions (`owner`) VALUES (?)", userNo) | ||
50 | + extNo, _ := res.LastInsertId() | ||
51 | + | ||
52 | + rows, err := db.Queryx("SELECT * FROM calllog") | ||
53 | + if err == nil { | ||
54 | + for rows.Next() { | ||
55 | + vals, _ := rows.SliceScan() | ||
56 | + tx.Exec("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...) | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | + sql := `SELECT | ||
61 | + a.packagename, a.name, a.version, a.wifiusage, a.cellularusage, | ||
62 | + u.lasttimeused, u.totaltimeforeground | ||
63 | + FROM AppInfo a JOIN AppUsageYear u ON a.packagename=u.packagename` | ||
64 | + rows, err = db.Queryx(sql) | ||
65 | + if err == nil { | ||
66 | + for rows.Next() { | ||
67 | + vals, _ := rows.SliceScan() | ||
68 | + tx.Exec("INSERT INTO apps VALUES (?, ?, ?, ?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...) | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + rows, err = db.Queryx("SELECT mid, type, address, body, date FROM sms") | ||
73 | + if err == nil { | ||
74 | + for rows.Next() { | ||
75 | + vals, _ := rows.SliceScan() | ||
76 | + tx.Exec("INSERT INTO messages VALUES (?, ?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...) | ||
77 | + } | ||
78 | + } | ||
79 | + | ||
80 | + rows, err = db.Queryx("SELECT PID, UID, PPID, STIME, TIME, CMD FROM process") | ||
81 | + if err == nil { | ||
82 | + for rows.Next() { | ||
83 | + vals, _ := rows.SliceScan() | ||
84 | + tx.Exec("INSERT INTO processes VALUES (?, ?, ?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...) | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + tx.Commit() | ||
89 | + | ||
42 | w.Write([]byte("success")) | 90 | w.Write([]byte("success")) |
43 | } | 91 | } | ... | ... |
-
Please register or login to post a comment