Example #1
0
    def get(self):
        jsondata = []
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            if AUTHIGNORE:
                query = "select * from persons;"
            else:
                query = "select * from persons where addedBy >= %d" % int(
                    admin_id)

            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                vTmp['person_id'] = val[0]
                vTmp['person_name'] = val[1]
                vTmp['person_addby'] = val[2]
                jsondata.append(vTmp)
            return jsonify(jsondata)
        except Exception as e:
            return jsonify(vTmp)
Example #2
0
    def get(self, site_id):
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()

        try:
            if AUTHIGNORE:
                query = "select * from sites where ID =%d " % int(site_id)
            else:
                if int(site_id) == int(admin_id):
                    query = "select * from sites where ID = %d " % int(site_id)
                else:
                    query = "select * from sites where ID = {} and addedBy >= {} ".format(
                        site_id, admin_id)

            cursor = conn.cursor()
            cursor.execute(query)
            for val in cursor.fetchall():
                result = {}
                result['site_id'] = val[0]
                result['site_addby'] = val[2]
                result['site_name'] = val[1]
                result['site_siteDescription'] = val[3]
            return jsonify(result)
        except:
            return jsonify(vTmp)
Example #3
0
    def get(self):
        jsondata = []
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            if AUTHIGNORE:
                query = "select * from users"
            else:
                query = "select * from users where parentID >= %d" % int(
                    admin_id)

            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                vTmp['user_id'] = val[0]
                vTmp['user_login'] = val[3]
                vTmp['user_email'] = val[5]
                vTmp['user_isadmin'] = val[2]
                vTmp['user_addby'] = val[1]
                vTmp['user_password'] = val[4]
                jsondata.append(vTmp)
            return jsonify(jsondata)
        except Exception as e:
            return jsonify(vTmp)
Example #4
0
    def get(self):
        jsondata = []
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        groupby = request.args.get("groupby", "")
        siteid = int(request.args.get("siteID", 0))
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            if groupby == 'siteID':
                if siteid > 0:
                    if AUTHIGNORE:
                        where = " WHERE st.ID = %d" % int(siteid)
                    else:
                        where = " WHERE st.ID = {} and st.addedBy >= {}".format(
                            siteid, admin_id)
                else:
                    if AUTHIGNORE:
                        where = ""
                    else:
                        where = " WHERE st.addedBy = {}".format(admin_id)
                query = "select ps.*, st.*, sum(ppr.Rank) as rank from persons as ps left join personspagerank as ppr " \
                        "ON ppr.`PersonID` = ps.ID left join pages as pg ON pg.ID = ppr.PageID left join sites as st " \
                        "ON st.`ID` = pg.`siteID`" + where + " group by ps.ID, ppr.`PersonID`, st.ID"
            else:
                query = "select * from personspagerank as ppr left join pages as pg ON pg.ID = ppr.PageID " \
                        "left join sites as st ON st.`ID` = pg.`siteID`"
                if AUTHIGNORE is False:
                    query = query + " where addedBy >= {}".format(admin_id)

            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                if groupby:
                    vTmp['person_id'] = val[0]
                    vTmp['person_name'] = val[1]
                    vTmp['person_addby'] = val[2]
                    vTmp['site_id'] = val[3]
                    vTmp['site_name'] = val[4]
                    vTmp['site_addby'] = val[5]
                    vTmp['person_rank'] = str(val[7])
                else:
                    vTmp['person_id'] = val[0]
                    vTmp['page_id'] = val[1]
                    vTmp['person_rank'] = val[2]
                jsondata.append(vTmp)
            return jsonify(jsondata)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Example #5
0
    def get(self):
        jsondata = []
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        _page = request.args.get('_page', 0)
        _siteID = int(request.args.get('siteID', 0))

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            where = " WHERE "
            if _siteID > 0:
                where = where + " st.ID = %d " % int(_siteID)
            else:
                where = ""

            if AUTHIGNORE:
                query = "select *,UNIX_TIMESTAMP(foundDatetime),UNIX_TIMESTAMP(lastScanDate) from pages " \
                        "" + where + " ORDER BY ID LIMIT {} OFFSET {}".format(LIMITPAGE, _page)
            else:
                if where != "":
                    where = where + " AND st.addedBy >= {}".format(admin_id)
                else:
                    where = "WHERE st.addedBy >= {}".format(admin_id)
                query = "select *,UNIX_TIMESTAMP(foundDatetime),UNIX_TIMESTAMP(lastScanDate) from pages  as pg " \
                        "left join sites as st ON st.`ID` = pg.`siteID` " \
                        "" + where + " ORDER BY pg.ID LIMIT {} OFFSET {} ".format(LIMITPAGE, _page)
            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                vTmp['page_id'] = val[0]
                vTmp['page_url'] = val[1]
                vTmp['page_site_id'] = val[2]
                vTmp['page_found_date_str'] = val[3]
                vTmp['page_last_scan_date_str'] = val[4]
                if AUTHIGNORE:
                    vTmp['page_found_date'] = val[5]
                    vTmp['page_last_scan_date'] = val[6]
                else:
                    vTmp['page_found_date'] = val[9]
                    vTmp['page_last_scan_date'] = val[10]
                jsondata.append(vTmp)
            return jsonify(jsondata)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Example #6
