From 85e5ebac0bb8e9523d8ff59bc85effb7acf283cb Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Mon, 6 May 2019 11:13:51 -0700 Subject: [PATCH] working program --- .envrc | 3 +++ .gitignore | 4 ++++ fileCsv2Json.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++ updateFilelist.sh | 8 +++++++ 4 files changed, 73 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100755 fileCsv2Json.py create mode 100755 updateFilelist.sh diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3625647 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +layout python +dotenv + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab358fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.direnv/* +__pycache__/* +.env +*.pyc diff --git a/fileCsv2Json.py b/fileCsv2Json.py new file mode 100755 index 0000000..8f38c82 --- /dev/null +++ b/fileCsv2Json.py @@ -0,0 +1,58 @@ +#!/usr/bin/python + +import csv +import json + +skip_list = [ + 'D:\Tank\Home', + 'D:\Tank\Shares\hr', + 'D:\Tank\Shares\payroll', + 'D:\Tank\Shares\cis' +] +share_names = { + 'D:\Tank\Shares\\acad': ['acad', 'V:\\'], + 'D:\Tank\Shares\common': ['common', 'X:\\'], + 'D:\Tank\Shares\commercial': ['commercial', 'N:\\'], + 'D:\Tank\Shares\scans': ['scans', 'J:\\'], + 'D:\Tank\Shares\costing': ['costing', 'K:\\'], + 'D:\Tank\Shares\marketing': ['marketing', 'M:\\'], + 'D:\Tank\Shares\\almar': ['almar', 'O:\\'], + 'D:\Tank\Shares\production': ['production', 'P:\\'], + 'D:\Tank\Shares\photos': ['photos', 'U:\\'], +} + +f = open("/tmp/dhcp.csv") +csv_f = csv.reader(f) +x = csv_f.next() +dhcp_list = {} + +for row in csv_f: + dhcp_list[row[0]] = row[8][:-20].upper() + +f = open('/tmp/files.csv') +csv_f = csv.reader(f) +x = csv_f.next() +file_list = [] + +for row in csv_f: + item = {} + if any(share in row[8] for share in skip_list): + continue + if row[8][-1:] == '\\': + continue + item['user'] = row[2][11:].lower() + item['computer'] = dhcp_list.get(row[1], 'Unknown') + if len(row[12]) > 0: + item['share'] = share_names[row[8][:len(row[8]) - len(row[12]) - 1]][0] + item['file'] = (share_names[row[8][:len(row[8]) - + len(row[12]) - 1]][1] + + row[12]) + else: + item['share'] = share_names[row[8]][0] + item['file'] = share_names[row[8]][1] + file_list.append(item) + +result = {'count': len(file_list), 'data': file_list} + +with open('/var/www/openfiles/files.json', 'w') as f: + json.dump(result, f) diff --git a/updateFilelist.sh b/updateFilelist.sh new file mode 100755 index 0000000..b6f9416 --- /dev/null +++ b/updateFilelist.sh @@ -0,0 +1,8 @@ +#!/bin/sh +/usr/bin/ssh fredw@nrb-02 'powershell.exe -command "& {Get-SmbOpenFile} | ConvertTo-Csv -notype | out-file -encoding UTF8 -filepath files.csv"' +/usr/bin/scp fredw@nrb-02:/home/fredw/files.csv /tmp/files.csv + +/usr/bin/ssh fredw@nrb-01 'powershell.exe -command "Get-DHCPServerv4scope | Get-DHCPServerv4Lease | ConvertTo-CSV -notype | out-file -encoding UTF8 -filepath dhcp.csv"' +/usr/bin/scp fredw@nrb-01:/home/fredw/dhcp.csv /tmp/dhcp.csv + +cd /root/.venv/openfiles && direnv exec . python fileCsv2Json.py >/dev/null 2>&1