0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NetworkManagerで大学回線に自動ログインする

0
Posted at

現在某信州にある大学では大学内の回線につなぐにはcurlでhttpsのログインページにポストすればログインが可能である。いちいちコマンドを打つのは面倒なのでNetworkManagerのイベント駆動的に動くディスパッチャーの機能をつかい作成した。

以下のとおりのスクリプトを作成して

#!/bin/dash
#/etc/NetworkManager/dispatcher.d/preferred-name.sh
INTERFACE="wlan0"
LOGINPAGE="https://your-login-page"
LOGNAME="your-preferred-name"
if [ "$2" = "connectivity-change" ] ; then
  CONNECTION_ID=$(nmcli -t -f NAME,DEVICE connection  show --active|rg ':wlan0$' --replace "" )
  logger -t "$LOGNAME" "INFO: get $CONNECTION_ID"
  logger -t "$LOGNAME" "INFO: connectivity changed to $CONNECTIVITY_STATE at $CONNECTION_ID"
  case "$CONNECTION_ID" in
  |"ssid1"|"ssid2")
      sleep 1
      case "$CONNECTIVITY_STATE" in
        "LIMITED"|"PORTAL")
          id=$(cut /etc/path-to/your-id)
          pass=$(cut /etc/path-to/your-password)
          curl --interface $INTERFACE -s -X POST -d \
            "uid=$id" -d "pwd=$pass" $LOGINPAGE  > /dev/null 2>&1
          if [ "$?" = "0" ]; then
              logger -t "$LOGNAME" "INFO: succeeded to curl post"
          else
              logger -t "$LOGNAME" "ERROR: failed to post"
              logger -t "$LOGNAME" "INFO: $INTERFACE reloading"
              nmcli d d $INTERFACE
              nmcli d u $INTERFACE
              logger -t "$LOGNAME" "INFO: $INTERFACE reloaded"
          fi
        ;;
      esac
  esac
fi

権限周り調整する

sudo chmod 755 /etc/NetworkManager/dispatcher.d/preferred-name.sh

注意点

  1. リロードに関してはおおよそ1分ほどかかる

  2. イーサネットやWifi端末など区別しないでコネクティビティ変化は発火する

  3. httpのログインページには自動化は危険なので推奨しない

  4. Gentooではネットつながるかのチェック用の設定がされていないため以下のように設定する必要がある

# /etc/NetworkManager/conf.d/20-connectivity.conf
[connectivity]
uri=http://nmcheck.gnome.org/check_network_status.txt
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?