Guest User

Untitled

a guest
May 27th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. #!/bin/bash
  2. #Script for cycling through several libertynet accounts trying to conect.
  3. #TODO: Due to a problem with the drivers?, the dongle must be reset between dial in attempts.
  4. #TODO: For now this reset must be done by physically pulling and re-inserting the dongle.
  5. #TODO: But someone smarter than me should figure out how to do this with code.
  6.  
  7. # TODO: Find a reasonable way to monitor for a successful connection connection.
  8. # TODO: When the connection is successful, start IRC. This is important because if all accounts are in use
  9. # TODO: a sms sent to twitter could post a mesage in the #baobab channel to alert those online that someone
  10. # TODO: is waiting to get online. For now we just print a reminder to start IRC.
  11. # TODO: Set up the SMS-twitter-IRC alerting system.
  12. # TODO: Another posibility: The SMS sent by a baobaber waiting for use of a libertynet account would
  13. # TODO: initiate a disonnect of the person who has been online the longest unless they override the dissconect.
  14.  
  15. # assign usernames to the array u and passwords to p, numberOfAccts is the number of accounts
  16. numberOfAccts=2
  17. u[0]="username0" # dummy values were put in to allow for public consumption
  18. p[0]="password0" # substitute with real usernames and passwords
  19. u[1]="username1"
  20. p[1]="password1"
  21.  
  22. #This is the config that will be put into /etc/wvdial.conf with the various usernames/passwords
  23. wvdialconf="
  24. [Dialer Defaults]
  25. New PPPD = yes
  26. Modem = /dev/ttyUSB0
  27. Init1 = ATZ
  28. Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
  29. Dial Command = ATDT
  30. Phone = #777
  31. Modem Type = Analog Modem
  32. Baud = 460800
  33. Carrier Check = on
  34. Username = 26u79n
  35. Password = 5vn7drq
  36. Stupid Mode = on
  37. Check Def Route = on
  38. Abort on Busy = off
  39. Abort on No Dialtone = off
  40. Auto Reconnect = off
  41. ISDN = 0
  42. Auto DNS = on
  43. Idle Seconds = 0
  44. Dial Attempts = 1
  45. "
  46.  
  47. echo "
  48. This script is supposed to facilitate the sharing of several libertynet
  49. accounts among several users. You probably should turn off other network
  50. connecitons before you connect to libertynet. (I always uncheck
  51. 'enable wireless' in the system tray.) Durring this script we will create
  52. new /etc/chap-secrets, /etc/pap-secrets, and /etc/wvdial.conf files. The
  53. originals will be backed up to /etc/chap-secrets.bak, /etc/pap-secrets.bak,
  54. and /etc/wvdial.conf.bak.
  55.  
  56. Please, start IRC when you get a successful connection.
  57. "
  58. read -p "Continue? <Y/n> " prompt
  59. if [[ $prompt == "n" || $prompt == "N" || $prompt == "no" || $prompt == "No" || $prompt == "NO" ]]
  60. then
  61. exit
  62. #~ else
  63. #~ echo "...continuing..."
  64. fi
  65.  
  66. sudo modprobe usbserial vendor=0x19d2 product=0xfffe #register the driver?
  67. #echo "...did the modprobe..."
  68.  
  69. #backup chap-secrets, pap-secrets, and wvdial.conf
  70. #echo "Backing up chap-secrets, pap-secrets, and wvdial.conf..."
  71. sudo mv -f /etc/ppp/pap-secrets /etc/ppp/pap-secrets.bak
  72. sudo mv -f /etc/ppp/chap-secrets /etc/ppp/chap-secrets.bak
  73. sudo mv -f /etc/wvdial.conf /etc/wvdial.conf.bak
  74.  
  75.  
  76. #Go through each username and password.
  77. index=0
  78. while true
  79. do
  80. echo "
  81. If the libertynet dongle is not inserted, insert it now. If it is, please
  82. remove and re-insert it. The dongle will be ready to dial once the orange
  83. light has extuingished. It should take about 20 seconds after it is inserted.
  84. "
  85. read -p "After the orange light on the dongle has extuingished, press <enter> to continue." prompt
  86.  
  87. echo "
  88.  
  89. Trying to connect with username ${u[$index]} and password ${p[$index]}
  90. "
  91. #substitute the current username/password into the configuration string and write it to /tmp/wvdial.conf
  92. echo "$wvdialconf" | sed "s_Password = [^ ]*_Password = ${p[$index]}_" | sed "s_Username = [^ ]*_Username = ${u[$index]}_" > /tmp/wvdial.conf
  93. #move the tmp config file to the /etc
  94. sudo mv /tmp/wvdial.conf /etc/wvdial.conf
  95. #little daemon-like loop that checks the log file to see if we are connected, this is disabled because i couldn't figure out how to kill it gracefully
  96. #~ while true
  97. #~ do
  98. #~ sleep 5
  99. #~ if grep -q "DNS address" /tmp/libertynet.log #the DNS address is sent to stderr when the connection is successful
  100. #~ then
  101. #~ echo "...connected..."
  102. #~ echo "Be a team player, start IRC and listen for requests to give up your connection from offline baobabers."
  103. #~ break
  104. #~ else
  105. #~ echo "...not connected..."
  106. #~ fi
  107. #~ done&
  108. #the dial/re-dial routine
  109. while true
  110. do
  111. >/tmp/libertynet.log #initialize the log for each dial attempt
  112. sudo wvdial 3>&1 1>&2 2>&3 | tee /tmp/libertynet.log #dial the modem, send stderr to log file and to screen (tee only works on stdout, so we swap stdout and stderr)
  113. if grep -q "Device or resource busy" /tmp/libertynet.log #this happens if the modem is not yet ready
  114. then
  115. echo
  116. echo "... looks like the modem was not available, is it already in use by another application?..."
  117. sleep 3
  118. echo "...re-dialing..."
  119. echo
  120. elif grep -q "No such file" /tmp/libertynet.log #this also happens if the modem is not yet ready
  121. then
  122. echo
  123. echo "... wvdial can not see the modem, is the dongle plugged in? ... "
  124. sleep 3
  125. echo "...re-dialing..."
  126. echo
  127. elif grep -q "NO CARRIER" /tmp/libertynet.log #this happens if the modem fails to find a cell tower
  128. then
  129. echo
  130. echo "...Modem did not succesfully connect to a cell tower, are you getting cell reception? "
  131. echo "...re-dialing..."
  132. echo
  133. elif grep -q "Modem not responding." /tmp/libertynet.log #this happens if the modem is not re-inserted
  134. then
  135. echo
  136. echo "...Looks like the dongle was not reset...."
  137. echo "...Don't forget to remove and re-insert the dongle when prompted..."
  138. echo
  139. break
  140. else
  141. echo
  142. echo "...Looks like that account is already in use...."
  143. echo
  144. break
  145. fi
  146. done
  147.  
  148. #~ if [ $! ] ; then kill $!; fi # Kill the background daemon-like loop, this seems to give some unwanted output
  149. # but at least the background process does stop. Disabled, because it was messy.
  150.  
  151. let "index += 1"
  152. if [ $index == $numberOfAccts ] #when we've tried all acounts, give the option to quit or start over
  153. then
  154. echo
  155. echo "We have tried all the libertynet accounts. Do you want to start over with the first account or quit?"
  156. read -p "<S>tart over or <q>uit?" prompt
  157. if [[ $prompt == "q" || $prompt == "Q" || $prompt == "quit" || $prompt == "Quit" || $prompt == "QUIT" ]]
  158. then
  159. exit 0
  160. else
  161. let "index=0"
  162. echo "...starting over with the first username/password..."
  163. fi
  164. fi
  165.  
  166. done
Add Comment
Please, Sign In to add comment