Exemple #1
0
def plugin(srv, item):

    srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__,
                      item.service, item.target)

    apikey = item.addrs[0]
    application = item.addrs[1]

    title = item.get('title', srv.SCRIPTNAME)
    text = item.message
    priority = int(item.get('priority', 0))

    try:
        p = pyprowl.Prowl(apikey)
        p.verify_key()
        srv.logging.info("Prowl API key successfully verified")
    except Exception as e:
        srv.logging.error("Error verifying Prowl API key: {}".format(e))
        return False

    try:
        p.notify(event=title,
                 description=text,
                 priority=priority,
                 url=None,
                 appName=application)
        srv.logging.debug("Sending notification to Prowl succeeded")
    except Exception as e:
        srv.logging.warning("Sending notification to Prowl failed: %s" % e)
        return False

    return True
Exemple #2
0
    def notify_prowl(self,
                     api_key,
                     event,
                     description,
                     priority=0,
                     url=None,
                     app_name="redball"):
        # Send a notification to Prowl
        p = pyprowl.Prowl(apiKey=api_key, appName=app_name)

        self.log.debug(
            f"Sending notification to Prowl with API Key: {api_key}. Event: {event}, Description: {description}, Priority: {priority}, URL: {url}..."
        )
        try:
            p.notify(
                event=event,
                description=description,
                priority=priority,
                url=url,
            )
            self.log.info("Notification successfully sent to Prowl!")
            return True
        except Exception as e:
            self.log.error("Error sending notification to Prowl: {}".format(e))
            return False
Exemple #3
0
    def read_emails(self):
        print("[*] Reading Emails")
        qassaCnt = euroClixCnt = dondinoCnt = bonusBunnyCnt = questlerCnt = 0
        prowlMsg = ""
        for mail_id in self.imapper.listids(limit=100):
            if mail_id in self.read_mails:
                continue
            self.read_mails.append(mail_id)
            mail = self.imapper.mail(mail_id, include_raw=True)
            if "Qassa" in mail.from_addr:
                print("[+] Found new Mail from Qassa")
                try:
                    url = re.search("(?P<url>https?://www.qassa.de/redirect[^\s]+)", mail.body).group("url")
                    get_real_link_r = self.s.get(url, allow_redirects=True)
                    real_url = re.search("(?P<url>https?://www.qassa.de//mailing[^\s]+)", get_real_link_r.content).group("url")
                    get_coins = self.s.get(real_url, allow_redirects=True)
                    print("[+] Visited Url")
                    qassaCnt += 1
                except:
                    print("[-] No Url found")
            if "EuroClix" in mail.from_addr:
                print("[+] Found new Mail from EuroClix")
                try:
                    url = re.search("(?P<url>https://www.euroclix.de/reference[^\s]+)", mail.body).group("url")
                    visit_link = self.s.get(url, allow_redirects=True)
                    print("[+] Visited link")
                    euroClixCnt += 1
                except:
                    print("[-] No Url found]")
            if "dondino" in mail.from_addr.lower():
                print("[+] Found new Mail from DonDino")
                try:
                    url = re.search("(?P<url>http://www.dondino.de/[^\s]+)", mail.body).group("url")
                    visit_link = self.s.get(url, allow_redirects=True)
                    print("[+] Visited link")
                    dondinoCnt += 1
                except:
                    print("[-] No Url found]")
            if "Bonus Bunny" in mail.from_addr:
                print("[+] Found new Mail from Bonus Bunny")
                try:
                    url = re.search("(?P<url>https://www.bonus-bunny.de/pmail.php[^\s]+)", mail.raw).group("url")
                    url = url.replace("\"", "")
                    visit_link = self.s.get(url, allow_redirects=True)
                    print("[+] Visited link")
                    bonusBunnyCnt += 1
                except:
                    print("[-] No Url found]")
            if "Questler.de" in mail.from_addr:
                print("[+] Found new Mail from Questler")
                try:
                    url = re.search("(?P<url>https://www.questler.de/earn/best.php[^\s]+)", mail.body).group("url")
                    visit_link = self.s.get(url, allow_redirects=True)
                    print("[+] Visited link")
                    questlerCnt += 1
                except:
                    print("[-] No Url found]")
        if (qassaCnt > 0):
            prowlMsg += str(qassaCnt) + " qassa|"
        if (euroClixCnt > 0):
            prowlMsg += str(euroClixCnt) + " EuroClix|"
        if (dondinoCnt > 0):
            prowlMsg += str(dondinoCnt) + " dondino|"
        if (bonusBunnyCnt > 0):
            prowlMsg += str(bonusBunnyCnt) + " Bonus Bunny|"
        if (questlerCnt > 0):
            prowlMsg += str(questlerCnt) + " Questler.de|"

        if (len(prowlMsg) > 0):
            print("[+] Confirmed mails: " + prowlMsg[:-1])
            if (len(self.prowl_api_key) > 0):
                try:
                    p = pyprowl.Prowl(self.prowl_api_key)
                    p.notify(event='Confirmed mails', description=prowlMsg[:-1], priority=0, appName='PaidMailBot')
                    print("[+] Notification successfully sent to Prowl!")
                except Exception as e:
                    print("[-] Error sending notification to Prowl: {}".format(e))
            else:
                print("[*] Skip prowl notification")
        else:
            print("[*] No links were confirmed")
        
        sleep = random.randint(0,3600) + 3600
        print("[*] Sleeping " + time.strftime('%H:%M', time.gmtime(sleep)) + " Hour")
        time.sleep(sleep)
        self.connect()
        self.read_emails()
