shopify-cli 1.4.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +2 -2
- data/.github/CONTRIBUTING.md +9 -1
- data/.github/PULL_REQUEST_TEMPLATE.md +3 -2
- data/.github/workflows/release.yml +0 -1
- data/.github/workflows/triage.yml +22 -0
- data/.rubocop.yml +21 -7
- data/.rubocop_todo.yml +2 -15
- data/.travis.yml +1 -1
- data/CHANGELOG.md +28 -0
- data/Gemfile +12 -11
- data/Gemfile.lock +17 -14
- data/README.md +39 -7
- data/RELEASING.md +5 -13
- data/Rakefile +32 -28
- data/bin/load_shopify.rb +6 -6
- data/bin/shopify +2 -2
- data/dev.yml +2 -2
- data/docs/_config.yml +1 -18
- data/docs/app/node/commands/index.md +2 -80
- data/docs/app/node/index.md +2 -33
- data/docs/app/rails/commands/index.md +2 -78
- data/docs/app/rails/index.md +2 -34
- data/docs/core/index.md +2 -84
- data/docs/getting-started/index.md +2 -25
- data/docs/getting-started/install/index.md +1 -118
- data/docs/getting-started/migrate/index.md +2 -94
- data/docs/getting-started/uninstall/index.md +2 -35
- data/docs/getting-started/upgrade/index.md +2 -39
- data/docs/help/start-app/index.md +2 -4
- data/docs/index.md +2 -24
- data/ext/shopify-cli/extconf.rb +7 -7
- data/install.sh +1 -1
- data/lib/docgen/markdown.rb +12 -12
- data/lib/graphql/fetch_specifications.graphql +14 -0
- data/lib/{project_types/extension/graphql → graphql}/get_app_by_api_key.graphql +0 -0
- data/lib/project_types/extension/cli.rb +54 -47
- data/lib/project_types/extension/commands/build.rb +3 -3
- data/lib/project_types/extension/commands/create.rb +17 -10
- data/lib/project_types/extension/commands/extension_command.rb +12 -5
- data/lib/project_types/extension/commands/push.rb +8 -8
- data/lib/project_types/extension/commands/register.rb +19 -30
- data/lib/project_types/extension/commands/serve.rb +31 -3
- data/lib/project_types/extension/commands/tunnel.rb +12 -12
- data/lib/project_types/extension/extension_project.rb +8 -4
- data/lib/project_types/extension/extension_project_keys.rb +4 -4
- data/lib/project_types/extension/features/argo.rb +117 -0
- data/lib/project_types/extension/features/argo_config.rb +5 -5
- data/lib/project_types/extension/features/argo_dependencies.rb +5 -5
- data/lib/project_types/extension/features/argo_setup.rb +2 -2
- data/lib/project_types/extension/features/argo_setup_steps.rb +4 -4
- data/lib/project_types/extension/forms/create.rb +28 -34
- data/lib/project_types/extension/forms/questions/ask_app.rb +53 -0
- data/lib/project_types/extension/forms/questions/ask_name.rb +40 -0
- data/lib/project_types/extension/forms/questions/ask_type.rb +47 -0
- data/lib/project_types/extension/messages/messages.rb +55 -52
- data/lib/project_types/extension/models/lazy_specification_handler.rb +12 -0
- data/lib/project_types/extension/models/specification.rb +37 -0
- data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +19 -0
- data/lib/project_types/extension/models/specification_handlers/default.rb +67 -0
- data/lib/project_types/extension/models/specifications.rb +88 -0
- data/lib/project_types/extension/tasks/configure_features.rb +52 -0
- data/lib/project_types/extension/tasks/converters/app_converter.rb +6 -6
- data/lib/project_types/extension/tasks/converters/registration_converter.rb +6 -6
- data/lib/project_types/extension/tasks/converters/validation_error_converter.rb +4 -4
- data/lib/project_types/extension/tasks/converters/version_converter.rb +7 -7
- data/lib/project_types/extension/tasks/create_extension.rb +4 -4
- data/lib/project_types/extension/tasks/fetch_specifications.rb +18 -0
- data/lib/project_types/extension/tasks/get_app.rb +4 -4
- data/lib/project_types/extension/tasks/get_apps.rb +3 -3
- data/lib/project_types/extension/tasks/update_draft.rb +4 -4
- data/lib/project_types/extension/tasks/user_errors.rb +4 -4
- data/lib/project_types/node/cli.rb +19 -16
- data/lib/project_types/node/commands/connect.rb +15 -0
- data/lib/project_types/node/commands/create.rb +44 -41
- data/lib/project_types/node/commands/deploy.rb +4 -4
- data/lib/project_types/node/commands/deploy/heroku.rb +24 -24
- data/lib/project_types/node/commands/generate.rb +9 -18
- data/lib/project_types/node/commands/open.rb +2 -2
- data/lib/project_types/node/commands/populate.rb +6 -6
- data/lib/project_types/node/commands/populate/customer.rb +5 -5
- data/lib/project_types/node/commands/populate/draft_order.rb +5 -5
- data/lib/project_types/node/commands/populate/product.rb +5 -5
- data/lib/project_types/node/commands/serve.rb +9 -9
- data/lib/project_types/node/commands/tunnel.rb +7 -7
- data/lib/project_types/node/forms/create.rb +17 -8
- data/lib/project_types/node/messages/messages.rb +20 -53
- data/lib/project_types/rails/cli.rb +21 -18
- data/lib/project_types/rails/commands/connect.rb +15 -0
- data/lib/project_types/rails/commands/create.rb +58 -57
- data/lib/project_types/rails/commands/deploy.rb +4 -4
- data/lib/project_types/rails/commands/deploy/heroku.rb +30 -30
- data/lib/project_types/rails/commands/generate.rb +7 -7
- data/lib/project_types/rails/commands/generate/webhook.rb +6 -6
- data/lib/project_types/rails/commands/open.rb +2 -2
- data/lib/project_types/rails/commands/populate.rb +6 -6
- data/lib/project_types/rails/commands/populate/customer.rb +5 -5
- data/lib/project_types/rails/commands/populate/draft_order.rb +5 -5
- data/lib/project_types/rails/commands/populate/product.rb +5 -5
- data/lib/project_types/rails/commands/serve.rb +11 -11
- data/lib/project_types/rails/commands/tunnel.rb +7 -7
- data/lib/project_types/rails/forms/create.rb +35 -25
- data/lib/project_types/rails/gem.rb +24 -24
- data/lib/project_types/rails/messages/messages.rb +13 -9
- data/lib/project_types/rails/ruby.rb +2 -2
- data/lib/project_types/script/cli.rb +44 -38
- data/lib/project_types/script/commands/create.rb +15 -10
- data/lib/project_types/script/commands/disable.rb +3 -3
- data/lib/project_types/script/commands/enable.rb +19 -9
- data/lib/project_types/script/commands/push.rb +10 -17
- data/lib/project_types/script/config/extension_points.yml +30 -12
- data/lib/project_types/script/errors.rb +22 -0
- data/lib/project_types/script/forms/create.rb +29 -5
- data/lib/project_types/script/graphql/app_script_update_or_create.graphql +12 -1
- data/lib/project_types/script/layers/application/build_script.rb +19 -19
- data/lib/project_types/script/layers/application/create_script.rb +45 -12
- data/lib/project_types/script/layers/application/disable_script.rb +2 -2
- data/lib/project_types/script/layers/application/enable_script.rb +2 -2
- data/lib/project_types/script/layers/application/extension_points.rb +24 -0
- data/lib/project_types/script/layers/application/project_dependencies.rb +4 -4
- data/lib/project_types/script/layers/application/push_script.rb +15 -18
- data/lib/project_types/script/layers/domain/config_ui.rb +16 -0
- data/lib/project_types/script/layers/domain/errors.rb +23 -0
- data/lib/project_types/script/layers/domain/extension_point.rb +67 -7
- data/lib/project_types/script/layers/domain/metadata.rb +55 -0
- data/lib/project_types/script/layers/domain/push_package.rb +29 -6
- data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +45 -55
- data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +41 -45
- data/lib/project_types/script/layers/infrastructure/config_ui_repository.rb +46 -0
- data/lib/project_types/script/layers/infrastructure/errors.rb +32 -5
- data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +12 -6
- data/lib/project_types/script/layers/infrastructure/project_creator.rb +2 -1
- data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +20 -13
- data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +72 -0
- data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +59 -0
- data/lib/project_types/script/layers/infrastructure/script_service.rb +39 -17
- data/lib/project_types/script/layers/infrastructure/task_runner.rb +4 -3
- data/lib/project_types/script/messages/messages.rb +76 -10
- data/lib/project_types/script/script_project.rb +26 -16
- data/lib/project_types/script/ui/error_handler.rb +135 -50
- data/lib/project_types/script/ui/printing_spinner.rb +1 -1
- data/lib/project_types/script/ui/strict_spinner.rb +1 -1
- data/lib/project_types/theme/cli.rb +40 -0
- data/lib/project_types/theme/commands/connect.rb +54 -0
- data/lib/project_types/theme/commands/create.rb +48 -0
- data/lib/project_types/theme/commands/deploy.rb +38 -0
- data/lib/project_types/theme/commands/generate.rb +20 -0
- data/lib/project_types/theme/commands/generate/env.rb +79 -0
- data/lib/project_types/theme/commands/push.rb +55 -0
- data/lib/project_types/theme/commands/serve.rb +31 -0
- data/lib/project_types/theme/forms/connect.rb +34 -0
- data/lib/project_types/theme/forms/create.rb +22 -0
- data/lib/project_types/theme/messages/messages.rb +147 -0
- data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +78 -0
- data/lib/project_types/theme/themekit.rb +113 -0
- data/lib/rubygems_plugin.rb +3 -3
- data/lib/shopify-cli/admin_api.rb +52 -12
- data/lib/shopify-cli/admin_api/populate_resource_command.rb +17 -17
- data/lib/shopify-cli/admin_api/schema.rb +3 -3
- data/lib/shopify-cli/api.rb +36 -31
- data/lib/shopify-cli/command.rb +1 -1
- data/lib/shopify-cli/commands.rb +9 -9
- data/lib/shopify-cli/commands/config.rb +28 -28
- data/lib/shopify-cli/commands/connect.rb +35 -18
- data/lib/shopify-cli/commands/create.rb +5 -5
- data/lib/shopify-cli/commands/help.rb +6 -6
- data/lib/shopify-cli/commands/logout.rb +3 -3
- data/lib/shopify-cli/commands/system.rb +33 -33
- data/lib/shopify-cli/commands/version.rb +2 -2
- data/lib/shopify-cli/context.rb +43 -22
- data/lib/shopify-cli/core.rb +4 -4
- data/lib/shopify-cli/core/entry_point.rb +5 -5
- data/lib/shopify-cli/core/executor.rb +1 -1
- data/lib/shopify-cli/core/help_resolver.rb +2 -2
- data/lib/shopify-cli/core/monorail.rb +17 -16
- data/lib/shopify-cli/db.rb +2 -2
- data/lib/shopify-cli/feature.rb +1 -3
- data/lib/shopify-cli/form.rb +1 -1
- data/lib/shopify-cli/git.rb +17 -17
- data/lib/shopify-cli/helpers.rb +1 -1
- data/lib/shopify-cli/helpers/haikunator.rb +1 -1
- data/lib/shopify-cli/heroku.rb +28 -28
- data/lib/shopify-cli/http_request.rb +21 -9
- data/lib/shopify-cli/js_deps.rb +13 -13
- data/lib/shopify-cli/js_system.rb +5 -5
- data/lib/shopify-cli/lazy_delegator.rb +55 -0
- data/lib/shopify-cli/messages/messages.rb +21 -10
- data/lib/shopify-cli/method_object.rb +104 -0
- data/lib/shopify-cli/oauth.rb +25 -25
- data/lib/shopify-cli/oauth/servlet.rb +9 -9
- data/lib/shopify-cli/options.rb +3 -3
- data/lib/shopify-cli/packager.rb +24 -24
- data/lib/shopify-cli/partners_api.rb +38 -16
- data/lib/shopify-cli/partners_api/organizations.rb +10 -10
- data/lib/shopify-cli/process_supervision.rb +8 -8
- data/lib/shopify-cli/project.rb +27 -23
- data/lib/shopify-cli/project_type.rb +21 -5
- data/lib/shopify-cli/resolve_constant.rb +25 -0
- data/lib/shopify-cli/resources.rb +1 -1
- data/lib/shopify-cli/resources/env_file.rb +9 -9
- data/lib/shopify-cli/result.rb +432 -0
- data/lib/shopify-cli/shopifolk.rb +35 -18
- data/lib/shopify-cli/sub_command.rb +1 -1
- data/lib/shopify-cli/task.rb +9 -1
- data/lib/shopify-cli/tasks.rb +7 -7
- data/lib/shopify-cli/tasks/create_api_client.rb +13 -4
- data/lib/shopify-cli/tasks/ensure_dev_store.rb +12 -12
- data/lib/shopify-cli/tasks/ensure_env.rb +18 -15
- data/lib/shopify-cli/tasks/ensure_loopback_url.rb +4 -4
- data/lib/shopify-cli/tasks/select_org_and_shop.rb +28 -24
- data/lib/shopify-cli/tasks/update_dashboard_urls.rb +10 -10
- data/lib/shopify-cli/transform_data_structure.rb +86 -0
- data/lib/shopify-cli/tunnel.rb +36 -30
- data/lib/shopify-cli/version.rb +1 -1
- data/lib/shopify_cli.rb +57 -52
- data/shopify-cli.gemspec +6 -6
- data/shopify.fish +1 -1
- data/shopify.sh +1 -1
- data/vendor/deps/cli-kit/REVISION +1 -1
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +2 -2
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +3 -3
- data/vendor/deps/cli-ui/REVISION +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui.rb +26 -22
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +4 -6
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -3
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +8 -9
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +15 -3
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +4 -11
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -5
- data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +10 -10
- data/vendor/deps/cli-ui/lib/cli/ui/version.rb +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +56 -0
- data/vendor/deps/webrick/.gitignore +9 -0
- data/vendor/deps/webrick/Gemfile +3 -0
- data/vendor/deps/webrick/LICENSE.txt +22 -0
- data/vendor/deps/webrick/README.md +61 -0
- data/vendor/deps/webrick/Rakefile +10 -0
- data/vendor/deps/webrick/lib/webrick.rb +232 -0
- data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
- data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
- data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
- data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
- data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
- data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
- data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
- data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
- data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
- data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
- data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
- data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
- data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
- data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
- data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
- data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
- data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
- data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
- data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
- data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
- data/vendor/deps/webrick/webrick.gemspec +74 -0
- data/vendor/gen/template/bin/update-deps +9 -9
- metadata +83 -29
- data/docs/Gemfile +0 -5
- data/docs/Gemfile.lock +0 -258
- data/docs/_data/nav.yml +0 -35
- data/docs/_includes/footer.html +0 -15
- data/docs/_includes/head.html +0 -19
- data/docs/_includes/sidebar_nav.html +0 -22
- data/docs/_includes/toc.html +0 -112
- data/docs/_layouts/default.html +0 -79
- data/docs/css/docs.css +0 -157
- data/docs/images/header.png +0 -0
- data/docs/installing-ruby.md +0 -28
- data/lib/project_types/extension/features/argo/admin.rb +0 -20
- data/lib/project_types/extension/features/argo/base.rb +0 -129
- data/lib/project_types/extension/features/argo/checkout.rb +0 -20
- data/lib/project_types/extension/forms/register.rb +0 -47
- data/lib/project_types/extension/models/type.rb +0 -81
- data/lib/project_types/extension/models/types/checkout_post_purchase.rb +0 -23
- data/lib/project_types/extension/models/types/product_subscription.rb +0 -24
- data/lib/project_types/node/commands/generate/billing.rb +0 -39
- data/lib/project_types/node/commands/generate/page.rb +0 -59
- data/lib/project_types/node/commands/generate/webhook.rb +0 -37
- data/lib/project_types/script/layers/domain/script.rb +0 -18
- data/lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb +0 -38
- data/lib/project_types/script/layers/infrastructure/script_repository.rb +0 -59
- data/lib/project_types/script/templates/ts/as-pect.config.js +0 -27
- data/lib/project_types/script/templates/ts/as-pect.d.ts +0 -1
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#--
|
3
|
+
# accesslog.rb -- Access log handling utilities
|
4
|
+
#
|
5
|
+
# Author: IPR -- Internet Programming with Ruby -- writers
|
6
|
+
# Copyright (c) 2002 keita yamaguchi
|
7
|
+
# Copyright (c) 2002 Internet Programming with Ruby writers
|
8
|
+
#
|
9
|
+
# $IPR: accesslog.rb,v 1.1 2002/10/01 17:16:32 gotoyuzo Exp $
|
10
|
+
|
11
|
+
module WEBrick
|
12
|
+
|
13
|
+
##
|
14
|
+
# AccessLog provides logging to various files in various formats.
|
15
|
+
#
|
16
|
+
# Multiple logs may be written to at the same time:
|
17
|
+
#
|
18
|
+
# access_log = [
|
19
|
+
# [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
|
20
|
+
# [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
|
21
|
+
# ]
|
22
|
+
#
|
23
|
+
# server = WEBrick::HTTPServer.new :AccessLog => access_log
|
24
|
+
#
|
25
|
+
# Custom log formats may be defined. WEBrick::AccessLog provides a subset
|
26
|
+
# of the formatting from Apache's mod_log_config
|
27
|
+
# http://httpd.apache.org/docs/mod/mod_log_config.html#formats. See
|
28
|
+
# AccessLog::setup_params for a list of supported options
|
29
|
+
|
30
|
+
module AccessLog
|
31
|
+
|
32
|
+
##
|
33
|
+
# Raised if a parameter such as %e, %i, %o or %n is used without fetching
|
34
|
+
# a specific field.
|
35
|
+
|
36
|
+
class AccessLogError < StandardError; end
|
37
|
+
|
38
|
+
##
|
39
|
+
# The Common Log Format's time format
|
40
|
+
|
41
|
+
CLF_TIME_FORMAT = "[%d/%b/%Y:%H:%M:%S %Z]"
|
42
|
+
|
43
|
+
##
|
44
|
+
# Common Log Format
|
45
|
+
|
46
|
+
COMMON_LOG_FORMAT = "%h %l %u %t \"%r\" %s %b"
|
47
|
+
|
48
|
+
##
|
49
|
+
# Short alias for Common Log Format
|
50
|
+
|
51
|
+
CLF = COMMON_LOG_FORMAT
|
52
|
+
|
53
|
+
##
|
54
|
+
# Referer Log Format
|
55
|
+
|
56
|
+
REFERER_LOG_FORMAT = "%{Referer}i -> %U"
|
57
|
+
|
58
|
+
##
|
59
|
+
# User-Agent Log Format
|
60
|
+
|
61
|
+
AGENT_LOG_FORMAT = "%{User-Agent}i"
|
62
|
+
|
63
|
+
##
|
64
|
+
# Combined Log Format
|
65
|
+
|
66
|
+
COMBINED_LOG_FORMAT = "#{CLF} \"%{Referer}i\" \"%{User-agent}i\""
|
67
|
+
|
68
|
+
module_function
|
69
|
+
|
70
|
+
# This format specification is a subset of mod_log_config of Apache:
|
71
|
+
#
|
72
|
+
# %a:: Remote IP address
|
73
|
+
# %b:: Total response size
|
74
|
+
# %e{variable}:: Given variable in ENV
|
75
|
+
# %f:: Response filename
|
76
|
+
# %h:: Remote host name
|
77
|
+
# %{header}i:: Given request header
|
78
|
+
# %l:: Remote logname, always "-"
|
79
|
+
# %m:: Request method
|
80
|
+
# %{attr}n:: Given request attribute from <tt>req.attributes</tt>
|
81
|
+
# %{header}o:: Given response header
|
82
|
+
# %p:: Server's request port
|
83
|
+
# %{format}p:: The canonical port of the server serving the request or the
|
84
|
+
# actual port or the client's actual port. Valid formats are
|
85
|
+
# canonical, local or remote.
|
86
|
+
# %q:: Request query string
|
87
|
+
# %r:: First line of the request
|
88
|
+
# %s:: Request status
|
89
|
+
# %t:: Time the request was received
|
90
|
+
# %T:: Time taken to process the request
|
91
|
+
# %u:: Remote user from auth
|
92
|
+
# %U:: Unparsed URI
|
93
|
+
# %%:: Literal %
|
94
|
+
|
95
|
+
def setup_params(config, req, res)
|
96
|
+
params = Hash.new("")
|
97
|
+
params["a"] = req.peeraddr[3]
|
98
|
+
params["b"] = res.sent_size
|
99
|
+
params["e"] = ENV
|
100
|
+
params["f"] = res.filename || ""
|
101
|
+
params["h"] = req.peeraddr[2]
|
102
|
+
params["i"] = req
|
103
|
+
params["l"] = "-"
|
104
|
+
params["m"] = req.request_method
|
105
|
+
params["n"] = req.attributes
|
106
|
+
params["o"] = res
|
107
|
+
params["p"] = req.port
|
108
|
+
params["q"] = req.query_string
|
109
|
+
params["r"] = req.request_line.sub(/\x0d?\x0a\z/o, '')
|
110
|
+
params["s"] = res.status # won't support "%>s"
|
111
|
+
params["t"] = req.request_time
|
112
|
+
params["T"] = Time.now - req.request_time
|
113
|
+
params["u"] = req.user || "-"
|
114
|
+
params["U"] = req.unparsed_uri
|
115
|
+
params["v"] = config[:ServerName]
|
116
|
+
params
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Formats +params+ according to +format_string+ which is described in
|
121
|
+
# setup_params.
|
122
|
+
|
123
|
+
def format(format_string, params)
|
124
|
+
format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
|
125
|
+
param, spec = $1, $2
|
126
|
+
case spec[0]
|
127
|
+
when ?e, ?i, ?n, ?o
|
128
|
+
raise AccessLogError,
|
129
|
+
"parameter is required for \"#{spec}\"" unless param
|
130
|
+
(param = params[spec][param]) ? escape(param) : "-"
|
131
|
+
when ?t
|
132
|
+
params[spec].strftime(param || CLF_TIME_FORMAT)
|
133
|
+
when ?p
|
134
|
+
case param
|
135
|
+
when 'remote'
|
136
|
+
escape(params["i"].peeraddr[1].to_s)
|
137
|
+
else
|
138
|
+
escape(params["p"].to_s)
|
139
|
+
end
|
140
|
+
when ?%
|
141
|
+
"%"
|
142
|
+
else
|
143
|
+
escape(params[spec].to_s)
|
144
|
+
end
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Escapes control characters in +data+
|
150
|
+
|
151
|
+
def escape(data)
|
152
|
+
data = data.gsub(/[[:cntrl:]\\]+/) {$&.dump[1...-1]}
|
153
|
+
data.untaint if RUBY_VERSION < '2.7'
|
154
|
+
data
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,313 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# cgi.rb -- Yet another CGI library
|
4
|
+
#
|
5
|
+
# Author: IPR -- Internet Programming with Ruby -- writers
|
6
|
+
# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
|
7
|
+
# reserved.
|
8
|
+
#
|
9
|
+
# $Id$
|
10
|
+
|
11
|
+
require_relative "httprequest"
|
12
|
+
require_relative "httpresponse"
|
13
|
+
require_relative "config"
|
14
|
+
require "stringio"
|
15
|
+
|
16
|
+
module WEBrick
|
17
|
+
|
18
|
+
# A CGI library using WEBrick requests and responses.
|
19
|
+
#
|
20
|
+
# Example:
|
21
|
+
#
|
22
|
+
# class MyCGI < WEBrick::CGI
|
23
|
+
# def do_GET req, res
|
24
|
+
# res.body = 'it worked!'
|
25
|
+
# res.status = 200
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# MyCGI.new.start
|
30
|
+
|
31
|
+
class CGI
|
32
|
+
|
33
|
+
# The CGI error exception class
|
34
|
+
|
35
|
+
CGIError = Class.new(StandardError)
|
36
|
+
|
37
|
+
##
|
38
|
+
# The CGI configuration. This is based on WEBrick::Config::HTTP
|
39
|
+
|
40
|
+
attr_reader :config
|
41
|
+
|
42
|
+
##
|
43
|
+
# The CGI logger
|
44
|
+
|
45
|
+
attr_reader :logger
|
46
|
+
|
47
|
+
##
|
48
|
+
# Creates a new CGI interface.
|
49
|
+
#
|
50
|
+
# The first argument in +args+ is a configuration hash which would update
|
51
|
+
# WEBrick::Config::HTTP.
|
52
|
+
#
|
53
|
+
# Any remaining arguments are stored in the <code>@options</code> instance
|
54
|
+
# variable for use by a subclass.
|
55
|
+
|
56
|
+
def initialize(*args)
|
57
|
+
if defined?(MOD_RUBY)
|
58
|
+
unless ENV.has_key?("GATEWAY_INTERFACE")
|
59
|
+
Apache.request.setup_cgi_env
|
60
|
+
end
|
61
|
+
end
|
62
|
+
if %r{HTTP/(\d+\.\d+)} =~ ENV["SERVER_PROTOCOL"]
|
63
|
+
httpv = $1
|
64
|
+
end
|
65
|
+
@config = WEBrick::Config::HTTP.dup.update(
|
66
|
+
:ServerSoftware => ENV["SERVER_SOFTWARE"] || "null",
|
67
|
+
:HTTPVersion => HTTPVersion.new(httpv || "1.0"),
|
68
|
+
:RunOnCGI => true, # to detect if it runs on CGI.
|
69
|
+
:NPH => false # set true to run as NPH script.
|
70
|
+
)
|
71
|
+
if config = args.shift
|
72
|
+
@config.update(config)
|
73
|
+
end
|
74
|
+
@config[:Logger] ||= WEBrick::BasicLog.new($stderr)
|
75
|
+
@logger = @config[:Logger]
|
76
|
+
@options = args
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Reads +key+ from the configuration
|
81
|
+
|
82
|
+
def [](key)
|
83
|
+
@config[key]
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Starts the CGI process with the given environment +env+ and standard
|
88
|
+
# input and output +stdin+ and +stdout+.
|
89
|
+
|
90
|
+
def start(env=ENV, stdin=$stdin, stdout=$stdout)
|
91
|
+
sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
|
92
|
+
req = HTTPRequest.new(@config)
|
93
|
+
res = HTTPResponse.new(@config)
|
94
|
+
unless @config[:NPH] or defined?(MOD_RUBY)
|
95
|
+
def res.setup_header
|
96
|
+
unless @header["status"]
|
97
|
+
phrase = HTTPStatus::reason_phrase(@status)
|
98
|
+
@header["status"] = "#{@status} #{phrase}"
|
99
|
+
end
|
100
|
+
super
|
101
|
+
end
|
102
|
+
def res.status_line
|
103
|
+
""
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
begin
|
108
|
+
req.parse(sock)
|
109
|
+
req.script_name = (env["SCRIPT_NAME"] || File.expand_path($0)).dup
|
110
|
+
req.path_info = (env["PATH_INFO"] || "").dup
|
111
|
+
req.query_string = env["QUERY_STRING"]
|
112
|
+
req.user = env["REMOTE_USER"]
|
113
|
+
res.request_method = req.request_method
|
114
|
+
res.request_uri = req.request_uri
|
115
|
+
res.request_http_version = req.http_version
|
116
|
+
res.keep_alive = req.keep_alive?
|
117
|
+
self.service(req, res)
|
118
|
+
rescue HTTPStatus::Error => ex
|
119
|
+
res.set_error(ex)
|
120
|
+
rescue HTTPStatus::Status => ex
|
121
|
+
res.status = ex.code
|
122
|
+
rescue Exception => ex
|
123
|
+
@logger.error(ex)
|
124
|
+
res.set_error(ex, true)
|
125
|
+
ensure
|
126
|
+
req.fixup
|
127
|
+
if defined?(MOD_RUBY)
|
128
|
+
res.setup_header
|
129
|
+
Apache.request.status_line = "#{res.status} #{res.reason_phrase}"
|
130
|
+
Apache.request.status = res.status
|
131
|
+
table = Apache.request.headers_out
|
132
|
+
res.header.each{|key, val|
|
133
|
+
case key
|
134
|
+
when /^content-encoding$/i
|
135
|
+
Apache::request.content_encoding = val
|
136
|
+
when /^content-type$/i
|
137
|
+
Apache::request.content_type = val
|
138
|
+
else
|
139
|
+
table[key] = val.to_s
|
140
|
+
end
|
141
|
+
}
|
142
|
+
res.cookies.each{|cookie|
|
143
|
+
table.add("Set-Cookie", cookie.to_s)
|
144
|
+
}
|
145
|
+
Apache.request.send_http_header
|
146
|
+
res.send_body(sock)
|
147
|
+
else
|
148
|
+
res.send_response(sock)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Services the request +req+ which will fill in the response +res+. See
|
155
|
+
# WEBrick::HTTPServlet::AbstractServlet#service for details.
|
156
|
+
|
157
|
+
def service(req, res)
|
158
|
+
method_name = "do_" + req.request_method.gsub(/-/, "_")
|
159
|
+
if respond_to?(method_name)
|
160
|
+
__send__(method_name, req, res)
|
161
|
+
else
|
162
|
+
raise HTTPStatus::MethodNotAllowed,
|
163
|
+
"unsupported method `#{req.request_method}'."
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
##
|
168
|
+
# Provides HTTP socket emulation from the CGI environment
|
169
|
+
|
170
|
+
class Socket # :nodoc:
|
171
|
+
include Enumerable
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
def initialize(config, env, stdin, stdout)
|
176
|
+
@config = config
|
177
|
+
@env = env
|
178
|
+
@header_part = StringIO.new
|
179
|
+
@body_part = stdin
|
180
|
+
@out_port = stdout
|
181
|
+
@out_port.binmode
|
182
|
+
|
183
|
+
@server_addr = @env["SERVER_ADDR"] || "0.0.0.0"
|
184
|
+
@server_name = @env["SERVER_NAME"]
|
185
|
+
@server_port = @env["SERVER_PORT"]
|
186
|
+
@remote_addr = @env["REMOTE_ADDR"]
|
187
|
+
@remote_host = @env["REMOTE_HOST"] || @remote_addr
|
188
|
+
@remote_port = @env["REMOTE_PORT"] || 0
|
189
|
+
|
190
|
+
begin
|
191
|
+
@header_part << request_line << CRLF
|
192
|
+
setup_header
|
193
|
+
@header_part << CRLF
|
194
|
+
@header_part.rewind
|
195
|
+
rescue Exception
|
196
|
+
raise CGIError, "invalid CGI environment"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def request_line
|
201
|
+
meth = @env["REQUEST_METHOD"] || "GET"
|
202
|
+
unless url = @env["REQUEST_URI"]
|
203
|
+
url = (@env["SCRIPT_NAME"] || File.expand_path($0)).dup
|
204
|
+
url << @env["PATH_INFO"].to_s
|
205
|
+
url = WEBrick::HTTPUtils.escape_path(url)
|
206
|
+
if query_string = @env["QUERY_STRING"]
|
207
|
+
unless query_string.empty?
|
208
|
+
url << "?" << query_string
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
# we cannot get real HTTP version of client ;)
|
213
|
+
httpv = @config[:HTTPVersion]
|
214
|
+
return "#{meth} #{url} HTTP/#{httpv}"
|
215
|
+
end
|
216
|
+
|
217
|
+
def setup_header
|
218
|
+
@env.each{|key, value|
|
219
|
+
case key
|
220
|
+
when "CONTENT_TYPE", "CONTENT_LENGTH"
|
221
|
+
add_header(key.gsub(/_/, "-"), value)
|
222
|
+
when /^HTTP_(.*)/
|
223
|
+
add_header($1.gsub(/_/, "-"), value)
|
224
|
+
end
|
225
|
+
}
|
226
|
+
end
|
227
|
+
|
228
|
+
def add_header(hdrname, value)
|
229
|
+
unless value.empty?
|
230
|
+
@header_part << hdrname << ": " << value << CRLF
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def input
|
235
|
+
@header_part.eof? ? @body_part : @header_part
|
236
|
+
end
|
237
|
+
|
238
|
+
public
|
239
|
+
|
240
|
+
def peeraddr
|
241
|
+
[nil, @remote_port, @remote_host, @remote_addr]
|
242
|
+
end
|
243
|
+
|
244
|
+
def addr
|
245
|
+
[nil, @server_port, @server_name, @server_addr]
|
246
|
+
end
|
247
|
+
|
248
|
+
def gets(eol=LF, size=nil)
|
249
|
+
input.gets(eol, size)
|
250
|
+
end
|
251
|
+
|
252
|
+
def read(size=nil)
|
253
|
+
input.read(size)
|
254
|
+
end
|
255
|
+
|
256
|
+
def each
|
257
|
+
input.each{|line| yield(line) }
|
258
|
+
end
|
259
|
+
|
260
|
+
def eof?
|
261
|
+
input.eof?
|
262
|
+
end
|
263
|
+
|
264
|
+
def <<(data)
|
265
|
+
@out_port << data
|
266
|
+
end
|
267
|
+
|
268
|
+
def write(data)
|
269
|
+
@out_port.write(data)
|
270
|
+
end
|
271
|
+
|
272
|
+
def cert
|
273
|
+
return nil unless defined?(OpenSSL)
|
274
|
+
if pem = @env["SSL_SERVER_CERT"]
|
275
|
+
OpenSSL::X509::Certificate.new(pem) unless pem.empty?
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def peer_cert
|
280
|
+
return nil unless defined?(OpenSSL)
|
281
|
+
if pem = @env["SSL_CLIENT_CERT"]
|
282
|
+
OpenSSL::X509::Certificate.new(pem) unless pem.empty?
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
def peer_cert_chain
|
287
|
+
return nil unless defined?(OpenSSL)
|
288
|
+
if @env["SSL_CLIENT_CERT_CHAIN_0"]
|
289
|
+
keys = @env.keys
|
290
|
+
certs = keys.sort.collect{|k|
|
291
|
+
if /^SSL_CLIENT_CERT_CHAIN_\d+$/ =~ k
|
292
|
+
if pem = @env[k]
|
293
|
+
OpenSSL::X509::Certificate.new(pem) unless pem.empty?
|
294
|
+
end
|
295
|
+
end
|
296
|
+
}
|
297
|
+
certs.compact
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def cipher
|
302
|
+
return nil unless defined?(OpenSSL)
|
303
|
+
if cipher = @env["SSL_CIPHER"]
|
304
|
+
ret = [ cipher ]
|
305
|
+
ret << @env["SSL_PROTOCOL"]
|
306
|
+
ret << @env["SSL_CIPHER_USEKEYSIZE"]
|
307
|
+
ret << @env["SSL_CIPHER_ALGKEYSIZE"]
|
308
|
+
ret
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|