Compare commits

..

9 Commits

5 changed files with 249 additions and 110 deletions

169
apache.cf
View File

@ -9,9 +9,39 @@
bundle agent apache bundle agent apache
{ {
classes:
# "apache enable_php";
vars: vars:
"admin_email" string => "[]",unless => isvariable( $(this.promiser) ) ; "admin_email" string => "[]",unless => isvariable( $(this.promiser) ) ;
apache_php_enable::
"php_mod" string => '{m: "$(php.apache_m)",f:"$(php.apache_f)"},';
"service_deps" slist => {
"apache_pkgs_installed",
"apache_php_pkgs_installed",
"apache_www_dir_created",
"apache_vhost_dir_created",
"apache_main_cfg_created"
};
"cfg_deps" slist => { "apache_pkgs_installed","apache_php_installed" };
!apache_php_enable::
"php_mod" string => "";
"service_deps" slist => {
"apache_pkgs_installed",
"apache_www_dir_created",
"apache_vhost_dir_created",
"apache_main_cfg_created"
};
"cfg_deps" slist => { "apache_pkgs_installed" };
freebsd:: freebsd::
"pkgs" slist => { "pkgs" slist => {
"apache24", "apache24",
@ -34,11 +64,11 @@ vars:
"default_html_dir" string => "$(www_dir)/apache24"; "default_html_dir" string => "$(www_dir)/apache24";
"server_root" string => "/usr/local"; "server_root" string => "/usr/local";
"modules" data => '[ "modules" data => '[
$(php_mod)
{m: "autoindex",f:"mod_autoindex"}, {m: "autoindex",f:"mod_autoindex"},
{m: "log_config",f:"mod_log_config"}, {m: "log_config",f:"mod_log_config"},
{m: "version",f:"mod_version"}, {m: "version",f:"mod_version"},
{m: "unixd",f:"mod_unixd"}, {m: "unixd",f:"mod_unixd"},
{m: "$(php.apache_m)",f:"$(php.apache_f)"},
{m: "ssl",f:"mod_ssl"} {m: "ssl",f:"mod_ssl"}
]'; ]';
@ -65,11 +95,13 @@ vars:
"server_root" string => "/usr"; "server_root" string => "/usr";
"modules" data => '[ "modules" data => '[
{m:"php",f:"libphp8.2"}, $(php_mod)
{m:"ssl",f:"mod_ssl"}, {m:"ssl",f:"mod_ssl"},
{m:"proxy",f:"mod_proxy"}, {m:"proxy",f:"mod_proxy"},
{m:"proxy_fcgi",f:"mod_proxy_fcgi"} {m:"proxy_fcgi",f:"mod_proxy_fcgi"}
]'; ]';
# {m:"php",f:"libphp$(php.version)"},
centos:: centos::
@ -131,6 +163,9 @@ vars:
{m: "authz_svn", f:"mod_authz_svn"}, {m: "authz_svn", f:"mod_authz_svn"},
{m: "ssl",f:"mod_ssl"} {m: "ssl",f:"mod_ssl"}
]'; ]';
reports:
} }
@ -140,30 +175,13 @@ vars:
freebsd:: freebsd::
"pkgs" slist => {"mod_php$(php.bsdvs)"}; "pkgs" slist => {"mod_php$(php.bsdvs)"};
debian:: debian::
"pkgs" slist => {"libapache2-mod-php"}; "pkgs" slist => {"libapache2-mod-php$(php.version)"};
centos:: centos::
"pkgs" slist => {"libapache2-mod-php"}; "pkgs" slist => {"libapache2-mod-php"};
packages: methods:
freebsd:: "any" usebundle => wmde_install_packages(@(pkgs),"apache_php"),
"$(pkgs)" handle => "apache_php_installed";
policy => "present",
package_module => pkg,
handle => "apache_php_installed",
classes => if_repaired(apache_changed);
debian::
"$(pkgs)"
policy => "present",
package_module => apt_get,
handle => "apache_php_installed",
depends_on => { "apache_mpm_event_disabled" },
classes => if_repaired(apache_changed);
fedora|centos::
"$(pkgs)"
policy => "present",
package_module => yum,
handle => "apache_php_installed",
classes => if_repaired(apache_changed);
commands: commands:
debian|ubuntu:: debian|ubuntu::
@ -172,45 +190,22 @@ commands:
inform=>"false", inform=>"false",
handle => "apache_mpm_event_disabled"; handle => "apache_mpm_event_disabled";
reports:
} }
bundle agent install_apache(raw) bundle agent install_apache(raw)
{ {
classes:
packages:
freebsd::
"$(apache.pkgs)"
policy => "present",
handle => "apache_pkgs_installed",
package_module => pkg,
classes => if_repaired(apache_changed);
debian::
"$(apache.pkgs)"
policy => "present",
package_module => apt_get,
handle => "apache_pkgs_installed",
classes => if_repaired(apache_changed);
fedora|centos::
"$(apache.pkgs)"
policy => "present",
package_module => yum,
handle => "apache_pkgs_installed",
classes => if_repaired(apache_changed);
methods: methods:
"any" usebundle => install_apache_php,
"any" usebundle => wmde_install_packages(@(apache.pkgs),"apache");
apache_php_enable::
"any" usebundle => install_apache_php,
depends_on => { "apache_pkgs_installed" }; depends_on => { "apache_pkgs_installed" };
commands:
# freebsd:: reports:
# "/usr/sbin/sysrc"
# handle => "apache_editrc",
# args => "apache24_enable=yes",
# inform=>"false";
# debian|centos::
# any::
# "/bin/true" handle => "apache_editrc",
# inform => "false";
files: files:
"$(apache.log_dir)/." "$(apache.log_dir)/."
@ -241,23 +236,43 @@ files:
create => "true", create => "true",
edit_template => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/httpd.conf.mustache", edit_template => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/httpd.conf.mustache",
template_method => "mustache", template_method => "mustache",
handle => "apache_main_cfg_crreated", handle => "apache_main_cfg_created",
depends_on => { "apache_pkgs_installed","apache_php_installed" }, depends_on => { @(apache.cfg_deps) },
classes => if_repaired(apache_changed); classes => if_repaired(apache_repaired);
services: methods:
# apache_editrs depends
"$(apache.service_name)"
depends_on => {"apache_vhost_dir_created","apache_www_dir_created","apache_main_cfg_crreated"}, "any" usebundle => wmde_service("$(apache.service_name)","apache_kept","apache_repaired|php_repaired"),
service_policy => "start", depends_on => @(apache.service_deps) ;
handle => "apache_running";
#depends_on => {
# "apache_php_pkgs_installed"
"php_changed|apache_changed":: #};
"$(apache.service_name)" #
depends_on => {"apache_vhost_dir_created","apache_www_dir_created","apache_main_cfg_crreated"},
service_policy => "restart"; files:
"$(sys.workdir)/data/agent/apache/."
create => "true",
handle => "apache_work_dir_created";
commands:
"/bin/sh"
args => "$(sys.workdir)/inputs/$(def.wmde_libdir)/scripts/del-files-not-in-list.sh $(apache.cfg_dir)/Vhosts $(sys.workdir)/data/agent/apache/domains.txt && echo dummy.conf > $(sys.workdir)/data/agent/apache/domains.txt",
inform => "false",
contain => wmde_cmd_useshell;
# "echo"
# args => "dummy.conf > $(sys.workdir)/data/agent/apache/domains.txt",
# inform => "false",
# contain => wmde_cmd_useshell;
reports:
} }
bundle agent restart_apache(arg) bundle agent restart_apache(arg)
@ -350,17 +365,18 @@ methods:
"any" usebundle => restart_apache("$(site[domain])"), "any" usebundle => restart_apache("$(site[domain])"),
depends_on => {"vhost_cfg_done$(site[domain])" }; depends_on => {"vhost_cfg_done$(site[domain])" };
commands:
"echo"
args => "$(site[domain]).conf >> $(sys.workdir)/data/agent/apache/domains.txt",
inform => "false",
depends_on => {"vhost_cfg_done$(site[domain])"},
contain => wmde_cmd_useshell;
reports: reports:
# "SSL_CERT: $(ssl_cert) $(ssl_key) ";
# use_ssl::
# "USE SSL";
# !use_ssl::
# "NOT USE_SSL";
# "RAW: $(site[raw])";
# "APACHE DOCROOT $(site[doc_root])";
} }
@ -372,6 +388,5 @@ methods:
"any" usebundle => apache_vhost(@(sites[$(idx)])); "any" usebundle => apache_vhost(@(sites[$(idx)]));
reports: reports:
# "IDXE $(idx)";
} }

