Skip to content

Commit

Permalink
improve tools, move wifi setup to wifi.pak
Browse files Browse the repository at this point in the history
  • Loading branch information
anzz1 committed May 12, 2023
1 parent 14f951b commit 8cef236
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 139 deletions.
11 changes: 5 additions & 6 deletions extras/Tools/FTP.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ cd "$DIR"

mkdir -p "$USERDATA_PATH/.wifi"

show confirm.png
show toggle.png
if [ -f "$USERDATA_PATH/.wifi/ftp_on.txt" ]; then
say "FTP: Enabled"
else
say "FTP: Disabled"
fi

while confirm; do
show confirm.png
show toggle.png
if [ -f "$USERDATA_PATH/.wifi/ftp_on.txt" ]; then
rm -f "$USERDATA_PATH/.wifi/ftp_on.txt"
say "FTP: ..."
LD_PRELOAD= killall ftpd > /dev/null 2>&1
LD_PRELOAD= killall tcpsvd > /dev/null 2>&1
show confirm.png
say "FTP: Disabled"
else
touch "$USERDATA_PATH/.wifi/ftp_on.txt"
LD_PRELOAD= tcpsvd -E 0.0.0.0 21 ftpd -w /mnt/SDCARD > /dev/null 2>&1 &
if [ -f "$USERDATA_PATH/.wifi/wifi_on.txt" ]; then
LD_PRELOAD= tcpsvd -E 0.0.0.0 21 ftpd -w /mnt/SDCARD > /dev/null 2>&1 &
fi
say "FTP: Enabled"
fi
sleep 1
done
11 changes: 5 additions & 6 deletions extras/Tools/Telnet.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@ cd "$DIR"

mkdir -p "$USERDATA_PATH/.wifi"

show confirm.png
show toggle.png
if [ -f "$USERDATA_PATH/.wifi/telnet_on.txt" ]; then
say "Telnet: Enabled"
else
say "Telnet: Disabled"
fi

while confirm; do
show confirm.png
show toggle.png
if [ -f "$USERDATA_PATH/.wifi/telnet_on.txt" ]; then
rm -f "$USERDATA_PATH/.wifi/telnet_on.txt"
say "Telnet: ..."
LD_PRELOAD= killall telnetd > /dev/null 2>&1
show confirm.png
say "Telnet: Disabled"
else
touch "$USERDATA_PATH/.wifi/telnet_on.txt"
(cd / && LD_PRELOAD= telnetd -l sh)
if [ -f "$USERDATA_PATH/.wifi/wifi_on.txt" ]; then
(cd / && LD_PRELOAD= telnetd -l sh)
fi
say "Telnet: Enabled"
fi
sleep 1
done
62 changes: 0 additions & 62 deletions extras/Tools/WiFi Setup.pak/launch.sh

This file was deleted.

73 changes: 49 additions & 24 deletions extras/Tools/WiFi.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,58 @@ cd "$DIR"

mkdir -p "$USERDATA_PATH/.wifi"

show confirm.png
if [ -f "$USERDATA_PATH/.wifi/wifi_on.txt" ]; then
WIFI_ON=1
say "WiFi: Enabled"
else
WIFI_ON=0
say "WiFi: Disabled"
if [ ! -f /mnt/SDCARD/.system/paks/WiFi.pak/8188fu.ko ]; then
show okay.png
say "WiFi driver is missing!"$'\n'"Please reinstall DotUI."
confirm any
exit 0
fi

while confirm; do
show confirm.png
if [ $WIFI_ON == 1 ]; then
WIFI_ON=0
say "WiFi: Disabled"
else
WIFI_ON=1
say "WiFi: Enabled"
fi
sleep 1
done

WIFI_ON=0
if [ -f "$USERDATA_PATH/.wifi/wifi_on.txt" ]; then
if [ $WIFI_ON == 0 ]; then
if [ -f /appconfigs/wpa_supplicant.conf ]; then
WIFI_ON=1
else
LD_PRELOAD= ./wifioff.sh > /dev/null 2>&1 &
fi
else
if [ $WIFI_ON == 1 ] && [ -f /mnt/SDCARD/.system/paks/WiFi.pak/8188fu.ko ] && [ -f /appconfigs/wpa_supplicant.conf ]; then
LD_PRELOAD= ./wifion.sh > /dev/null 2>&1 &
fi
fi