0
    def get(self, persons_id):
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        try:
            conn = mysql.connect()
            cursor = conn.cursor()

            if AUTHIGNORE:
                query = "select * from persons where ID =%d " % int(persons_id)
                key_qry = "select id,name from keywords where personID =%d " % int(
                    persons_id)
            else:
                if int(persons_id) == int(admin_id):
                    query = "select * from persons where ID =%d " % int(
                        persons_id)
                    key_qry = "select id,name from keywords where personID =%d " % int(
                        persons_id)
                else:
                    query = "select * from persons where ID = {} and addedBy = {}".format(
                        persons_id, admin_id)
                    key_qry = "select id,name from keywords where personID =%d " % int(
                        persons_id)

            try:
                cursor.execute(query)
                for val in cursor.fetchall():
                    result = {}
                    result['person_keywords'] = []
                    result['person_id'] = val[0]
                    result['person_name'] = val[1]
                    result['person_addby'] = val[2]
                    cursor.execute(key_qry)
                    kTmp = {}
                    kTmp['keyword_id'] = 0
                    kTmp['keyword_name'] = val[1]
                    result['person_keywords'].append(kTmp)
                    for (kid, kname) in cursor.fetchall():
                        kTmp = {}
                        kTmp['keyword_id'] = kid
                        kTmp['keyword_name'] = kname
                        result['person_keywords'].append(kTmp)
                return jsonify(result)
            except Exception as e:
                return jsonify(vTmp)
        except:
            return jsonify(vTmp)
Example #7
0
    def get(self, page_id):
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            where = " WHERE "

            if AUTHIGNORE:
                query = "select *,UNIX_TIMESTAMP(foundDatetime),UNIX_TIMESTAMP(lastScanDate) from pages "\
                        + where + " ID = %d" % int(page_id)
            else:
                where = "WHERE st.addedBy >= {} AND pg.ID = {} ".format(admin_id, page_id)
                query = "select *,UNIX_TIMESTAMP(foundDatetime),UNIX_TIMESTAMP(lastScanDate) from pages  as pg " \
                        "left join sites as st ON st.`ID` = pg.`siteID` " \
                        "" + where

            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                vTmp['page_id'] = val[0]
                vTmp['page_url'] = val[1]
                vTmp['page_site_id'] = val[2]
                vTmp['page_found_date_str'] = val[3]
                vTmp['page_last_scan_date_str'] = val[4]
                if AUTHIGNORE:
                    vTmp['page_found_date'] = val[5]
                    vTmp['page_last_scan_date'] = val[6]
                else:
                    vTmp['page_found_date'] = val[9]
                    vTmp['page_last_scan_date'] = val[10]
            return jsonify(vTmp)
        except:
            return jsonify(vTmp)
Example #8
0
    def get(self):
        jsondata = []
        vTmp = {}
        vTmp['success'] = 0

        _sortby = request.args.get("_sortby", "DESC")
        _from = request.args.get('_from', 19760101)
        _till = request.args.get('_till', 21001231)

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            if AUTHIGNORE:
                query = "select *,UNIX_TIMESTAMP(logDate) from log " \
                        "where `logDate` BETWEEN '{}' AND '{}' order by logDate {} LIMIT {}".format(_from, _till, _sortby, LIMITPAGE)
            else:
                query = "select *,UNIX_TIMESTAMP(logDate) from log where adminID >= {} and " \
                        "`logDate` BETWEEN '{}' AND '{}' order by logDate  {} LIMIT {}".format(admin_id, _from, _till, _sortby, LIMITPAGE)

            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                vTmp['log_id'] = val[0]
                vTmp['log_admin_id'] = val[1]
                vTmp['log_action'] = val[2]
                vTmp['log_date'] = val[4]
                jsondata.append(vTmp)
            return jsonify(jsondata)
        except Exception as e:
            return jsonify(vTmp)
Example #9
0
    def get(self, user_id):
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            if AUTHIGNORE:
                query = "select * from users where ID = %d " % int(user_id)
            else:
                if int(user_id) == int(admin_id):
                    query = "select * from users where ID = %d " % int(user_id)
                else:
                    query = "select * from users where ID = {} and parentID >= {}".format(
                        user_id, admin_id)
            try:
                cursor.execute(query)
                for val in cursor.fetchall():
                    result = {}
                    result['user_id'] = val[0]
                    result['user_login'] = val[3]
                    result['user_email'] = val[5]
                    result['user_isadmin'] = val[2]
                    result['user_addby'] = val[1]
                    result['user_password'] = val[4]
                return jsonify(result)
            except:
                return jsonify(vTmp)
        except:
            return jsonify(vTmp)
