Version v0.2.72 - Clean pipe mode output - suppressed startup messages for seamless piping
This commit is contained in:
49
otp.c
49
otp.c
@@ -134,18 +134,23 @@ int main(int argc, char* argv[]) {
|
|||||||
// Load preferences first
|
// Load preferences first
|
||||||
load_preferences();
|
load_preferences();
|
||||||
|
|
||||||
|
// Check for piped input first (before any output)
|
||||||
|
int is_pipe_mode = (argc == 1 && has_stdin_data());
|
||||||
|
|
||||||
// Check for OTP thumb drive on startup
|
// Check for OTP thumb drive on startup
|
||||||
char otp_drive_path[512];
|
char otp_drive_path[512];
|
||||||
if (detect_otp_thumb_drive(otp_drive_path, sizeof(otp_drive_path))) {
|
if (detect_otp_thumb_drive(otp_drive_path, sizeof(otp_drive_path))) {
|
||||||
|
// Only show messages in interactive/command mode, not pipe mode
|
||||||
|
if (!is_pipe_mode) {
|
||||||
printf("Detected OTP thumb drive: %s\n", otp_drive_path);
|
printf("Detected OTP thumb drive: %s\n", otp_drive_path);
|
||||||
printf("Using as default pads directory for this session.\n\n");
|
printf("Using as default pads directory for this session.\n\n");
|
||||||
|
}
|
||||||
strncpy(current_pads_dir, otp_drive_path, sizeof(current_pads_dir) - 1);
|
strncpy(current_pads_dir, otp_drive_path, sizeof(current_pads_dir) - 1);
|
||||||
current_pads_dir[sizeof(current_pads_dir) - 1] = '\0';
|
current_pads_dir[sizeof(current_pads_dir) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for piped input
|
if (is_pipe_mode) {
|
||||||
if (argc == 1 && has_stdin_data()) {
|
// No arguments but has piped data - enter pipe mode
|
||||||
// No arguments but has piped data - enter pipe mode for interactive pad selection
|
|
||||||
char* piped_text = read_stdin_text();
|
char* piped_text = read_stdin_text();
|
||||||
if (piped_text) {
|
if (piped_text) {
|
||||||
int result = pipe_mode(argc, argv, piped_text);
|
int result = pipe_mode(argc, argv, piped_text);
|
||||||
@@ -2409,8 +2414,6 @@ int pipe_mode(int argc, char* argv[], const char* piped_text) {
|
|||||||
(void)argc; // Suppress unused parameter warning
|
(void)argc; // Suppress unused parameter warning
|
||||||
(void)argv; // Suppress unused parameter warning
|
(void)argv; // Suppress unused parameter warning
|
||||||
|
|
||||||
printf("Piped text received: \"%s\"\n", piped_text);
|
|
||||||
|
|
||||||
// Check if we have a default pad configured
|
// Check if we have a default pad configured
|
||||||
char* default_pad = get_default_pad_path();
|
char* default_pad = get_default_pad_path();
|
||||||
if (default_pad) {
|
if (default_pad) {
|
||||||
@@ -2427,51 +2430,23 @@ int pipe_mode(int argc, char* argv[], const char* piped_text) {
|
|||||||
strncpy(pad_checksum, filename, 64);
|
strncpy(pad_checksum, filename, 64);
|
||||||
pad_checksum[64] = '\0';
|
pad_checksum[64] = '\0';
|
||||||
|
|
||||||
printf("Using default pad: %.16s...\n\n", pad_checksum);
|
|
||||||
free(default_pad);
|
free(default_pad);
|
||||||
|
|
||||||
// Encrypt using the default pad
|
// Encrypt using the default pad (silent mode)
|
||||||
return encrypt_text(pad_checksum, piped_text);
|
return encrypt_text(pad_checksum, piped_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Warning: Default pad not found or invalid: %s\n", default_pad);
|
fprintf(stderr, "Error: Default pad not found or invalid: %s\n", default_pad);
|
||||||
free(default_pad);
|
free(default_pad);
|
||||||
// Fall through to interactive selection
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("No default pad configured.\n\n");
|
|
||||||
|
|
||||||
// List available pads for interactive selection
|
|
||||||
int pad_count = list_available_pads();
|
|
||||||
if (pad_count == 0) {
|
|
||||||
printf("No pads available. Generate a pad first.\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reopen stdin from the controlling terminal for interactive input
|
fprintf(stderr, "Error: No default pad configured for pipe mode\n");
|
||||||
FILE* tty = fopen("/dev/tty", "r");
|
fprintf(stderr, "Configure a default pad in ~/.otp/otp.conf\n");
|
||||||
if (!tty) {
|
|
||||||
printf("Error: Cannot open terminal for input\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nEnter pad selection (number, checksum, or prefix): ");
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
char pad_input[MAX_HASH_LENGTH];
|
|
||||||
if (!fgets(pad_input, sizeof(pad_input), tty)) {
|
|
||||||
printf("Error: Failed to read pad selection\n");
|
|
||||||
fclose(tty);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pad_input[strcspn(pad_input, "\n")] = 0;
|
|
||||||
fclose(tty);
|
|
||||||
|
|
||||||
// Encrypt the piped text
|
|
||||||
return encrypt_text(pad_input, piped_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preferences management functions implementation
|
// Preferences management functions implementation
|
||||||
int load_preferences(void) {
|
int load_preferences(void) {
|
||||||
char* home_dir = getenv("HOME");
|
char* home_dir = getenv("HOME");
|
||||||
|
|||||||
Reference in New Issue
Block a user