'Search shared files from a file name (either a string or a
regexp), only from scripts using the "ls" NSE module.'

@classmethod
def searchfile(cls, fname=None, scripts=None):

    if (fname is None):
        req = Script.data.op('@>')('{"ls":    {"volumes":    [{"files":    []}]}}')
    elif isinstance(fname, utils.REGEXP_T):
        base1 = select([Script.port, func.jsonb_array_elements(func.jsonb_array_elements(Script.data['ls']['volumes']).op('->')('files')).op('->>')('filename').label('filename')]).where(Script.data.op('@>')('{"ls":    {"volumes":    [{"files":    []}]}}')).cte('base1')
        base2 = select([column('port')]).select_from(base1).where(column('filename').op(('~*' if (fname.flags & re.IGNORECASE) else '~'))(fname.pattern)).cte('base2')
        return NmapFilter(port=[(True, Port.id.in_(base2))])
    else:
        req = Script.data.op('@>')(json.dumps({'ls': {'volumes': [{'files': [{'filename': fname}]}]}}))
    if (scripts is None):
        return NmapFilter(script=[req])
    if isinstance(scripts, basestring):
        scripts = [scripts]
    if (len(scripts) == 1):
        return NmapFilter(script=[and_((Script.name == scripts.pop()), req)])
    return NmapFilter(script=[and_(Script.name.in_(scripts), req)])
