技術的なことはまったくわからねーが Cloudflare Worker ってのをさわんねーといけね Cloudflare R2 ってとこにファイルを置けば簡単に静的ウェブサイトができるってんでやってみたら, /にアクセスしてもindex.htmlが公開されないということが分かった. https://example.com ではページは見られなくて, https://example.com/index.html と指定しないといけないわけだ. やってみるまでわからなかったからまあ勉強になったよね. どうするかというと Cloudflare Worker ってやつを噛ませるようだ. その設定は denoflare ってプログラムでやるといい感じになるらしくって, その denoflare をインストールするためには deno ってプログラムが必要だって話だ. これだけでめんどうな匂いがするよね. ここまででだいぶ舐めてたことがおわかりいただけると思う Easily make your R2 bucket publicly-readable on your own domain 自分は macOS なんで deno は homebrew でインストールするよ. こんな感じでインストールしたけれど エラーで躓いてしまった. # homebrew で deno をインストール # https://denoflare.dev/cli/#installation # https://docs.deno.com/runtime/getting_started/installation/#download-and-install brew install deno # deno で denoflare をインストール # https://denoflare.dev/cli/#installation deno install --unstable-worker-options --allow-read --allow-net --allow-env --allow-run --name denoflare --force https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/cli.ts # error: the following required arguments were not provided: # --global # Note: Permission flags can only be used in a global setting # --global フラグをつけて再度インストール deno install --global --unstable-worker-options --allow-read --allow-net --allow-env --allow-run --name denoflare --force https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/cli.ts # cloudflare の ウェブ管理画面で受け入れ準備を済ませて denoflare で設定を cloudflare に push する # https://denoflare.dev/examples/r2-public-read denoflare push 'https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/examples/r2-public-read-worker/worker.ts' \ --name ${MY_BUCKET}-public-read \ --r2-bucket-binding bucket:"${MY_BUCKET}" \ --text-binding flags:listDirectories,emulatePages \ --text-binding 'allowCorsOrigins:\*' \ --custom-domain "${MY_SUBDOMAIN}" \ --account-id "${ACCOUNT_ID}" \ --api-token "${API_TOKEN}" # bundling memo-public-read into bundle.js... # TS0: error: unexpected argument 'https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/examples/r2-public-read-worker/worker.ts' found # Usage: deno bundle [OPTIONS] # at undefined: # error: Uncaught (in promise) Error: bundle failed # throw new Error('bundle failed'); # ^ # at bundle (https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/bundle.ts:108:15) # at eventLoopTick (ext:core/01_core.js:177:7) # at async buildAndPutScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/cli_push.ts:57:28) # at async Object.push [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/cli_push.ts:124:5) # at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/cli_command.ts:104:13) # at async https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/cli.ts:41:5 インストールしたプログラムのそれぞれのバージョンをチェックする denoflare version # 0.6.0 deno --version # deno 2.2.4 (stable, release, aarch64-apple-darwin) # v8 13.4.114.11-rusty # typescript 5.7.3 deno と denoflare のバージョンのミスマッチが怪しいので, deno のバージョンを 1.x 系にバージョンを落とせないか調べる. asdf ってのがあるんだ… くぁwせdrftgyふじこlp リスペクトでしょ. deno uninstall denoflare brew uninstall deno # https://docs.deno.com/runtime/getting_started/installation/#download-and-install brew install asdf asdf plugin add deno # deno の1.x系のバージョンを調べる asdf list all deno asdf install deno 1.46.3 asdf set deno 1.46.3 asdf current deno # Name Version Source Installed # deno 1.46.3 /Users/me/.tool-versions true deno 1.x 系で再度 push する deno # zsh: command not found: deno # asdf.sh を shell の rc に登録する? 面倒だったので手動で読み込みした. source /opt/homebrew/opt/asdf/libexec/asdf.sh # もう一度 deno install --global --unstable-worker-options --allow-read --allow-net --allow-env --allow-run --name denoflare --force https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/cli/cli.ts denoflare # zsh: command not found: denoflare # PATH に登録する? 面倒だったので絶対パスを指定した. /Users/me/.asdf/installs/deno/1.46.3/.deno/bin/denoflare push https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/examples/r2-public-read-worker/worker.ts \ --name ${MY_BUCKET}-public-read \ --r2-bucket-binding bucket:"${MY_BUCKET}" \ --text-binding flags:listDirectories,emulatePages \ --text-binding 'allowCorsOrigins:\*' \ --custom-domain "${MY_SUBDOMAIN}" \ --account-id "${ACCOUNT_ID}" \ --api-token "${API_TOKEN}" # bundling memo-public-read into bundle.js... # bundle finished (process) in 752ms # computed bindings in 1ms # putting module-based worker memo-public-read... (14.6kb) (4.2kb compressed) # put script memo-public-read in 2236ms # ensuring memo.montaworks.com points to memo-public-read... # bound worker to custom domain in 776ms できた…けど, たぶん一度限りの作業だと思う とても面倒だったので, そのうちCloudflareの設定画面で簡単にできるようになるのではないかな? ...
Speed Wi-Fi HOME 5G L12 ホームルータの調整
メルカリの業者さん垢から中古を買った L12 は NEC 製のルータで比較的お求めやすい値段で中古が売りに出されている. 熱暴走のトラブルが嫌がられて安く手に入るようだ. 民主的平和論に則り, ネットワーク製品は実質的に民主主義である国のメーカーのものを使うようにしてる. 内部を清掃する 分解レポートを写真付きで見せてくれてるブログがあったので手順をなぞって分解した. 基盤の裏表にヒートシンクが付いているのだけど, チップとヒートシンクの間に挟まれている熱伝導接着剤に製造時に剥がすべき保護フィルムが残置されている. クリーニングしておいた. これで熱暴走が予防できたらうれしい. MTU の調整をする 設定できる MTU は 1400〜1440 なので調整幅が少ない. 設定をいろいろ試したいときは不便. ウェブ画面以外から MTU を設定してみる MTU の制限は画面で保存ボタンを押したときにチェックをしているだけという記事を読んだので, ウェブ画面以外から設定する方法を考える. ssh も積んでいるようだが, 設定を on にする方法はわからなかった. Web ブラウザでルーターのクイック設定 Web を開いてパスワードを入力してログインする. トップページ-> 詳細設定-> その他の設定 を開く. ブラウザのデベロッパーツール-> アプリケーションタブ-> Cookie で確認すると認証情報が保存されている. sysauth=3fe56f2e0086af243bed7f956152f4de ブラウザのデベロッパーツール-> 要素 で token を検索すると token に値がセットされているのがわかる. <input type="hidden" name="token" id="token" value="937a36e9ebd2b69e09b9e7a73dbeb4f0"> 設定ボタンを押したときと同じデータ(payload)を sysauth と token と合わせてサーバーに送信(POST)してみる. 設定ボタンを押したときにどんなデータが送られているかはデベロッパーツールのネットワークで見つかる. 実際の payload はこんな感じ "Security_Protection_Function_check=on&Security_Protection_Function=1&TCP_Timer_seconds=1200&UDP_Timer_seconds=100&UPnP_Function=0&DMZ_Host_Function=0&IP_Address_of_DMZ_Host=&Firmware_Update_Notification_Feature_check=on&Firmware_Update_Notification_Feature=1&Lamp_Lighting_Mode=0&Lamp_Off_Transition_Time=1&MTU_bytes=1440&PING_Response_Function_check=on&PING_Response_Function=1&Quality_Report_Function=0&button_id=Apply_9&token=937a36e9ebd2b69e09b9e7a73dbeb4f0" bash にまとめるとこんな感じ #!/bin/bash # ルーターの IP とパスワードを指定するよ IP="192.168.2.1" PASSWORD="PASSWORD" # 設定したいMTUを指定するよ MTU_BYTES="1500" # MTU(Bytes) # その他の設定を全部指定するよ SECURITY_PROTECTION_FUNCTION="1" # セキュリティ保護機能 on:1 off:0 TCP_TIMER_SECONDS="1200" # NAPT設定 TCPタイマ(秒) UDP_TIMER_SECONDS="100" # NAPT設定 UDPタイマ(秒) UPNP_FUNCTION="0" # UPnP機能 on:1 off:0 DMZ_HOST_FUNCTION="0" # DMZホスト機能 on:1 off:0 IP_ADDRESS_OF_DMZ_HOST="" # DMZホストのIPアドレス FIRMWARE_UPDATE_NOTIFICATION_FEATURE="1" # ファームウェア更新通知機能 on:1 off:0 LAMP_LIGHTING_MODE="0" # ランプ消灯モード 消灯:1 点灯:0 LAMP_OFF_TRANSITION_TIME="1" # ランプ消灯移行時間(分) PING_RESPONSE_FUNCTION="1" # PING応答機能 on:1 off:0 QUALITY_REPORT_FUNCTION="0" # 品質情報収集機能 on:1 off:0 # mac の場合は互換性維持のために homebrew の ggrep, gsed を使いたい. Linux ではそのまま grep, sed を使う. GREP_CMD=$(command -v ggrep || command -v grep) SED_CMD=$(command -v gsed || command -v sed) # ログインして sysauth をゲットするよ SYSAUTH=$(curl -s -D - -d "luci_username=root" -d "Password=${PASSWORD}" http://${IP}/cgi-bin/luci/ \ | "${GREP_CMD}" -i 'Set-Cookie: sysauth=' \ | "${SED_CMD}" -n 's/^Set-Cookie: sysauth=\([^;]*\);.*/\1/p') # 設定に必要な token を取得するよ TOKEN=$(curl -s "http://${IP}/cgi-bin/luci/Advanced_Settings/Other_Settings" -b "sysauth=${SYSAUTH}" | "${GREP_CMD}" -oP 'id="token" value="\K[^"]+') if [ -z "${TOKEN}" ]; then echo "--------------" echo "tokenが取得できなかった! Speed Wi-Fi HOME 5G L12 のIPアドレスと PASSWORD の値を確認してね." echo "--------------" else POST_DATA="Security_Protection_Function_check=on&\ Security_Protection_Function=${SECURITY_PROTECTION_FUNCTION}&\ TCP_Timer_seconds=${TCP_TIMER_SECONDS}&\ UDP_Timer_seconds=${UDP_TIMER_SECONDS}&\ UPnP_Function=${UPNP_FUNCTION}&\ DMZ_Host_Function=${DMZ_HOST_FUNCTION}&\ IP_Address_of_DMZ_Host=${IP_ADDRESS_OF_DMZ_HOST}&\ Firmware_Update_Notification_Feature_check=on&\ Firmware_Update_Notification_Feature=${FIRMWARE_UPDATE_NOTIFICATION_FEATURE}&\ Lamp_Lighting_Mode=${LAMP_LIGHTING_MODE}&\ Lamp_Off_Transition_Time=${LAMP_OFF_TRANSITION_TIME}&\ MTU_bytes=${MTU_BYTES}&\ PING_Response_Function_check=on&\ PING_Response_Function=${PING_RESPONSE_FUNCTION}&\ Quality_Report_Function=${QUALITY_REPORT_FUNCTION}&\ button_id=Apply_9&\ token=${TOKEN}" # 実際に POSTしてみるよ. curl -X POST "http://${IP}/cgi-bin/luci/Advanced_Settings/Other_Settings/Apply_1" \ -H "Content-Type: application/x-www-form-urlencoded" \ -b "sysauth=${SYSAUTH}" \ --data "${POST_DATA}" \ -v fi レスポンスは 302 * Trying 192.168.2.1:80... * Connected to 192.168.2.1 (192.168.2.1) port 80 > POST /cgi-bin/luci/Advanced_Settings/Other_Settings/Apply_1 HTTP/1.1 > Host: 192.168.2.1 > User-Agent: curl/8.7.1 > Accept: */* > Cookie: sysauth=3fe56f2e0086af243bed7f956152f47e > Content-Type: application/x-www-form-urlencoded > Content-Length: 461 > * upload completely sent off: 461 bytes < HTTP/1.1 302 Found < Connection: Keep-Alive < Transfer-Encoding: chunked < Keep-Alive: timeout=20 < Location: /cgi-bin/luci/Advanced_Settings/Other_Settings < * Connection #0 to host 192.168.2.1 left intact 最適な MTU を設定する MTU の最適な値は ping で調べられる. まずルーターの MTU を最大の 1500 にして 1472 のサイズの ping をしてみる. パケットの分割(fragment)が起きていたら MTU の値が大きすぎるので, ルーターの MTU はそのままに, ping のサイズだけ 1472 から下げていって実験を進める. fragment が起きなくなる最大の MTU をルーターに設定する. ping は OS によって引数がバラバラ. macOS だとこんな感じ. ...