mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
Move history and logfile to ~/.proxmark3
This commit is contained in:
parent
03867018f1
commit
d2d58db985
5 changed files with 74 additions and 13 deletions
65
client/ui.c
65
client/ui.c
|
@ -24,6 +24,9 @@
|
|||
#include <readline/readline.h>
|
||||
#include <complex.h>
|
||||
#include "util.h"
|
||||
#include "proxmark3.h" // PROXLOG
|
||||
#include "fileutils.h"
|
||||
#include "pm3_cmd.h"
|
||||
|
||||
session_arg_t session;
|
||||
|
||||
|
@ -36,9 +39,45 @@ bool GridLocked = false;
|
|||
bool showDemod = true;
|
||||
|
||||
pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static const char *logfilename = "proxmark3.log";
|
||||
|
||||
static void fPrintAndLog(FILE *stream, const char *fmt, ...);
|
||||
|
||||
// needed by flasher, so let's put it here instead of fileutils.c
|
||||
int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) {
|
||||
if (foundpath == NULL)
|
||||
return PM3_EINVARG;
|
||||
char *user_path = getenv("HOME");
|
||||
if (user_path == NULL)
|
||||
return PM3_EFILE;
|
||||
char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1, sizeof(char));
|
||||
if (path == NULL)
|
||||
return PM3_EMALLOC;
|
||||
strcpy(path, user_path);
|
||||
strcat(path, PM3_USER_DIRECTORY);
|
||||
|
||||
#ifdef _WIN32
|
||||
struct _stat st;
|
||||
int result = _stat(path, &st);
|
||||
#else
|
||||
struct stat st;
|
||||
int result = stat(path, &st);
|
||||
#endif
|
||||
if ((result != 0) && create_home) {
|
||||
if (mkdir(path, 0700)) {
|
||||
free(path);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
}
|
||||
if (filename == NULL) {
|
||||
*foundpath = path;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
path = realloc(path, (strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(filename) + 1) * sizeof(char));
|
||||
strcat(path, filename);
|
||||
*foundpath = path;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) {
|
||||
char buff[2000] = "Options:\n";
|
||||
char format[2000] = "";
|
||||
|
@ -166,10 +205,24 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
|||
pthread_mutex_lock(&print_lock);
|
||||
|
||||
if (logging && !logfile) {
|
||||
logfile = fopen(logfilename, "a");
|
||||
if (!logfile) {
|
||||
fprintf(stderr, "Can't open logfile, logging disabled!\n");
|
||||
char *my_logfile_path = NULL;
|
||||
char filename[40];
|
||||
struct tm *timenow;
|
||||
time_t now = time(NULL);
|
||||
timenow = gmtime(&now);
|
||||
strftime(filename, sizeof(filename), PROXLOG, timenow);
|
||||
if (searchHomeFilePath(&my_logfile_path, filename, true) != PM3_SUCCESS) {
|
||||
fprintf(stderr, "Could not create $HOME/.proxmark3/%s, no log will be recorded\n", filename);
|
||||
my_logfile_path = NULL;
|
||||
logging = 0;
|
||||
} else {
|
||||
logfile = fopen(my_logfile_path, "a");
|
||||
if (logfile == NULL) {
|
||||
fprintf(stderr, "Can't open logfile %s, logging disabled!\n", my_logfile_path);
|
||||
logging = 0;
|
||||
}
|
||||
printf("Session is logged into %s\n", my_logfile_path);
|
||||
free(my_logfile_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,10 +281,6 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
|||
pthread_mutex_unlock(&print_lock);
|
||||
}
|
||||
|
||||
void SetLogFilename(char *fn) {
|
||||
logfilename = fn;
|
||||
}
|
||||
|
||||
void SetFlushAfterWrite(bool value) {
|
||||
flushAfterWrite = value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue