android-project-46group / api-server

MIT License
2 stars 0 forks source link

不具合の報告を受け取るリンクの作成 #19

Closed kokoichi206 closed 2 years ago

kokoichi206 commented 3 years ago

不具合の報告を受け取るリンクの作成

kokoichi206 commented 3 years ago

https://github.com/android-project-46group/android/issues/37

kokoichi206 commented 3 years ago

cgi からファイルへの書き込みが行えない

code 抜粋

if [ ! -z "$post" ]; then
    echo "${post}" >> "${FILE_PATH}"
    echo "pien" >> /var/www/html/issues.txt
fi

apache error.log

/usr/lib/cgi-bin/issue_report.sh: 28: cannot create /tmp/log/issues.txt: Directory nonexistent
/usr/lib/cgi-bin/issue_report.sh: 29: cannot create /var/www/html/issues.txt: Permission denied

Directory nonexistent が解決できない

おそらく、セキュリティの観点から /tmp などの外部フォルダが見れなくなっている模様

→ /var/www/html 配下に保存するようにした

kokoichi206 commented 3 years ago

サーバーサイドのログの例

$ cat issues.txt
[Mon Nov 22 15:56:55 UTC 2021] issue "Railsー"
[Mon Nov 22 16:18:25 UTC 2021] issue "遠藤さくらさんが可愛すぎます"
kokoichi206 commented 3 years ago

とりあえずの cgi ファイルの例

#!/bin/sh

method="$REQUEST_METHOD"
### post data is expected to be passed as text/plane ###
POST_STRING=$(cat)
post="$POST_STRING"

if [ "${method}" = "POST" ]; then
    # /tmp/log/ だと上手くいかなかった(なんで?)
    LOG_DIR="/var/www/html/sakamichi_log/"
    FILE_NAME="issues.txt"
    FILE_PATH="${LOG_DIR}${FILE_NAME}"
    TIME="date"

    DATA_TYPE="issue"
    if [ ! -z "$post" ]; then
        echo [`date`] ${DATA_TYPE} "${post}" >> "${FILE_PATH}"
    fi
    status=$?
cat << EOF
Content-Type: application/json; charset=UTF-8

{
    "status": "check"
}
EOF
elif [ "${method}" = "GET" ]; then
cat << EOF
Content-Type: application/json; charset=UTF-8

{
    "me": "`whoami`",
    "home_dir": "`ls ~/`",
    "files_in /tmp/log/": "${FILES_IN_LOG}",
    "pwd": "`pwd`",
    "path": "${FILE_PATH}",
    "ident": "${ident}",
    "method": "${method}",
    "post body": "${post}",
    "success": "false"
}
EOF
fi
kokoichi206 commented 2 years ago

ある URL から確認もできるようにしたい