Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on fluere-config/src/init.rs:14:43 #73

Merged
merged 9 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ repository = "https://github.com/SkuldNorniern/fluere"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version = "4.0.32", features = ["cargo"]}
tokio = { version = "1.32", features = ["full","macros", "rt-multi-thread"] }
clap = { version = "4.0.32", features = ["cargo"] }
tokio = { version = "1.32", features = ["full", "macros", "rt-multi-thread"] }
pnet = { version = "0.34.0", features = ["std"] }
pnet_macros_support = "0.34.0"
pnet_macros = "0.34.0"
# using custom forked version of pcap-rs for fixing audits
pcap = { version = "1.1.0",git = "https://github.com/SkuldNorniern/pcap", rev= "40f1163"}
pcap = { version = "1.1.0", git = "https://github.com/SkuldNorniern/pcap", rev = "40f1163" }

chrono = { version = "0.4.29", default-features = false, features = ["clock"] }
libc = "0.2"
csv = "1.1"
nom = "7.1.2"
snafu = "0.7.4"
serde = { version = "1.0.186", features = ["derive"]}
serde = { version = "1.0.186", features = ["derive"] }
toml = "0.7.1"

fluere_plugin = { version = "0.1.0", path = "./fluere-plugin" }
Expand All @@ -38,13 +38,12 @@ logs = "0.7.1"
env_logger = "0.10.0"



[workspace]
members = [
"fluere-plugin",
"fluere-config",
#"fluere-plugin-trait",
"fluereflow"
"fluere-plugin",
"fluere-config",
#"fluere-plugin-trait",
"fluereflow",
]

[package.metadata.rpm]
Expand All @@ -61,5 +60,5 @@ libpcap = "*"

[package.metadata.generate-rpm]
assets = [
{ source = "target/release/fluere", dest = "/usr/bin/fluere", mode = "755" },
{ source = "target/release/fluere", dest = "/usr/bin/fluere", mode = "755" },
]
8 changes: 7 additions & 1 deletion fluere-config/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ impl Config {
let path_file = path_base.join(Path::new("fluere.toml"));
println!("path_file: {:?}", path_file);
if !path_base.exists() {
fs::create_dir_all(path_base).unwrap();
match fs::create_dir_all(&path_base) {
Ok(_) => (),
Err(e) => {
eprintln!("Failed to create directory at {:?}: {}", path_base, e);
return Config::default();
}
}
}

if !path_file.exists() {
Expand Down
35 changes: 19 additions & 16 deletions fluere-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@ impl PluginManager {
let lua_guard = lua_clone.lock().await;
let lua = &*lua_guard;
// println!("lua path: {}", path);
let lua_plugin_path = format!("package.path = package.path .. \";{}/?.lua\"", path);
let lua_plugin_path =
format!("package.path = package.path .. \";{}/?.lua\"", path);
let _ = lua.load(lua_plugin_path).exec();

let chunk = lua.load(&code);
let plugin_table: mlua::Table = chunk.eval()?;
let func: mlua::Function = plugin_table.get("init")?;

let argument_table = lua.create_table()?;

// println!("extra argument details{:?}", plugin_config.extra_arguments);
for (key, value) in plugin_config.extra_arguments.clone().unwrap().iter() {
for (key, value) in
plugin_config.extra_arguments.clone().unwrap().iter()
{
argument_table.set(key.as_str(), value.as_str())?;
}

func.call(argument_table)?;
lua.globals().set(name.as_str(), plugin_table)?;
/*let _ = lua_guard.context(|ctx| -> mlua::Result<()> {
Expand Down Expand Up @@ -101,14 +104,16 @@ impl PluginManager {
match download_plugin_from_github(name) {
Ok(_) => {
let path = home_cache_path().join(name.split('/').last().unwrap());
match std::fs::read_to_string(path.join("init.lua"))
{
match std::fs::read_to_string(path.join("init.lua")) {
Ok(code) => {
let lua_clone = self.lua.clone();
let lua_guard = lua_clone.lock().await;
let lua = &*lua_guard;

let lua_plugin_path = format!("package.path = package.path .. \";{}/?.lua\"", path.to_str().unwrap());
let lua_plugin_path = format!(
"package.path = package.path .. \";{}/?.lua\"",
path.to_str().unwrap()
);
let _ = lua.load(lua_plugin_path).exec();
// println!("lua path: {}", path.to_str().unwrap());

Expand All @@ -119,7 +124,9 @@ impl PluginManager {
let argument_table = lua.create_table()?;

// println!("extra argument details{:?}", plugin_config.extra_arguments);
for (key, value) in plugin_config.extra_arguments.clone().unwrap().iter() {
for (key, value) in
plugin_config.extra_arguments.clone().unwrap().iter()
{
argument_table.set(key.as_str(), value.as_str())?;
}

Expand Down Expand Up @@ -251,7 +258,7 @@ impl PluginManager {
// Cleanup each plugin before exiting
let lua_clone = self.lua.clone();
let plugins_clone = self.plugins.clone();

let lua = lua_clone.lock().await;
let plugins = plugins_clone.lock().await;

Expand All @@ -262,15 +269,11 @@ impl PluginManager {
.expect("Plugin table not found");

if let Ok(func) = plugin_table.get::<_, mlua::Function>("cleanup") {
func.call::<(), ()>(()).expect(format!("Error on plugin: {}", plugin_name).as_str());
func.call::<(), ()>(())
.expect(format!("Error on plugin: {}", plugin_name).as_str());
} else {
println!(
"cleanup function not found in plugin: {}",
plugin_name
);
println!("cleanup function not found in plugin: {}", plugin_name);
}
}


}
}