Browse Source

Update

master
Adrian Heine 5 years ago
parent
commit
e8b8122973
  1. 3
      src/symbols/acme/cert.rs
  2. 4
      src/symbols/git/submodules.rs
  3. 10
      src/symbols/stored_directory.rs
  4. 2
      src/symbols/systemd/node_js_user_service.rs
  5. 14
      src/symbols/tls/self_signed_cert.rs
  6. 1
      src/symbols/wordpress/mod.rs
  7. 76
      src/symbols/wordpress/plugin.rs

3
src/symbols/acme/cert.rs

@ -49,8 +49,7 @@ impl<'a> Symbol for AcmeCert<'a> {
if stdout != format!("subject=CN = {}\nCertificate will not expire\n", self.domain).as_bytes() {
return Ok(false);
}
try!(self.command_runner.run_successfully("openssl", &["verify", "--untrusted", "/home/acme/lets_encrypt_x3_cross_signed.pem", &self.get_cert_path()]));
Ok(true)
Ok(self.command_runner.run_successfully("openssl", &["verify", "--untrusted", "/home/acme/lets_encrypt_x3_cross_signed.pem", &self.get_cert_path()]).is_ok())
}
fn execute(&self) -> Result<(), Box<Error>> {

4
src/symbols/git/submodules.rs

@ -1,5 +1,6 @@
use std::error::Error;
use std::fmt;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
@ -34,6 +35,9 @@ impl<'a> GitSubmodules<'a> {
impl<'a> Symbol for GitSubmodules<'a> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
if !Path::new(self.target).exists() {
return Ok(false);
}
let output = try!(String::from_utf8(try!(self._run_in_target_repo(&["submodule", "status"]))));
Ok(output.lines().all(|line| line.len() == 0 || line.starts_with(' ')))
}

10
src/symbols/stored_directory.rs

@ -56,11 +56,19 @@ impl<'a, S> Symbol for StoredDirectory<'a, S> where S: Storage {
let dump_date = try!(self.storage.recent_date());
let output = try!(self.command_runner.get_output("sh", &["-c", &format!("find {} -printf '%T@\\n' | sort -r | head -n1 | grep '^[0-9]\\+' -o", self.path)]));
let modified_date = try!(u64::from_str(try!(String::from_utf8(output)).trim_right()));
Ok(if self.dir == StorageDirection::Save { modified_date <= dump_date } else { dump_date <= modified_date })
if if self.dir == StorageDirection::Save { modified_date > dump_date } else { dump_date > modified_date } {
let output = try!(self.command_runner.run_with_args("diff", &["-rq", &try!(self.storage.read_filename()), self.path.borrow()]));
match output.status.code() {
Some(0) => Ok(true),
Some(1) => Ok(false),
_ => Err(try!(String::from_utf8(output.stderr)).into())
}
} else { Ok(true) }
}
fn execute(&self) -> Result<(), Box<Error>> {
if self.dir == StorageDirection::Load {
try!(self.command_runner.run_successfully("rm", &["-rf", self.path.borrow()]));
self.command_runner.run_successfully("cp", &["-a", &try!(self.storage.read_filename()), self.path.borrow()])
} else {
self.command_runner.run_successfully("cp", &["-a", self.path.borrow(), &self.storage.write_filename()])

2
src/symbols/systemd/node_js_user_service.rs

@ -64,7 +64,7 @@ impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> whe
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), name);
let content = format!("[Service]
ExecStartPre=rm /var/tmp/{1}-{2}.socket
ExecStartPre=/bin/rm -f /var/tmp/{1}-{2}.socket
# This only works if the path is a directory
WorkingDirectory={0}
ExecStart=/usr/bin/nodejs {0}

14
src/symbols/tls/self_signed_cert.rs

@ -42,8 +42,18 @@ impl<'a> Symbol for SelfSignedTlsCert<'a> {
if !Path::new(&self.get_cert_path()).exists() {
return Ok(false);
}
let output = try!(self.command_runner.get_output("openssl", &["x509", "-in", &self.get_cert_path(), "-noout", "-subject", "-checkend", &(30*DAYS_IN_SECONDS).to_string()]));
Ok(output == format!("subject=CN = {}\nCertificate will not expire\n", self.domain).as_bytes())
let output = try!(self.command_runner.run_with_args("openssl", &["x509", "-in", &self.get_cert_path(), "-noout", "-subject", "-checkend", &(30*DAYS_IN_SECONDS).to_string()]));
println!("{}", output.status.code().unwrap());
match output.status.code() {
Some(0) => Ok(output.stdout == format!("subject=CN = {}\nCertificate will not expire\n", self.domain).as_bytes()),
Some(_) => if output.stdout == format!("subject=CN = {}\nCertificate will expire\n", self.domain).as_bytes() {
Ok(false)
} else {
Err("Exit code non-zero, but wrong stdout".to_string().into())
},
_ => Err("Apparently killed by signal".to_string().into())
}
}
fn execute(&self) -> Result<(), Box<Error>> {

1
src/symbols/wordpress/mod.rs

@ -1 +1,2 @@
pub mod plugin;
pub mod translation;

76
src/symbols/wordpress/plugin.rs

@ -0,0 +1,76 @@
use regex::Regex;
use std::error::Error;
use std::fmt;
use std::fs::File as FsFile;
use std::io::Read;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use command_runner::CommandRunner;
use symbols::Symbol;
use resources::Resource;
pub struct WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: 'a + CommandRunner {
base: C,
name: C,
command_runner: &'a R
}
impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: CommandRunner {
pub fn new(base: C, name: C, command_runner: &'a R) -> Self {
WordpressPlugin {
base: base,
name: name,
command_runner: command_runner
}
}
fn get_path(&self) -> PathBuf {
Path::new(&*self.base).join("wp-content/plugins").join(&*self.name)
}
}
impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: CommandRunner {
fn target_reached(&self) -> Result<bool, Box<Error>> {
if !self.get_path().exists() {
return Ok(false);
}
let path = self.get_path().join(self.name.to_string() + ".php");
let mut file = try!(FsFile::open(path));
let mut file_content = String::new();
try!(file.read_to_string(&mut file_content));
let mut version = String::new();
let mut plugin_uri = String::new();
let regex = try!(Regex::new("(?m)^(Plugin URI|Version): (.+)$"));
for matches in regex.captures_iter(&file_content) {
if &matches[1] == "Plugin URI" {
plugin_uri = matches[2].to_string();
} else {
version = matches[2].to_string();
}
}
let upstream = try!(self.command_runner.get_output("curl", &["--form", &format!(r###"plugins={{"plugins":{{"{0}/{0}.php":{{"Version":"{1}", "PluginURI":"{2}"}}}}}}"###, self.name, version, plugin_uri), "https://api.wordpress.org/plugins/update-check/1.1/"]));
Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###))
}
fn execute(&self) -> Result<(), Box<Error>> {
let zip = format!("/tmp/{}.zip", self.name);
try!(self.command_runner.run_successfully("curl", &[&format!("https://downloads.wordpress.org/plugin/{}.zip", self.name), "-o", &zip]));
try!(self.command_runner.run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()]));
self.command_runner.run_successfully("unzip", &[&zip, "-d", &Path::new(&*self.base).join("wp-content/plugins").to_string_lossy()])
}
fn get_prerequisites(&self) -> Vec<Resource> {
match self.get_path().parent() {
Some(p) => vec![ Resource::new("dir", p.to_string_lossy()) ],
None => vec![]
}
}
}
impl<'a, C, R> fmt::Display for WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: CommandRunner {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
write!(f, "WordpressPlugin {}", self.name)
}
}
Loading…
Cancel
Save