2018/06/25

[MySQL] XAMPPのMySQLとphpMyAdminのパスワード設定

XAMPPのMySQLとphpMyAdminのパスワード設定
http://cly7796.net/wp/other/password-setting-of-mysql-root-and-phpmyadmin-of-xampp/

2018/06/10

[Python] 文字列内で変数を展開する

3.6 より formatted string literal が利用可能

Python 3.6の新機能f-strings(フォーマット文字列リテラル)について
http://codom.hatenablog.com/entry/2016/12/27/000000

Python3.6 から追加された文法機能
https://qiita.com/shirakiya/items/2767b30fd4f9c05d930b

ヒアドキュメント文字列でも利用可能

2018/05/27

[Windows] リネームしたはずのフォルダ名が元の名前に戻ってしまう

Explorer からフォルダ名変更 → 他のフォルダに移動すると、元の名前に戻ってしまう。
変更後にフォルダのプロパティを見ると、[全般]タブでは変更後の名前になっているが、隣の[共有]タブでは変更前の名前のままになっていることが確認できる。
原因は多岐にわたるようだが、当該フォルダ内の「隠しファイル」が影響している場合がある。

<autorun.infが影響する場合>
If this problem occurs again, enable hidden items to be shown in windows explorer. Find a Setup Information File called "autorun.inf" and edit or delete this file with administrator rights. Restart your computer and your problem should be fixed.

autorun.inf

[Autorun]
Label=Drive

https://social.technet.microsoft.com/Forums/en-US/b4da4617-f4ec-465e-a43d-f7e365784f99/still-cant-rename-folders-in-windows-10-file-explorer?forum=win10itprogeneral

他にも「desktop.ini」が影響する場合等々。
隠しファイルを表示できる状態にし、当該ファイルを削除で事象解消できることを確認

2018/05/21

[Ruby] `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate) (OpenSSL::SSL::SSLError)

証明書を検証をしない方法でエラー抑止

require 'open-uri'
require 'openssl'
puts open('https://www.google.com/', :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read

[Ruby] open-uri の HTTPS リクエストで certificate verify failed
http://mofuken.blogspot.jp/2012/12/ruby-open-uri-https-certificate-verify.html

2018/05/17

[セキュリティ] certbot で Let's Encrypt 証明書更新

sudo /usr/local/bin/certbot \
    certonly \
    --webroot \
    -d example.com\
    -w /var/app/current/example.com

[aws] Elastic Beanstalk 単一インスタンス+ワイルドカード証明書(Let's Encrypt)で http 通信を利用する際の設定

Elastic Load Balancing(ELB)使用時は、Certificate Managerで作成したSSL証明書適用でOKだが、シングルインスタンスではNGなので、自前の証明書を適用。

<証明書取得>
certbot インストール
sudo pip install certbot

Zone APEX用証明書
sudo /usr/local/bin/certbot certonly \
--manual \
--preferred-challenges dns-01 \
--server https://acme-v02.api.letsencrypt.org/directory \
--domains example.com

SSLCertificateFile    "/etc/letsencrypt/live/example.com/fullchain.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/example.com/privkey.pem"
が生成。
Route 53 で _acme-challenge.example.com の TXTレコードに指示された値を設定し、有効化。


ワイルドカードサブドメイン用証明書
sudo /usr/local/bin/certbot certonly \
--manual \
--preferred-challenges dns-01 \
--server https://acme-v02.api.letsencrypt.org/directory \
--domains *.example.com

SSLCertificateFile    "/etc/letsencrypt/live/example.com-0001/fullchain.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/example.com-0001/privkey.pem"
が生成。
Route 53 で _acme-challenge.example.com の TXTレコードに指示された値を設定し、有効化。


<証明書設定>

/etc/httpd/conf.d/ssl.conf
以下の通り設定

  LoadModule ssl_module modules/mod_ssl.so
  Listen 443
  NameVirtualHost *:443

  <VirtualHost *:443>
    ServerName example.com
    DocumentRoot "/var/app/current/example/example.com"
    SSLEngine             on
    SSLCertificateFile    "/etc/letsencrypt/live/example.com-0001/fullchain.pem"
    SSLCertificateKeyFile "/etc/letsencrypt/live/example.com-0001/privkey.pem"
    <Directory "/var/app/current/example/example.com">
      AllowOverride All
      Require all granted
    </Directory>
  </VirtualHost>

  <VirtualHost *:443>
    ServerName example.com
    DocumentRoot "/var/app/current/example/sub.example.com"
    SSLEngine             on
    SSLCertificateFile    "/etc/letsencrypt/live/example.com/fullchain.pem"
    SSLCertificateKeyFile "/etc/letsencrypt/live/example.com/privkey.pem"
    <Directory "/var/app/current/example/sub.example.com">
      AllowOverride All
      Require all granted
    </Directory>
  </VirtualHost>

  SSLCipherSuite        EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
  SSLProtocol           All -SSLv2 -SSLv3
  SSLHonorCipherOrder   On
  SSLSessionTickets     Off
  Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
  Header always set X-Frame-Options DENY
  Header always set X-Content-Type-Options nosniff

サーバ再起動後、SSL Sever Test にて確認。


installation error on amazon linux
https://github.com/certbot/certbot/issues/1680#issuecomment-358728515

CertbotでDNSによる認証(DNS-01)で無料のSSL/TLS証明書を取得する
http://blog.jicoman.info/2017/04/certbot_dns_01/

Let's Encryptのワイルドカード証明書を早速発行してもらう
https://narusejun.com/archives/23/

付録: Amazon Linux 2 での Let's Encrypt と Certbot の使用
https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/SSL-on-an-instance.html

SSL Server Test
https://www.ssllabs.com/ssltest/

2018/05/12

[Apache] xamppで https 利用するための自己署名証明書の作成方法

XAMPP for WindowsでSSLを有効にする
https://qiita.com/sutara79/items/21a068494bc3a08a4803


1. C:\xampp\apache\conf\extra\httpd-ssl.conf に VirtualHost設定

<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/my-server.crt"
    SSLCertificateKeyFile "conf/ssl.key/my-server.key"
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs"
    ServerName test.localhost
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/my-server.crt"
    SSLCertificateKeyFile "conf/ssl.key/my-server.key"
</VirtualHost>


2. C:\xampp\apache\conf\openssl.cnf 編集

[ req ]セクション
x509_extensions = v3_ca # The extensions to add to the self signed cert
→ x509_extensions = v3_req # The extensions to add to the self signed cert

末尾追記
[ SAN ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = localhost
DNS.2 = test.localhost
# DNS.3 = <他に認証したいドメインがあれば>

→ *.localhost の設定はNG(事由不明)


3. openssl(Git Bash)で証明書作成

cd /c/xampp/apache/conf
openssl req \
    -newkey     rsa:4096 \
    -keyout     my-server.key \
    -x509 \
    -nodes \
    -out        my-server.crt \
    -subj       "//CN=localhost" \
    -reqexts    SAN \
    -extensions SAN \
    -config     openssl.cnf \
    -days       3650


4. 証明書設置
C:\xampp\apache\conf\ssl.crt\my-server.crt
C:\xampp\apache\conf\ssl.key\my-server.key


5. 証明書認証
C:\xampp\apache\conf\ssl.crt\my-server.crt ダブルクリック
→ [証明書のインストール]
→ [保存場所] 現在のユーザー → [次へ]
→ 証明書をすべて次のストアに配置する、[証明書ストア] 信頼されたルート証明機関 → [次へ]
→ [完了] → [はい]


6. Firefoxで自己署名証明書認証の例外設定

2018/05/10

[aws] スナップショットからボリューム復元後に ssh 接続できない

EBSでスナップショットからボリューム作成
→ アタッチ
→ ec2 インスタンス停止
→ 現ボリュームデタッチ
→ 新ボリュームアタッチ
→ インスタンス再起動
で、ssh 接続試みると WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! の警告表示され、ログイン不可。

接続サーバの fingerprint が変化して、なりすましの可能性を検知したため。
ssh-keygen -R hostname (ex. ec2-xx-xx-xx-xxx.ap-northeast-1.compute.amazonaws.com) にて解消。

Windows では ssh-keygen -R 未サポートなので Git-Bash から実行

SSH接続エラー回避方法:.ssh/known_hostsから特定のホストを削除する/削除しないで対処する3つの方法
https://qiita.com/grgrjnjn/items/8ca33b64ea0406e12938

2018/05/09

[TLS] 分かりやすいテキスト形式で証明書の内容を出力する

Windows上で、証明書や秘密鍵をPEM形式に変換してエクスポートする
http://www.atmarkit.co.jp/ait/articles/1602/05/news039.html


C:\temp>openssl x509 -inform PEM -text -noout -in example2.cer ……「example2.cer」の内容を表示させてみる

opensslコマンドの各オプションの意味は次の通りだ。

x509: 証明書を取り扱うためのコマンド
-inform PEM: 入力ファイルの形式としてPEMを指定する(デフォルトの形式はPEMなので、通常は明示的に指定する必要はない)
-text: 分かりやすいテキスト形式で証明書の内容を出力する
-noout: 証明書をファイルに出力しない
-in <ファイル名>: 入力ファイルの指定(この場合は証明書ファイル)

2018/05/06

[Apache] クローラーBot対策

(1) robots.txt で Disallow

(2) .htaccess で BrowserMatchNoCase で環境変数設定して、deny from env=その環境変数

Chrome / Firefox の User-agent 偽装アドオンをインストールして確認

2018/05/05

[aws] Elastic Beanstalk で DocumentRoot 配下に WinSCPでファイルを書き込めない

/var 配下に書き込み権がないたいため

# ec2-userでssh接続
sudo chmod -R 755 /var/www/html #フォルダのアクセス権限を変更
sudo chown -R ec2-user /var/www/html #一応オーナーも変更

# Elastic Beanstalk では
sudo chmod -R 755 /var/app/current
sudo chown -R ec2-user /var/app/current

CyberduckでEC2(Amazon Linux AMI)にファイルをアップロードできない
https://teratail.com/questions/22478

[Windows] 「最近使った項目」を復活+スタートメニューにピン留めする

クイックアクセスには表示したくないが、機能は使いたい

「最近使った項目」を復活+スタートメニューにピン留めする
https://news.mynavi.jp/article/win10tips-132/

2018/05/04

[Apache] localhost で 400 Bad Request

ホスト名に_(アンダースコア)を使ったため。ハイフンに修正して解消

Xamppにおいて、Apacheのバーチャルホストの設定でBad Requestが出る
https://teratail.com/questions/80836

Apache ローカル環境 400 Bad Request になるとき
https://chaika.hatenablog.com/entry/2018/01/26/090000

[Windows] 右クリックメニューに複数存在する「FAX受信者」を1つにする

Win 10 1803アップグレード後に、例によって「FAX受信者」が増えたので、余分なものを削除する

Windows10のコンテキストメニューをいじってみる その2
http://blog.livedoor.jp/lost_elysium/archives/1916371.html

WINDOWS10にアップグレードした後、ファイルを右クリックして、「送る」... - Yahoo!知恵袋
https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10148853345

2018/05/03

[メール] mailto: リンクを Gmail で開く

mailto:のメールリンクをGMAILで開くようにする設定の仕方
http://www.kagua.biz/tool/chrome-extension/mailto-gmail-handler.html

2018/05/01

[Windows] Windows 10 メジャーアップデート時に行うレジストリ再設定

一部設定が初期化されてしまうので、再度レジストリを設定しなおし

Windows 10で「Windowsフォトビューワー」を使う方法
http://ascii.jp/elem/000/001/078/1078506/

[Shift]+右クリックメニューに「コマンドウィンドウをここで開く」を復活させる方法
http://www.atmarkit.co.jp/ait/articles/1709/15/news025.html

Windows 10のPCが、数分で勝手にスリープするのを防ぐ
http://www.atmarkit.co.jp/ait/articles/1803/22/news018.html

Windowsで特定のフォルダを仮想ドライブとしてマウントする方法
http://did2memo.net/2012/06/19/how-to-mount-folder-as-virtual-drive-windows/

[Fix] Search Results defaults to Content View in Windows 10
http://www.winhelponline.com/blog/search-results-content-view-fix-details-windows-10/

2018/04/29

[Apache] 特定の URL を存在しないページ扱い(404)にする

.htaccess に Redirect 404 /path 設定

Redirect ディレクティブ
https://httpd.apache.org/docs/2.4/ja/mod/mod_alias.html#redirect

実際に path(対象ファイル or ディレクトリ)が存在する&削除可能であれば、削除 → 規定の 404 でよいが、
「当該 pathが存在するが削除できない/したくない」
場合は、mod_alias で、当該pathを明示的に 404 ステータスにリダイレクト

記述場所はどこでも(末尾でも)よい

2018/04/27

[Windows] iPod Shuffle 接続時に PC の起動、スリープ復帰が遅い

「リムーバブルドライブに対して行う操作」を「何もしない」に変更して解消

エクスプローラー → iPod Shuffle ドライブ右クリック → [自動再生を開く] → [何もしない]

[LibreOffice] Calc のデフォルトフォントを変更する

LibreOffice Calc のデフォルトフォントを変更する
https://freesoft.tvbok.com/freesoft/alt_tools/libreoffice-default-fonts.html

ver 6.0.2.1 では以下の通り。

ファイル場所 : C:\Program Files\LibreOffice\share\template\shellnew\soffice.ods
→ この場所では編集できないので、別の場所に移して編集

操作 : [スタイル] → [スタイル更新] → [標準]右クリック → [編集] → [フォント]

変更後に、元の場所にファイル移動

2018/04/25

[Windows] Windowsのバッチファイル中で日付をファイル名に使用する

Windowsのバッチファイル中で日付をファイル名に使用する (1/2)
http://www.atmarkit.co.jp/ait/articles/0405/01/news002.html

date環境変数から日付の数字だけを抽出する
年月日 : %date:~0,4%%date:~5,2%%date:~8,2%

[Windows] robocopy、RichCopy によるフォルダのバックアップ/同期

CUI : 「robocopy」コマンドでフォルダをバックアップ/同期させる
http://www.atmarkit.co.jp/ait/articles/0704/20/news130.html

GUI : WindowsのRichCopyでフォルダをバックアップ/同期させる
http://www.atmarkit.co.jp/ait/articles/0904/17/news110.html

2018/04/24

[Python] 複数バージョンの扱い方(Windowsの場合)

https://gammasoft.jp/python/python-version-management/

・Pythonランチャー(py.exe)で複数バージョン切り替え可(Windows版のPython3.3からデフォルトでインストール)
・マイクロバージョンアップ → 上書き
・マイナーバージョンアップ → 別フォルダにインストール

2018/03/10

[Python] Git bash から Python インタプリタ起動

Git bash 上から Python インタプリタを起動する
https://qiita.com/cointoss1973/items/a0da81df10f8cc04c83e

alias を ~/.bashrc に追記
alias python='winpty python.exe'

[WSL] Ubuntu と python 導入

Ubuntu インストール

1. Windows Store から Ubuntu インストール
2. unix ユーザー名、パスワード設定
3. sudo apt-get update
4. sudo apt-get upgrade

初期インストールされているのは python3 のみ
$ which python3
/usr/bin/python3
$ python
The program 'python' can be found in the following packages:
* python-minimal
* python3
Try: sudo apt install <selected package>

python3 用 pip dev のみインストール
$ sudo apt install python3-pip python3-dev

$ which pip3
/usr/bin/pip3
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

venvインストール
$ sudo apt install python3-venv

そのままでは Python3.6のインストール失敗
$ sudo apt install python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'

当面、3.5 のまま運用

というか、当面 git bash から Windows 版の Python(3.6)の方を利用する方針

というか、当面 git CMD から Windows 版の Python(3.6)の方を利用する方針

[Ubuntu] インストールされている Ubuntu のバージョンを確認

WSL のターミナルで確認
$ cat /etc/os-release

NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

uname は
$ uname -a
Linux [machinename] 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux

2018/03/06

[Visual Studio Code] タブキーで挿入される空白文字数を言語ごとに切り替える

Visual Studio Codeで言語ごとにインデントの設定をしたい
https://ja.stackoverflow.com/questions/34014/visual-studio-code%E3%81%A7%E8%A8%80%E8%AA%9E%E3%81%94%E3%81%A8%E3%81%AB%E3%82%A4%E3%83%B3%E3%83%87%E3%83%B3%E3%83%88%E3%81%AE%E8%A8%AD%E5%AE%9A%E3%82%92%E3%81%97%E3%81%9F%E3%81%84


Ctrl+Shift+Pで開くコマンドパレットにPreferences: Configure language specific settingsを入力/選択してユーザー用設定を開く。
編集対象の言語を入力/選択する。
{
    "[javascript]": {
        "editor.tabSize": 2
    },
    "[html]": {
        "editor.tabSize": 2,
    },
    "[css]": {
        "editor.tabSize": 2
    }
}
--

HTML, JavaScript, CSS は2タブ(2スペース)、その他は4タブ(4スペース)

2018/03/05

自動ページリローディングツール

LiveReload、LivePage ではなく、BrowserSync を npm から導入。

cd [websitebasedir]
browser-sync start --server --files *

で起動