admin管理员组文章数量:1310143
I working on creating a Linux Digital signage Box, which my clients can buy, and choose what to show on it. At the moment, it boot up in Firefox, check if it have internet, query my server and get a unique URL which Firefox change to. If it don't have any internet connection, i show a page "You dont have internet, please connect a ethernet cable or connect to WIFI."
That my question, what will be the best way to allow my client to connect a Wireless hotspot from Firefox? At the moment my idea is:
I add a "Connect wireless" button, which with some javascript call a php script, which SSH to the BOX (localhost), and use connmanctl to first, find all WIFI hotspot and if they reguire password. The Javascript then show this, and SSH again to connect and so on..
Do you know a opensource system, which do that? or a better way to do it?
I working on creating a Linux Digital signage Box, which my clients can buy, and choose what to show on it. At the moment, it boot up in Firefox, check if it have internet, query my server and get a unique URL which Firefox change to. If it don't have any internet connection, i show a page "You dont have internet, please connect a ethernet cable or connect to WIFI."
That my question, what will be the best way to allow my client to connect a Wireless hotspot from Firefox? At the moment my idea is:
I add a "Connect wireless" button, which with some javascript call a php script, which SSH to the BOX (localhost), and use connmanctl to first, find all WIFI hotspot and if they reguire password. The Javascript then show this, and SSH again to connect and so on..
Do you know a opensource system, which do that? or a better way to do it?
Share Improve this question asked Oct 7, 2014 at 9:44 klausenbuskklausenbusk 411 gold badge1 silver badge4 bronze badges 1- 1 SSH to localhost seems redundant. – Biffen Commented Oct 7, 2014 at 9:52
2 Answers
Reset to default 3This is what i would do.
You can run system code with the function shell_exec. Use this function in your PHP script to execute the native WiFi connection possibilities of your Linux distribution. How to do this for your distro is most likey answered here.
Good luck!
I am using php-wifi in my project. It gives you interfaces to scan, connect and disconnects to wifi. Based on embedded in OS utilities. Here is an example of a controller and web form:
Connect to wi-fi with PHP - screen
<?php
use Sanches\WiFi\WiFi;
class Example
{
public $device;
/**
* @throws Exception
*/
public function getAllNetworks()
{
$allNetworks = WiFi::scan()->getAll();
if (count($allNetworks) > 0) {
foreach ($allNetworks as $network) {
echo $network . "\n";
}
}
}
/**
* @param $ssid
* @param $password
* @throws Exception
*/
public function connect($ssid, $password)
{
$networks = WiFi::scan()
->getBySsid($ssid);
if (count($networks) > 0) {
$networks[0]->connect($password, $this->device);
} else {
echo "Network $ssid wasn't found!\r\n";
}
}
/**
* @throws Exception
*/
public function disconnect()
{
$connectedNetworks = WiFi::scan()->getConnected();
foreach ($connectedNetworks as $network) {
$network->disconnect($this->device);
}
}
}
$example = new Example();
try {
$example->device = 'en1';
$example->getAllNetworks();
$example->connect('Redmi', '12345');
$example->disconnect();
} catch (Exception $e) {
//
}
本文标签: How to connect to WIFI from a browser with Javascript and PHPStack Overflow
版权声明:本文标题:How to connect to WIFI from a browser with Javascript and PHP? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741848214a2400905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论