diff --git a/front/plugins/csv_backup/README.md b/front/plugins/csv_backup/README.md new file mode 100755 index 00000000..48c16bab --- /dev/null +++ b/front/plugins/csv_backup/README.md @@ -0,0 +1,13 @@ +## Overview + +Plugin generating CSV backups of your Devices database table, including the network mappings. Can be used for importing your setup via the Maintenance > Backup / Restore > CSV Import feature. + +### Usage + +- Go to settings and find TBC + +#### Examples: +- TBC + +### Known Limitations +- TBC diff --git a/front/plugins/csv_backup/config.json b/front/plugins/csv_backup/config.json new file mode 100755 index 00000000..04e31149 --- /dev/null +++ b/front/plugins/csv_backup/config.json @@ -0,0 +1,180 @@ +{ + "code_name": "csv_backup", + "unique_prefix": "CSVBCKP", + "enabled": true, + "data_source": "script", + "show_ui": false, + "localized": ["display_name", "description", "icon"], + + "display_name": [ + { + "language_code": "en_us", + "string": "CSV backup" + }, + { + "language_code": "es_es", + "string": "N/A" + } + ], + "icon": [ + { + "language_code": "en_us", + "string": "" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "A plugin to auto-generate devices.csv backups." + }, + { + "language_code": "es_es", + "string": "N/A" + } + ], + "params" : [{ + "name" : "overwrite", + "type" : "setting", + "value" : "CSVBCKP_overwrite" + }, + { + "name" : "location", + "type" : "setting", + "value" : "CSVBCKP_location" + } + ], + + "settings": [ + { + "function": "RUN", + "type": "text.select", + "default_value":"disabled", + "options": ["disabled", "once", "always_after_scan"], + "localized": ["name", "description"], + "name" :[{ + "language_code":"en_us", + "string" : "When to run" + }, + { + "language_code":"es_es", + "string" : "Cuándo ejecuta" + }], + "description": [{ + "language_code":"en_us", + "string" : "When the backup should be created. A daily SCHEDULE is a good option." + }] + }, + { + "function": "CMD", + "type": "readonly", + "default_value": "python3 /home/pi/pialert/front/plugins/csv_backup/script.py overwrite={overwrite} location={location}", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Command" + }, + { + "language_code": "es_es", + "string": "Comando" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Command to run. This can not be changed" + }, + { + "language_code": "es_es", + "string": "Comando a ejecutar. Esto no se puede cambiar" + } + ] + }, + { + "function": "RUN_SCHD", + "type": "text", + "default_value":"0 2 3 * *", + "options": [], + "localized": ["name", "description"], + "name" : [{ + "language_code":"en_us", + "string" : "Schedule" + }, + { + "language_code":"es_es", + "string" : "Schedule" + }], + "description": [{ + "language_code":"en_us", + "string" : "Only enabled if you select schedule in the CSVBCKP_RUN setting. Make sure you enter the schedule in the correct cron-like format (e.g. validate at crontab.guru). For example entering 0 4 * * * will run the scan after 4 am in the TIMEZONE you set above. Will be run NEXT time the time passes." + }, + { + "language_code":"es_es", + "string" : "Solo está habilitado si selecciona schedule en la configuración CSVBCKP_RUN. Asegúrese de ingresar la programación en el formato similar a cron correcto (por ejemplo, valide en crontab.guru). Por ejemplo, ingresar 0 4 * * * ejecutará el escaneo después de las 4 a.m. en el TIMEZONE que configuró arriba. Se ejecutará la PRÓXIMA vez que pase el tiempo." + }] + }, + { + "function": "RUN_TIMEOUT", + "type": "integer", + "default_value": 30, + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Run timeout" + }, + { + "language_code": "es_es", + "string": "Tiempo límite de ejecución" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Maximum time in seconds to wait for the script to finish. If this time is exceeded the script is aborted." + }, + { + "language_code": "es_es", + "string": "Tiempo máximo en segundos para esperar a que finalice el script. Si se supera este tiempo, el script se cancela." + } + ] + }, + { + "function": "overwrite", + "type": "boolean", + "default_value":false, + "options": [], + "localized": ["name", "description"], + "name" : [{ + "language_code":"en_us", + "string" : "Overwrite file" + }], + "description": [{ + "language_code":"en_us", + "string" : "If the devices.csv file should be always overwritten. If disabled, the date and time is added to the name." + }] + }, + { + "function": "location", + "type": "text", + "default_value":"/home/pi/pialert/config", + "options": [], + "localized": ["name", "description"], + "name" : [{ + "language_code":"en_us", + "string" : "File location" + }], + "description": [{ + "language_code":"en_us", + "string" : "Where the devices.csv file should be saved." + }] + } + ], + + "database_column_definitions": + [ + + ] +} diff --git a/front/plugins/csv_backup/script.py b/front/plugins/csv_backup/script.py new file mode 100755 index 00000000..1126cd33 --- /dev/null +++ b/front/plugins/csv_backup/script.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# test script by running python script.py devices=test,dummy + +import os +import pathlib +import argparse +import sys +import hashlib +import csv +from io import StringIO + +sys.path.append("/home/pi/pialert/front/plugins") +sys.path.append('/home/pi/pialert/pialert') + +import database +from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 +from logger import mylog, append_line_to_file +from helper import timeNowTZ +from const import logPath, pialertPath + + +CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) +LOG_FILE = os.path.join(CUR_PATH, 'script.log') +RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') + +def main(): + + # the script expects a parameter in the format of devices=device1,device2,... + parser = argparse.ArgumentParser(description='TBC') + parser.add_argument('location', action="store", help="TBC") + parser.add_argument('overwrite', action="store", help="TBC") + values = parser.parse_args() + + mylog('verbose', ['[CSVBCKP] In script']) + + # plugin_objects = Plugin_Objects( RESULT_FILE ) + + # if values.devices: + # for fake_dev in values.devices.split('=')[1].split(','): + + # fake_mac = string_to_mac_hash(fake_dev) + + # plugin_objects.add_object( + # primaryId=fake_dev, # MAC (Device Name) + # secondaryId="0.0.0.0", # IP Address (always 0.0.0.0) + # watched1=fake_dev, # Device Name + # watched2="", + # watched3="", + # watched4="", + # extra="", + # foreignKey=fake_mac) + + # plugin_objects.write_result_file() + + # # Execute your SQL query + # cursor.execute("SELECT * FROM Devices") + + # # Get column names + # columns = [desc[0] for desc in cursor.description] + + # # Initialize the CSV writer + # csv_writer = csv.writer(output, quoting=csv.QUOTE_MINIMAL) + + # # Write the header row + # csv_writer.writerow(columns) + + # # Fetch and write data rows + # for row in cursor.fetchall(): + # csv_writer.writerow(row) + + # # Close the database connection + # conn.close() + + # # Prepare the CSV data for download + # csv_data = output.getvalue() + + return 0 + + +#=============================================================================== +# BEGIN +#=============================================================================== +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/front/plugins/unifi_import/config.json b/front/plugins/unifi_import/config.json index d68e5ffd..d9cd84c5 100755 --- a/front/plugins/unifi_import/config.json +++ b/front/plugins/unifi_import/config.json @@ -581,7 +581,7 @@ { "function": "version", "type": "text", - "default_value":"", + "default_value":"v4", "options": [], "localized": ["name", "description"], "name" : [{