From 8c03e6420cddd115b2e2eb16c245a7f23cc42370 Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Sun, 8 Nov 2020 06:37:58 +0100 Subject: [PATCH] fix: php.rs olvidado. --- src/php.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/php.rs diff --git a/src/php.rs b/src/php.rs new file mode 100644 index 0000000..0720e7e --- /dev/null +++ b/src/php.rs @@ -0,0 +1,42 @@ +use std::io::Write; +fn execute_php(command: &str, arguments: &[&str]) -> String { + let mut execute_array: Vec<&str> = Vec::new(); + execute_array.extend(&["-r", &command, "--"]); + execute_array.extend(arguments); + let output = std::process::Command::new("php") + .args(execute_array) + .output() + .expect(""); + let mut buff_stderr = std::io::BufWriter::new(std::io::stderr()); + buff_stderr + .write(&output.stderr) + .expect("Unable to write to stderr."); + buff_stderr.flush().expect("Unable to flush stderr."); + return String::from_utf8(output.stdout).expect("Unable to parse php response"); +} + +pub fn ls(path: &str, user: &str, nextcloud_location: &str) { + let php_script: String = [ + "define('OC_CONSOLE', 1);", + "$user = $argv[1];", + "$nextcloud_location = $argv[2];", + "$path = $argv[3];", + "include $nextcloud_location . '/lib/base.php';", + "use Symfony\\Component\\Console\\Application as SymfonyApplication;", + "use \\OC\\Files\\View;", + "$application = new SymfonyApplication( + \\OC::$server->getThemingDefaults()->getName(), + \\OC_Util::getVersionString() + );", + "\\OC_Util::setupFS($user);", + "$view = new View('/'. $user . '/files');", + "foreach ($view->getDirectoryContent($path) as $node) { + print $node->getName() . \"\\n\"; + }", + ] + .join("\n"); + eprintln!( + "{}", + execute_php(&php_script, &[user, nextcloud_location, path]) + ); +}