1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#include <stdio.h>
#include <signal.h>
#include <sys/wait.h>
#include <termios.h>
#include "fppxp.h"
#include <support.h>
#include <xcio.h>
#include <ppxp.h>
static struct {
FL_OBJECT *obj;
const char *name, *key;
} buttons[]={
{NULL, "Connect", "#C"},
{NULL, "Terminal", "#T"},
{NULL, "Bye", "#B"},
{NULL, "Quit", "#Q"},
};
enum {
CONNECT_BUTTON,
TERMINAL_BUTTON,
BYE_BUTTON,
QUIT_BUTTON,
MAX_BUTTONS
};
#define BUTTON_WIDTH 70
#define BUTTON_HEIGHT 25
static pid_t termPid;
static int autoTerm;
FL_OBJECT *autoModeObj, *openTermObj;
static void
SigChld(int sig)
{
int ps;
pid_t pid;
signal(SIGCHLD, SigChld);
pid = wait3(&ps, WNOHANG, 0);
if (pid == termPid) autoTerm = termPid = 0;
};
void
ExecTerminal(int mode)
{
pid_t child;
extern char termCommand[];
if ((child = fork()) < 0) return;
signal(SIGCHLD, SigChld);
if (!child) {
char *argv[]={termCommand, "-e", PATH_PPXP, NULL};
seteuid(getuid());
execvp(argv[0], argv);
{char buf[200];
sprintf(buf, "<%s><%s><%s>\n", argv[0], argv[1], argv[2]);
perror(buf);}
exit(-1);
}
termPid = child;
}
void
UpdateButtons(struct pppinfo_s *old, struct pppinfo_s *new)
{
if (old->phase != new->phase) {
fl_set_object_label(buttons[CONNECT_BUTTON].obj,
(new->phase < PS_ESTABLISH)
? "Connect": "Disconnect");
}
if (old->m_flag != new->m_flag) {
fl_set_button(autoModeObj,
(new->m_flag & MFLAG_AUTO) ? 1: 0);
}
if (old->l_stat != new->l_stat) {
if (new->l_stat & LSTAT_TTY) {
if (!termPid && fl_get_button(openTermObj)) {
ExecTerminal(1);
if (termPid) autoTerm = 1;
}
} else if (termPid && autoTerm) {
kill(termPid, SIGKILL);
}
}
}
static void
ButtonsCallBack(FL_OBJECT *obj, long arg)
{
int i;
switch (arg) {
case CONNECT_BUTTON:
XcCommand(strcasecmp(obj->label, "disconnect") ?
XCMD_CONNECT: XCMD_DISCONNECT, NULL, NULL);
break;
case TERMINAL_BUTTON:
if (!termPid && !autoTerm) ExecTerminal(0);
break;
case QUIT_BUTTON:
XcCommand(XCMD_QUIT, NULL, NULL);
break;
case BYE_BUTTON:
exit(0);
}
}
static void
ChecksCallBack(FL_OBJECT *obj, long arg)
{
if (obj == autoModeObj)
XcCommand(XCMD_AUTO, NULL,
fl_get_button(obj) ? "on": "off", NULL);
}
void
CreateButtons(FL_FORM *form)
{
FL_OBJECT *obj;
int y=FRAME_GAP;
unsigned n;
obj = fl_add_box(FL_FRAME_BOX,
form->w - BUTTON_WIDTH - FRAME_GAP * 3,
y, BUTTON_WIDTH + FRAME_GAP * 2,
(BUTTON_HEIGHT + FRAME_GAP) * MAX_BUTTONS +
FRAME_GAP, "");
fl_set_object_color(obj, FL_INDIANRED, FL_COL1);
for (n = 0; n < MAX_BUTTONS; n ++) {
y += FRAME_GAP;
obj = fl_add_button(FL_NORMAL_BUTTON,
form->w - BUTTON_WIDTH - FRAME_GAP * 2,
y, BUTTON_WIDTH, BUTTON_HEIGHT,
buttons[n].name);
/*fl_set_object_boxtype(obj, FL_SHADOW_BOX);*/
fl_set_object_callback(obj, ButtonsCallBack, n);
fl_set_object_shortcut(obj, buttons[n].key, 1);
buttons[n].obj = obj;
y += BUTTON_HEIGHT;
}
fl_set_object_label(autoModeObj, "AUTO");
fl_set_object_callback(autoModeObj, ChecksCallBack, 0);
fl_set_object_label(openTermObj, "TERM");
fl_set_object_callback(openTermObj, ChecksCallBack, 0);
}
|