Skip to content

Commit

Permalink
handle Roy Marples dhcpcd pid file, added '--version' option, added '…
Browse files Browse the repository at this point in the history
…-viewer sixel' option, added manpage, added 'make install'
  • Loading branch information
ColumPaget committed Mar 8, 2024
1 parent a8c70e3 commit 9da429c
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 54 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v3.1 (2024-03-08)
* handle Roy Marples DHCPCD default pid file
* added '--version' option
* added '-viewer sixel' option
* added manpage
* added 'make install'

v3.0 (2024-01-20)
* command-line qrcode export support
* sudo support
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
VERSION=3.0
VERSION=3.1
CC=gcc
LIBS= -lcrypto -lssl -lUseful-5
FLAGS=-g -O2 -DVERSION=\"$(VERSION)\"
prefix=/usr/local
exec_prefix=${prefix}
BINDIR=${exec_prefix}/bin
man_prefix=@man_prefix@
MANDIR=${prefix}/share/man

OBJ=common.o net.o netdev.o runcommand.o iw.o wireless_tools.o wpa_supplicant.o wifi.o interactive.o settings.o qrcode.o command_line.o help.o

Expand Down Expand Up @@ -54,5 +59,12 @@ command_line.o: command_line.h command_line.c common.h
clean:
rm term_wifi *.o libUseful-4/*.o libUseful-4/*.a libUseful-4/*.so *.orig

install:
mkdir -p $(BINDIR)
cp -f term_wifi $(BINDIR)
mkdir -p $(MANDIR)/man1
cp -f term_wifi.1 $(MANDIR)/man1


test:
echo "no tests"
14 changes: 13 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
VERSION=3.0
VERSION=3.1
CC=@CC@
LIBS=@LDFLAGS@ @LIBS@ @LIBUSEFUL_BUNDLED@
FLAGS=@CFLAGS@ -DVERSION=\"$(VERSION)\"
prefix=@prefix@
exec_prefix=@exec_prefix@
BINDIR=@bindir@
man_prefix=@man_prefix@
MANDIR=@mandir@

OBJ=common.o net.o netdev.o runcommand.o iw.o wireless_tools.o wpa_supplicant.o wifi.o interactive.o settings.o qrcode.o command_line.o help.o

Expand Down Expand Up @@ -54,5 +59,12 @@ command_line.o: command_line.h command_line.c common.h
clean:
rm term_wifi *.o libUseful-4/*.o libUseful-4/*.a libUseful-4/*.so *.orig

install:
mkdir -p $(BINDIR)
cp -f term_wifi $(BINDIR)
mkdir -p $(MANDIR)/man1
cp -f term_wifi.1 $(MANDIR)/man1


test:
echo "no tests"
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ To 'forget' (delete) a configured network
term_wifi connect <essid> join configured network with default interface
term_wifi qrcode <essid> display qr code for saved network with essid '<essid>'
term_wifi qrcode <essid> -viewer <list> display qr code for saved network with essid '<essid>' using first viewer program found in comma-separated list '<list>'
term_wifi qrcode <essid> -viewer "sixel" display qr code using terminal's sixel support
term_wifi qrcode <essid> -o <path> write qr code for network '<essid>' to PNG file at <path>
term_wifi -? this help
term_wifi -h this help
Expand All @@ -116,6 +117,7 @@ options that apply to connect/interactive mode
-i <interface> interface to use
-ap <access point mac address> access point to join (if many for same essid)
-k <key> authentication key for given essid/network)
-w <path> path to control sock of existing/running wpa_supplicant
```

you can use `-i <interface>` to specify and interface to use for the 'connect', 'scan' and tui commands.
Expand All @@ -124,6 +126,19 @@ you can use `-i <interface>` to specify and interface to use for the 'connect',
QR CODES
========

the command-line 'qrcode' action will produce a qrcode PNG and attempt to find an image-viewer to display it. You can specify an image-viewer command using the '-viewer' option. Failing that, term_wifi has an internal list of image-viewer programs to try. After all the image viewers, there are two options that output sixel images to the terminal, provided your terminal supports sixel image display. Finally, if nothing matching is found, the ultimate fallback is to use qrencodes 'ANSI256' display message to create a giant QR code with ANSI graphics.
the command-line 'qrcode' action will produce a qrcode PNG and attempt to find an image-viewer to display it. You can specify an image-viewer command using the '-viewer' option. Failing that, term_wifi has an internal list of image-viewer programs to try. Currently this default list is:

```
imlib2_view, fim, feh, display, xv, phototonic, qimageviewer, pix, sxiv, qimgv, qview, nomacs, geeqie, ristretto, mirage, fotowall, links -g, convert, img2sixel -e
```
The '-viewer' option can be used to alter this list, like so:

```
term_wifi -qrcode mynet -viewer "imgview,fim,xv"
```

If no image viewers are found, there are two options at the end of this list that output sixel images to the terminal, provided your terminal supports sixel image display. To force use of sixel images use '-viewer sixel'.

Finally, if nothing matching is found, the ultimate fallback is to use qrencodes 'ANSI256' display message to create a giant QR code with ANSI graphics.


10 changes: 9 additions & 1 deletion command_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int ParseCommandLine(int argc, char *argv[], TNet *Conf)
Conf->ESSID=CopyStr(Conf->ESSID, CommandLineNext(CL));
}
else if (strcmp(ptr, "help")==0) Act=ACT_HELP;
else if (strcmp(ptr, "version")==0) Act=ACT_VERSION;
}


Expand All @@ -88,13 +89,20 @@ int ParseCommandLine(int argc, char *argv[], TNet *Conf)
else if (strcmp(ptr, "-h")==0) Act=ACT_HELP;
else if (strcmp(ptr, "-help")==0) Act=ACT_HELP;
else if (strcmp(ptr, "--help")==0) Act=ACT_HELP;
else if (strcmp(ptr, "-version")==0) Act=ACT_VERSION;
else if (strcmp(ptr, "--version")==0) Act=ACT_VERSION;
else if (strcmp(ptr, "-i")==0) Conf->Interface=CopyStr(Conf->Interface, CommandLineNext(CL));
else if (strcmp(ptr, "-ap")==0) Conf->AccessPoint=CopyStr(Conf->AccessPoint, CommandLineNext(CL));
else if (strcmp(ptr, "-k")==0) Conf->Key=CopyStr(Conf->Key, CommandLineNext(CL));
else if (strcmp(ptr, "-w")==0) Settings.WPASupplicantSock=CopyStr(Settings.WPASupplicantSock, CommandLineNext(CL));
else if (strcmp(ptr, "-o")==0) Settings.OutputPath=CopyStr(Settings.OutputPath, CommandLineNext(CL));
else if (strcmp(ptr, "-viewer")==0) Settings.ImageViewer=CopyStr(Settings.ImageViewer, CommandLineNext(CL));
else if (strcmp(ptr, "-view")==0) Settings.ImageViewer=CopyStr(Settings.ImageViewer, CommandLineNext(CL));
else if (strcmp(ptr, "-view")==0)
{
ptr=CommandLineNext(CL);
if (strcasecmp(ptr, "sixel")==0) Settings.ImageViewer=CopyStr(Settings.ImageViewer, "img2sixel -e,convert");
else Settings.ImageViewer=CopyStr(Settings.ImageViewer, CommandLineNext(CL));
}

ptr=CommandLineNext(CL);
}
Expand Down
3 changes: 2 additions & 1 deletion command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#define ACT_FORGET 6
#define ACT_IFACE_LIST 7
#define ACT_QRCODE 8
#define ACT_HELP 99
#define ACT_VERSION 98
#define ACT_HELP 99



Expand Down
15 changes: 12 additions & 3 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ void SendSignal(pid_t pid, int Sig)
}


void PidFileKill(const char *AppName)
void PidPathKill(const char *Path)
{
char *Path=NULL, *Tempstr=NULL;
char *Tempstr=NULL;
STREAM *S;
pid_t pid;

Path=MCopyStr(Path, Settings.PidsDir, "/", AppName, ".pid", NULL);
S=STREAMOpen(Path, "r");
if (S)
{
Expand All @@ -47,6 +46,16 @@ void PidFileKill(const char *AppName)
}

Destroy(Tempstr);
}


void PidFileKill(const char *AppName)
{
char *Path=NULL;

Path=MCopyStr(Path, Settings.PidsDir, "/", AppName, ".pid", NULL);
PidPathKill(Path);

Destroy(Path);
}

Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern STREAM *StdIO;
typedef void (*INTERACTIVE_STATUS_CALLBACK)(TNetDev *Dev, const char *Text);

extern INTERACTIVE_STATUS_CALLBACK DisplayStatus;
void PidPathKill(const char *Path);
void PidFileKill(const char *AppName);
TNet *NetCreate();
void NetDestroy(void *p_Net);
Expand Down
62 changes: 27 additions & 35 deletions config.log
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ generated by GNU Autoconf 2.69. Invocation command line was
## Platform. ##
## --------- ##

hostname = DellM6400
hostname = hplap
uname -m = x86_64
uname -r = 5.19.6-64
uname -s = Linux
Expand All @@ -27,51 +27,42 @@ uname -v = #1 SMP PREEMPT_DYNAMIC Sat Sep 3 14:17:57 BST 2022
/usr/bin/oslevel = unknown
/bin/universe = unknown

PATH: /home/colum/bin
PATH: /usr/prebin
PATH: /home/colum/bin
PATH: /usr/local/bin
PATH: /usr/bin
PATH: /usr/X11R7/bin
PATH: /bin
PATH: /usr/games/bin
PATH: .
PATH: /opt/blender-2.79b/bin
PATH: /opt/brlcad-7.26.4/bin
PATH: /opt/chess/bin
PATH: /opt/cmake-3.26.4/bin
PATH: /opt/Csound-6.05/bin
PATH: /opt/Drawing/bin
PATH: /opt/FLTK/bin
PATH: /opt/games/bin
PATH: /opt/ghostscript-9.26/bin
PATH: /opt/ghostscript-9.28rc2/bin
PATH: /opt/gifprogs-5.1.2/bin
PATH: /opt/git-2.21.0/bin
PATH: /opt/gnuplot-5.4.8/bin
PATH: /opt/graphviz-2.40.1/bin
PATH: /opt/GTK/bin
PATH: /opt/jpegprogs-9c/bin
PATH: /opt/LibreCAD/bin
PATH: /opt/Python-3.7.1/bin
PATH: /opt/Qt5/bin
PATH: /opt/SDL/bin
PATH: /opt/SDL2/bin
PATH: /opt/boinc_client-7.14.2/bin
PATH: /opt/chess/bin
PATH: /opt/games/bin
PATH: /opt/ghostscript-9.22/bin
PATH: /opt/git-2.16.2/bin
PATH: /opt/lua-5.3.4/bin
PATH: /opt/luajid-2.0.4/bin
PATH: /opt/mujs-1.0.5/bin
PATH: /opt/mujs-1.0.3/bin
PATH: /opt/netpbm-10.66.02/bin
PATH: /opt/ogre-3d/bin
PATH: /opt/OoklaSpeedtest/bin
PATH: /opt/opengl/bin
PATH: /opt/openjdk-15.0.2/bin
PATH: /opt/perl-5.24.1/bin
PATH: /opt/pngprogs-1.6.30/bin
PATH: /opt/Python-2.7.15/bin
PATH: /opt/Python-3.11.3/bin
PATH: /opt/qemu-3.1.0_SDL/bin
PATH: /opt/Qt5/bin
PATH: /opt/ruby-2.7.1/bin
PATH: /opt/SDL2/bin
PATH: /opt/SDL/bin
PATH: /opt/sound-studio/bin
PATH: /opt/tcl-8.6.9/bin
PATH: /opt/tiffprogs-4.0.8/bin
PATH: /opt/wine-8.2/bin
PATH: /opt/qemu-5.2.1_SDL/bin
PATH: /opt/ruby-2.5.0/bin
PATH: /opt/rust-1.57.0/bin
PATH: /opt/schily/bin
PATH: /opt/tcl-8.6.8/bin
PATH: /opt/tesseract-5.3.4/bin
PATH: /opt/timekeeper/bin
PATH: /opt/wine-6.0/bin


## ----------- ##
Expand All @@ -83,7 +74,7 @@ configure:2092: found /usr/bin/gcc
configure:2103: result: gcc
configure:2332: checking for C compiler version
configure:2341: gcc --version >&5
gcc (GCC) 8.3.0
gcc (GCC) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Expand All @@ -92,11 +83,11 @@ configure:2352: $? = 0
configure:2341: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-pc-linux-gnu/8.3.0/lto-wrapper
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-pc-linux-gnu/8.1.0/lto-wrapper
Target: i486-pc-linux-gnu
Configured with: ../gcc-8.3.0-src/configure --enable-languages=c,c++,go --disable-nls --disable-multilib --prefix=/usr --sysconfdir=/etc --includedir=/usr/include --localstatedir=/var --mandir=/usr/share/man --infodir=/usr/share/info --host=i486-pc-linux-gnu --build=i486-pc-linux-gnu --target=i486-pc-linux-gnu
Configured with: ../gcc-8.1.0-src/configure --prefix=/usr --sysconfdir=/etc --includedir=/usr/include --localstatedir=/var --mandir=/usr/share/man --infodir=/usr/share/info --host=i486-pc-linux-gnu --build=i486-pc-linux-gnu --target=i486-pc-linux-gnu --enable-languages=c,c++,go --disable-nls --disable-multilib
Thread model: posix
gcc version 8.3.0 (GCC)
gcc version 8.1.0 (GCC)
configure:2352: $? = 0
configure:2341: gcc -V >&5
gcc: error: unrecognized command line option '-V'
Expand Down Expand Up @@ -328,9 +319,10 @@ generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_COMMANDS =
$ ./config.status

on DellM6400
on hplap

config.status:726: creating Makefile
config.status:825: WARNING: 'Makefile.in' seems to ignore the --datarootdir setting

## ---------------- ##
## Cache variables. ##
Expand Down
12 changes: 9 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,19 @@ int main(int argc, char *argv[])
Interactive(Dev);
break;

case ACT_IFACE_LIST:
ListInterfaces();
break;

case ACT_VERSION:
printf("term_wifi %s\n", VERSION);
break;

case ACT_HELP:
DisplayHelp();
break;

case ACT_IFACE_LIST:
ListInterfaces();
break;

}
}

Expand Down
Loading

0 comments on commit 9da429c

Please sign in to comment.