This repository has been archived by the owner on Apr 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
joxcat
committed
Jul 16, 2019
0 parents
commit 1c169c0
Showing
26 changed files
with
1,050 additions
and
0 deletions.
There are no files selected for viewing
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,21 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
/.idea | ||
/.vscode | ||
|
||
/keys | ||
user_db | ||
|
||
**/*.exe | ||
**/*.zip | ||
**/*.pub | ||
**/*.prv |
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,8 @@ | ||
{ | ||
"generalSettings": { | ||
"shouldScanRepo": true | ||
}, | ||
"checkRunSettings": { | ||
"vulnerableCheckRunConclusionLevel": "failure" | ||
} | ||
} |
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,20 @@ | ||
[package] | ||
name = "hume-endpoints" | ||
version = "0.1.0" | ||
authors = ["Arthur Hugon <dev@planchon.xyz>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
actix-web = "1.0.2" | ||
actix-web-codegen = "0.1" | ||
log = "0.4" | ||
badlog = "1.1" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
base64 = "0.10" | ||
simple-error = "0.2" | ||
futures = "0.1" | ||
http = "0.1" | ||
arthur-hugon-tools = { git = "https://github.com/joxcat/arthur-hugon-tools.git", features = ["security","urlenc","passwords","simple-db"] } | ||
chrono = "0.4" | ||
lazy_static = "1.3" |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Planchon | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
hume-endpoints |
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,15 @@ | ||
#![allow(dead_code)] | ||
pub const ADDR: &str = "127.0.0.1:3001"; | ||
pub const LOG_LEVEL: &str = "INFO"; | ||
#[cfg(target_os = "windows")] | ||
pub const EXECUTABLE_PATH: &str = "\\bin"; | ||
#[cfg(not(target_os = "windows"))] | ||
pub const EXECUTABLE_PATH: &str = "/bin"; | ||
#[cfg(target_os = "windows")] | ||
pub const CERTIFICATOR: &str = "\\gsuite-cert.exe"; | ||
#[cfg(not(target_os = "windows"))] | ||
pub const CERTIFICATOR: &str = "/gsuite-cert"; | ||
#[cfg(target_os = "windows")] | ||
pub const NEXT: &str = "\\nextcloud-api-rs.exe"; | ||
#[cfg(not(target_os = "windows"))] | ||
pub const NEXT: &str = "/nextcloud-api-rs"; |
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,13 @@ | ||
#![allow(dead_code)] | ||
|
||
pub type ErrorChainResult<T> = Result<T, Box<dyn std::error::Error>>; | ||
|
||
type CustomErrorResult = super::structs::ResponseTypes; | ||
pub fn custom_404(reason: &str) -> super::structs::Response<CustomErrorResult> { | ||
super::structs::Response { | ||
status_code: 400, | ||
err_short: Some("Bad Request"), | ||
err_long: Some(reason), | ||
value: None as super::structs::GenericResponse<CustomErrorResult>, | ||
} | ||
} |
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,10 @@ | ||
pub use super::structs; | ||
|
||
mod consts; | ||
pub use consts::*; | ||
|
||
mod dynamics; | ||
pub use dynamics::*; | ||
|
||
mod prefab; | ||
pub use prefab::*; |
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,48 @@ | ||
#![allow(dead_code)] | ||
pub const ERROR_400: super::structs::Response<super::structs::ResponseTypes> = | ||
super::structs::Response { | ||
status_code: 400, | ||
err_short: Some("Bad Request"), | ||
err_long: Some("Bad parameters in the request!"), | ||
value: None as super::structs::GenericResponse<super::structs::ResponseTypes>, | ||
}; | ||
|
||
pub const ERROR_401: super::structs::Response<super::structs::ResponseTypes> = | ||
super::structs::Response { | ||
status_code: 401, | ||
err_short: Some("Unauthorized"), | ||
err_long: Some("Please authenticate yourself correctly"), | ||
value: None as super::structs::GenericResponse<super::structs::ResponseTypes>, | ||
}; | ||
|
||
pub const ERROR_403: super::structs::Response<super::structs::ResponseTypes> = | ||
super::structs::Response { | ||
status_code: 403, | ||
err_short: Some("Forbidden"), | ||
err_long: Some("Please make another request"), | ||
value: None as super::structs::GenericResponse<super::structs::ResponseTypes>, | ||
}; | ||
|
||
pub const ERROR_404: super::structs::Response<super::structs::ResponseTypes> = | ||
super::structs::Response { | ||
status_code: 404, | ||
err_short: Some("Not Found"), | ||
err_long: Some("Route not found!"), | ||
value: None as super::structs::GenericResponse<super::structs::ResponseTypes>, | ||
}; | ||
|
||
pub const ERROR_405: super::structs::Response<super::structs::ResponseTypes> = | ||
super::structs::Response { | ||
status_code: 405, | ||
err_short: Some("Method Not Allowed"), | ||
err_long: Some("This method is not allowed here!"), | ||
value: None as super::structs::GenericResponse<super::structs::ResponseTypes>, | ||
}; | ||
|
||
pub const ERROR_500: super::structs::Response<super::structs::ResponseTypes> = | ||
super::structs::Response { | ||
status_code: 500, | ||
err_short: Some("Internal Server Error"), | ||
err_long: Some("Internal server error please try again soon!"), | ||
value: None as super::structs::GenericResponse<super::structs::ResponseTypes>, | ||
}; |
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,42 @@ | ||
use std::process::Command; | ||
|
||
pub fn execute(app: &str, args: &[&str]) -> Result<String, Box<dyn std::error::Error>> { | ||
Ok(String::from_utf8( | ||
Command::new(format!( | ||
"{}{}{}", | ||
std::env::current_exe()? | ||
.parent() | ||
.ok_or("Folder not found")? | ||
.to_str() | ||
.ok_or("Folder not found")?, | ||
super::defaults::EXECUTABLE_PATH, | ||
app | ||
)) | ||
.args(args) | ||
.output()? | ||
.stdout, | ||
)?) | ||
} | ||
|
||
pub fn execute_with_envs( | ||
app: &str, | ||
args: &[&str], | ||
envs: Vec<(&str, &str)>, | ||
) -> Result<String, Box<dyn std::error::Error>> { | ||
Ok(String::from_utf8( | ||
Command::new(format!( | ||
"{}{}{}", | ||
std::env::current_exe()? | ||
.parent() | ||
.ok_or("Folder not found")? | ||
.to_str() | ||
.ok_or("Folder not found")?, | ||
super::defaults::EXECUTABLE_PATH, | ||
app | ||
)) | ||
.args(args) | ||
.envs(envs) | ||
.output()? | ||
.stdout, | ||
)?) | ||
} |
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,13 @@ | ||
mod structures; | ||
pub mod structs { | ||
pub use super::structures::*; | ||
} | ||
|
||
mod methods; | ||
pub use methods::*; | ||
|
||
pub mod defaults; | ||
|
||
pub mod routes; | ||
|
||
pub mod security; |
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 @@ | ||
use super::{ | ||
defaults, execute, | ||
structs::{ExternalResponse, IdOnly, Response, ResponseTypes}, | ||
}; | ||
use crate::library::security::{get_token, validate_token}; | ||
use actix_web::web::Json; | ||
use actix_web::{HttpRequest, HttpResponse}; | ||
use actix_web_codegen::delete; | ||
|
||
/** | ||
* @todo Create the method in nextcloud-rust-api | ||
*/ | ||
#[delete("/nextcloud/user")] | ||
pub fn sync_delete_nextcloud_user( | ||
req: HttpRequest, | ||
params: Json<IdOnly>, | ||
) -> actix_web::Result<HttpResponse> { | ||
match get_token(req.headers()) { | ||
Ok(x) => { | ||
if validate_token(x.as_str()).unwrap() { | ||
let res = |id: String| -> Result<String, Box<dyn std::error::Error>> { | ||
Ok(execute(defaults::NEXT, &["delete", "-i", id.as_str()])?) | ||
}; | ||
|
||
Ok(match res(params.clone().id) { | ||
Ok(x) => { | ||
let x = ss!(ExternalResponse<bool>, x.as_str()); | ||
let x = Response::ok(200, ResponseTypes::Boolean(x.value.unwrap())); | ||
response!(Ok, x) | ||
} | ||
Err(e) => response!(BadRequest, e.to_string()), | ||
_ => response!(InternalServerError, defaults::ERROR_500), | ||
}) | ||
} else { | ||
Ok(response!(Unauthorized, defaults::ERROR_401)) | ||
} | ||
} | ||
Err(e) => Ok(response!(BadRequest, defaults::ERROR_400)), | ||
} | ||
} |
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,45 @@ | ||
use super::{ | ||
defaults, | ||
structs::{Response, ResponseTypes}, | ||
}; | ||
use crate::library::security::{disconnect, get_token, mail_from_token, validate_token}; | ||
use actix_web::{HttpRequest, HttpResponse}; | ||
use actix_web_codegen::delete; | ||
|
||
/** | ||
* @todo Generate SA Certs | ||
*/ | ||
#[delete("/session")] | ||
pub fn sync_post_logout(req: HttpRequest) -> actix_web::Result<HttpResponse> { | ||
Ok(match get_token(req.headers()) { | ||
Ok(x) => match validate_token(x.clone().as_str()) { | ||
Ok(v) => { | ||
if v { | ||
match mail_from_token(x.clone()) { | ||
Ok(x) => match disconnect(x.as_str()) { | ||
Ok(x) => { | ||
if x { | ||
response!( | ||
Ok, | ||
Response::ok( | ||
200, | ||
ResponseTypes::PlainText("disconnecting".to_owned()) | ||
) | ||
) | ||
} else { | ||
response!(InternalServerError, defaults::ERROR_403) | ||
} | ||
} | ||
Err(_) => response!(InternalServerError, defaults::ERROR_500), | ||
}, | ||
Err(_) => response!(InternalServerError, defaults::ERROR_500), | ||
} | ||
} else { | ||
response!(Unauthorized, defaults::ERROR_401) | ||
} | ||
} | ||
Err(_) => response!(Unauthorized, defaults::ERROR_401), | ||
}, | ||
Err(_) => response!(BadRequest, defaults::ERROR_400), | ||
}) | ||
} |
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,61 @@ | ||
use super::{ | ||
defaults, execute, | ||
structs::{ExternalResponse, NextCloudCoke, NextCloudUser, Response, ResponseTypes}, | ||
}; | ||
use crate::library::security::{get_token, validate_token}; | ||
use actix_web::web::Json; | ||
use actix_web::{HttpRequest, HttpResponse}; | ||
use actix_web_codegen::get; | ||
|
||
#[get("/nextcloud/cookies")] | ||
pub fn sync_get_nextcloud_cookies( | ||
req: HttpRequest, | ||
params: Json<NextCloudUser>, | ||
) -> actix_web::Result<HttpResponse> { | ||
match get_token(req.headers()) { | ||
Ok(x) => { | ||
if validate_token(x.as_str()).unwrap() { | ||
let res = |(u, p): (String, String), | ||
r: Option<String>| | ||
-> Result<String, Box<dyn std::error::Error>> { | ||
Ok(match r { | ||
Some(x) => execute( | ||
defaults::NEXT, | ||
&[ | ||
"cookies", | ||
"-u", | ||
u.as_str(), | ||
"-p", | ||
p.as_str(), | ||
"-e", | ||
x.as_str(), | ||
], | ||
)?, | ||
None => execute( | ||
defaults::NEXT, | ||
&["cookies", "-u", u.as_str(), "-p", p.as_str()], | ||
)?, | ||
}) | ||
}; | ||
|
||
Ok( | ||
match res( | ||
(params.clone().username, params.clone().password), | ||
params.clone().response_type, | ||
) { | ||
Ok(x) => { | ||
let x = ss!(ExternalResponse<NextCloudCoke>, x.as_str()); | ||
let x = Response::ok(200, ResponseTypes::Cookie(x.value.unwrap())); | ||
response!(Ok, x) | ||
} | ||
Err(e) => response!(BadRequest, e.to_string()), | ||
_ => response!(InternalServerError, defaults::ERROR_500), | ||
}, | ||
) | ||
} else { | ||
Ok(response!(Unauthorized, defaults::ERROR_401)) | ||
} | ||
} | ||
Err(e) => Ok(response!(BadRequest, defaults::ERROR_400)), | ||
} | ||
} |
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,10 @@ | ||
use actix_web::HttpResponse; | ||
use actix_web_codegen::get; | ||
|
||
/** | ||
* @todo Create the method in daemon-hume | ||
*/ | ||
#[get("/sa")] | ||
pub fn sync_get_sa() -> actix_web::Result<HttpResponse> { | ||
Ok(HttpResponse::Ok().finish()) | ||
} |
Oops, something went wrong.