Binary for fixing filenames.
This commit is contained in:
parent
2277f8e580
commit
f7a79c0003
4 changed files with 79 additions and 1 deletions
|
@ -304,6 +304,9 @@ module.exports = function (grunt) {
|
|||
// Copies remaining files to places other tasks can use
|
||||
copy: {
|
||||
dist: {
|
||||
options: {
|
||||
mode: true
|
||||
},
|
||||
files: [
|
||||
{
|
||||
expand: true,
|
||||
|
@ -342,6 +345,12 @@ module.exports = function (grunt) {
|
|||
cwd: '.',
|
||||
dest: '<%= yeoman.dist %>/',
|
||||
src: ['package.json']
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'bin',
|
||||
dest: '<%= yeoman.dist %>/bin',
|
||||
src: ['*']
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
69
bin/fix_key_file_names.py
Executable file
69
bin/fix_key_file_names.py
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print('usage: ' + sys.argv[0] + ' /path/to/peers')
|
||||
sys.exit(1)
|
||||
|
||||
peersDir = sys.argv[1]
|
||||
|
||||
def normalizeMac(mac):
|
||||
mac = mac.lower()
|
||||
normalized = ''
|
||||
|
||||
n = 0
|
||||
|
||||
for c in mac:
|
||||
if c != ':':
|
||||
if n > 0 and n % 2 == 0:
|
||||
normalized = normalized + ':'
|
||||
normalized = normalized + c
|
||||
n += 1
|
||||
|
||||
return normalized
|
||||
|
||||
def toFilename(peer):
|
||||
filename = ''
|
||||
for field in ['name', 'mac', 'vpn', 'token']:
|
||||
if peer.has_key(field):
|
||||
filename = filename + peer[field]
|
||||
filename = filename + '@'
|
||||
|
||||
return filename[:-1]
|
||||
|
||||
for filename in os.listdir(peersDir):
|
||||
if len(filename) == 0 or filename[0] == '.':
|
||||
continue
|
||||
|
||||
absFilename = peersDir + '/' + filename
|
||||
if os.path.isfile(absFilename):
|
||||
peerFile = open(absFilename, 'r')
|
||||
try:
|
||||
peerLines = peerFile.readlines()
|
||||
peer = {}
|
||||
mac = None
|
||||
for line in peerLines:
|
||||
parts = line.split()
|
||||
|
||||
if len(parts) > 0:
|
||||
if parts[1] == 'Knotenname:':
|
||||
peer['name'] = parts[2].lower()
|
||||
elif parts[1] == 'MAC:':
|
||||
peer['mac'] = normalizeMac(parts[2])
|
||||
elif parts[1] == 'Token:':
|
||||
peer['token'] = parts[2].lower()
|
||||
elif parts[0] == 'key':
|
||||
peer['vpn'] = parts[1].split('"')[1].lower()
|
||||
|
||||
newFilename = toFilename(peer)
|
||||
|
||||
if filename != newFilename:
|
||||
os.rename(absFilename, peersDir + '/' + newFilename)
|
||||
|
||||
except Exception as e:
|
||||
print('Error in %s, ignoring peer: %s' % (absFilename, e));
|
||||
finally:
|
||||
peerFile.close()
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
"grunt-contrib-compass": "~0.7.2",
|
||||
"grunt-contrib-concat": "~0.3.0",
|
||||
"grunt-contrib-connect": "~0.5.0",
|
||||
"grunt-contrib-copy": "~0.4.1",
|
||||
"grunt-contrib-copy": "~0.5.0",
|
||||
"grunt-contrib-cssmin": "~0.7.0",
|
||||
"grunt-contrib-htmlmin": "~0.1.3",
|
||||
"grunt-contrib-imagemin": "~0.3.0",
|
||||
|
|
0
server/main.js
Executable file → Normal file
0
server/main.js
Executable file → Normal file
Loading…
Reference in a new issue