diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..ddc2b53 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,22 @@ +name: Rust + +on: + push: + branches: [ "Development" ] + pull_request: + branches: [ "Development" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index 0d72193..478548d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,11 +224,63 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + [[package]] name = "anthena" -version = "0.1.0" +version = "0.1.22" dependencies = [ "actix-web", + "anyhow", + "clap", "dotenv", "rand 0.8.5", "reqwest", @@ -385,12 +437,58 @@ dependencies = [ "windows-link", ] +[[package]] +name = "clap" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + [[package]] name = "cmov" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746" +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + [[package]] name = "const-oid" version = "0.10.2" @@ -1124,6 +1222,12 @@ dependencies = [ "serde", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "itoa" version = "1.0.18" @@ -1323,6 +1427,12 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + [[package]] name = "openssl" version = "0.10.76" @@ -1960,6 +2070,12 @@ dependencies = [ "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" @@ -2326,6 +2442,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 0d6db2a..e13adeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "anthena" -version = "0.1.0" +version = "0.1.22" edition = "2024" [dependencies] @@ -12,7 +12,8 @@ serde_json = "1" tokio = { version = "1", features = ["full"] } reqwest = { version = "0.12", features = ["json"] } tokio-postgres = { version = "0.7", features=["with-chrono-0_4"]} - +anyhow = "1.0" +clap = { version = "4.5",features = ["derive"]} [profile.release] opt-level = 3 lto = true \ No newline at end of file diff --git a/DOC/README.md b/document/README.md similarity index 100% rename from DOC/README.md rename to document/README.md diff --git a/document/README/en.md b/document/README/en.md new file mode 100644 index 0000000..e69de29 diff --git a/DOC/development/README.md b/document/development/README.md similarity index 100% rename from DOC/development/README.md rename to document/development/README.md diff --git a/DOC/development/installer/README.md b/document/development/installer/README.md similarity index 100% rename from DOC/development/installer/README.md rename to document/development/installer/README.md diff --git a/DOC/development/installer/installer.md b/document/development/installer/installer.md similarity index 100% rename from DOC/development/installer/installer.md rename to document/development/installer/installer.md diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..3fe3b1f --- /dev/null +++ b/install.sh @@ -0,0 +1,2 @@ +sudo apt update +sudo apt install curl \ No newline at end of file diff --git a/src/admin/index.html b/src/admin/index.html new file mode 100644 index 0000000..6ae3b7d --- /dev/null +++ b/src/admin/index.html @@ -0,0 +1,16 @@ + + + + ANTHENA - 管理パネルトップ + + + + +
+

ようこそ

+

ANTHENAの最高権限がある管理パネルです。

+

注意:このパネルにはANTHENAの最高権限が付与されているため、公開しないようにしてください。 +

+
+ + \ No newline at end of file diff --git a/src/admin/index.js b/src/admin/index.js new file mode 100644 index 0000000..1a583ac --- /dev/null +++ b/src/admin/index.js @@ -0,0 +1,6 @@ +/* + ANTHENAの管理ページは時間があって + 気が向いたら作ります。 + + まぁ、作れる人がいたら作ってくれるとありがたいです。 +*/ \ No newline at end of file diff --git a/src/admin/style.css b/src/admin/style.css new file mode 100644 index 0000000..2b2d5c7 --- /dev/null +++ b/src/admin/style.css @@ -0,0 +1,5 @@ +/* + + 未実装 + +*/ \ No newline at end of file diff --git a/src/installer/installer.rs b/src/installer/installer.rs index 2c1c26c..c56b129 100644 --- a/src/installer/installer.rs +++ b/src/installer/installer.rs @@ -1,26 +1,45 @@ use std::process::Command; use std::process; +use std::env; +use tokio; +use tokio_postgres::{NoTls,Error}; +use std::fs; +use std::io::{self,BufRead}; + +const SYSTEM_USERNAME:&str = "ANTHENA"; + pub fn installer(){ - printwelcom(); - chek_postgres(); + let allow:bool = allow_install(); + if allow == true { + printwelcom(); + chek_postgres(); + }else if allow ==false { + println!("お使いのデバイスはANTHENAをインストールする要件が不足しています。"); + process::exit(0); + }else{ + println!("[ERROR]ANTHENAインストール中にエラーが発生しました。"); + process::exit(1); + } } + /* インストーラーを書く人へ 今はUbuntuしかサポートしていません。 今後別のディストリビューションへのサポートや別のOSへのサポートをする場合、OS検知と、サポート外OSへのインストール拒否を実装してください。 */ + fn printwelcom(){ let logo = r#" ╔═══════════════════════════════════╗ ║ ║ ║ A N T H E N A ║ ║ ║ - ║ 認証・認可システム ║ + ║ 認証・認可システム ║ ║ ║ ║ Authentication & Auth. ║ ║ ║ ╚═══════════════════════════════════╝ - "#; + "#;//絶対に手を加えないで println!("{logo}"); println!("Welcom to ANTHENA Instaler!!"); @@ -48,10 +67,12 @@ fn chek_postgres(){ } } + +//ANTHENAのインストール各処理 fn setup(){ println!("[INF]システムのインストールを準備中です..."); super::user::create_system_user(); - super::table::table(0); + super::table::create_table(); create_systemctl(); } @@ -90,7 +111,7 @@ fn create_systemctl(){ let systemname:&str = "anthenaauth.service"; println!("[INF]System名:{systemname}"); - + //この下か上にsystemctlを書く処理を実装する println!("[INF]サービスを読み込み中"); let _ = Command::new("sudo") .args(["systemctl", "daemon-reload"]) @@ -106,4 +127,41 @@ fn create_systemctl(){ println!("[INF]インストールが完了しました。インストールウェザードを終了します。"); process::exit(0); +} + +fn allow_install()->bool{ + let os:&str = env::consts::OS; + if os == "linux" { + let apt_available: bool = Command::new("which") + .arg("apt") + .output() + .map(|output| output.status.success()) + .unwrap_or(false); + apt_available + }else{ + false + } +} + +const DBNAME:&str = ""; +fn create_db(){ + println!("ここでDBに関する操作がおこなわれます。"); + //既存のDBに接続する必要があるため、パスワードがあったらな +} + + +fn user_exists(username:&str)->io::Result{ + let file = fs::File::Open("/etc/passwd")?; + + let reader = io::BufReader::new(file); + + for line in reader.lines(){ + let line = line?; + if let Some(name) = line.split(":").next(){ + if name == username { + return OK(true); + } + } + } + OK(false) } \ No newline at end of file diff --git a/src/installer/main.rs b/src/installer/main.rs index 19e7932..9e2a2cb 100644 --- a/src/installer/main.rs +++ b/src/installer/main.rs @@ -4,16 +4,13 @@ pub fn installer(installertype:i32){ let _ = Command::new("sudo") .args(["-l"]) .output(); - if installertype == 0 { - super::installer::installer(); - }else if installertype == 1 { - super::updater::update::update(); - }else if installertype == 2 { - super::uninstaller::uninstall::uninstall(); - }else{ - eprintln!("インストーラーの起動に失敗しました。"); - } + match installertype{ + 0 => super::installer::installer(), + 1 => super::updater::update::update(), + 2 => super::uninstaller::uninstall::uninstall(), + _ => println!("インストーラーの起動に失敗しました。"), + } } /* installertypeが0ならインストール,1ならアップデート,2ならアンインストールパッケージを実行します。*/ \ No newline at end of file diff --git a/src/installer/table.rs b/src/installer/table.rs index 6d530f7..b3f717a 100644 --- a/src/installer/table.rs +++ b/src/installer/table.rs @@ -1,17 +1,10 @@ -pub fn table(option:i32){ - if option == 0 { - create_table(); - }else if option == 1 { - del_table(); - }else{ - println!("[ERROR]不明なテーブル操作です。"); - } -} +/* + このファイル内に、DBのテーブルの作成、修復、削除、アップデート + に関するコードを書きます。 + まだ現時点でANTHENA自体の設計図を作っている途中なので + 現在はprintln!だけ実装しています-_- +*/ -fn create_table(){ - println!("[INF]テーブルをセットアップ中です..."); -} - -fn del_table(){ - println!("[INF]テーブルを削除中です..."); +pub fn create_table(){ + println!("[DEBUG]ここでは、テーブルに関する処理をおこないますが、現在はメモが出力されています。"); } \ No newline at end of file diff --git a/src/installer/user.rs b/src/installer/user.rs index abe67cb..b168ec2 100644 --- a/src/installer/user.rs +++ b/src/installer/user.rs @@ -1,7 +1,46 @@ +use rand::Rng; +use std::process::Command; +use std::process; + +const SYSTEM_USERNAME:&str = "ANTHENA"; + pub fn create_system_user(){ - println!("[MEM]この関数でUbuntuのユーザーを作成します。"); - /* - let _ = Command::new("sudo") - .args(["adduser",""]) - */ + let user_password:String = create_pass(); + println!("生成したパスワード:{user_password}"); + + let create = Command::new("useradd") + .args([ + "--system", + "--no-create-home", + "--shell", + "/usr/sbin/nologin", + SYSTEM_USERNAME + ]) + .status(); + match create { + Ok(s) if s.success() => { + println!("[INF]システムユーザーを作成しました。"); + } + Ok(_s) => { + eprintln!("[ERROR]システムユーザーの作成に失敗しました。"); + eprintln!("[ERROR]インストーラーを終了します。"); + process::exit(1); + } + Err(_e) => { + eprintln!("[ERROR]システムユーザーの作成に失敗しました。"); + eprintln!("[ERROR]インストーラーを終了します。"); + process::exit(1); + } + } +} + + +fn create_pass()-> String { + let pass:String = rand::thread_rng() + .sample_iter(&rand::distributions::Alphanumeric) + .take(10) + .map(char::from) + .collect(); + + pass } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index bd2ca3a..336e450 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,41 +1,17 @@ mod installer; -use std::env; - -use actix_web::{web,App,HttpServer,HttpRequest,HttpResponse}; -use reqwest::Client; +//use std::env; fn main() { let cheak_system = cheak_anthena_system(); if cheak_system == true { - api_server(); }else if cheak_system == false { - installer::main::installer(1);//これは、将来的にif文に直してください。 + installer::main::installer(0);//これは、将来的にif文に直してください。 }else{ println!("[INF]ANTHENA起動中にエラーが発生しました。"); } - api_server(); } fn cheak_anthena_system()-> bool { - true + false //今は問答無用でfalseを返してるけどここにインストール済みをチェックするコードを書きます。てか、書いてほしい。 -} -#[actix_web::main] -async fn api_server()->std::io::Result<()>{ - /* - HttpServer::new(||{ - App::new() - }) - .bind("0.0.0.0::8080")? - .run() - .await; - */ - println!("[INF]API起動中....");//仮 - loop{}//まぁ、APIが起動している風でいいでしょ今は - -} - -fn cheak_os()->bool { - //メモ:対応OSかどうかのみboolで返します。 - true } \ No newline at end of file