366 lines
12 KiB
CFEngine3
366 lines
12 KiB
CFEngine3
#
|
|
#
|
|
#
|
|
|
|
|
|
bundle agent roundcube(cfg)
|
|
{
|
|
|
|
classes:
|
|
"dlbyversion" expression => not (isvariable ("cfg[src_tgz]"));
|
|
"keep_installer" expression => isvariable("cfg[keep_installer]");
|
|
|
|
|
|
"roundcube_untar" expression => not(fileexists("$(install_sub_dir)/index.php"));
|
|
"config_exists" expression => fileexists("$(install_sub_dir)/config/config.inc.php");
|
|
"backup_config_exists" expression => fileexists("$(cfg[backup_dir])/config.inc.php");
|
|
|
|
|
|
"run_backups" expression => isvariable("cfg[backup_dir]");
|
|
|
|
|
|
run_backups::
|
|
"backup_config_exists" expression => fileexists("$(cfg[backup_dir])/config.inc.php");
|
|
"sql_backup_exists" expression => fileexists("$(cfg[backup_dir])/roundcube.sql");
|
|
|
|
vars:
|
|
"dldir" string =>"$(sys.workdir)/data/agent/roundcube";
|
|
|
|
!(dlbyversion)::
|
|
"dlfile" string => "$(sys.workdir)/data/public/$(cfg[src_tgz])";
|
|
"dltype" string => "policyhub";
|
|
"dlsrc" string => "$(def.hub_public_dir)/$(cfg[src_tgz])";
|
|
"install_sub_dir" string => "$(cfg[install_sub_dir])";
|
|
|
|
dlbyversion::
|
|
"tgzname" string => "roundcubemail-$(cfg[version])-complete.tar.gz";
|
|
"dlfile" string => "$(dldir)/$(tgzname)";
|
|
"install_sub_dir" string => "$(cfg[install_dir])/roundcubemail-$(cfg[version])";
|
|
"dltype" string => "wget";
|
|
"dlsrc" string => "https://github.com/roundcube/roundcubemail/releases/download/$(cfg[version])/$(tgzname)";
|
|
|
|
"config_file" string => "$(install_sub_dir)/config/config.inc.php";
|
|
|
|
reports:
|
|
# dlbyversion::
|
|
# "dl by version";
|
|
# !dlbyversion::
|
|
# "not dl by version";
|
|
|
|
files:
|
|
"$(dldir)/."
|
|
create => "true",
|
|
handle => "roundcube_agent_dir_created";
|
|
|
|
methods:
|
|
"any" usebundle => download_file("$(dltype)","$(dlsrc)","$(dlfile)","roundcube_tgz_file",'{}'),
|
|
handle => "roundcube_tgz_copied",
|
|
depends_on => {"roundcube_agent_dir_created"};
|
|
# classes => if_repaired ("roundcube_untar");
|
|
|
|
|
|
# "$(dlfile)"
|
|
# copy_from => remote_dcp("$(def.hub_public_dir)/$(cfg[src_tgz])","$(sys.policy_hub)"),
|
|
# perms => m(644);
|
|
|
|
files:
|
|
"$(cfg[install_dir])/public"
|
|
link_from => ln_s("$(install_sub_dir)"),
|
|
move_obstructions => "true",
|
|
depends_on => {"roundcube_untarred"};
|
|
|
|
run_backups&(!config_exists)&backup_config_exists::
|
|
"$(install_sub_dir)/config/config.inc.php"
|
|
copy_from => local_cp("$(cfg[backup_dir])/config.inc.php"),
|
|
perms => m("644"),
|
|
classes => if_repaired("roundcube_config_repaired"),
|
|
depends_on => {"roundcube_untarred"};
|
|
|
|
run_backups&config_exists::
|
|
"$(cfg[backup_dir])/config.inc.php"
|
|
copy_from => local_dcp("$(install_sub_dir)/config/config.inc.php"),
|
|
depends_on => {"roundcube_untarred"};
|
|
methods:
|
|
"any" usebundle => mysql_table_exists(@(cfg),"users");
|
|
|
|
config_exists|roundcube_config_repaired::
|
|
"any" usebundle => rm_rf ("$(install_sub_dir)/installer"),
|
|
if => not(keep_installer);
|
|
|
|
commands:
|
|
roundcube_untar|roundcube_tgz_file_repaired::
|
|
"/usr/bin/tar"
|
|
args => "xzf $(dlfile) -C $(cfg[install_dir]) && chown -R $(cfg[www_user]):$(cfg[www_group]) $(cfg[install_dir])",
|
|
depends_on => {"roundcube_tgz_copied"},
|
|
contain => wmde_cmd_useshell,
|
|
handle => "roundcube_untarred";
|
|
(!roundcube_untar)&(!roundcube_tgz_file_repaired)::
|
|
"/usr/bin/true"
|
|
inform => "false",
|
|
depends_on => {"roundcube_tgz_copied"},
|
|
handle => "roundcube_untarred";
|
|
|
|
"run_backups&sql_backup_exists&(!mysql_$(cfg[db_name])_users_exists)"::
|
|
"$(mysql.mysql_cmd)"
|
|
args => "-h$(cfg[db_host]) -u$(cfg[db_user]) -p$(cfg[db_pass]) $(cfg[db_name]) < $(cfg[backup_dir])/roundcube.sql",
|
|
contain => wmde_cmd_useshell;
|
|
|
|
methods:
|
|
run_backups::
|
|
"any" usebundle => create_mysql_backup_cron_job(@(cfg),"$(cfg[backup_dir])/roundcube.sql","users","true");
|
|
!run_backups::
|
|
"any" usebundle => create_mysql_backup_cron_job(@(cfg),"$(cfg[backup_dir])/roundcube.sql","users","false");
|
|
|
|
|
|
|
|
reports:
|
|
# "mysql_$(cfg[db_name])_users_exists"::
|
|
# "DB EXISTS! ROUNDCUBE";
|
|
|
|
# "sql_backup_exists"::
|
|
# "SQL_BACKUP_EXISTS FILE $(cfg[backup_dir])/roundcube.sql"
|
|
# ;
|
|
|
|
# run_backups&(!config_exists)&backup_config_exists::
|
|
# "ROUNDCUBE CAN RESTORE config";
|
|
|
|
# "run_backups"::
|
|
# "ROUNDCUBE SHOULD RUN BACKUPS";
|
|
}
|
|
|
|
|
|
bundle agent download_roundcube(cfg)
|
|
{
|
|
vars:
|
|
|
|
"tgzname" string => "roundcubemail-$(cfg[version])-complete.tar.gz";
|
|
"dldir" string =>"$(sys.workdir)/data/agent/roundcube";
|
|
"dst" string => "$(dldir)/$(tgzname)";
|
|
files:
|
|
"$(dldir)/."
|
|
create => "true",
|
|
handle => "roundcube_agentdir_created";
|
|
|
|
methods:
|
|
"any" usebundle => download_file("wget",
|
|
"https://github.com/roundcube/roundcubemail/releases/download/$(cfg[version])/$(tgzname)",
|
|
"$(dst)","roundcube_tgz_file",'{}');
|
|
|
|
}
|
|
|
|
|
|
bundle edit_line roundcube_values(tab, sectionName)
|
|
{
|
|
vars:
|
|
"index" slist => getindices("$(tab)[$(sectionName)]");
|
|
|
|
# Be careful if the index string contains funny chars
|
|
"cindex[$(index)]" string => canonify("$(index)");
|
|
|
|
classes:
|
|
"edit_$(cindex[$(index)])" not => strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"),
|
|
comment => "Create conditions to make changes";
|
|
|
|
field_edits:
|
|
|
|
# If the line is there, but commented out, first uncomment it
|
|
# "#+\s*$(index)\s*=.*"
|
|
# select_region => INI_section(escape("$(sectionName)")),
|
|
# edit_field => col("\s*=\s*","1","$(index)","set"),
|
|
# if => "edit_$(cindex[$(index)])";
|
|
|
|
# match a line starting like the key something
|
|
"\s*$(index)\s*=.*"
|
|
edit_field => col("\s*=\s*","2","$($(tab)[$(sectionName)][$(index)])","set"),
|
|
select_region => INI_section(escape("$(sectionName)")),
|
|
classes => results("bundle", "set_variable_values_ini_not_$(cindex[$(index)])"),
|
|
if => "edit_$(cindex[$(index)])";
|
|
|
|
delete_lines:
|
|
"!include.*";
|
|
|
|
insert_lines:
|
|
"[$(sectionName)]"
|
|
location => start,
|
|
comment => "Insert lines";
|
|
|
|
"$(index)=$($(tab)[$(sectionName)][$(index)])"
|
|
select_region => INI_section(escape("$(sectionName)")),
|
|
if => "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired).edit_$(cindex[$(index)])";
|
|
|
|
}
|
|
|
|
|
|
bundle edit_line rc_line_based(v)
|
|
{
|
|
vars:
|
|
"i" slist => getindices("$(v)");
|
|
|
|
# Escape the value (had a problem with special characters and regex's)
|
|
"ev[$(i)]" string => escape("$($(v)[$(i)])");
|
|
|
|
vars:
|
|
"exx" string => "^\s*\$config\s*\['$(i)'\s*]\s*=\s*(?!33).*$";
|
|
|
|
"thev" string => "$($(v)[$(i)])";
|
|
|
|
replace_patterns:
|
|
# "^\s*\$config\s*\['$(i)'\s*]\s*=\s*(?!$($(v)[$(i)]);$).*"
|
|
"^\s*\$config\s*\['$(i)'\s*]\s*=\s*(?!$(ev[$(i)]);$).*"
|
|
comment => "Correct the value '$(i)'",
|
|
#replace_with => value("$config['$(i)']=$($(v)[$(i)])"),
|
|
replace_with => value("$config['$(i)']=$($(v)[$(i)]);"),
|
|
classes => results("bundle", "replace_attempted_$(i)");
|
|
|
|
reports:
|
|
"THE V: $(thev)";
|
|
|
|
insert_lines:
|
|
# If the line doesn't exist, or there is more than one occurrence
|
|
# of the LHS commented out, insert a new line and try to place it
|
|
# after the commented LHS (keep new line with old comments)
|
|
# "$(i)$(sep)$($(v)[$(i)])"
|
|
# comment => "Insert the value, marker '$(i)' exists",
|
|
# location => after("^$(cp)($(i)$(bp).*|$(i))$"),
|
|
# if => "replace_attempted_$(ci[$(i)])_reached.multiple_comments_$(ci[$(i)])";
|
|
|
|
# If the line doesn't exist and there are no occurrences
|
|
# of the LHS commented out, insert a new line at the eof
|
|
# "$(i)$(sep)$($(v)[$(i)])"
|
|
# comment => "Insert the value, marker '$(i)' doesn't exist",
|
|
# if => "replace_attempted_$(ci[$(i)])_reached.!multiple_comments_$(ci[$(i)]).!exists_$(ci[$(i)])";
|
|
|
|
reports:
|
|
verbose_mode|EXTRA::
|
|
"$(this.bundle): Line for '$(i)' exists" if => "exists_$(ci[$(i)])";
|
|
"$(this.bundle): Line for '$(i)' does not exist" if => "!exists_$(ci[$(i)])";
|
|
}
|
|
|
|
|
|
|
|
bundle agent configure_roundcube(cfg)
|
|
{
|
|
|
|
vars:
|
|
|
|
"settings[db_dsnw]" string => "'mysql://$(cfg[db_user]):$(cfg[db_pass])@$(cfg[db_host])/$(cfg[db_name])'";
|
|
"settings[language]" string => "'us_EN'";
|
|
# enigma disabled
|
|
"settings[plugins]" string => "['acl', 'archive', 'attachment_reminder', 'emoticons', 'hide_blockquote', 'identicon', 'jqueryui', 'managesieve', 'markasjunk', 'newmail_notifier', 'password', 'vcard_attachments', 'zipdownload']";
|
|
|
|
"idx" slist => getindices(@(cfg[settings]));
|
|
"settings[$(idx)]" string => "$(cfg[settings][$(idx)])";
|
|
|
|
|
|
methods:
|
|
"any" usebundle => mysql_table_exists(@(cfg),"users");
|
|
|
|
files:
|
|
"$(roundcube.config_file)"
|
|
perms => m("644"),
|
|
copy_from => seed_cp("$(def.wmde_lib)/templates/roundcube-config.inc.php.mustache"),
|
|
handle => "roundcube_config_created";
|
|
|
|
"$(roundcube.config_file)"
|
|
edit_line => rc_line_based("$(this.bundle).settings"),
|
|
handle => "roundcube_config_edited",
|
|
depends_on => {"roundcube_config_created"};
|
|
|
|
commands:
|
|
"!mysql_$(cfg[db_name])_users_exists"::
|
|
"cd $(roundcube.install_sub_dir) && bin/initdb.sh --dir SQL"
|
|
depends_on => {"roundcube_config_edited"},
|
|
contain => wmde_cmd_useshell;
|
|
|
|
|
|
|
|
reports:
|
|
}
|
|
|
|
|
|
bundle agent configure_roundcube_password_plugin(cfg)
|
|
{
|
|
vars:
|
|
"config_file" string => "$(roundcube.install_sub_dir)/plugins/password/config.inc.php";
|
|
|
|
|
|
"settings[password_driver]" string => "'sql'";
|
|
"settings[password_confirm_current]" string => "false";
|
|
"settings[password_algorithm]" string => "'sha256-crypt'";
|
|
"settings[password_db_dsn]" string => "'mysql://$(cfg[db_user]):$(cfg[db_pass])@$(cfg[db_host])/$(cfg[db_name])'";
|
|
"settings[password_query]" string => "\"UPDATE mailbox SET password=%P WHERE username=%u;\"";
|
|
"settings[password_crypt_hash]" string => "'sha256'";
|
|
|
|
files:
|
|
"$(config_file)"
|
|
perms => m("644"),
|
|
copy_from => seed_cp("$(def.wmde_lib)/templates/roundcube-password-config.inc.php.mustache"),
|
|
handle => "roundcube_password_config_created";
|
|
|
|
"$(config_file)"
|
|
edit_line => rc_line_based("$(this.bundle).settings"),
|
|
handle => "roundcube_password_config_edited",
|
|
depends_on => {"roundcube_password_config_created"};
|
|
}
|
|
|
|
|
|
bundle agent roundcube_install_password_recovery_plugin(param_cfg)
|
|
{
|
|
classes:
|
|
"run_git" expression => not(fileexists("$(roundcube.install_sub_dir)/plugins/password_recovery"));
|
|
|
|
vars:
|
|
"config_file" string => "$(roundcube.install_sub_dir)/plugins/password_recovery/config.inc.php";
|
|
|
|
"default_cfg" data => '{
|
|
"password_recovery_git_url":"https://srcsrv.wikimedia.de/WMDE/roundcube-password_recovery.git -b wmde",
|
|
}';
|
|
|
|
|
|
|
|
"cfg" data => mergedata(@(default_cfg),@(param_cfg));
|
|
|
|
"settings[pr_db_dsn]" string => "'mysql://$(cfg[db_user]):$(cfg[db_pass])@$(cfg[db_host])/$(cfg[db_name])'";
|
|
"settings[pr_fields]" string => "[ 'altemail' => 'alt_email']";
|
|
"settings[pr_default_smtp_server]" string => "'localhost:25'";
|
|
|
|
"idx" slist => getindices(@(cfg[settings]));
|
|
"settings[$(idx)]" string => "$(cfg[settings][$(idx)])";
|
|
|
|
methods:
|
|
"any" usebundle => install_wget, handle=>"roundcube_wget_installed";
|
|
|
|
commands:
|
|
run_git::
|
|
"git clone --depth 1 $(cfg[password_recovery_git_url]) $(roundcube.install_sub_dir)/plugins/password_recovery && chown -R $(apache.www_user):$(apache.www_group) $(roundcube.install_sub_dir)/plugins/password_recovery"
|
|
|
|
contain => wmde_cmd_useshell,
|
|
handle => "roundcube_password_recovery_git_cloned",
|
|
depends_on => {"roundcube_wget_installed"};
|
|
|
|
!run_git::
|
|
"/usr/bin/true"
|
|
inform => "false",
|
|
handle => "roundcube_password_recovery_git_cloned";
|
|
|
|
files:
|
|
"$(config_file)"
|
|
perms => m("644"),
|
|
copy_from => seed_cp("$(def.wmde_lib)/templates/roundcube-password_recovery-config.inc.php.mustache"),
|
|
depends_on => {"roundcube_password_recovery_git_cloned"},
|
|
handle => "roundcube_password_recover_config_created";
|
|
|
|
"$(config_file)"
|
|
edit_line => rc_line_based("$(this.bundle).settings"),
|
|
handle => "roundcube_password_recover_config_edited",
|
|
depends_on => {"roundcube_password_recover_config_created"};
|
|
|
|
reports:
|
|
run_git::
|
|
"Run git";
|
|
!run_git::
|
|
"Dont run git";
|
|
}
|
|
|
|
|