openship 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -24
- package/dist/bare-2HYDXQEH.js +23 -0
- package/dist/{bowser-L6PVH37V.js → bowser-O3AEA6AN.js} +3 -1
- package/dist/{chunk-R74UB4X4.js → chunk-2ZLR7ULL.js} +253 -65
- package/dist/{chunk-E3ZPCNPU.js → chunk-3JQTL4R4.js} +234 -99
- package/dist/{chunk-YFLQGDN2.js → chunk-4TJC4JZQ.js} +18 -9
- package/dist/{chunk-JXQCFTDV.js → chunk-4Z5QO7N6.js} +4 -2
- package/dist/{chunk-7EYFCKZX.js → chunk-5FNIWBFI.js} +8 -6
- package/dist/{chunk-JJVSOE4I.js → chunk-5MZ624VX.js} +2 -0
- package/dist/{chunk-TDFK6ISF.js → chunk-6APIPIJY.js} +6 -4
- package/dist/{chunk-3LCRNQ2C.js → chunk-6APULWSU.js} +151 -133
- package/dist/{chunk-FTBXJ2VA.js → chunk-6B5YCFFV.js} +6 -4
- package/dist/{chunk-MDFYN2QH.js → chunk-AVIB7CT7.js} +3 -1
- package/dist/{chunk-VJTXRCTT.js → chunk-C5OHTYEF.js} +10 -6
- package/dist/{chunk-W7KGHYLV.js → chunk-DYPH4HCI.js} +2 -0
- package/dist/{chunk-5WI7ZXOC.js → chunk-EI575GHN.js} +4 -2
- package/dist/{chunk-Z6EKX6CX.js → chunk-FPRHYBY2.js} +2 -0
- package/dist/chunk-FQGJZ2HS.js +248 -0
- package/dist/{chunk-FZJX6XP7.js → chunk-FRNAR33O.js} +4 -2
- package/dist/{chunk-XRWV5ZNR.js → chunk-FXTBHTWY.js} +360 -42
- package/dist/chunk-ILFETZOM.js +131 -0
- package/dist/{chunk-PARRPUXN.js → chunk-IXCHURVK.js} +5 -3
- package/dist/{chunk-YJAS5RQX.js → chunk-JYGD5WSN.js} +2 -0
- package/dist/{chunk-JWBXYO24.js → chunk-KI2EY3WB.js} +2 -0
- package/dist/{chunk-YVXF6GGR.js → chunk-L2VOGB2X.js} +5 -104
- package/dist/{chunk-K5OH5U7N.js → chunk-MZ2WEHHY.js} +5 -3
- package/dist/{chunk-SJBR527P.js → chunk-O6ZZF52V.js} +3 -1
- package/dist/{chunk-VLPJLXXB.js → chunk-OWED2GRM.js} +3 -1
- package/dist/{chunk-C4FOQJ63.js → chunk-OXWDY22G.js} +4 -2
- package/dist/{chunk-NPVJYR7M.js → chunk-Q2CIRAOK.js} +2 -0
- package/dist/{chunk-JYAGTMSJ.js → chunk-RPHRPFEH.js} +2 -0
- package/dist/{chunk-UMYQALBH.js → chunk-SQ77DZOI.js} +1726 -1484
- package/dist/{chunk-HYL4QYZM.js → chunk-TGIINPVM.js} +13 -2
- package/dist/{chunk-SYCZE6FQ.js → chunk-TYVME3XD.js} +7 -1
- package/dist/{chunk-HDV4NSA3.js → chunk-V6AN6XLZ.js} +16 -6
- package/dist/{chunk-3YCMJRDZ.js → chunk-VDMQJHPI.js} +36 -15
- package/dist/{chunk-RZPDJC2J.js → chunk-VFINNTUL.js} +20 -1
- package/dist/{chunk-65KKUJBR.js → chunk-VWPEKOH6.js} +4 -2
- package/dist/{chunk-GHXGCANU.js → chunk-W73X43R7.js} +4 -2
- package/dist/{cloud-7IGG45CF.js → cloud-7QYOGF7F.js} +4 -2
- package/dist/cloud-ZSKOS4GY.js +30 -0
- package/dist/detect-SH4FHFBI.js +36 -0
- package/dist/{dist-NQB6QGX3.js → dist-IQJ6H6UZ.js} +4 -2
- package/dist/{dist-es-DCR6UJMP.js → dist-es-5DY7K32L.js} +7 -5
- package/dist/{dist-es-TYYZ5KEF.js → dist-es-JSTDUS7Q.js} +7 -5
- package/dist/{dist-es-7EZIM4JU.js → dist-es-OSNJBLXB.js} +6 -4
- package/dist/{dist-es-6RSPR56Q.js → dist-es-RYHIPOTN.js} +15 -13
- package/dist/{dist-es-33Z3Y6VE.js → dist-es-VNKHQVIB.js} +5 -3
- package/dist/{dist-es-D6QQVWRZ.js → dist-es-WV4AMOII.js} +9 -7
- package/dist/{dist-es-GMEQINIE.js → dist-es-X3B5QYKB.js} +7 -5
- package/dist/docker-U7AF5PTA.js +16 -0
- package/dist/docker-edge-executor-VHW3JPJS.js +13 -0
- package/dist/edge-import-V5CBA47C.js +45 -0
- package/dist/ensure-container-edge-CMYROUSI.js +33 -0
- package/dist/{event-streams-G7F6Q7QY.js → event-streams-EHRAKL75.js} +5 -3
- package/dist/{executor-O5NR7LMP.js → executor-YPT6RH6O.js} +9 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.js +256 -245
- package/dist/{loadSso-LH753OSJ.js → loadSso-46FQRIZS.js} +11 -9
- package/dist/local-executor-V7U5VOZW.js +12 -0
- package/dist/nginx-2GTRUIDE.js +24 -0
- package/dist/{noop-6KC6HRDB.js → noop-FMMFG2EZ.js} +4 -2
- package/dist/{openresty-lua-KFCOJAG4.js → openresty-lua-4WLGDSER.js} +11 -3
- package/dist/server/engine/ChangeLog +2289 -0
- package/dist/server/engine/Documentations +5 -0
- package/dist/server/engine/LICENSE +674 -0
- package/dist/server/engine/README.md +34 -0
- package/dist/server/engine/conf/amavisd +150 -0
- package/dist/server/engine/conf/clamav +71 -0
- package/dist/server/engine/conf/core +632 -0
- package/dist/server/engine/conf/dovecot +151 -0
- package/dist/server/engine/conf/fail2ban +72 -0
- package/dist/server/engine/conf/global +698 -0
- package/dist/server/engine/conf/iredapd +52 -0
- package/dist/server/engine/conf/logwatch +28 -0
- package/dist/server/engine/conf/postfix +97 -0
- package/dist/server/engine/conf/postgresql +93 -0
- package/dist/server/engine/conf/spamassassin +39 -0
- package/dist/server/engine/dialog/config_via_dialog.sh +258 -0
- package/dist/server/engine/dialog/optional_components.sh +122 -0
- package/dist/server/engine/dialog/pgsql_config.sh +52 -0
- package/dist/server/engine/dialog/virtual_domain_config.sh +94 -0
- package/dist/server/engine/functions/amavisd.sh +267 -0
- package/dist/server/engine/functions/backend.sh +85 -0
- package/dist/server/engine/functions/clamav.sh +100 -0
- package/dist/server/engine/functions/cleanup.sh +393 -0
- package/dist/server/engine/functions/dovecot.sh +583 -0
- package/dist/server/engine/functions/fail2ban.sh +209 -0
- package/dist/server/engine/functions/iredapd.sh +356 -0
- package/dist/server/engine/functions/optional_components.sh +24 -0
- package/dist/server/engine/functions/packages.sh +522 -0
- package/dist/server/engine/functions/packages_freebsd.sh +179 -0
- package/dist/server/engine/functions/postfix.sh +457 -0
- package/dist/server/engine/functions/postgresql.sh +239 -0
- package/dist/server/engine/functions/spamassassin.sh +49 -0
- package/dist/server/engine/functions/system_accounts.sh +128 -0
- package/dist/server/engine/iRedMail.sh +144 -0
- package/dist/server/engine/pkgs/get_all.sh +338 -0
- package/dist/server/engine/pkgs/pkgs.freebsd.sha256 +3 -0
- package/dist/server/engine/pkgs/pkgs.openbsd.sha256 +6 -0
- package/dist/server/engine/pkgs/pkgs.sha256 +1 -0
- package/dist/server/engine/samples/amavisd/amavisd.conf +677 -0
- package/dist/server/engine/samples/amavisd/amavisd.mysql +278 -0
- package/dist/server/engine/samples/amavisd/amavisd.pgsql +253 -0
- package/dist/server/engine/samples/amavisd/amavisd.schema +942 -0
- package/dist/server/engine/samples/amavisd/default_spam_policy.sql +46 -0
- package/dist/server/engine/samples/dovecot/dovecot-2.4-mariadb.conf +758 -0
- package/dist/server/engine/samples/dovecot/dovecot-2.4-openldap.conf +767 -0
- package/dist/server/engine/samples/dovecot/dovecot-2.4-pgsql.conf +762 -0
- package/dist/server/engine/samples/dovecot/dovecot-last-login.conf +50 -0
- package/dist/server/engine/samples/dovecot/dovecot-ldap.conf +21 -0
- package/dist/server/engine/samples/dovecot/dovecot-share-folder.conf +22 -0
- package/dist/server/engine/samples/dovecot/dovecot-sql.conf +28 -0
- package/dist/server/engine/samples/dovecot/dovecot-used-quota.conf +13 -0
- package/dist/server/engine/samples/dovecot/dovecot.conf +484 -0
- package/dist/server/engine/samples/dovecot/dovecot.sieve +7 -0
- package/dist/server/engine/samples/dovecot/dovecot2-quota-warning.sh +38 -0
- package/dist/server/engine/samples/dovecot/sql/imap_share_folder.mysql +16 -0
- package/dist/server/engine/samples/dovecot/sql/last_login.mysql +12 -0
- package/dist/server/engine/samples/dovecot/sql/used_quota.mysql +26 -0
- package/dist/server/engine/samples/dovecot/systemd/override.conf +3 -0
- package/dist/server/engine/samples/fail2ban/action.d/banned_db.conf +9 -0
- package/dist/server/engine/samples/fail2ban/bin/fail2ban_banned_db +268 -0
- package/dist/server/engine/samples/fail2ban/fail2ban.local +17 -0
- package/dist/server/engine/samples/fail2ban/filter.d/dovecot.iredmail.conf +5 -0
- package/dist/server/engine/samples/fail2ban/filter.d/postfix-pregreet.iredmail.conf +16 -0
- package/dist/server/engine/samples/fail2ban/filter.d/postfix.iredmail.conf +18 -0
- package/dist/server/engine/samples/fail2ban/filter.d/roundcube.iredmail.conf +9 -0
- package/dist/server/engine/samples/fail2ban/jail.d/dovecot.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/nginx-http-auth.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/postfix-pregreet.local +9 -0
- package/dist/server/engine/samples/fail2ban/jail.d/postfix.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/roundcube.local +9 -0
- package/dist/server/engine/samples/fail2ban/jail.d/sogo.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/sshd.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.local +6 -0
- package/dist/server/engine/samples/fail2ban/openbsd/rc +27 -0
- package/dist/server/engine/samples/fail2ban/sql/fail2ban.mysql +49 -0
- package/dist/server/engine/samples/fail2ban/sql/fail2ban.pgsql +48 -0
- package/dist/server/engine/samples/firewall/firewalld/services/ssh.xml +6 -0
- package/dist/server/engine/samples/firewall/firewalld/zones/iredmail.xml +15 -0
- package/dist/server/engine/samples/firewall/iptables/ip6tables.init.debian +362 -0
- package/dist/server/engine/samples/firewall/iptables/ip6tables.rules +53 -0
- package/dist/server/engine/samples/firewall/iptables/iptables.init.debian +363 -0
- package/dist/server/engine/samples/firewall/iptables/iptables.rules +54 -0
- package/dist/server/engine/samples/firewall/nftables.conf +58 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/dovecot.conf +3 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/iredapd.conf +1 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/mlmmjadmin.conf +1 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/php-fpm.conf +2 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/slapd.conf +1 -0
- package/dist/server/engine/samples/freebsd/syslog.d/dovecot.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/fail2ban.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/iredapd.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/mlmmjadmin.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/php-fpm.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/slapd.conf +2 -0
- package/dist/server/engine/samples/iredmail/iredmail.mysql +491 -0
- package/dist/server/engine/samples/iredmail/iredmail.pgsql +465 -0
- package/dist/server/engine/samples/iredmail/iredmail.schema +456 -0
- package/dist/server/engine/samples/iredmail/used_quota_triggers_dovecot_2.3.pgsql +40 -0
- package/dist/server/engine/samples/iredmail/used_quota_triggers_dovecot_2.4.pgsql +18 -0
- package/dist/server/engine/samples/logrotate/dovecot +13 -0
- package/dist/server/engine/samples/logrotate/iredapd +13 -0
- package/dist/server/engine/samples/logrotate/mlmmjadmin +13 -0
- package/dist/server/engine/samples/logrotate/openldap +19 -0
- package/dist/server/engine/samples/logrotate/php-fpm +13 -0
- package/dist/server/engine/samples/openbsd/ldapd.conf +58 -0
- package/dist/server/engine/samples/openbsd/pf.conf +28 -0
- package/dist/server/engine/samples/postfix/command_filter.pcre +3 -0
- package/dist/server/engine/samples/postfix/freebsd/mailer.conf +9 -0
- package/dist/server/engine/samples/postfix/helo_access.pcre +180 -0
- package/dist/server/engine/samples/postfix/ldap/catchall_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/recipient_bcc_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/recipient_bcc_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/relay_domains.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_bcc_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_bcc_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_dependent_relayhost_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_dependent_relayhost_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_login_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/transport_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/transport_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_alias_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_group_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_group_members_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_mailbox_domains.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_mailbox_maps.cf +12 -0
- package/dist/server/engine/samples/postfix/main.cf +282 -0
- package/dist/server/engine/samples/postfix/main.cf.amavisd +7 -0
- package/dist/server/engine/samples/postfix/main.cf.dovecot +8 -0
- package/dist/server/engine/samples/postfix/main.cf.ldap +39 -0
- package/dist/server/engine/samples/postfix/main.cf.mlmmj +5 -0
- package/dist/server/engine/samples/postfix/main.cf.mysql +39 -0
- package/dist/server/engine/samples/postfix/main.cf.pgsql +39 -0
- package/dist/server/engine/samples/postfix/main.cf.postscreen +30 -0
- package/dist/server/engine/samples/postfix/master.cf +87 -0
- package/dist/server/engine/samples/postfix/mysql/catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/domain_alias_catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/domain_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/recipient_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/recipient_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/relay_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/sender_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/sender_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/sender_dependent_relayhost_maps.cf +6 -0
- package/dist/server/engine/samples/postfix/mysql/sender_login_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/transport_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/transport_maps_maillist.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/transport_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/virtual_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/virtual_mailbox_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/virtual_mailbox_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/domain_alias_catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/domain_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/recipient_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/recipient_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/relay_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_dependent_relayhost_maps.cf +6 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_login_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/transport_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/transport_maps_maillist.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/transport_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/virtual_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/virtual_mailbox_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/virtual_mailbox_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/postscreen_access.cidr +6 -0
- package/dist/server/engine/samples/postgresql/sql/add_first_domain_and_user.sql +34 -0
- package/dist/server/engine/samples/postgresql/sql/grant_permissions.sql +14 -0
- package/dist/server/engine/samples/postgresql/sql/init_vmail_db.sql +15 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-dovecot.conf +23 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-fail2ban.conf +2 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-iredapd.conf +12 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-mlmmjadmin.conf +12 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-openldap.conf +2 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-phpfpm.conf +3 -0
- package/dist/server/engine/samples/spamassassin/local.cf +186 -0
- package/dist/server/engine/samples/spamassassin/razor.conf +1 -0
- package/dist/server/engine/samples/systemd/clamd.service.d/override.conf +2 -0
- package/dist/server/engine/samples/systemd/mariadb.service.d/override.conf +3 -0
- package/dist/server/engine/samples/systemd/slapd.service.d/override.conf +6 -0
- package/dist/server/engine/samples/yum/CentOS-Linux-AppStream.repo +6 -0
- package/dist/server/engine/samples/yum/CentOS-Linux-PowerTools.repo +6 -0
- package/dist/server/engine/samples/yum/CentOS-Stream-AppStream.repo +7 -0
- package/dist/server/engine/samples/yum/CentOS-Stream-PowerTools.repo +7 -0
- package/dist/server/engine/samples/yum/symas-openldap.repo +6 -0
- package/dist/server/engine/tools/add_enabled_service.py +60 -0
- package/dist/server/engine/tools/backup_mysql.sh +238 -0
- package/dist/server/engine/tools/backup_openldap.sh +230 -0
- package/dist/server/engine/tools/backup_pgsql.sh +217 -0
- package/dist/server/engine/tools/backup_sogo.sh +156 -0
- package/dist/server/engine/tools/create_mail_user_OpenLDAP.py +335 -0
- package/dist/server/engine/tools/create_mail_user_OpenLDAP.sh +287 -0
- package/dist/server/engine/tools/create_mail_user_SQL.sh +127 -0
- package/dist/server/engine/tools/enable_postscreen.sh +144 -0
- package/dist/server/engine/tools/fail2ban_unban_ip.sh +39 -0
- package/dist/server/engine/tools/find_sasl_login_ip.sh +20 -0
- package/dist/server/engine/tools/find_top_sasl_usernames.sh +28 -0
- package/dist/server/engine/tools/generate_ssl_keys.sh +85 -0
- package/dist/server/engine/tools/kill_high_cpu_sogo_process.sh +32 -0
- package/dist/server/engine/tools/ldap_assign_user_to_groups.py +151 -0
- package/dist/server/engine/tools/ldap_move_members_to_another_group.py +129 -0
- package/dist/server/engine/tools/migrate_sql_alias_table.py +177 -0
- package/dist/server/engine/update/0.9.8/amavisd.mysql +29 -0
- package/dist/server/engine/update/0.9.8/amavisd.pgsql +39 -0
- package/dist/server/engine/update/0.9.8/iredmail.mysql +53 -0
- package/dist/server/engine/update/0.9.8/iredmail.pgsql +61 -0
- package/dist/server/engine/update/0.9.9/iredmail.mysql +2 -0
- package/dist/server/engine/update/0.9.9/iredmail.pgsql +2 -0
- package/dist/server/engine/update/1.0/iredmail.mysql +2 -0
- package/dist/server/engine/update/1.0/iredmail.pgsql +2 -0
- package/dist/server/engine/update/1.2/last_login.mysql +16 -0
- package/dist/server/engine/update/1.4.0/iredmail.mysql +22 -0
- package/dist/server/engine/update/1.4.0/iredmail.pgsql +20 -0
- package/dist/server/engine/update/1.4.1/iredmail.mysql +3 -0
- package/dist/server/engine/update/1.4.1/iredmail.pgsql +3 -0
- package/dist/server/engine/update/1.4.1/sogo.mysql +11 -0
- package/dist/server/engine/update/1.4.1/sogo.pgsql +30 -0
- package/dist/server/engine/update/1.4.1/update-ldap.py +66 -0
- package/dist/server/engine/update/1.4.2/iredmail.mysql +9 -0
- package/dist/server/engine/update/1.4.2/iredmail.pgsql +9 -0
- package/dist/server/engine/update/1.4.2/sogo.pgsql +30 -0
- package/dist/server/engine/update/1.6.0/sogo_view.pgsql +27 -0
- package/dist/server/engine/update/1.6.3/iredmail.mysql +1 -0
- package/dist/server/engine/update/1.7.0/fail2ban.mysql +11 -0
- package/dist/server/engine/update/1.7.0/fail2ban.pgsql +12 -0
- package/dist/server/engine/update/1.7.1/amavisd.mysql +1 -0
- package/dist/server/engine/update/1.7.2/vmail.mysql +30 -0
- package/dist/server/engine/update/1.7.3/deleted_mailboxes.mysql +43 -0
- package/dist/server/engine/update/1.7.3/iredadmin.mysql +26 -0
- package/dist/server/engine/update/1.7.3/vmail.mysql +79 -0
- package/dist/server/engine/update/1.7.3/vmail.pgsql +9 -0
- package/dist/server/engine/update/README.md +1 -0
- package/dist/server/engine/update/ldap/README.md +40 -0
- package/dist/server/engine/update/ldap/update-ldap-dovecot-2.3.py +69 -0
- package/dist/server/index.js +55574 -53675
- package/dist/server/migrations/0071_gh_device_token.sql +3 -0
- package/dist/server/migrations/0072_gh_device_token_method.sql +1 -0
- package/dist/server/migrations/meta/_journal.json +14 -0
- package/dist/setup-HQIZLUOJ.js +20 -0
- package/dist/{signin-PVC7MBZJ.js → signin-ITOPKKUB.js} +11 -9
- package/dist/{sso-oidc-ZXY77BSL.js → sso-oidc-NON2PD7Y.js} +11 -9
- package/dist/{sts-LX5L4UU3.js → sts-HHFFSAY2.js} +10 -8
- package/package.json +1 -1
- package/dist/bare-CNSFDNSZ.js +0 -20
- package/dist/cloud-655YYCEW.js +0 -26
- package/dist/docker-UWQPDEGW.js +0 -14
- package/dist/docker-edge-executor-ZLAYE5FE.js +0 -11
- package/dist/edge-import-AFID2EN3.js +0 -41
- package/dist/nginx-M36GDYL7.js +0 -18
- package/dist/setup-ZXXB5S22.js +0 -16
|
@@ -1,1472 +1,1724 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
":" //# ; exec "$(command -v bun || command -v node)" "$0" "$@"
|
|
1
3
|
import { createRequire as __ospCreateRequire } from "node:module";
|
|
2
4
|
const require = __ospCreateRequire(import.meta.url);
|
|
3
5
|
import {
|
|
4
|
-
describeProcess,
|
|
5
|
-
probeListeningPort,
|
|
6
6
|
resolveEnvironment
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-L2VOGB2X.js";
|
|
8
8
|
import {
|
|
9
9
|
formatDuration,
|
|
10
10
|
isRemoteConnectionError,
|
|
11
11
|
systemDebug
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-RPHRPFEH.js";
|
|
13
|
+
import {
|
|
14
|
+
containerCommand,
|
|
15
|
+
edgeContainerExecutor,
|
|
16
|
+
isSafeCertPath,
|
|
17
|
+
readDeclaredPair,
|
|
18
|
+
readMaybeInContainer,
|
|
19
|
+
validateCertFor
|
|
20
|
+
} from "./chunk-FXTBHTWY.js";
|
|
13
21
|
import {
|
|
14
22
|
sq
|
|
15
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-FPRHYBY2.js";
|
|
24
|
+
import {
|
|
25
|
+
EdgeConflictError,
|
|
26
|
+
EdgeMigrateRequested,
|
|
27
|
+
freeEdgeTargets,
|
|
28
|
+
invalidateEdgeContainer,
|
|
29
|
+
ourLuaOnHost,
|
|
30
|
+
probeEdge,
|
|
31
|
+
resolveOurEdgeContainer,
|
|
32
|
+
sq as sq2,
|
|
33
|
+
stopTargetsForStatus
|
|
34
|
+
} from "./chunk-FQGJZ2HS.js";
|
|
16
35
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
deployLuaScripts,
|
|
20
|
-
detectOpenRestyPaths,
|
|
21
|
-
ensureOpenRestyConfig
|
|
22
|
-
} from "./chunk-RZPDJC2J.js";
|
|
36
|
+
waitForPortListening
|
|
37
|
+
} from "./chunk-ILFETZOM.js";
|
|
23
38
|
import {
|
|
24
|
-
|
|
39
|
+
EDGE_CONTAINER_MOUNTS,
|
|
40
|
+
EDGE_HOST_PATHS,
|
|
41
|
+
OPENRESTY_DEFAULT_PATHS,
|
|
42
|
+
detectOpenRestyPaths
|
|
43
|
+
} from "./chunk-VFINNTUL.js";
|
|
44
|
+
import {
|
|
45
|
+
buildEdgeImageRef,
|
|
25
46
|
compareSemver,
|
|
26
47
|
safeErrorMessage
|
|
27
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-6APULWSU.js";
|
|
28
49
|
|
|
29
|
-
// ../../packages/adapters/src/system/
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
50
|
+
// ../../packages/adapters/src/system/proxy/import/parse-utils.ts
|
|
51
|
+
async function tryExec(executor, command) {
|
|
52
|
+
try {
|
|
53
|
+
return await executor.exec(command);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
36
56
|
}
|
|
37
|
-
return {
|
|
38
|
-
supported: true,
|
|
39
|
-
installCommand: "curl -fsSL https://get.docker.com | sh",
|
|
40
|
-
startCommand: profile.serviceManager === "systemd" ? "systemctl enable docker && systemctl start docker" : void 0,
|
|
41
|
-
verifyCommand: "docker --version"
|
|
42
|
-
};
|
|
43
57
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
apt: "apt-get update -qq && apt-get install -y -qq git",
|
|
47
|
-
dnf: "dnf install -y git",
|
|
48
|
-
yum: "yum install -y git",
|
|
49
|
-
apk: "apk add --no-cache git",
|
|
50
|
-
brew: "brew install git"
|
|
51
|
-
};
|
|
52
|
-
const installCommand = commands[profile.packageManager];
|
|
53
|
-
if (!installCommand) {
|
|
54
|
-
return {
|
|
55
|
-
supported: false,
|
|
56
|
-
unsupportedReason: "No supported package manager found for Git installation"
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
supported: true,
|
|
61
|
-
installCommand,
|
|
62
|
-
verifyCommand: "git --version"
|
|
63
|
-
};
|
|
58
|
+
function stripComments(text) {
|
|
59
|
+
return text.replace(/#.*$/gm, "");
|
|
64
60
|
}
|
|
65
|
-
function
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
function extractBlocks(text, keyword) {
|
|
62
|
+
const blocks = [];
|
|
63
|
+
const re = new RegExp(`(?:^|[\\s;}])${keyword}\\b[^{;]*\\{`, "g");
|
|
64
|
+
let m;
|
|
65
|
+
while ((m = re.exec(text)) !== null) {
|
|
66
|
+
const openIdx = m.index + m[0].length - 1;
|
|
67
|
+
let depth = 1;
|
|
68
|
+
let i = openIdx + 1;
|
|
69
|
+
for (; i < text.length && depth > 0; i++) {
|
|
70
|
+
if (text[i] === "{") depth++;
|
|
71
|
+
else if (text[i] === "}") depth--;
|
|
72
|
+
}
|
|
73
|
+
if (depth === 0) {
|
|
74
|
+
blocks.push(text.slice(openIdx + 1, i - 1));
|
|
75
|
+
re.lastIndex = i;
|
|
76
|
+
} else {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
79
|
}
|
|
80
|
-
return
|
|
81
|
-
supported: true,
|
|
82
|
-
installCommand,
|
|
83
|
-
verifyCommand: "rsync --version | head -n 1"
|
|
84
|
-
};
|
|
80
|
+
return blocks;
|
|
85
81
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
unsupportedReason: "OpenResty installation is only supported on Linux servers"
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
let installCommand;
|
|
116
|
-
if (profile.packageManager === "apt") {
|
|
117
|
-
const distro = profile.distro === "debian" ? "debian" : "ubuntu";
|
|
118
|
-
installCommand = [
|
|
119
|
-
"set -e",
|
|
120
|
-
// Heal a stale/bad openresty.list left by a prior run (e.g. the #86
|
|
121
|
-
// 'resolute' pin) BEFORE the first apt-get update reads it — otherwise
|
|
122
|
-
// set -e aborts here and the repo never gets rewritten.
|
|
123
|
-
"rm -f /etc/apt/sources.list.d/openresty.list",
|
|
124
|
-
"apt-get update -qq && apt-get install -y -qq wget gnupg2 lsb-release",
|
|
125
|
-
"wget -qO /tmp/openresty-pubkey.gpg https://openresty.org/package/pubkey.gpg",
|
|
126
|
-
"gpg --yes --dearmor -o /usr/share/keyrings/openresty.gpg /tmp/openresty-pubkey.gpg",
|
|
127
|
-
`REPO=${distro}`,
|
|
128
|
-
...OPENRESTY_APT_SOURCES,
|
|
129
|
-
"apt-get update -qq && apt-get install -y -qq openresty"
|
|
130
|
-
].join("\n");
|
|
131
|
-
} else if (profile.packageManager === "dnf") {
|
|
132
|
-
const distro = profile.distro === "fedora" ? "fedora" : "centos";
|
|
133
|
-
installCommand = `wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/${distro}/openresty.repo && dnf install -y openresty`;
|
|
134
|
-
} else if (profile.packageManager === "yum") {
|
|
135
|
-
installCommand = "wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/centos/openresty.repo && yum install -y openresty";
|
|
136
|
-
} else if (profile.packageManager === "apk") {
|
|
137
|
-
installCommand = [
|
|
138
|
-
"apk add --no-cache wget",
|
|
139
|
-
"wget -qO /etc/apk/keys/admin@openresty.com-5ea678a6.rsa.pub https://openresty.org/package/alpine/admin@openresty.com-5ea678a6.rsa.pub",
|
|
140
|
-
`. /etc/os-release && echo "https://openresty.org/package/alpine/v$( echo $VERSION_ID | cut -d. -f1,2 )/main" >> /etc/apk/repositories`,
|
|
141
|
-
"apk update && apk add openresty"
|
|
142
|
-
].join(" && ");
|
|
143
|
-
} else {
|
|
144
|
-
installCommand = [
|
|
145
|
-
"set -e",
|
|
146
|
-
"if command -v apt-get >/dev/null 2>&1; then",
|
|
147
|
-
" rm -f /etc/apt/sources.list.d/openresty.list",
|
|
148
|
-
" apt-get update -qq && apt-get install -y -qq wget gnupg2 lsb-release",
|
|
149
|
-
" wget -qO /tmp/openresty-pubkey.gpg https://openresty.org/package/pubkey.gpg",
|
|
150
|
-
" gpg --yes --dearmor -o /usr/share/keyrings/openresty.gpg /tmp/openresty-pubkey.gpg",
|
|
151
|
-
' DISTRO=$(. /etc/os-release 2>/dev/null && echo "$ID" || echo "ubuntu")',
|
|
152
|
-
' case "$DISTRO" in debian) REPO=debian ;; *) REPO=ubuntu ;; esac',
|
|
153
|
-
...OPENRESTY_APT_SOURCES.map((l) => " " + l),
|
|
154
|
-
" apt-get update -qq && apt-get install -y -qq openresty",
|
|
155
|
-
"elif command -v dnf >/dev/null 2>&1; then",
|
|
156
|
-
" wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/centos/openresty.repo && dnf install -y openresty",
|
|
157
|
-
"elif command -v yum >/dev/null 2>&1; then",
|
|
158
|
-
" wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/centos/openresty.repo && yum install -y openresty",
|
|
159
|
-
"elif command -v apk >/dev/null 2>&1; then",
|
|
160
|
-
" apk add --no-cache wget \\",
|
|
161
|
-
" && wget -qO /etc/apk/keys/admin@openresty.com-5ea678a6.rsa.pub https://openresty.org/package/alpine/admin@openresty.com-5ea678a6.rsa.pub \\",
|
|
162
|
-
' && . /etc/os-release && echo "https://openresty.org/package/alpine/v$(echo $VERSION_ID | cut -d. -f1,2)/main" >> /etc/apk/repositories \\',
|
|
163
|
-
" && apk update && apk add openresty",
|
|
164
|
-
"else",
|
|
165
|
-
' echo "No supported package manager found (tried apt-get, dnf, yum, apk)" >&2 && exit 1',
|
|
166
|
-
"fi"
|
|
167
|
-
].join("\n");
|
|
82
|
+
function sq3(value) {
|
|
83
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ../../packages/adapters/src/system/proxy/import/nginx.ts
|
|
87
|
+
async function loadNginxConfig(executor) {
|
|
88
|
+
const dumped = await tryExec(executor, "nginx -T 2>/dev/null");
|
|
89
|
+
if (dumped && /server\s*\{/.test(dumped)) return dumped;
|
|
90
|
+
const cat = await tryExec(
|
|
91
|
+
executor,
|
|
92
|
+
"cat /etc/nginx/nginx.conf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/*.conf 2>/dev/null"
|
|
93
|
+
);
|
|
94
|
+
return cat ?? "";
|
|
95
|
+
}
|
|
96
|
+
function firstDirective(body, name) {
|
|
97
|
+
const m = body.match(new RegExp(`(?:^|[;{\\s])${name}\\s+([^;]+);`));
|
|
98
|
+
return m?.[1]?.trim();
|
|
99
|
+
}
|
|
100
|
+
function parseUpstreams(config) {
|
|
101
|
+
const map = /* @__PURE__ */ new Map();
|
|
102
|
+
const re = /(?:^|[\s;}])upstream\s+(\S+)\s*\{([^}]*)\}/g;
|
|
103
|
+
let m;
|
|
104
|
+
while ((m = re.exec(config)) !== null) {
|
|
105
|
+
const name = m[1];
|
|
106
|
+
const server = m[2].match(/(?:^|[\s;{])server\s+([^;\s]+)/);
|
|
107
|
+
if (name && server?.[1]) map.set(name, server[1].trim());
|
|
168
108
|
}
|
|
169
|
-
return
|
|
170
|
-
supported: true,
|
|
171
|
-
installCommand,
|
|
172
|
-
startCommand: profile.serviceManager === "systemd" ? "systemctl enable openresty && systemctl start openresty" : void 0,
|
|
173
|
-
verifyCommand: "openresty -v 2>&1"
|
|
174
|
-
};
|
|
109
|
+
return map;
|
|
175
110
|
}
|
|
176
|
-
function
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
111
|
+
function resolveProxyTarget(proxyPass, upstreams) {
|
|
112
|
+
const raw = proxyPass.replace(/;$/, "").trim();
|
|
113
|
+
if (raw.includes("$")) return { reason: `proxy_pass "${raw}" uses an nginx variable` };
|
|
114
|
+
if (/\/\/unix:/i.test(raw)) return { reason: `proxy_pass "${raw}" targets a unix socket` };
|
|
115
|
+
const m = raw.match(/^(https?:\/\/)([^/]+)(\/.*)?$/i);
|
|
116
|
+
if (!m) return { reason: `unrecognized proxy_pass "${raw}"` };
|
|
117
|
+
const scheme = m[1];
|
|
118
|
+
const authority = m[2];
|
|
119
|
+
const host = authority.replace(/:\d+$/, "");
|
|
120
|
+
if (upstreams.has(host)) return { url: `${scheme}${upstreams.get(host)}` };
|
|
121
|
+
const isIp = /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
|
|
122
|
+
if (isIp || host === "localhost" || host.includes(".")) return { url: raw };
|
|
123
|
+
return { reason: `proxy_pass host "${host}" is an undeclared upstream \u2014 not migratable` };
|
|
124
|
+
}
|
|
125
|
+
function extractLocationProxies(serverBody) {
|
|
126
|
+
const out = [];
|
|
127
|
+
const re = /(?:^|[\s;}])location\s+([^{]+?)\s*\{/g;
|
|
128
|
+
let m;
|
|
129
|
+
while ((m = re.exec(serverBody)) !== null) {
|
|
130
|
+
const path = m[1].trim();
|
|
131
|
+
const openIdx = m.index + m[0].length - 1;
|
|
132
|
+
let depth = 1;
|
|
133
|
+
let i = openIdx + 1;
|
|
134
|
+
for (; i < serverBody.length && depth > 0; i++) {
|
|
135
|
+
if (serverBody[i] === "{") depth++;
|
|
136
|
+
else if (serverBody[i] === "}") depth--;
|
|
137
|
+
}
|
|
138
|
+
if (depth !== 0) break;
|
|
139
|
+
const locBody = serverBody.slice(openIdx + 1, i - 1);
|
|
140
|
+
re.lastIndex = i;
|
|
141
|
+
const pp = firstDirective(locBody, "proxy_pass");
|
|
142
|
+
if (pp) out.push({ path, proxyPass: pp });
|
|
189
143
|
}
|
|
190
|
-
return
|
|
191
|
-
supported: true,
|
|
192
|
-
installCommand,
|
|
193
|
-
verifyCommand: "certbot --version 2>/dev/null"
|
|
194
|
-
};
|
|
144
|
+
return out;
|
|
195
145
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
],
|
|
210
|
-
parseVersion: (output) => output.match(/openresty\/(\S+)/)?.[1] ?? output.match(/nginx\/(\S+)/)?.[1] ?? output,
|
|
211
|
-
missingMessage: "OpenResty is not installed",
|
|
212
|
-
notRunningMessage: "OpenResty is installed but not running"
|
|
213
|
-
},
|
|
214
|
-
certbot: {
|
|
215
|
-
versionCommand: "certbot --version 2>/dev/null",
|
|
216
|
-
parseVersion: (output) => output.match(/certbot\s+(\S+)/)?.[1] ?? output,
|
|
217
|
-
missingMessage: "Certbot is not installed"
|
|
218
|
-
},
|
|
219
|
-
git: {
|
|
220
|
-
versionCommand: "git --version",
|
|
221
|
-
parseVersion: (output) => output.match(/git version (\S+)/)?.[1] ?? output,
|
|
222
|
-
missingMessage: "Git is not installed"
|
|
223
|
-
},
|
|
224
|
-
rsync: {
|
|
225
|
-
versionCommand: "rsync --version | head -n 1",
|
|
226
|
-
parseVersion: (output) => output.match(/rsync\s+version\s+(\S+)/i)?.[1] ?? output,
|
|
227
|
-
missingMessage: "rsync is not installed"
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
installs: {
|
|
231
|
-
docker: dockerInstallPlan,
|
|
232
|
-
git: gitInstallPlan,
|
|
233
|
-
rsync: rsyncInstallPlan,
|
|
234
|
-
openresty: openrestyInstallPlan,
|
|
235
|
-
certbot: certbotInstallPlan
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
// ../../packages/adapters/src/system/available-version.ts
|
|
240
|
-
var PACKAGE_NAMES = {
|
|
241
|
-
git: "git",
|
|
242
|
-
rsync: "rsync",
|
|
243
|
-
openresty: "openresty",
|
|
244
|
-
certbot: "certbot",
|
|
245
|
-
docker: null
|
|
246
|
-
};
|
|
247
|
-
function normalizePkgVersion(raw) {
|
|
248
|
-
let v = raw.trim();
|
|
249
|
-
const colon = v.lastIndexOf(":");
|
|
250
|
-
if (colon !== -1) v = v.slice(colon + 1);
|
|
251
|
-
const dash = v.indexOf("-");
|
|
252
|
-
if (dash !== -1) v = v.slice(0, dash);
|
|
253
|
-
return v.trim();
|
|
146
|
+
function isHttpsUpgradeForSelf(body, names) {
|
|
147
|
+
const targets = [
|
|
148
|
+
...body.matchAll(/(?:^|[\s;{])return\s+30[1-8]\s+([^;]+);/g),
|
|
149
|
+
...body.matchAll(/(?:^|[\s;{])rewrite\s+\S+\s+([^;]+?)\s+permanent\s*;/g)
|
|
150
|
+
].map((m) => m[1].trim());
|
|
151
|
+
if (targets.length === 0) return false;
|
|
152
|
+
return targets.every((raw) => {
|
|
153
|
+
if (!/^https:\/\//i.test(raw)) return false;
|
|
154
|
+
const authority = raw.replace(/^https:\/\//i, "").split(/[/\s]/)[0] ?? "";
|
|
155
|
+
const host = (authority.match(/^(\$[a-z_]+|[^$:]+)/i)?.[1] ?? "").replace(/:\d+$/, "");
|
|
156
|
+
if (host === "$host" || host === "$server_name" || host === "$http_host") return true;
|
|
157
|
+
return names.includes(host);
|
|
158
|
+
});
|
|
254
159
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
160
|
+
function parseServer(body, source, upstreams) {
|
|
161
|
+
const warnings = [];
|
|
162
|
+
const names = firstDirective(body, "server_name")?.split(/\s+/).filter((n) => n && n !== "_" && !n.startsWith("~")) ?? [];
|
|
163
|
+
const listens = [...body.matchAll(/(?:^|[;{\s])listen\s+([^;]+);/g)].map((m) => m[1]);
|
|
164
|
+
const ssl = listens.some((l) => /\bssl\b/.test(l) || /\b443\b/.test(l));
|
|
165
|
+
const root = firstDirective(body, "root");
|
|
166
|
+
const certPath = firstDirective(body, "ssl_certificate");
|
|
167
|
+
const keyPath = firstDirective(body, "ssl_certificate_key");
|
|
168
|
+
if (names.length === 0) return { warnings: [] };
|
|
169
|
+
const rawTargets = extractLocationProxies(body);
|
|
170
|
+
if (rawTargets.length === 0) {
|
|
171
|
+
const serverLevel = firstDirective(body, "proxy_pass");
|
|
172
|
+
if (serverLevel) rawTargets.push({ path: "/", proxyPass: serverLevel });
|
|
173
|
+
}
|
|
174
|
+
const resolved = [];
|
|
175
|
+
for (const t of rawTargets) {
|
|
176
|
+
const r = resolveProxyTarget(t.proxyPass, upstreams);
|
|
177
|
+
if ("reason" in r) warnings.push(`nginx: ${names[0]} ${t.path} \u2014 ${r.reason} (skipped)`);
|
|
178
|
+
else resolved.push({ path: t.path, url: r.url });
|
|
179
|
+
}
|
|
180
|
+
let target;
|
|
181
|
+
let routes;
|
|
182
|
+
if (resolved.length > 0) {
|
|
183
|
+
const primary = resolved.find((r) => r.path === "/") ?? resolved[0];
|
|
184
|
+
target = { kind: "proxy", url: primary.url };
|
|
185
|
+
routes = resolved;
|
|
186
|
+
} else if (root) {
|
|
187
|
+
target = { kind: "static", root: root.replace(/;$/, "") };
|
|
188
|
+
} else if (isHttpsUpgradeForSelf(body, names)) {
|
|
189
|
+
return { warnings: [] };
|
|
190
|
+
} else {
|
|
191
|
+
warnings.push(`nginx: ${names[0]} has neither proxy_pass nor root \u2014 skipped (${source})`);
|
|
192
|
+
return { warnings };
|
|
260
193
|
}
|
|
194
|
+
const site = { serverNames: names, ssl, target, source };
|
|
195
|
+
if (routes) site.routes = routes;
|
|
196
|
+
if (certPath && keyPath) site.tls = { certPath, keyPath };
|
|
197
|
+
return { site, warnings };
|
|
261
198
|
}
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return
|
|
199
|
+
function parseNginxConfig(raw) {
|
|
200
|
+
const warnings = [];
|
|
201
|
+
const sites = [];
|
|
202
|
+
if (!raw.trim()) {
|
|
203
|
+
return { proxy: "nginx", sites, warnings: ["nginx: no readable configuration found"] };
|
|
267
204
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
);
|
|
273
|
-
return out?.trim().split(/\s+/)[1]?.trim() ?? null;
|
|
205
|
+
const config = stripComments(raw);
|
|
206
|
+
const upstreams = parseUpstreams(config);
|
|
207
|
+
const blocks = extractBlocks(config, "server");
|
|
208
|
+
if (blocks.length === 0) {
|
|
209
|
+
warnings.push("nginx: no server blocks found");
|
|
274
210
|
}
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
211
|
+
for (const body of blocks) {
|
|
212
|
+
const { site, warnings: blockWarnings } = parseServer(body, "nginx", upstreams);
|
|
213
|
+
warnings.push(...blockWarnings);
|
|
214
|
+
if (site) sites.push(site);
|
|
279
215
|
}
|
|
280
|
-
return
|
|
216
|
+
return { proxy: "nginx", sites, warnings };
|
|
281
217
|
}
|
|
282
|
-
async function
|
|
283
|
-
|
|
284
|
-
(s) => s.installed && s.version && PACKAGE_NAMES[s.name]
|
|
285
|
-
);
|
|
286
|
-
await Promise.all(
|
|
287
|
-
targets.map(async (s) => {
|
|
288
|
-
try {
|
|
289
|
-
const pkg = PACKAGE_NAMES[s.name];
|
|
290
|
-
const candidate = await probeCandidate(executor, profile.packageManager, pkg);
|
|
291
|
-
if (!candidate) return;
|
|
292
|
-
const avail = normalizePkgVersion(candidate);
|
|
293
|
-
const installed = normalizePkgVersion(s.version);
|
|
294
|
-
if (avail && compareSemver(avail, installed) > 0) {
|
|
295
|
-
s.availableVersion = avail;
|
|
296
|
-
s.updateAvailable = true;
|
|
297
|
-
}
|
|
298
|
-
} catch {
|
|
299
|
-
}
|
|
300
|
-
})
|
|
301
|
-
);
|
|
218
|
+
async function scanNginx(executor) {
|
|
219
|
+
return parseNginxConfig(await loadNginxConfig(executor));
|
|
302
220
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
name: "docker",
|
|
308
|
-
label: "Docker",
|
|
309
|
-
description: "Container runtime for deployments",
|
|
310
|
-
installable: true,
|
|
311
|
-
category: "core"
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
name: "git",
|
|
315
|
-
label: "Git",
|
|
316
|
-
description: "Version control for source code",
|
|
317
|
-
installable: true,
|
|
318
|
-
category: "core"
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
name: "openresty",
|
|
322
|
-
label: "OpenResty",
|
|
323
|
-
description: "Reverse proxy with Lua scripting for routing and traffic control",
|
|
324
|
-
installable: true,
|
|
325
|
-
category: "infrastructure"
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
name: "certbot",
|
|
329
|
-
label: "Certbot",
|
|
330
|
-
description: "Let's Encrypt certificate provisioning",
|
|
331
|
-
installable: true,
|
|
332
|
-
category: "infrastructure"
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
name: "rsync",
|
|
336
|
-
label: "rsync",
|
|
337
|
-
description: "Fast directory sync for remote local-build transfers",
|
|
338
|
-
installable: true,
|
|
339
|
-
category: "infrastructure"
|
|
340
|
-
}
|
|
221
|
+
var OUR_EDGE_SITE_GLOBS = [
|
|
222
|
+
`${EDGE_HOST_PATHS.sitesDir}/*.conf`,
|
|
223
|
+
`${OPENRESTY_DEFAULT_PATHS.sitesDir}/*.conf`,
|
|
224
|
+
"/etc/openresty/sites-enabled/*.conf"
|
|
341
225
|
];
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
installable: false,
|
|
351
|
-
category: "infrastructure"
|
|
352
|
-
};
|
|
226
|
+
async function scanOpenshipEdge(executor) {
|
|
227
|
+
const cat = `cat ${OUR_EDGE_SITE_GLOBS.join(" ")} 2>/dev/null`;
|
|
228
|
+
const raw = await tryExec(executor, cat);
|
|
229
|
+
if (raw?.trim()) return parseNginxConfig(raw);
|
|
230
|
+
const container = await resolveOurEdgeContainer(executor);
|
|
231
|
+
if (!container) return parseNginxConfig("");
|
|
232
|
+
const fromContainer = await tryExec(executor, containerCommand(container, cat));
|
|
233
|
+
return parseNginxConfig(fromContainer ?? "");
|
|
353
234
|
}
|
|
354
235
|
|
|
355
|
-
// ../../packages/adapters/src/system/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
`exec:abort ${command} (${formatDuration(startedAt)}) ${safeErrorMessage(err)}`
|
|
371
|
-
);
|
|
372
|
-
throw err;
|
|
236
|
+
// ../../packages/adapters/src/system/proxy/import/caddy.ts
|
|
237
|
+
var CADDYFILE_PATHS = ["/etc/caddy/Caddyfile", "/etc/Caddyfile"];
|
|
238
|
+
async function loadCaddyJson(executor) {
|
|
239
|
+
for (const p of CADDYFILE_PATHS) {
|
|
240
|
+
const out = await tryExec(executor, `caddy adapt --adapter caddyfile --config ${p} 2>/dev/null`);
|
|
241
|
+
if (out && out.trim().startsWith("{")) return out;
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
function flattenHandlers(handlers, out = []) {
|
|
246
|
+
for (const h of handlers ?? []) {
|
|
247
|
+
if (h.handler === "subroute") {
|
|
248
|
+
for (const r of h.routes ?? []) flattenHandlers(r.handle, out);
|
|
249
|
+
} else {
|
|
250
|
+
out.push(h);
|
|
373
251
|
}
|
|
374
|
-
const msg = safeErrorMessage(err);
|
|
375
|
-
systemDebug(
|
|
376
|
-
"checks",
|
|
377
|
-
`exec:fail ${command} (${formatDuration(startedAt)}) ${msg}`
|
|
378
|
-
);
|
|
379
|
-
return null;
|
|
380
252
|
}
|
|
253
|
+
return out;
|
|
381
254
|
}
|
|
382
|
-
function
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
installed: true,
|
|
390
|
-
version,
|
|
391
|
-
running,
|
|
392
|
-
healthy: running !== void 0 ? running : true,
|
|
393
|
-
message: running ? `${name} ${version} - running` : `${name} ${version} - installed`
|
|
394
|
-
};
|
|
255
|
+
function targetFromRoute(route) {
|
|
256
|
+
const flat = flattenHandlers(route.handle);
|
|
257
|
+
const dial = flat.find((h) => h.handler === "reverse_proxy")?.upstreams?.find((u) => u.dial)?.dial;
|
|
258
|
+
if (dial) return { kind: "proxy", url: /^https?:\/\//.test(dial) ? dial : `http://${dial}` };
|
|
259
|
+
const root = flat.find((h) => h.handler === "vars" && typeof h.root === "string")?.root;
|
|
260
|
+
if (root && flat.some((h) => h.handler === "file_server")) return { kind: "static", root };
|
|
261
|
+
return null;
|
|
395
262
|
}
|
|
396
|
-
function
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
installable: component.installable,
|
|
403
|
-
installed: !!opts?.version,
|
|
404
|
-
version: opts?.version,
|
|
405
|
-
running: opts?.running,
|
|
406
|
-
healthy: false,
|
|
407
|
-
message
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
async function checkDocker(executor) {
|
|
411
|
-
const startedAt = Date.now();
|
|
412
|
-
const recipe = systemCatalog.checks.docker;
|
|
413
|
-
const version = await tryExec2(executor, recipe.versionCommand);
|
|
414
|
-
if (!version) {
|
|
415
|
-
systemDebug("checks", `docker:missing (${formatDuration(startedAt)})`);
|
|
416
|
-
return unhealthy("docker", recipe.missingMessage);
|
|
263
|
+
function parseCaddyJson(raw) {
|
|
264
|
+
let cfg;
|
|
265
|
+
try {
|
|
266
|
+
cfg = JSON.parse(raw);
|
|
267
|
+
} catch {
|
|
268
|
+
return null;
|
|
417
269
|
}
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
270
|
+
const servers = cfg.apps?.http?.servers;
|
|
271
|
+
if (!servers) return null;
|
|
272
|
+
const sites = [];
|
|
273
|
+
for (const srv of Object.values(servers)) {
|
|
274
|
+
const ssl = (srv.listen ?? []).some((l) => l.endsWith(":443"));
|
|
275
|
+
for (const route of srv.routes ?? []) {
|
|
276
|
+
const hosts = (route.match ?? []).flatMap((m) => m.host ?? []).filter((h) => h && h !== "*");
|
|
277
|
+
if (hosts.length === 0) continue;
|
|
278
|
+
const target = targetFromRoute(route);
|
|
279
|
+
if (!target) continue;
|
|
280
|
+
sites.push({ serverNames: hosts, ssl, target, source: "caddy (adapt)" });
|
|
281
|
+
}
|
|
426
282
|
}
|
|
427
|
-
|
|
428
|
-
return healthy("docker", parsed, true);
|
|
283
|
+
return { sites, warnings: [] };
|
|
429
284
|
}
|
|
430
|
-
async function
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
if (!version) {
|
|
435
|
-
systemDebug("checks", `git:missing (${formatDuration(startedAt)})`);
|
|
436
|
-
return unhealthy("git", recipe.missingMessage);
|
|
285
|
+
async function loadCaddyfile(executor) {
|
|
286
|
+
for (const p of CADDYFILE_PATHS) {
|
|
287
|
+
const out = await tryExec(executor, `cat ${p} 2>/dev/null`);
|
|
288
|
+
if (out && out.trim()) return out;
|
|
437
289
|
}
|
|
438
|
-
|
|
439
|
-
systemDebug("checks", `git:healthy (${formatDuration(startedAt)})`);
|
|
440
|
-
return healthy("git", parsed);
|
|
290
|
+
return "";
|
|
441
291
|
}
|
|
442
|
-
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
292
|
+
function caddyBlocks(text) {
|
|
293
|
+
const out = [];
|
|
294
|
+
let i = 0;
|
|
295
|
+
let headerStart = 0;
|
|
296
|
+
while (i < text.length) {
|
|
297
|
+
if (text[i] === "{") {
|
|
298
|
+
const header = text.slice(headerStart, i).trim();
|
|
299
|
+
let depth = 1;
|
|
300
|
+
let j = i + 1;
|
|
301
|
+
for (; j < text.length && depth > 0; j++) {
|
|
302
|
+
if (text[j] === "{") depth++;
|
|
303
|
+
else if (text[j] === "}") depth--;
|
|
304
|
+
}
|
|
305
|
+
if (depth !== 0) break;
|
|
306
|
+
out.push({ header, body: text.slice(i + 1, j - 1) });
|
|
307
|
+
i = j;
|
|
308
|
+
headerStart = j;
|
|
309
|
+
} else {
|
|
310
|
+
i++;
|
|
311
|
+
}
|
|
449
312
|
}
|
|
450
|
-
|
|
451
|
-
systemDebug("checks", `rsync:healthy (${formatDuration(startedAt)})`);
|
|
452
|
-
return healthy("rsync", parsed);
|
|
313
|
+
return out;
|
|
453
314
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
315
|
+
function parseAddresses(header) {
|
|
316
|
+
return header.split(/[\s,]+/).filter(Boolean).map((addr) => {
|
|
317
|
+
const httpScheme = /^http:\/\//i.test(addr);
|
|
318
|
+
const host = addr.replace(/^https?:\/\//i, "").replace(/:\d+$/, "");
|
|
319
|
+
const isPort80 = /:80$/.test(addr);
|
|
320
|
+
return { host, ssl: !httpScheme && !isPort80 };
|
|
321
|
+
}).filter((a) => a.host && !a.host.startsWith(":") && a.host !== "*");
|
|
322
|
+
}
|
|
323
|
+
async function scanCaddy(executor) {
|
|
324
|
+
const json = await loadCaddyJson(executor);
|
|
325
|
+
if (json) {
|
|
326
|
+
const parsed = parseCaddyJson(json);
|
|
327
|
+
if (parsed && parsed.sites.length > 0) {
|
|
328
|
+
return { proxy: "caddy", sites: parsed.sites, warnings: parsed.warnings };
|
|
329
|
+
}
|
|
461
330
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
);
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
331
|
+
return scanCaddyText(executor);
|
|
332
|
+
}
|
|
333
|
+
async function scanCaddyText(executor) {
|
|
334
|
+
const raw = await loadCaddyfile(executor);
|
|
335
|
+
const warnings = [];
|
|
336
|
+
const sites = [];
|
|
337
|
+
if (!raw.trim()) {
|
|
338
|
+
return { proxy: "caddy", sites, warnings: ["caddy: no readable Caddyfile found"] };
|
|
339
|
+
}
|
|
340
|
+
const text = stripComments(raw);
|
|
341
|
+
let blocks = caddyBlocks(text);
|
|
342
|
+
if (blocks.length === 0) {
|
|
343
|
+
const lines = text.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
344
|
+
if (lines.length > 0) {
|
|
345
|
+
blocks = [{ header: lines[0], body: lines.slice(1).join("\n") }];
|
|
346
|
+
} else {
|
|
347
|
+
warnings.push("caddy: config present but no parseable site blocks");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
for (const { header, body } of blocks) {
|
|
351
|
+
if (!header) continue;
|
|
352
|
+
const addrs = parseAddresses(header);
|
|
353
|
+
if (addrs.length === 0) {
|
|
354
|
+
warnings.push(`caddy: skipped a block with no usable address (${header.slice(0, 40)})`);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
const proxyMatch = body.match(/(?:^|\s)reverse_proxy\s+([^\n{]+)/);
|
|
358
|
+
const rootMatch = body.match(/(?:^|\s)root\s+\*?\s*([^\n\s]+)/);
|
|
359
|
+
const tlsMatch = body.match(/(?:^|\s)tls\s+(\S+)\s+(\S+)/);
|
|
360
|
+
let target;
|
|
361
|
+
if (proxyMatch) {
|
|
362
|
+
const upstream = proxyMatch[1].trim().split(/\s+/)[0];
|
|
363
|
+
target = { kind: "proxy", url: /^https?:\/\//.test(upstream) ? upstream : `http://${upstream}` };
|
|
364
|
+
} else if (rootMatch) {
|
|
365
|
+
target = { kind: "static", root: rootMatch[1] };
|
|
366
|
+
} else {
|
|
367
|
+
warnings.push(`caddy: ${addrs[0].host} has no reverse_proxy or root \u2014 skipped`);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const site = {
|
|
371
|
+
serverNames: addrs.map((a) => a.host),
|
|
372
|
+
ssl: addrs.some((a) => a.ssl),
|
|
373
|
+
target,
|
|
374
|
+
source: "caddy"
|
|
375
|
+
};
|
|
376
|
+
if (tlsMatch && tlsMatch[1].includes("/")) {
|
|
377
|
+
site.tls = { certPath: tlsMatch[1], keyPath: tlsMatch[2] };
|
|
378
|
+
}
|
|
379
|
+
sites.push(site);
|
|
473
380
|
}
|
|
474
|
-
|
|
381
|
+
return { proxy: "caddy", sites, warnings };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// ../../packages/adapters/src/system/proxy/import/apache.ts
|
|
385
|
+
async function vhostFilesFromDump(executor) {
|
|
386
|
+
const dump = await tryExec(
|
|
475
387
|
executor,
|
|
476
|
-
|
|
388
|
+
"apachectl -S 2>/dev/null || apache2ctl -S 2>/dev/null || httpd -S 2>/dev/null"
|
|
477
389
|
);
|
|
478
|
-
if (!
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
{ version: parsed, running: true }
|
|
484
|
-
);
|
|
390
|
+
if (!dump) return [];
|
|
391
|
+
const files = /* @__PURE__ */ new Set();
|
|
392
|
+
for (const m of dump.matchAll(/\(([^()]+?):\d+\)/g)) {
|
|
393
|
+
const f = m[1].trim();
|
|
394
|
+
if (f.startsWith("/")) files.add(f);
|
|
485
395
|
}
|
|
486
|
-
|
|
487
|
-
return healthy("openresty", parsed, true);
|
|
396
|
+
return [...files];
|
|
488
397
|
}
|
|
489
|
-
async function
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
systemDebug("checks", `certbot:missing (${formatDuration(startedAt)})`);
|
|
495
|
-
return unhealthy("certbot", recipe.missingMessage);
|
|
398
|
+
async function loadApacheConfig(executor) {
|
|
399
|
+
const files = await vhostFilesFromDump(executor);
|
|
400
|
+
if (files.length > 0) {
|
|
401
|
+
const cat2 = await tryExec(executor, `cat ${files.map(sq3).join(" ")} 2>/dev/null`);
|
|
402
|
+
if (cat2 && cat2.trim()) return cat2;
|
|
496
403
|
}
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
var COMPONENT_CHECKS = {
|
|
502
|
-
docker: checkDocker,
|
|
503
|
-
openresty: checkOpenResty,
|
|
504
|
-
certbot: checkCertbot,
|
|
505
|
-
git: checkGit,
|
|
506
|
-
rsync: checkRsync
|
|
507
|
-
};
|
|
508
|
-
async function mapWithConcurrency(items, limit, fn) {
|
|
509
|
-
const results = new Array(items.length);
|
|
510
|
-
let cursor = 0;
|
|
511
|
-
const worker = async () => {
|
|
512
|
-
while (cursor < items.length) {
|
|
513
|
-
const index = cursor++;
|
|
514
|
-
results[index] = await fn(items[index]);
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
await Promise.all(
|
|
518
|
-
Array.from({ length: Math.min(limit, items.length) }, worker)
|
|
404
|
+
const cat = await tryExec(
|
|
405
|
+
executor,
|
|
406
|
+
"cat /etc/apache2/sites-enabled/*.conf /etc/apache2/apache2.conf /etc/httpd/conf.d/*.conf /etc/httpd/conf/httpd.conf 2>/dev/null"
|
|
519
407
|
);
|
|
520
|
-
return
|
|
408
|
+
return cat ?? "";
|
|
521
409
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
);
|
|
530
|
-
const results = await mapWithConcurrency(
|
|
531
|
-
entries,
|
|
532
|
-
CHECK_CONCURRENCY,
|
|
533
|
-
([, fn]) => fn(executor)
|
|
410
|
+
function directive(body, name) {
|
|
411
|
+
const m = body.match(new RegExp(`(?:^|\\n)\\s*${name}\\s+([^\\n]+)`, "i"));
|
|
412
|
+
return m?.[1]?.trim();
|
|
413
|
+
}
|
|
414
|
+
function directiveAll(body, name) {
|
|
415
|
+
return [...body.matchAll(new RegExp(`(?:^|\\n)\\s*${name}\\s+([^\\n]+)`, "gi"))].map(
|
|
416
|
+
(m) => m[1].trim()
|
|
534
417
|
);
|
|
535
|
-
await enrichAvailable(executor, results);
|
|
536
|
-
systemDebug("checks", `checkAll:done (${formatDuration(startedAt)})`);
|
|
537
|
-
return results;
|
|
538
418
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
419
|
+
function parseVhost(body, portHint) {
|
|
420
|
+
const serverName = directive(body, "ServerName")?.split(/\s+/)[0];
|
|
421
|
+
const aliases = directiveAll(body, "ServerAlias").flatMap((line) => line.split(/\s+/));
|
|
422
|
+
const names = [serverName, ...aliases].filter((n) => Boolean(n));
|
|
423
|
+
if (names.length === 0) {
|
|
424
|
+
return { warning: "apache: skipped a VirtualHost with no ServerName" };
|
|
425
|
+
}
|
|
426
|
+
const routes = [...body.matchAll(/(?:^|\n)\s*ProxyPass\s+(\S+)\s+(\S+)/gi)].map((m) => ({ path: m[1], url: m[2] })).filter((p) => p.url && p.url !== "!");
|
|
427
|
+
const docRoot = directive(body, "DocumentRoot")?.replace(/^["']|["']$/g, "");
|
|
428
|
+
const certPath = directive(body, "SSLCertificateFile");
|
|
429
|
+
const keyPath = directive(body, "SSLCertificateKeyFile");
|
|
430
|
+
const ssl = /:443/.test(portHint) || /SSLEngine\s+on/i.test(body) || Boolean(certPath);
|
|
431
|
+
let target;
|
|
432
|
+
if (routes.length > 0) {
|
|
433
|
+
const primary = routes.find((r) => r.path === "/") ?? routes[0];
|
|
434
|
+
target = { kind: "proxy", url: primary.url };
|
|
435
|
+
} else if (docRoot) {
|
|
436
|
+
target = { kind: "static", root: docRoot };
|
|
437
|
+
} else {
|
|
438
|
+
return { warning: `apache: ${names[0]} has neither ProxyPass nor DocumentRoot \u2014 skipped` };
|
|
544
439
|
}
|
|
440
|
+
const site = { serverNames: names, ssl, target, source: "apache" };
|
|
441
|
+
if (routes.length > 0) site.routes = routes;
|
|
442
|
+
if (certPath && keyPath) site.tls = { certPath, keyPath };
|
|
443
|
+
return site;
|
|
545
444
|
}
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
)
|
|
560
|
-
|
|
445
|
+
function vhostBlocks(text) {
|
|
446
|
+
const out = [];
|
|
447
|
+
const re = /<VirtualHost([^>]*)>([\s\S]*?)<\/VirtualHost>/gi;
|
|
448
|
+
let m;
|
|
449
|
+
while ((m = re.exec(text)) !== null) {
|
|
450
|
+
out.push({ args: m[1].trim(), body: m[2] });
|
|
451
|
+
}
|
|
452
|
+
return out;
|
|
453
|
+
}
|
|
454
|
+
async function scanApache(executor) {
|
|
455
|
+
const raw = await loadApacheConfig(executor);
|
|
456
|
+
const warnings = [];
|
|
457
|
+
const sites = [];
|
|
458
|
+
if (!raw.trim()) {
|
|
459
|
+
return { proxy: "apache", sites, warnings: ["apache: no readable configuration found"] };
|
|
460
|
+
}
|
|
461
|
+
const text = stripComments(raw);
|
|
462
|
+
const blocks = vhostBlocks(text);
|
|
463
|
+
if (blocks.length === 0) warnings.push("apache: no <VirtualHost> blocks found");
|
|
464
|
+
for (const { args, body } of blocks) {
|
|
465
|
+
const parsed = parseVhost(body, args);
|
|
466
|
+
if ("warning" in parsed) warnings.push(parsed.warning);
|
|
467
|
+
else sites.push(parsed);
|
|
468
|
+
}
|
|
469
|
+
return { proxy: "apache", sites, warnings };
|
|
561
470
|
}
|
|
562
471
|
|
|
563
|
-
// ../../packages/adapters/src/system/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
472
|
+
// ../../packages/adapters/src/system/proxy/import/traefik.ts
|
|
473
|
+
function extractHosts(rule) {
|
|
474
|
+
const hosts = [];
|
|
475
|
+
for (const call of rule.matchAll(/\bHost\(([^)]*)\)/gi)) {
|
|
476
|
+
for (const m of call[1].matchAll(/[`'"]([^`'"]+)[`'"]/g)) {
|
|
477
|
+
const h = m[1].trim();
|
|
478
|
+
if (h) hosts.push(h);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return hosts;
|
|
567
482
|
}
|
|
568
|
-
function
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
483
|
+
function extraMatchers(rule) {
|
|
484
|
+
const found = /* @__PURE__ */ new Set();
|
|
485
|
+
for (const m of rule.matchAll(
|
|
486
|
+
/\b(PathPrefix|PathRegexp|Path|HeadersRegexp|Headers|Method|Query|ClientIP|HostRegexp)\b/gi
|
|
487
|
+
)) {
|
|
488
|
+
found.add(m[1]);
|
|
489
|
+
}
|
|
490
|
+
return [...found];
|
|
572
491
|
}
|
|
573
|
-
function
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
492
|
+
function parseTraefikLabels(containers) {
|
|
493
|
+
const sites = [];
|
|
494
|
+
const warnings = [];
|
|
495
|
+
for (const c of containers) {
|
|
496
|
+
if (c.labels["traefik.enable"] === "false") continue;
|
|
497
|
+
const routers = /* @__PURE__ */ new Map();
|
|
498
|
+
const servicePorts = /* @__PURE__ */ new Map();
|
|
499
|
+
for (const [key, val] of Object.entries(c.labels)) {
|
|
500
|
+
const r = key.match(/^traefik\.http\.routers\.([^.]+)\.(.+)$/);
|
|
501
|
+
if (r) {
|
|
502
|
+
const bag = routers.get(r[1]) ?? {};
|
|
503
|
+
bag[r[2]] = val;
|
|
504
|
+
routers.set(r[1], bag);
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
const s = key.match(/^traefik\.http\.services\.([^.]+)\.loadbalancer\.server\.port$/);
|
|
508
|
+
if (s) servicePorts.set(s[1], val);
|
|
590
509
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
510
|
+
for (const [rname, props] of routers) {
|
|
511
|
+
const rule = props.rule;
|
|
512
|
+
if (!rule) continue;
|
|
513
|
+
const hosts = extractHosts(rule);
|
|
514
|
+
if (hosts.length === 0) {
|
|
515
|
+
warnings.push(
|
|
516
|
+
/HostRegexp/i.test(rule) ? `traefik: router "${rname}" uses HostRegexp (${rule}) \u2014 regex hosts aren't migratable` : `traefik: router "${rname}" has no Host() rule (${rule}) \u2014 skipped`
|
|
517
|
+
);
|
|
518
|
+
continue;
|
|
596
519
|
}
|
|
597
|
-
|
|
598
|
-
|
|
520
|
+
if (!c.ip) {
|
|
521
|
+
warnings.push(
|
|
522
|
+
`traefik: ${hosts.join(", ")} \u2014 couldn't resolve container ${c.name}'s IP; re-add the upstream manually`
|
|
523
|
+
);
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
const svc = props.service;
|
|
527
|
+
const rawPort = (svc && servicePorts.get(svc)) ?? (servicePorts.size === 1 ? [...servicePorts.values()][0] : void 0) ?? "80";
|
|
528
|
+
const port = /^\d{1,5}$/.test(String(rawPort)) ? String(rawPort) : "80";
|
|
529
|
+
const url = `http://${c.ip}:${port}`;
|
|
530
|
+
const extras = extraMatchers(rule);
|
|
531
|
+
if (extras.length > 0) {
|
|
532
|
+
warnings.push(
|
|
533
|
+
`traefik: ${hosts.join(", ")} also matches ${extras.join(", ")} \u2014 only the Host() part is migrated; re-add path/header rules manually`
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
if (props.middlewares) {
|
|
537
|
+
warnings.push(`traefik: ${hosts.join(", ")} uses middleware(s) "${props.middlewares}" \u2014 not migrated`);
|
|
538
|
+
}
|
|
539
|
+
const ssl = Object.keys(props).some((p) => p === "tls" || p.startsWith("tls."));
|
|
540
|
+
sites.push({
|
|
541
|
+
serverNames: hosts,
|
|
542
|
+
ssl,
|
|
543
|
+
target: { kind: "proxy", url },
|
|
544
|
+
source: `traefik container ${c.name}`
|
|
545
|
+
});
|
|
599
546
|
}
|
|
600
|
-
}
|
|
547
|
+
}
|
|
548
|
+
return { proxy: "traefik", sites, warnings };
|
|
601
549
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
409,
|
|
610
|
-
"EDGE_CONFLICT"
|
|
611
|
-
);
|
|
612
|
-
this.status = status;
|
|
613
|
-
this.name = "EdgeConflictError";
|
|
550
|
+
async function scanTraefik(executor) {
|
|
551
|
+
const out = await tryExec(
|
|
552
|
+
executor,
|
|
553
|
+
"docker ps -q 2>/dev/null | xargs -r docker inspect --format '{{.Name}} {{json .Config.Labels}} {{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' 2>/dev/null"
|
|
554
|
+
);
|
|
555
|
+
if (!out) {
|
|
556
|
+
return { proxy: "traefik", sites: [], warnings: ["traefik: couldn't read container labels via docker inspect"] };
|
|
614
557
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
558
|
+
const containers = [];
|
|
559
|
+
for (const line of out.split("\n")) {
|
|
560
|
+
const [rawName, rawLabels, rawIps] = line.split(" ");
|
|
561
|
+
if (!rawName || !rawLabels) continue;
|
|
562
|
+
let labels;
|
|
563
|
+
try {
|
|
564
|
+
labels = JSON.parse(rawLabels) ?? {};
|
|
565
|
+
} catch {
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (!Object.keys(labels).some((k) => k.startsWith("traefik."))) continue;
|
|
569
|
+
const ip = (rawIps ?? "").trim().split(/\s+/)[0] || void 0;
|
|
570
|
+
containers.push({ name: rawName.replace(/^\//, ""), labels, ip });
|
|
623
571
|
}
|
|
624
|
-
|
|
625
|
-
|
|
572
|
+
return parseTraefikLabels(containers);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// ../../packages/adapters/src/system/proxy/import/index.ts
|
|
576
|
+
var INSTALLED_MARKERS = [
|
|
577
|
+
{ proxy: "nginx", paths: ["/etc/nginx/nginx.conf"] },
|
|
578
|
+
{ proxy: "caddy", paths: ["/etc/caddy/Caddyfile"] },
|
|
579
|
+
{ proxy: "apache", paths: ["/etc/apache2/apache2.conf", "/etc/httpd/conf/httpd.conf"] },
|
|
580
|
+
{
|
|
581
|
+
proxy: "openresty",
|
|
582
|
+
paths: ["/usr/local/openresty/nginx/conf/nginx.conf", "/etc/openresty/nginx.conf"]
|
|
583
|
+
}
|
|
584
|
+
];
|
|
585
|
+
async function detectInstalledProxy(executor) {
|
|
586
|
+
const probe = INSTALLED_MARKERS.map(({ proxy, paths }) => {
|
|
587
|
+
const test = paths.map((p) => `[ -f '${p}' ]`).join(" || ");
|
|
588
|
+
return `{ ${test}; } && echo ${proxy}`;
|
|
589
|
+
}).join("; ");
|
|
590
|
+
let out = "";
|
|
626
591
|
try {
|
|
627
|
-
|
|
592
|
+
out = await executor.exec(`{ ${probe}; } 2>/dev/null; true`, { timeout: 1e4 });
|
|
628
593
|
} catch {
|
|
629
594
|
return null;
|
|
630
595
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (!text) return void 0;
|
|
634
|
-
const t = text.toLowerCase();
|
|
635
|
-
if (t.includes("openresty")) return "openresty";
|
|
636
|
-
if (/(^|[\s/:])nginx/.test(t)) return "nginx";
|
|
637
|
-
if (/(^|[\s/:])caddy/.test(t)) return "caddy";
|
|
638
|
-
if (/(apache2|httpd)/.test(t)) return "apache";
|
|
639
|
-
if (/(^|[\s/:])traefik/.test(t)) return "traefik";
|
|
640
|
-
if (/(^|[\s/:])haproxy/.test(t)) return "haproxy";
|
|
641
|
-
return void 0;
|
|
642
|
-
}
|
|
643
|
-
function sq2(value) {
|
|
644
|
-
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
645
|
-
}
|
|
646
|
-
function isOurEdgeContainer(name, image) {
|
|
647
|
-
return /openship-edge/i.test(`${name ?? ""} ${image ?? ""}`);
|
|
648
|
-
}
|
|
649
|
-
async function ourEdgeContainerRunning(executor) {
|
|
650
|
-
const byName = await tryExec3(
|
|
651
|
-
executor,
|
|
652
|
-
`docker ps --filter name=openship-edge --format '{{.Names}}' 2>/dev/null | head -1`
|
|
653
|
-
);
|
|
654
|
-
if (byName && byName.trim()) return true;
|
|
655
|
-
const all = await tryExec3(executor, `docker ps --format '{{.Names}} {{.Image}}' 2>/dev/null`);
|
|
656
|
-
if (!all) return false;
|
|
657
|
-
return all.split("\n").map((line) => line.trim()).filter(Boolean).some((line) => {
|
|
658
|
-
const [name, image] = line.split(" ");
|
|
659
|
-
return isOurEdgeContainer(name, image);
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
async function ourLuaOnHost(executor) {
|
|
663
|
-
const lua = await tryExec3(
|
|
664
|
-
executor,
|
|
665
|
-
`test -f ${OPENRESTY_LUA_DIR}/site_logger.lua && echo ok`
|
|
596
|
+
const found = new Set(
|
|
597
|
+
out.split("\n").map((l) => l.trim()).filter(Boolean)
|
|
666
598
|
);
|
|
667
|
-
return
|
|
599
|
+
return INSTALLED_MARKERS.find((m) => found.has(m.proxy))?.proxy ?? null;
|
|
668
600
|
}
|
|
669
|
-
async function
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
var WORKER_RE = /\b(?:nginx|openresty)\s*:\s*worker process/i;
|
|
690
|
-
var MASTER_RE = /\b(?:nginx|openresty)\s*:\s*master process/i;
|
|
691
|
-
async function resolveProxyMaster(executor, listener) {
|
|
692
|
-
if (!listener?.pid) return listener;
|
|
693
|
-
if (!WORKER_RE.test(`${listener.rawCommand ?? ""} ${listener.command ?? ""}`)) return listener;
|
|
694
|
-
const ppidRaw = await tryExec3(
|
|
695
|
-
executor,
|
|
696
|
-
`awk '/^PPid:/{print $2}' /proc/${listener.pid}/status 2>/dev/null || true`
|
|
697
|
-
);
|
|
698
|
-
const ppid = Number.parseInt((ppidRaw ?? "").trim(), 10);
|
|
699
|
-
if (!Number.isInteger(ppid) || ppid <= 1) return listener;
|
|
700
|
-
const master = await describeProcess(executor, ppid);
|
|
701
|
-
if (!master || !MASTER_RE.test(`${master.rawCommand ?? ""} ${master.command ?? ""}`)) {
|
|
702
|
-
return listener;
|
|
703
|
-
}
|
|
704
|
-
return master;
|
|
705
|
-
}
|
|
706
|
-
async function probeEdgePort(executor, port, ours) {
|
|
707
|
-
const listener = await resolveProxyMaster(executor, await probeListeningPort(executor, port));
|
|
708
|
-
const docker = await detectDockerOnPort(executor, port);
|
|
709
|
-
if (!listener && !docker) return null;
|
|
710
|
-
const proxy = classifyProxy(
|
|
711
|
-
[
|
|
712
|
-
docker?.image,
|
|
713
|
-
docker?.name,
|
|
714
|
-
listener?.rawCommand,
|
|
715
|
-
listener?.command,
|
|
716
|
-
listener?.systemdUnit
|
|
717
|
-
].filter(Boolean).join(" ")
|
|
718
|
-
);
|
|
719
|
-
const foreignDockerProxy = Boolean(docker) && !isOurEdgeContainer(docker?.name, docker?.image);
|
|
720
|
-
const managedByOpenship = isOurEdgeContainer(docker?.name, docker?.image) || ours.containerRunning && !foreignDockerProxy || !docker && ours.luaOnHost && await listenerIsOurOpenResty(executor, listener);
|
|
721
|
-
return {
|
|
722
|
-
port,
|
|
723
|
-
pid: listener?.pid ?? void 0,
|
|
724
|
-
command: docker ? `docker container ${docker.name} (${docker.image})` : listener?.command,
|
|
725
|
-
rawCommand: listener?.rawCommand,
|
|
726
|
-
systemdUnit: listener?.systemdUnit,
|
|
727
|
-
systemdDescription: listener?.systemdDescription,
|
|
728
|
-
isDocker: Boolean(docker),
|
|
729
|
-
containerName: docker?.name,
|
|
730
|
-
proxy,
|
|
731
|
-
managedByOpenship
|
|
732
|
-
};
|
|
601
|
+
async function scanImportableSites(executor, proxy) {
|
|
602
|
+
switch (proxy) {
|
|
603
|
+
case "nginx":
|
|
604
|
+
return scanNginx(executor);
|
|
605
|
+
case "caddy":
|
|
606
|
+
return scanCaddy(executor);
|
|
607
|
+
case "apache":
|
|
608
|
+
return scanApache(executor);
|
|
609
|
+
case "traefik":
|
|
610
|
+
return scanTraefik(executor);
|
|
611
|
+
case "openresty":
|
|
612
|
+
return scanOpenshipEdge(executor);
|
|
613
|
+
default:
|
|
614
|
+
return {
|
|
615
|
+
proxy,
|
|
616
|
+
sites: [],
|
|
617
|
+
warnings: [`${proxy}: config import not supported \u2014 takeover only`]
|
|
618
|
+
};
|
|
619
|
+
}
|
|
733
620
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const luaOnHost = await ourLuaOnHost(executor);
|
|
737
|
-
const all = [];
|
|
738
|
-
for (const port of EDGE_PORTS) {
|
|
739
|
-
const occ = await probeEdgePort(executor, port, { containerRunning, luaOnHost });
|
|
740
|
-
if (occ) all.push(occ);
|
|
741
|
-
}
|
|
742
|
-
const foreign = all.filter((o) => !o.managedByOpenship);
|
|
743
|
-
let classification;
|
|
744
|
-
if (all.length === 0) classification = "free";
|
|
745
|
-
else if (foreign.length === 0) classification = "ours";
|
|
746
|
-
else if (foreign.every((o) => o.proxy && o.proxy !== "openresty")) classification = "known";
|
|
747
|
-
else classification = "unknown";
|
|
748
|
-
return {
|
|
749
|
-
classification,
|
|
750
|
-
occupants: foreign,
|
|
751
|
-
canProceedClean: classification === "free" || classification === "ours"
|
|
752
|
-
};
|
|
621
|
+
function canImportProxy(proxy) {
|
|
622
|
+
return proxy === "nginx" || proxy === "caddy" || proxy === "apache" || proxy === "traefik" || proxy === "openresty";
|
|
753
623
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
624
|
+
|
|
625
|
+
// ../../packages/adapters/src/system/proxy/import/caddy-certs.ts
|
|
626
|
+
var CADDY_DATA_ROOTS = [
|
|
627
|
+
"/var/lib/caddy/.local/share/caddy",
|
|
628
|
+
"/root/.local/share/caddy",
|
|
629
|
+
"/home/caddy/.local/share/caddy",
|
|
630
|
+
"/data/caddy"
|
|
631
|
+
];
|
|
632
|
+
function candidateNames(host) {
|
|
633
|
+
const names = [host];
|
|
634
|
+
const dot = host.indexOf(".");
|
|
635
|
+
if (dot > 0) names.push(`wildcard_${host.slice(dot)}`);
|
|
636
|
+
return names;
|
|
637
|
+
}
|
|
638
|
+
async function findPairIn(exec, root, host, container) {
|
|
639
|
+
for (const name of candidateNames(host)) {
|
|
640
|
+
const glob = `${root}/certificates/*/${name}/${name}.crt`;
|
|
641
|
+
let certPath = firstCrt(await tryExec(exec, `ls -1 ${glob} 2>/dev/null`));
|
|
642
|
+
if (!certPath && container) {
|
|
643
|
+
certPath = firstCrt(
|
|
644
|
+
await tryExec(exec, containerCommand(container, `ls -1 ${glob} 2>/dev/null`))
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
if (certPath) return { certPath, keyPath: certPath.replace(/\.crt$/, ".key") };
|
|
770
648
|
}
|
|
771
|
-
return
|
|
649
|
+
return null;
|
|
772
650
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
`systemctl disable --now ${sq2(t.unit)} 2>/dev/null || systemctl stop ${sq2(t.unit)} 2>/dev/null || true; systemctl reset-failed ${sq2(t.unit)} 2>/dev/null || true`
|
|
785
|
-
);
|
|
786
|
-
} else if (t.pid) {
|
|
787
|
-
onLog(`Stopping ${t.label ?? `process ${t.pid}`}${where}...`, "warn");
|
|
788
|
-
await tryExec3(executor, `kill ${t.pid} 2>/dev/null || true`);
|
|
789
|
-
await new Promise((r) => setTimeout(r, 800));
|
|
790
|
-
await tryExec3(executor, `kill -9 ${t.pid} 2>/dev/null || true`);
|
|
651
|
+
function firstCrt(listing) {
|
|
652
|
+
return (listing ?? "").split("\n").map((l) => l.trim()).find((l) => l.endsWith(".crt"));
|
|
653
|
+
}
|
|
654
|
+
async function caddyStoreCert(exec, host, container) {
|
|
655
|
+
for (const root of CADDY_DATA_ROOTS) {
|
|
656
|
+
const pair = await findPairIn(exec, root, host, container);
|
|
657
|
+
if (!pair) continue;
|
|
658
|
+
const certPem = await readMaybeInContainer(exec, pair.certPath, container);
|
|
659
|
+
const keyPem = await readMaybeInContainer(exec, pair.keyPath, container);
|
|
660
|
+
if (certPem.trim() && keyPem.trim()) {
|
|
661
|
+
return { certPem, keyPem, source: `caddy store ${pair.certPath}` };
|
|
791
662
|
}
|
|
792
663
|
}
|
|
793
|
-
|
|
664
|
+
return null;
|
|
794
665
|
}
|
|
795
666
|
|
|
796
|
-
// ../../packages/adapters/src/system/proxy/import/
|
|
797
|
-
|
|
667
|
+
// ../../packages/adapters/src/system/proxy/import/traefik-certs.ts
|
|
668
|
+
var DEFAULT_ACME_PATHS = ["/acme.json", "/etc/traefik/acme.json", "/data/acme.json", "/letsencrypt/acme.json"];
|
|
669
|
+
var TRAEFIK_STATIC_CONFIGS = [
|
|
670
|
+
"/etc/traefik/traefik.yml",
|
|
671
|
+
"/etc/traefik/traefik.yaml",
|
|
672
|
+
"/etc/traefik/traefik.toml"
|
|
673
|
+
];
|
|
674
|
+
function prop(obj, name) {
|
|
675
|
+
const hit = Object.keys(obj).find((k) => k.toLowerCase() === name.toLowerCase());
|
|
676
|
+
return hit === void 0 ? void 0 : obj[hit];
|
|
677
|
+
}
|
|
678
|
+
async function candidateStoragePaths(exec, container) {
|
|
679
|
+
const found = [];
|
|
680
|
+
const collect = (text) => {
|
|
681
|
+
for (const m of (text ?? "").matchAll(/acme\.storage[=:\s]+["']?(\/[^\s"',}]+)/gi)) {
|
|
682
|
+
if (isSafeCertPath(m[1])) found.push(m[1]);
|
|
683
|
+
}
|
|
684
|
+
for (const m of (text ?? "").matchAll(/(?:^|\s)storage:\s*["']?(\/[^\s"',}]+\.json)/gi)) {
|
|
685
|
+
if (isSafeCertPath(m[1])) found.push(m[1]);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
if (container) {
|
|
689
|
+
collect(
|
|
690
|
+
await tryExec(
|
|
691
|
+
exec,
|
|
692
|
+
`docker inspect ${sq2(container)} --format '{{json .Config.Cmd}} {{json .Args}} {{json .Config.Env}}' 2>/dev/null`
|
|
693
|
+
)
|
|
694
|
+
);
|
|
695
|
+
for (const cfg of TRAEFIK_STATIC_CONFIGS) {
|
|
696
|
+
collect(await readMaybeInContainer(exec, cfg, container));
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return [.../* @__PURE__ */ new Set([...found, ...DEFAULT_ACME_PATHS])];
|
|
700
|
+
}
|
|
701
|
+
async function loadAcmeJson(exec, container) {
|
|
702
|
+
for (const path of await candidateStoragePaths(exec, container)) {
|
|
703
|
+
const raw = await readMaybeInContainer(exec, path, container);
|
|
704
|
+
if (raw.trim().startsWith("{")) return { raw, path };
|
|
705
|
+
}
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
function certFromAcmeJson(raw, host) {
|
|
709
|
+
let parsed;
|
|
798
710
|
try {
|
|
799
|
-
|
|
711
|
+
parsed = JSON.parse(raw);
|
|
800
712
|
} catch {
|
|
801
713
|
return null;
|
|
802
714
|
}
|
|
715
|
+
const target = host.toLowerCase();
|
|
716
|
+
const matches = (name) => {
|
|
717
|
+
const n = (name ?? "").toLowerCase();
|
|
718
|
+
if (!n) return false;
|
|
719
|
+
if (n === target) return true;
|
|
720
|
+
if (!n.startsWith("*.")) return false;
|
|
721
|
+
const suffix = n.slice(1);
|
|
722
|
+
return target.endsWith(suffix) && !target.slice(0, -suffix.length).includes(".");
|
|
723
|
+
};
|
|
724
|
+
for (const [resolver, value] of Object.entries(parsed)) {
|
|
725
|
+
if (!value || typeof value !== "object") continue;
|
|
726
|
+
const certs = prop(value, "certificates");
|
|
727
|
+
if (!Array.isArray(certs)) continue;
|
|
728
|
+
for (const entry of certs) {
|
|
729
|
+
const domain = entry && prop(entry, "domain");
|
|
730
|
+
const names = [domain?.main, ...domain?.sans ?? []];
|
|
731
|
+
if (!names.some(matches)) continue;
|
|
732
|
+
const certB64 = prop(entry, "certificate");
|
|
733
|
+
const keyB64 = prop(entry, "key");
|
|
734
|
+
if (typeof certB64 !== "string" || typeof keyB64 !== "string") continue;
|
|
735
|
+
const certPem = Buffer.from(certB64, "base64").toString("utf-8");
|
|
736
|
+
const keyPem = Buffer.from(keyB64, "base64").toString("utf-8");
|
|
737
|
+
if (!certPem.includes("-----BEGIN") || !keyPem.includes("-----BEGIN")) continue;
|
|
738
|
+
return { certPem, keyPem, resolver };
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return null;
|
|
803
742
|
}
|
|
804
|
-
function
|
|
805
|
-
|
|
743
|
+
async function traefikAcmeCert(exec, host, container) {
|
|
744
|
+
const loaded = await loadAcmeJson(exec, container);
|
|
745
|
+
if (!loaded) return null;
|
|
746
|
+
const hit = certFromAcmeJson(loaded.raw, host);
|
|
747
|
+
if (!hit) return null;
|
|
748
|
+
return {
|
|
749
|
+
certPem: hit.certPem,
|
|
750
|
+
keyPem: hit.keyPem,
|
|
751
|
+
source: `traefik ${loaded.path} (resolver ${hit.resolver})`
|
|
752
|
+
};
|
|
806
753
|
}
|
|
807
|
-
function
|
|
808
|
-
const
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
const
|
|
813
|
-
|
|
814
|
-
let i =
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
}
|
|
819
|
-
if (depth === 0) {
|
|
820
|
-
blocks.push(text.slice(openIdx + 1, i - 1));
|
|
821
|
-
re.lastIndex = i;
|
|
822
|
-
} else {
|
|
823
|
-
break;
|
|
754
|
+
async function traefikDeclaredCertPaths(exec, container) {
|
|
755
|
+
const pairs = [];
|
|
756
|
+
for (const cfg of TRAEFIK_STATIC_CONFIGS) {
|
|
757
|
+
const text = await readMaybeInContainer(exec, cfg, container);
|
|
758
|
+
if (!text.trim()) continue;
|
|
759
|
+
const certFiles = [...text.matchAll(/certFile:\s*["']?(\/[^\s"',}]+)/gi)].map((m) => m[1]);
|
|
760
|
+
const keyFiles = [...text.matchAll(/keyFile:\s*["']?(\/[^\s"',}]+)/gi)].map((m) => m[1]);
|
|
761
|
+
for (let i = 0; i < Math.min(certFiles.length, keyFiles.length); i++) {
|
|
762
|
+
if (isSafeCertPath(certFiles[i]) && isSafeCertPath(keyFiles[i])) {
|
|
763
|
+
pairs.push({ certPath: certFiles[i], keyPath: keyFiles[i] });
|
|
764
|
+
}
|
|
824
765
|
}
|
|
825
766
|
}
|
|
826
|
-
return
|
|
827
|
-
}
|
|
828
|
-
function sq3(value) {
|
|
829
|
-
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
767
|
+
return pairs;
|
|
830
768
|
}
|
|
831
769
|
|
|
832
|
-
// ../../packages/adapters/src/system/proxy/
|
|
833
|
-
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
if (upstreams.has(host)) return { url: `${scheme}${upstreams.get(host)}` };
|
|
867
|
-
const isIp = /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
|
|
868
|
-
if (isIp || host === "localhost" || host.includes(".")) return { url: raw };
|
|
869
|
-
return { reason: `proxy_pass host "${host}" is an undeclared upstream \u2014 not migratable` };
|
|
870
|
-
}
|
|
871
|
-
function extractLocationProxies(serverBody) {
|
|
872
|
-
const out = [];
|
|
873
|
-
const re = /(?:^|[\s;}])location\s+([^{]+?)\s*\{/g;
|
|
874
|
-
let m;
|
|
875
|
-
while ((m = re.exec(serverBody)) !== null) {
|
|
876
|
-
const path = m[1].trim();
|
|
877
|
-
const openIdx = m.index + m[0].length - 1;
|
|
878
|
-
let depth = 1;
|
|
879
|
-
let i = openIdx + 1;
|
|
880
|
-
for (; i < serverBody.length && depth > 0; i++) {
|
|
881
|
-
if (serverBody[i] === "{") depth++;
|
|
882
|
-
else if (serverBody[i] === "}") depth--;
|
|
770
|
+
// ../../packages/adapters/src/system/proxy/api.ts
|
|
771
|
+
function buildProxyRouteIndex(sites) {
|
|
772
|
+
const byPort = /* @__PURE__ */ new Map();
|
|
773
|
+
for (const site of sites) {
|
|
774
|
+
const upstreams = site.routes ?? (site.target.kind === "proxy" ? [{ path: "/", url: site.target.url }] : []);
|
|
775
|
+
for (const up of upstreams) {
|
|
776
|
+
let port;
|
|
777
|
+
try {
|
|
778
|
+
port = Number(new URL(up.url).port);
|
|
779
|
+
} catch {
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
if (!Number.isFinite(port) || port <= 0) continue;
|
|
783
|
+
const list = byPort.get(port) ?? [];
|
|
784
|
+
const existing = list.find((r) => r.path === up.path);
|
|
785
|
+
if (existing) {
|
|
786
|
+
existing.domains = [.../* @__PURE__ */ new Set([...existing.domains, ...site.serverNames])];
|
|
787
|
+
if (site.ssl) {
|
|
788
|
+
existing.ssl.enabled = true;
|
|
789
|
+
if (!existing.ssl.certPath && site.tls) {
|
|
790
|
+
existing.ssl.certPath = site.tls.certPath;
|
|
791
|
+
existing.ssl.keyPath = site.tls.keyPath;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
} else {
|
|
795
|
+
list.push({
|
|
796
|
+
port,
|
|
797
|
+
path: up.path,
|
|
798
|
+
domains: [...site.serverNames],
|
|
799
|
+
ssl: site.ssl ? { enabled: true, certPath: site.tls?.certPath, keyPath: site.tls?.keyPath } : { enabled: false },
|
|
800
|
+
source: site.source
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
byPort.set(port, list);
|
|
883
804
|
}
|
|
884
|
-
if (depth !== 0) break;
|
|
885
|
-
const locBody = serverBody.slice(openIdx + 1, i - 1);
|
|
886
|
-
re.lastIndex = i;
|
|
887
|
-
const pp = firstDirective(locBody, "proxy_pass");
|
|
888
|
-
if (pp) out.push({ path, proxyPass: pp });
|
|
889
|
-
}
|
|
890
|
-
return out;
|
|
891
|
-
}
|
|
892
|
-
function isHttpsUpgradeForSelf(body, names) {
|
|
893
|
-
const targets = [
|
|
894
|
-
...body.matchAll(/(?:^|[\s;{])return\s+30[1-8]\s+([^;]+);/g),
|
|
895
|
-
...body.matchAll(/(?:^|[\s;{])rewrite\s+\S+\s+([^;]+?)\s+permanent\s*;/g)
|
|
896
|
-
].map((m) => m[1].trim());
|
|
897
|
-
if (targets.length === 0) return false;
|
|
898
|
-
return targets.every((raw) => {
|
|
899
|
-
if (!/^https:\/\//i.test(raw)) return false;
|
|
900
|
-
const authority = raw.replace(/^https:\/\//i, "").split(/[/\s]/)[0] ?? "";
|
|
901
|
-
const host = (authority.match(/^(\$[a-z_]+|[^$:]+)/i)?.[1] ?? "").replace(/:\d+$/, "");
|
|
902
|
-
if (host === "$host" || host === "$server_name" || host === "$http_host") return true;
|
|
903
|
-
return names.includes(host);
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
function parseServer(body, source, upstreams) {
|
|
907
|
-
const warnings = [];
|
|
908
|
-
const names = firstDirective(body, "server_name")?.split(/\s+/).filter((n) => n && n !== "_" && !n.startsWith("~")) ?? [];
|
|
909
|
-
const listens = [...body.matchAll(/(?:^|[;{\s])listen\s+([^;]+);/g)].map((m) => m[1]);
|
|
910
|
-
const ssl = listens.some((l) => /\bssl\b/.test(l) || /\b443\b/.test(l));
|
|
911
|
-
const root = firstDirective(body, "root");
|
|
912
|
-
const certPath = firstDirective(body, "ssl_certificate");
|
|
913
|
-
const keyPath = firstDirective(body, "ssl_certificate_key");
|
|
914
|
-
if (names.length === 0) return { warnings: [] };
|
|
915
|
-
const rawTargets = extractLocationProxies(body);
|
|
916
|
-
if (rawTargets.length === 0) {
|
|
917
|
-
const serverLevel = firstDirective(body, "proxy_pass");
|
|
918
|
-
if (serverLevel) rawTargets.push({ path: "/", proxyPass: serverLevel });
|
|
919
|
-
}
|
|
920
|
-
const resolved = [];
|
|
921
|
-
for (const t of rawTargets) {
|
|
922
|
-
const r = resolveProxyTarget(t.proxyPass, upstreams);
|
|
923
|
-
if ("reason" in r) warnings.push(`nginx: ${names[0]} ${t.path} \u2014 ${r.reason} (skipped)`);
|
|
924
|
-
else resolved.push({ path: t.path, url: r.url });
|
|
925
|
-
}
|
|
926
|
-
let target;
|
|
927
|
-
let routes;
|
|
928
|
-
if (resolved.length > 0) {
|
|
929
|
-
const primary = resolved.find((r) => r.path === "/") ?? resolved[0];
|
|
930
|
-
target = { kind: "proxy", url: primary.url };
|
|
931
|
-
routes = resolved;
|
|
932
|
-
} else if (root) {
|
|
933
|
-
target = { kind: "static", root: root.replace(/;$/, "") };
|
|
934
|
-
} else if (isHttpsUpgradeForSelf(body, names)) {
|
|
935
|
-
return { warnings: [] };
|
|
936
|
-
} else {
|
|
937
|
-
warnings.push(`nginx: ${names[0]} has neither proxy_pass nor root \u2014 skipped (${source})`);
|
|
938
|
-
return { warnings };
|
|
939
805
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
806
|
+
return byPort;
|
|
807
|
+
}
|
|
808
|
+
async function declaredCert(ctx) {
|
|
809
|
+
const tls = ctx.site?.tls;
|
|
810
|
+
if (!tls) return null;
|
|
811
|
+
const pems = await readDeclaredPair(ctx.exec, tls.certPath, tls.keyPath, ctx.container);
|
|
812
|
+
return pems ? { ...pems, source: tls.certPath } : null;
|
|
813
|
+
}
|
|
814
|
+
var CERT_SOURCES = {
|
|
815
|
+
nginx: [declaredCert],
|
|
816
|
+
openresty: [declaredCert],
|
|
817
|
+
apache: [declaredCert],
|
|
818
|
+
caddy: [declaredCert, (c) => caddyStoreCert(c.exec, c.host, c.container)],
|
|
819
|
+
traefik: [
|
|
820
|
+
(c) => traefikAcmeCert(c.exec, c.host, c.container),
|
|
821
|
+
// File provider: paths aren't bound to a hostname (traefik picks by SNI), so
|
|
822
|
+
// hand every declared pair to the validator and let coverage decide.
|
|
823
|
+
async (c) => {
|
|
824
|
+
for (const pair of await traefikDeclaredCertPaths(c.exec, c.container)) {
|
|
825
|
+
const pems = await readDeclaredPair(c.exec, pair.certPath, pair.keyPath, c.container);
|
|
826
|
+
if (!pems) continue;
|
|
827
|
+
if (validateCertFor(c.host, pems, pair.certPath).cert) {
|
|
828
|
+
return { ...pems, source: pair.certPath };
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
],
|
|
834
|
+
// Takeover-only: no importable config, so no cert to find either.
|
|
835
|
+
haproxy: []
|
|
836
|
+
};
|
|
837
|
+
async function edgeProxy(exec, opts = {}) {
|
|
838
|
+
const status = opts.status ?? await probeEdge(exec).catch(() => null);
|
|
839
|
+
if (!status) return null;
|
|
840
|
+
let kind = null;
|
|
841
|
+
let ours = false;
|
|
842
|
+
if (status.classification === "ours") {
|
|
843
|
+
kind = "openresty";
|
|
844
|
+
ours = true;
|
|
845
|
+
} else if (status.classification === "known") {
|
|
846
|
+
const found = status.occupants.find((o) => o.proxy)?.proxy;
|
|
847
|
+
kind = found && canImportProxy(found) ? found : null;
|
|
848
|
+
}
|
|
849
|
+
if (!kind) kind = await detectInstalledProxy(exec).catch(() => null);
|
|
850
|
+
if (!kind) return null;
|
|
851
|
+
const container = status.occupants.find((o) => o.proxy === kind)?.containerName ?? null;
|
|
852
|
+
return makeApi(exec, kind, ours, container);
|
|
853
|
+
}
|
|
854
|
+
function edgeProxyFor(exec, kind, opts = {}) {
|
|
855
|
+
return makeApi(exec, kind, opts.ours ?? kind === "openresty", opts.container ?? null);
|
|
856
|
+
}
|
|
857
|
+
async function collectProxyCerts(api, sites) {
|
|
858
|
+
const certPems = {};
|
|
946
859
|
const warnings = [];
|
|
947
|
-
const
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
warnings.push("nginx: no server blocks found");
|
|
956
|
-
}
|
|
957
|
-
for (const body of blocks) {
|
|
958
|
-
const { site, warnings: blockWarnings } = parseServer(body, "nginx", upstreams);
|
|
959
|
-
warnings.push(...blockWarnings);
|
|
960
|
-
if (site) sites.push(site);
|
|
860
|
+
const hosts = [...new Set(sites.filter((s) => s.ssl).flatMap((s) => s.serverNames))];
|
|
861
|
+
for (const host of hosts) {
|
|
862
|
+
const candidate = await api.certCandidateFor(host).catch(() => null);
|
|
863
|
+
if (candidate?.cert) {
|
|
864
|
+
certPems[host] = { certPem: candidate.cert.certPem, keyPem: candidate.cert.keyPem };
|
|
865
|
+
} else if (candidate?.reason) {
|
|
866
|
+
warnings.push(`${host}: no reusable certificate \u2014 ${candidate.reason}`);
|
|
867
|
+
}
|
|
961
868
|
}
|
|
962
|
-
return {
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
869
|
+
return { certPems, warnings };
|
|
870
|
+
}
|
|
871
|
+
function makeApi(exec, kind, ours, container) {
|
|
872
|
+
let scan = null;
|
|
873
|
+
const listSites = () => {
|
|
874
|
+
scan ??= (ours ? scanOpenshipEdge(exec) : scanImportableSites(exec, kind)).catch(() => ({
|
|
875
|
+
proxy: kind,
|
|
876
|
+
sites: [],
|
|
877
|
+
warnings: [`${kind}: config scan failed`]
|
|
878
|
+
}));
|
|
879
|
+
return scan;
|
|
880
|
+
};
|
|
881
|
+
const siteFor = async (host) => {
|
|
882
|
+
const target = host.toLowerCase();
|
|
883
|
+
const { sites } = await listSites();
|
|
884
|
+
return sites.find((s) => s.serverNames.some((n) => n.toLowerCase() === target)) ?? // A wildcard vhost (`*.example.com`) serves the host without naming it.
|
|
885
|
+
sites.find(
|
|
886
|
+
(s) => s.serverNames.some((n) => {
|
|
887
|
+
const name = n.toLowerCase();
|
|
888
|
+
if (!name.startsWith("*.")) return false;
|
|
889
|
+
const suffix = name.slice(1);
|
|
890
|
+
return target.endsWith(suffix) && !target.slice(0, -suffix.length).includes(".");
|
|
891
|
+
})
|
|
892
|
+
) ?? null;
|
|
893
|
+
};
|
|
894
|
+
const certCandidateFor = async (host) => {
|
|
895
|
+
const site = await siteFor(host);
|
|
896
|
+
const ctx = { exec, host, site, container };
|
|
897
|
+
let lastReason = null;
|
|
898
|
+
for (const source of CERT_SOURCES[kind] ?? []) {
|
|
899
|
+
const raw = await source(ctx).catch(() => null);
|
|
900
|
+
if (!raw) continue;
|
|
901
|
+
const candidate = validateCertFor(host, raw, raw.source);
|
|
902
|
+
if (candidate.cert) return candidate;
|
|
903
|
+
lastReason = candidate.reason;
|
|
904
|
+
}
|
|
905
|
+
return { cert: null, reason: lastReason ?? `${kind}: no certificate found for ${host}` };
|
|
906
|
+
};
|
|
907
|
+
return {
|
|
908
|
+
kind,
|
|
909
|
+
ours,
|
|
910
|
+
container,
|
|
911
|
+
listSites,
|
|
912
|
+
sitesByPort: async () => buildProxyRouteIndex((await listSites()).sites),
|
|
913
|
+
siteFor,
|
|
914
|
+
certFor: async (host) => (await certCandidateFor(host)).cert,
|
|
915
|
+
certCandidateFor
|
|
916
|
+
};
|
|
966
917
|
}
|
|
967
918
|
|
|
968
|
-
// ../../packages/adapters/src/system/proxy/
|
|
969
|
-
var
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
919
|
+
// ../../packages/adapters/src/system/proxy/takeover-journal.ts
|
|
920
|
+
var JOURNAL_DIR = "/var/lib/openship";
|
|
921
|
+
var JOURNAL_PATH = `${JOURNAL_DIR}/edge-takeover.json`;
|
|
922
|
+
function log(message, level = "info") {
|
|
923
|
+
return { timestamp: (/* @__PURE__ */ new Date()).toISOString(), message, level };
|
|
924
|
+
}
|
|
925
|
+
async function tryExec2(executor, cmd) {
|
|
926
|
+
try {
|
|
927
|
+
return await executor.exec(cmd);
|
|
928
|
+
} catch {
|
|
929
|
+
return null;
|
|
974
930
|
}
|
|
975
|
-
return null;
|
|
976
931
|
}
|
|
977
|
-
function
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
932
|
+
async function buildJournal(executor, status) {
|
|
933
|
+
const units = /* @__PURE__ */ new Map();
|
|
934
|
+
const containers = /* @__PURE__ */ new Map();
|
|
935
|
+
const processes = /* @__PURE__ */ new Map();
|
|
936
|
+
for (const o of status.occupants) {
|
|
937
|
+
if (o.containerName && !containers.has(o.containerName)) {
|
|
938
|
+
const r = await tryExec2(
|
|
939
|
+
executor,
|
|
940
|
+
`docker inspect -f '{{.HostConfig.RestartPolicy.Name}}' ${sq2(o.containerName)} 2>/dev/null`
|
|
941
|
+
);
|
|
942
|
+
containers.set(o.containerName, { name: o.containerName, restart: r?.trim() || "no" });
|
|
943
|
+
} else if (o.systemdUnit && !units.has(o.systemdUnit)) {
|
|
944
|
+
const en = await tryExec2(executor, `systemctl is-enabled ${sq2(o.systemdUnit)} 2>/dev/null`);
|
|
945
|
+
units.set(o.systemdUnit, { unit: o.systemdUnit, wasEnabled: en?.trim() === "enabled" });
|
|
946
|
+
} else if (!o.containerName && !o.systemdUnit && o.pid && !processes.has(o.pid)) {
|
|
947
|
+
processes.set(o.pid, { pid: o.pid, command: o.rawCommand });
|
|
983
948
|
}
|
|
984
949
|
}
|
|
985
|
-
return
|
|
950
|
+
return {
|
|
951
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
952
|
+
units: [...units.values()],
|
|
953
|
+
containers: [...containers.values()],
|
|
954
|
+
processes: [...processes.values()]
|
|
955
|
+
};
|
|
986
956
|
}
|
|
987
|
-
function
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
return null;
|
|
957
|
+
async function writeJournal(executor, journal) {
|
|
958
|
+
try {
|
|
959
|
+
await executor.mkdir(JOURNAL_DIR);
|
|
960
|
+
await executor.writeFile(JOURNAL_PATH, JSON.stringify(journal, null, 2));
|
|
961
|
+
} catch {
|
|
962
|
+
}
|
|
994
963
|
}
|
|
995
|
-
function
|
|
996
|
-
|
|
964
|
+
async function clearJournal(executor) {
|
|
965
|
+
await tryExec2(executor, `rm -f ${JOURNAL_PATH}`);
|
|
966
|
+
}
|
|
967
|
+
async function readJournal(executor) {
|
|
968
|
+
const raw = await tryExec2(executor, `cat ${JOURNAL_PATH} 2>/dev/null`);
|
|
969
|
+
if (!raw?.trim()) return null;
|
|
997
970
|
try {
|
|
998
|
-
|
|
971
|
+
return JSON.parse(raw);
|
|
999
972
|
} catch {
|
|
973
|
+
await clearJournal(executor);
|
|
1000
974
|
return null;
|
|
1001
975
|
}
|
|
1002
|
-
const servers = cfg.apps?.http?.servers;
|
|
1003
|
-
if (!servers) return null;
|
|
1004
|
-
const sites = [];
|
|
1005
|
-
for (const srv of Object.values(servers)) {
|
|
1006
|
-
const ssl = (srv.listen ?? []).some((l) => l.endsWith(":443"));
|
|
1007
|
-
for (const route of srv.routes ?? []) {
|
|
1008
|
-
const hosts = (route.match ?? []).flatMap((m) => m.host ?? []).filter((h) => h && h !== "*");
|
|
1009
|
-
if (hosts.length === 0) continue;
|
|
1010
|
-
const target = targetFromRoute(route);
|
|
1011
|
-
if (!target) continue;
|
|
1012
|
-
sites.push({ serverNames: hosts, ssl, target, source: "caddy (adapt)" });
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
return { sites, warnings: [] };
|
|
1016
976
|
}
|
|
1017
|
-
async function
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
977
|
+
async function rollback(executor, journal, onLog) {
|
|
978
|
+
onLog(log("Rolling back \u2014 restoring the previous proxy...", "warn"));
|
|
979
|
+
await tryExec2(
|
|
980
|
+
executor,
|
|
981
|
+
"systemctl disable --now openresty 2>/dev/null || systemctl stop openresty 2>/dev/null || true; systemctl reset-failed openresty 2>/dev/null || true"
|
|
982
|
+
);
|
|
983
|
+
for (const u of journal.units) {
|
|
984
|
+
await tryExec2(
|
|
985
|
+
executor,
|
|
986
|
+
u.wasEnabled ? `systemctl enable --now ${sq2(u.unit)} 2>/dev/null || true` : `systemctl start ${sq2(u.unit)} 2>/dev/null || true`
|
|
987
|
+
);
|
|
1021
988
|
}
|
|
1022
|
-
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
let j = i + 1;
|
|
1033
|
-
for (; j < text.length && depth > 0; j++) {
|
|
1034
|
-
if (text[j] === "{") depth++;
|
|
1035
|
-
else if (text[j] === "}") depth--;
|
|
1036
|
-
}
|
|
1037
|
-
if (depth !== 0) break;
|
|
1038
|
-
out.push({ header, body: text.slice(i + 1, j - 1) });
|
|
1039
|
-
i = j;
|
|
1040
|
-
headerStart = j;
|
|
989
|
+
for (const c of journal.containers) {
|
|
990
|
+
await tryExec2(executor, `docker update --restart=${sq2(c.restart)} ${sq2(c.name)} 2>/dev/null || true`);
|
|
991
|
+
await tryExec2(executor, `docker start ${sq2(c.name)} 2>/dev/null || true`);
|
|
992
|
+
}
|
|
993
|
+
for (const p of journal.processes ?? []) {
|
|
994
|
+
if (p.command) {
|
|
995
|
+
await tryExec2(
|
|
996
|
+
executor,
|
|
997
|
+
`setsid -f sh -c ${sq2(p.command)} 2>/dev/null || (nohup sh -c ${sq2(p.command)} >/dev/null 2>&1 &) || true`
|
|
998
|
+
);
|
|
1041
999
|
} else {
|
|
1042
|
-
|
|
1000
|
+
onLog(log(`Could not restore process ${p.pid} \u2014 no command captured.`, "warn"));
|
|
1043
1001
|
}
|
|
1044
1002
|
}
|
|
1045
|
-
return out;
|
|
1046
1003
|
}
|
|
1047
|
-
function
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
const host = addr.replace(/^https?:\/\//i, "").replace(/:\d+$/, "");
|
|
1051
|
-
const isPort80 = /:80$/.test(addr);
|
|
1052
|
-
return { host, ssl: !httpScheme && !isPort80 };
|
|
1053
|
-
}).filter((a) => a.host && !a.host.startsWith(":") && a.host !== "*");
|
|
1004
|
+
async function beginEdgeTakeover(executor, status, onLog) {
|
|
1005
|
+
await writeJournal(executor, await buildJournal(executor, status));
|
|
1006
|
+
await freeEdgeTargets(executor, stopTargetsForStatus(status), (m, l) => onLog(log(m, l)));
|
|
1054
1007
|
}
|
|
1055
|
-
async function
|
|
1056
|
-
const
|
|
1057
|
-
if (
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
return scanCaddyText(executor);
|
|
1008
|
+
async function rollbackEdgeTakeover(executor, onLog) {
|
|
1009
|
+
const journal = await readJournal(executor);
|
|
1010
|
+
if (!journal || journal.completed) return false;
|
|
1011
|
+
await rollback(executor, journal, onLog);
|
|
1012
|
+
await clearJournal(executor);
|
|
1013
|
+
return true;
|
|
1064
1014
|
}
|
|
1065
|
-
async function
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
return { proxy: "caddy", sites, warnings: ["caddy: no readable Caddyfile found"] };
|
|
1015
|
+
async function completeEdgeTakeover(executor) {
|
|
1016
|
+
const journal = await readJournal(executor);
|
|
1017
|
+
if (journal) {
|
|
1018
|
+
journal.completed = true;
|
|
1019
|
+
await writeJournal(executor, journal);
|
|
1071
1020
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1021
|
+
await clearJournal(executor);
|
|
1022
|
+
}
|
|
1023
|
+
async function recoverInterruptedTakeover(executor, onLog, isEdgeHealthy) {
|
|
1024
|
+
const journal = await readJournal(executor);
|
|
1025
|
+
if (!journal) return;
|
|
1026
|
+
if (journal.completed) {
|
|
1027
|
+
await clearJournal(executor);
|
|
1028
|
+
return;
|
|
1081
1029
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
warnings.push(`caddy: skipped a block with no usable address (${header.slice(0, 40)})`);
|
|
1087
|
-
continue;
|
|
1088
|
-
}
|
|
1089
|
-
const proxyMatch = body.match(/(?:^|\s)reverse_proxy\s+([^\n{]+)/);
|
|
1090
|
-
const rootMatch = body.match(/(?:^|\s)root\s+\*?\s*([^\n\s]+)/);
|
|
1091
|
-
const tlsMatch = body.match(/(?:^|\s)tls\s+(\S+)\s+(\S+)/);
|
|
1092
|
-
let target;
|
|
1093
|
-
if (proxyMatch) {
|
|
1094
|
-
const upstream = proxyMatch[1].trim().split(/\s+/)[0];
|
|
1095
|
-
target = { kind: "proxy", url: /^https?:\/\//.test(upstream) ? upstream : `http://${upstream}` };
|
|
1096
|
-
} else if (rootMatch) {
|
|
1097
|
-
target = { kind: "static", root: rootMatch[1] };
|
|
1098
|
-
} else {
|
|
1099
|
-
warnings.push(`caddy: ${addrs[0].host} has no reverse_proxy or root \u2014 skipped`);
|
|
1100
|
-
continue;
|
|
1101
|
-
}
|
|
1102
|
-
const site = {
|
|
1103
|
-
serverNames: addrs.map((a) => a.host),
|
|
1104
|
-
ssl: addrs.some((a) => a.ssl),
|
|
1105
|
-
target,
|
|
1106
|
-
source: "caddy"
|
|
1107
|
-
};
|
|
1108
|
-
if (tlsMatch && tlsMatch[1].includes("/")) {
|
|
1109
|
-
site.tls = { certPath: tlsMatch[1], keyPath: tlsMatch[2] };
|
|
1110
|
-
}
|
|
1111
|
-
sites.push(site);
|
|
1030
|
+
if (isEdgeHealthy && await isEdgeHealthy()) {
|
|
1031
|
+
onLog(log("Found an unfinished edge takeover, but our edge is serving \u2014 keeping it.", "warn"));
|
|
1032
|
+
await clearJournal(executor);
|
|
1033
|
+
return;
|
|
1112
1034
|
}
|
|
1113
|
-
|
|
1035
|
+
onLog(log("Found an interrupted edge takeover \u2014 restoring the previous proxy.", "warn"));
|
|
1036
|
+
await rollback(executor, journal, onLog);
|
|
1037
|
+
await clearJournal(executor);
|
|
1114
1038
|
}
|
|
1115
1039
|
|
|
1116
|
-
// ../../packages/adapters/src/system/
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
const files = /* @__PURE__ */ new Set();
|
|
1124
|
-
for (const m of dump.matchAll(/\(([^()]+?):\d+\)/g)) {
|
|
1125
|
-
const f = m[1].trim();
|
|
1126
|
-
if (f.startsWith("/")) files.add(f);
|
|
1040
|
+
// ../../packages/adapters/src/system/catalog.ts
|
|
1041
|
+
function dockerInstallPlan(profile) {
|
|
1042
|
+
if (profile.os !== "linux") {
|
|
1043
|
+
return {
|
|
1044
|
+
supported: false,
|
|
1045
|
+
unsupportedReason: "Docker installation is only supported on Linux servers"
|
|
1046
|
+
};
|
|
1127
1047
|
}
|
|
1128
|
-
return
|
|
1048
|
+
return {
|
|
1049
|
+
supported: true,
|
|
1050
|
+
installCommand: "curl -fsSL https://get.docker.com | sh",
|
|
1051
|
+
startCommand: profile.serviceManager === "systemd" ? "systemctl enable docker && systemctl start docker" : void 0,
|
|
1052
|
+
verifyCommand: "docker --version"
|
|
1053
|
+
};
|
|
1129
1054
|
}
|
|
1130
|
-
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1055
|
+
function gitInstallPlan(profile) {
|
|
1056
|
+
const commands = {
|
|
1057
|
+
apt: "apt-get update -qq && apt-get install -y -qq git",
|
|
1058
|
+
dnf: "dnf install -y git",
|
|
1059
|
+
yum: "yum install -y git",
|
|
1060
|
+
apk: "apk add --no-cache git",
|
|
1061
|
+
brew: "brew install git"
|
|
1062
|
+
};
|
|
1063
|
+
const installCommand = commands[profile.packageManager];
|
|
1064
|
+
if (!installCommand) {
|
|
1065
|
+
return {
|
|
1066
|
+
supported: false,
|
|
1067
|
+
unsupportedReason: "No supported package manager found for Git installation"
|
|
1068
|
+
};
|
|
1135
1069
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
}
|
|
1142
|
-
function directive(body, name) {
|
|
1143
|
-
const m = body.match(new RegExp(`(?:^|\\n)\\s*${name}\\s+([^\\n]+)`, "i"));
|
|
1144
|
-
return m?.[1]?.trim();
|
|
1145
|
-
}
|
|
1146
|
-
function directiveAll(body, name) {
|
|
1147
|
-
return [...body.matchAll(new RegExp(`(?:^|\\n)\\s*${name}\\s+([^\\n]+)`, "gi"))].map(
|
|
1148
|
-
(m) => m[1].trim()
|
|
1149
|
-
);
|
|
1070
|
+
return {
|
|
1071
|
+
supported: true,
|
|
1072
|
+
installCommand,
|
|
1073
|
+
verifyCommand: "git --version"
|
|
1074
|
+
};
|
|
1150
1075
|
}
|
|
1151
|
-
function
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
const primary = routes.find((r) => r.path === "/") ?? routes[0];
|
|
1166
|
-
target = { kind: "proxy", url: primary.url };
|
|
1167
|
-
} else if (docRoot) {
|
|
1168
|
-
target = { kind: "static", root: docRoot };
|
|
1169
|
-
} else {
|
|
1170
|
-
return { warning: `apache: ${names[0]} has neither ProxyPass nor DocumentRoot \u2014 skipped` };
|
|
1076
|
+
function rsyncInstallPlan(profile) {
|
|
1077
|
+
const commands = {
|
|
1078
|
+
apt: "apt-get update -qq && apt-get install -y -qq rsync",
|
|
1079
|
+
dnf: "dnf install -y rsync",
|
|
1080
|
+
yum: "yum install -y rsync",
|
|
1081
|
+
apk: "apk add --no-cache rsync",
|
|
1082
|
+
brew: "brew install rsync"
|
|
1083
|
+
};
|
|
1084
|
+
const installCommand = commands[profile.packageManager];
|
|
1085
|
+
if (!installCommand) {
|
|
1086
|
+
return {
|
|
1087
|
+
supported: false,
|
|
1088
|
+
unsupportedReason: "No supported package manager found for rsync installation"
|
|
1089
|
+
};
|
|
1171
1090
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1091
|
+
return {
|
|
1092
|
+
supported: true,
|
|
1093
|
+
installCommand,
|
|
1094
|
+
verifyCommand: "rsync --version | head -n 1"
|
|
1095
|
+
};
|
|
1176
1096
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1097
|
+
var OPENRESTY_APT_SOURCES = [
|
|
1098
|
+
// ARM64: openresty.org publishes aarch64 debs under a SEPARATE path
|
|
1099
|
+
// (openresty.org/package/arm64/<repo>); the default path is amd64-only, so on
|
|
1100
|
+
// aarch64 `apt-get install openresty` finds no candidate and `set -e` aborts
|
|
1101
|
+
// the whole setup (issue #109). Switch the base URL by arch and tag the deb
|
|
1102
|
+
// line with `arch=` so apt fetches the right index. `dpkg --print-architecture`
|
|
1103
|
+
// returns exactly amd64/arm64 (matches OpenResty's path + arch qualifier).
|
|
1104
|
+
'OR_ARCH="$(dpkg --print-architecture 2>/dev/null || echo amd64)"',
|
|
1105
|
+
'if [ "$OR_ARCH" = arm64 ]; then OR_BASE="http://openresty.org/package/arm64/$REPO"; else OR_BASE="http://openresty.org/package/$REPO"; fi',
|
|
1106
|
+
// `|| REPO_CODENAME=""` so a failed substitution (no lsb_release AND no
|
|
1107
|
+
// /etc/os-release, e.g. a stripped container) doesn't trip `set -e` before
|
|
1108
|
+
// the empty-var fallback below can pick a default.
|
|
1109
|
+
'REPO_CODENAME="$(lsb_release -sc 2>/dev/null || { . /etc/os-release 2>/dev/null && echo "$VERSION_CODENAME"; })" || REPO_CODENAME=""',
|
|
1110
|
+
'if [ "$REPO" = debian ]; then OR_FALLBACKS="bookworm bullseye"; else OR_FALLBACKS="noble jammy focal"; fi',
|
|
1111
|
+
'OR_CODENAME=""',
|
|
1112
|
+
"for c in $REPO_CODENAME $OR_FALLBACKS; do",
|
|
1113
|
+
' if wget -q --spider --tries=2 --timeout=15 "$OR_BASE/dists/$c/Release"; then OR_CODENAME="$c"; break; fi',
|
|
1114
|
+
"done",
|
|
1115
|
+
'if [ -z "$OR_CODENAME" ]; then case "$REPO" in debian) OR_CODENAME=bookworm ;; *) OR_CODENAME=noble ;; esac; fi',
|
|
1116
|
+
'[ "$OR_CODENAME" = "$REPO_CODENAME" ] || echo "[openresty] apt repo has no codename $REPO_CODENAME; using nearest supported LTS $OR_CODENAME" >&2',
|
|
1117
|
+
'echo "deb [arch=$OR_ARCH signed-by=/usr/share/keyrings/openresty.gpg] $OR_BASE $OR_CODENAME main" > /etc/apt/sources.list.d/openresty.list'
|
|
1118
|
+
];
|
|
1119
|
+
function openrestyInstallPlan(profile) {
|
|
1120
|
+
if (profile.os !== "linux") {
|
|
1121
|
+
return {
|
|
1122
|
+
supported: false,
|
|
1123
|
+
unsupportedReason: "OpenResty installation is only supported on Linux servers"
|
|
1124
|
+
};
|
|
1183
1125
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1126
|
+
let installCommand;
|
|
1127
|
+
if (profile.packageManager === "apt") {
|
|
1128
|
+
const distro = profile.distro === "debian" ? "debian" : "ubuntu";
|
|
1129
|
+
installCommand = [
|
|
1130
|
+
"set -e",
|
|
1131
|
+
// Heal a stale/bad openresty.list left by a prior run (e.g. the #86
|
|
1132
|
+
// 'resolute' pin) BEFORE the first apt-get update reads it — otherwise
|
|
1133
|
+
// set -e aborts here and the repo never gets rewritten.
|
|
1134
|
+
"rm -f /etc/apt/sources.list.d/openresty.list",
|
|
1135
|
+
"apt-get update -qq && apt-get install -y -qq wget gnupg2 lsb-release",
|
|
1136
|
+
"wget -qO /tmp/openresty-pubkey.gpg https://openresty.org/package/pubkey.gpg",
|
|
1137
|
+
"gpg --yes --dearmor -o /usr/share/keyrings/openresty.gpg /tmp/openresty-pubkey.gpg",
|
|
1138
|
+
`REPO=${distro}`,
|
|
1139
|
+
...OPENRESTY_APT_SOURCES,
|
|
1140
|
+
"apt-get update -qq && apt-get install -y -qq openresty"
|
|
1141
|
+
].join("\n");
|
|
1142
|
+
} else if (profile.packageManager === "dnf") {
|
|
1143
|
+
const distro = profile.distro === "fedora" ? "fedora" : "centos";
|
|
1144
|
+
installCommand = `wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/${distro}/openresty.repo && dnf install -y openresty`;
|
|
1145
|
+
} else if (profile.packageManager === "yum") {
|
|
1146
|
+
installCommand = "wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/centos/openresty.repo && yum install -y openresty";
|
|
1147
|
+
} else if (profile.packageManager === "apk") {
|
|
1148
|
+
installCommand = [
|
|
1149
|
+
"apk add --no-cache wget",
|
|
1150
|
+
"wget -qO /etc/apk/keys/admin@openresty.com-5ea678a6.rsa.pub https://openresty.org/package/alpine/admin@openresty.com-5ea678a6.rsa.pub",
|
|
1151
|
+
`. /etc/os-release && echo "https://openresty.org/package/alpine/v$( echo $VERSION_ID | cut -d. -f1,2 )/main" >> /etc/apk/repositories`,
|
|
1152
|
+
"apk update && apk add openresty"
|
|
1153
|
+
].join(" && ");
|
|
1154
|
+
} else {
|
|
1155
|
+
installCommand = [
|
|
1156
|
+
"set -e",
|
|
1157
|
+
"if command -v apt-get >/dev/null 2>&1; then",
|
|
1158
|
+
" rm -f /etc/apt/sources.list.d/openresty.list",
|
|
1159
|
+
" apt-get update -qq && apt-get install -y -qq wget gnupg2 lsb-release",
|
|
1160
|
+
" wget -qO /tmp/openresty-pubkey.gpg https://openresty.org/package/pubkey.gpg",
|
|
1161
|
+
" gpg --yes --dearmor -o /usr/share/keyrings/openresty.gpg /tmp/openresty-pubkey.gpg",
|
|
1162
|
+
' DISTRO=$(. /etc/os-release 2>/dev/null && echo "$ID" || echo "ubuntu")',
|
|
1163
|
+
' case "$DISTRO" in debian) REPO=debian ;; *) REPO=ubuntu ;; esac',
|
|
1164
|
+
...OPENRESTY_APT_SOURCES.map((l) => " " + l),
|
|
1165
|
+
" apt-get update -qq && apt-get install -y -qq openresty",
|
|
1166
|
+
"elif command -v dnf >/dev/null 2>&1; then",
|
|
1167
|
+
" wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/centos/openresty.repo && dnf install -y openresty",
|
|
1168
|
+
"elif command -v yum >/dev/null 2>&1; then",
|
|
1169
|
+
" wget -qO /etc/yum.repos.d/openresty.repo https://openresty.org/package/centos/openresty.repo && yum install -y openresty",
|
|
1170
|
+
"elif command -v apk >/dev/null 2>&1; then",
|
|
1171
|
+
" apk add --no-cache wget \\",
|
|
1172
|
+
" && wget -qO /etc/apk/keys/admin@openresty.com-5ea678a6.rsa.pub https://openresty.org/package/alpine/admin@openresty.com-5ea678a6.rsa.pub \\",
|
|
1173
|
+
' && . /etc/os-release && echo "https://openresty.org/package/alpine/v$(echo $VERSION_ID | cut -d. -f1,2)/main" >> /etc/apk/repositories \\',
|
|
1174
|
+
" && apk update && apk add openresty",
|
|
1175
|
+
"else",
|
|
1176
|
+
' echo "No supported package manager found (tried apt-get, dnf, yum, apk)" >&2 && exit 1',
|
|
1177
|
+
"fi"
|
|
1178
|
+
].join("\n");
|
|
1192
1179
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1180
|
+
return {
|
|
1181
|
+
supported: true,
|
|
1182
|
+
installCommand,
|
|
1183
|
+
startCommand: profile.serviceManager === "systemd" ? "systemctl enable openresty && systemctl start openresty" : void 0,
|
|
1184
|
+
verifyCommand: "openresty -v 2>&1"
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
function certbotInstallPlan(profile) {
|
|
1188
|
+
const commands = {
|
|
1189
|
+
apt: "apt-get update -qq && apt-get install -y -qq certbot",
|
|
1190
|
+
dnf: "dnf install -y certbot",
|
|
1191
|
+
yum: "yum install -y certbot",
|
|
1192
|
+
apk: "apk add --no-cache certbot"
|
|
1193
|
+
};
|
|
1194
|
+
const installCommand = commands[profile.packageManager];
|
|
1195
|
+
if (!installCommand) {
|
|
1196
|
+
return {
|
|
1197
|
+
supported: false,
|
|
1198
|
+
unsupportedReason: "Certbot installation is only supported on Linux with apt, dnf, or yum"
|
|
1199
|
+
};
|
|
1200
1200
|
}
|
|
1201
|
-
return {
|
|
1201
|
+
return {
|
|
1202
|
+
supported: true,
|
|
1203
|
+
installCommand,
|
|
1204
|
+
verifyCommand: "certbot --version 2>/dev/null"
|
|
1205
|
+
};
|
|
1202
1206
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1207
|
+
var systemCatalog = {
|
|
1208
|
+
checks: {
|
|
1209
|
+
docker: {
|
|
1210
|
+
versionCommand: "docker --version",
|
|
1211
|
+
daemonCommand: "docker info --format '{{.ServerVersion}}'",
|
|
1212
|
+
parseVersion: (output) => output.match(/Docker version ([^\s,]+)/)?.[1] ?? output,
|
|
1213
|
+
missingMessage: "Docker is not installed",
|
|
1214
|
+
notRunningMessage: "Docker is installed but the daemon is not running"
|
|
1215
|
+
},
|
|
1216
|
+
openresty: {
|
|
1217
|
+
versionCommand: "openresty -v 2>&1 || /usr/local/openresty/bin/openresty -v 2>&1",
|
|
1218
|
+
runningCommands: [
|
|
1219
|
+
"pgrep -f 'nginx.*openresty' || pgrep -f '/usr/local/openresty'"
|
|
1220
|
+
],
|
|
1221
|
+
parseVersion: (output) => output.match(/openresty\/(\S+)/)?.[1] ?? output.match(/nginx\/(\S+)/)?.[1] ?? output,
|
|
1222
|
+
missingMessage: "OpenResty is not installed",
|
|
1223
|
+
notRunningMessage: "OpenResty is installed but not running"
|
|
1224
|
+
},
|
|
1225
|
+
certbot: {
|
|
1226
|
+
versionCommand: "certbot --version 2>/dev/null",
|
|
1227
|
+
parseVersion: (output) => output.match(/certbot\s+(\S+)/)?.[1] ?? output,
|
|
1228
|
+
missingMessage: "Certbot is not installed"
|
|
1229
|
+
},
|
|
1230
|
+
git: {
|
|
1231
|
+
versionCommand: "git --version",
|
|
1232
|
+
parseVersion: (output) => output.match(/git version (\S+)/)?.[1] ?? output,
|
|
1233
|
+
missingMessage: "Git is not installed"
|
|
1234
|
+
},
|
|
1235
|
+
rsync: {
|
|
1236
|
+
versionCommand: "rsync --version | head -n 1",
|
|
1237
|
+
parseVersion: (output) => output.match(/rsync\s+version\s+(\S+)/i)?.[1] ?? output,
|
|
1238
|
+
missingMessage: "rsync is not installed"
|
|
1211
1239
|
}
|
|
1240
|
+
},
|
|
1241
|
+
installs: {
|
|
1242
|
+
docker: dockerInstallPlan,
|
|
1243
|
+
git: gitInstallPlan,
|
|
1244
|
+
rsync: rsyncInstallPlan,
|
|
1245
|
+
openresty: openrestyInstallPlan,
|
|
1246
|
+
certbot: certbotInstallPlan
|
|
1212
1247
|
}
|
|
1213
|
-
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
// ../../packages/adapters/src/system/elevated-executor.ts
|
|
1251
|
+
var INSTALL_ENV = "DEBIAN_FRONTEND=noninteractive DPKG_FORCE=confnew";
|
|
1252
|
+
function elevateCommand(command) {
|
|
1253
|
+
return `sudo -n sh -c ${sq(`export ${INSTALL_ENV}; ${command}`)}`;
|
|
1214
1254
|
}
|
|
1215
|
-
function
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
)) {
|
|
1220
|
-
found.add(m[1]);
|
|
1221
|
-
}
|
|
1222
|
-
return [...found];
|
|
1255
|
+
function dirOf(path) {
|
|
1256
|
+
const idx = path.lastIndexOf("/");
|
|
1257
|
+
if (idx < 0) return ".";
|
|
1258
|
+
return idx === 0 ? "/" : path.slice(0, idx);
|
|
1223
1259
|
}
|
|
1224
|
-
function
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1260
|
+
function elevatedExecutor(inner) {
|
|
1261
|
+
const writeFileElevated = async (path, content) => {
|
|
1262
|
+
const tmp = `/tmp/.openship-elev-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
1263
|
+
await inner.writeFile(tmp, content);
|
|
1264
|
+
await inner.exec(
|
|
1265
|
+
elevateCommand(`mkdir -p ${sq(dirOf(path))} && mv -f ${sq(tmp)} ${sq(path)}`)
|
|
1266
|
+
);
|
|
1267
|
+
};
|
|
1268
|
+
const overrides = {
|
|
1269
|
+
exec: (command, opts) => inner.exec(elevateCommand(command), opts),
|
|
1270
|
+
streamExec: (command, onLog) => inner.streamExec(elevateCommand(command), onLog),
|
|
1271
|
+
writeFile: writeFileElevated,
|
|
1272
|
+
// Elevated for the same reason as writeFile: the vhost/conf dirs are root-owned,
|
|
1273
|
+
// and the Proxy would otherwise forward this to the inner executor unelevated —
|
|
1274
|
+
// EACCES immediately after an elevated write succeeded.
|
|
1275
|
+
rename: async (from, to) => {
|
|
1276
|
+
await inner.exec(elevateCommand(`mv -f ${sq(from)} ${sq(to)}`));
|
|
1277
|
+
},
|
|
1278
|
+
mkdir: async (path) => {
|
|
1279
|
+
await inner.exec(elevateCommand(`mkdir -p ${sq(path)}`));
|
|
1280
|
+
},
|
|
1281
|
+
rm: async (path) => {
|
|
1282
|
+
await inner.exec(elevateCommand(`rm -rf ${sq(path)}`));
|
|
1241
1283
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
warnings.push(
|
|
1248
|
-
/HostRegexp/i.test(rule) ? `traefik: router "${rname}" uses HostRegexp (${rule}) \u2014 regex hosts aren't migratable` : `traefik: router "${rname}" has no Host() rule (${rule}) \u2014 skipped`
|
|
1249
|
-
);
|
|
1250
|
-
continue;
|
|
1251
|
-
}
|
|
1252
|
-
if (!c.ip) {
|
|
1253
|
-
warnings.push(
|
|
1254
|
-
`traefik: ${hosts.join(", ")} \u2014 couldn't resolve container ${c.name}'s IP; re-add the upstream manually`
|
|
1255
|
-
);
|
|
1256
|
-
continue;
|
|
1257
|
-
}
|
|
1258
|
-
const svc = props.service;
|
|
1259
|
-
const rawPort = (svc && servicePorts.get(svc)) ?? (servicePorts.size === 1 ? [...servicePorts.values()][0] : void 0) ?? "80";
|
|
1260
|
-
const port = /^\d{1,5}$/.test(String(rawPort)) ? String(rawPort) : "80";
|
|
1261
|
-
const url = `http://${c.ip}:${port}`;
|
|
1262
|
-
const extras = extraMatchers(rule);
|
|
1263
|
-
if (extras.length > 0) {
|
|
1264
|
-
warnings.push(
|
|
1265
|
-
`traefik: ${hosts.join(", ")} also matches ${extras.join(", ")} \u2014 only the Host() part is migrated; re-add path/header rules manually`
|
|
1266
|
-
);
|
|
1267
|
-
}
|
|
1268
|
-
if (props.middlewares) {
|
|
1269
|
-
warnings.push(`traefik: ${hosts.join(", ")} uses middleware(s) "${props.middlewares}" \u2014 not migrated`);
|
|
1284
|
+
};
|
|
1285
|
+
return new Proxy(inner, {
|
|
1286
|
+
get(target, prop2) {
|
|
1287
|
+
if (Object.prototype.hasOwnProperty.call(overrides, prop2)) {
|
|
1288
|
+
return overrides[prop2];
|
|
1270
1289
|
}
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1273
|
-
serverNames: hosts,
|
|
1274
|
-
ssl,
|
|
1275
|
-
target: { kind: "proxy", url },
|
|
1276
|
-
source: `traefik container ${c.name}`
|
|
1277
|
-
});
|
|
1290
|
+
const value = Reflect.get(target, prop2, target);
|
|
1291
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
1278
1292
|
}
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// ../../packages/adapters/src/system/installer.ts
|
|
1297
|
+
function log2(message, level = "info") {
|
|
1298
|
+
return { timestamp: (/* @__PURE__ */ new Date()).toISOString(), message, level };
|
|
1299
|
+
}
|
|
1300
|
+
async function prepareExecutor(executor, component) {
|
|
1301
|
+
const profile = await resolveEnvironment(executor);
|
|
1302
|
+
if (profile.isRoot) return { ok: true, executor, profile };
|
|
1303
|
+
if (profile.canSudo) return { ok: true, executor: elevatedExecutor(executor), profile };
|
|
1304
|
+
return {
|
|
1305
|
+
ok: false,
|
|
1306
|
+
result: {
|
|
1307
|
+
component,
|
|
1308
|
+
success: false,
|
|
1309
|
+
error: `Installing ${component} needs root. Connect this server as root, or as a user with passwordless sudo.`
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
async function installDocker(executor, onLog) {
|
|
1314
|
+
const prep = await prepareExecutor(executor, "docker");
|
|
1315
|
+
if (!prep.ok) return prep.result;
|
|
1316
|
+
executor = prep.executor;
|
|
1317
|
+
const profile = prep.profile;
|
|
1318
|
+
const plan = systemCatalog.installs.docker(profile);
|
|
1319
|
+
if (!plan.supported || !plan.installCommand || !plan.verifyCommand) {
|
|
1320
|
+
return { component: "docker", success: false, error: plan.unsupportedReason ?? "Docker install not supported" };
|
|
1321
|
+
}
|
|
1322
|
+
onLog(log2("Installing Docker Engine..."));
|
|
1323
|
+
try {
|
|
1324
|
+
const { code } = await executor.streamExec(plan.installCommand, onLog);
|
|
1325
|
+
if (code !== 0) return { component: "docker", success: false, error: "Docker install failed" };
|
|
1326
|
+
if (plan.startCommand) {
|
|
1327
|
+
onLog(log2("Starting Docker service..."));
|
|
1328
|
+
await executor.streamExec(plan.startCommand, onLog);
|
|
1329
|
+
}
|
|
1330
|
+
const version = await executor.exec(plan.verifyCommand);
|
|
1331
|
+
const parsed = systemCatalog.checks.docker.parseVersion(version);
|
|
1332
|
+
onLog(log2(`Docker ${parsed} installed`));
|
|
1333
|
+
return { component: "docker", success: true, version: parsed };
|
|
1334
|
+
} catch (err) {
|
|
1335
|
+
const msg = safeErrorMessage(err);
|
|
1336
|
+
onLog(log2(`Docker installation failed: ${msg}`, "error"));
|
|
1337
|
+
return { component: "docker", success: false, error: msg };
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
async function installGit(executor, onLog, opts) {
|
|
1341
|
+
const prep = await prepareExecutor(executor, "git");
|
|
1342
|
+
if (!prep.ok) return prep.result;
|
|
1343
|
+
executor = prep.executor;
|
|
1344
|
+
const profile = prep.profile;
|
|
1345
|
+
const plan = systemCatalog.installs.git(profile);
|
|
1346
|
+
if (!plan.supported || !plan.installCommand || !plan.verifyCommand) {
|
|
1347
|
+
return { component: "git", success: false, error: plan.unsupportedReason ?? "Git install not supported" };
|
|
1348
|
+
}
|
|
1349
|
+
onLog(log2(opts?.label ? `Installing Git in ${opts.label}...` : "Installing Git..."));
|
|
1350
|
+
try {
|
|
1351
|
+
const { code } = await executor.streamExec(plan.installCommand, onLog);
|
|
1352
|
+
if (code !== 0) return { component: "git", success: false, error: "Git installation failed" };
|
|
1353
|
+
const version = await executor.exec(plan.verifyCommand);
|
|
1354
|
+
const parsed = systemCatalog.checks.git.parseVersion(version);
|
|
1355
|
+
onLog(log2(opts?.label ? `Git ${parsed} installed in ${opts.label}` : `Git ${parsed} installed`));
|
|
1356
|
+
return { component: "git", success: true, version: parsed };
|
|
1357
|
+
} catch (err) {
|
|
1358
|
+
const msg = safeErrorMessage(err);
|
|
1359
|
+
onLog(log2(`Git installation failed: ${msg}`, "error"));
|
|
1360
|
+
return { component: "git", success: false, error: msg };
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
async function installRsync(executor, onLog) {
|
|
1364
|
+
const prep = await prepareExecutor(executor, "rsync");
|
|
1365
|
+
if (!prep.ok) return prep.result;
|
|
1366
|
+
executor = prep.executor;
|
|
1367
|
+
const profile = prep.profile;
|
|
1368
|
+
const plan = systemCatalog.installs.rsync(profile);
|
|
1369
|
+
if (!plan.supported || !plan.installCommand || !plan.verifyCommand) {
|
|
1370
|
+
return { component: "rsync", success: false, error: plan.unsupportedReason ?? "rsync install not supported" };
|
|
1371
|
+
}
|
|
1372
|
+
onLog(log2("Installing rsync..."));
|
|
1373
|
+
try {
|
|
1374
|
+
const { code } = await executor.streamExec(plan.installCommand, onLog);
|
|
1375
|
+
if (code !== 0) return { component: "rsync", success: false, error: "rsync installation failed" };
|
|
1376
|
+
const version = await executor.exec(plan.verifyCommand);
|
|
1377
|
+
const parsed = systemCatalog.checks.rsync.parseVersion(version);
|
|
1378
|
+
onLog(log2(`rsync ${parsed} installed`));
|
|
1379
|
+
return { component: "rsync", success: true, version: parsed };
|
|
1380
|
+
} catch (err) {
|
|
1381
|
+
const msg = safeErrorMessage(err);
|
|
1382
|
+
onLog(log2(`rsync installation failed: ${msg}`, "error"));
|
|
1383
|
+
return { component: "rsync", success: false, error: msg };
|
|
1279
1384
|
}
|
|
1280
|
-
return { proxy: "traefik", sites, warnings };
|
|
1281
1385
|
}
|
|
1282
|
-
async function
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
)
|
|
1287
|
-
|
|
1288
|
-
|
|
1386
|
+
async function installContainerEdge(executor, onLog, config) {
|
|
1387
|
+
const prep = await prepareExecutor(executor, "edge");
|
|
1388
|
+
if (!prep.ok) return prep.result;
|
|
1389
|
+
executor = prep.executor;
|
|
1390
|
+
if (!await dockerAvailable(executor)) {
|
|
1391
|
+
const error = "The edge is a container image and needs Docker on this server. Install the Docker component first, then install the edge.";
|
|
1392
|
+
onLog(log2(error, "error"));
|
|
1393
|
+
return { component: "edge", success: false, error };
|
|
1289
1394
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
continue;
|
|
1395
|
+
try {
|
|
1396
|
+
const result = await ensureContainerEdge(executor, {
|
|
1397
|
+
onLog,
|
|
1398
|
+
config,
|
|
1399
|
+
image: config?.edgeImage
|
|
1400
|
+
});
|
|
1401
|
+
if (result.converted) {
|
|
1402
|
+
onLog(log2("Edge moved from host OpenResty to the container edge", "warn"));
|
|
1299
1403
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1404
|
+
const version = await executor.exec(containerCommand(result.container, "openresty -v 2>&1")).catch(() => "");
|
|
1405
|
+
return {
|
|
1406
|
+
component: "edge",
|
|
1407
|
+
success: true,
|
|
1408
|
+
version: version ? systemCatalog.checks.openresty.parseVersion(version) : void 0
|
|
1409
|
+
};
|
|
1410
|
+
} catch (err) {
|
|
1411
|
+
if (err instanceof EdgeMigrateRequested) throw err;
|
|
1412
|
+
const msg = safeErrorMessage(err);
|
|
1413
|
+
onLog(log2(`Edge setup failed: ${msg}`, "error"));
|
|
1414
|
+
return { component: "edge", success: false, error: msg };
|
|
1303
1415
|
}
|
|
1304
|
-
return parseTraefikLabels(containers);
|
|
1305
1416
|
}
|
|
1417
|
+
var COMPONENT_INSTALLERS = {
|
|
1418
|
+
docker: (exec, log5) => installDocker(exec, log5),
|
|
1419
|
+
// The edge is ONE component and it is a container image. `installOpenResty` /
|
|
1420
|
+
// `installCertbot` are NOT reachable from here — they remain only for the mail
|
|
1421
|
+
// server's own proxy (mail.service.ts) and for converting a legacy host edge.
|
|
1422
|
+
edge: (exec, log5, config) => installContainerEdge(exec, log5, config),
|
|
1423
|
+
git: (exec, log5) => installGit(exec, log5),
|
|
1424
|
+
rsync: (exec, log5) => installRsync(exec, log5)
|
|
1425
|
+
};
|
|
1306
1426
|
|
|
1307
|
-
// ../../packages/adapters/src/system/
|
|
1308
|
-
var
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1427
|
+
// ../../packages/adapters/src/system/available-version.ts
|
|
1428
|
+
var PACKAGE_NAMES = {
|
|
1429
|
+
git: "git",
|
|
1430
|
+
rsync: "rsync",
|
|
1431
|
+
// The edge is an IMAGE, not a repo package — its "newer version available" comes
|
|
1432
|
+
// from the registry (see the update scanner's imageDigest), never from apt.
|
|
1433
|
+
edge: null,
|
|
1434
|
+
docker: null
|
|
1435
|
+
};
|
|
1436
|
+
function normalizePkgVersion(raw) {
|
|
1437
|
+
let v = raw.trim();
|
|
1438
|
+
const colon = v.lastIndexOf(":");
|
|
1439
|
+
if (colon !== -1) v = v.slice(colon + 1);
|
|
1440
|
+
const dash = v.indexOf("-");
|
|
1441
|
+
if (dash !== -1) v = v.slice(0, dash);
|
|
1442
|
+
return v.trim();
|
|
1443
|
+
}
|
|
1444
|
+
async function tryExec3(executor, cmd) {
|
|
1319
1445
|
try {
|
|
1320
|
-
|
|
1446
|
+
return await executor.exec(cmd);
|
|
1321
1447
|
} catch {
|
|
1322
1448
|
return null;
|
|
1323
1449
|
}
|
|
1324
|
-
const found = new Set(
|
|
1325
|
-
out.split("\n").map((l) => l.trim()).filter(Boolean)
|
|
1326
|
-
);
|
|
1327
|
-
return INSTALLED_MARKERS.find((m) => found.has(m.proxy))?.proxy ?? null;
|
|
1328
1450
|
}
|
|
1329
|
-
async function
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1451
|
+
async function probeCandidate(executor, pm, pkg) {
|
|
1452
|
+
const q = `'${pkg.replace(/'/g, "'\\''")}'`;
|
|
1453
|
+
if (pm === "apt") {
|
|
1454
|
+
const out = await tryExec3(executor, `apt-cache policy ${q} 2>/dev/null`);
|
|
1455
|
+
return out?.match(/Candidate:\s*(\S+)/)?.[1]?.trim() ?? null;
|
|
1456
|
+
}
|
|
1457
|
+
if (pm === "dnf" || pm === "yum") {
|
|
1458
|
+
const out = await tryExec3(
|
|
1459
|
+
executor,
|
|
1460
|
+
`${pm} -q --cacheonly list available ${q} 2>/dev/null | tail -n1`
|
|
1461
|
+
);
|
|
1462
|
+
return out?.trim().split(/\s+/)[1]?.trim() ?? null;
|
|
1463
|
+
}
|
|
1464
|
+
if (pm === "apk") {
|
|
1465
|
+
const out = await tryExec3(executor, `apk policy ${q} 2>/dev/null`);
|
|
1466
|
+
const versions = [...out?.matchAll(/^\s+([\w.+~-]+):\s*$/gm) ?? []].map((m) => m[1]);
|
|
1467
|
+
return versions.length ? versions[versions.length - 1] : null;
|
|
1345
1468
|
}
|
|
1469
|
+
return null;
|
|
1346
1470
|
}
|
|
1347
|
-
function
|
|
1348
|
-
|
|
1471
|
+
async function enrichAvailableVersions(executor, profile, statuses) {
|
|
1472
|
+
const targets = statuses.filter(
|
|
1473
|
+
(s) => s.installed && s.version && PACKAGE_NAMES[s.name]
|
|
1474
|
+
);
|
|
1475
|
+
await Promise.all(
|
|
1476
|
+
targets.map(async (s) => {
|
|
1477
|
+
try {
|
|
1478
|
+
const pkg = PACKAGE_NAMES[s.name];
|
|
1479
|
+
const candidate = await probeCandidate(executor, profile.packageManager, pkg);
|
|
1480
|
+
if (!candidate) return;
|
|
1481
|
+
const avail = normalizePkgVersion(candidate);
|
|
1482
|
+
const installed = normalizePkgVersion(s.version);
|
|
1483
|
+
if (avail && compareSemver(avail, installed) > 0) {
|
|
1484
|
+
s.availableVersion = avail;
|
|
1485
|
+
s.updateAvailable = true;
|
|
1486
|
+
}
|
|
1487
|
+
} catch {
|
|
1488
|
+
}
|
|
1489
|
+
})
|
|
1490
|
+
);
|
|
1349
1491
|
}
|
|
1350
1492
|
|
|
1351
|
-
// ../../packages/adapters/src/system/
|
|
1352
|
-
var
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1493
|
+
// ../../packages/adapters/src/system/components.ts
|
|
1494
|
+
var SYSTEM_COMPONENTS = [
|
|
1495
|
+
{
|
|
1496
|
+
name: "docker",
|
|
1497
|
+
label: "Docker",
|
|
1498
|
+
description: "Container runtime for deployments",
|
|
1499
|
+
installable: true,
|
|
1500
|
+
category: "core"
|
|
1501
|
+
},
|
|
1502
|
+
{
|
|
1503
|
+
name: "git",
|
|
1504
|
+
label: "Git",
|
|
1505
|
+
description: "Version control for source code",
|
|
1506
|
+
installable: true,
|
|
1507
|
+
category: "core"
|
|
1508
|
+
},
|
|
1509
|
+
{
|
|
1510
|
+
// ONE component for the edge, because it is ONE artifact: the openship-edge
|
|
1511
|
+
// image. OpenResty, its Lua, and certbot all ship inside it — they were three
|
|
1512
|
+
// rows in this list for a thing that is installed, checked, and removed as a
|
|
1513
|
+
// unit, and neither "openresty" nor "certbot" was independently installable
|
|
1514
|
+
// on a converted box.
|
|
1515
|
+
name: "edge",
|
|
1516
|
+
label: "Edge",
|
|
1517
|
+
description: "Routing + TLS \u2014 the openship-edge container (OpenResty, Lua, certbot)",
|
|
1518
|
+
installable: true,
|
|
1519
|
+
category: "infrastructure"
|
|
1520
|
+
},
|
|
1521
|
+
{
|
|
1522
|
+
name: "rsync",
|
|
1523
|
+
label: "rsync",
|
|
1524
|
+
description: "Fast directory sync for remote local-build transfers",
|
|
1525
|
+
installable: true,
|
|
1526
|
+
category: "infrastructure"
|
|
1362
1527
|
}
|
|
1528
|
+
];
|
|
1529
|
+
var SYSTEM_COMPONENTS_BY_NAME = new Map(
|
|
1530
|
+
SYSTEM_COMPONENTS.map((component) => [component.name, component])
|
|
1531
|
+
);
|
|
1532
|
+
function getSystemComponentDefinition(name) {
|
|
1533
|
+
return SYSTEM_COMPONENTS_BY_NAME.get(name) ?? {
|
|
1534
|
+
name,
|
|
1535
|
+
label: name,
|
|
1536
|
+
description: `${name} component`,
|
|
1537
|
+
installable: false,
|
|
1538
|
+
category: "infrastructure"
|
|
1539
|
+
};
|
|
1363
1540
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1541
|
+
|
|
1542
|
+
// ../../packages/adapters/src/system/checks.ts
|
|
1543
|
+
async function tryExec4(executor, command) {
|
|
1544
|
+
const startedAt = Date.now();
|
|
1545
|
+
systemDebug("checks", `exec:start ${command}`);
|
|
1546
|
+
try {
|
|
1547
|
+
const result = await executor.exec(command, { timeout: 1e4 });
|
|
1548
|
+
systemDebug(
|
|
1549
|
+
"checks",
|
|
1550
|
+
`exec:ok ${command} (${formatDuration(startedAt)})`
|
|
1551
|
+
);
|
|
1552
|
+
return result;
|
|
1553
|
+
} catch (err) {
|
|
1554
|
+
if (isRemoteConnectionError(err)) {
|
|
1555
|
+
systemDebug(
|
|
1556
|
+
"checks",
|
|
1557
|
+
`exec:abort ${command} (${formatDuration(startedAt)}) ${safeErrorMessage(err)}`
|
|
1373
1558
|
);
|
|
1374
|
-
|
|
1375
|
-
} else if (o.systemdUnit && !units.has(o.systemdUnit)) {
|
|
1376
|
-
const en = await tryExec5(executor, `systemctl is-enabled ${sq2(o.systemdUnit)} 2>/dev/null`);
|
|
1377
|
-
units.set(o.systemdUnit, { unit: o.systemdUnit, wasEnabled: en?.trim() === "enabled" });
|
|
1378
|
-
} else if (!o.containerName && !o.systemdUnit && o.pid && !processes.has(o.pid)) {
|
|
1379
|
-
processes.set(o.pid, { pid: o.pid, command: o.rawCommand });
|
|
1559
|
+
throw err;
|
|
1380
1560
|
}
|
|
1561
|
+
const msg = safeErrorMessage(err);
|
|
1562
|
+
systemDebug(
|
|
1563
|
+
"checks",
|
|
1564
|
+
`exec:fail ${command} (${formatDuration(startedAt)}) ${msg}`
|
|
1565
|
+
);
|
|
1566
|
+
return null;
|
|
1381
1567
|
}
|
|
1568
|
+
}
|
|
1569
|
+
function healthy(name, version, running) {
|
|
1570
|
+
const component = getSystemComponentDefinition(name);
|
|
1382
1571
|
return {
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1572
|
+
name,
|
|
1573
|
+
label: component.label,
|
|
1574
|
+
description: component.description,
|
|
1575
|
+
installable: component.installable,
|
|
1576
|
+
installed: true,
|
|
1577
|
+
version,
|
|
1578
|
+
running,
|
|
1579
|
+
healthy: running !== void 0 ? running : true,
|
|
1580
|
+
message: running ? `${name} ${version} - running` : `${name} ${version} - installed`
|
|
1387
1581
|
};
|
|
1388
1582
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1583
|
+
function unhealthy(name, message, opts) {
|
|
1584
|
+
const component = getSystemComponentDefinition(name);
|
|
1585
|
+
return {
|
|
1586
|
+
name,
|
|
1587
|
+
label: component.label,
|
|
1588
|
+
description: component.description,
|
|
1589
|
+
installable: component.installable,
|
|
1590
|
+
installed: !!opts?.version,
|
|
1591
|
+
version: opts?.version,
|
|
1592
|
+
running: opts?.running,
|
|
1593
|
+
healthy: false,
|
|
1594
|
+
message
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
async function checkDocker(executor) {
|
|
1598
|
+
const startedAt = Date.now();
|
|
1599
|
+
const recipe = systemCatalog.checks.docker;
|
|
1600
|
+
const version = await tryExec4(executor, recipe.versionCommand);
|
|
1601
|
+
if (!version) {
|
|
1602
|
+
systemDebug("checks", `docker:missing (${formatDuration(startedAt)})`);
|
|
1603
|
+
return unhealthy("docker", recipe.missingMessage);
|
|
1604
|
+
}
|
|
1605
|
+
const parsed = recipe.parseVersion(version);
|
|
1606
|
+
const info = await tryExec4(executor, recipe.daemonCommand);
|
|
1607
|
+
if (!info) {
|
|
1608
|
+
systemDebug("checks", `docker:not-running (${formatDuration(startedAt)})`);
|
|
1609
|
+
return unhealthy("docker", recipe.notRunningMessage, {
|
|
1610
|
+
version: parsed,
|
|
1611
|
+
running: false
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
systemDebug("checks", `docker:healthy (${formatDuration(startedAt)})`);
|
|
1615
|
+
return healthy("docker", parsed, true);
|
|
1616
|
+
}
|
|
1617
|
+
async function checkGit(executor) {
|
|
1618
|
+
const startedAt = Date.now();
|
|
1619
|
+
const recipe = systemCatalog.checks.git;
|
|
1620
|
+
const version = await tryExec4(executor, recipe.versionCommand);
|
|
1621
|
+
if (!version) {
|
|
1622
|
+
systemDebug("checks", `git:missing (${formatDuration(startedAt)})`);
|
|
1623
|
+
return unhealthy("git", recipe.missingMessage);
|
|
1394
1624
|
}
|
|
1625
|
+
const parsed = recipe.parseVersion(version);
|
|
1626
|
+
systemDebug("checks", `git:healthy (${formatDuration(startedAt)})`);
|
|
1627
|
+
return healthy("git", parsed);
|
|
1395
1628
|
}
|
|
1396
|
-
async function
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
return JSON.parse(raw);
|
|
1404
|
-
} catch {
|
|
1405
|
-
await clearJournal(executor);
|
|
1406
|
-
return null;
|
|
1629
|
+
async function checkRsync(executor) {
|
|
1630
|
+
const startedAt = Date.now();
|
|
1631
|
+
const recipe = systemCatalog.checks.rsync;
|
|
1632
|
+
const version = await tryExec4(executor, recipe.versionCommand);
|
|
1633
|
+
if (!version) {
|
|
1634
|
+
systemDebug("checks", `rsync:missing (${formatDuration(startedAt)})`);
|
|
1635
|
+
return unhealthy("rsync", recipe.missingMessage);
|
|
1407
1636
|
}
|
|
1637
|
+
const parsed = recipe.parseVersion(version);
|
|
1638
|
+
systemDebug("checks", `rsync:healthy (${formatDuration(startedAt)})`);
|
|
1639
|
+
return healthy("rsync", parsed);
|
|
1408
1640
|
}
|
|
1409
|
-
async function
|
|
1410
|
-
|
|
1411
|
-
await
|
|
1412
|
-
|
|
1413
|
-
"
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
executor,
|
|
1418
|
-
u.wasEnabled ? `systemctl enable --now ${sq2(u.unit)} 2>/dev/null || true` : `systemctl start ${sq2(u.unit)} 2>/dev/null || true`
|
|
1641
|
+
async function checkEdge(executor) {
|
|
1642
|
+
const startedAt = Date.now();
|
|
1643
|
+
const container = await resolveOurEdgeContainer(executor);
|
|
1644
|
+
if (!container) {
|
|
1645
|
+
systemDebug("checks", `edge:missing (${formatDuration(startedAt)})`);
|
|
1646
|
+
return unhealthy(
|
|
1647
|
+
"edge",
|
|
1648
|
+
"No edge on this server. The edge is the openship-edge container \u2014 install it (requires Docker)."
|
|
1419
1649
|
);
|
|
1420
1650
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
`setsid -f sh -c ${sq2(p.command)} 2>/dev/null || (nohup sh -c ${sq2(p.command)} >/dev/null 2>&1 &) || true`
|
|
1430
|
-
);
|
|
1431
|
-
} else {
|
|
1432
|
-
onLog(log(`Could not restore process ${p.pid} \u2014 no command captured.`, "warn"));
|
|
1433
|
-
}
|
|
1651
|
+
const version = await tryExec4(executor, containerCommand(container, "openresty -v 2>&1"));
|
|
1652
|
+
if (!version) {
|
|
1653
|
+
systemDebug("checks", `edge:container-unresponsive (${formatDuration(startedAt)})`);
|
|
1654
|
+
return unhealthy(
|
|
1655
|
+
"edge",
|
|
1656
|
+
`The edge container ${container} is running but not responding \u2014 check \`docker logs ${container}\``,
|
|
1657
|
+
{ running: false }
|
|
1658
|
+
);
|
|
1434
1659
|
}
|
|
1660
|
+
systemDebug("checks", `edge:healthy (${formatDuration(startedAt)})`);
|
|
1661
|
+
return healthy("edge", systemCatalog.checks.openresty.parseVersion(version), true);
|
|
1435
1662
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1663
|
+
var COMPONENT_CHECKS = {
|
|
1664
|
+
docker: checkDocker,
|
|
1665
|
+
edge: checkEdge,
|
|
1666
|
+
git: checkGit,
|
|
1667
|
+
rsync: checkRsync
|
|
1668
|
+
};
|
|
1669
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
1670
|
+
const results = new Array(items.length);
|
|
1671
|
+
let cursor = 0;
|
|
1672
|
+
const worker = async () => {
|
|
1673
|
+
while (cursor < items.length) {
|
|
1674
|
+
const index = cursor++;
|
|
1675
|
+
results[index] = await fn(items[index]);
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
await Promise.all(
|
|
1679
|
+
Array.from({ length: Math.min(limit, items.length) }, worker)
|
|
1680
|
+
);
|
|
1681
|
+
return results;
|
|
1439
1682
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1683
|
+
var CHECK_CONCURRENCY = 4;
|
|
1684
|
+
async function checkAll(executor) {
|
|
1685
|
+
const startedAt = Date.now();
|
|
1686
|
+
const entries = SYSTEM_COMPONENTS.map((component) => [component.name, COMPONENT_CHECKS[component.name]]).filter((entry) => Boolean(entry[1]));
|
|
1687
|
+
systemDebug(
|
|
1688
|
+
"checks",
|
|
1689
|
+
`checkAll:start [${entries.map(([name]) => name).join(", ")}]`
|
|
1690
|
+
);
|
|
1691
|
+
const results = await mapWithConcurrency(
|
|
1692
|
+
entries,
|
|
1693
|
+
CHECK_CONCURRENCY,
|
|
1694
|
+
([, fn]) => fn(executor)
|
|
1695
|
+
);
|
|
1696
|
+
await enrichAvailable(executor, results);
|
|
1697
|
+
systemDebug("checks", `checkAll:done (${formatDuration(startedAt)})`);
|
|
1698
|
+
return results;
|
|
1446
1699
|
}
|
|
1447
|
-
async function
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1700
|
+
async function enrichAvailable(executor, results) {
|
|
1701
|
+
try {
|
|
1702
|
+
const profile = await resolveEnvironment(executor);
|
|
1703
|
+
await enrichAvailableVersions(executor, profile, results);
|
|
1704
|
+
} catch {
|
|
1452
1705
|
}
|
|
1453
|
-
await clearJournal(executor);
|
|
1454
1706
|
}
|
|
1455
|
-
async function
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1707
|
+
async function checkComponents(executor, names) {
|
|
1708
|
+
const startedAt = Date.now();
|
|
1709
|
+
const fns = names.map((name) => COMPONENT_CHECKS[name]).filter((fn) => Boolean(fn));
|
|
1710
|
+
systemDebug("checks", `checkComponents:start [${names.join(", ")}]`);
|
|
1711
|
+
const results = await mapWithConcurrency(
|
|
1712
|
+
fns,
|
|
1713
|
+
CHECK_CONCURRENCY,
|
|
1714
|
+
(fn) => fn(executor)
|
|
1715
|
+
);
|
|
1716
|
+
await enrichAvailable(executor, results);
|
|
1717
|
+
systemDebug(
|
|
1718
|
+
"checks",
|
|
1719
|
+
`checkComponents:done [${names.join(", ")}] (${formatDuration(startedAt)})`
|
|
1720
|
+
);
|
|
1721
|
+
return results;
|
|
1470
1722
|
}
|
|
1471
1723
|
|
|
1472
1724
|
// ../../packages/adapters/src/system/proxy/index.ts
|
|
@@ -1496,20 +1748,20 @@ function describeEdgeOwner(occupants) {
|
|
|
1496
1748
|
}
|
|
1497
1749
|
|
|
1498
1750
|
// ../../packages/adapters/src/system/proxy/consent.ts
|
|
1499
|
-
function
|
|
1751
|
+
function log3(message, level = "info") {
|
|
1500
1752
|
return { timestamp: (/* @__PURE__ */ new Date()).toISOString(), message, level };
|
|
1501
1753
|
}
|
|
1502
1754
|
async function ensureEdgeClear(executor, config, onLog) {
|
|
1503
1755
|
const status = await probeEdge(executor);
|
|
1504
1756
|
if (status.canProceedClean) return { tookOver: false };
|
|
1505
1757
|
const takeover = async () => {
|
|
1506
|
-
onLog(
|
|
1758
|
+
onLog(log3(
|
|
1507
1759
|
`Taking over ports from ${status.occupants.map((o) => o.command ?? o.port).join(", ")}...`,
|
|
1508
1760
|
"warn"
|
|
1509
1761
|
));
|
|
1510
1762
|
const configured = config?.edgePolicy?.stopTargets ?? [];
|
|
1511
1763
|
const targets = configured.length ? configured : stopTargetsForStatus(status);
|
|
1512
|
-
await freeEdgeTargets(executor, targets, (m, l) => onLog(
|
|
1764
|
+
await freeEdgeTargets(executor, targets, (m, l) => onLog(log3(m, l)));
|
|
1513
1765
|
};
|
|
1514
1766
|
if (config?.edgePolicy?.mode === "takeover") {
|
|
1515
1767
|
await takeover();
|
|
@@ -1549,223 +1801,213 @@ async function ensureEdgeClear(executor, config, onLog) {
|
|
|
1549
1801
|
throw new EdgeConflictError(status);
|
|
1550
1802
|
}
|
|
1551
1803
|
|
|
1552
|
-
// ../../packages/adapters/src/system/
|
|
1553
|
-
|
|
1804
|
+
// ../../packages/adapters/src/system/proxy/ensure-container-edge.ts
|
|
1805
|
+
var EDGE_CONTAINER_NAME = "openship-edge";
|
|
1806
|
+
function log4(message, level = "info") {
|
|
1554
1807
|
return { timestamp: (/* @__PURE__ */ new Date()).toISOString(), message, level };
|
|
1555
1808
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1809
|
+
var injectedDefaultImage;
|
|
1810
|
+
function setDefaultEdgeImage(image) {
|
|
1811
|
+
injectedDefaultImage = image?.trim() || void 0;
|
|
1812
|
+
}
|
|
1813
|
+
function resolveEdgeImage(explicit) {
|
|
1814
|
+
return buildEdgeImageRef({ explicit, injectedDefault: injectedDefaultImage });
|
|
1815
|
+
}
|
|
1816
|
+
async function dockerAvailable(executor) {
|
|
1817
|
+
return executor.exec("docker version --format '{{.Server.Version}}' 2>/dev/null").then((v) => Boolean(v.trim())).catch(() => false);
|
|
1818
|
+
}
|
|
1819
|
+
async function runningImage(executor, container) {
|
|
1820
|
+
const out = await executor.exec(`docker inspect -f '{{.Config.Image}}' ${sq(container)} 2>/dev/null`).catch(() => "");
|
|
1821
|
+
return out.trim() || null;
|
|
1822
|
+
}
|
|
1823
|
+
async function containerEdgeProvider(executor, container, opts) {
|
|
1824
|
+
const { NginxProvider: Provider } = await import("./nginx-2GTRUIDE.js");
|
|
1825
|
+
return new Provider({
|
|
1826
|
+
...opts,
|
|
1827
|
+
// Vhosts go to the BIND-MOUNTED HOST dir (so every host-side reader — the
|
|
1828
|
+
// migrate proxy scan, cert reuse, the mail cert symlinks — keeps working),
|
|
1829
|
+
// while reload/certbot run inside the container.
|
|
1830
|
+
paths: EDGE_HOST_PATHS,
|
|
1831
|
+
executor: edgeContainerExecutor(executor, container),
|
|
1832
|
+
// MUST be pinned: re-detection answers from inside the container and would
|
|
1833
|
+
// repoint sitesDir at a host dir the edge never reads.
|
|
1834
|
+
pinPaths: true
|
|
1835
|
+
});
|
|
1564
1836
|
}
|
|
1565
|
-
async function
|
|
1566
|
-
const
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1837
|
+
async function localContainerEdgeProvider(container, opts) {
|
|
1838
|
+
const { DockerEdgeExecutor } = await import("./docker-edge-executor-VHW3JPJS.js");
|
|
1839
|
+
const { NginxProvider: Provider } = await import("./nginx-2GTRUIDE.js");
|
|
1840
|
+
return new Provider({
|
|
1841
|
+
...opts,
|
|
1842
|
+
paths: OPENRESTY_DEFAULT_PATHS,
|
|
1843
|
+
executor: new DockerEdgeExecutor({ containerName: container }),
|
|
1844
|
+
// nginx.conf + the Lua are BAKED into the image — nothing to detect, install
|
|
1845
|
+
// or patch, and detection would answer from inside the container anyway.
|
|
1846
|
+
pinPaths: true
|
|
1847
|
+
});
|
|
1572
1848
|
}
|
|
1573
|
-
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1849
|
+
function buildEdgeRunCommand(container, image) {
|
|
1850
|
+
const mounts = EDGE_CONTAINER_MOUNTS.map(
|
|
1851
|
+
// `:z` relabels for SELinux-enforcing hosts; a no-op elsewhere.
|
|
1852
|
+
(m) => `-v ${sq(`${m.host}:${m.container}:z`)}`
|
|
1853
|
+
).join(" ");
|
|
1854
|
+
return [
|
|
1855
|
+
"docker run -d",
|
|
1856
|
+
`--name ${sq(container)}`,
|
|
1857
|
+
"--network host",
|
|
1858
|
+
"--restart unless-stopped",
|
|
1859
|
+
mounts,
|
|
1860
|
+
sq(image)
|
|
1861
|
+
].join(" ");
|
|
1862
|
+
}
|
|
1863
|
+
async function swapEdgeImage(executor, container, from, to, opts) {
|
|
1864
|
+
const { onLog } = opts;
|
|
1865
|
+
onLog(log4(`Updating the edge: ${from} \u2192 ${to}`));
|
|
1866
|
+
const pull = await executor.streamExec(`docker pull ${sq(to)}`, onLog);
|
|
1867
|
+
if (pull.code !== 0) {
|
|
1868
|
+
onLog(log4(`Could not pull ${to} \u2014 the edge stays on ${from}.`, "warn"));
|
|
1869
|
+
return { swapped: false, edgeDown: false };
|
|
1870
|
+
}
|
|
1871
|
+
const start = async (image) => {
|
|
1872
|
+
await executor.exec(`docker rm -f ${sq(container)} 2>/dev/null || true`).catch(() => {
|
|
1873
|
+
});
|
|
1874
|
+
const run = await executor.streamExec(
|
|
1875
|
+
buildEdgeRunCommand(container, image),
|
|
1876
|
+
onLog
|
|
1877
|
+
);
|
|
1878
|
+
invalidateEdgeContainer(executor);
|
|
1879
|
+
if (run.code !== 0) return false;
|
|
1880
|
+
const listening = await waitForPortListening(executor, 80, {
|
|
1881
|
+
timeoutMs: opts.verifyTimeoutMs ?? 3e4
|
|
1882
|
+
});
|
|
1883
|
+
return !(listening.checked && !listening.listening);
|
|
1584
1884
|
};
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1885
|
+
if (await start(to)) {
|
|
1886
|
+
onLog(log4(`Edge updated to ${to}`));
|
|
1887
|
+
return { swapped: true, edgeDown: false };
|
|
1888
|
+
}
|
|
1889
|
+
onLog(log4(`Edge ${to} failed to come up \u2014 rolling back to ${from}...`, "error"));
|
|
1890
|
+
if (await start(from)) {
|
|
1891
|
+
return { swapped: false, edgeDown: false };
|
|
1892
|
+
}
|
|
1893
|
+
onLog(log4(`Rollback to ${from} ALSO failed \u2014 the edge is down on this server.`, "error"));
|
|
1894
|
+
return { swapped: false, edgeDown: true };
|
|
1895
|
+
}
|
|
1896
|
+
async function ensureContainerEdge(executor, opts) {
|
|
1897
|
+
const { onLog } = opts;
|
|
1898
|
+
const container = opts.container?.trim() || EDGE_CONTAINER_NAME;
|
|
1899
|
+
const image = resolveEdgeImage(opts.image);
|
|
1900
|
+
const existing = await resolveOurEdgeContainer(executor, { fresh: true });
|
|
1901
|
+
if (existing) {
|
|
1902
|
+
const current = await runningImage(executor, existing);
|
|
1903
|
+
if (current && current !== image) {
|
|
1904
|
+
const swap = await swapEdgeImage(executor, existing, current, image, opts);
|
|
1905
|
+
return {
|
|
1906
|
+
container: existing,
|
|
1907
|
+
image,
|
|
1908
|
+
converted: false,
|
|
1909
|
+
updated: swap.swapped,
|
|
1910
|
+
edgeDown: swap.edgeDown
|
|
1911
|
+
};
|
|
1602
1912
|
}
|
|
1603
|
-
|
|
1604
|
-
const parsed = systemCatalog.checks.docker.parseVersion(version);
|
|
1605
|
-
onLog(log3(`Docker ${parsed} installed`));
|
|
1606
|
-
return { component: "docker", success: true, version: parsed };
|
|
1607
|
-
} catch (err) {
|
|
1608
|
-
const msg = safeErrorMessage(err);
|
|
1609
|
-
onLog(log3(`Docker installation failed: ${msg}`, "error"));
|
|
1610
|
-
return { component: "docker", success: false, error: msg };
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
async function installGit(executor, onLog, opts) {
|
|
1614
|
-
const prep = await prepareExecutor(executor, "git");
|
|
1615
|
-
if (!prep.ok) return prep.result;
|
|
1616
|
-
executor = prep.executor;
|
|
1617
|
-
const profile = prep.profile;
|
|
1618
|
-
const plan = systemCatalog.installs.git(profile);
|
|
1619
|
-
if (!plan.supported || !plan.installCommand || !plan.verifyCommand) {
|
|
1620
|
-
return { component: "git", success: false, error: plan.unsupportedReason ?? "Git install not supported" };
|
|
1621
|
-
}
|
|
1622
|
-
onLog(log3(opts?.label ? `Installing Git in ${opts.label}...` : "Installing Git..."));
|
|
1623
|
-
try {
|
|
1624
|
-
const { code } = await executor.streamExec(plan.installCommand, onLog);
|
|
1625
|
-
if (code !== 0) return { component: "git", success: false, error: "Git installation failed" };
|
|
1626
|
-
const version = await executor.exec(plan.verifyCommand);
|
|
1627
|
-
const parsed = systemCatalog.checks.git.parseVersion(version);
|
|
1628
|
-
onLog(log3(opts?.label ? `Git ${parsed} installed in ${opts.label}` : `Git ${parsed} installed`));
|
|
1629
|
-
return { component: "git", success: true, version: parsed };
|
|
1630
|
-
} catch (err) {
|
|
1631
|
-
const msg = safeErrorMessage(err);
|
|
1632
|
-
onLog(log3(`Git installation failed: ${msg}`, "error"));
|
|
1633
|
-
return { component: "git", success: false, error: msg };
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
async function installRsync(executor, onLog) {
|
|
1637
|
-
const prep = await prepareExecutor(executor, "rsync");
|
|
1638
|
-
if (!prep.ok) return prep.result;
|
|
1639
|
-
executor = prep.executor;
|
|
1640
|
-
const profile = prep.profile;
|
|
1641
|
-
const plan = systemCatalog.installs.rsync(profile);
|
|
1642
|
-
if (!plan.supported || !plan.installCommand || !plan.verifyCommand) {
|
|
1643
|
-
return { component: "rsync", success: false, error: plan.unsupportedReason ?? "rsync install not supported" };
|
|
1913
|
+
return { container: existing, image, converted: false };
|
|
1644
1914
|
}
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
const parsed = systemCatalog.checks.rsync.parseVersion(version);
|
|
1651
|
-
onLog(log3(`rsync ${parsed} installed`));
|
|
1652
|
-
return { component: "rsync", success: true, version: parsed };
|
|
1653
|
-
} catch (err) {
|
|
1654
|
-
const msg = safeErrorMessage(err);
|
|
1655
|
-
onLog(log3(`rsync installation failed: ${msg}`, "error"));
|
|
1656
|
-
return { component: "rsync", success: false, error: msg };
|
|
1915
|
+
await ensureEdgeClear(executor, opts.config, onLog);
|
|
1916
|
+
if (!await dockerAvailable(executor)) {
|
|
1917
|
+
throw new Error(
|
|
1918
|
+
"Docker isn't available on this server, and the edge now runs as a container. Install the Docker component first, then set up the edge."
|
|
1919
|
+
);
|
|
1657
1920
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
const
|
|
1661
|
-
if (
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
if (!plan.supported || !plan.installCommand || !plan.verifyCommand) {
|
|
1666
|
-
return { component: "certbot", success: false, error: plan.unsupportedReason ?? "Certbot install not supported" };
|
|
1921
|
+
const bareWasOurs = await ourLuaOnHost(executor);
|
|
1922
|
+
onLog(log4(`Pulling edge image ${image}...`));
|
|
1923
|
+
const pull = await executor.streamExec(`docker pull ${sq(image)}`, onLog);
|
|
1924
|
+
if (pull.code !== 0) {
|
|
1925
|
+
throw new Error(
|
|
1926
|
+
`Could not pull the edge image ${image} \u2014 the box is unchanged and still serving. Check the server's network access to the registry, then retry.`
|
|
1927
|
+
);
|
|
1667
1928
|
}
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
if (code !== 0) return { component: "certbot", success: false, error: "Certbot installation failed" };
|
|
1672
|
-
const version = await executor.exec(plan.verifyCommand);
|
|
1673
|
-
const parsed = systemCatalog.checks.certbot.parseVersion(version);
|
|
1674
|
-
onLog(log3(`Certbot ${parsed} installed`));
|
|
1675
|
-
return { component: "certbot", success: true, version: parsed };
|
|
1676
|
-
} catch (err) {
|
|
1677
|
-
const msg = safeErrorMessage(err);
|
|
1678
|
-
onLog(log3(`Certbot installation failed: ${msg}`, "error"));
|
|
1679
|
-
return { component: "certbot", success: false, error: msg };
|
|
1929
|
+
for (const mount of EDGE_CONTAINER_MOUNTS) {
|
|
1930
|
+
await executor.exec(`mkdir -p ${sq(mount.host)}`).catch(() => {
|
|
1931
|
+
});
|
|
1680
1932
|
}
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
if (!plan.supported || !plan.installCommand || !plan.verifyCommand) {
|
|
1690
|
-
return { component: "openresty", success: false, error: plan.unsupportedReason ?? "OpenResty install not supported" };
|
|
1933
|
+
const sitesTarget = EDGE_HOST_PATHS.sitesDir;
|
|
1934
|
+
if (bareWasOurs) {
|
|
1935
|
+
const barePaths = await detectOpenRestyPaths(executor).catch(() => OPENRESTY_DEFAULT_PATHS);
|
|
1936
|
+
if (barePaths.sitesDir !== sitesTarget && await executor.exists(barePaths.sitesDir)) {
|
|
1937
|
+
onLog(log4(`Carrying vhosts from ${barePaths.sitesDir}...`));
|
|
1938
|
+
await executor.exec(`cp -a ${sq(`${barePaths.sitesDir}/.`)} ${sq(`${sitesTarget}/`)} 2>/dev/null || true`).catch(() => {
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1691
1941
|
}
|
|
1692
|
-
|
|
1942
|
+
const restoreBare = async () => {
|
|
1943
|
+
if (!bareWasOurs) return;
|
|
1944
|
+
onLog(log4("Restoring the host OpenResty edge...", "warn"));
|
|
1945
|
+
await executor.exec("systemctl enable --now openresty 2>/dev/null || true").catch(() => {
|
|
1946
|
+
});
|
|
1947
|
+
};
|
|
1693
1948
|
try {
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
await
|
|
1699
|
-
|
|
1700
|
-
}
|
|
1701
|
-
if (profile.packageManager === "apt") {
|
|
1702
|
-
await ensureAptReady(executor, onLog);
|
|
1703
|
-
}
|
|
1704
|
-
const { code } = await executor.streamExec(plan.installCommand, onLog);
|
|
1705
|
-
if (code !== 0) return { component: "openresty", success: false, error: "OpenResty installation failed" };
|
|
1706
|
-
await execSafe(executor, "systemctl stop openresty 2>/dev/null || true");
|
|
1707
|
-
await execSafe(executor, "pkill -f '[o]penresty' 2>/dev/null || true");
|
|
1708
|
-
await execSafe(executor, "systemctl reset-failed openresty 2>/dev/null || true");
|
|
1709
|
-
const paths = await detectOpenRestyPaths(executor);
|
|
1710
|
-
await ensureOpenRestyConfig(executor, paths);
|
|
1711
|
-
onLog(log3("Validating config..."));
|
|
1712
|
-
const { code: testCode } = await executor.streamExec(`${paths.bin} -t 2>&1`, onLog);
|
|
1713
|
-
if (testCode !== 0) {
|
|
1714
|
-
return { component: "openresty", success: false, error: "OpenResty config invalid - see logs above" };
|
|
1949
|
+
if (bareWasOurs) {
|
|
1950
|
+
onLog(log4("Stopping the host OpenResty edge..."));
|
|
1951
|
+
await executor.exec("systemctl disable --now openresty 2>/dev/null || true").catch(() => {
|
|
1952
|
+
});
|
|
1953
|
+
await executor.exec("systemctl reset-failed openresty 2>/dev/null || true").catch(() => {
|
|
1954
|
+
});
|
|
1715
1955
|
}
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
${journal}`, "error"));
|
|
1732
|
-
return { component: "openresty", success: false, error: "OpenResty installed but failed to start" };
|
|
1733
|
-
}
|
|
1956
|
+
await executor.exec(`docker rm -f ${sq(container)} 2>/dev/null || true`).catch(() => {
|
|
1957
|
+
});
|
|
1958
|
+
onLog(log4("Starting the edge container..."));
|
|
1959
|
+
const run = await executor.streamExec(
|
|
1960
|
+
buildEdgeRunCommand(container, image),
|
|
1961
|
+
onLog
|
|
1962
|
+
);
|
|
1963
|
+
invalidateEdgeContainer(executor);
|
|
1964
|
+
if (run.code !== 0) throw new Error("the edge container failed to start");
|
|
1965
|
+
await executor.exec(containerCommand(container, "openresty -t"));
|
|
1966
|
+
const listening = await waitForPortListening(executor, 80, {
|
|
1967
|
+
timeoutMs: opts.verifyTimeoutMs ?? 3e4
|
|
1968
|
+
});
|
|
1969
|
+
if (listening.checked && !listening.listening) {
|
|
1970
|
+
throw new Error("the edge container started but nothing is listening on :80");
|
|
1734
1971
|
}
|
|
1735
|
-
await executor.exec(
|
|
1736
|
-
onLog(
|
|
1737
|
-
|
|
1738
|
-
const version = await executor.exec(plan.verifyCommand);
|
|
1739
|
-
const parsed = systemCatalog.checks.openresty.parseVersion(version);
|
|
1740
|
-
onLog(log3(`OpenResty ${parsed} installed`));
|
|
1741
|
-
return { component: "openresty", success: true, version: parsed };
|
|
1972
|
+
const version = await executor.exec(containerCommand(container, "openresty -v 2>&1")).catch(() => "");
|
|
1973
|
+
onLog(log4(`Edge container running${version.trim() ? ` (${version.trim()})` : ""}`));
|
|
1974
|
+
return { container, image, converted: bareWasOurs };
|
|
1742
1975
|
} catch (err) {
|
|
1743
|
-
if (err instanceof EdgeMigrateRequested) throw err;
|
|
1744
1976
|
const msg = safeErrorMessage(err);
|
|
1745
|
-
onLog(
|
|
1746
|
-
|
|
1977
|
+
onLog(log4(`Edge container setup failed: ${msg}`, "error"));
|
|
1978
|
+
const logs = await executor.exec(`docker logs --tail 40 ${sq(container)} 2>&1 || true`).catch(() => "");
|
|
1979
|
+
if (logs.trim()) onLog(log4(`Edge container logs:
|
|
1980
|
+
${logs}`, "error"));
|
|
1981
|
+
await executor.exec(`docker rm -f ${sq(container)} 2>/dev/null || true`).catch(() => {
|
|
1982
|
+
});
|
|
1983
|
+
invalidateEdgeContainer(executor);
|
|
1984
|
+
await restoreBare();
|
|
1985
|
+
throw new Error(`Edge container setup failed: ${msg}`);
|
|
1747
1986
|
}
|
|
1748
1987
|
}
|
|
1749
|
-
var COMPONENT_INSTALLERS = {
|
|
1750
|
-
docker: (exec, log4) => installDocker(exec, log4),
|
|
1751
|
-
openresty: (exec, log4, config) => installOpenResty(exec, log4, config),
|
|
1752
|
-
certbot: (exec, log4) => installCertbot(exec, log4),
|
|
1753
|
-
git: (exec, log4) => installGit(exec, log4),
|
|
1754
|
-
rsync: (exec, log4) => installRsync(exec, log4)
|
|
1755
|
-
};
|
|
1756
1988
|
|
|
1757
1989
|
export {
|
|
1758
1990
|
systemCatalog,
|
|
1759
1991
|
checkGit,
|
|
1760
1992
|
checkAll,
|
|
1761
1993
|
checkComponents,
|
|
1762
|
-
ourEdgeContainerRunning,
|
|
1763
1994
|
detectInstalledProxy,
|
|
1764
1995
|
scanImportableSites,
|
|
1996
|
+
edgeProxy,
|
|
1997
|
+
edgeProxyFor,
|
|
1998
|
+
collectProxyCerts,
|
|
1765
1999
|
beginEdgeTakeover,
|
|
1766
2000
|
rollbackEdgeTakeover,
|
|
1767
2001
|
completeEdgeTakeover,
|
|
1768
2002
|
recoverInterruptedTakeover,
|
|
2003
|
+
EDGE_CONTAINER_NAME,
|
|
2004
|
+
setDefaultEdgeImage,
|
|
2005
|
+
resolveEdgeImage,
|
|
2006
|
+
dockerAvailable,
|
|
2007
|
+
containerEdgeProvider,
|
|
2008
|
+
localContainerEdgeProvider,
|
|
2009
|
+
buildEdgeRunCommand,
|
|
2010
|
+
ensureContainerEdge,
|
|
1769
2011
|
importSites,
|
|
1770
2012
|
foreignProxyOnEdge,
|
|
1771
2013
|
installGit,
|