while :; do
if [ ! -f /appconfigs/wpa_supplicant.conf ]; then
show ./wifi2.png
say "WiFi: Not configured"$'\n'$'\n'"Please configure your WiFi network"$'\n'"by pressing SELECT."
else
show ./wifi.png
if [ $WIFI_ON == 1 ]; then
say "WiFi: Enabled"
else
say "WiFi: Disabled"
fi
fi
while :; do
confirm any
KEY=$?
if [ $KEY -eq 57 ]; then # 57 = A
if [ -f /appconfigs/wpa_supplicant.conf ]; then
WIFI_ON=$(( ! WIFI_ON ))
break
fi
elif [ $KEY -eq 97 ]; then # 97 = SELECT
./wifisetup.sh
break
elif [ $KEY -eq 29 ]; then # 29 = B
if [ -f /appconfigs/wpa_supplicant.conf ]; then
if [ -f "$USERDATA_PATH/.wifi/wifi_on.txt" ]; then
if [ $WIFI_ON == 0 ]; then
LD_PRELOAD= ./wifioff.sh > /dev/null 2>&1 &
fi
else
if [ $WIFI_ON == 1 ]; then
LD_PRELOAD= ./wifion.sh > /dev/null 2>&1 &
fi
fi
fi
exit 0
fi
done
done
Binary file added extras/Tools/WiFi.pak/wifi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extras/Tools/WiFi.pak/wifi2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions extras/Tools/WiFi.pak/wifireload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

killall telnetd > /dev/null 2>&1 &
killall ftpd > /dev/null 2>&1 &
killall tcpsvd > /dev/null 2>&1 &
killall wpa_supplicant > /dev/null 2>&1
killall udhcpc > /dev/null 2>&1
ifconfig wlan0 down

ifconfig lo up
ifconfig wlan0 up
/customer/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf
udhcpc -i wlan0 -s /etc/init.d/udhcpc.script > /dev/null 2>&1 &

# Telnet
if [ -f "$USERDATA_PATH/.wifi/telnet_on.txt" ] && [ -f "$TOOLS_PATH/Telnet.pak/launch.sh" ]; then
(cd / && telnetd -l sh)
fi

# FTP
if [ -f "$USERDATA_PATH/.wifi/ftp_on.txt" ] && [ -f "$TOOLS_PATH/FTP.pak/launch.sh" ]; then
tcpsvd -E 0.0.0.0 21 ftpd -w /mnt/SDCARD > /dev/null 2>&1 &
fi
54 changes: 54 additions & 0 deletions extras/Tools/WiFi.pak/wifisetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

DIR=$(dirname "$0")
cd "$DIR"

mkdir -p "$USERDATA_PATH/.wifi"

WIFI_SSID="$(keyboard "Enter WiFi network name:" 32)"

if [ $? -eq 0 ] && [ ! -z "$WIFI_SSID" ]; then
show confirm.png
say "WiFi network name set:"$'\n'"${WIFI_SSID:0:16}"$'\n'"${WIFI_SSID:17}"
if confirm; then
WIFI_PASS="$(keyboard "Enter WiFi network pass:" 63)"
if [ $? -eq 0 ]; then
show confirm.png
if [ ! -z "$WIFI_PASS" ]; then
say "WiFi network password set:"$'\n'"${WIFI_PASS:0:16}"$'\n'"${WIFI_PASS:17:16}"$'\n'"${WIFI_PASS:33:16}"$'\n'"${WIFI_PASS:48}"
else
say "WiFi network password set to empty"
fi
if confirm; then
echo "ctrl_interface=/var/run/wpa_supplicant" > /appconfigs/wpa_supplicant.conf
echo "update_config=1" >> /appconfigs/wpa_supplicant.conf
echo $'\n'"network={" >> /appconfigs/wpa_supplicant.conf
echo $'\tssid="'"$WIFI_SSID"$'"' >> /appconfigs/wpa_supplicant.conf
if [ ! -z "$WIFI_PASS" ]; then
echo $'\tpsk="'"$WIFI_PASS"$'"' >> /appconfigs/wpa_supplicant.conf
else
echo $'\t'"key_mgmt=NONE" >> /appconfigs/wpa_supplicant.conf
fi
echo "}" >> /appconfigs/wpa_supplicant.conf
show okay.png
if [ ! -f /appconfigs/wpa_supplicant.conf ]; then
if [ -f "$USERDATA_PATH/.wifi/wifi_on.txt" ]; then
LD_PRELOAD= ./wifioff.sh > /dev/null 2>&1 &
fi
say "Error:"$'\n'"Could not save WiFi network settings!"
else
if [ -f "$USERDATA_PATH/.wifi/wifi_on.txt" ]; then
LD_PRELOAD= ./wifireload.sh > /dev/null 2>&1 &
fi
say "WiFi network settings saved."
fi
confirm only
exit 0
fi
fi
fi
fi

