# HG changeset patch # User Pascal Bellard # Date 1533109852 -7200 # Node ID e0d366200e99f6544e4c79e56b1c0b0fd9a22d76 # Parent be4846d01eb1145d6da806d21b8715caca4b89c9 ppp/ppp.cgi: add gsm/bluetooth support diff -r be4846d01eb1 -r e0d366200e99 ppp/stuff/ppp.cgi --- a/ppp/stuff/ppp.cgi Tue Jul 31 22:02:23 2018 +0200 +++ b/ppp/stuff/ppp.cgi Wed Aug 01 09:50:52 2018 +0200 @@ -10,6 +10,79 @@ get_config +set_secrets() +{ + grep -qs "^$1 " /etc/ppp/pap-secrets || + echo "$1 * $2" >> /etc/ppp/pap-secrets + grep -qs "^$1 " /etc/ppp/chap-secrets || + echo "$1 * $2" >> /etc/ppp/chap-secrets +} + + +create_gsm_conf() +{ + local provider="${1:-myGSMprovider}" + set_secrets "$provider" "$provider" + [ -s /etc/ppp/scripts/gsm.chat ] || + cat > /etc/ppp/scripts/gsm.chat < /etc/ppp/options-gsm << EOT +rfcomm0 +460800 +lock +crtscts +modem +passive +novj +defaultroute +noipdefault +usepeerdns +noauth +hide-password +persist +holdoff 10 +maxfail 0 +debug +EOT + [ -s /etc/ppp/peers/gsm ] || + cat > /etc/ppp/peers/gsm << EOT +file /etc/ppp/options-gsm +user "$provider" +password "$provider" +connect "/usr/sbin/chat -v -t15 -f /etc/ppp/scripts/gsm.chat" +EOT +} + + +phone_names() +{ + rfcomm | awk '/connected/{print $2}' | while read mac; do + grep -A2 $mac /etc/bluetooth/rfcomm.conf | \ + sed '/comment/!d;s/.* "\(.*\) modem";/ \1/' + done +} + + case "$1" in menu) TEXTDOMAIN_original=$TEXTDOMAIN @@ -25,7 +98,7 @@
  • $(_ 'PPP/SSH')
  • EOT ;; - *) + *) cat <$(_ 'PPP Modem') EOT @@ -40,27 +113,56 @@ # case " $(GET) " in -*\ setppppstn\ *) - if [ "$(GET start_pstn)" -a "$(GET user)" ]; then - grep -s "$(GET user)" /etc/ppp/pap-secrets || - echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets - grep -s "$(GET user)" /etc/ppp/chap-secrets || - echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets +*\ start_pstn\ *) + if [ "$(GET user)" ]; then + set_secrets "$(GET user)" "$(GET pass)" sed -i 's/^name /d' /etc/ppp/options echo "name $(GET user)" >> /etc/ppp/options /etc/ppp/scripts/ppp-off /etc/ppp/scripts/ppp-on & - fi - if [ "$(GET stop_pstn)" ]; then - /etc/ppp/scripts/ppp-off - fi - ;; -*\ setpppoe\ *) - if [ "$(GET start_pppoe)" -a "$(GET user)" ]; then - grep -s "$(GET user)" /etc/ppp/pap-secrets || - echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets - grep -s "$(GET user)" /etc/ppp/chap-secrets || - echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets + fi ;; +*\ start_gsm\ *) + if [ "$(GET gsmprovider)" ]; then + [ -n "$(pidof dbus-daemon)" ] || /etc/init.d/dbus start + [ -n "$(pidof bluetoothd)" ] || bluetoothd + grep -qs btusb /proc/modules || modprobe btusb + hcitool scan | grep : | while read dev name; do + set -- $dev "$name" $(sdptool browse $dev | awk ' +/Service Class ID List/ {n=0} +/Dialup Networking/ {n=1} +/RFCOMM/ {n++} +/Channel/ {if (n==2) { print $2; exit } }') + [ -n "$3" ] || continue + grep -qs $1 /etc/bluetooth/rfcomm.conf || + cat >> /etc/bluetooth/rfcomm.conf < /etc/ppp/options <> /etc/ppp/options ( . /etc/network.conf ; pppd $INTERFACE & ) - fi - if [ "$(GET stop_pppoe)" ]; then - killall pppd - fi - ;; + fi ;; +*\ stop_pppoe\ *) + killall pppd ;; *\ setpppssh\ *) cat > /etc/ppp/pppssh < $(_ 'Configuration') +EOT +[ "$(which sdptool 2>/dev/null)" ] && create_gsm_conf && cat <$(_ 'GSM device')

    + $(_ 'PPP GSM script')

    + $(_ 'PPP GSM chat')

    + $(_ 'PPP GSM options')

    +EOT +cat << EOT $(_ 'PPP PSTN script')

    - $(_ 'PPP dialer chat')

    - $(_ 'PPP options')

    + $(_ 'PPP PSTN chat')

    + $(_ 'PPP PSTN options')

    $(_ 'chap users')

    $(_ 'pap users')

    EOT for i in /etc/ppp/peers/* ; do - [ -s "$i" ] && cat << EOT + [ -s "$i" ] && [ "$i" != "/etc/ppp/peers/gsm" ] && cat << EOT $(basename $i)

    EOT done @@ -175,12 +283,65 @@ else stopoe_disabled='disabled' fi +if [ "$(busybox ps x | grep "pppd" | awk '/gsm/{print $1}')" ]; then + startgsm_disabled='disabled' +else + stopgsm_disabled='disabled' +fi +head="

    +
    + +
    +
    + $(_ 'Install extra') +
    " +while read file pkg name ; do + [ -z "$(which $file 2>/dev/null)" ] && echo $head && head="" && + echo " $name" +done <
    +EOT +if [ "$(which sdptool 2>/dev/null)" ]; then + cat < +
    +
    + $(_ 'GSM modem') - + $(_ 'Manage Bluetooth GSM Internet connections') +
    +
    + + + + + + + + + + +
    $(_ 'GSM provider') /dev/null)" />
    $(_ 'Bluetooth PIN')
    +
    $(phone_names)
    +
    +
    +EOT +fi +cat << EOT