mirror of
https://git.nickiel.net/Nickiel/nicks_nextcloud_integrations.git
synced 2025-04-03 01:51:29 -07:00
Compare commits
16 commits
a50efdeea0
...
3faccc1b99
Author | SHA1 | Date | |
---|---|---|---|
3faccc1b99 | |||
c9ff715dca | |||
cb4def2aee | |||
5ddc4274c8 | |||
395244fbc1 | |||
84581376b6 | |||
2a082646b1 | |||
16b74d9cdd | |||
f88f190386 | |||
6ef6ef6588 | |||
40131dcad8 | |||
8b17e76d42 | |||
9cf719abe4 | |||
0f107a3985 | |||
0551352b7e | |||
8494664829 |
4 changed files with 137 additions and 104 deletions
160
Cargo.lock
generated
160
Cargo.lock
generated
|
@ -208,18 +208,6 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "confy"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e37668cb35145dcfaa1931a5f37fde375eeae8068b4c0d2f289da28a270b2d2c"
|
||||
dependencies = [
|
||||
"directories",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
|
@ -236,26 +224,6 @@ version = "0.8.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||
|
||||
[[package]]
|
||||
name = "directories"
|
||||
version = "4.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.32"
|
||||
|
@ -265,6 +233,12 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.2"
|
||||
|
@ -370,17 +344,6 @@ dependencies = [
|
|||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.27.3"
|
||||
|
@ -399,7 +362,7 @@ dependencies = [
|
|||
"futures-sink",
|
||||
"futures-util",
|
||||
"http",
|
||||
"indexmap",
|
||||
"indexmap 1.9.3",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
|
@ -412,6 +375,12 @@ version = "0.12.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
|
@ -535,7 +504,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
"hashbrown 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.14.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -753,15 +732,6 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.3.5"
|
||||
|
@ -771,17 +741,6 @@ dependencies = [
|
|||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall 0.2.16",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.18"
|
||||
|
@ -907,6 +866,15 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
|
@ -954,10 +922,10 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
"confy",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -985,31 +953,11 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
|
|||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"redox_syscall 0.3.5",
|
||||
"redox_syscall",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.45"
|
||||
|
@ -1078,11 +1026,36 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.11"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
|
||||
checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.19.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a"
|
||||
dependencies = [
|
||||
"indexmap 2.0.0",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1355,6 +1328,15 @@ version = "0.48.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.10.1"
|
||||
|
|
|
@ -37,7 +37,7 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
|
|||
rustSettings = with pkgs; {
|
||||
src = ./.;
|
||||
nativeBuildInputs = [ pkg-config ];
|
||||
buildInputs = [ openssl ];
|
||||
buildInputs = [ openssl hddtemp ];
|
||||
cargoHash = nixpkgs.lib.fakeHash;
|
||||
};
|
||||
meta = with nixpkgs.lib; {
|
||||
|
@ -62,7 +62,7 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
|
|||
pname = "status_cloud";
|
||||
version = "0.1.0";
|
||||
buildAndTestSubdir = "status_cloud";
|
||||
cargoHash = "sha256-2eSCxWKf2VH9escaWUDFcozJyyo4xt9SCgBPxlwckTk=";
|
||||
cargoHash = "sha256-Z5JFg9OnCOO9jM/J5T9Tr64x21HOxNf8M4qJKiXiF54=";
|
||||
meta = meta // {
|
||||
description = "Server status saved to a nextcloud note service.";
|
||||
};
|
||||
|
@ -93,11 +93,12 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
|
|||
cfg = config.services.status_cloud;
|
||||
pkg = self.packages.${system}.status_cloud;
|
||||
in lib.mkIf cfg.enable {
|
||||
description = pkg.meta.description;
|
||||
#description = pkg.meta.description;
|
||||
description = "Status Cloud";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = ''
|
||||
${cfg.package}/bin/status_cloud --config_file ${builtins.toString cfg.config_path}
|
||||
${cfg.package}/bin/status_cloud --hddtemp-executable ${pkgs.hddtemp}/bin/hddtemp --config-file ${builtins.toString cfg.config_path}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
chrono = "0.4.26"
|
||||
clap = { version = "4.4.0", features = ["derive"] }
|
||||
confy = "0.5.1"
|
||||
reqwest = { version = "0.11.18", features = ["blocking", "json"] }
|
||||
serde = { version = "1.0.184", features = ["serde_derive"] }
|
||||
serde_json = "1.0.105"
|
||||
toml = "0.7.6"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use reqwest::blocking::Client;
|
||||
|
||||
use toml;
|
||||
use clap::Parser;
|
||||
use confy;
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
|
@ -12,13 +12,38 @@ use std::process::Command;
|
|||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let args = CliArgs::parse();
|
||||
let cfg: Config = confy::load_path(args.config_file)?;
|
||||
|
||||
println!("Opening Config file: {}", args.config_file);
|
||||
println!("File exists: {}", std::fs::metadata(args.config_file.clone()).is_ok());
|
||||
|
||||
let file_contents = match std::fs::read_to_string(args.config_file) {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
println!("Could not read file: {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let cfg: Config = match toml::from_str(file_contents.as_str()) {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
println!("Could not parse file: {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let mut body_content: String = format!("*Last Updated:* {} \n", chrono::Local::now().format("%D - %H:%M:%S"));
|
||||
|
||||
let mut drives: Vec<String> = vec![];
|
||||
|
||||
{
|
||||
let rust_drives = std::fs::read_dir("/dev/").unwrap();
|
||||
let rust_drives = match std::fs::read_dir("/dev/") {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
println!("Error opening /dev/: {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
for path in rust_drives {
|
||||
match path {
|
||||
|
@ -35,14 +60,35 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
}
|
||||
|
||||
match Command::new(args.hddtemp_executable.clone()).output() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
println!("Error running hddtemp at all: {}", e.to_string());
|
||||
println!("hddtemp = {}", args.hddtemp_executable.clone());
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
let mut drive_temps: Vec<String> = vec![];
|
||||
|
||||
for drive in drives {
|
||||
let output = Command::new("hddtemp").arg(drive).output()?;
|
||||
let output = match Command::new(args.hddtemp_executable.clone()).arg(drive.clone()).output() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
println!("Error running hddtemp: {}", e.to_string());
|
||||
println!("Drive was: '{}'", drive);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let tmp = std::str::from_utf8(&output.stdout)?.to_string();
|
||||
let tmp = match std::str::from_utf8(&output.stdout) {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
println!("Error parsing hddtemp output: {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
}.to_string();
|
||||
|
||||
if !tmp.contains("sensor") {
|
||||
drive_temps.push(tmp.replace("\n", "Not running as sudo?"));
|
||||
|
@ -55,14 +101,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
|
||||
|
||||
let update = Client::new()
|
||||
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", cfg.note_id.clone()))
|
||||
Client::new()
|
||||
.put(format!("https://{}/index.php/apps/notes/api/v1/notes/{}", cfg.server_url.clone(), cfg.note_id.clone()))
|
||||
.header("Accept", "application/json")
|
||||
.header("Content-Type", "application/json")
|
||||
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
|
||||
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
|
||||
|
||||
//println!("{:#?}", update.send()?.json::<Note>()?);
|
||||
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap())
|
||||
.send()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -90,6 +135,7 @@ struct Config {
|
|||
user: String,
|
||||
pswd: String,
|
||||
note_id: String,
|
||||
server_url: String
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -98,6 +144,7 @@ impl Default for Config {
|
|||
user: "".to_string(),
|
||||
pswd: "".to_string(),
|
||||
note_id: "".to_string(),
|
||||
server_url: "".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,4 +155,7 @@ struct CliArgs {
|
|||
/// Path to config .toml file
|
||||
#[arg(short, long)]
|
||||
config_file: String,
|
||||
|
||||
#[arg(short, long)]
|
||||
hddtemp_executable: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue