Merge branch 'Nexround-v4.1.0'

This commit is contained in:
Lakindu Akash 2021-09-12 15:36:32 +05:30
commit 4de749d5fe
No known key found for this signature in database
GPG Key ID: 6FB0085A614E0AC2
7 changed files with 272 additions and 7 deletions

View File

@ -21,8 +21,9 @@
* Support both 2.4GHz and 5GHz (Need to be compatible with your wifi adapter). Ex: You have connected to the 5GHz network and share a connection with 2.4GHz.
* Select Channel.
* Hide SSID
* Show the connected devices
![screenshot](docs/sc2.png)
![screenshot](docs/sc3.png)
### Command line help and documentation

BIN
docs/sc3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="window">
@ -503,16 +503,133 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkExpander">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="can_focus">True</property>
<child>
<placeholder/>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<property name="min_content_height">100</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Number</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Hostname</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">IP</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">MAC</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid_devices">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_homogeneous">True</property>
<property name="column_homogeneous">True</property>
<property name="baseline_row">1</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_refresh">
<property name="label" translatable="yes">Refresh</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="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Connected devices</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>

View File

@ -420,3 +420,56 @@ char** get_wifi_interface_list(int *length){
return NULL;
}
Node get_connected_devices(char *PID)
{
char cmd[BUFSIZE];
snprintf(cmd, BUFSIZE, "%s --list-clients %s", CREATE_AP, PID);
FILE *fp;
Node l = (struct Device *)malloc(sizeof(struct Device));
Position head = l;
fp = popen(cmd, "r");
char line[BUFSIZE];
int _n = 0; //Device number
while (fgets(line, BUFSIZE, fp) != NULL)
{
if (strstr(line, "MAC") != NULL)
continue;
_n++;
int size = strlen(line);
int marker[3] = {0};
int n = 0; // For marker
line[size - 1] = '\0'; // Remove "\n"
for (int i = 0; i < size; i++)
{
if (*(line + i) != ' ' && *(line + i + 1) == ' ')
{
// End
*(line + i + 1) = '\0';
i++;
}
if (*(line + i) == ' ' && *(line + i + 1) != ' ')
{
// Head
*(line + i) = '\0';
marker[++n] = i + 1;
}
}
l = add_device_node(l, _n, line, marker);
}
return head;
}
PtrToNode add_device_node(PtrToNode l, int number, char line[BUFSIZE], int marker[3])
{
Node next = (PtrToNode)malloc(sizeof(struct Device));
strcpy(next->MAC, line);
strcpy(next->IP, line + marker[1]);
strcpy(next->HOSTNAME, line + marker[2]);
next->Number = number;
next->Next = NULL;
l->Next = next;
return next;
}

View File

@ -35,6 +35,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "read_config.h"
typedef struct Device *PtrToNode;
struct Device
{
char HOSTNAME[2048];
char IP[2048];
char MAC[2048];
unsigned int Number;
PtrToNode Next;
}; // Head node is null
typedef PtrToNode Position;
typedef PtrToNode Node;
static int parse_output(const char *);
const char *build_wh_start_command(char *, char *, char *, char *);
@ -59,4 +71,7 @@ void write_accepted_macs(char* filename, char* accepted_macs);
char * read_mac_filter_file(char * filename);
Node get_connected_devices(char *PID);
PtrToNode add_device_node(Node l, int number, char *line, int marker[3]);
#endif //WIHOTSPOT_H_PROP_H

View File

@ -57,6 +57,14 @@ GObject *window;
GtkButton *button_create_hp;
GtkButton *button_stop_hp;
GtkButton *button_about;
GtkButton *button_refresh;
GtkGrid *grid_devices;
GtkWidget *label_cd_hostname;
GtkWidget *label_cd_ip;
GtkWidget *label_cd_mac;
GtkWidget *label_cd_number;
PtrToNode device_list;
GtkEntry *entry_ssd;
GtkEntry *entry_pass;
@ -360,6 +368,9 @@ int initUi(int argc, char *argv[]){
button_create_hp = (GtkButton *) gtk_builder_get_object(builder, "button_create_hp");
button_stop_hp = (GtkButton *) gtk_builder_get_object(builder, "button_stop_hp");
button_about = (GtkButton *) gtk_builder_get_object(builder, "button_about");
button_refresh = (GtkButton *)gtk_builder_get_object(builder, "button_refresh");
grid_devices = (GtkGrid *)gtk_builder_get_object(builder, "grid_devices");
entry_ssd = (GtkEntry *) gtk_builder_get_object(builder, "entry_ssid");
entry_pass = (GtkEntry *) gtk_builder_get_object(builder, "entry_pass");
@ -403,6 +414,7 @@ int initUi(int argc, char *argv[]){
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 (button_about, "clicked", G_CALLBACK(on_about_open_click), NULL);
g_signal_connect (button_refresh, "clicked", G_CALLBACK(on_refresh_clicked), NULL); //new
g_signal_connect (entry_mac, "changed", G_CALLBACK(entry_mac_warn), NULL);
g_signal_connect (entry_ssd, "changed", G_CALLBACK(entry_ssid_warn), NULL);
@ -865,4 +877,65 @@ gchar* get_accepted_macs(){
return accepted_macs;
}
/**
* Clear device list
*/
static void clear_connecetd_devices_list(){
// Remove all the children widgets
GList *children, *iter;
children = gtk_container_get_children(GTK_CONTAINER(grid_devices));
for (iter = children; iter != NULL; iter = g_list_next(iter))
{
gtk_widget_destroy(GTK_WIDGET(iter->data));
}
g_list_free(children);
}
/**
* Set connected device list
*
*/
static void set_connected_devices_label()
{
Position tmp;
device_list = get_connected_devices(running_info[0]); // running_info[0] PID
clear_connecetd_devices_list();
while (device_list->Next != NULL)
{
tmp = device_list; // Save the last one
device_list = device_list->Next;
char number[2];
sprintf(number, "%d", device_list->Number);
label_cd_number = gtk_label_new(number);
label_cd_hostname = gtk_label_new(device_list->HOSTNAME);
label_cd_ip = gtk_label_new(device_list->IP);
label_cd_mac = gtk_label_new(device_list->MAC);
gtk_grid_attach(grid_devices, label_cd_number, 0, device_list->Number, 1, 1);
gtk_grid_attach(grid_devices, label_cd_hostname, 1, device_list->Number, 1, 1);
gtk_grid_attach(grid_devices, label_cd_ip, 2, device_list->Number, 1, 1);
gtk_grid_attach(grid_devices, label_cd_mac, 3, device_list->Number, 1, 1);
gtk_widget_show_all((GtkWidget *)grid_devices);
free(tmp); // Free the last pointer
}
}
/**
* When conncetd devices refresh button clicked
*/
static void on_refresh_clicked(GtkWidget *widget, gpointer data)
{
if (running_info[0] != NULL)
{
set_connected_devices_label();
}
else {
clear_connecetd_devices_list();
}
}

View File

@ -70,4 +70,10 @@ static void set_error_text(char * text);
gchar* get_accepted_macs();
static void set_connected_devices_label(); // new
static void on_refresh_clicked(GtkWidget *widget, gpointer data);
static void clear_connecetd_devices_list();
#endif //WIHOTSPOT_UI_H