Skip to content

Commit

Permalink
version: v0.2.0 reseda-rust #12
Browse files Browse the repository at this point in the history
version: v0.2.0 `reseda-rust`
  • Loading branch information
bennjii committed Jun 19, 2022
2 parents 54bb4e2 + d3c8818 commit db11226
Show file tree
Hide file tree
Showing 13 changed files with 538 additions and 985 deletions.
30 changes: 29 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn is_wireguard_up() -> String {
String::from_utf8(output.stdout.to_vec()).unwrap()
}


#[tauri::command]
fn start_wireguard_tunnel() -> String {
println!("Starting Tunnel... ");
Expand Down Expand Up @@ -82,6 +83,32 @@ fn stop_wireguard_tunnel() -> String {
"Y".to_string()
}

#[tauri::command]
fn add_peer(public_key: String, endpoint: String) -> String {
println!("Adding Peer");

let output = Command::new("wg")
.args(["set", "wg0", "peer", &public_key, "allowed-ips", "0.0.0.0/0", "endpoint", &endpoint])
.output()
.expect("Failed to start wireguard!");

println!("{:?}", output);

"Yes".to_string()
}

#[tauri::command]
fn remove_peer(public_key: String) -> String {
println!("Adding Peer");

Command::new("wg")
.args(["set", "wg0", "peer", &public_key, "remove"])
.output()
.expect("Failed to start wireguard!");

"Yes".to_string()
}

fn read_text_file(path: PathBuf, file_name: String) -> String {
println!("Reading script from file.. {}", file_name);

Expand Down Expand Up @@ -134,6 +161,7 @@ fn generate_public_key(private_key: String) -> String {
String::from_utf8(output.stdout.to_vec()).unwrap()
}

#[tauri::command]
fn generate_private_key() -> String {
println!("Generating Private Key... ");

Expand Down Expand Up @@ -189,7 +217,7 @@ fn remove_windows_service() -> Result<String, &'static str> {
fn main() {
// Then Build TAURI.
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![start_wireguard_tunnel, stop_wireguard_tunnel, generate_public_key, is_wireguard_up, remove_windows_service, log_to_console])
.invoke_handler(tauri::generate_handler![generate_private_key, add_peer, remove_peer, start_wireguard_tunnel, stop_wireguard_tunnel, generate_public_key, is_wireguard_up, remove_windows_service, log_to_console])
.setup(| _app | {
let rpath = _app.path_resolver().resource_dir().expect("Unable to access resources directory.");
let apath = _app.path_resolver().app_dir().expect("Unable to access app directory...");
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "reseda",
"version": "0.1.1"
"version": "0.2.0"
},
"build": {
"distDir": "../out",
Expand Down
83 changes: 2 additions & 81 deletions src/components/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { NextPage } from 'next'
import { useEffect, useState } from 'react'
import TabView from '@components/tabview'
import { connect, disconnect, ResedaConnection } from '@root/reseda-api'
import styles from '@styles/Home.module.css'
import { platform } from 'os'
import ip from "ip"
Expand All @@ -10,24 +9,6 @@ import Button from './un-ui/button'
import Input from './un-ui/input'
import { AlertCircle, Check } from 'react-feather'

const fetcher = (url, token) =>
fetch(url, {
method: 'GET',
headers: new Headers({ 'Content-Type': 'application/json', token }),
credentials: 'same-origin',
}).then((res) => res.json())

type Packet = {
id: number,
author: string,
server: string,
client_pub_key: string,
svr_pub_key: string,
client_number: number,
awaiting: boolean,
server_endpoint: string
}

const Auth: NextPage = () => {
const [ authState, setAuthState ] = useState('auth-login');
const [ authInputState, setAuthInputState ] = useState({
Expand All @@ -41,14 +22,6 @@ const Auth: NextPage = () => {
setAuthError(null);
}, [authState])

useEffect(() => {
// const session = supabase.auth.session()

// fetcher('/api/getUser', session?.access_token ?? "x").then(e => {
// console.log(e);
// });
}, []);

return (
<div className={styles.container}>
{
Expand All @@ -58,19 +31,11 @@ const Auth: NextPage = () => {
Reseda VPN
</div>

<PlatformControls
// onClose={() => remote.getCurrentWindow().close()}
// onMinimize={() => remote.getCurrentWindow().minimize()}
// onMaximize={() => {
// maximized == "maximized" ? remote.getCurrentWindow().unmaximize() : remote.getCurrentWindow().maximize();
// setMaximized(maximized == "maximized" ? "unmaximized" : "maximized")
// }}
/>
<PlatformControls />
</div>
:
<></>
}


<div className={styles.resedaAuth}>
<div>
Expand Down Expand Up @@ -107,17 +72,6 @@ const Auth: NextPage = () => {
}

<div>
{/* <Button title={"Login"} onClick={(out, callback) => {
// supabase.auth.signIn({
// email: authInputState.email,
// password: authInputState.password,
// }).then(e => {
// if(e.error) setAuthError(e.error.message)
// else setAuthError(null)
// callback();
// })
}}>Login</Button> */}
<p>Don't have an account? <a href="#" onClick={() => setAuthState('auth-signup')}>Sign Up</a></p>
</div>
</div>
Expand All @@ -142,39 +96,6 @@ const Auth: NextPage = () => {
}

<div>
{/* <Button title={"Sign Up"} onClick={async (out, callback) => {
if(authInputState.email && authInputState.password && authInputState.username) {
const usr = await supabase.auth.signUp({
email: authInputState.email,
password: authInputState.password,
}).then(u => {
console.log(u.error)
if(u.error) {
setAuthError(u.error?.message)
return;
}
else setAuthError(null)
supabase
.from('users')
.insert([
{
id: u.user.id,
username: authInputState.username
}
])
.then(e => {
console.log(e);
setAuthState('auth-email');
callback();
});
}).catch(e => {
console.error(e)
})
}
}}>Sign Up</Button> */}
<p>Already have an account? <a href="#" onClick={() => setAuthState('auth-login')}>Log in</a></p>
</div>
</div>
Expand All @@ -198,7 +119,7 @@ const Auth: NextPage = () => {
</div>

<div>
<p>Havent recieved an email? <a href="#" onClick={() => setAuthState('auth-login')}>Re-send</a></p>
<p>Haven{'\''}t received an email? <a href="#" onClick={() => setAuthState('auth-login')}>Re-send</a></p>
</div>
</div>
}
Expand Down
8 changes: 1 addition & 7 deletions src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ const WindowButton = ({
const width = platform === 'win32' ? '100%' : '20px';
const height = platform === 'win32' ? '100%' : '20px';
return (
<div
// className={styles.Control}
>
<div>
<div
style={{
width,
height,
// color: config.color,
// background: config.background,
// borderRadius: controls.borderRadius,
// border: controls.border
}}
onClick={onClick}
onMouseOver={() => { config = close ? controls.close.hover! : controls.normal.hover! }}
Expand Down
105 changes: 0 additions & 105 deletions src/components/home.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions src/components/platform_controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ const buttons = (isWin: boolean, maximized: boolean, onMinimize: () => void, onM
onClick: onMinimize,
icon: <MinimizeIcon isWin={isWin} />
},
// {
// type: 'maximize',
// onClick: onMaximize,
// icon: maximized ? <RestoreIcon isWin={isWin} /> : <MaximizeIcon isWin={isWin} />
// },
{
type: 'close',
onClick: onClose,
Expand Down

0 comments on commit db11226

Please sign in to comment.