Compare commits
3 Commits
ab8bfbbed3
...
61cc570289
Author | SHA1 | Date | |
---|---|---|---|
61cc570289 | |||
ed4b8153bb | |||
|
41f8e8f2ab |
@ -1 +1 @@
|
|||||||
DATABASE_URL=sqlite://C:/Users/Joe/AppData/Roaming/creddy/creddy.dev.db
|
DATABASE_URL=sqlite://creddy.db?mode=rwc
|
||||||
|
13
src-tauri/Cargo.lock
generated
13
src-tauri/Cargo.lock
generated
@ -69,7 +69,6 @@ dependencies = [
|
|||||||
"aws-types",
|
"aws-types",
|
||||||
"clap",
|
"clap",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
"is-terminal",
|
|
||||||
"netstat2",
|
"netstat2",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"serde",
|
"serde",
|
||||||
@ -2016,18 +2015,6 @@ dependencies = [
|
|||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "is-terminal"
|
|
||||||
version = "0.4.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi 0.3.1",
|
|
||||||
"io-lifetimes",
|
|
||||||
"rustix",
|
|
||||||
"windows-sys 0.48.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.10.5"
|
version = "0.10.5"
|
||||||
|
@ -35,7 +35,6 @@ strum_macros = "0.24"
|
|||||||
auto-launch = "0.4.0"
|
auto-launch = "0.4.0"
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
clap = { version = "3.2.23", features = ["derive"] }
|
clap = { version = "3.2.23", features = ["derive"] }
|
||||||
is-terminal = "0.4.7"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
#![cfg_attr(
|
||||||
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
|
windows_subsystem = "windows"
|
||||||
|
)]
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@ -27,6 +32,33 @@ use crate::{
|
|||||||
pub static APP: OnceCell<AppHandle> = OnceCell::new();
|
pub static APP: OnceCell<AppHandle> = OnceCell::new();
|
||||||
|
|
||||||
|
|
||||||
|
async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
|
||||||
|
APP.set(app.handle()).unwrap();
|
||||||
|
|
||||||
|
let conn_opts = SqliteConnectOptions::new()
|
||||||
|
.filename(config::get_or_create_db_path()?)
|
||||||
|
.create_if_missing(true);
|
||||||
|
let pool_opts = SqlitePoolOptions::new();
|
||||||
|
let pool: SqlitePool = pool_opts.connect_with(conn_opts).await?;
|
||||||
|
sqlx::migrate!().run(&pool).await?;
|
||||||
|
|
||||||
|
let conf = AppConfig::load(&pool).await?;
|
||||||
|
let session = Session::load(&pool).await?;
|
||||||
|
let srv = Server::new(conf.listen_addr, conf.listen_port, app.handle()).await?;
|
||||||
|
|
||||||
|
config::set_auto_launch(conf.start_on_login)?;
|
||||||
|
if !conf.start_minimized {
|
||||||
|
app.get_window("main")
|
||||||
|
.ok_or(HandlerError::NoMainWindow)?
|
||||||
|
.show()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = AppState::new(conf, session, srv, pool);
|
||||||
|
app.manage(state);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn run() -> tauri::Result<()> {
|
pub fn run() -> tauri::Result<()> {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
|
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
|
||||||
@ -57,36 +89,4 @@ pub fn run() -> tauri::Result<()> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn connect_db() -> Result<SqlitePool, SetupError> {
|
|
||||||
let conn_opts = SqliteConnectOptions::new()
|
|
||||||
.filename(config::get_or_create_db_path()?)
|
|
||||||
.create_if_missing(true);
|
|
||||||
let pool_opts = SqlitePoolOptions::new();
|
|
||||||
let pool: SqlitePool = pool_opts.connect_with(conn_opts).await?;
|
|
||||||
sqlx::migrate!().run(&pool).await?;
|
|
||||||
Ok(pool)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
|
|
||||||
APP.set(app.handle()).unwrap();
|
|
||||||
|
|
||||||
let pool = connect_db().await?;
|
|
||||||
let conf = AppConfig::load(&pool).await?;
|
|
||||||
let session = Session::load(&pool).await?;
|
|
||||||
let srv = Server::new(conf.listen_addr, conf.listen_port, app.handle()).await?;
|
|
||||||
|
|
||||||
config::set_auto_launch(conf.start_on_login)?;
|
|
||||||
if !conf.start_minimized {
|
|
||||||
app.get_window("main")
|
|
||||||
.ok_or(HandlerError::NoMainWindow)?
|
|
||||||
.show()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let state = AppState::new(conf, session, srv, pool);
|
|
||||||
app.manage(state);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::io::{Read, Write};
|
||||||
use std::process::Command as ChildCommand;
|
use std::process::Command as ChildCommand;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
@ -8,14 +9,9 @@ use clap::{
|
|||||||
ArgMatches,
|
ArgMatches,
|
||||||
ArgAction
|
ArgAction
|
||||||
};
|
};
|
||||||
use tokio::{
|
use std::net::TcpStream;
|
||||||
net::TcpStream,
|
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
use crate::app;
|
|
||||||
use crate::config::AppConfig;
|
|
||||||
use crate::credentials::{BaseCredentials, SessionCredentials};
|
use crate::credentials::{BaseCredentials, SessionCredentials};
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
|
|
||||||
@ -102,19 +98,16 @@ pub fn exec(args: &ArgMatches) -> Result<(), CliError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
fn get_credentials(base: bool) -> Result<String, RequestError> {
|
||||||
async fn get_credentials(base: bool) -> Result<String, RequestError> {
|
|
||||||
let pool = app::connect_db().await?;
|
|
||||||
let config = AppConfig::load(&pool).await?;
|
|
||||||
let path = if base {"/creddy/base-credentials"} else {"/"};
|
let path = if base {"/creddy/base-credentials"} else {"/"};
|
||||||
|
|
||||||
let mut stream = TcpStream::connect((config.listen_addr, config.listen_port)).await?;
|
let mut stream = TcpStream::connect("127.0.0.1:12345")?;
|
||||||
let req = format!("GET {path} HTTP/1.0\r\n\r\n");
|
let req = format!("GET {path} HTTP/1.0\r\n\r\n");
|
||||||
stream.write_all(req.as_bytes()).await?;
|
stream.write_all(req.as_bytes())?;
|
||||||
|
|
||||||
// some day we'll have a proper HTTP parser
|
// some day we'll have a proper HTTP parser
|
||||||
let mut buf = vec![0; 8192];
|
let mut buf = vec![0; 8192];
|
||||||
stream.read_to_end(&mut buf).await?;
|
stream.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
let status = buf.split(|&c| &[c] == b" ")
|
let status = buf.split(|&c| &[c] == b" ")
|
||||||
.skip(1)
|
.skip(1)
|
||||||
|
@ -2,7 +2,6 @@ use std::net::Ipv4Addr;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use auto_launch::AutoLaunchBuilder;
|
use auto_launch::AutoLaunchBuilder;
|
||||||
use is_terminal::IsTerminal;
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
@ -91,17 +90,16 @@ pub fn set_auto_launch(is_configured: bool) -> Result<(), SetupError> {
|
|||||||
|
|
||||||
|
|
||||||
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
|
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
|
||||||
|
// debug_assertions doesn't always mean we are running in dev
|
||||||
|
if cfg!(debug_assertions) && std::env::var("HOME").is_ok() {
|
||||||
|
return Ok(PathBuf::from("./creddy.db"));
|
||||||
|
}
|
||||||
|
|
||||||
let mut path = dirs::data_dir()
|
let mut path = dirs::data_dir()
|
||||||
.ok_or(DataDirError::NotFound)?;
|
.ok_or(DataDirError::NotFound)?;
|
||||||
path.push("creddy");
|
|
||||||
|
|
||||||
std::fs::create_dir_all(&path)?;
|
std::fs::create_dir_all(&path)?;
|
||||||
if cfg!(debug_assertions) && std::io::stdout().is_terminal() {
|
path.push("creddy.db");
|
||||||
path.push("creddy.dev.db");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
path.push("creddy.db");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
@ -198,8 +198,6 @@ pub enum RequestError {
|
|||||||
InvalidJson,
|
InvalidJson,
|
||||||
#[error("Error reading/writing stream: {0}")]
|
#[error("Error reading/writing stream: {0}")]
|
||||||
StreamIOError(#[from] std::io::Error),
|
StreamIOError(#[from] std::io::Error),
|
||||||
#[error("Error loading configuration data: {0}")]
|
|
||||||
Setup(#[from] SetupError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
#![cfg_attr(
|
|
||||||
all(not(debug_assertions), target_os = "windows"),
|
|
||||||
windows_subsystem = "windows"
|
|
||||||
)]
|
|
||||||
|
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod config;
|
mod config;
|
||||||
|
@ -59,7 +59,16 @@ impl Handler {
|
|||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
let base = req_path == b"/creddy/base-credentials";
|
let base = req_path == b"/creddy/base-credentials";
|
||||||
|
if base {
|
||||||
|
if clients.len() != 1
|
||||||
|
|| clients[0].is_none()
|
||||||
|
|| clients[0].as_ref().unwrap().exe != std::env::current_exe()?
|
||||||
|
{
|
||||||
|
self.stream.write(b"HTTP/1.0 403 Access Denied\r\n\r\n").await?;
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let req = Request {id: self.request_id, clients, base};
|
let req = Request {id: self.request_id, clients, base};
|
||||||
self.app.emit_all("credentials-request", &req)?;
|
self.app.emit_all("credentials-request", &req)?;
|
||||||
let starting_visibility = self.show_window()?;
|
let starting_visibility = self.show_window()?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user