This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
307 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
CC = gcc | ||
CFLAGS = -Wall | ||
|
||
DEPS = src/utils/list.h src/email.h src/load_fileitem.h src/validation.h | ||
OBJ = src/utils/list.o src/email.o src/load_fileitem.o src/validation.o src/main.o | ||
|
||
%.o: %.c $(DEPS) | ||
$(CC) -c -o $@ $< $(CFLAGS) | ||
|
||
lugbar: $(OBJ) | ||
$(CC) -o $@ $^ $(CFLAGS) | ||
|
||
.PHONY: clean | ||
|
||
clean: | ||
rm -f $(OBJ) lugbar *~ | ||
|
||
install: | ||
mkdir -p /etc/lugbar | ||
wget https://raw.githubusercontent.com/Roma2Lug-Projects/NFC-Emulator/main/src/config/products.txt -O /etc/lugbar/item.txt | ||
cp lugbar /usr/local/bin/ | ||
chmod u+x /usr/local/bin/lugbar | ||
|
||
uninstall: | ||
rm -rf /usr/local/bin/lugbar | ||
rm -rf /etc/lugbar/item.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Package: lugbar | ||
Version: 0.0-1 | ||
Section: base | ||
Priority: optional | ||
Architecture: amd64 | ||
Depends: msmtp, wget | ||
Maintainer: Valerio | ||
Description: lugbar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
mkdir -p /etc/lugbar | ||
wget https://raw.githubusercontent.com/Roma2Lug-Projects/NFC-Emulator/main/src/config/products.txt -O /etc/lugbar/item.txt | ||
|
||
chmod u+x /usr/local/bin/lugbar | ||
chmod 775 /etc/lugbar/item.txt |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
void sendemail(char *item) { | ||
|
||
char command[100]; | ||
|
||
sprintf(command, "printf 'Subject:%s' | msmtp -a lugbar [email protected]", item); | ||
if(system(command) == -1) { | ||
perror("Error: "); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int sendemail(char *item); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "utils/list.h" | ||
|
||
struct head_node *loadfile(){ | ||
|
||
char const* const file_name = "/etc/lugbar/item.txt"; | ||
FILE* file = fopen(file_name, "r"); | ||
char line[32]; | ||
|
||
struct head_node *item_list = create_list(); | ||
|
||
while (fgets(line, sizeof(line), file)) { | ||
|
||
insert_node(&item_list, line); | ||
} | ||
|
||
fclose(file); | ||
|
||
return item_list; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
struct head_node *loadfile(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include "load_fileitem.h" | ||
#include "email.h" | ||
#include "validation.h" | ||
#include "utils/list.h" | ||
|
||
int main(int argc, char **argv) { | ||
|
||
int i = 0; | ||
|
||
if (valid() == -1) { | ||
return 0; | ||
} | ||
|
||
struct head_node *item_list = loadfile(); | ||
struct node *current = item_list->next; | ||
int max_item = item_list->count; | ||
|
||
if(argc == 1) { | ||
printf("Uso: %s [OPZIONE]...[NUMERO] ...\n\nPer ordinare usa %s [NUMERO]\nOpzioni disponibili:\n--lista\tlista gli elementi col corrispettivo numero di ordinazione\n", argv[0], argv[0]); | ||
return 0; | ||
} | ||
|
||
else if (strcmp(argv[1], "--lista") == 0) { | ||
while(i++ < max_item){ | ||
printf("%d. %s\n", i, current->item_name); | ||
current = current->next; | ||
} | ||
return 0; | ||
} | ||
|
||
else if (strcmp(argv[1], "versamento") == 0) { | ||
if (argc < 3) { | ||
printf("Assente l'importo del versamento\n"); | ||
} | ||
else { | ||
char subject[16]; | ||
sprintf(subject, "versamento %s", argv[2]); | ||
|
||
if(!sendemail(subject)) { | ||
printf("Versato %s\n", argv[2]); | ||
} | ||
} | ||
} | ||
|
||
else if (atoi(argv[1]) > max_item) { | ||
puts("Acquisto non valido. Usa lugbar -lista per listare gli elementi"); | ||
return 0; | ||
} | ||
|
||
else if (atoi(argv[1]) < max_item && atoi(argv[1]) > 0) { | ||
char *choice_item = lookup_list(¤t, atoi(argv[1])-1); | ||
char subject[16]; | ||
sprintf(subject, "acquisto %s", choice_item); | ||
if(!sendemail(subject)) { | ||
printf("Acquistato %s\n", choice_item); | ||
|
||
} | ||
} | ||
|
||
else { | ||
printf("Uso: %s [OPZIONE]...[NUMERO] ...\n\nPer ordinare usa %s [NUMERO]\n\nOpzioni disponibili:\n--lista lista gli elementi col corrispettivo numero di ordinazione\n", argv[0], argv[0]); | ||
return 0; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "list.h" | ||
|
||
char *lookup_list(struct node **first_node, int p) { | ||
struct node *cursor; | ||
cursor = *first_node; | ||
while(cursor) { | ||
if(cursor->pos != p) { | ||
cursor = cursor->next; | ||
} | ||
else { | ||
return cursor->item_name; | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
struct head_node *create_list(){ | ||
|
||
struct head_node *temp; | ||
temp = malloc(sizeof(struct head_node)); | ||
temp->count = 0; | ||
temp->next = NULL; | ||
|
||
return temp; | ||
} | ||
|
||
void insert_node(struct head_node **head, char *item) { | ||
|
||
struct node *temp = malloc(sizeof(struct node)); | ||
strcpy(temp->item_name, item); | ||
temp->next=NULL; | ||
int i = 1; | ||
|
||
if((*head)->next == NULL) { | ||
(*head)->next = temp; | ||
(*head)->count = 1; | ||
} | ||
|
||
else { | ||
|
||
struct node *current; | ||
current = (*head)->next; | ||
while(current->next!=NULL) { | ||
i++; | ||
current=current->next; | ||
} | ||
|
||
temp->pos = i; | ||
current->next=temp; | ||
(*head)->count = ((*head)->count) + 1; | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
struct node { | ||
int pos; | ||
char item_name[32]; | ||
struct node* next; | ||
}; | ||
|
||
struct head_node { | ||
int count; | ||
struct node* next; | ||
}; | ||
|
||
void insert_node(struct head_node **head, char *item); | ||
struct head_node *create_list(); | ||
char *lookup_list(struct node **first_node, int p); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <errno.h> | ||
|
||
int check_fileitem(){ | ||
|
||
char* fullpath = "/etc/lugbar/item.txt"; | ||
|
||
FILE *file; | ||
|
||
if ((file = fopen(fullpath, "r")) == NULL) { | ||
if (errno == ENOENT) { | ||
return -1; | ||
} | ||
} | ||
|
||
fclose(file); | ||
return 1; | ||
} | ||
|
||
int check_msmtp(){ | ||
if (system("which msmtp > /dev/null 2>&1")){ | ||
return -1; | ||
} | ||
return 1; | ||
} | ||
|
||
int check_config(){ | ||
char* fullpath = "/etc/msmtprc"; | ||
|
||
FILE *file; | ||
|
||
if ((file = fopen(fullpath, "r")) == NULL) { | ||
if (errno == ENOENT) { | ||
return -1; | ||
} | ||
} | ||
|
||
fclose(file); | ||
return 1; | ||
} | ||
|
||
|
||
|
||
int valid(){ | ||
|
||
if(check_fileitem() == -1) { | ||
printf("File /etc/lugbar/item.txt assente\n"); | ||
return -1; | ||
} | ||
if(check_msmtp() == -1) { | ||
printf("Programma msmtp non installato\n"); | ||
return -1; | ||
} | ||
|
||
if(check_config() == -1) { | ||
printf("File in /etc/msmtprc assente\n"); | ||
printf("Esempio file:\n\n" | ||
"defaults\n" | ||
"syslog LOG_MAIL\n" | ||
"auth on\n" | ||
"tls on\n" | ||
"aliases /etc/aliases\n" | ||
"# Example with GMAIL\n" | ||
"account lugbar\n" | ||
"host smtp.gmail.com\n" | ||
"port 465\n" | ||
"tls on\n" | ||
"tls_starttls off\n" | ||
"from \"tuo nome\"\n" | ||
"user [email protected]\n" | ||
"password \"password\"""\n" | ||
"set_from_header on\n\n" | ||
"Se usi Gmail devi generare una password per app https://myaccount.google.com/apppasswords\n"); | ||
return -1; | ||
} | ||
|
||
return 1; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
int check_fileitem(); | ||
int check_msmtp(); | ||
int check_config(); | ||
int valid(); |