-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
490 additions
and
228 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
DROP TABLE activity; | ||
|
||
PRAGMA foreign_keys=off; | ||
|
||
-- ports | ||
CREATE TABLE _ports_new ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
ip_addr_id INTEGER NOT NULL, | ||
value VARCHAR NOT NULL, | ||
ip_addr VARCHAR NOT NULL, | ||
port INTEGER NOT NULL, | ||
protocol VARCHAR NOT NULL, | ||
status VARCHAR NOT NULL, | ||
unscoped BOOLEAN DEFAULT 0 NOT NULL, | ||
|
||
banner VARCHAR, | ||
service VARCHAR, | ||
version VARCHAR, | ||
|
||
FOREIGN KEY(ip_addr_id) REFERENCES ipaddrs(id) ON DELETE CASCADE, | ||
CONSTRAINT port_unique UNIQUE (value) | ||
); | ||
|
||
INSERT INTO _ports_new (id, ip_addr_id, value, ip_addr, port, protocol, status, unscoped, banner, service, version) | ||
SELECT id, ip_addr_id, value, ip_addr, port, protocol, status, unscoped, banner, service, version | ||
FROM ports; | ||
|
||
DROP TABLE ports; | ||
ALTER TABLE _ports_new RENAME TO ports; | ||
|
||
PRAGMA foreign_keys=on; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
CREATE TABLE activity ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
topic VARCHAR NOT NULL, | ||
time DATETIME NOT NULL, | ||
uniq VARCHAR, | ||
latitude FLOAT, | ||
longitude FLOAT, | ||
content VARCHAR NOT NULL | ||
); | ||
CREATE UNIQUE INDEX activity_uniq ON activity(uniq); | ||
|
||
PRAGMA foreign_keys=off; | ||
|
||
-- ports | ||
CREATE TABLE _ports_new ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
ip_addr_id INTEGER NOT NULL, | ||
value VARCHAR NOT NULL, | ||
ip_addr VARCHAR NOT NULL, | ||
port INTEGER NOT NULL, | ||
protocol VARCHAR NOT NULL, | ||
status VARCHAR, | ||
unscoped BOOLEAN DEFAULT 0 NOT NULL, | ||
|
||
banner VARCHAR, | ||
service VARCHAR, | ||
version VARCHAR, | ||
|
||
FOREIGN KEY(ip_addr_id) REFERENCES ipaddrs(id) ON DELETE CASCADE, | ||
CONSTRAINT port_unique UNIQUE (value) | ||
); | ||
|
||
INSERT INTO _ports_new (id, ip_addr_id, value, ip_addr, port, protocol, status, unscoped, banner, service, version) | ||
SELECT id, ip_addr_id, value, ip_addr, port, protocol, status, unscoped, banner, service, version | ||
FROM ports; | ||
|
||
DROP TABLE ports; | ||
ALTER TABLE _ports_new RENAME TO ports; | ||
|
||
PRAGMA foreign_keys=on; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- Description: Log some dummy activity | ||
-- Version: 0.1.0 | ||
-- License: GPL-3.0 | ||
|
||
function run() | ||
local uniq = getopt('uniq') | ||
|
||
if getopt('gps') then | ||
lat=1.23 | ||
lon=4.56 | ||
end | ||
|
||
while true do | ||
db_activity({ | ||
topic='harness/activity-ping:dummy', | ||
time=sn0int_time(), | ||
uniq=uniq, | ||
latitude=lat, | ||
longitude=lon, | ||
content={ | ||
msg='ohai', | ||
}, | ||
}) | ||
sleep(5) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use crate::errors::*; | ||
use crate::schema::activity; | ||
use diesel; | ||
use diesel::prelude::*; | ||
use crate::models::*; | ||
use chrono::NaiveDateTime; | ||
|
||
|
||
#[derive(Identifiable, Queryable, Serialize, Deserialize, PartialEq, Debug)] | ||
#[table_name="activity"] | ||
pub struct Activity { | ||
pub id: i32, | ||
pub topic: String, | ||
pub time: NaiveDateTime, | ||
pub uniq: Option<String>, | ||
pub latitude: Option<f32>, | ||
pub longitude: Option<f32>, | ||
pub content: String, | ||
} | ||
|
||
impl Activity { | ||
pub fn uniq(db: &Database, my_uniq: &str) -> Result<Option<Activity>> { | ||
use crate::schema::activity::dsl::*; | ||
activity.filter(uniq.eq(my_uniq)) | ||
.first::<Self>(db.db()) | ||
.optional() | ||
.map_err(|e| Error::from(e)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Insertable, Serialize, Deserialize)] | ||
#[table_name="activity"] | ||
pub struct NewActivity { | ||
pub topic: String, | ||
pub time: NaiveDateTime, | ||
pub uniq: Option<String>, | ||
pub latitude: Option<f32>, | ||
pub longitude: Option<f32>, | ||
pub content: String, | ||
} | ||
|
||
impl NewActivity { | ||
pub fn insert(&self, db: &Database) -> Result<()> { | ||
diesel::insert_into(activity::table) | ||
.values(self) | ||
.execute(db.db())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct InsertActivity { | ||
pub topic: String, | ||
pub time: NaiveDateTime, | ||
pub uniq: Option<String>, | ||
pub latitude: Option<f32>, | ||
pub longitude: Option<f32>, | ||
pub content: serde_json::Value, | ||
} | ||
|
||
impl InsertToNew for InsertActivity { | ||
type Target = NewActivity; | ||
|
||
#[inline] | ||
fn try_into_new(self) -> Result<NewActivity> { | ||
let content = serde_json::to_string(&self.content)?; | ||
Ok(NewActivity { | ||
topic: self.topic, | ||
time: self.time, | ||
uniq: self.uniq, | ||
latitude: self.latitude, | ||
longitude: self.longitude, | ||
content, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,3 +424,6 @@ pub use self::port::*; | |
|
||
mod cryptoaddr; | ||
pub use self::cryptoaddr::*; | ||
|
||
mod activity; | ||
pub use self::activity::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.