aboutsummaryrefslogtreecommitdiffstats
path: root/license-generator/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'license-generator/src/main.rs')
-rw-r--r--license-generator/src/main.rs75
1 files changed, 64 insertions, 11 deletions
diff --git a/license-generator/src/main.rs b/license-generator/src/main.rs
index ccf2a73..bd8b192 100644
--- a/license-generator/src/main.rs
+++ b/license-generator/src/main.rs
@@ -17,6 +17,7 @@ use license_generator::database;
use license_generator::errors::*;
use license_generator::purchaser::Purchaser;
use license_generator::request;
+use license_generator::response;
fn main() -> Result<()> {
let log_file_path = env::var("LOG_FILE")
@@ -48,23 +49,75 @@ fn main() -> Result<()> {
}
fastcgi::run(|mut req| {
- write!(&mut req.stdout(), "Content-Type: text/plain\n\nHello, world!")
- .unwrap_or(());
+ match req.param("REQUEST_METHOD") {
+ Some(method) => {
+ if method != "POST" {
+ response::set_405(&mut req.stdout(), "POST")
+ .unwrap_or(());
+ write!(&mut req.stdout(), "Content-Type: text/plain
+
+405 Method Not Allowed")
+ .unwrap_or(());
+
+ return;
+ }
+ },
+ None => {
+ response::set_500(&mut req.stdout()).unwrap_or(());
+ write!(&mut req.stdout(), "Content-Type: text/plain
+
+500 Internal Server Error")
+ .unwrap_or(());
+
+ return;
+ },
+ };
+
+ let mut stdin = String::new();
+ match req.stdin().read_to_string(&mut stdin) {
+ Ok(_) => (),
+ Err(e) => {
+ error!("{}", e);
+
+ response::set_500(&mut req.stdout()).unwrap_or(());
+ write!(&mut req.stdout(), "Content-Type: text/plain
- let mut params = String::new();
- for (key, val) in req.params() {
- params.push_str(format!("{}: {}\n", key, val).as_str());
+500 Internal Server Error")
+ .unwrap_or(());
+
+ return;
+ },
}
- info!("{}", params);
+ let is_verified = match request::verified(&stdin) {
+ Ok(v) => v,
+ Err(e) => {
+ error!("{}", e);
- let mut stdin = String::new();
- req.stdin().read_to_string(&mut stdin).unwrap();
+ response::set_500(&mut req.stdout()).unwrap_or(());
+ write!(&mut req.stdout(), "Content-Type: text/plain
+
+500 Internal Server Error")
+ .unwrap_or(());
- info!("{}", stdin);
+ return;
+ },
+ };
- let is_verified = request::verified(&stdin);
- info!("{:?}", is_verified);
+ if !is_verified {
+ response::set_403(&mut req.stdout()).unwrap_or(());
+ write!(&mut req.stdout(), "Content-Type: text/plain
+
+403 Forbidden: Invalid request signature")
+ .unwrap_or(());
+
+ return;
+ }
+
+ write!(&mut req.stdout(), "Content-Type: text/plain
+
+200 OK")
+ .unwrap_or(());
});
Ok(())