@@ -542,16 +542,15 @@ def configure_ipsec(self, obj):
542542 logging .info ("Configured vpn %s %s" , leftpeer , rightpeer )
543543 CsHelper .execute ("ipsec rereadsecrets" )
544544
545+ # This will load the new config and start the connection when needed since auto=start in the config
545546 CsHelper .execute ("ipsec reload" )
546- if not obj ['passive' ]:
547- CsHelper .execute ("sudo nohup ipsec down vpn-%s" % rightpeer )
548- CsHelper .execute ("sudo nohup ipsec up vpn-%s &" % rightpeer )
549547 os .chmod (vpnsecretsfile , 0400 )
550548
551549 def convert_sec_to_h (self , val ):
552550 hrs = int (val ) / 3600
553551 return "%sh" % hrs
554552
553+
555554class CsVpnUser (CsDataBag ):
556555 PPP_CHAP = '/etc/ppp/chap-secrets'
557556
@@ -570,42 +569,37 @@ def add_l2tp_ipsec_user(self, user, obj):
570569 userfound = False
571570 password = obj ['password' ]
572571
573- userSearchEntry = "%s \* %s \*" % (user ,password )
574572 userAddEntry = "%s * %s *" % (user ,password )
575- logging .debug ("Adding vpn user %s " % userSearchEntry )
573+ logging .debug ("Adding vpn user '%s' " % user )
576574
577575 file = CsFile (self .PPP_CHAP )
578- userfound = file .searchString (userSearchEntry , '#' )
576+ userfound = file .searchString (userAddEntry , '#' )
579577 if not userfound :
580- logging .debug ("User is not there already, so adding user " )
578+ logging .debug ("User is not there already, so adding user" )
581579 self .del_l2tp_ipsec_user (user , obj )
582580 file .add (userAddEntry )
583581 file .commit ()
584582
585-
586583 def del_l2tp_ipsec_user (self , user , obj ):
587584 userfound = False
588585 password = obj ['password' ]
589- userentry = "%s \ * %s \*" % (user ,password )
586+ userentry = "%s * %s *" % (user ,password )
590587
591- logging .debug ("Deleting the user %s " % user )
588+ logging .debug ("Deleting the user '%s' " % user )
592589 file = CsFile (self .PPP_CHAP )
593590 file .deleteLine (userentry )
594591 file .commit ()
595592
596593 if not os .path .exists ('/var/run/pppd2.tdb' ):
597594 return
598595
599- logging .debug ("kiing the PPPD process for the user %s " % user )
596+ logging .debug ("killing the PPPD process for the user '%s' " % user )
600597
601598 fileContents = CsHelper .execute ("tdbdump /var/run/pppd2.tdb" )
602- print fileContents
603-
604599 for line in fileContents :
605600 if user in line :
606601 contentlist = line .split (';' )
607602 for str in contentlist :
608- print 'in del_l2tp str = ' + str
609603 pppd = str .split ('=' )[0 ]
610604 if pppd == 'PPPD_PID' :
611605 pid = str .split ('=' )[1 ]
@@ -614,7 +608,6 @@ def del_l2tp_ipsec_user(self, user, obj):
614608 CsHelper .execute ('kill -9 %s' % pid )
615609
616610
617-
618611class CsRemoteAccessVpn (CsDataBag ):
619612 VPNCONFDIR = "/etc/ipsec.d"
620613
@@ -635,9 +628,7 @@ def process(self):
635628 logging .debug ("Remote accessvpn data bag %s" , self .dbag )
636629 self .remoteaccessvpn_iptables (public_ip , self .dbag [public_ip ])
637630
638- CsHelper .execute ("ipsec down L2TP-PSK" )
639631 CsHelper .execute ("ipsec update" )
640- CsHelper .execute ("service xl2tpd stop" )
641632 CsHelper .execute ("service xl2tpd start" )
642633 CsHelper .execute ("ipsec rereadsecrets" )
643634 else :
0 commit comments