Example #10
0
    def get(self):
        vTmp = {}
        vTmp['success'] = 0

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)

        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()

        try:
            if AUTHIGNORE:
                query = "select UNIX_TIMESTAMP(min(pg.foundDateTime)) as minDate, UNIX_TIMESTAMP(max(pg.foundDateTime)) " \
                        "as maxDate from persons as ps left join personspagerank as ppr ON ppr.`PersonID` = ps.ID " \
                        "left join pages as pg ON pg.ID = ppr.PageID " \
                        "left join sites as st ON st.`ID` = pg.`siteID`"
            else:
                where = "WHERE st.addedBy >= {}".format(admin_id)
                query = "select UNIX_TIMESTAMP(min(pg.foundDateTime)) as minDate, UNIX_TIMESTAMP(max(pg.foundDateTime)) " \
                        "as maxDate from persons as ps left join personspagerank as ppr ON ppr.`PersonID` = ps.ID " \
                        "left join pages as pg ON pg.ID = ppr.PageID " \
                        "left join sites as st ON st.`ID` = pg.`siteID`" + where
            print(query)
            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                vTmp['since_date'] = val[0]
                vTmp['till_date'] = val[1]

            if AUTHIGNORE:
                query = "select * from persons"
            else:
                where = "WHERE addedBy >= {}".format(admin_id)
                query = "select * from persons " + where
            cursor.execute(query)
            jsondata = []
            for val in cursor.fetchall():
                pTmp = {}
                pTmp['person_id'] = val[0]
                pTmp['person_name'] = val[1]
                jsondata.append(pTmp)
            vTmp['persons'] = jsondata

            if AUTHIGNORE:
                query = "select * from sites"
            else:
                where = "WHERE addedBy >= {}".format(admin_id)
                query = "select * from sites " + where
            cursor.execute(query)
            jsondata = []
            for val in cursor.fetchall():
                pTmp = {}
                pTmp['site_id'] = val[0]
                pTmp['site_name'] = val[1]
                jsondata.append(pTmp)
            vTmp['sites'] = jsondata

            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Example #11
0
    def get(self):
        vTmp = {}
        jsondata = []
        vTmp['success'] = 0

        print(request)
        _from = request.args.get('_from', "19760101")
        _till = request.args.get('_till', "21000101")
        _persons = request.args.get('_persons', "").split(',')
        _personids = request.args.get('_personids', "").split(',')
        _sites = request.args.get('_sites', "").split(',')
        _groupdate = request.args.get('_groupdate', "day")

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)
        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        mAnd = "OR "
        personsWhere = ""
        if not all(_personids):
            for v in _persons:
                if v != "":
                    if personsWhere == "":
                        personsWhere = " AND ("
                        personsWhere = personsWhere + "ps.name = '" + v + "' "
                    else:
                        personsWhere = personsWhere + mAnd + "ps.name = '" + v + "' "
            if personsWhere != "":
                personsWhere = personsWhere + ")"
        else:
            for v in _personids:
                if v != "":
                    if personsWhere == "":
                        personsWhere = " AND ("
                        personsWhere = personsWhere + "ps.id = " + v + " "
                    else:
                        personsWhere = personsWhere + mAnd + "ps.id = " + v + " "
            if personsWhere != "":
                personsWhere = personsWhere + ")"

        sitesWhere = ""
        for v in _sites:
            if v != "":
                if sitesWhere == "":
                    sitesWhere = " AND ("
                    sitesWhere = sitesWhere + "st.name = '" + v + "' "
                else:
                    sitesWhere = sitesWhere + mAnd + "st.name = '" + v + "' "
        if sitesWhere != "":
            sitesWhere = sitesWhere + ")"

        conn = mysql.connect()
        cursor = conn.cursor()
        try:
            if _groupdate == 'month':
                groupby = " MONTH(pg.foundDateTime) "
                _dateformat = " DATE_FORMAT(pg.foundDateTime,'%Y-%m') "
            elif _groupdate == 'year':
                groupby = " YEAR(pg.foundDateTime) "
                _dateformat = " DATE_FORMAT(pg.foundDateTime,'%Y') "
            else:
                groupby = " DAY(pg.foundDateTime) "
                _dateformat = " DATE_FORMAT(pg.foundDateTime,'%Y-%m-%d') "

            if AUTHIGNORE:
                where = "WHERE pg.`foundDateTime` BETWEEN '{}' AND '{}' ".format(
                    _from, _till)
                query = "select ps.*, st.*, sum(ppr.Rank) as rank, " + _dateformat + \
                        " from persons as ps left join personspagerank as ppr " \
                      "ON ppr.`PersonID` = ps.ID left join pages as pg ON pg.ID = ppr.PageID left join sites as st " \
                      "ON st.`ID` = pg.`siteID`" + where + " " + personsWhere + " " + sitesWhere + " group by ps.ID, ppr.`PersonID`, st.ID," + groupby
            else:
                """pg.lastScanDate"""
                query = "select  st.*, ps.*, sum(ppr.Rank) as rank, " + _dateformat + " from persons as ps " \
                    "left join personspagerank as ppr ON ppr.`PersonID` = ps.ID left join pages as pg ON pg.ID = ppr.PageID " \
                    "left join sites as st ON st.`ID` = pg.`siteID` " \
                    "where pg.`foundDateTime` BETWEEN '{}' AND '{}' ".format(_from, _till)
                query = query + " AND st.addedBy >= %d " % int(admin_id)
                query = query + " " + personsWhere + " " + sitesWhere
                query = query + " GROUP BY ps.ID, ppr.`PersonID`, st.ID," + groupby

            print(query)
            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                vTmp['person_id'] = val[0]
                vTmp['person_name'] = val[1]
                vTmp['person_addby'] = val[2]
                vTmp['site_id'] = val[3]
                vTmp['site_name'] = val[4]
                vTmp['site_addby'] = val[5]
                vTmp['person_rank'] = int(val[7])
                vTmp['person_rank_date'] = val[8]
                jsondata.append(vTmp)
            return jsonify(jsondata)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Example #12
