2019-01-26 01:57:24 +00:00
import main
from core . bot import deliverRelayCommands
from utils . logging . log import *
2019-08-25 20:29:11 +00:00
def provisionUserData ( num , nick , altnick , ident , realname , unused ) : # last field is password, which we don't want to inherit here, but still want to use * expansion, so this is a bit of a hack
2019-01-26 01:57:24 +00:00
commands = { }
commands [ " controlpanel " ] = [ ]
2019-08-25 20:29:11 +00:00
commands [ " controlpanel " ] . append ( " AddUser %s %s " % ( nick , main . config [ " Relay " ] [ " Password " ] ) )
commands [ " controlpanel " ] . append ( " Set Nick %s %s " % ( nick , nick ) )
commands [ " controlpanel " ] . append ( " Set Altnick %s %s " % ( nick , altnick ) )
commands [ " controlpanel " ] . append ( " Set Ident %s %s " % ( nick , ident ) )
commands [ " controlpanel " ] . append ( " Set RealName %s %s " % ( nick , realname ) )
deliverRelayCommands ( num , commands )
2019-01-26 01:57:24 +00:00
return
2019-08-25 20:29:11 +00:00
def provisionNetworkData ( num , nick , network , host , port , security , auth , password ) :
2019-01-26 01:57:24 +00:00
commands = { }
stage2commands = { }
2019-03-16 17:05:16 +00:00
stage3commands = { }
2019-01-26 01:57:24 +00:00
commands [ " controlpanel " ] = [ ]
2019-08-25 20:29:11 +00:00
commands [ " controlpanel " ] . append ( " AddNetwork %s %s " % ( nick , network ) )
2019-01-26 01:57:24 +00:00
if security == " ssl " :
2019-08-25 20:29:11 +00:00
commands [ " controlpanel " ] . append ( " SetNetwork TrustAllCerts %s %s true " % ( nick , network ) ) # Don't judge me
commands [ " controlpanel " ] . append ( " AddServer %s %s %s + %s " % ( nick , network , host , port ) )
2019-01-26 01:57:24 +00:00
elif security == " plain " :
2019-08-25 20:29:11 +00:00
commands [ " controlpanel " ] . append ( " AddServer %s %s %s %s " % ( nick , network , host , port ) )
2019-01-26 01:57:24 +00:00
if auth == " sasl " :
stage2commands [ " status " ] = [ ]
stage2commands [ " sasl " ] = [ ]
stage2commands [ " status " ] . append ( " LoadMod sasl " )
stage2commands [ " sasl " ] . append ( " Mechanism plain " )
2019-08-25 20:29:11 +00:00
stage2commands [ " sasl " ] . append ( " Set %s %s " % ( nick , password ) )
2019-01-26 01:57:24 +00:00
elif auth == " ns " :
stage2commands [ " status " ] = [ ]
stage2commands [ " nickserv " ] = [ ]
2019-08-15 20:20:49 +00:00
stage2commands [ " status " ] . append ( " LoadMod nickserv " )
2019-01-26 01:57:24 +00:00
stage2commands [ " nickserv " ] . append ( " Set %s " % password )
2019-03-16 17:05:16 +00:00
if not main . config [ " ConnectOnCreate " ] :
stage3commands [ " status " ] = [ ]
stage3commands [ " status " ] . append ( " Disconnect " )
2019-08-11 19:52:10 +00:00
if main . config [ " Toggles " ] [ " CycleChans " ] :
stage2commands [ " status " ] = [ ]
stage2commands [ " status " ] . append ( " LoadMod disconkick " )
2019-08-15 20:20:49 +00:00
stage2commands [ " status " ] . append ( " LoadMod chansaver " )
2019-08-25 20:29:11 +00:00
deliverRelayCommands ( num , commands ,
stage2 = [ [ nick + " / " + network , stage2commands ] ,
[ nick + " / " + network , stage3commands ] ] )
2019-01-26 01:57:24 +00:00
return
2019-08-25 20:29:11 +00:00
def provisionRelayForNetwork ( num , alias , network ) :
provisionNetworkData ( num , alias , network ,
main . network [ network ] . host ,
main . network [ network ] . port ,
main . network [ network ] . security ,
main . network [ network ] . auth ,
main . network [ network ] . aliases [ num ] [ " password " ] )
return
2019-02-01 23:26:01 +00:00
2019-08-25 20:29:11 +00:00
def provisionRelay ( num , network ) :
2019-09-29 21:45:16 +00:00
aliasObj = main . alias [ num ]
2019-08-25 20:29:11 +00:00
alias = aliasObj [ " nick " ]
provisionUserData ( num , * aliasObj . values ( ) )
provisionRelayForNetwork ( num , alias , network )
2019-09-29 21:45:16 +00:00
if main . config [ " ConnectOnCreate " ] :
main . network [ network ] . start_bot ( num )
2019-08-25 20:29:11 +00:00
return alias