Auto-accepting Wifi ToS captive portal via octopi-wpa-supplicant.txt on headless Raspberry Pi 4 for OctoPrint

203 views Asked by At

I'm trying to auto-accept a public wifi's terms on a popup window. Off the Pi, the terms window automatically loads via a webpage when a user attempts to join the network. Since I'm using a headless Pi, I'm wondering if there is a way to do this automatically and any time my Pi gets kicked off the network (every 24 hrs or so). Unfortunately, I don't have the programming knowledge to be able to do this by changing the octopi-wpa-supplicant.txt file.

Below is an example of what I would normally use to gain access to a public network without a terms popup window.

## Open/unsecured
network={
  ssid="Public"
  key_mgmt=NONE
}

One idea I saw online is writing code to open the wifi terms of service webpage, and then sending keystrokes to accept the terms.

The accept button on the terms page has the following HTML code when clicked...

function submitAction(){
      var link = document.location.href;
      var searchString = "redirect=";
      var equalIndex = link.indexOf(searchString);
      var redirectUrl = "";

      if (document.forms[0].action == "") {
      var url = window.location.href;
      var args = new Object();
      var query = location.search.substring(1);
      var pairs = query.split("&");
          for(var i=0;i<pairs.length;i++){
              var pos = pairs[i].indexOf('=');
              if(pos == -1) continue;
              var argname = pairs[i].substring(0,pos);
              var value = pairs[i].substring(pos+1);
              args[argname] = unescape(value);
          }
          document.forms[0].action = args.switch_url;       
      }       
      if(equalIndex >= 0) {
            equalIndex += searchString.length;
            redirectUrl = "";
            redirectUrl += link.substring(equalIndex);
      }
      if(redirectUrl.length > 255)
      redirectUrl = redirectUrl.substring(0,255);
      document.forms[0].redirect_url.value = redirectUrl;
      document.forms[0].buttonClicked.value = 4;
      document.forms[0].submit();
}

Anyone have ideas for changing the supplicant.txt file so my Pi can connect to the network automatically?

0

There are 0 answers