Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-2-capstone-design1
/
JJS_project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Ma Suhyeon
2020-12-15 12:05:11 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b6a1439a227997e9f35f185fa26e35c86339ac01
b6a1439a
1 parent
8dc295e6
Edit extraction upload
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
9 deletions
source/server/extraction.go
source/server/extraction.go
View file @
b6a1439
package
main
import
(
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/
google/uuid
"
"github.com/
jmoiron/sqlx
"
)
func
(
app
*
App
)
PostExtractions
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -22,11 +20,7 @@ func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) {
defer
form
.
Close
()
dir
:=
fmt
.
Sprintf
(
"data/%d"
,
userNo
)
os
.
MkdirAll
(
dir
,
0644
)
name
:=
strings
.
Replace
(
uuid
.
New
()
.
String
(),
"-"
,
""
,
-
1
)
file
,
err
:=
os
.
Create
(
fmt
.
Sprintf
(
"%s/%s"
,
dir
,
name
))
file
,
err
:=
ioutil
.
TempFile
(
""
,
"db"
)
if
err
!=
nil
{
WriteError
(
w
,
http
.
StatusInternalServerError
,
"Unknown error"
)
return
...
...
@@ -39,5 +33,59 @@ func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) {
return
}
db
,
err
:=
sqlx
.
Connect
(
"sqlite3"
,
file
.
Name
())
if
err
!=
nil
{
WriteError
(
w
,
http
.
StatusInternalServerError
,
"Could not open db file"
)
return
}
defer
db
.
Close
()
tx
,
err
:=
app
.
db
.
Beginx
()
if
err
!=
nil
{
WriteError
(
w
,
http
.
StatusInternalServerError
,
"Unknown error"
)
return
}
res
,
_
:=
tx
.
Exec
(
"INSERT INTO extractions (`owner`) VALUES (?)"
,
userNo
)
extNo
,
_
:=
res
.
LastInsertId
()
rows
,
err
:=
db
.
Queryx
(
"SELECT * FROM calllog"
)
if
err
==
nil
{
for
rows
.
Next
()
{
vals
,
_
:=
rows
.
SliceScan
()
tx
.
Exec
(
"INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?)"
,
append
([]
interface
{}{
extNo
},
vals
...
)
...
)
}
}
sql
:=
`SELECT
a.packagename, a.name, a.version, a.wifiusage, a.cellularusage,
u.lasttimeused, u.totaltimeforeground
FROM AppInfo a JOIN AppUsageYear u ON a.packagename=u.packagename`
rows
,
err
=
db
.
Queryx
(
sql
)
if
err
==
nil
{
for
rows
.
Next
()
{
vals
,
_
:=
rows
.
SliceScan
()
tx
.
Exec
(
"INSERT INTO apps VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
,
append
([]
interface
{}{
extNo
},
vals
...
)
...
)
}
}
rows
,
err
=
db
.
Queryx
(
"SELECT mid, type, address, body, date FROM sms"
)
if
err
==
nil
{
for
rows
.
Next
()
{
vals
,
_
:=
rows
.
SliceScan
()
tx
.
Exec
(
"INSERT INTO messages VALUES (?, ?, ?, ?, ?, ?)"
,
append
([]
interface
{}{
extNo
},
vals
...
)
...
)
}
}
rows
,
err
=
db
.
Queryx
(
"SELECT PID, UID, PPID, STIME, TIME, CMD FROM process"
)
if
err
==
nil
{
for
rows
.
Next
()
{
vals
,
_
:=
rows
.
SliceScan
()
tx
.
Exec
(
"INSERT INTO processes VALUES (?, ?, ?, ?, ?, ?, ?)"
,
append
([]
interface
{}{
extNo
},
vals
...
)
...
)
}
}
tx
.
Commit
()
w
.
Write
([]
byte
(
"success"
))
}
...
...
Please
register
or
login
to post a comment