From 9d794f1b961324af001cc4d0edac905b6978b629 Mon Sep 17 00:00:00 2001 From: 641i130 <46945263+641i130@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:11:43 -0500 Subject: [PATCH] Moved around --- src/main.rs | 60 ++++++++----------------------------- src/routes.rs | 1 + src/routes/card_routes.rs | 63 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 47 deletions(-) create mode 100644 src/routes/card_routes.rs diff --git a/src/main.rs b/src/main.rs index eb1295d..1a5d63c 100755 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ use futures_util::future::FutureExt; // Modules mod routes; use crate::routes::game_routes::game_stuff; +use crate::routes::card_routes::cardn; // AES mod cry; use crate::cry::aes::{aes_en, aes_dec}; @@ -74,6 +75,16 @@ async fn incomALL() -> HttpResponse { resp!("1+1") } +#[post("/service/incom/incom.php")] +async fn incom() -> HttpResponse { + resp!("1+1") +} + +#[post("/service/incom/shop.php")] +async fn shop() -> HttpResponse { + resp!("1+1") +} + #[post("/service/respone/respone.php")] async fn respone() -> HttpResponse { resp!("1") @@ -103,53 +114,6 @@ async fn game_info() -> HttpResponse { HttpResponse::Ok().append_header(ContentType::octet_stream()).body(ciphertext) } -// Card Command Codes -#[derive(Debug, Deserialize)] -pub enum CardCmd { - READ = 256, - REGISTER = 512, - REISSUE = 1536, -} - -impl CardCmd { - fn from_u16(cmd_str: u16) -> Option { - match cmd_str { - 256 => Some(CardCmd::READ), - 512 => Some(CardCmd::REGISTER), - 1536 => Some(CardCmd::REISSUE), - _ => None, // Handle unknown values - } - } -} - -#[derive(Debug, Deserialize)] -pub struct CardVals { - cmd_str: u16, // Commands for card functions - card_no: u64, // Example: 7020392002385103 -} - -#[post("/service/card/cardn.cgi")] -async fn cardn(web::Form(form): web::Form) -> HttpResponse { - dbg!(&form); - match CardCmd::from_u16(form.cmd_str) { - Some(CardCmd::READ) => { - println!("READ"); - resp!(format!("1\n1,1\n{}",form.card_no)) - }, - Some(CardCmd::REISSUE) => { - println!("REISSUE"); - resp!("27") - }, - Some(CardCmd::REGISTER) => { - println!("REGISTER"); - // Add user into database later - resp!(format!("1\n1,1\n{}",form.card_no)) - }, - _ => HttpResponse::NotFound().into() - } -} - - #[derive(Serialize, Deserialize, Debug)] pub struct Certify { pub gid: u32, @@ -220,6 +184,8 @@ async fn main() -> std::io::Result<()> { .service(alive) .service(alive_i) .service(incomALL) + .service(incom) + .service(shop) .service(respone) .service(fire_alert) .service(cursel) diff --git a/src/routes.rs b/src/routes.rs index 6970908..0add41f 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,3 +1,4 @@ pub mod game_routes; pub mod nesys_routes; +pub mod card_routes; diff --git a/src/routes/card_routes.rs b/src/routes/card_routes.rs new file mode 100644 index 0000000..7aa0b78 --- /dev/null +++ b/src/routes/card_routes.rs @@ -0,0 +1,63 @@ +use colored::Colorize; +use actix_web::{web, HttpResponse, dev::Service, dev::ServiceRequest, dev::ServiceResponse, Error, Result, get, http::header::ContentType, post, App, HttpRequest, HttpServer}; +// AES +use crate::cry::aes::{aes_en, aes_dec}; + +macro_rules! resp { + ($str:expr) => { + //HttpResponse::Ok().append_header(ContentType(mime::TEXT_HTML)).body($str) + HttpResponse::Ok().append_header(ContentType::octet_stream()).body($str) + }; +} + +/////////////////////////////////////////////////////////////////////////////////////////// +use serde::Deserialize; + + +// Card Command Codes +#[derive(Debug, Deserialize)] +pub enum CardCmd { + READ = 256, + REGISTER = 512, + REISSUE = 1536, +} + +impl CardCmd { + fn from_u16(cmd_str: u16) -> Option { + match cmd_str { + 256 => Some(CardCmd::READ), + 512 => Some(CardCmd::REGISTER), + 1536 => Some(CardCmd::REISSUE), + _ => None, // Handle unknown values + } + } +} + +#[derive(Debug, Deserialize)] +pub struct CardVals { + cmd_str: u16, // Commands for card functions + card_no: u64, // Example: 7020392002385103 +} + +#[post("/service/card/cardn.cgi")] +async fn cardn(web::Form(form): web::Form) -> HttpResponse { + dbg!(&form); + match CardCmd::from_u16(form.cmd_str) { + Some(CardCmd::READ) => { + println!("READ"); + resp!(format!("1\n1,1\n{}",form.card_no)) + }, + Some(CardCmd::REISSUE) => { + println!("REISSUE"); + resp!("27") + }, + Some(CardCmd::REGISTER) => { + println!("REGISTER"); + // Add user into database later + resp!(format!("1\n1,1\n{}",form.card_no)) + }, + _ => HttpResponse::NotFound().into() + } +} + +