mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2025-02-16 07:30:09 +00:00
commit
d9c233f7b5
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
build
|
||||
.idea
|
||||
.idea
|
||||
src/cmake-build-debug
|
26
LICENSE
26
LICENSE
@ -1,29 +1,3 @@
|
||||
Copyright (c) 2013, oblique
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*All modification to this software is under following licence
|
||||
|
||||
Copyright (c) 2019, lakinduaksh
|
||||
All rights reserved.
|
||||
|
||||
|
13
Makefile
Normal file
13
Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
PREFIX=/usr
|
||||
MANDIR=$(PREFIX)/share/man
|
||||
BINDIR=$(PREFIX)/bin
|
||||
|
||||
all:
|
||||
@echo "Run 'make install' for installation."
|
||||
@echo "Run 'make uninstall' for uninstallation."
|
||||
|
||||
install:
|
||||
$(MAKE) -C src/scripts install
|
||||
|
||||
uninstall:
|
||||
$(MAKE) -C src/scripts uninstall
|
97
README.md
97
README.md
@ -1,89 +1,12 @@
|
||||
## Features
|
||||
* Create an AP (Access Point) at any channel.
|
||||
* Choose one of the following encryptions: WPA, WPA2, WPA/WPA2, Open (no encryption).
|
||||
* Hide your SSID.
|
||||
* Disable communication between clients (client isolation).
|
||||
* IEEE 802.11n & 802.11ac support
|
||||
* Internet sharing methods: NATed or Bridged or None (no Internet sharing).
|
||||
* Choose the AP Gateway IP (only for 'NATed' and 'None' Internet sharing methods).
|
||||
* You can create an AP with the same interface you are getting your Internet connection.
|
||||
* You can pass your SSID and password through pipe or through arguments (see examples).
|
||||
## Linux Wifi Hotspot
|
||||
|
||||
### Features
|
||||
|
||||
* Share your wifi like in Windows - Share wifi on same interface while you are connected to a network
|
||||
|
||||
* Support both 2.4GHz and 5GHz (Need to compatible with your wifi adapter). Ex: You have connected to 5GHz and share connection with 2.4GHz
|
||||
|
||||
* Select Channel to share
|
||||
|
||||
|
||||
## Dependencies
|
||||
### General
|
||||
* bash (to run this script)
|
||||
* util-linux (for getopt)
|
||||
* procps or procps-ng
|
||||
* hostapd
|
||||
* iproute2
|
||||
* iw
|
||||
* iwconfig (you only need this if 'iw' can not recognize your adapter)
|
||||
* haveged (optional)
|
||||
|
||||
### For 'NATed' or 'None' Internet sharing method
|
||||
* dnsmasq
|
||||
* iptables
|
||||
|
||||
|
||||
## Installation
|
||||
### Generic
|
||||
git clone https://github.com/oblique/create_ap
|
||||
cd create_ap
|
||||
make install
|
||||
|
||||
### ArchLinux
|
||||
pacman -S create_ap
|
||||
|
||||
### Gentoo
|
||||
emerge layman
|
||||
layman -f -a jorgicio
|
||||
emerge net-wireless/create_ap
|
||||
|
||||
## Examples
|
||||
### No passphrase (open network):
|
||||
create_ap wlan0 eth0 MyAccessPoint
|
||||
|
||||
### WPA + WPA2 passphrase:
|
||||
create_ap wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### AP without Internet sharing:
|
||||
create_ap -n wlan0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Bridged Internet sharing:
|
||||
create_ap -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Bridged Internet sharing (pre-configured bridge interface):
|
||||
create_ap -m bridge wlan0 br0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Internet sharing from the same WiFi interface:
|
||||
create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Choose a different WiFi adapter driver
|
||||
create_ap --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### No passphrase (open network) using pipe:
|
||||
echo -e "MyAccessPoint" | create_ap wlan0 eth0
|
||||
|
||||
### WPA + WPA2 passphrase using pipe:
|
||||
echo -e "MyAccessPoint\nMyPassPhrase" | create_ap wlan0 eth0
|
||||
|
||||
### Enable IEEE 802.11n
|
||||
create_ap --ieee80211n --ht_capab '[HT40+]' wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Client Isolation:
|
||||
create_ap --isolate-clients wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
## Systemd service
|
||||
Using the persistent [systemd](https://wiki.archlinux.org/index.php/systemd#Basic_systemctl_usage) service
|
||||
### Start service immediately:
|
||||
systemctl start create_ap
|
||||
|
||||
### Start on boot:
|
||||
systemctl enable create_ap
|
||||
|
||||
|
||||
## License
|
||||
FreeBSD
|
||||
- Copyright (c) 2013, oblique
|
||||
- Copyright (c) 2019, lakinduakash
|
||||
### Installing
|
||||
|
@ -1,15 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(wihotspot C)
|
||||
project(wihotspot)
|
||||
|
||||
include(FindPkgConfig)
|
||||
pkg_check_modules(GTK gtk+-3.0 REQUIRED)
|
||||
include_directories(${GTK_INCLUDE_DIRS})
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(wihotspot ui/main.c ui/h_prop.c ui/h_prop.h)
|
||||
add_executable(wihotspot ui/main.c ui/h_prop.c ui/h_prop.h ui/ui.c ui/ui.h ui/read_config.cpp ui/read_config.h)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ${GTK_LIBRARIES} "pthread")
|
||||
target_link_libraries(${PROJECT_NAME} ${GTK_LIBRARIES} config)
|
||||
|
||||
include_directories(/usr/include)
|
||||
|
||||
|
49
src/scripts/LICENSE
Normal file
49
src/scripts/LICENSE
Normal file
@ -0,0 +1,49 @@
|
||||
Copyright (c) 2013, oblique
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*All modification to this software is under following licence
|
||||
|
||||
Copyright (c) 2019, lakinduaksh
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
89
src/scripts/README.md
Normal file
89
src/scripts/README.md
Normal file
@ -0,0 +1,89 @@
|
||||
## Features
|
||||
* Create an AP (Access Point) at any channel.
|
||||
* Choose one of the following encryptions: WPA, WPA2, WPA/WPA2, Open (no encryption).
|
||||
* Hide your SSID.
|
||||
* Disable communication between clients (client isolation).
|
||||
* IEEE 802.11n & 802.11ac support
|
||||
* Internet sharing methods: NATed or Bridged or None (no Internet sharing).
|
||||
* Choose the AP Gateway IP (only for 'NATed' and 'None' Internet sharing methods).
|
||||
* You can create an AP with the same interface you are getting your Internet connection.
|
||||
* You can pass your SSID and password through pipe or through arguments (see examples).
|
||||
|
||||
|
||||
## Dependencies
|
||||
### General
|
||||
* bash (to run this script)
|
||||
* util-linux (for getopt)
|
||||
* procps or procps-ng
|
||||
* hostapd
|
||||
* iproute2
|
||||
* iw
|
||||
* iwconfig (you only need this if 'iw' can not recognize your adapter)
|
||||
* haveged (optional)
|
||||
|
||||
### For 'NATed' or 'None' Internet sharing method
|
||||
* dnsmasq
|
||||
* iptables
|
||||
|
||||
|
||||
## Installation
|
||||
### Generic
|
||||
git clone https://github.com/oblique/create_ap
|
||||
cd create_ap
|
||||
make install
|
||||
|
||||
### ArchLinux
|
||||
pacman -S create_ap
|
||||
|
||||
### Gentoo
|
||||
emerge layman
|
||||
layman -f -a jorgicio
|
||||
emerge net-wireless/create_ap
|
||||
|
||||
## Examples
|
||||
### No passphrase (open network):
|
||||
create_ap wlan0 eth0 MyAccessPoint
|
||||
|
||||
### WPA + WPA2 passphrase:
|
||||
create_ap wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### AP without Internet sharing:
|
||||
create_ap -n wlan0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Bridged Internet sharing:
|
||||
create_ap -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Bridged Internet sharing (pre-configured bridge interface):
|
||||
create_ap -m bridge wlan0 br0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Internet sharing from the same WiFi interface:
|
||||
create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Choose a different WiFi adapter driver
|
||||
create_ap --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### No passphrase (open network) using pipe:
|
||||
echo -e "MyAccessPoint" | create_ap wlan0 eth0
|
||||
|
||||
### WPA + WPA2 passphrase using pipe:
|
||||
echo -e "MyAccessPoint\nMyPassPhrase" | create_ap wlan0 eth0
|
||||
|
||||
### Enable IEEE 802.11n
|
||||
create_ap --ieee80211n --ht_capab '[HT40+]' wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
### Client Isolation:
|
||||
create_ap --isolate-clients wlan0 eth0 MyAccessPoint MyPassPhrase
|
||||
|
||||
## Systemd service
|
||||
Using the persistent [systemd](https://wiki.archlinux.org/index.php/systemd#Basic_systemctl_usage) service
|
||||
### Start service immediately:
|
||||
systemctl start create_ap
|
||||
|
||||
### Start on boot:
|
||||
systemctl enable create_ap
|
||||
|
||||
|
||||
## License
|
||||
FreeBSD
|
||||
- Copyright (c) 2013, oblique
|
||||
- Copyright (c) 2019, lakinduakash
|
@ -985,6 +985,8 @@ write_config() {
|
||||
eval echo $config_opt=\$$config_opt
|
||||
done >> "$STORE_CONFIG"
|
||||
|
||||
chmod 600 $STORE_CONFIG
|
||||
chown $(logname):$(logname) $STORE_CONFIG
|
||||
echo -e "Config options written to '$STORE_CONFIG'"
|
||||
exit 0
|
||||
}
|
||||
@ -1262,7 +1264,7 @@ trap "die" SIGUSR2
|
||||
[[ -n "$STORE_CONFIG" ]] && write_config "$@"
|
||||
|
||||
if [[ $LIST_RUNNING -eq 1 ]]; then
|
||||
echo -e "List of running $PROGNAME instances:\n"
|
||||
#echo -e "List of running $PROGNAME instances:\n"
|
||||
list_running
|
||||
exit 0
|
||||
fi
|
||||
|
@ -18,10 +18,13 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">3</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="label" translatable="yes">SSID</property>
|
||||
</object>
|
||||
<packing>
|
||||
@ -47,6 +50,8 @@
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_left">20</property>
|
||||
<property name="label" translatable="yes">Passphare</property>
|
||||
</object>
|
||||
<packing>
|
||||
@ -77,7 +82,71 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="label" translatable="yes">Wifi interface</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">2</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="combo_wifi">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">2</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_left">20</property>
|
||||
<property name="label" translatable="yes">Internet interface</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">2</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="combo_internet">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">2</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">10</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
|
208
src/ui/h_prop.c
208
src/ui/h_prop.c
@ -4,19 +4,35 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "h_prop.h"
|
||||
#include "read_config.h"
|
||||
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
|
||||
#define SUDO "sudo"
|
||||
#define SUDO "pkexec --user root"
|
||||
#define CREATE_AP "create_ap"
|
||||
|
||||
char cmd[BUFSIZE];
|
||||
#define MKCONFIG "--mkconfig"
|
||||
#define LOAD_CONFIG "--config"
|
||||
|
||||
int parse_output(char *cmd) {
|
||||
|
||||
char cmd_start[BUFSIZE];
|
||||
char cmd_mkconfig[BUFSIZE];
|
||||
char cmd_config[BUFSIZE];
|
||||
|
||||
char running_info[BUFSIZE];
|
||||
char interface_list[BUFSIZE];
|
||||
|
||||
const char* g_ssid=NULL;
|
||||
const char* g_pass=NULL;
|
||||
|
||||
config_t cfg;
|
||||
|
||||
static int parse_output(const char *cmd) {
|
||||
|
||||
char buf[BUFSIZE];
|
||||
FILE *fp;
|
||||
@ -28,7 +44,7 @@ int parse_output(char *cmd) {
|
||||
|
||||
while (fgets(buf, BUFSIZE, fp) != NULL) {
|
||||
// Do whatever you want here...
|
||||
printf("OUTPUT: %s", buf);
|
||||
printf("%s", buf);
|
||||
}
|
||||
|
||||
if (pclose(fp)) {
|
||||
@ -40,15 +56,187 @@ int parse_output(char *cmd) {
|
||||
}
|
||||
|
||||
|
||||
char *build_command(char *iface_src, char *iface_dest, char *ssid, char *pass) {
|
||||
const char *build_wh_start_command(char *iface_src, char *iface_dest, char *ssid, char *pass) {
|
||||
|
||||
snprintf(cmd, BUFSIZE, "%s %s %s %s %s %s", SUDO, CREATE_AP, iface_src, iface_dest, ssid, pass);
|
||||
snprintf(cmd_start, BUFSIZE, "%s %s %s %s %s %s", SUDO, CREATE_AP, iface_src, iface_dest, ssid, pass);
|
||||
|
||||
return cmd_start;
|
||||
}
|
||||
|
||||
return cmd;
|
||||
const char *build_wh_mkconfig_command(char *iface_src, char *iface_dest, char *ssid, char *pass){
|
||||
|
||||
const char* a=get_config_file(CONFIG_FILE_NAME);
|
||||
|
||||
snprintf(cmd_mkconfig, BUFSIZE, "%s %s %s %s %s %s %s", CREATE_AP, iface_src, iface_dest, ssid, pass,MKCONFIG,a);
|
||||
printf("%s \n",cmd_mkconfig);
|
||||
return cmd_mkconfig;
|
||||
|
||||
}
|
||||
|
||||
const char *build_wh_from_config(){
|
||||
|
||||
snprintf(cmd_config, BUFSIZE, "%s %s %s %s", SUDO, CREATE_AP,LOAD_CONFIG,get_config_file(CONFIG_FILE_NAME));
|
||||
return cmd_config;
|
||||
|
||||
}
|
||||
|
||||
int startShell(const char *cmd) {
|
||||
parse_output(cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int startShell(char *cmd) {
|
||||
parse_output(cmd);
|
||||
}
|
||||
int write_config(char* file){
|
||||
|
||||
config_t cfg;
|
||||
config_setting_t *root, *setting, *group, *array;
|
||||
int i;
|
||||
|
||||
config_init(&cfg);
|
||||
root = config_root_setting(&cfg);
|
||||
|
||||
/* Add some settings to the configuration. */
|
||||
|
||||
|
||||
setting = config_setting_add(root, SSID, CONFIG_TYPE_STRING);
|
||||
config_setting_set_string(setting, "myssid");
|
||||
|
||||
setting = config_setting_add(root, PASSPHRASE, CONFIG_TYPE_STRING);
|
||||
config_setting_set_string(setting, "123456789");
|
||||
|
||||
/* Write out the new configuration. */
|
||||
if(! config_write_file(&cfg, get_config_file(CONFIG_FILE_NAME)))
|
||||
{
|
||||
fprintf(stderr, "Error while writing file.\n");
|
||||
config_destroy(&cfg);
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fprintf(stderr, "New configuration successfully written to: %s\n",
|
||||
get_config_file(CONFIG_FILE_NAME));
|
||||
|
||||
config_destroy(&cfg);
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
static int init_get_running(){
|
||||
|
||||
const char* cmd="create_ap --list-running";
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = popen(cmd, "r")) == NULL) {
|
||||
printf("Error opening pipe!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(running_info, BUFSIZE, fp) != NULL) {
|
||||
// Do whatever you want here...
|
||||
//printf("%s", running_info);
|
||||
}
|
||||
|
||||
if (pclose(fp)) {
|
||||
printf("Command not found or exited with error status\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Ex:
|
||||
// char *a[3];
|
||||
//get_running_info(a);
|
||||
//printf("%s",a[0]);
|
||||
|
||||
int get_running_info(char* a[3]){
|
||||
|
||||
if(init_get_running()==0){
|
||||
char * pch;
|
||||
pch = strtok (running_info," ");
|
||||
int i=0;
|
||||
while (pch != NULL && i<3)
|
||||
{
|
||||
a[i] = strdup(pch);
|
||||
pch = strtok (NULL, " ");
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int init_get_interface_list(){
|
||||
const char* cmd="ls -x /sys/class/net ";
|
||||
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = popen(cmd, "r")) == NULL) {
|
||||
printf("Error opening pipe!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(interface_list, BUFSIZE, fp) != NULL) {
|
||||
// Do whatever you want here...
|
||||
//printf("%s", running_info);
|
||||
}
|
||||
|
||||
if (pclose(fp)) {
|
||||
printf("Command not found or exited with error status\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//int i=0;
|
||||
//char ** a=get_interface_list(&i);
|
||||
//
|
||||
//for(int j=0;j<i;j++){
|
||||
//printf("%s ",a[j]);
|
||||
//}
|
||||
|
||||
char** get_interface_list(int *length){
|
||||
|
||||
if(init_get_interface_list()==0){
|
||||
|
||||
char *a=strdup(interface_list);
|
||||
char *b=strdup(interface_list);
|
||||
|
||||
char * pch;
|
||||
pch = strtok (a," ");
|
||||
int i=0;
|
||||
while (pch != NULL)
|
||||
{
|
||||
pch = strtok (NULL, " ");
|
||||
i++;
|
||||
}
|
||||
|
||||
static char** arr;
|
||||
arr =malloc(i * sizeof(char*));
|
||||
|
||||
free(a);
|
||||
|
||||
pch = strtok (b," ");
|
||||
i=0;
|
||||
while (pch != NULL)
|
||||
{
|
||||
arr[i]=strdup(pch);
|
||||
pch = strtok (NULL, " \n");
|
||||
i++;
|
||||
}
|
||||
|
||||
*length= i;
|
||||
|
||||
return arr;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,21 @@
|
||||
#ifndef WIHOTSPOT_H_PROP_H
|
||||
#define WIHOTSPOT_H_PROP_H
|
||||
|
||||
int parse_output(char *);
|
||||
char * build_command(char*, char*,char*, char*);
|
||||
int startShell(char*);
|
||||
|
||||
static int parse_output(const char *);
|
||||
|
||||
const char *build_wh_start_command(char *, char *, char *, char *);
|
||||
const char *build_wh_mkconfig_command(char *, char *, char *, char *);
|
||||
const char *build_wh_from_config(void);
|
||||
|
||||
int startShell(const char *);
|
||||
|
||||
int write_config(char *);
|
||||
|
||||
int get_running_info(char** a);
|
||||
static int init_get_running();
|
||||
|
||||
static int init_get_interface_list();
|
||||
char** get_interface_list(int*);
|
||||
|
||||
#endif //WIHOTSPOT_H_PROP_H
|
||||
|
@ -1,84 +1,14 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "ui.h"
|
||||
#include "h_prop.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
|
||||
typedef struct {
|
||||
GtkEntry *ssid;
|
||||
GtkEntry *pass;
|
||||
} WIData;
|
||||
|
||||
|
||||
void *threadFunc(void *args) {
|
||||
startShell(args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *stopHp() {
|
||||
startShell("sudo create_ap --stop ap0");
|
||||
}
|
||||
|
||||
static void on_create_hp_clicked(GtkWidget *widget,
|
||||
gpointer data) {
|
||||
|
||||
WIData *d = (WIData *) data;
|
||||
g_thread_new("shell", threadFunc, build_command("wlp3s0", "wlp3s0", (char *) gtk_entry_get_text(d->ssid),
|
||||
(char *) gtk_entry_get_text(d->pass)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void on_stop_hp_clicked(GtkWidget *widget, gpointer data) {
|
||||
g_thread_new("shell2", stopHp, NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
GtkBuilder *builder;
|
||||
GObject *window;
|
||||
GtkButton *button_create_hp;
|
||||
GtkButton *button_stop_hp;
|
||||
GtkEntry *entry_ssd;
|
||||
GtkEntry *entry_pass;
|
||||
GError *error = NULL;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
builder = gtk_builder_new();
|
||||
if (gtk_builder_add_from_file(builder, "glade/wifih.ui", &error) == 0) {
|
||||
g_printerr("Error loading file: %s\n", error->message);
|
||||
g_clear_error(&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Connect signal handlers to the constructed widgets. */
|
||||
window = gtk_builder_get_object(builder, "window");
|
||||
g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
|
||||
|
||||
entry_ssd = (GtkEntry *) gtk_builder_get_object(builder, "entry_ssid");
|
||||
entry_pass = (GtkEntry *) gtk_builder_get_object(builder, "entry_pass");
|
||||
|
||||
|
||||
WIData wiData = {
|
||||
.pass= entry_pass,
|
||||
.ssid= entry_ssd
|
||||
};
|
||||
|
||||
button_create_hp = (GtkButton *) gtk_builder_get_object(builder, "button_create_hp");
|
||||
g_signal_connect (button_create_hp, "clicked", G_CALLBACK(on_create_hp_clicked), &wiData);
|
||||
|
||||
button_stop_hp = (GtkButton *) gtk_builder_get_object(builder, "button_stop_hp");
|
||||
g_signal_connect (button_stop_hp, "clicked", G_CALLBACK(on_stop_hp_clicked), NULL);
|
||||
|
||||
gtk_main();
|
||||
|
||||
initUi(argc,argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
95
src/ui/read_config.cpp
Normal file
95
src/ui/read_config.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
//
|
||||
// Created by lakinduakash on 14/04/19.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "read_config.h"
|
||||
|
||||
#define CONFIG_KEY_COUNT 30
|
||||
#define STRING_MAX_LENGTH 100
|
||||
#define BUFSIZE 150
|
||||
|
||||
extern "C" {
|
||||
|
||||
ConfigValues configValues;
|
||||
|
||||
char configs[CONFIG_KEY_COUNT][STRING_MAX_LENGTH];
|
||||
|
||||
int read_config_file() {
|
||||
// std::ifstream is RAII, i.e. no need to call close
|
||||
std::ifstream cFile(get_config_file(CONFIG_FILE_NAME));
|
||||
if (cFile.is_open()) {
|
||||
std::string line;
|
||||
|
||||
int i=0;
|
||||
while (getline(cFile, line)) {
|
||||
line.erase(std::remove_if(line.begin(), line.end(), isspace),
|
||||
line.end());
|
||||
if (line[0] == '#' || line.empty())
|
||||
continue;
|
||||
auto delimiterPos = line.find('=');
|
||||
auto name = line.substr(0, delimiterPos);
|
||||
auto value = line.substr(delimiterPos + 1);
|
||||
|
||||
strcpy(configs[i],value.c_str());
|
||||
setConfigValues(name.c_str(),configs[i]);
|
||||
//std::cout << name << " " << value << '\n';
|
||||
++i;
|
||||
}
|
||||
|
||||
} else {
|
||||
std::cerr << "Couldn't open config file for reading.\n";
|
||||
return READ_CONFIG_FILE_FAIL;
|
||||
}
|
||||
|
||||
return READ_CONFIG_FILE_SUCCESS;
|
||||
}
|
||||
|
||||
ConfigValues* getConfigValues(){
|
||||
return &configValues;
|
||||
}
|
||||
|
||||
|
||||
static void setConfigValues(const char * key, char *value){
|
||||
|
||||
if( !strcmp ( SSID, key ))
|
||||
configValues.ssid = value;
|
||||
|
||||
if( !strcmp ( PASSPHRASE, key ))
|
||||
configValues.pass = value;
|
||||
|
||||
if( !strcmp ( WIFI_IFACE, key ))
|
||||
configValues.iface_wifi = value;
|
||||
|
||||
if( !strcmp ( INTERNET_IFACE, key ))
|
||||
configValues.iface_inet = value;
|
||||
}
|
||||
|
||||
|
||||
const char* get_config_file(const char* file){
|
||||
static char *homedir;
|
||||
|
||||
static char a[BUFSIZE];
|
||||
|
||||
if ((homedir = getenv("HOME")) == nullptr) {
|
||||
homedir = getpwuid(getuid())->pw_dir;
|
||||
}
|
||||
snprintf(a,BUFSIZE,"%s%s%s",homedir,"/",file);
|
||||
|
||||
//printf(" from %s \n",a);
|
||||
return (const char*)a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
70
src/ui/read_config.h
Normal file
70
src/ui/read_config.h
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Created by lakinduakash on 14/04/19.
|
||||
//
|
||||
|
||||
#ifndef WIHOTSPOT_READ_CONFIG_H
|
||||
#define WIHOTSPOT_READ_CONFIG_H
|
||||
|
||||
#include "h_prop.h"
|
||||
|
||||
#define READ_CONFIG_FILE_SUCCESS 0
|
||||
#define READ_CONFIG_FILE_FAIL 1
|
||||
|
||||
|
||||
|
||||
#define CHANNEL "CHANNEL"
|
||||
#define GATEWAY "GATEWAY"
|
||||
#define WPA_VERSION "WPA_VERSION"
|
||||
#define ETC_HOSTS "ETC_HOSTS"
|
||||
#define DHCP_DNS "DHCP_DNS"
|
||||
#define NO_DNS "NO_DNS"
|
||||
#define NO_DNSMASQ "NO_DNSMASQ"
|
||||
#define HIDDEN "HIDDEN"
|
||||
#define MAC_FILTER "MAC_FILTER"
|
||||
#define MAC_FILTER_ACCEP "MAC_FILTER_ACCEPT"
|
||||
#define ISOLATE_CLIENTS "ISOLATE_CLIENTS"
|
||||
#define SHARE_METHOD "SHARE_METHOD"
|
||||
#define IEEE80211N "IEEE80211N"
|
||||
#define IEEE80211AC "IEEE80211AC"
|
||||
#define HT_CAPAB "HT_CAPAB"
|
||||
#define VHT_CAPAB "VHT_CAPAB"
|
||||
#define DRIVER "DRIVER"
|
||||
#define NO_VIRT "NO_VIRT"
|
||||
#define COUNTRY "COUNTRY"
|
||||
#define FREQ_BAND "FREQ_BAND"
|
||||
#define NEW_MACADDR "NEW_MACADDR"
|
||||
#define DAEMONIZE "DAEMONIZE"
|
||||
#define NO_HAVEGED "NO_HAVEGED"
|
||||
#define WIFI_IFACE "WIFI_IFACE"
|
||||
#define INTERNET_IFACE "INTERNET_IFACE"
|
||||
#define SSID "SSID"
|
||||
#define PASSPHRASE "PASSPHRASE"
|
||||
#define USE_PSK "USE_PSK"
|
||||
|
||||
|
||||
|
||||
#define CONFIG_FILE_NAME ".wh.config"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct{
|
||||
char *ssid;
|
||||
char *pass;
|
||||
char *iface_wifi;
|
||||
char *iface_inet;
|
||||
} ConfigValues;
|
||||
|
||||
int read_config_file();
|
||||
static void setConfigValues(const char * key, char *value);
|
||||
ConfigValues* getConfigValues(void);
|
||||
const char *get_config_file(const char* file);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif //WIHOTSPOT_READ_CONFIG_H
|
183
src/ui/ui.c
Normal file
183
src/ui/ui.c
Normal file
@ -0,0 +1,183 @@
|
||||
//
|
||||
// Created by lakinduakash on 13/04/19.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "h_prop.h"
|
||||
#include "ui.h"
|
||||
#include "read_config.h"
|
||||
|
||||
GtkBuilder *builder;
|
||||
GObject *window;
|
||||
GtkButton *button_create_hp;
|
||||
GtkButton *button_stop_hp;
|
||||
GtkEntry *entry_ssd;
|
||||
GtkEntry *entry_pass;
|
||||
|
||||
GtkComboBox *combo_wifi;
|
||||
GtkComboBox *combo_internet;
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
|
||||
const char** iface_list;
|
||||
int iface_list_length;
|
||||
|
||||
void init_interface_list();
|
||||
static int find_str(char *find, const char **array, int length);
|
||||
|
||||
void *threadFunc(void *args) {
|
||||
startShell(args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *stopHp() {
|
||||
startShell("sudo create_ap --stop ap0");
|
||||
}
|
||||
|
||||
static void on_create_hp_clicked(GtkWidget *widget,
|
||||
gpointer data) {
|
||||
|
||||
WIData *d = (WIData *) data;
|
||||
|
||||
if (gtk_combo_box_get_active (combo_wifi) >= 0 && gtk_combo_box_get_active (combo_internet) >= 0) {
|
||||
|
||||
|
||||
gchar *wifi = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(combo_wifi));
|
||||
gchar *internet = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(combo_internet));
|
||||
|
||||
//Remove trailing new lines
|
||||
wifi[strcspn(wifi, "\n")] = 0;
|
||||
internet[strcspn(internet, "\n")] = 0;
|
||||
|
||||
startShell(build_wh_mkconfig_command(wifi, internet, (char *) gtk_entry_get_text(d->ssid),
|
||||
(char *) gtk_entry_get_text(d->pass)));
|
||||
|
||||
g_thread_new("shell_create_hp", threadFunc, (void*)build_wh_from_config());
|
||||
|
||||
g_free (wifi);
|
||||
g_free (internet);
|
||||
} else{
|
||||
|
||||
g_print("Please select Wifi and Internet interfaces\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void on_stop_hp_clicked(GtkWidget *widget, gpointer data) {
|
||||
g_thread_new("shell2", stopHp, NULL);
|
||||
|
||||
}
|
||||
|
||||
int initUi(int argc, char *argv[]){
|
||||
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
builder = gtk_builder_new();
|
||||
if (gtk_builder_add_from_file(builder, "glade/wifih.ui", &error) == 0) {
|
||||
g_printerr("Error loading file: %s\n", error->message);
|
||||
g_clear_error(&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Connect signal handlers to the constructed widgets. */
|
||||
window = gtk_builder_get_object(builder, "window");
|
||||
g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
|
||||
|
||||
entry_ssd = (GtkEntry *) gtk_builder_get_object(builder, "entry_ssid");
|
||||
entry_pass = (GtkEntry *) gtk_builder_get_object(builder, "entry_pass");
|
||||
|
||||
combo_wifi = (GtkComboBox *) gtk_builder_get_object(builder, "combo_wifi");
|
||||
combo_internet = (GtkComboBox *) gtk_builder_get_object(builder, "combo_internet");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
WIData wiData = {
|
||||
.pass= entry_pass,
|
||||
.ssid= entry_ssd
|
||||
};
|
||||
|
||||
init_interface_list();
|
||||
|
||||
init_ui_from_config(&wiData);
|
||||
|
||||
button_create_hp = (GtkButton *) gtk_builder_get_object(builder, "button_create_hp");
|
||||
g_signal_connect (button_create_hp, "clicked", G_CALLBACK(on_create_hp_clicked), &wiData);
|
||||
|
||||
button_stop_hp = (GtkButton *) gtk_builder_get_object(builder, "button_stop_hp");
|
||||
g_signal_connect (button_stop_hp, "clicked", G_CALLBACK(on_stop_hp_clicked), NULL);
|
||||
|
||||
|
||||
gtk_main();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void init_ui_from_config(WIData* data){
|
||||
|
||||
if(read_config_file()==READ_CONFIG_FILE_SUCCESS){
|
||||
|
||||
ConfigValues *values=getConfigValues();
|
||||
|
||||
|
||||
if(values->ssid!=NULL)
|
||||
gtk_entry_set_text(data->ssid,values->ssid);
|
||||
if(values->pass!=NULL)
|
||||
gtk_entry_set_text(data->pass,values->pass);
|
||||
|
||||
if(values->iface_wifi!=NULL){
|
||||
int idw=find_str(values->iface_wifi,iface_list,iface_list_length);
|
||||
|
||||
if(idw !=-1){
|
||||
gtk_combo_box_set_active(combo_wifi,idw);
|
||||
}
|
||||
}
|
||||
|
||||
if(values->iface_inet!=NULL){
|
||||
int idw=find_str(values->iface_inet,iface_list,iface_list_length);
|
||||
|
||||
if(idw !=-1){
|
||||
gtk_combo_box_set_active(combo_internet,idw);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void init_interface_list(){
|
||||
|
||||
iface_list_length=0;
|
||||
iface_list=(const char**)get_interface_list(&iface_list_length);
|
||||
|
||||
for (int i = 0; i < iface_list_length; i++){
|
||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_wifi), iface_list[i]);
|
||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_internet), iface_list[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int find_str(char *find, const char **array, int length) {
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < length; i++ ) {
|
||||
g_print("%s ", array[i]);
|
||||
if (strcmp(array[i], find) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
18
src/ui/ui.h
Normal file
18
src/ui/ui.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by lakinduakash on 13/04/19.
|
||||
//
|
||||
|
||||
#ifndef WIHOTSPOT_UI_H
|
||||
#define WIHOTSPOT_UI_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
typedef struct {
|
||||
GtkEntry *ssid;
|
||||
GtkEntry *pass;
|
||||
} WIData;
|
||||
|
||||
int initUi(int argc, char *argv[]);
|
||||
void init_ui_from_config(WIData* data);
|
||||
|
||||
#endif //WIHOTSPOT_UI_H
|
Loading…
Reference in New Issue
Block a user