working program

This commit is contained in:
Fred Warren 2019-05-06 11:13:51 -07:00
commit 85e5ebac0b
4 changed files with 73 additions and 0 deletions

3
.envrc Normal file
View File

@ -0,0 +1,3 @@
layout python
dotenv

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.direnv/*
__pycache__/*
.env
*.pyc

58
fileCsv2Json.py Executable file
View File

@ -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)

8
updateFilelist.sh Executable file
View File

@ -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