Exemple #4
0
#!/usr/bin/env python
"""
Example usage of pyprowl module
"""

import pyprowl

p = pyprowl.Prowl('YOUR_PROWL_API_KEY')

try:
    p.verify_key()
    print("Prowl API key successfully verified!")
except Exception as e:
    print("Error verifying Prowl API key: {}".format(e))
    exit()

try:
    p.notify(
        event='Event name',
        description='Description of event',
        priority=0,
        url='http://www.example.com',
        #apiKey='uncomment and add API KEY here if different',
        appName='Name of app sending the notification')
    print("Notification successfully sent to Prowl!")
except Exception as e:
    print("Error sending notification to Prowl: {}".format(e))
Exemple #5
0
def monitor(domains):
    """ domains is a list of Domain class objects """
    dh = DreamHost(API_URL, API_KEY)
    currentIp = ""

    global PROWL_API_KEY
    if PROWL_API_KEY != "":
        logger.info("Setting up Prowl notifications...")
        prowl = pyprowl.Prowl(apiKey=PROWL_API_KEY, appName="dh-dhs")
        verifyKey = prowl.verify_key()
        if verifyKey.get("status") == "success":
            logger.info("Prowl API key successfully verified. Notifications enabled!")
        else:
            PROWL_API_KEY = ""
            prowl = None
            logger.error(
                "Unable to verify Prowl API key. Disabling Prowl notifications. Error code: %s %s, message: %s",
                verifyKey.get("status"),
                verifyKey.get("message"),
                verifyKey.get("errMsg"),
            )
    else:
        prowl = None

    while True:  # Enter update loop
        # Pull current domain info from DH
        dhDomainResponse = dh.api_call(
            dh.cmds["list"]
        )  # List all domains from DH account
        if dhDomainResponse.get("result") == "success":
            for data in [
                data for data in dhDomainResponse.get("data") if data.get("type") == "A"
            ]:
                dh.allDomains.update(
                    {
                        data.get("record"): {
                            "value": data.get("value"),
                            "editable": data.get("editable"),
                            "comment": data.get("comment"),
                        }
                    }
                )
            logger.debug("All A records from DreamHost: %s", format(dh.allDomains))
        else:
            logger.error(
                "Error reported by DreamHost API: %s.", dhDomainResponse.get("data")
            )

        newIp = ""
        validIp = False

        # Get current IP
        try:
            newIp = requests.get("https://api.ipify.org").text.strip()
            ipType = IP(newIp).iptype()
            if ipType != "PUBLIC":
                logger.warn(
                    "%s IP address detected: [%s]. PUBLIC IP required, ignoring.",
                    ipType,
                    newIp,
                )
            else:
                logger.debug("%s IP address detected: [%s].", ipType, newIp)
                validIp = True
        except Exception as e:
            logger.error("Error encountered while looking up current IP: %s.", e)

        if not validIp:
            try:
                IP(
                    currentIp
                )  # Failed to look up current IP, so check if last known IP is valid
            except ValueError as e:
                logger.error(
                    "Last known IP is invalid: %s. Skipping domain check and sleeping for %i minutes.",
                    e,
                    UPDATE_INTERVAL,
                )
            else:
                newIp = currentIp
                validIp = True
                logger.info("Checking domains against last known IP: [%s].", newIp)

        if validIp:
            for domain in domains:
                addFlag = False
                if dh.allDomains.get(domain.name):
                    # Monitored domain already exists
                    if dh.allDomains.get(domain.name).get("editable") == "0":
                        logger.warn("Domain %s is not editable, skipping.", domain.name)
                        if prowl:  # Send Prowl notification
                            event = (
                                "Monitored DNS Record Not Editable: ["
                                + domain.name
                                + "]"
                            )
                            description = (
                                "Please check your configuration. Domain "
                                + domain.name
                                + " is monitored but DreamHost says it is not editable."
                            )
                            try:
                                prowlResult = prowl.notify(event, description)
                                if prowlResult.get("status") == "success":
                                    logger.debug(
                                        "Successfully sent notification to Prowl... Event: %s, Description: %s",
                                        event,
                                        description,
                                    )
                                else:
                                    logger.error(
                                        "Failed to send notification to Prowl... Event: %s, Description: %s, Status code: %s %s, Error message: %s",
                                        event,
                                        description,
                                        prowlResult.get("status"),
                                        prowlResult.get("message"),
                                        prowlResult.get("errMsg"),
                                    )
                            except Exception as e:
                                logger.error(
                                    "Failed to send notification to Prowl... Event: %s, Description: %s, Error message: %s",
                                    event,
                                    description,
                                    e,
                                )

                    elif dh.allDomains.get(domain.name).get("value") == newIp:
                        logger.info("No update needed for %s.", domain.name)
                    else:
                        # Update needed - remove record and set flag to add it
                        logger.info(
                            "New IP detected for %s: [%s]. Deleting existing record.",
                            domain.name,
                            newIp,
                        )
                        dhRemoveResponse = dh.api_call(
                            dh.cmds["remove"]
                            + "&type=A&record="
                            + domain.name
                            + "&value="
                            + dh.allDomains.get(domain.name).get("value")
                        )
                        if dhRemoveResponse.get("result") == "success":
                            logger.info("Successfully deleted domain %s.", domain.name)
                            addFlag = True
                        else:
                            logger.error(
                                "Error deleting domain %s: %s.",
                                domain.name,
                                dhRemoveResponse.get("data"),
                            )
                            if prowl:  # Send Prowl notification
                                event = (
                                    "Failed to Delete DNS Record: [" + domain.name + "]"
                                )
                                description = (
                                    "Domain "
                                    + domain.name
                                    + " needs to be updated with new IP ["
                                    + newIp
                                    + "], but the deletion failed.\nError message: "
                                    + dhRemoveResponse.get("data")
                                )
                                try:
                                    prowlResult = prowl.notify(event, description)
                                    if prowlResult.get("status") == "success":
                                        logger.debug(
                                            "Successfully sent notification to Prowl... Event: %s, Description: %s",
                                            event,
                                            description,
                                        )
                                    else:
                                        logger.error(
                                            "Failed to send notification to Prowl... Event: %s, Description: %s, Status code: %s %s, Error message: %s",
                                            event,
                                            description,
                                            prowlResult.get("status"),
                                            prowlResult.get("message"),
                                            prowlResult.get("errMsg"),
                                        )
                                except Exception as e:
                                    logger.error(
                                        "Failed to send notification to Prowl... Event: %s, Description: %s, Error message: %s",
                                        event,
                                        description,
                                        e,
                                    )
                else:
                    # Monitored domain does not exist
                    logger.info("Domain %s does not exist.", domain.name)
                    addFlag = True

                if addFlag:
                    if len(COMMENT) > 0:
                        comment = "&comment=" + quote_plus(
                            COMMENT.replace(
                                "{date}",
                                datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
                            )
                        )
                    else:
                        comment = ""
                    dhAddResponse = dh.api_call(
                        dh.cmds["add"]
                        + "&record="
                        + domain.name
                        + "&type=A&value="
                        + newIp
                        + comment
                    )
                    if dhAddResponse.get("result") == "success":
                        domain.lastUpdate = datetime.utcnow().strftime(
                            "%Y-%m-%dT%H:%M:%SZ"
                        )
                        logger.info(
                            "Successfully added domain %s with IP [%s].",
                            domain.name,
                            newIp,
                        )
                        if prowl:  # Send Prowl notification
                            event = "DNS Record Updated: [" + domain.name + "]"
                            description = (
                                "Successfully updated domain "
                                + domain.name
                                + " with IP ["
                                + newIp
                                + "]."
                            )
                            try:
                                prowlResult = prowl.notify(event, description)
                                if prowlResult.get("status") == "success":
                                    logger.debug(
                                        "Successfully sent notification to Prowl... Event: %s, Description: %s",
                                        event,
                                        description,
                                    )
                                else:
                                    logger.error(
                                        "Failed to send notification to Prowl... Event: %s, Description: %s, Status code: %s %s, Error message: %s",
                                        event,
                                        description,
                                        prowlResult.get("status"),
                                        prowlResult.get("message"),
                                        prowlResult.get("errMsg"),
                                    )
                            except Exception as e:
                                logger.error(
                                    "Failed to send notification to Prowl... Event: %s, Description: %s, Error message: %s",
                                    event,
                                    description,
                                    e,
                                )
                    else:
                        logger.error(
                            "Error adding domain %s: %s.",
                            domain.name,
                            dhAddResponse.get("data"),
                        )
                        if prowl:  # Send Prowl notification
                            event = "DNS Record Update Failed: [" + domain.name + "]"
                            description = (
                                "Failed to update domain "
                                + domain.name
                                + " with IP ["
                                + newIp
                                + "]:\n"
                                + dhAddResponse.get("data")
                            )
                            try:
                                prowlResult = prowl.notify(event, description)
                                if prowlResult.get("status") == "success":
                                    logger.debug(
                                        "Successfully sent notification to Prowl... Event: %s, Description: %s",
                                        event,
                                        description,
                                    )
                                else:
                                    logger.error(
                                        "Failed to send notification to Prowl... Event: %s, Description: %s, Status code: %s %s, Error message: %s",
                                        event,
                                        description,
                                        prowlResult.get("status"),
                                        prowlResult.get("message"),
                                        prowlResult.get("errMsg"),
                                    )
                            except Exception as e:
                                logger.error(
                                    "Failed to send notification to Prowl... Event: %s, Description: %s, Error message: %s",
                                    event,
                                    description,
                                    e,
                                )

            currentIp = newIp
            logger.info(
                "Done checking/updating domains. Sleeping for %i minutes.",
                UPDATE_INTERVAL,
            )

        sleep(UPDATE_INTERVAL * 60)