mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2025-02-16 07:30:09 +00:00
commit
c2302b5e33
@ -7,6 +7,7 @@
|
||||
* Includes Both command line and gui.
|
||||
* 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.
|
||||
* Hide ssid
|
||||
|
||||
### Dependencies
|
||||
|
||||
@ -48,6 +49,9 @@ install it using your distro's package manager_
|
||||
## Uninstallation
|
||||
sudo make uninstall
|
||||
|
||||
## Running
|
||||
`wihotspot`
|
||||
|
||||
Tested with Ubuntu 18.10. If any issue found, file a issue on github.
|
||||
|
||||
**credits** - oblique
|
||||
|
22
src/ui/glade/style.css
Normal file
22
src/ui/glade/style.css
Normal file
@ -0,0 +1,22 @@
|
||||
.stop_button{
|
||||
background: #ff3f4e;
|
||||
color: #ffffff;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.stop_button:disabled{
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
|
||||
button:active {
|
||||
background-color: #0274d9;
|
||||
}
|
||||
|
||||
.entry-error {
|
||||
border-color: #ff6a6b;
|
||||
}
|
||||
|
||||
.label-error{
|
||||
color: #ff3f4e;
|
||||
}
|
@ -50,17 +50,43 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<object class="GtkBox">
|
||||
<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>
|
||||
<property name="spacing">10</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Password</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="cb_open">
|
||||
<property name="label" translatable="yes">Open</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">2</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
@ -366,6 +392,7 @@
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
@ -375,6 +402,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">end</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -389,6 +417,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">end</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -423,14 +452,9 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_status">
|
||||
<object class="GtkSeparator">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_top">1</property>
|
||||
<property name="margin_bottom">1</property>
|
||||
<property name="label" translatable="yes">Running status</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -438,6 +462,47 @@
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_status">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_top">1</property>
|
||||
<property name="margin_bottom">1</property>
|
||||
<property name="label" translatable="yes">Running status</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_input_error">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
@ -66,11 +66,38 @@ const char *build_wh_start_command(char *iface_src, char *iface_dest, char *ssid
|
||||
return cmd_start;
|
||||
}
|
||||
|
||||
const char *build_wh_mkconfig_command(char *iface_src, char *iface_dest, char *ssid, char *pass){
|
||||
|
||||
const char *build_wh_mkconfig_command(ConfigValues* cv){
|
||||
|
||||
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);
|
||||
snprintf(cmd_mkconfig, BUFSIZE, "%s %s %s %s %s %s %s", CREATE_AP, cv->iface_wifi, cv->iface_inet, cv->ssid, cv->pass,MKCONFIG,a);
|
||||
|
||||
if(cv->freq!=NULL){
|
||||
strcat(cmd_mkconfig," --freq-band ");
|
||||
strcat(cmd_mkconfig,cv->freq);
|
||||
}
|
||||
|
||||
if(cv->no_virt!=NULL && (strcmp(cv->no_virt,"1") == 0))
|
||||
strcat(cmd_mkconfig," --no-virt ");
|
||||
|
||||
if(cv->use_psk!=NULL && (strcmp(cv->use_psk,"1") == 0))
|
||||
strcat(cmd_mkconfig," --psk ");
|
||||
|
||||
if(cv->hidden!=NULL && (strcmp(cv->hidden,"1") == 0))
|
||||
strcat(cmd_mkconfig," --hidden ");
|
||||
|
||||
if(cv->channel!=NULL && (strcmp(cv->channel,"default") != 0) && (cv->freq==NULL||(strcmp(cv->freq,"2.4") == 0)|| (strcmp(cv->freq,"5") == 0))){
|
||||
|
||||
strcat(cmd_mkconfig," -c ");
|
||||
strcat(cmd_mkconfig,cv->channel);
|
||||
}
|
||||
|
||||
if(cv->mac!=NULL) {
|
||||
strcat(cmd_mkconfig, " --mac ");
|
||||
strcat(cmd_mkconfig, cv->mac);
|
||||
}
|
||||
|
||||
printf("%s \n",cmd_mkconfig);
|
||||
return cmd_mkconfig;
|
||||
|
||||
|
@ -6,10 +6,11 @@
|
||||
#define WIHOTSPOT_H_PROP_H
|
||||
|
||||
|
||||
#include "read_config.h"
|
||||
|
||||
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 *);
|
||||
@ -23,6 +24,8 @@ static int init_get_interface_list();
|
||||
char** get_interface_list(int*);
|
||||
const char* build_kill_create_ap_command(char* pid);
|
||||
|
||||
const char *build_wh_mkconfig_command(ConfigValues* cv);
|
||||
|
||||
char** get_wifi_interface_list(int *length);
|
||||
|
||||
#endif //WIHOTSPOT_H_PROP_H
|
||||
|
@ -71,6 +71,25 @@ static void setConfigValues(const char * key, char *value){
|
||||
|
||||
if( !strcmp ( INTERNET_IFACE, key ))
|
||||
configValues.iface_inet = value;
|
||||
|
||||
if( !strcmp ( HIDDEN, key ))
|
||||
configValues.hidden = value;
|
||||
|
||||
if( !strcmp ( NO_VIRT, key ))
|
||||
configValues.no_virt = value;
|
||||
|
||||
if( !strcmp ( NEW_MACADDR, key ))
|
||||
configValues.mac = value;
|
||||
|
||||
if( !strcmp ( CHANNEL, key ))
|
||||
configValues.channel = value;
|
||||
|
||||
if( !strcmp ( FREQ_BAND, key ))
|
||||
configValues.freq = value;
|
||||
|
||||
if( !strcmp ( USE_PSK, key ))
|
||||
configValues.use_psk = value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
#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
|
||||
@ -54,8 +53,15 @@ typedef struct{
|
||||
char *pass;
|
||||
char *iface_wifi;
|
||||
char *iface_inet;
|
||||
char *no_virt;
|
||||
char *use_psk;
|
||||
char *channel;
|
||||
char *freq;
|
||||
char *hidden;
|
||||
char *mac;
|
||||
} ConfigValues;
|
||||
|
||||
|
||||
int read_config_file();
|
||||
static void setConfigValues(const char * key, char *value);
|
||||
ConfigValues* getConfigValues(void);
|
||||
|
439
src/ui/ui.c
439
src/ui/ui.c
@ -7,6 +7,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "h_prop.h"
|
||||
#include "ui.h"
|
||||
@ -16,6 +17,14 @@
|
||||
#define BUFSIZE 512
|
||||
#define AP_ENABLED "AP-ENABLED"
|
||||
|
||||
#define INSTALL_PATH_PREFIX "/usr/share/wihotspot"
|
||||
#define ERROR_SSID_MSG "SSID must not empty"
|
||||
#define ERROR_PASS_MSG "Password must contain 8 characters"
|
||||
#define ERROR_CHANNEL_MSG "Invalid channel number"
|
||||
#define ERROR_CHANNEL_MSG_2 "Channel must be 1-11"
|
||||
#define ERROR_CHANNEL_MSG_5 "Channel must be 1-36"
|
||||
#define ERROR_MAC_MSG "Invalid Mac address"
|
||||
|
||||
GtkBuilder *builder;
|
||||
GObject *window;
|
||||
GtkButton *button_create_hp;
|
||||
@ -37,13 +46,26 @@ GtkCheckButton *cb_hidden;
|
||||
GtkCheckButton *cb_psk;
|
||||
GtkCheckButton *cb_mac;
|
||||
GtkCheckButton *cb_novirt;
|
||||
GtkCheckButton *cb_channel;
|
||||
GtkCheckButton *cb_open;
|
||||
|
||||
GtkProgressBar *progress_bar;
|
||||
|
||||
GtkLabel *label_status;
|
||||
GtkLabel *label_input_error;
|
||||
|
||||
GtkCssProvider* provider;
|
||||
GdkDisplay *display;
|
||||
GdkScreen *screen;
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
GtkStyleContext *context_entry_mac;
|
||||
GtkStyleContext *context_entry_pass;
|
||||
GtkStyleContext *context_entry_ssid;
|
||||
GtkStyleContext *context_entry_channel;
|
||||
GtkStyleContext *context_label_input_error;
|
||||
|
||||
|
||||
const char** iface_list;
|
||||
const char** wifi_iface_list;
|
||||
@ -51,6 +73,7 @@ int iface_list_length;
|
||||
int wifi_iface_list_length;
|
||||
char* running_info[3];
|
||||
guint id;
|
||||
static ConfigValues cv;
|
||||
|
||||
|
||||
|
||||
@ -67,31 +90,21 @@ static void *stopHp() {
|
||||
|
||||
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) {
|
||||
init_config_val_input(&cv);
|
||||
|
||||
|
||||
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", run_create_hp_shell, (void*)build_wh_from_config());
|
||||
|
||||
g_free (wifi);
|
||||
g_free (internet);
|
||||
} else{
|
||||
|
||||
g_print("Please select Wifi and Internet interfaces\n");
|
||||
if(validator(&cv)==FALSE){
|
||||
set_error_text("Check inputs");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
startShell(build_wh_mkconfig_command(&cv));
|
||||
|
||||
g_thread_new("shell_create_hp", run_create_hp_shell, (void*)build_wh_from_config());
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void on_stop_hp_clicked(GtkWidget *widget, gpointer data) {
|
||||
@ -99,6 +112,191 @@ static void on_stop_hp_clicked(GtkWidget *widget, gpointer data) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void loadStyles(){
|
||||
provider = gtk_css_provider_new();
|
||||
display = gdk_display_get_default();
|
||||
screen = gdk_display_get_default_screen (display);
|
||||
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
const char *style_file;
|
||||
|
||||
const char* debug_style_file="glade/style.css";
|
||||
const char* prod_style_file="/usr/share/wihotspot/glade/style.css";
|
||||
|
||||
FILE *file;
|
||||
|
||||
if ((file = fopen(debug_style_file, "r"))){
|
||||
fclose(file);
|
||||
style_file = debug_style_file;
|
||||
gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),"glade/style.css",NULL);
|
||||
|
||||
}
|
||||
else if ((file = fopen(prod_style_file, "r"))){
|
||||
fclose(file);
|
||||
style_file = prod_style_file;
|
||||
|
||||
} else{
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),style_file,NULL);
|
||||
}
|
||||
|
||||
static void init_style_contexts(){
|
||||
context_entry_mac = gtk_widget_get_style_context((GtkWidget*)entry_mac);
|
||||
context_entry_ssid = gtk_widget_get_style_context((GtkWidget*)entry_ssd);
|
||||
context_entry_pass = gtk_widget_get_style_context((GtkWidget*)entry_pass);
|
||||
context_entry_channel = gtk_widget_get_style_context((GtkWidget*)entry_channel);
|
||||
context_label_input_error = gtk_widget_get_style_context((GtkWidget*)label_input_error);
|
||||
|
||||
}
|
||||
|
||||
static void set_error_text(char * text){
|
||||
gtk_label_set_label(label_input_error,text);
|
||||
}
|
||||
|
||||
static void* entry_mac_warn(GtkWidget *widget, gpointer data){
|
||||
|
||||
const char *mac = gtk_entry_get_text(GTK_ENTRY(widget));
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_mac))==TRUE) {
|
||||
|
||||
if (mac == NULL || isValidMacAddress(mac) != 1) {
|
||||
set_error_text(ERROR_MAC_MSG);
|
||||
gtk_style_context_add_class(context_entry_mac, "entry-error");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_style_context_remove_class(context_entry_mac,"entry-error");
|
||||
set_error_text("");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void* entry_ssid_warn(GtkWidget *widget, gpointer data){
|
||||
|
||||
const char *ssid = gtk_entry_get_text(GTK_ENTRY(widget));
|
||||
|
||||
if(ssid !=NULL)
|
||||
{
|
||||
size_t len = strlen(ssid);
|
||||
|
||||
if(len<1){
|
||||
gtk_style_context_add_class(context_entry_ssid, "entry-error");
|
||||
set_error_text(ERROR_SSID_MSG);
|
||||
return NULL;
|
||||
} else{
|
||||
gtk_style_context_remove_class(context_entry_ssid, "entry-error");
|
||||
set_error_text("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(ssid ==NULL)
|
||||
{
|
||||
gtk_style_context_add_class(context_entry_ssid, "entry-error");
|
||||
set_error_text(ERROR_SSID_MSG);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gtk_style_context_remove_class(context_entry_ssid,"entry-error");
|
||||
set_error_text("");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void* entry_pass_warn(GtkWidget *widget, gpointer data){
|
||||
|
||||
const char *pass = gtk_entry_get_text(GTK_ENTRY(widget));
|
||||
|
||||
if(pass !=NULL)
|
||||
{
|
||||
size_t len = strlen(pass);
|
||||
|
||||
if(len<8 && len>0){
|
||||
gtk_style_context_add_class(context_entry_pass, "entry-error");
|
||||
set_error_text(ERROR_PASS_MSG);
|
||||
return NULL;
|
||||
} else{
|
||||
gtk_style_context_remove_class(context_entry_pass, "entry-error");
|
||||
}
|
||||
}
|
||||
|
||||
gtk_style_context_remove_class(context_entry_mac,"entry-error");
|
||||
set_error_text("");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void* entry_channel_warn(GtkWidget *widget, gpointer data){
|
||||
|
||||
const char *channel = gtk_entry_get_text(GTK_ENTRY(widget));
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_channel))==TRUE) {
|
||||
|
||||
if (channel == NULL) {
|
||||
gtk_style_context_add_class(context_entry_channel, "entry-error");
|
||||
set_error_text(ERROR_CHANNEL_MSG);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
char *end;
|
||||
long li;
|
||||
char *c = strdup(channel);
|
||||
li = strtol(c, &end, 10);
|
||||
|
||||
if (end == c) {
|
||||
gtk_style_context_add_class(context_entry_channel, "entry-error");
|
||||
set_error_text(ERROR_CHANNEL_MSG);
|
||||
return FALSE;
|
||||
} else if ('\0' != *end) {
|
||||
gtk_style_context_add_class(context_entry_channel, "entry-error");
|
||||
set_error_text(ERROR_CHANNEL_MSG);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (cv.freq == NULL) {
|
||||
if (!(li <= 36 && li > 0)) {
|
||||
gtk_style_context_add_class(context_entry_channel, "entry-error");
|
||||
set_error_text(ERROR_CHANNEL_MSG);
|
||||
return FALSE;
|
||||
}
|
||||
} else if (strcmp(cv.freq, "2.4") == 0) {
|
||||
if (!(li <= 11 && li > 0)) {
|
||||
gtk_style_context_add_class(context_entry_channel, "entry-error");
|
||||
set_error_text(ERROR_CHANNEL_MSG_2);
|
||||
return FALSE;
|
||||
}
|
||||
} else if (strcmp(cv.freq, "5") == 0) {
|
||||
if (!(li <= 36 && li > 0)) {
|
||||
gtk_style_context_add_class(context_entry_channel, "entry-error");
|
||||
set_error_text(ERROR_CHANNEL_MSG_5);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
gtk_style_context_remove_class(context_entry_channel,"entry-error");
|
||||
set_error_text("");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void *update_freq_toggle(){
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_freq_2)))
|
||||
cv.freq = "2.4";
|
||||
|
||||
else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_freq_5)))
|
||||
cv.freq ="5";
|
||||
else
|
||||
cv.freq =NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int initUi(int argc, char *argv[]){
|
||||
|
||||
XInitThreads();
|
||||
@ -106,6 +304,23 @@ int initUi(int argc, char *argv[]){
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
|
||||
//
|
||||
// DIR* dir = opendir("mydir");
|
||||
// if (dir)
|
||||
// {
|
||||
// /* Directory exists. */
|
||||
// closedir(dir);
|
||||
// }
|
||||
// else if (ENOENT == errno)
|
||||
// {
|
||||
// /* Directory does not exist. */
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// /* opendir() failed for some other reason. */
|
||||
// }
|
||||
|
||||
const char* debug_glade_file="glade/wifih.ui";
|
||||
const char* prod_glade_file="/usr/share/wihotspot/glade/wifih.ui";
|
||||
|
||||
@ -153,29 +368,45 @@ int initUi(int argc, char *argv[]){
|
||||
cb_psk = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_psk");
|
||||
cb_mac = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_mac");
|
||||
cb_novirt = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_novirt");
|
||||
cb_channel = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_channel");
|
||||
cb_open = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_open");
|
||||
|
||||
rb_freq_auto = (GtkRadioButton *) gtk_builder_get_object(builder, "rb_freq_auto");
|
||||
rb_freq_2 = (GtkRadioButton *) gtk_builder_get_object(builder, "rb_freq_2");
|
||||
rb_freq_5 = (GtkRadioButton *) gtk_builder_get_object(builder, "rb_freq_5");
|
||||
|
||||
label_status = (GtkLabel *) gtk_builder_get_object(builder, "label_status");
|
||||
label_input_error = (GtkLabel *) gtk_builder_get_object(builder, "label_input_error");
|
||||
|
||||
progress_bar = (GtkProgressBar *) gtk_builder_get_object(builder, "progress_bar");
|
||||
|
||||
loadStyles();
|
||||
init_style_contexts();
|
||||
|
||||
gtk_style_context_add_class(context_label_input_error, "label-error");
|
||||
|
||||
|
||||
//gtk_entry_set_visibility(entry_pass,FALSE);
|
||||
|
||||
WIData wiData = {
|
||||
.pass= entry_pass,
|
||||
.ssid= entry_ssd
|
||||
};
|
||||
g_signal_connect (button_create_hp, "clicked", G_CALLBACK(on_create_hp_clicked), NULL);
|
||||
g_signal_connect (button_stop_hp, "clicked", G_CALLBACK(on_stop_hp_clicked), NULL);
|
||||
|
||||
g_signal_connect (entry_mac, "changed", G_CALLBACK(entry_mac_warn), NULL);
|
||||
g_signal_connect (entry_ssd, "changed", G_CALLBACK(entry_ssid_warn), NULL);
|
||||
g_signal_connect (entry_pass, "changed", G_CALLBACK(entry_pass_warn), NULL);
|
||||
|
||||
g_signal_connect (entry_channel, "changed", G_CALLBACK(entry_channel_warn), NULL);
|
||||
|
||||
g_signal_connect (rb_freq_2, "toggled", G_CALLBACK(update_freq_toggle), NULL);
|
||||
g_signal_connect (rb_freq_5, "toggled", G_CALLBACK(update_freq_toggle), NULL);
|
||||
g_signal_connect (rb_freq_auto, "toggled", G_CALLBACK(update_freq_toggle), NULL);
|
||||
|
||||
|
||||
start_pb_pulse();
|
||||
g_thread_new("init_running",init_running_info,NULL);
|
||||
//init_running_info();
|
||||
|
||||
init_interface_list();
|
||||
|
||||
init_ui_from_config(&wiData);
|
||||
|
||||
g_signal_connect (button_create_hp, "clicked", G_CALLBACK(on_create_hp_clicked), &wiData);
|
||||
g_signal_connect (button_stop_hp, "clicked", G_CALLBACK(on_stop_hp_clicked), NULL);
|
||||
init_ui_from_config();
|
||||
|
||||
|
||||
gtk_main();
|
||||
@ -184,7 +415,7 @@ int initUi(int argc, char *argv[]){
|
||||
}
|
||||
|
||||
|
||||
void init_ui_from_config(WIData* data){
|
||||
void init_ui_from_config(){
|
||||
|
||||
if(read_config_file()==READ_CONFIG_FILE_SUCCESS){
|
||||
|
||||
@ -192,9 +423,9 @@ void init_ui_from_config(WIData* data){
|
||||
|
||||
|
||||
if(values->ssid!=NULL)
|
||||
gtk_entry_set_text(data->ssid,values->ssid);
|
||||
gtk_entry_set_text(entry_ssd,values->ssid);
|
||||
if(values->pass!=NULL)
|
||||
gtk_entry_set_text(data->pass,values->pass);
|
||||
gtk_entry_set_text(entry_pass,values->pass);
|
||||
|
||||
if(values->iface_wifi!=NULL){
|
||||
int idw=find_str(values->iface_wifi,wifi_iface_list,wifi_iface_list_length);
|
||||
@ -361,3 +592,147 @@ static void *run_create_hp_shell(void *cmd) {
|
||||
init_running_info();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static gboolean validator(ConfigValues *cv){
|
||||
|
||||
|
||||
if(cv->pass !=NULL)
|
||||
{
|
||||
size_t len = strlen(cv->pass);
|
||||
|
||||
if(len<8){
|
||||
if(len>0)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if(cv->ssid !=NULL)
|
||||
{
|
||||
size_t len = strlen(cv->ssid);
|
||||
|
||||
if(len<1){
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if(cv->ssid ==NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_mac))==TRUE){
|
||||
|
||||
if(cv->mac==NULL)
|
||||
return FALSE;
|
||||
|
||||
if(isValidMacAddress(cv->mac)==1){
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_channel))==TRUE){
|
||||
|
||||
if(cv->channel==NULL)
|
||||
return FALSE;
|
||||
|
||||
char *end;
|
||||
long li;
|
||||
char *c=strdup(cv->channel);
|
||||
li = strtol(c,&end,10);
|
||||
|
||||
if (end == c) {
|
||||
fprintf(stderr, "%s: not a decimal number\n", c);
|
||||
return FALSE;
|
||||
} else if ('\0' != *end) {
|
||||
fprintf(stderr, "%s: extra characters at end of input: %s\n", c, end);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if(cv->freq==NULL){
|
||||
if(!(li<=36 && li>0))
|
||||
return FALSE;
|
||||
}
|
||||
else if(strcmp(cv->freq,"2.4")==0){
|
||||
if(!(li<=11 && li>0))
|
||||
return FALSE;
|
||||
} else if(strcmp(cv->freq,"5")==0){
|
||||
if(!(li<=36 && li>0))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int init_config_val_input(ConfigValues* cv){
|
||||
|
||||
|
||||
if (gtk_combo_box_get_active (combo_wifi) >= 0 && gtk_combo_box_get_active (combo_internet) >= 0) {
|
||||
|
||||
|
||||
gchar *wifi =cv->iface_wifi= gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(combo_wifi));
|
||||
gchar *internet =cv->iface_inet= 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;
|
||||
|
||||
|
||||
cv->ssid = (char *) gtk_entry_get_text(entry_ssd);
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_open))){
|
||||
cv->pass = "";
|
||||
}
|
||||
else{
|
||||
cv->pass = (char *) gtk_entry_get_text(entry_pass);
|
||||
}
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_freq_2)))
|
||||
cv->freq = "2.4";
|
||||
|
||||
else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_freq_5)))
|
||||
cv->freq ="5";
|
||||
else
|
||||
cv->freq =NULL;
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_channel)))
|
||||
cv->channel = (char*)gtk_entry_get_text(entry_channel);
|
||||
else
|
||||
cv->channel = NULL;
|
||||
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_mac)))
|
||||
cv->mac = (char*)gtk_entry_get_text(entry_mac);
|
||||
else
|
||||
cv->mac =NULL;
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_hidden)))
|
||||
cv->hidden = "1";
|
||||
|
||||
else
|
||||
cv->hidden =NULL;
|
||||
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_novirt)))
|
||||
cv->no_virt = "1";
|
||||
else
|
||||
cv->no_virt=NULL;
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_psk)))
|
||||
cv->use_psk = "1";
|
||||
else
|
||||
cv->use_psk =NULL;
|
||||
|
||||
return 0;
|
||||
|
||||
} else{
|
||||
|
||||
g_print("Please select Wifi and Internet interfaces\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
10
src/ui/ui.h
10
src/ui/ui.h
@ -7,6 +7,8 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "read_config.h"
|
||||
|
||||
typedef struct {
|
||||
GtkEntry *ssid;
|
||||
GtkEntry *pass;
|
||||
@ -14,7 +16,7 @@ typedef struct {
|
||||
|
||||
int initUi(int argc, char *argv[]);
|
||||
|
||||
void init_ui_from_config(WIData* data);
|
||||
void init_ui_from_config();
|
||||
|
||||
static void* run_create_hp_shell(void *cmd);
|
||||
|
||||
@ -34,4 +36,10 @@ static void on_create_hp_clicked(GtkWidget *widget,gpointer data);
|
||||
|
||||
static void *stopHp();
|
||||
|
||||
static int init_config_val_input(ConfigValues* cv);
|
||||
|
||||
static gboolean validator(ConfigValues *cv);
|
||||
|
||||
static void set_error_text(char * text);
|
||||
|
||||
#endif //WIHOTSPOT_UI_H
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include "util.h"
|
||||
|
||||
int find_str(char *find, const char **array, int length) {
|
||||
@ -33,3 +34,30 @@ void rand_str(char *dest, size_t length) {
|
||||
}
|
||||
*dest = '\0';
|
||||
}
|
||||
|
||||
|
||||
int isValidMacAddress(const char* mac) {
|
||||
int i = 0;
|
||||
int s = 0;
|
||||
|
||||
while (*mac) {
|
||||
if (isxdigit(*mac)) {
|
||||
i++;
|
||||
}
|
||||
else if (*mac == ':' || *mac == '-') {
|
||||
|
||||
if (i == 0 || i / 2 - 1 != s)
|
||||
break;
|
||||
|
||||
++s;
|
||||
}
|
||||
else {
|
||||
s = -1;
|
||||
}
|
||||
|
||||
|
||||
++mac;
|
||||
}
|
||||
|
||||
return (i == 12 && (s == 5 || s == 0));
|
||||
}
|
@ -7,5 +7,6 @@
|
||||
|
||||
int find_str(char *find, const char **array, int length);
|
||||
void rand_str(char *dest, size_t length);
|
||||
int isValidMacAddress(const char*);
|
||||
|
||||
#endif //WIHOTSPOT_UTIL_H
|
||||
|
Loading…
Reference in New Issue
Block a user