Skip to content

Add --no-bookends option #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion man/logkeys.8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logkeys \- a GNU/Linux keylogger that works!
.SH SYNOPSIS
.B logkeys \fB-s\fR [\fB-m \fIkeymap\fR | \fB-u\fR] [\fB-o \fIlogfile\fR] [\fB-d \fIdevice\fR]
.br
[\fB--no-func-keys\fR] [\fB--no-timestamps\fR]
[\fB--no-func-keys\fR] [\fB--no-timestamps\fR] [\fB--no-bookends\fR]
.br
[\fB--post-http=\fIURL\fR] [\fB--post-size=\fISIZE\fR]
.br
Expand Down Expand Up @@ -92,6 +92,10 @@ on a virtual terminal outside of X (\fI/dev/ttyX\fR).
.IP
See section \fBKEYMAP FORMAT\fR for exported keymap format.

.TP
\fB-\-no-bookends\fR
When this option is set, logkeys doesn't log messages when starting and stopping.

.TP
\fB-\-no-func-keys\fR
This option makes logkeys log all and only character key presses
Expand Down
18 changes: 10 additions & 8 deletions src/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ struct arguments
std::string irc_port; // if --post-irc effective, this holds the IRC port number
off_t post_size; // post log file to remote when of size post_size, --post-size switch
int flags; // holds the following option flags
#define FLAG_EXPORT_KEYMAP 0x1 // export keymap obtained from dumpkeys, --export-keymap is used
#define FLAG_NO_FUNC_KEYS 0x2 // only log character keys (e.g. 'c', '2', etc.) and don't log function keys (e.g. <LShift>, etc.), --no-func-keys switch
#define FLAG_NO_TIMESTAMPS 0x4 // don't log timestamps, --no-timestamps switch
#define FLAG_POST_HTTP 0x8 // post log to remote HTTP server, --post-http switch
#define FLAG_POST_IRC 0x10 // post log to remote IRC server, --post-irc switch
#define FLAG_POST_SIZE 0x20 // post log to remote HTTP or IRC server when log of size optarg, --post-size
#define FLAG_NO_DAEMON 0x40 // don't daemonize process, stay in foreground, --no-daemon switch
#define FLAG_TIMESTAMP_EVERY 0x80 // log timestamps on every key, --timestamp-every switch
#define FLAG_EXPORT_KEYMAP 0x1 // export keymap obtained from dumpkeys, --export-keymap is used
#define FLAG_NO_FUNC_KEYS 0x2 // only log character keys (e.g. 'c', '2', etc.) and don't log function keys (e.g. <LShift>, etc.), --no-func-keys switch
#define FLAG_NO_TIMESTAMPS 0x4 // don't log timestamps, --no-timestamps switch
#define FLAG_POST_HTTP 0x8 // post log to remote HTTP server, --post-http switch
#define FLAG_POST_IRC 0x10 // post log to remote IRC server, --post-irc switch
#define FLAG_POST_SIZE 0x20 // post log to remote HTTP or IRC server when log of size optarg, --post-size
#define FLAG_NO_DAEMON 0x40 // don't daemonize process, stay in foreground, --no-daemon switch
#define FLAG_TIMESTAMP_EVERY 0x80 // log timestamps on every key, --timestamp-every switch
#define FLAG_NO_BOOKENDS 0x100 // don't log "Staring logging..." and "Stopping logging..." messages
} args = {0}; // default all args to 0x0 or ""


Expand All @@ -52,6 +53,7 @@ void process_command_line_arguments(int argc, char **argv)
{"device", required_argument, 0, 'd'},
{"help", no_argument, 0, '?'},
{"export-keymap", required_argument, &flags, FLAG_EXPORT_KEYMAP},
{"no-bookends", no_argument, &flags, FLAG_NO_BOOKENDS},
{"no-func-keys", no_argument, &flags, FLAG_NO_FUNC_KEYS},
{"no-timestamps", no_argument, &flags, FLAG_NO_TIMESTAMPS},
{"post-http", required_argument, &flags, FLAG_POST_HTTP},
Expand Down
18 changes: 11 additions & 7 deletions src/logkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,12 @@ void log_loop()
time(&cur_time);
strftime(timestamp, sizeof(timestamp), TIME_FORMAT, localtime(&cur_time));

if (args.flags & FLAG_NO_TIMESTAMPS)
file_size += fprintf(out, "Logging started at %s\n\n", timestamp);
else
file_size += fprintf(out, "Logging started ...\n\n%s", timestamp);
if (!(args.flags & FLAG_NO_BOOKENDS)) {
if (args.flags & FLAG_NO_TIMESTAMPS)
file_size += fprintf(out, "Logging started at %s\n\n", timestamp);
else
file_size += fprintf(out, "Logging started ...\n\n%s", timestamp);
}
fflush(out);

// infinite loop: exit gracefully by receiving SIGHUP, SIGINT or SIGTERM (of which handler closes input_fd)
Expand All @@ -647,9 +649,11 @@ void log_loop()
}

// append final timestamp, close files and exit
time(&cur_time);
strftime(timestamp, sizeof(timestamp), "%F %T%z", localtime(&cur_time));
fprintf(out, "\n\nLogging stopped at %s\n\n", timestamp);
if (!(args.flags & FLAG_NO_BOOKENDS)) {
time(&cur_time);
strftime(timestamp, sizeof(timestamp), "%F %T%z", localtime(&cur_time));
fprintf(out, "\n\nLogging stopped at %s\n\n", timestamp);
}
fclose(out);
}

Expand Down