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-05 12:59:06 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
af32f170d36a74ec00cc898e306675c9d2209ad4
af32f170
1 parent
1c2d911f
Implement proccesses and alarms
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
1 deletions
source/server/app.go
source/server/data.go
source/server/app.go
View file @
af32f17
...
...
@@ -39,6 +39,8 @@ func NewApp(config Config) *App {
app
.
router
.
HandleFunc
(
"/extractions/{file}/calls/analyses"
,
app
.
GetCallsAnalyses
)
.
Methods
(
"GET"
)
app
.
router
.
HandleFunc
(
"/extractions/{file}/apps/analyses"
,
app
.
GetAppsAnalyses
)
.
Methods
(
"GET"
)
app
.
router
.
HandleFunc
(
"/extractions/{file}/messages/analyses"
,
app
.
GetMessagesAnalyses
)
.
Methods
(
"GET"
)
app
.
router
.
HandleFunc
(
"/extractions/{file}/processes"
,
app
.
GetProcesses
)
.
Methods
(
"GET"
)
app
.
router
.
HandleFunc
(
"/extractions/{file}/alarms"
,
app
.
GetAlarms
)
.
Methods
(
"GET"
)
return
app
}
...
...
source/server/data.go
View file @
af32f17
...
...
@@ -3,6 +3,8 @@ package main
import
(
"fmt"
"net/http"
"strconv"
"strings"
"time"
"github.com/gorilla/mux"
...
...
@@ -145,7 +147,90 @@ func (app *App) GetMessagesAnalyses(w http.ResponseWriter, r *http.Request) {
(SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=1) receive,
(SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=2) send
FROM sms s GROUP BY address ORDER BY receive + send DESC`
fmt
.
Println
(
db
.
Select
(
&
messages
,
query
)
)
db
.
Select
(
&
messages
,
query
)
WriteJson
(
w
,
messages
)
}
type
Process
struct
{
UID
string
`json:"uid" db:"UID"`
PID
int
`json:"pid" db:"PID"`
PPID
int
`json:"ppid" db:"PPID"`
STIME
string
`json:"stime" db:"STIME"`
TIME
string
`json:"time" db:"TIME"`
CMD
string
`json:"cmd" db:"CMD"`
}
func
(
app
*
App
)
GetProcesses
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
processes
:=
[]
Process
{}
db
,
err
:=
sqlx
.
Connect
(
"sqlite3"
,
fmt
.
Sprintf
(
"data/1/%s"
,
vars
[
"file"
]))
if
err
!=
nil
{
WriteError
(
w
,
http
.
StatusInternalServerError
,
"Could not open db file"
)
return
}
defer
db
.
Close
()
query
:=
`SELECT UID, CAST(PID AS INTEGER) PID, CAST(PPID AS INTEGER) PPID, STIME, TIME, CMD FROM process WHERE UID LIKE 'u%' ORDER BY TIME DESC`
db
.
Select
(
&
processes
,
query
)
WriteJson
(
w
,
processes
)
}
type
Alarm
struct
{
ID
string
`json:"id"`
When
time
.
Time
`json:"when"`
History
[]
AlarmHistory
`json:"history"`
}
type
AlarmHistory
struct
{
Type
string
`json:"type"`
When
time
.
Time
`json:"when"`
}
func
(
app
*
App
)
GetAlarms
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
db
,
err
:=
sqlx
.
Connect
(
"sqlite3"
,
fmt
.
Sprintf
(
"data/1/%s"
,
vars
[
"file"
]))
if
err
!=
nil
{
WriteError
(
w
,
http
.
StatusInternalServerError
,
"Could not open db file"
)
return
}
defer
db
.
Close
()
alarms
:=
map
[
string
]
Alarm
{}
rows
,
_
:=
db
.
Queryx
(
"SELECT * FROM alarm ORDER BY TIME"
)
for
rows
.
Next
()
{
var
tm
string
var
typ
string
var
detail
string
rows
.
Scan
(
&
tm
,
&
typ
,
&
detail
)
detail
=
detail
[
strings
.
Index
(
detail
,
"{"
)
+
1
:
strings
.
Index
(
detail
,
"}"
)]
s
:=
strings
.
Split
(
detail
,
" "
)
timestamp
,
_
:=
strconv
.
ParseInt
(
s
[
4
],
10
,
64
)
timestamp
/=
1000
if
_
,
ok
:=
alarms
[
s
[
0
]];
!
ok
{
alarms
[
s
[
0
]]
=
Alarm
{
ID
:
s
[
0
],
When
:
time
.
Unix
(
timestamp
,
0
)}
}
when
,
_
:=
time
.
Parse
(
"2006-01-02 15:04:05"
,
tm
)
alarm
:=
alarms
[
s
[
0
]]
alarm
.
History
=
append
(
alarms
[
s
[
0
]]
.
History
,
AlarmHistory
{
Type
:
typ
,
When
:
when
,
})
alarms
[
s
[
0
]]
=
alarm
}
results
:=
[]
Alarm
{}
for
_
,
v
:=
range
alarms
{
results
=
append
(
results
,
v
)
}
WriteJson
(
w
,
results
)
}
...
...
Please
register
or
login
to post a comment