29
29
import time
30
30
import re
31
31
import boto3
32
+ import datetime
32
33
from plogical .childDomain import ChildDomainManager
33
34
from math import ceil
34
35
from plogical .alias import AliasManager
@@ -549,16 +550,33 @@ def AutoLogin(self, request=None, userID=None):
549
550
550
551
if (Status == 1 ) or ProcessUtilities .decideServer () == ProcessUtilities .ent :
551
552
552
- ## Get title
553
+ # list existing administrators
554
+
555
+ command = f'sudo -u %s { FinalPHPPath } /usr/bin/wp user list --role=administrator --format=json --path=%s --skip-plugins --skip-themes' % (
556
+ WPobj .owner .externalApp , WPobj .path )
557
+ result = ProcessUtilities .outputExecutioner (command )
558
+ existing_admins = json .loads (result )
559
+
560
+ # Extract username and registration date
561
+ for admin in existing_admins :
562
+ username = admin ['user_login' ]
563
+ if 'autologin' in username :
564
+ reg_date = admin ['user_registered' ]
565
+ # if user was registered more than 2 days ago, delete it
566
+ if (datetime .datetime .now () - datetime .datetime .strptime (reg_date , '%Y-%m-%d %H:%M:%S' )).days > 2 :
567
+ command = f'sudo -u %s { FinalPHPPath } /usr/bin/wp user delete %s --path=%s --skip-plugins --skip-themes' % (
568
+ WPobj .owner .externalApp , username , WPobj .path )
569
+ ProcessUtilities .executioner (command )
553
570
554
571
password = randomPassword .generate_pass (10 )
572
+ username = 'autologin' + str (randint (10000 , 99999 ))
555
573
556
- command = f'sudo -u %s { FinalPHPPath } /usr/bin/wp user create autologin %s --role=administrator --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (
557
- WPobj .owner .externalApp , 'autologin@cloudpages.cloud' , password , WPobj .path )
574
+ command = f'sudo -u %s { FinalPHPPath } /usr/bin/wp user create %s %s@a.local --role=administrator --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (
575
+ WPobj .owner .externalApp , username , username , password , WPobj .path )
558
576
ProcessUtilities .executioner (command )
559
577
560
- command = f'sudo -u %s { FinalPHPPath } /usr/bin/wp user update autologin --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (
561
- WPobj .owner .externalApp , password , WPobj .path )
578
+ command = f'sudo -u %s { FinalPHPPath } /usr/bin/wp user update %s --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (
579
+ WPobj .owner .externalApp , username , password , WPobj .path )
562
580
ProcessUtilities .executioner (command )
563
581
564
582
data = {}
@@ -569,7 +587,7 @@ def AutoLogin(self, request=None, userID=None):
569
587
FinalURL = WPobj .FinalURL
570
588
571
589
data ['url' ] = 'https://%s' % (FinalURL )
572
- data ['userName' ] = 'autologin'
590
+ data ['userName' ] = username
573
591
data ['password' ] = password
574
592
575
593
proc = httpProc (request , 'websiteFunctions/AutoLogin.html' ,
0 commit comments