mailcnf_tools.py 2.37 KB

from mysql.connector import MySQLConnection, Error
from read_dbconfig import read_db_config
import sqlite3
#import hashlib
#import tornado.ioloop
#import tornado.web
##import  tornado.escape
#import  tornado
import os.path

class mailcnf_tools:
    def getDomainNamebyGuid(self,guid):
        if guid == 0:
            query = " SELECT name FROM `virtual_domains` WHERE   deleted='0' "
        else:
            query = " SELECT name FROM `virtual_domains` WHERE  group_id in ( "+guid+" ) AND deleted='0' "
        try:
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
    
            cursor = conn.cursor()
            cursor.execute(query)
            fields=cursor.fetchall()
            combolist=[]
            for field in fields:
                combolist.append(str(field[0]))
            combolist.sort()
            return combolist
        except Error as error:
            print(error)
        finally:
            cursor.close()
            conn.close()  
    
    def get_domain_id_by_name(self,name):
            id=0
            query = " SELECT id FROM `virtual_domains` WHERE  `name`='"+name+"' "
            try:
                db_config = read_db_config()
                conn = MySQLConnection(**db_config)
                cursor = conn.cursor()
                cursor.execute(query)
                fields=cursor.fetchall()
                for field in fields:
                    id=field[0]       
            except Error as error:
                print(error)
            finally:
                cursor.close()
                conn.close()
            return id
            
    def get_user_groups_srvcnf(self):
        dbpath =os.path.dirname(__file__)+ "/srvcnf.sqlite3"
        self.write(dbpath)
 #       password=self.get_argument("password")
        self.write(" - ")
        self.db=sqlite3.connect(dbpath)
        self.dbcursor=self.db.cursor()
        #sql = ' SELECT _id,groupname FROM `srvgrps`  ORDER BY `_id` ASC  '
        sql = ' SELECT _id FROM `srvgrps`  ORDER BY `_id` ASC  '
#        password=''

        combolist=[]
        for field in self.dbcursor.execute(sql):
                combolist.append(str(field[0]))
        combolist.sort()
        return combolist
            
            
            
            
        #    password= row[0]   #String.valueOf(c.getInt(c.getColumnIndex("password")));
        #return password