Jump to content

Import SSID on Mark VII


Thermostaten

Recommended Posts

Posted

I have my favorite list of SSID's that i really like to keep on my Pineapple, but EVERYTIME i upgrade I have to re-add them.

In "older days.." you could just ssh to the pineapple and import them via the command line like: 

cat ${SSID_LIST_FILE}|grep -v ^#|while read SSID; do 
 # SSID_SAFE=$(echo ${SSID}|LC_ALL=C sed -e 's/[^a-zA-Z0-9,._+@%/-]/\\&/g; 1{$s/^$/""/}; 1!s/^/"/; $!s/$/"/')
  SSID_SAFE="${SSID}"
 # SSID_SAFE="${SSID_SAFE//\\/\\\\}"  # remove all backslashes first
 # SSID_SAFE="${SSID_SAFE//\//\\/}"   # remove slashes
 # SSID_SAFE="${SSID_SAFE//\*/\\*}"   # remove asterisks
 # SSID_SAFE="${SSID_SAFE//./\\.}"    # remove full stops
 # SSID_SAFE="${SSID_SAFE//\[/\\[}"   # remove [ 
 # SSID_SAFE="${SSID_SAFE//\[/\\]}"   # remove ]
 # SSID_SAFE="${SSID_SAFE//^/\\^}"    # remove ^ 
 # SSID_SAFE="${SSID_SAFE//\$/\\\$}"  # remove $
 # SSID_SAFE="${SSID_SAFE//[$'\n']/}" # remove newlines
 # printf "Adding SSID: %-64s Original_Name: %-64s" "${SSID_SAFE}" "${SSID}"
 printf "Adding SSID: %-64s" "${SSID_SAFE}"
 GOOD=$(\
  curl --silent \
       -X POST \
       -H "Content-type: application/json" \
       -d '{"module":\
            "PineAP",\
            "action":"addSSID",\
            "ssid":"'"${SSID_SAFE}"'",\
            "apiToken":"put-yout-api-key-here"}' \
       "http://172.16.42.1:1471/api/"|grep -c success)
 if [ ${GOOD:-0} -eq 1 ]; then 
  echo " [OK]"
 else
  echo " [FAILED]"
 fi 
done

How the bleep do I do that today ? 

Regards Keld Norman

 

Posted

I found the RTFM :) .. ( Read the friendly manuals ) .. 

You can use something like this to import the SSID's - just upload it to your pineapple + the text file containing the list of SSID's and run it 

./add_ssids.sh ./file_with_ssids.txt

#!/bin/bash
clear
#set -x
#----------------------------------------------------------------------------
# Need txt file containing list of SSID's as parameter 
#----------------------------------------------------------------------------
if [ ! $# -eq 1 ]; then 
 printf "\n ### ERROR - Missing file containing SSID names as parameter\n\n"}
 exit 
fi
#----------------------------------------------------------------------------
# Check if the import file exist
#----------------------------------------------------------------------------
if [ ! -s $1 ]; then 
 printf "\n ### ERROR - The SSID list file is missing or empty ($1)"
 exit 1
fi
#----------------------------------------------------------------------------
# Generate API token
#----------------------------------------------------------------------------
TOKEN=$(curl -X POST http://172.16.42.1:1471/api/login -d '{"username": "root", "password": "pineapplesareyummy?"}' 2>/dev/null|grep "token"|cut -d '"' -f4)
if [ -z "${TOKEN}" ]; then 
 printf "\n ### ERROR - Failed to get an API token!"
 exit 1
fi
#----------------------------------------------------------------------------
# Import the SSIDS
#----------------------------------------------------------------------------
printf "\n Importing $(cat $1|wc -l) SSID's..\n\n"
cat ${1}|grep -v ^#|while read SSID; do 
 # SSID_SAFE=$(echo ${SSID}|LC_ALL=C sed -e 's/[^a-zA-Z0-9,._+@%/-]/\\&/g; 1{$s/^$/""/}; 1!s/^/"/; $!s/$/"/')
 SSID_SAFE="${SSID}"
 # SSID_SAFE="${SSID_SAFE//\\/\\\\}"  # remove all backslashes first
 # SSID_SAFE="${SSID_SAFE//\//\\/}"   # remove slashes
 # SSID_SAFE="${SSID_SAFE//\*/\\*}"   # remove asterisks
 # SSID_SAFE="${SSID_SAFE//./\\.}"    # remove full stops
 # SSID_SAFE="${SSID_SAFE//\[/\\[}"   # remove [ 
 # SSID_SAFE="${SSID_SAFE//\[/\\]}"   # remove ]
 # SSID_SAFE="${SSID_SAFE//^/\\^}"    # remove ^ 
 # SSID_SAFE="${SSID_SAFE//\$/\\\$}"  # remove $
 # SSID_SAFE="${SSID_SAFE//[$'\n']/}" # remove newlines
 # printf " Adding SSID: %-64s Original_Name: %-64s" "${SSID_SAFE}" "${SSID}"
 printf " Adding SSID: %-64s" "${SSID_SAFE}"
 STATUS=$(\
  curl --silent \
       -X PUT \
       -H "Content-type: application/json" \
       -H "Authorization: Bearer ${TOKEN}" \
       -d '{"ssid":"'"${SSID_SAFE}"'"}' \
       "http://172.16.42.1:1471/api/pineap/ssids/ssid")
       
 HOW_DID_IT_GO=$(echo ${STATUS}|grep -c '{"success":true}')
 if [ ${HOW_DID_IT_GO:-0} -eq 1 ]; then 
  echo " [OK]"
 else
  printf " [FAILED] - ${STATUS}\n"
 fi 
done
printf " $(date) - End of import!\n\n"
#----------------------------------------------------------------------------
# END OF SCRIPT
#----------------------------------------------------------------------------
 

Posted

If you don't require the use of the API, you may also simply copy your SSID file (seperated by newlines) to the device via SFTP and use PineAP to add them:

 

pineap add_ssid_file <path_to_file>

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...