Merge pull request #1 from lakinduakash/dev-1

Dev 1
This commit is contained in:
Lakindu Akash 2019-04-13 03:57:37 +05:30 committed by GitHub
commit 48add96e85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 406 additions and 4 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build
.idea

23
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.12)
project(wihotspot C)
include(FindPkgConfig)
pkg_check_modules(GTK gtk+-3.0 REQUIRED)
include_directories(${GTK_INCLUDE_DIRS})
set(CMAKE_C_STANDARD 99)
add_executable(wihotspot ui/main.c ui/h_prop.c ui/h_prop.h)
target_link_libraries(${PROJECT_NAME} ${GTK_LIBRARIES} "pthread")
include_directories(/usr/include)
set (source "${CMAKE_SOURCE_DIR}/ui/glade")
set (destination "${CMAKE_CURRENT_BINARY_DIR}/glade")
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ${source} ${destination}
DEPENDS ${destination}
COMMENT "symbolic link resources folder from ${source} => ${destination}"
)

22
src/makefile.old Normal file
View File

@ -0,0 +1,22 @@
CC=gcc
CFLAGS=`pkg-config --cflags gtk+-3.0`
ODIR=../build
LIBS=`pkg-config --libs gtk+-3.0`
_OBJ = main.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: ui/%.c
$(CC) -c -o $@ $< $(CFLAGS)
wihotspot: $(OBJ)
$(CC) -o ui/$@ $^ $(CFLAGS) $(LIBS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o

View File

@ -354,6 +354,10 @@ is_wifi_connected() {
return 1
}
#is_wifi_connected() {
# return 1
#}
is_macaddr() {
echo "$1" | grep -E "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$" > /dev/null 2>&1
}
@ -625,6 +629,7 @@ VHT_CAPAB=
DRIVER=nl80211
NO_VIRT=0
COUNTRY=
FREQ_BAND_SET=0
FREQ_BAND=2.4
NEW_MACADDR=
DAEMONIZE=0
@ -1132,6 +1137,7 @@ while :; do
--freq-band)
shift
FREQ_BAND="$1"
FREQ_BAND_SET=1
shift
;;
--mac)
@ -1230,8 +1236,7 @@ if [[ -n "$LOAD_CONFIG" && $# -eq 0 ]]; then
fi
# Check if required number of positional args are present
if [[ $# -lt 1 && $FIX_UNMANAGED -eq 0 && -z "$STOP_ID" &&
$LIST_RUNNING -eq 0 && -z "$LIST_CLIENTS_ID" ]]; then
if [[ $# -lt 1 && $FIX_UNMANAGED -eq 0 && -z "$STOP_ID" && $LIST_RUNNING -eq 0 && -z "$LIST_CLIENTS_ID" ]]; then
usage >&2
exit 1
fi
@ -1528,7 +1533,8 @@ if [[ $NO_VIRT -eq 0 ]]; then
echo "DONE"
fi
if is_wifi_connected ${WIFI_IFACE}; then
if is_wifi_connected ${WIFI_IFACE} && [[ $FREQ_BAND_SET -eq 0 ]]; then
WIFI_IFACE_FREQ=$(iw dev ${WIFI_IFACE} link | grep -i freq | awk '{print $2}')
WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel ${WIFI_IFACE_FREQ})
echo -n "${WIFI_IFACE} is already associated with channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
@ -1541,10 +1547,14 @@ if [[ $NO_VIRT -eq 0 ]]; then
echo ", fallback to channel ${WIFI_IFACE_CHANNEL}"
CHANNEL=$WIFI_IFACE_CHANNEL
else
echo
echo "channel------------------ ${CHANNEL}"
fi
elif is_wifi_connected ${WIFI_IFACE} && [[ $FREQ_BAND_SET -eq 1 ]]; then
echo "Custom frequency band set with ${FREQ_BAND}Mhz with channel ${CHANNEL}"
fi
VIRTDIEMSG="Maybe your WiFi adapter does not fully support virtual interfaces.
Try again with --no-virt."
echo -n "Creating a virtual WiFi interface... "

60
src/ui/glade/main.ui Normal file
View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="window">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">10</property>
<property name="title">Grid</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="quit">
<property name="label">Quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<signal name="clicked" handler="quit_clicked_cb" object="window" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="button1" object="window" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_new">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="ss" object="window" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

135
src/ui/glade/wifih.ui Normal file
View File

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="window">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">3</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">SSID</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="GtkEntry" id="entry_ssid">
<property name="visible">True</property>
<property name="can_focus">True</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="label" translatable="yes">Passphare</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="GtkEntry" id="entry_pass">
<property name="visible">True</property>
<property name="can_focus">True</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">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkButton" id="button_stop_hp">
<property name="label" translatable="yes">Stop</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</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>
<object class="GtkButton" id="button_create_hp">
<property name="label" translatable="yes">Create hotspot</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">10</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">10</property>
<property name="position">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>

54
src/ui/h_prop.c Normal file
View File

@ -0,0 +1,54 @@
//
// Created by lakinduakash on 13/04/19.
//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "h_prop.h"
#define BUFSIZE 1024
#define SUDO "sudo"
#define CREATE_AP "create_ap"
char cmd[BUFSIZE];
int parse_output(char *cmd) {
char buf[BUFSIZE];
FILE *fp;
if ((fp = popen(cmd, "r")) == NULL) {
printf("Error opening pipe!\n");
return -1;
}
while (fgets(buf, BUFSIZE, fp) != NULL) {
// Do whatever you want here...
printf("OUTPUT: %s", buf);
}
if (pclose(fp)) {
printf("Command not found or exited with error status\n");
return -1;
}
return 0;
}
char *build_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);
return cmd;
}
int startShell(char *cmd) {
parse_output(cmd);
}

12
src/ui/h_prop.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by lakinduakash on 13/04/19.
//
#ifndef WIHOTSPOT_H_PROP_H
#define WIHOTSPOT_H_PROP_H
int parse_output(char *);
char * build_command(char*, char*,char*, char*);
int startShell(char*);
#endif //WIHOTSPOT_H_PROP_H

84
src/ui/main.c Normal file
View File

@ -0,0 +1,84 @@
#include <gtk/gtk.h>
#include <stdlib.h>
#include <pthread.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();
return 0;
}