예제 #1
0
def undoAnnounce(session,baseDir: str,federationList: [], \
                 nickname: str, domain: str, port: int, \
                 toUrl: str, ccUrl: str, httpPrefix: str, \
                 objectUrl: str, saveToFile: bool, \
                 clientToServer: bool, \
                 sendThreads: [],postLog: [], \
                 personCache: {},cachedWebfingers: {}, \
                 debug: bool) -> {}:
    """Undoes an announce message
    Typically toUrl will be https://www.w3.org/ns/activitystreams#Public
    and ccUrl might be a specific person whose post was repeated and the
    objectUrl is typically the url of the message which was repeated,
    corresponding to url or atomUri in createPostBase
    """
    if not urlPermitted(objectUrl,federationList,"inbox:write"):
        return None

    if ':' in domain:
        domain=domain.split(':')[0]
    fullDomain=domain
    if port:
        if port!=80 and port!=443:
            if ':' not in domain:
                fullDomain=domain+':'+str(port)

    newUndoAnnounce = {
        "@context": "https://www.w3.org/ns/activitystreams",
        'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname,
        'type': 'Undo',
        'cc': [],
        'to': [toUrl],
        'object': {
            'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname,
            'cc': [],
            'object': objectUrl,
            'to': [toUrl],
            'type': 'Announce'
        }
    }
    if ccUrl:
        if len(ccUrl)>0:
            newUndoAnnounce['object']['cc']=[ccUrl]

    announceNickname=None
    announceDomain=None
    announcePort=None
    if '/users/' in objectUrl or '/profile/' in objectUrl:
        announceNickname=getNicknameFromActor(objectUrl)
        announceDomain,announcePort=getDomainFromActor(objectUrl)

    if announceNickname and announceDomain:
        sendSignedJson(newUndoAnnounce,session,baseDir, \
                       nickname,domain,port, \
                       announceNickname,announceDomain,announcePort, \
                       'https://www.w3.org/ns/activitystreams#Public', \
                       httpPrefix,True,clientToServer,federationList, \
                       sendThreads,postLog,cachedWebfingers,personCache,debug)
            
    return newUndoAnnounce
예제 #2
0
def sendFollowRequest(session,baseDir: str, \
                      nickname: str,domain: str,port: int,httpPrefix: str, \
                      followNickname: str,followDomain: str, \
                      followPort: int,followHttpPrefix: str, \
                      clientToServer: bool,federationList: [], \
                      sendThreads: [],postLog: [],cachedWebfingers: {}, \
                      personCache: {},debug : bool, \
                      projectVersion: str) -> {}:
    """Gets the json object for sending a follow request
    """    
    if not domainPermitted(followDomain,federationList):
        return None

    fullDomain=domain
    followActor=httpPrefix+'://'+domain+'/users/'+nickname
    if port:
        if port!=80 and port!=443:
            if ':' not in domain:
                fullDomain=domain+':'+str(port)
                followActor=httpPrefix+'://'+domain+':'+str(port)+'/users/'+nickname

    requestDomain=followDomain
    if followPort:
        if followPort!=80 and followPort!=443:
            if ':' not in followDomain:
                requestDomain=followDomain+':'+str(followPort)

    statusNumber,published = getStatusNumber()
    
    followedId=followHttpPrefix+'://'+requestDomain+'/users/'+followNickname

    newFollowJson = {
        '@context': 'https://www.w3.org/ns/activitystreams',
        'id': followActor+'/statuses/'+str(statusNumber),
        'type': 'Follow',
        'actor': followActor,
        'object': followedId
    }

    sendSignedJson(newFollowJson,session,baseDir,nickname,domain,port, \
                   followNickname,followDomain,followPort, \
                   'https://www.w3.org/ns/activitystreams#Public', \
                   httpPrefix,True,clientToServer, \
                   federationList, \
                   sendThreads,postLog,cachedWebfingers,personCache, \
                   debug,projectVersion)

    return newFollowJson
예제 #3
0
def followedAccountRejects(session,baseDir: str,httpPrefix: str, \
                           nicknameToFollow: str,domainToFollow: str,port: int, \
                           nickname: str,domain: str,fromPort: int, \
                           personUrl: str,federationList: [], \
                           followJson: {}, \
                           sendThreads: [],postLog: [], \
                           cachedWebfingers: {},personCache: {}, \
                           debug: bool,projectVersion: str):
    """The person receiving a follow request rejects the new follower
    and sends back a Reject activity
    """
    # send reject back
    if debug:
        print('DEBUG: sending Reject activity for follow request which arrived at '+ \
              nicknameToFollow+'@'+domainToFollow+' back to '+nickname+'@'+domain)
    rejectJson=createReject(baseDir,federationList, \
                            nicknameToFollow,domainToFollow,port, \
                            personUrl,'',httpPrefix,followJson)
    if debug:
        pprint(rejectJson)
        print('DEBUG: sending follow Reject from '+ \
              nicknameToFollow+'@'+domainToFollow+ \
              ' port '+str(port)+' to '+ \
              nickname+'@'+domain+' port '+ str(fromPort))
    clientToServer=False
    return sendSignedJson(rejectJson,session,baseDir, \
                          nicknameToFollow,domainToFollow,port, \
                          nickname,domain,fromPort, '', \
                          httpPrefix,True,clientToServer, \
                          federationList, \
                          sendThreads,postLog,cachedWebfingers, \
                          personCache,debug,projectVersion)
