5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[メモ] らずぱい WebUIでシャットダウン (セキュリティ考慮無し)

Posted at

概要

  • shutdown とか rebootって、タイプするのが、ダるい。

    => ボタンおすと、再起動とか、シャットダウン

    => Webサーバ立てて、php で、system関数呼べば...
  • セキュリティは考慮してないので、外部から接続されないように、おうちのLANだけとか、ラズパイをWifi-APにしてしまうとか、しましょう。
  • 参考: Basic way to shutdown via web

環境

  • Raspberry Pi 2 / 3
  • Raspbian: 2017-04-10-raspbian-jessie
  • lighttpdを使用
  • 知らないヒトが入ってこない、ネットワーク環境.

手順

  1. いつもの

    • Raspbianを焼いて
    • 適当に初期設定
    • パッケージ更新:
      sudo apt-get update && sudo apt-get upgrade -y
  2. Webサーバ(lighttpd)の導入、phpの有効化

パッケージ取得

sudo apt-get update && sudo apt-get install lighttpd php5-cgi

モジュールを有効化

sudo lighty-enable-mod fastcgi fastcgi-php

サービス再起動

sudo systemctl restart lighttpd.service

    - `/var/www/html` が htmlのルートディレクトリ
    - ブラウザから、http://<らずぱいのIPアドレス>/にあくせすしてみよう


3. sudores の設定

    ```bash:シェルにこぴぺ
# www-dataユーザが、sudo shutdownを呼べるようにする.
# ファイル:/etc/sudoers.d/www-data_shutdown
echo 'www-data ALL= NOPASSWD: /sbin/shutdown' | sudo tee /etc/sudoers.d/www-data_shutdown
  1. html,phpファイルの準備

    シェルにこぴぺ

ファイル:/var/www/html/shutdown.php

cat <<EOF | sudo tee /var/www/html/shutdown.php

/dev/null &'); ?>

Shutting down
EOF

ファイル: /var/www/html/reboot.php

cat <<EOF | sudo tee /var/www/html/reboot.php

/dev/null &'); ?>

Rebooting
EOF

ファイル: /var/www/html/index.html

cat <<EOF | sudo tee /var/www/html/index.html







EOF ``` - /var/www/html/ 以下に - ボタンを表示。押すと、phpのファイルへジャンプ
		```html:index.html 
		<html>
		<form action="reboot.php ">    <input type="submit" value="Reboot" style="height: 240px; width: 50% ;font-size: 50px;" /></form>
		<br><br><br><br><br><br>
		<form action="shutdown.php ">    <input type="submit" value="Shutdown" style="height: 240px; width: 50% ;font-size: 50px;" /></form>
		</html>
		```		
    - シャットダウン

		```php:shutdown.php
		<script>setTimeout(function(){ history.go(-1); }, 1000);</script>
		<?php system('sudo /sbin/shutdown -h now > /dev/null &'); ?>
		Shutting down
		```

    - 再起動

		```php:reboot.php
		<script>setTimeout(function(){ history.go(-1); }, 1000);</script>
		<?php system('sudo /sbin/shutdown -r now > /dev/null &'); ?>
		Rebooting
		```
  1. ブラウザから、http://<らずぱいのIPアドレス>/にアクセス。
    ナイスなUIデザインがほしい
    デザインがいまいちだと、使う気が...(ぉ
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?