Compare commits
No commits in common. "2783cc9ca8dede0e46601be3df6ed3c993288f0a" and "805caebe3559e61623e6994988f1b4dbaf5f4503" have entirely different histories.
2783cc9ca8
...
805caebe35
|
@ -10,7 +10,7 @@ argparse = "0.2.2"
|
||||||
base64 = "0.21.4"
|
base64 = "0.21.4"
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
eyre = "0.6.8"
|
eyre = "0.6.8"
|
||||||
ircparser = { git = "https://forgejo.vanten-s.com/vanten-s/ircparser" }
|
ircparser = "0.2.1"
|
||||||
openssl = "0.10"
|
openssl = "0.10"
|
||||||
pgp = "0.10.2"
|
pgp = "0.10.2"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
|
@ -1,41 +1,10 @@
|
||||||
use crate::helpers::bytes_to_privmsg_base64;
|
use crate::helpers::bytes_to_privmsg_base64;
|
||||||
use crate::{encryption, helpers, State};
|
use crate::{encryption, helpers};
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use pgp::{Deserializable, SignedPublicKey};
|
use pgp::{Deserializable, SignedPublicKey};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::mpsc::{Receiver, Sender};
|
use std::sync::mpsc::{Receiver, Sender};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct InvalidCommand;
|
|
||||||
|
|
||||||
impl std::fmt::Display for InvalidCommand {
|
|
||||||
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::error::Error for InvalidCommand {}
|
|
||||||
|
|
||||||
fn parse_bouncer_command(message: String, state: &mut State) -> Result<()> {
|
|
||||||
macro_rules! unwrap_option {
|
|
||||||
($t:expr) => {
|
|
||||||
match $t {
|
|
||||||
Some(val) => val,
|
|
||||||
None => return Err(InvalidCommand.into()),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut splitted = message.split(' ');
|
|
||||||
match unwrap_option!(splitted.next()) {
|
|
||||||
"ALLOW_UNENCRYPTED" => state
|
|
||||||
.nicks_without_encryption
|
|
||||||
.push(unwrap_option!(splitted.next()).to_string().to_lowercase()),
|
|
||||||
_ => return Err(InvalidCommand.into()),
|
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_message_from_client(
|
pub fn handle_message_from_client(
|
||||||
recieved: &str,
|
recieved: &str,
|
||||||
public_key: &Vec<u8>,
|
public_key: &Vec<u8>,
|
||||||
|
@ -45,34 +14,10 @@ pub fn handle_message_from_client(
|
||||||
writer_channel_rx: &Receiver<String>,
|
writer_channel_rx: &Receiver<String>,
|
||||||
listener_channel_tx: &Sender<String>,
|
listener_channel_tx: &Sender<String>,
|
||||||
_listener_channel_rx: &Receiver<String>,
|
_listener_channel_rx: &Receiver<String>,
|
||||||
state: &mut State,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut recieved = recieved.to_string();
|
let command = &ircparser::parse(recieved).expect("Got an invalid IRC instruction")[0];
|
||||||
|
|
||||||
if recieved.split(' ').count() == 1 {
|
|
||||||
recieved += " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
let parsed = ircparser::parse(&recieved);
|
|
||||||
let command = match parsed {
|
|
||||||
Ok(val) => val[0].clone(),
|
|
||||||
Err(_) => {
|
|
||||||
writer_channel_tx.send(recieved)?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if command.command == "PRIVMSG" && !command.params[0].starts_with('#') {
|
if command.command == "PRIVMSG" && !command.params[0].starts_with('#') {
|
||||||
if command.params[0] == "BOUNCER" {
|
|
||||||
return parse_bouncer_command(command.params[1].clone(), state);
|
|
||||||
}
|
|
||||||
if state
|
|
||||||
.nicks_without_encryption
|
|
||||||
.contains(&command.params[0].to_lowercase())
|
|
||||||
{
|
|
||||||
writer_channel_tx.send(recieved)?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let other = &command.params[0];
|
let other = &command.params[0];
|
||||||
|
|
||||||
if !keys.contains_key(other) {
|
if !keys.contains_key(other) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use eyre::Result;
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct IrcParseError;
|
struct IrcParseError;
|
||||||
|
|
||||||
impl std::fmt::Display for IrcParseError {
|
impl std::fmt::Display for IrcParseError {
|
||||||
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
@ -35,22 +35,6 @@ macro_rules! unwrap_or_return_option {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct State {
|
|
||||||
pub nicks_without_encryption: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
State {
|
|
||||||
nicks_without_encryption: vec![
|
|
||||||
"nickserv".to_string(),
|
|
||||||
"chanserv".to_string(),
|
|
||||||
"hostserv".to_string(),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn forward(
|
fn forward(
|
||||||
message: String,
|
message: String,
|
||||||
stream: &Sender<String>,
|
stream: &Sender<String>,
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -1,7 +1,6 @@
|
||||||
use argparse::{ArgumentParser, Store};
|
use argparse::{ArgumentParser, Store};
|
||||||
use dirs::config_local_dir;
|
use dirs::config_local_dir;
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use helpers::State;
|
|
||||||
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -82,11 +81,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
let tmp_port = port.clone();
|
let tmp_port = port.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
listener_server::listen_to_client(
|
listener_server::listen_to_client(listener_channel_send_tx, listener_channel_recv_rx, tmp_port)
|
||||||
listener_channel_send_tx,
|
|
||||||
listener_channel_recv_rx,
|
|
||||||
tmp_port,
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
let tmp_port = server_port.clone();
|
let tmp_port = server_port.clone();
|
||||||
let tmp_server = server.clone();
|
let tmp_server = server.clone();
|
||||||
|
@ -100,7 +95,6 @@ fn main() -> Result<()> {
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut keys: HashMap<String, SignedPublicKey> = HashMap::new();
|
let mut keys: HashMap<String, SignedPublicKey> = HashMap::new();
|
||||||
let mut state = State::new();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match listener_channel_rx.try_recv() {
|
match listener_channel_rx.try_recv() {
|
||||||
|
@ -114,7 +108,6 @@ fn main() -> Result<()> {
|
||||||
&writer_channel_rx,
|
&writer_channel_rx,
|
||||||
&listener_channel_tx,
|
&listener_channel_tx,
|
||||||
&listener_channel_rx,
|
&listener_channel_rx,
|
||||||
&mut state,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(error) => match error {
|
Err(error) => match error {
|
||||||
|
@ -136,7 +129,6 @@ fn main() -> Result<()> {
|
||||||
&writer_channel_rx,
|
&writer_channel_rx,
|
||||||
&listener_channel_tx,
|
&listener_channel_tx,
|
||||||
&listener_channel_rx,
|
&listener_channel_rx,
|
||||||
&mut state,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(error) => match error {
|
Err(error) => match error {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::unwrap_or_return_option;
|
use crate::unwrap_or_return_option;
|
||||||
use crate::unwrap_or_return_result;
|
use crate::unwrap_or_return_result;
|
||||||
use crate::State;
|
|
||||||
use crate::{encryption, helpers};
|
use crate::{encryption, helpers};
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
||||||
|
@ -26,20 +25,15 @@ pub fn handle_message_from_server(
|
||||||
writer_channel_rx: &Receiver<String>,
|
writer_channel_rx: &Receiver<String>,
|
||||||
listener_channel_tx: &Sender<String>,
|
listener_channel_tx: &Sender<String>,
|
||||||
_listener_channel_rx: &Receiver<String>,
|
_listener_channel_rx: &Receiver<String>,
|
||||||
state: &mut State,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let recieved_parsed = &unwrap_or_return_result!(ircparser::parse(recieved))[0];
|
let recieved_parsed = &unwrap_or_return_result!(ircparser::parse(recieved))[0];
|
||||||
|
|
||||||
let default_reciever = String::new();
|
|
||||||
|
|
||||||
let reciever = match recieved_parsed.params.get(0) {
|
|
||||||
Some(val) => val,
|
|
||||||
None => &default_reciever,
|
|
||||||
};
|
|
||||||
|
|
||||||
if recieved_parsed.command != "PRIVMSG"
|
if recieved_parsed.command != "PRIVMSG"
|
||||||
|| reciever.starts_with('#')
|
|| recieved_parsed
|
||||||
|| state.nicks_without_encryption.contains(&reciever)
|
.params
|
||||||
|
.get(0)
|
||||||
|
.unwrap_or(&String::new())
|
||||||
|
.starts_with('#')
|
||||||
{
|
{
|
||||||
forward(recieved, listener_channel_tx, server)?;
|
forward(recieved, listener_channel_tx, server)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
Loading…
Reference in a new issue