mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2026-04-30 18:49:09 +00:00
Compare commits
3 Commits
0e7bd8f627
...
fe4efdda81
| Author | SHA1 | Date | |
|---|---|---|---|
| fe4efdda81 | |||
| 64299960a5 | |||
| ed0942e332 |
24
fwa.service
Normal file
24
fwa.service
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Feuerwehr Anwesenheit Service
|
||||||
|
Requires=local-fs.target
|
||||||
|
After=local-fs.target
|
||||||
|
StartLimitIntervalSec=500
|
||||||
|
StartLimitBurst=5
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/local/bin/fwa
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
User=root
|
||||||
|
Group=root
|
||||||
|
RuntimeDirectory=/var/lib/fwa
|
||||||
|
|
||||||
|
Environment="PM3_BIN=/usr/local/bin/pm3/pm3"
|
||||||
|
#Environment="LOG_LEVEL=warn"
|
||||||
|
#Environment="HOTSPOT_IDS=578B5DF2;c1532b57"
|
||||||
|
#Environment="HOTSPOT_SSID=fwa"
|
||||||
|
#Environment="HOTSPOT_PW=a9LG2kUVrsRRVUo1"
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Feuerwehr Anwesenheit Service
|
|
||||||
Requires=local-fs.target
|
|
||||||
After=local-fs.target
|
|
||||||
StartLimitIntervalSec=500
|
|
||||||
StartLimitBurst=5
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
ExecStart=/home/pi/fw-anwesenheit
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5
|
|
||||||
User=root
|
|
||||||
Group=root
|
|
||||||
Environment="PM3_BIN=/home/pi/proxmark3/pm3"
|
|
||||||
RuntimeDirectory=/home/pi
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
31
src/pm3.rs
31
src/pm3.rs
@@ -1,4 +1,4 @@
|
|||||||
use log::{info, trace};
|
use log::{debug, info, trace, warn};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
@@ -10,6 +10,8 @@ use tokio::sync::broadcast;
|
|||||||
/// The pm3 binary is ether set in the env var PM3_BIN or found in the path
|
/// The pm3 binary is ether set in the env var PM3_BIN or found in the path
|
||||||
/// The ouput is parsed and send via the `tx` channel
|
/// The ouput is parsed and send via the `tx` channel
|
||||||
pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>> {
|
pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>> {
|
||||||
|
kill_orphans().await;
|
||||||
|
|
||||||
let pm3_path = match env::var("PM3_BIN") {
|
let pm3_path = match env::var("PM3_BIN") {
|
||||||
Ok(path) => path,
|
Ok(path) => path,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@@ -32,10 +34,15 @@ pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>
|
|||||||
|
|
||||||
let mut reader = BufReader::new(stdout).lines();
|
let mut reader = BufReader::new(stdout).lines();
|
||||||
|
|
||||||
|
let mut last_id: String = "".to_owned();
|
||||||
|
|
||||||
while let Some(line) = reader.next_line().await? {
|
while let Some(line) = reader.next_line().await? {
|
||||||
trace!("PM3: {line}");
|
trace!("PM3: {line}");
|
||||||
if let Some(uid) = super::parser::parse_line(&line) {
|
if let Some(uid) = super::parser::parse_line(&line) {
|
||||||
tx.send(uid)?;
|
if last_id == uid {
|
||||||
|
tx.send(uid.clone())?;
|
||||||
|
}
|
||||||
|
last_id = uid.to_owned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,3 +54,23 @@ pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>
|
|||||||
Err("PM3 exited with a non zero exit code".into())
|
Err("PM3 exited with a non zero exit code".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Kills any open pm3 instances
|
||||||
|
/// Also funny name. hehehe.
|
||||||
|
async fn kill_orphans() {
|
||||||
|
let kill_result = Command::new("pkill")
|
||||||
|
.arg("-KILL")
|
||||||
|
.arg("-x")
|
||||||
|
.arg("proxmark3")
|
||||||
|
.output()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match kill_result {
|
||||||
|
Ok(_) => {
|
||||||
|
debug!("Successfully killed orphaned pm3 instances");
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("Failed to kill pm3 orphans: {e} Continuing anyway");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user