diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..1106474 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,34 @@ +**Note: for support questions, please use stackoverflow**. This repository's issues are reserved for feature requests and bug reports. + +* **I'm submitting a ...** + - [ ] bug report + - [ ] feature request + - [ ] support request => Please do not submit support request here, see note at the top of this template. + + +* **Do you want to request a *feature* or report a *bug*?** + + + +* **What is the current behavior?** + + + +* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** + + + +* **What is the expected behavior?** + + + +* **What is the motivation / use case for changing the behavior?** + + + +* **Please tell us about your environment:** + + - Version: v1.0.0 + - OS: [Windows | Linux | Mac] + +* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..155a1eb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,27 @@ +--- +name: Bug Report +about: Create a report to help us improve +title: "Bug: " +labels: bug +assignees: Xanthus58 +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Command to reproduce this behaviour: +`` + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. Fedora Linux] + - Version [e.g. 6.0.0] + +**Additional context** +Add any other context about the problem here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 0000000..edec139 Binary files /dev/null and b/.github/ISSUE_TEMPLATE/feature-request.md differ diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..e0da0d5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,29 @@ +-- +name: Pull Request +about: Create a PR and assist the development team +title: " " +assignees: Xanthus58 + +--- + +* **Please check if the PR fulfills these requirements** +- [ ] The commit message follows our guidelines and licences + + +* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) + + + +* **What is the current behavior?** (You can also link to an open issue here) + + + +* **What is the new behavior (if this is a feature change)?** + + + +* **Does this PR introduce a breaking change?** (What changes might users need to make in their application due to this PR?) + + + +* **Other information**: diff --git a/.github/workflows/artifacts.yaml b/.github/workflows/artifacts.yaml new file mode 100644 index 0000000..1230ca5 --- /dev/null +++ b/.github/workflows/artifacts.yaml @@ -0,0 +1,28 @@ +on: + release: + types: [created] + +name: Build-Artifacts +jobs: + release: + name: release ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-pc-windows-gnu + archive: zip + - target: x86_64-unknown-linux-musl + archive: tar.gz tar.xz tar.zst + - target: x86_64-apple-darwin + archive: zip + steps: + - uses: actions/checkout@master + - name: Compile and release + uses: rust-build/rust-build.action@v1.4.3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + RUSTTARGET: ${{ matrix.target }} + ARCHIVE_TYPES: ${{ matrix.archive }} \ No newline at end of file diff --git a/.github/workflows/rust-core.yaml b/.github/workflows/rust-core.yaml new file mode 100644 index 0000000..aeed275 --- /dev/null +++ b/.github/workflows/rust-core.yaml @@ -0,0 +1,98 @@ +# A custom github action for all of the core jobs i want done across all of my repos +# Made by @Xanthus58 + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support. + +name: Rust-Core + +on: + push: + branches: [ "*" ] + +jobs: +# Ensure the application can be built and run successfully + build: + name: Run Cargo build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose + +# Ensures theres no security vulnerabilities in the programs dependencies + security_audit: + name: Run Security-audit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/audit-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + +# Runs rust clippy for any and all suggestions + rust-clippy-analyze: + name: Run rust-clippy analyzing + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1 + with: + profile: minimal + toolchain: stable + components: clippy + override: true + + - name: Install required cargo + run: cargo install clippy-sarif sarif-fmt + + - name: Run rust-clippy + run: + cargo clippy + --all-features + --message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt + continue-on-error: true + + - name: Upload analysis results to GitHub + uses: github/codeql-action/upload-sarif@v1 + with: + sarif_file: rust-clippy-results.sarif + wait-for-processing: true + +# Runs cargo fmt and pushes any changes to the github repo + format: + name: Run Cargo fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + override: true + - uses: mbrobbel/rustfmt-check@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + +# Runs cargo update to update the cargo.lock file + update: + name: Run Cargo update + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - uses: actions-rs/cargo@v1 + with: + command: update + args: \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 209b1ac..73bebd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2616,18 +2616,18 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.171" +version = "1.0.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +checksum = "e91f70896d6720bc714a4a57d22fc91f1db634680e65c8efe13323f1fa38d53f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.171" +version = "1.0.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +checksum = "a6250dde8342e0232232be9ca3db7aa40aceb5a3e5dd9bddbc00d99a007cde49" dependencies = [ "proc-macro2", "quote", @@ -3906,9 +3906,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a56c84a8ccd4258aed21c92f70c0f6dea75356b6892ae27c24139da456f9336" +checksum = "47430998a7b5d499ccee752b41567bc3afc57e1327dc855b1a2aa44ce29b5fa1" [[package]] name = "zbus" diff --git a/src/main.rs b/src/main.rs index b7e16cc..34917d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,23 +25,27 @@ struct MyApp { closable: bool, duration: f32, - server_bool: bool, + server_valid: bool, ip: String, port: i32, login_bool: bool, username: String, password: String, + + tx: mpsc::Sender, + rx: mpsc::Receiver, } impl Default for MyApp { fn default() -> Self { + let (tx, rx) = mpsc::channel(); Self { toasts: Toasts::default().with_anchor(Anchor::BottomRight), closable: true, duration: 3.5, - server_bool: false, + server_valid: false, login_bool: false, ip: "127.0.0.1".to_owned(), @@ -49,6 +53,9 @@ impl Default for MyApp { username: "".to_owned(), password: "".to_owned(), + + tx, + rx, } } } @@ -64,22 +71,24 @@ impl eframe::App for MyApp { .set_duration(Some(Duration::from_millis((1000. * self.duration) as u64))); }; - if self.server_bool == false { + if !self.server_valid { ui.heading("Vault GUI"); ui.label("Please enter the ip and port of the sql server below"); ui.horizontal(|ui| { - ui.label("IP: "); + ui.label("IP:"); ui.text_edit_singleline(&mut self.ip); }); ui.horizontal(|ui| { - ui.label("Port: "); + ui.label("Port:"); ui.add(egui::DragValue::new(&mut self.port).speed(1.0).clamp_range(0..=65535)); }); if ui.button("Connect").clicked() { + cb(self.toasts.info("Testing connection...")); + let ip_verified = validate_ip_address(&self.ip); - if ip_verified == false { + if !ip_verified { cb(self.toasts.error("Invalid IP Address!")); println!("Invalid IP Address!"); return @@ -93,50 +102,55 @@ impl eframe::App for MyApp { let port = self.port; // Create a channel to communicate the result of the ping test - let (tx, rx) = mpsc::channel(); + let tx = self.tx.clone(); //TODO: Fix this async code and try to make it not freeze the gui thread::spawn(move || { let result = tokio::runtime::Runtime::new() .unwrap() .block_on(is_server_alive(ip, port as u16, 5)); - tx.send(result).unwrap(); + tx.send(dbg!(result)).expect("Failed to send result"); }); - - if let Ok(result) = rx.recv_timeout(Duration::from_secs(30)) { - if result { - cb(self.toasts.success("Connection Successful!")); - self.server_bool = true; - println!("Connection Successful!") - } else { - cb(self.toasts.error("Connection Failed!")); - println!("Connection Failed!") - } - } else { - cb(self.toasts.error("Connection Timed Out!")); - println!("Connection Timed Out!") - } } - } + } - if self.login_bool == false && self.server_bool == true { + if !self.login_bool && self.server_valid { ui.label("Please enter your username and password below"); + ui.horizontal(|ui| { - ui.label("Username: "); + ui.label("Username:"); ui.text_edit_singleline(&mut self.username); }); + ui.horizontal(|ui| { - ui.label("Password: "); + ui.label("Password:"); ui.add(egui::TextEdit::singleline(&mut self.password).password(true)); }); - if ui.button("Login").clicked() { - println!("Username: {}", self.username); - println!("Password: {}", self.password); + + ui.horizontal(|ui| { + if ui.button("Login").clicked() { + println!("Username: {}", self.username); + println!("Password: {}", self.password); + } + + if ui.button("Return").clicked() { + self.server_valid = false; + } + }); + } + + if let Ok(result) = self.rx.try_recv() { + if result { + cb(self.toasts.success("Connection Successful!")); + self.server_valid = true; + println!("Connection Successful!") + } else { + cb(self.toasts.error("Connection Failed!")); + println!("Connection Failed!") } } }); self.toasts.show(ctx); // Requests to render toasts } -} - +} \ No newline at end of file