0
    def get(self, persons_id):
        vTmp = {}
        jsondata = []
        vTmp['success'] = 0

        groupby = request.args.get("groupby", "")
        siteid = int(request.args.get("siteID", 0))
        _from = request.args.get('_from', 1)
        _till = request.args.get('_till', 1)

        token = request.args.get("token_auth", "")
        admin_id = checkTokenUser(token)
        if admin_id == 0 and AUTHIGNORE is False:
            return jsonify(vTmp)

        conn = mysql.connect()
        cursor = conn.cursor()
        try:
            if groupby == 'siteID':
                where = " WHERE "
                if siteid > 0:
                    where = where + "st.ID = %d AND " % int(siteid)

                if AUTHIGNORE is False:
                    where = where + "st.addedBy >= %d AND " % int(admin_id)

                where = where + " pg.`foundDateTime` BETWEEN '{}' AND '{}' AND ps.ID = {}".format(
                    _from, _till, persons_id)
                query = "select ps.*, st.*, sum(ppr.Rank) as rank from persons as ps left join personspagerank as ppr " \
                      "ON ppr.`PersonID` = ps.ID left join pages as pg ON pg.ID = ppr.PageID left join sites as st " \
                      "ON st.`ID` = pg.`siteID`" + where + " group by ps.ID, ppr.`PersonID`, st.ID"
            else:
                query = "select *,UNIX_TIMESTAMP(foundDatetime),UNIX_TIMESTAMP(lastScanDate) from persons as ps left join personspagerank as ppr ON ppr.`PersonID` = ps.ID left join pages \
                        as pg ON pg.ID = ppr.PageID left join sites as st ON st.`ID` = pg.`siteID` \
                    where  pg.`foundDateTime` BETWEEN '{}' AND '{}' AND ps.ID = {}".format(
                    _from, _till, persons_id)
                if AUTHIGNORE is False:
                    query = query + " AND st.addedBy >= %d " % int(admin_id)

            cursor.execute(query)
            for val in cursor.fetchall():
                vTmp = {}
                if groupby:
                    vTmp['person_id'] = val[0]
                    vTmp['person_name'] = val[1]
                    vTmp['person_addby'] = val[2]
                    vTmp['site_id'] = val[3]
                    vTmp['site_name'] = val[4]
                    vTmp['site_addby'] = val[5]
                    vTmp['person_rank'] = str(val[7])
                else:
                    vTmp['person_id'] = val[0]
                    vTmp['person_name'] = val[1]
                    vTmp['person_addby'] = val[2]
                    vTmp['page_id'] = val[4]
                    vTmp['person_rank'] = val[5]
                    vTmp['person_page_id'] = val[6]
                    vTmp['page_url'] = val[7]
                    vTmp['page_site_id'] = val[8]
                    vTmp['site_found_date'] = val[15]
                    vTmp['site_last_scan_date'] = val[16]
                    vTmp['site_found_date_str'] = val[9]
                    vTmp['site_last_scan_date_str'] = val[10]
                    vTmp['site_id'] = val[11]
                    vTmp['site_name'] = val[12]
                    vTmp['site_addby'] = val[13]
                    vTmp['site_description'] = val[14]
                jsondata.append(vTmp)
            return jsonify(jsondata)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)