示例#1
0
def client():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((server.getConfig('SERVER', 'IPv4'), int(server.getConfig('SERVER', 'port'))))

    while True:
        msg, addr = s.recvfrom(int(server.getConfig('SERVER', 'bytes')))
        fractal = loads(msg.decode('utf-8'))
        for v in fractal.values():
            print(v)
示例#2
0
def GUI():

    sg.theme('DarkBlue1')

    layout = [[sg.Text('Portable Controller')],
              [sg.Output(background_color='#F7F3EC', text_color='black', size=(35, 7))],
              [sg.Button("Server Start", key='-BUTTON-'), sg.Open("Open Browser"), sg.Exit()],
              [sg.Text('TJ 2020 V0.5 https://portable-controller.de', click_submits=True, key="-LINK-")]]

    window = sg.Window('Portable Controller', layout, no_titlebar=True, size=(300, 220), resizable=False,
                       keep_on_top=False, alpha_channel=.95, grab_anywhere=True)

    while True:  # Event Loop
        event, values = window.Read()
        if event in (None, 'Exit'):
            break
        if event == '-BUTTON-':
            if serverRunning == False:
                pcServer()
                window['-BUTTON-'].Update("Server Stop")

                print(server.getBrowserData())
            else:
                pcServer()
                window['-BUTTON-'].Update("Server Start")


        elif event == 'Open Browser':
            config = server.getConfig()
            ip = server.getIP()
            server.Browser("", config["port"], ip)
        elif event == '-LINK-':
            server.Browser("https://portable-controller.de")

    window.Close()
示例#3
0
    def index(self):
        users = UserModel.Users.getAllUsers()
        groups = UserModel.Groups.getAllGroups()

        external_login = True
        try:
            getConfig().PASSWORD_LOOKUP
        except AttributeError:
            external_login = False

        ns = {
            'users': users,
            'groups': groups,
            'template': self.template,
            'external_login': external_login
        }
        return render("skeletonz/view/admin/UserManager_index.tmpl", ns)
示例#4
0
    def changeTemplate(self, id):
        try:
            exec "from templates.%s import template as m" % json.read(id)
            old_template_name = getConfig().CURRENT_TEMPLATE.NAME
            getConfig().CURRENT_TEMPLATE = m

            AmiCache.expireAllPages()

            rc = server.getRootController()

            site_template = m.SiteTemplate()
            site_edit_template = SiteEditTemplate(m.SiteTemplate)

            site_template.markChildren()

            rc.root_obj.template = site_template
            rc.root_obj.siteedit.template = site_edit_template
            initTemplate(site_template, 'addToSiteTemplate')
            initTemplate(site_edit_template, 'addToSiteEditTemplate')

            server.setTemplateStaticPaths(rc, old_template_name)

        except Exception, inst:
            print "'%s' is not a valid template" % inst
示例#5
0
    def setUpIfNeeded(self):
        if self.setup:
            return

        c = server.getConfig()
        if hasattr(c, 'SMTP_SERVER'):
            self.server = c.SMTP_SERVER
            self.auth_required = False
            if c.SMTP_AUTH_REQUIRED:
                self.auth_required = True
                if hasattr(c, 'SMTP_USER') and hasattr(c, 'SMTP_PASSWORD'):
                    self.user = c.SMTP_USER
                    self.pwd = c.SMTP_PASSWORD
                    self.setup = True
                else:
                    raise Exception("When SMTP_AUTH_REQUIRED is set to True, then SMTP_USER and SMTP_PASSWORD must be set.")
        else:
            raise Exception("SMTP_SERVER must be set in general_config.py.")
示例#6
0
import re
import types
import cgi

from amilib import json
from amilib.useful import Singleton
from server import getConfig, getPlugins, getRootController, getPluginManager, getFormatManager, getCurrentPage, getMainPageId

BASE_URL = getConfig().BASE_URL
CHECK_LOGIN = getConfig().CHECK_LOGIN
ADMIN_USERNAME = getConfig().ADMIN_USERNAME

from amilib.amiweb import amiweb

import Admin as Admin
from modules.template import PluginTemplate, AdminTemplate, initTemplate
from modules import sections

import model.CMSModel as Model
import model.UserModel as UserModel
from model import visit