show okay.png
say "WiFi network settings"$'\n'"were not changed."
confirm only
Binary file added skeleton/.system/res/toggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 44 additions & 36 deletions src/confirm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,62 @@
#include <sys/mman.h>
#include <unistd.h>

#define BUTTON_A KEY_SPACE
#define BUTTON_B KEY_LEFTCTRL
#define BUTTON_A KEY_SPACE
#define BUTTON_B KEY_LEFTCTRL

#define E_RELEASE 0
#define E_PRESS 1
#define E_REPEAT 2

int main(int argc , char* argv[]) {
int any = 0;
int only = 0;
if (argc<1) {
puts("Usage: confirm [any|only]");
puts(" default: only A button confirms, only B button cancels");
puts(" any: any button confirms, none cancel");
puts(" only: only the A button confirms, none cancel");
return 0;
}

// if (argc<1) {
// puts("Usage: confirm [any|only]");
// puts(" default: only A button confirms, only B button cancels");
// puts(" any: any button confirms, none cancel");
// puts(" only: only the A button confirms, none cancel");
// return 0;
// }

if (argc>1) {
char mode[4];
strncpy(mode,argv[1],4);
any = strncmp(mode, "any", 4)==0;
only = strncmp(mode, "only", 4)==0;
any = !strncmp(mode, "any", 3);
only = !strncmp(mode, "only", 4);
}
int confirmed = 0; // true in shell

int ret = 0; // true in shell

int input_fd = open("/dev/input/event0", O_RDONLY);
struct input_event event;
while (read(input_fd, &event, sizeof(event))==sizeof(event)) {
if (event.type!=EV_KEY || event.value>1) continue;
if (event.type==EV_KEY) {
if (any || event.code==BUTTON_A) break;
else if (!only && event.code==BUTTON_B) {
confirmed = 1; // false in shell terms
break;
if (input_fd != -1) {
struct input_event event;
while (read(input_fd, &event, sizeof(event))==sizeof(event)) {
if (event.type==EV_KEY && event.value==E_PRESS) {
if (any) {
ret = event.code;
break;
} else if (event.code==BUTTON_A) {
break;
} else if (!only && event.code==BUTTON_B) {
ret = 1; // false in shell terms
break;
}
}
}
close(input_fd);
}

// clear screen
int fb0_fd = open("/dev/fb0", O_RDWR);
struct fb_var_screeninfo vinfo;
ioctl(fb0_fd, FBIOGET_VSCREENINFO, &vinfo);
int map_size = vinfo.xres * vinfo.yres * (vinfo.bits_per_pixel / 8); // 640x480x4
char* fb0_map = (char*)mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb0_fd, 0);
memset(fb0_map, 0, map_size);
munmap(fb0_map, map_size);
close(fb0_fd);

close(input_fd);

return confirmed;
// int fb0_fd = open("/dev/fb0", O_RDWR);
// struct fb_var_screeninfo vinfo;
// ioctl(fb0_fd, FBIOGET_VSCREENINFO, &vinfo);
// int map_size = vinfo.xres * vinfo.yres * (vinfo.bits_per_pixel / 8); // 640x480x4
// char* fb0_map = (char*)mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb0_fd, 0);
// memset(fb0_map, 0, map_size);
// munmap(fb0_map, map_size);
// close(fb0_fd);

return ret;
}
Loading

0 comments on commit 8cef236

Please sign in to comment.