From 35f1161453c73ab8b1ddcd5352c0fb13fc67b151 Mon Sep 17 00:00:00 2001 From: Mriyam Tamuli Date: Sat, 8 Oct 2016 14:53:53 +0530 Subject: [PATCH 1/4] Solves SSH Key problem when admin user already exists --- contrib/dokku-installer.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py index b57cf3b63..ab01a01a6 100755 --- a/contrib/dokku-installer.py +++ b/contrib/dokku-installer.py @@ -3,6 +3,7 @@ import cgi import json import os +import re import SimpleHTTPServer import SocketServer import subprocess @@ -100,7 +101,10 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): with open('{0}/HOSTNAME'.format(dokku_root), 'w') as f: f.write(params['hostname'].value) - command = ['sshcommand', 'acl-add', 'dokku', 'admin'] + user = 'admin' + if self.admin_user_exists(): + user = 'web-admin' + command = ['sshcommand', 'acl-add', 'dokku', user] for key in params['keys'].value.split("\n"): proc = subprocess.Popen(command, stdin=subprocess.PIPE) proc.stdin.write(key) @@ -119,6 +123,16 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.end_headers() self.wfile.write(json.dumps({'status': 'ok'})) + def admin_user_exists(self): + command = 'dokku ssh-keys:list' + pattern = re.compile(r'NAME="admin"') + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + for line in proc.stdout: + if pattern.search(line): + return True + else: + return False + def set_debconf_selection(debconf_type, key, value): found = False From 056ff73c2823469197d5c92a7e692c67c2258b49 Mon Sep 17 00:00:00 2001 From: Mriyam Tamuli Date: Thu, 13 Oct 2016 05:18:45 +0530 Subject: [PATCH 2/4] Proper usernames --- contrib/dokku-installer.py | 48 +++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py index ab01a01a6..9634951dc 100755 --- a/contrib/dokku-installer.py +++ b/contrib/dokku-installer.py @@ -101,11 +101,20 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): with open('{0}/HOSTNAME'.format(dokku_root), 'w') as f: f.write(params['hostname'].value) - user = 'admin' - if self.admin_user_exists(): - user = 'web-admin' - command = ['sshcommand', 'acl-add', 'dokku', user] - for key in params['keys'].value.split("\n"): + for (index, key) in enumerate(params['keys'].value.splitlines(), 1): + user = 'admin' + if self.admin_user_exists() is not None: + user = 'web-admin' + if self.web_admin_user_exists() is not None: + index = int(self.web_admin_user_exists()) + 1 + elif self.web_admin_user_exists() is None: + index = 1 + elif self.admin_user_exists() is None: + pass + else: + index = int(self.admin_user_exists()) + 1 + user = user + str(index) + command = ['sshcommand', 'acl-add', 'dokku', user] proc = subprocess.Popen(command, stdin=subprocess.PIPE) proc.stdin.write(key) proc.stdin.close() @@ -123,15 +132,28 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.end_headers() self.wfile.write(json.dumps({'status': 'ok'})) + def web_admin_user_exists(self): + return self.user_exists('web-admin(\d)') + def admin_user_exists(self): - command = 'dokku ssh-keys:list' - pattern = re.compile(r'NAME="admin"') - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) - for line in proc.stdout: - if pattern.search(line): - return True - else: - return False + return self.user_exists('admin(\d)') + + def user_exists(self, name): + command = 'dokku ssh-keys:list' + pattern = re.compile(r'NAME="' + name + '"') + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + max_num = 0 + exists = False + for line in proc.stdout: + m = pattern.search(line) + if m: + # User of the form `user` or `user#` exists + exists = True + max_num = max(max_num, m.group(1)) + if exists: + return max_num + else: + return None def set_debconf_selection(debconf_type, key, value): From 48b3dffecb8e4c194d23eab45aeefdd2f0187df3 Mon Sep 17 00:00:00 2001 From: Mriyam Tamuli Date: Thu, 13 Oct 2016 15:55:59 +0530 Subject: [PATCH 3/4] Proper usernames --- contrib/dokku-installer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py index 9634951dc..0e103d010 100755 --- a/contrib/dokku-installer.py +++ b/contrib/dokku-installer.py @@ -133,10 +133,10 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.wfile.write(json.dumps({'status': 'ok'})) def web_admin_user_exists(self): - return self.user_exists('web-admin(\d)') + return self.user_exists('web-admin(\d+)') def admin_user_exists(self): - return self.user_exists('admin(\d)') + return self.user_exists('admin(\d+)') def user_exists(self, name): command = 'dokku ssh-keys:list' From 10bb4900c031cfbece8f9f71ce7e8307a0874a68 Mon Sep 17 00:00:00 2001 From: Mriyam Tamuli Date: Thu, 13 Oct 2016 19:13:29 +0530 Subject: [PATCH 4/4] Correct indentation --- contrib/dokku-installer.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py index 0e103d010..9c897fc70 100755 --- a/contrib/dokku-installer.py +++ b/contrib/dokku-installer.py @@ -133,27 +133,27 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.wfile.write(json.dumps({'status': 'ok'})) def web_admin_user_exists(self): - return self.user_exists('web-admin(\d+)') + return self.user_exists('web-admin(\d+)') def admin_user_exists(self): - return self.user_exists('admin(\d+)') + return self.user_exists('admin(\d+)') def user_exists(self, name): - command = 'dokku ssh-keys:list' - pattern = re.compile(r'NAME="' + name + '"') - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) - max_num = 0 - exists = False - for line in proc.stdout: - m = pattern.search(line) - if m: - # User of the form `user` or `user#` exists - exists = True - max_num = max(max_num, m.group(1)) - if exists: - return max_num - else: - return None + command = 'dokku ssh-keys:list' + pattern = re.compile(r'NAME="' + name + '"') + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + max_num = 0 + exists = False + for line in proc.stdout: + m = pattern.search(line) + if m: + # User of the form `user` or `user#` exists + exists = True + max_num = max(max_num, m.group(1)) + if exists: + return max_num + else: + return None def set_debconf_selection(debconf_type, key, value):