'set [opt [= <val>]]
Set a configuration variable in SpiderFoot.'

def do_set(self, line):

    c = self.myparseline(line, replace=False)
    cfg = None
    val = None
    if (len(c[0]) > 0):
        cfg = c[0][0]
    if (len(c[0]) > 2):
        try:
            val = c[0][2]
        except BaseException as e:
            self.edprint('Invalid    syntax.')
            return
    d = self.request((self.ownopts['cli.server_baseurl'] + '/optsraw'))
    if (not d):
        return
    j = list()
    serverconfig = dict()
    token = ''
    if (not d):
        self.edprint('Unable    to    obtain    SpiderFoot    server-side    config.')
    else:
        j = json.loads(d)
        if (j[0] == 'ERROR'):
            self.edprint('Error    fetching    SpiderFoot    server-side    config.')
            return
        else:
            serverconfig = j[1]['data']
            token = j[1]['token']
    self.ddprint(str(serverconfig))
    if ((not cfg) or (not val)):
        ks = self.ownopts.keys()
        ks.sort()
        output = list()
        for k in ks:
            c = self.ownopts[k]
            if (type(c) == bool):
                if c:
                    c = 'True'
                else:
                    c = 'False'
            if (not cfg):
                output.append({'opt': k, 'val': c})
            elif (cfg == k):
                self.dprint(((k + '    =    ') + c), plain=True)
        for k in sorted(serverconfig.keys()):
            if (type(serverconfig[k]) == list):
                serverconfig[k] = ','.join(serverconfig[k])
            if (not cfg):
                output.append({'opt': k, 'val': str(serverconfig[k])})
            elif (cfg == k):
                self.dprint(((k + '    =    ') + str(serverconfig[k])), plain=True)
        if (len(output) > 0):
            self.send_output(json.dumps(output), line, {'opt': 'Option', 'val': 'Value'}, total=False)
        return
    if val:
        if ((cfg in self.ownopts) or cfg.startswith('$')):
            if (not cfg.startswith('$')):
                if (type(self.ownopts[cfg]) == bool):
                    if ((val.lower() == 'false') or (val == '0')):
                        val = False
                    else:
                        val = True
            self.ownopts[cfg] = val
            self.dprint(((cfg + '    set    to    ') + str(val)))
            return
        else:
            confdata = dict()
            found = False
            for k in serverconfig:
                if (k == cfg):
                    serverconfig[k] = val
                    found = True
            if (not found):
                self.edprint('Variable    not    found,    so    not    set.')
                return
            for k in serverconfig:
                optstr = ':'.join(k.split('.')[1:])
                if (type(serverconfig[k]) == bool):
                    if (not serverconfig[k]):
                        confdata[optstr] = '0'
                    else:
                        confdata[optstr] = '1'
                if (type(serverconfig[k]) == list):
                    confdata[optstr] = ','.join(serverconfig[k])
                if (type(serverconfig[k]) == int):
                    confdata[optstr] = str(serverconfig[k])
                if (type(serverconfig[k]) in [str, unicode]):
                    confdata[optstr] = serverconfig[k]
            self.ddprint(str(confdata))
            d = self.request((self.ownopts['cli.server_baseurl'] + '/savesettingsraw'), post={'token': token, 'allopts': json.dumps(confdata)})
            j = list()
            if (not d):
                self.edprint('Unable    to    set    SpiderFoot    server-side    config.')
                return
            else:
                j = json.loads(d)
                if (j[0] == 'ERROR'):
                    self.edprint(('Error    setting    SpiderFoot    server-side    config:    ' + str(j[1])))
                    return
                self.dprint(((cfg + '    set    to    ') + str(val)))
                return
    if (cfg not in self.ownopts):
        self.edprint('Variable    not    found,    so    not    set.    Did    you    mean    to    use    a    $    variable?')
        return