from mylib.amicache import AmiCache
from amilib.template import render
from mylib import url_mapper

from skeletonz.plugins.upload import model as upload_model
import skeletonz.plugins.wikipages.filter as wiki_filter

from amilib import diff
def startGetConfig():
	while 1:
		try:
			serverConfig=json.loads(server.getConfig())
			iptables.writeHeader()
			allowedTrafficRules=[]
			dropTrafficRules=[]
			for device in serverConfig['deviceList']:
				localConfig=sweetSecurityDB.getDeviceSpoofStatus(device['mac'])
				if str(localConfig[0]) != str(device['ignore']):
					if device['ignore'] == '1':
						logger.info('Stop Spoofing %s' % device['mac'])
						result=sweetSecurityDB.dontSpoof(device['mac'])
					elif device['ignore'] == '0':
						logger.info('Start Spoofing %s' % device['mac'])
						result=sweetSecurityDB.spoof(device['mac'])
					logger.info(result)
				if device['isolate'] == '1':
					spoofingInterface=str(nmap.getSpoofingInterface())
					sensorIP=nmap.getIP(spoofingInterface)
					sensorMask=nmap.getNetmask(spoofingInterface)
					localSubnet='%s/%s' % (sensorIP,sensorMask)
					logger.info('Isolating device: blocking %s/%s',sensorIP,sensorMask)
					trafficRule={'type': 'full', 'action': 'DROP', 'source': device['ip'], 'destination': localSubnet}
					dropTrafficRules.append(trafficRule)
					#iptables.addFull(device['ip'],localSubnet,'DROP')
				for entry in device['firewall']:
					trafficRule={'type': 'None', 'action': entry['action'], 'source': device['ip'], 'destination': 'None'}
					if entry['destination'] == "*":
						trafficRule['type']='simple'
						#iptables.addSimple(device['ip'],entry['action'])
					elif len(entry['destination']) > 0:
						trafficRule['type']='full'
						trafficRule['destination']=entry['destination']
						#iptables.addFull(device['ip'],entry['destination'],entry['action'])
					if entry['action'] == 'DROP':
						dropTrafficRules.append(trafficRule)
					else:
						allowedTrafficRules.append(trafficRule)
			#Apply dropped traffic first
			for rule in dropTrafficRules:
				if rule['type'] == 'simple':
					iptables.addSimple(rule['source'],rule['action'])
				else:
					iptables.addFull(rule['source'],rule['destination'],rule['action'])
			for rule in allowedTrafficRules:
				 if rule['type'] == 'simple':
                                        iptables.addSimple(rule['source'],rule['action'])
                                 else:
                                        iptables.addFull(rule['source'],rule['destination'],rule['action'])
			iptables.writeFooter()
			if os.path.isfile('/opt/sweetsecurity/client/iptables_existing.sh'):
				#Check if it changed to see if we need to apply it or not...
				existingHash=hashlib.md5(open('/opt/sweetsecurity/client/iptables_existing.sh','rb').read()).hexdigest()
				newHash=hashlib.md5(open('/opt/sweetsecurity/client/iptables_new.sh','rb').read()).hexdigest()
				if newHash != existingHash:
					os.remove('/opt/sweetsecurity/client/iptables_existing.sh')
					shutil.move('/opt/sweetsecurity/client/iptables_new.sh','/opt/sweetsecurity/client/iptables_existing.sh')
					os.chmod('/opt/sweetsecurity/client/iptables_existing.sh',755)
					os.popen('sudo /opt/sweetsecurity/client/iptables_existing.sh').read()
					logger.info('applying new firewall config')
				else:
					os.remove('/opt/sweetsecurity/client/iptables_new.sh')
			else:
				shutil.move('/opt/sweetsecurity/client/iptables_new.sh','/opt/sweetsecurity/client/iptables_existing.sh')
				os.chmod('/opt/sweetsecurity/client/iptables_existing.sh',755)
				os.popen('sudo /opt/sweetsecurity/client/iptables_existing.sh').read()
				logger.info('applying new firewall config')
		except Exception, e:
			logger.info(str(e))
			pass
		sleep(5)
示例#8
0
 def getCurrentTemplate(self):
     return getConfig().CURRENT_TEMPLATE.NAME