Beispiel #1
0
    def delete(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                req_json = request.json

                if 'token_auth' in req_json:
                    token = request.json['token_auth']
                else:
                    return jsonify(vTmp)

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

                query = "select * from users where token = '{}' and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            return jsonify(vTmp)

        if 'keyword_id' in req_json:
            keyword_id = request.json['keyword_id']
        else:
            return jsonify(vTmp)

        try:
            query = "SELECT * FROM keywords WHERE ID = {}".format(keyword_id)
            cursor.execute(query)
            if cursor.rowcount >= 1:
                query = "DELETE FROM keywords WHERE ID = {}".format(keyword_id)
                cursor.execute(query)
                conn.commit()
            else:
                return jsonify(vTmp)

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Удалил кейворд c id {}".format(keyword_id))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #2
0
    def patch(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            return jsonify(vTmp)

        try:
            name = request.json['name']
            person_id = request.json['person_id']
        except:
            return jsonify(vTmp)

        try:
            query = "SELECT * FROM persons WHERE ID = {}".format(person_id)
            cursor.execute(query)
            if cursor.rowcount == 0:
                return jsonify(vTmp)

            query = "UPDATE persons SET name = '{}' WHERE ID = {} ".format(
                name, person_id)
            print(query)
            cursor.execute(query)
            conn.commit()

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id,
                      "Изменил персону c id {} на {}".format(person_id, name))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #3
0
    def post(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and isAdmin = 1 and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            return jsonify(vTmp)

        try:
            login = request.json['user']
            password = request.json['password']
            email = request.json['email']
            is_admin = request.json['isAdmin']
        except Exception as e:
            return jsonify(vTmp)

        try:
            query = "insert into users (parentID, isAdmin, login, password, email) values('{}','{}'," \
                    "'{}','{}','{}')".format(parent_id, is_admin, login, password, email)
            cursor.execute(query)
            conn.commit()
            vTmp["user_id"] = cursor.lastrowid

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Создал пользователя {}".format(login))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #4
0
    def post(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                print(query)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            return jsonify(vTmp)

        try:
            name = request.json['name']
        except Exception as e:
            return jsonify(vTmp)

        try:
            query = "insert into persons (addedBy, name) values('{}','{}')".format(
                parent_id, name)
            print(query)
            cursor.execute(query)
            conn.commit()
            vTmp["person_id"] = cursor.lastrowid

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Добавил персону {}".format(name))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #5
0
    def post(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and isAdmin = 1 and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            return jsonify(vTmp)

        try:
            page_url = request.json['page_url']
            page_site_id = request.json['page_site_id']
        except Exception as e:
            return jsonify(vTmp)

        req_json = request.json
        if 'page_found_date' in req_json:
            page_fd = request.json['page_found_date']
        else:
            page_fd = "Null"
        if 'page_last_scan_date' in req_json:
            page_lsd = request.json['page_last_scan_date']
        else:
            page_lsd = "Null"

        try:
            query = "insert into pages (URL, siteID, foundDateTime, lastScanDate) values('{}','{}'," \
                    "{},{})".format(page_url, page_site_id, page_fd, page_lsd)
            cursor.execute(query)
            conn.commit()
            vTmp["page_id"] = cursor.lastrowid

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Добавлена страница c url {}".format(page_url))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #6
0
    def patch(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and isAdmin = 1 and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)

        try:
            page_id = request.json['page_id']
        except Exception as e:
            return jsonify(vTmp)

        req_json = request.json
        if 'page_url' in req_json:
            page_url = req_json['page_url']
        if 'page_found_date' in req_json:
            page_fd = req_json['page_found_date']
        if 'page_last_scan_date' in req_json:
            page_lsd = req_json['page_last_scan_date']
        if 'page_site_id' in req_json:
            page_site_id = req_json['page_site_id']

        try:
            query = "SELECT * FROM pages WHERE ID = {}".format(page_id)
            cursor.execute(query)
            if cursor.rowcount == 0:
                return jsonify(vTmp)

            query = "UPDATE pages SET "
            if 'page_url' in req_json:
                query = query + "URL = '{}' ".format(page_url)
            if 'page_found_date' in req_json:
                if 'page_url' in req_json:
                    query = query + ", "
                query = query + "foundDateTime = {} ".format(page_fd)
            if 'page_last_scan_date' in req_json:
                if 'page_url' or 'page_found_date' in req_json:
                    query = query + ", "
                query = query + "lastScanDate = {} ".format(page_lsd)
            if 'page_site_id' in req_json:
                if 'page_url' or 'page_found_date' or 'page_last_scan_date' in req_json:
                    query = query + ", "
                query = query + "siteID = {} ".format(page_site_id)
            query = query + "WHERE ID = {} ".format(page_id)
            cursor.execute(query)
            conn.commit()

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Изменил страницу id {}".format(page_id))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #7
0
    def post(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0
        """ {"Ким Чин Ыну", "Ким Чин Ына", "Ким Чин Ыном","Ким Чин Ынамом"  } """

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                print(query)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    vTmp['exception'] = str(e)
                    return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)

        try:
            person_id = request.json['person_id']
            keywords = request.json['keywords']
        except Exception as e:
            return jsonify(vTmp)

        try:
            keyIDs = []
            for key in keywords:
                query = "insert into keywords (personID, name) values('{}','{}')".format(
                    person_id, keywords[key])
                print(query)
                cursor.execute(query)
                conn.commit()
                keyIDs.append(cursor.lastrowid)
            vTmp["keywords_id"] = keyIDs

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Добавил кейворд(ы) {}".format(keywords))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #8
0
    def post(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    vTmp['exception'] = str(e)
                    return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)

        try:
            name = request.json['name']
            description = request.json['description']
            pageURL = request.json['pageURL']
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)

        try:
            query = "insert into sites (addedBy, name, siteDescription) values({}, '{}', '{}')".format(
                parent_id, name, description)
            cursor.execute(query)
            conn.commit()
            vTmp["site_id"] = cursor.lastrowid

            query = "insert into pages (URL, siteID, foundDateTime) values('{}', '{}',  now())".format(
                pageURL, vTmp['site_id'])
            cursor.execute(query)
            conn.commit()

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Добавлена сайт {}".format(name))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #9
0
    def patch(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            return jsonify(vTmp)

        try:
            site_id = request.json['site_id']
        except:
            return jsonify(vTmp)

        req_json = request.json
        name = ""
        description = ""
        if 'name' in req_json:
            name = req_json['name']
        if 'description' in req_json:
            description = req_json['description']

        try:
            query = "SELECT * FROM sites WHERE ID = {}".format(site_id)
            cursor.execute(query)
            if cursor.rowcount == 0:
                return jsonify(vTmp)

            query = "UPDATE sites SET "
            if 'name' in req_json:
                query = query + "name = '{}' ".format(name)
            if 'description' in req_json:
                if 'name' in req_json:
                    query = query + ", "
                query = query + "siteDescription= '{}' ".format(description)
            query = query + "WHERE ID = {} ".format(site_id)
            cursor.execute(query)
            conn.commit()

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Изменил сайт id {}".format(site_id))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)
Beispiel #10
0
    def patch(self):
        vTmp = {}
        vTmp['success'] = 0
        parent_id = 0

        try:
            if not request.json:
                return jsonify(vTmp)
            else:
                token = request.json['token_auth']

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

                query = "select * from users where token = '{}' and isAdmin = 1 and " \
                        "tokenLastAccess > NOW() - INTERVAL {} MINUTE;".format(token, LOGINTIME)
                try:
                    cursor.execute(query)
                    if cursor.rowcount == 1:
                        for userValue in cursor.fetchall():
                            parent_id = userValue[0]
                    else:
                        return jsonify(vTmp)
                except Exception as e:
                    return jsonify(vTmp)
        except Exception as e:
            return jsonify(vTmp)

        try:
            user_id = request.json['user_id']
        except:
            return jsonify(vTmp)

        req_json = request.json
        login = ""
        password = ""
        email = ""
        is_admin = ""
        if 'user' in req_json:
            login = req_json['user']
        if 'password' in req_json:
            password = req_json['password']
        if 'email' in req_json:
            email = req_json['email']
        if 'is_admin' in req_json:
            is_admin = req_json['is_admin']

        try:
            query = "SELECT * FROM users WHERE ID = {}".format(user_id)
            cursor.execute(query)
            if cursor.rowcount == 0:
                return jsonify(vTmp)

            query = "UPDATE users SET "
            if 'user' in req_json:
                query = query + "login = '******' ".format(login)
            if 'password' in req_json:
                if 'user' in req_json:
                    query = query + ", "
                query = query + "password = '******' ".format(password)
            if 'email' in req_json:
                if 'login' or 'password' in req_json:
                    query = query + ", "
                query = query + "email = '{}' ".format(email)
            if 'is_admin' in req_json:
                if 'login' or 'password' or 'email' in req_json:
                    query = query + ", "
                query = query + "isAdmin = {} ".format(is_admin)
            query = query + "WHERE ID = {} ".format(user_id)
            cursor.execute(query)
            conn.commit()

            query = "UPDATE users SET token = '{}', tokenLastAccess = now() WHERE ID = {}".format(
                token, parent_id)
            cursor.execute(query)
            conn.commit()

            insertLog(parent_id, "Изменил пользователя {}".format(login))

            vTmp['success'] = 1
            return jsonify(vTmp)
        except Exception as e:
            vTmp['exception'] = str(e)
            return jsonify(vTmp)