예제 #4
0
파일: delete.py 프로젝트: miklobit/epicyon
def createDelete(session,baseDir: str,federationList: [], \
                 nickname: str, domain: str, port: int, \
                 toUrl: str, ccUrl: str, httpPrefix: str, \
                 objectUrl: str,clientToServer: bool, \
                 sendThreads: [],postLog: [], \
                 personCache: {},cachedWebfingers: {}, \
                 debug: bool) -> {}:
    """Creates a delete message
    Typically toUrl will be https://www.w3.org/ns/activitystreams#Public
    and ccUrl might be a specific person whose post is to be deleted
    objectUrl is typically the url of the message, corresponding to url
    or atomUri in createPostBase
    """
    if not urlPermitted(objectUrl, federationList, "inbox:write"):
        return None

    if ':' in domain:
        domain = domain.split(':')[0]
        fullDomain = domain
    if port:
        if port != 80 and port != 443:
            if ':' not in domain:
                fullDomain = domain + ':' + str(port)

    statusNumber, published = getStatusNumber()
    newDeleteId= \
        httpPrefix+'://'+fullDomain+'/users/'+nickname+'/statuses/'+statusNumber
    newDelete = {
        "@context":
        "https://www.w3.org/ns/activitystreams",
        'actor':
        httpPrefix + '://' + fullDomain + '/users/' + nickname,
        'atomUri':
        httpPrefix + '://' + fullDomain + '/users/' + nickname + '/statuses/' +
        statusNumber,
        'cc': [],
        'id':
        newDeleteId + '/activity',
        'object':
        objectUrl,
        'published':
        published,
        'to': [toUrl],
        'type':
        'Delete'
    }
    if ccUrl:
        if len(ccUrl) > 0:
            newDelete['cc'] = [ccUrl]

    deleteNickname = None
    deleteDomain = None
    deletePort = None
    if '/users/' in objectUrl or '/profile/' in objectUrl:
        deleteNickname = getNicknameFromActor(objectUrl)
        deleteDomain, deletePort = getDomainFromActor(objectUrl)

    if deleteNickname and deleteDomain:
        sendSignedJson(newDelete,session,baseDir, \
                       nickname,domain,port, \
                       deleteNickname,deleteDomain,deletePort, \
                       'https://www.w3.org/ns/activitystreams#Public', \
                       httpPrefix,True,clientToServer,federationList, \
                       sendThreads,postLog,cachedWebfingers,personCache,debug)

    return newDelete
예제 #5
0
def createAnnounce(session,baseDir: str,federationList: [], \
                   nickname: str, domain: str, port: int, \
                   toUrl: str, ccUrl: str, httpPrefix: str, \
                   objectUrl: str, saveToFile: bool, \
                   clientToServer: bool, \
                   sendThreads: [],postLog: [], \
                   personCache: {},cachedWebfingers: {}, \
                   debug: bool,projectVersion: str) -> {}:
    """Creates an announce message
    Typically toUrl will be https://www.w3.org/ns/activitystreams#Public
    and ccUrl might be a specific person favorited or repeated and the
    followers url objectUrl is typically the url of the message,
    corresponding to url or atomUri in createPostBase
    """
    if not urlPermitted(objectUrl,federationList,"inbox:write"):
        return None

    if ':' in domain:
        domain=domain.split(':')[0]
    fullDomain=domain
    if port:
        if port!=80 and port!=443:
            if ':' not in domain:
                fullDomain=domain+':'+str(port)

    statusNumber,published = getStatusNumber()
    newAnnounceId= \
        httpPrefix+'://'+fullDomain+'/users/'+nickname+'/statuses/'+statusNumber
    newAnnounce = {
        "@context": "https://www.w3.org/ns/activitystreams",
        'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname,
        'atomUri': httpPrefix+'://'+fullDomain+'/users/'+nickname+'/statuses/'+statusNumber,
        'cc': [],
        'id': newAnnounceId+'/activity',
        'object': objectUrl,
        'published': published,
        'to': [toUrl],
        'type': 'Announce'
    }
    if ccUrl:
        if len(ccUrl)>0:
            newAnnounce['cc']=[ccUrl]
    if saveToFile:
        outboxDir = createOutboxDir(nickname,domain,baseDir)
        filename=outboxDir+'/'+newAnnounceId.replace('/','#')+'.json'
        with open(filename, 'w') as fp:
            commentjson.dump(newAnnounce, fp, indent=4, sort_keys=False)

    announceNickname=None
    announceDomain=None
    announcePort=None
    if '/users/' in objectUrl or '/profile/' in objectUrl:
        announceNickname=getNicknameFromActor(objectUrl)
        announceDomain,announcePort=getDomainFromActor(objectUrl)

    if announceNickname and announceDomain:
        sendSignedJson(newAnnounce,session,baseDir, \
                       nickname,domain,port, \
                       announceNickname,announceDomain,announcePort, \
                       'https://www.w3.org/ns/activitystreams#Public', \
                       httpPrefix,True,clientToServer,federationList, \
                       sendThreads,postLog,cachedWebfingers,personCache, \
                       debug,projectVersion)
            
    return newAnnounce