29
lib.cf
View File

@ -172,3 +172,32 @@ reports:
} }
bundle agent install_apt_repo(name,repo_src,key_src,key_name)
{
classes:
debian|ubuntu::
"do_install" expression => not(fileexists("/etc/apt/sources.list.d/$(name).list"));
vars:
do_install::
"pkgs" slist => {
"curl",
"ca-certificates",
"lsb-release"
};
"add_repo_cmd" string => "/usr/bin/add-apt-repository";
methods:
do_install::
"any" usebundle => wmde_install_packages(@(pkgs),"apt_repo");
commands:
do_install::
"/bin/sh"
args => "$(sys.workdir)/inputs/$(def.wmde_libdir)/scripts/install-php-repo.sh $(name) $(repo_src) $(key_src) $(key_name)";
}

102
php.cf
View File

@ -4,19 +4,12 @@
bundle agent install_php bundle agent install_php
{ {
classes:
"php_install_repo" expression => not(fileexists("/etc/apt/sources.list.d/php.list"));
vars: vars:
debian::
"version" string => "8.2";
ubuntu_20::
"version" string => "7.4";
ubuntu_22::
"version" string => "8.1";
freebsd::
"version" string => "$(php.version)"; "version" string => "$(php.version)";
"bsdvs" string => "$(php.bsdvs)";
freebsd::
freebsd:: freebsd::
"cli_exe" string => "/usr/local/bin/php"; "cli_exe" string => "/usr/local/bin/php";
@ -39,19 +32,19 @@ vars:
debian:: debian::
"pkgs" slist => { "pkgs" slist => {
"php-cli", "php$(version)-cli",
"php$(version)-common", "php$(version)-common",
"php$(version)-zip", "php$(version)-zip",
"php$(version)-pgsql", "php$(version)-pgsql",
"php$(version)-mysql", "php$(version)-mysql",
"php-json",
"php$(version)-xml", "php$(version)-xml",
"php-gd", "php$(version)-gd",
"php-mbstring", "php$(version)-mbstring",
"php-intl", "php$(version)-intl",
"php-curl", "php$(version)-curl",
"php-imagick", "php$(version)-imagick",
"php-ldap", "php$(version)-ldap",
"php-json"
}; };
ubuntu:: ubuntu::
@ -68,31 +61,60 @@ vars:
}; };
packages: commands:
freebsd:: # (debian|ubuntu)&php_install_repo::
"$(pkgs)" # "/bin/sh"
policy => "present", # args => "$(sys.workdir)/inputs/$(def.wmde_libdir)/scripts/install-php-sury.sh",
package_module => pkg, # handle => "php_repo_ready";
classes => if_repaired(php_changed); # (debian|ubuntu)&(!php_install_repo)::
debian:: # "/usr/bin/true"
"$(pkgs)" # inform => "false",
policy => "present", # handle => "php_repo_ready";
package_module => apt_get,
handle => "php_installed", # !(debian|ubuntu)::
classes => if_repaired(php_changed);
methods:
"any" usebundle => install_apt_repo("php","$(php.apt_repo_url)","$(php.apt_repo_key)","$(php.apt_repo_key_name)"),
handle => "php_repo_ready";
"any" usebundle => wmde_install_packages(@(pkgs),"php"),
depends_on => {"php_repo_ready"};
} }
bundle agent php(settings) bundle agent php(settings)
{ {
vars: vars:
debian:: debian::
"version" string => "8.0";
"ini_files" slist => { "ini_files" slist => {
"/etc/php/$(install_php.version)/apache2/php.ini", "/etc/php/$(php.version)/apache2/php.ini",
"/etc/php/$(install_php.version)/fpm/php.ini" "/etc/php/$(php.version)/fpm/php.ini"
}; };
"cli_exe" string => "/usr/bin/php"; "cli_exe" string => "/usr/bin/php";
"fpm_pkgs" slist => { "php$(version)-fpm" };
"fpm_service_name" string => "php$(version)-fpm";
"fpm_socket" string => "/run/php/php$(version)-fpm.sock";
"apt_repo_url" string => "https://packages.sury.org/php/";
"apt_repo_key" string => "https://packages.sury.org/php/apt.gpg";
"apt_repo_key_name" string=> "deb.sury.org-php.gpg";
"apache_m" string => "php";
"apache_f" string => "libphp$(php.version)";
ubuntu::
"apt_repo_url" string => "https://ppa.launchpadcontent.net/ondrej/php/ubuntu/";
"apt_repo_key" string => "";
"apt_repo_key_name" string=> "";
ubuntu_22::
"version" string => "8.2";
freebsd:: freebsd::
"ini_files" slist => { "ini_files" slist => {
"/etc/php/$(install_php.version)/apache2/php.ini", "/etc/php/$(install_php.version)/apache2/php.ini",
@ -111,7 +133,7 @@ files:
edit_template => "$(sys.workdir)/inputs/$(wmde_libdir)/templates/php.ini.mustache", edit_template => "$(sys.workdir)/inputs/$(wmde_libdir)/templates/php.ini.mustache",
template_method => "mustache", template_method => "mustache",
template_data => @(settings), template_data => @(settings),
classes => if_repaired(php_changed); classes => if_repaired(php_repaired);
methods: methods:
@ -121,6 +143,20 @@ reports:
} }
bundle agent install_php_fpm
{
methods:
"any" usebundle => install_php;
"any" usebundle => wmde_install_packages(@(php.fpm_pkgs),"php_fpm");
"any" usebundle => wmde_service("$(php.fpm_service_name)","php_kept|php_fpm_kept","php_repaired|php_fpm_repaired"),
depends_on =>{
"php_fpm_pkgs_installed",
"php_pkgs_installed"
};
}
bundle agent php_composer(cfg) bundle agent php_composer(cfg)
{ {

View File

@ -0,0 +1,36 @@
#!/bin/bash
# Path to the folder containing files
folder_path="$1"
# Path to the file containing the list of filenames
list_file="$2"
# Check if the folder exists
if [ ! -d "$folder_path" ]; then
echo "Folder does not exist: $folder_path"
exit 1
fi
# Check if the list file exists
if [ ! -f "$list_file" ]; then
echo "List file does not exist: $list_file"
exit 1
fi
# Loop through the files in the folder
for file_in_folder in "$folder_path"/*; do
# Check if the current file is a regular file
if [ -f "$file_in_folder" ]; then
# Get the filename without the path
filename=$(basename "$file_in_folder")
# Check if the filename is not in the list
if ! grep -qFx "$filename" "$list_file"; then
echo "Deleting: $file_in_folder"
rm "$file_in_folder"
fi
fi
done

View File

@ -0,0 +1,23 @@
!/bin/sh
# To add this repository please do:
echo $1 $2 $3
echo "PARAMS $1 $2 $3"
if [ -n "$3" ]; then
echo "it dollaar 3"
curl -sSLo /usr/share/keyrings/$4 $3
echo "deb [signed-by=/usr/share/keyrings/$4] $2 $(lsb_release -sc) main" > /etc/apt/sources.list.d/$1.list
else
echo "its not $3"
echo "deb $2 $(lsb_release -sc) main" > /etc/apt/sources.list.d/$1.list
fi
apt-get update