Exemplo n.º 1
0
    def uninstallOldApi(self):
        rundir = mw.getRunDir()
        name = request.form.get('name', '')
        version = request.form.get('version', '')
        if name.strip() == '':
            return mw.returnJson(False, "缺少插件名称!", ())

        if version.strip() == '':
            return mw.returnJson(False, "缺少版本信息!", ())

        infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'

        if not os.path.exists(infoJsonPos):
            return mw.returnJson(False, "配置文件不存在!", ())

        pluginInfo = json.loads(mw.readFile(infoJsonPos))

        execstr = "cd " + os.getcwd() + "/plugins/" + \
            name + " && /bin/bash " + pluginInfo["shell"] \
            + " uninstall " + version

        taskAdd = (None, '卸载[' + name + '-' + version + ']', 'execshell', '0',
                   time.strftime('%Y-%m-%d %H:%M:%S'), execstr)

        mw.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
        return mw.returnJson(True, '已将卸载任务添加到队列!')
Exemplo n.º 2
0
    def uninstallApi(self):
        rundir = mw.getRunDir()
        name = request.form.get('name', '')
        version = request.form.get('version', '')
        if name.strip() == '':
            return mw.returnJson(False, "缺少插件名称!", ())

        if version.strip() == '':
            return mw.returnJson(False, "缺少版本信息!", ())

        infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'

        if not os.path.exists(infoJsonPos):
            return mw.returnJson(False, "配置文件不存在!", ())

        pluginInfo = json.loads(mw.readFile(infoJsonPos))

        execstr = "cd " + os.getcwd() + "/plugins/" + \
            name + " && /bin/bash " + pluginInfo["shell"] \
            + " uninstall " + version

        data = mw.execShell(execstr)
        if mw.isAppleSystem():
            print(execstr)
            print(data[0], data[1])
        return mw.returnJson(True, '卸载执行成功!')
Exemplo n.º 3
0
    def installApi(self):
        rundir = mw.getRunDir()
        name = request.form.get('name', '')
        version = request.form.get('version', '')

        mmsg = '安装'
        if hasattr(request.form, 'upgrade'):
            mtype = 'update'
            mmsg = 'upgrade'

        if name.strip() == '':
            return mw.returnJson(False, '缺少插件名称!', ())

        if version.strip() == '':
            return mw.returnJson(False, '缺少版本信息!', ())

        infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'
        # print infoJsonPos

        if not os.path.exists(infoJsonPos):
            return mw.returnJson(False, '配置文件不存在!', ())

        pluginInfo = json.loads(mw.readFile(infoJsonPos))

        execstr = "cd " + os.getcwd() + "/plugins/" + \
            name + " && /bin/bash " + pluginInfo["shell"] \
            + " install " + version

        taskAdd = (None, mmsg + '[' + name + '-' + version + ']', 'execshell',
                   '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr)

        mw.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
        return mw.returnJson(True, '已将安装任务添加到队列!')
Exemplo n.º 4
0
    def setSshPortApi(self):
        port = request.form.get('port', '1').strip()
        if int(port) < 22 or int(port) > 65535:
            return mw.returnJson(False, '端口范围必需在22-65535之间!')

        ports = ['21', '25', '80', '443', '7200', '8080', '888', '8888']
        if port in ports:
            return mw.returnJson(False, '(' + port + ')' + '特殊端口不可设置!')

        file = '/etc/ssh/sshd_config'
        conf = mw.readFile(file)

        rep = "#*Port\s+([0-9]+)\s*\n"
        conf = re.sub(rep, "Port " + port + "\n", conf)
        mw.writeFile(file, conf)

        if self.__isFirewalld:
            mw.execShell('setenforce 0')
            mw.execShell(
                'sed -i "s#SELINUX=enforcing#SELINUX=disabled#" /etc/selinux/config')
            mw.execShell("systemctl restart sshd.service")
        elif self.__isUfw:
            mw.execShell('ufw allow ' + port + '/tcp')
            mw.execShell("service ssh restart")
        else:
            mw.execShell(
                'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT')
            mw.execShell("/etc/init.d/sshd restart")

        self.firewallReload()
        # mw.M('firewall').where(
        #     "ps=?", ('SSH远程管理服务',)).setField('port', port)
        msg = mw.getInfo('改SSH端口为[{1}]成功!', port)
        mw.writeLog("防火墙管理", msg)
        return mw.returnJson(True, '修改成功!')
Exemplo n.º 5
0
def test():
    qb = pQbClient()
    # magnet_link = "magnet:?xt=urn:btih:57a0ec92a61c60585f1b7a206a75798aa69285a5"
    # print qb.download_from_link(magnet_link)
    torrents = qb.torrents(filter='downloading')
    for torrent in torrents:
        print mw.returnJson(False, torrent)
Exemplo n.º 6
0
    def setAdminPathApi(self):
        admin_path = request.form.get('admin_path', '').strip()
        admin_path_checks = ['/', '/close', '/login', '/do_login', '/site',
                             '/sites', '/download_file', '/control', '/crontab',
                             '/firewall', '/files', 'config', '/soft', '/system',
                             '/code', '/ssl', '/plugins']
        if admin_path == '':
            admin_path = '/'
        if admin_path != '/':
            if len(admin_path) < 6:
                return mw.returnJson(False, '安全入口地址长度不能小于6位!')
            if admin_path in admin_path_checks:
                return mw.returnJson(False, '该入口已被面板占用,请使用其它入口!')
            if not re.match("^/[\w\./-_]+$", admin_path):
                return mw.returnJson(False, '入口地址格式不正确,示例: /my_panel')
        else:
            domain = mw.readFile('data/domain.conf')
            if not domain:
                domain = ''
            limitip = mw.readFile('data/limitip.conf')
            if not limitip:
                limitip = ''
            if not domain.strip() and not limitip.strip():
                return mw.returnJson(False, '警告,关闭安全入口等于直接暴露你的后台地址在外网,十分危险,至少开启以下一种安全方式才能关闭:<a style="color:red;"><br>1、绑定访问域名<br>2、绑定授权IP</a>')

        admin_path_file = 'data/admin_path.pl'
        admin_path_old = '/'
        if os.path.exists(admin_path_file):
            admin_path_old = mw.readFile(admin_path_file).strip()

        if admin_path_old != admin_path:
            mw.writeFile(admin_path_file, admin_path)
            mw.restartMw()
        return mw.returnJson(True, '修改成功!')
Exemplo n.º 7
0
def pm2Add():
    args = getArgs()
    data = checkArgs(args, ['path', 'run', 'pname'])
    if not data[0]:
        return data[1]

    path = args['path']
    run = args['run']
    pname = args['pname']

    runFile = (path + '/' + run).replace('//', '/')
    if not os.path.exists(runFile):
        return mw.returnJson(False, '指定文件不存在!')

    nlist = pm2GetList()
    for node in nlist:
        if pname == node['name']:
            return mw.returnJson(False, '指定项目名称已经存在!')
    if os.path.exists(path + '/package.json'
                      ) and not os.path.exists(path + '/package-lock.json'):
        mw.execShell(__SR + "cd " + path + ' && npm install -s')
    mw.execShell(__SR + 'cd ' + path + ' && pm2 start ' + runFile +
                 ' --name "' + pname + '"|grep ' + pname)
    mw.execShell(__SR + 'pm2 save && pm2 startup')
    if not os.path.exists(__path):
        mw.execShell('mkdir -p ' + __path)
    mw.writeFile(__path + '/' + pname, path)
    return mw.returnJson(True, '添加成功!')
Exemplo n.º 8
0
    def getTaskSpeedApi(self):
        tempFile = os.getcwd() + '/tmp/panelExec.log'
        freshFile = os.getcwd() + '/tmp/panelFresh'

        find = mw.M('tasks').where('status=? OR status=?',
                                   ('-1', '0')).field('id,type,name,execstr').find()
        if not len(find):
            return mw.returnJson(False, '当前没有任务队列在执行-2!')

        isTask = os.getcwd() + '/tmp/panelTask.pl'
        mw.writeFile(isTask, 'True')

        echoMsg = {}
        echoMsg['name'] = find['name']
        echoMsg['execstr'] = find['execstr']
        if find['type'] == 'download':
            import json
            try:
                tmp = mw.readFile(tempFile)
                if len(tmp) < 10:
                    return mw.returnJson(False, '当前没有任务队列在执行-3!')
                echoMsg['msg'] = json.loads(tmp)
                echoMsg['isDownload'] = True
            except:
                mw.M('tasks').where(
                    "id=?", (find['id'],)).save('status', ('0',))
                return mw.returnJson(False, '当前没有任务队列在执行-4!')
        else:
            echoMsg['msg'] = mw.getLastLine(tempFile, 10)
            echoMsg['isDownload'] = False

        echoMsg['task'] = mw.M('tasks').where("status!=?", ('1',)).field(
            'id,status,name,type').order("id asc").select()
        return mw.getJson(echoMsg)
Exemplo n.º 9
0
def modUser():

    args = getArgs()
    data = checkArgs(args, ['username', 'password'])
    if not data[0]:
        return data[1]

    path = getPathFile()
    username = args['username']
    password = args['password']

    # sed -i "/^\<${user}\>/d" /etc/ppp/chap-secrets
    # echo "${user}    l2tpd    ${pass}       *" >> /etc/ppp/chap-secrets

    if mw.isAppleSystem():
        mw.execShell("sed -i .bak '/^\(" + username + "\)/d' " + path)
    else:
        mw.execShell("sed -i '/^\(" + username + "\)/d' " + path)
    # print 'echo "' + username + "    l2tpd    " + password + "      *\" >>"
    # + path
    ret = mw.execShell("echo \"" + username +
                       "    l2tpd    " + password + "       *\" >>" + path)
    if ret[1] == '':
        return mw.returnJson(True, '修改成功!')
    return mw.returnJson(False, '修改失败')
Exemplo n.º 10
0
def getXhPort():
    try:
        port = getPort()
        return mw.returnJson(True, 'OK', port)
    except Exception as e:
        print e
        return mw.returnJson(False, '插件未启动!')
Exemplo n.º 11
0
def getUserList():
    import re
    path = getPathFile()
    if not os.path.exists(path):
        return mw.returnJson(False, '密码配置文件不存在!')
    conf = mw.readFile(path)

    conf = re.sub('#(.*)\n', '', conf)

    if conf.strip() == '':
        return mw.returnJson(True, 'ok', [])

    ulist = conf.strip().split('\n')

    user = []
    for line in ulist:
        line_info = {}
        line = re.match(r'(\w*)\s*(\w*)\s*(\w*)\s*(.*)',
                        line.strip(), re.M | re.I).groups()
        line_info['user'] = line[0]
        line_info['pwd'] = line[2]
        line_info['type'] = line[1]
        line_info['ip'] = line[3]
        user.append(line_info)

    return mw.returnJson(True, 'ok', user)
Exemplo n.º 12
0
    def delDropAddressApi(self):
        if not self.getFwStatus():
            return mw.returnJson(False, '防火墙启动时,才能删除规则!')

        port = request.form.get('port', '').strip()
        ps = request.form.get('ps', '').strip()
        sid = request.form.get('id', '').strip()
        address = port
        if self.__isUfw:
            mw.execShell('ufw delete deny from ' + address + ' to any')
        else:
            if self.__isFirewalld:
                mw.execShell(
                    'firewall-cmd --permanent --remove-rich-rule=\'rule family=ipv4 source address="' + address + '" drop\'')
            elif self.__isMac:
                pass
            else:
                cmd = 'iptables -D INPUT -s ' + address + ' -j DROP'
                mw.execShell(cmd)

        msg = mw.getInfo('解除IP[{1}]的屏蔽!', (address,))
        mw.writeLog("防火墙管理", msg)
        mw.M('firewall').where("id=?", (sid,)).delete()

        self.firewallReload()
        return mw.returnJson(True, '删除成功!')
Exemplo n.º 13
0
def getLibConf(version):
    fname = mw.getServerDir() + '/php/' + version + '/etc/php.ini'
    if not os.path.exists(fname):
        return mw.returnJson(False, '指定PHP版本不存在!')

    phpini = mw.readFile(fname)

    libpath = getPluginDir() + '/versions/phplib.conf'
    phplib = json.loads(mw.readFile(libpath))

    libs = []
    tasks = mw.M('tasks').where("status!=?",
                                ('1', )).field('status,name').select()
    for lib in phplib:
        lib['task'] = '1'
        for task in tasks:
            tmp = mw.getStrBetween('[', ']', task['name'])
            if not tmp:
                continue
            tmp1 = tmp.split('-')
            if tmp1[0].lower() == lib['name'].lower():
                lib['task'] = task['status']
                lib['phpversions'] = []
                lib['phpversions'].append(tmp1[1])
        if phpini.find(lib['check']) == -1:
            lib['status'] = False
        else:
            lib['status'] = True
        libs.append(lib)
    return mw.returnJson(True, 'OK!', libs)
Exemplo n.º 14
0
 def delPanelInfoApi(self):
     mid = request.form.get('id', '')
     isExists = mw.M('panel').where('id=?', (mid,)).count()
     if not isExists:
         return mw.returnJson(False, '指定面板资料不存在!')
     mw.M('panel').where('id=?', (mid,)).delete()
     return mw.returnJson(True, '删除成功!')
Exemplo n.º 15
0
    def addAcceptPortApi(self):

        if not self.getFwStatus():
            return mw.returnJson(False, '防火墙启动时,才能添加规则!')

        import re
        import time
        port = request.form.get('port', '').strip()
        ps = request.form.get('ps', '').strip()
        stype = request.form.get('type', '').strip()

        rep = "^\d{1,5}(:\d{1,5})?$"
        if not re.search(rep, port):
            return mw.returnJson(False, '端口范围不正确!')

        if mw.M('firewall').where("port=?", (port,)).count() > 0:
            return mw.returnJson(False, '您要放行的端口已存在,无需重复放行!')

        msg = mw.getInfo('放行端口[{1}]成功', (port,))
        mw.writeLog("防火墙管理", msg)
        addtime = time.strftime('%Y-%m-%d %X', time.localtime())
        mw.M('firewall').add('port,ps,addtime', (port, ps, addtime))

        self.addAcceptPort(port)
        self.firewallReload()
        return mw.returnJson(True, '添加放行(' + port + ')端口成功!')
Exemplo n.º 16
0
def binLog():
    args = getArgs()
    conf = getConf()
    con = mw.readFile(conf)

    if con.find('#log-bin=mysql-bin') != -1:
        if args.has_key('status'):
            return mw.returnJson(False, '0')
        con = con.replace('#log-bin=mysql-bin', 'log-bin=mysql-bin')
        con = con.replace('#binlog_format=mixed', 'binlog_format=mixed')
        mw.execShell('sync')
        restart()
    else:
        path = getDataDir()
        if args.has_key('status'):
            dsize = 0
            for n in os.listdir(path):
                if len(n) < 9:
                    continue
                if n[0:9] == 'mysql-bin':
                    dsize += os.path.getsize(path + '/' + n)
            return mw.returnJson(True, dsize)
        con = con.replace('log-bin=mysql-bin', '#log-bin=mysql-bin')
        con = con.replace('binlog_format=mixed', '#binlog_format=mixed')
        mw.execShell('sync')
        restart()
        mw.execShell('rm -f ' + path + '/mysql-bin.*')

    mw.writeFile(conf, con)
    return mw.returnJson(True, '设置成功!')
Exemplo n.º 17
0
    def setFwApi(self):
        if mw.isAppleSystem():
            return mw.returnJson(True, '开发机不能设置!')

        status = request.form.get('status', '1')
        if status == '1':
            if self.__isUfw:
                mw.execShell('/usr/sbin/ufw stop')
                return
            if self.__isFirewalld:
                mw.execShell('systemctl stop firewalld.service')
                mw.execShell('systemctl disable firewalld.service')
            elif self.__isMac:
                pass
            else:
                mw.execShell('/etc/init.d/iptables save')
                mw.execShell('/etc/init.d/iptables stop')
        else:
            if self.__isUfw:
                mw.execShell('/usr/sbin/ufw start')
                return
            if self.__isFirewalld:
                mw.execShell('systemctl start firewalld.service')
                mw.execShell('systemctl enable firewalld.service')
            elif self.__isMac:
                pass
            else:
                mw.execShell('/etc/init.d/iptables save')
                mw.execShell('/etc/init.d/iptables restart')

        return mw.returnJson(True, '设置成功!')
Exemplo n.º 18
0
    def setFileAccessApi(self):

        if mw.isAppleSystem():
            return mw.returnJson(True, '开发机不设置!')

        filename = request.form.get('filename', '').encode('utf-8')
        user = request.form.get('user', '').encode('utf-8')
        access = request.form.get('access', '755')
        sall = '-R'
        try:
            if not self.checkDir(filename):
                return mw.returnJson(False, '请不要花样作死')

            if not os.path.exists(filename):
                return mw.returnJson(False, '指定文件不存在!')

            os.system('chmod ' + sall + ' ' + access + " '" + filename + "'")
            os.system('chown ' + sall + ' ' + user + ':' + user + " '" +
                      filename + "'")
            msg = mw.getInfo('设置[{1}]权限为[{2}]所有者为[{3}]', (
                filename,
                access,
                user,
            ))
            mw.writeLog('文件管理', msg)
            return mw.returnJson(True, '设置成功!')
        except:
            return mw.returnJson(False, '设置失败!')
Exemplo n.º 19
0
    def delAcceptPortApi(self):
        port = request.form.get('port', '').strip()
        sid = request.form.get('id', '').strip()
        mw_port = mw.readFile('data/port.pl')
        try:
            if(port == mw_port):
                return mw.returnJson(False, '失败,不能删除当前面板端口!')
            if self.__isUfw:
                mw.execShell('ufw delete allow ' + port + '/tcp')
            else:
                if self.__isFirewalld:
                    mw.execShell(
                        'firewall-cmd --permanent --zone=public --remove-port=' + port + '/tcp')
                    mw.execShell(
                        'firewall-cmd --permanent --zone=public --remove-port=' + port + '/udp')
                else:
                    mw.execShell(
                        'iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT')
            msg = mw.getInfo('删除防火墙放行端口[{1}]成功!', (port,))
            mw.writeLog("防火墙管理", msg)
            mw.M('firewall').where("id=?", (sid,)).delete()

            self.firewallReload()
            return mw.returnJson(True, '删除成功!')
        except Exception as e:
            return mw.returnJson(False, '删除失败!:' + str(e))
Exemplo n.º 20
0
def setRootPwd():
    args = getArgs()
    data = checkArgs(args, ['password'])
    if not data[0]:
        return data[1]

    password = args['password']
    try:
        pdb = pMysqlDb()
        result = pdb.query("show databases")
        isError = isSqlError(result)
        if isError != None:
            return isError

        m_version = mw.readFile(getServerDir() + '/version.pl')
        if m_version.find('5.7') == 0 or m_version.find('8.0') == 0:
            pdb.execute(
                "UPDATE mysql.user SET authentication_string='' WHERE user='******'")
            pdb.execute(
                "ALTER USER 'root'@'localhost' IDENTIFIED BY '%s'" % password)
            pdb.execute(
                "ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '%s'" % password)
        else:
            result = pdb.execute(
                "update mysql.user set Password=password('" + password + "') where User='******'")
        pdb.execute("flush privileges")
        pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (password,))
        return mw.returnJson(True, '数据库root密码修改成功!')
    except Exception as ex:
        return mw.returnJson(False, '修改错误:' + str(ex))
Exemplo n.º 21
0
def delDb():
    args = getArgs()
    data = checkArgs(args, ['id', 'name'])
    if not data[0]:
        return data[1]
    try:
        id = args['id']
        name = args['name']
        psdb = pSqliteDb('databases')
        pdb = pMysqlDb()
        find = psdb.where("id=?", (id,)).field(
            'id,pid,name,username,password,accept,ps,addtime').find()
        accept = find['accept']
        username = find['username']

        # 删除MYSQL
        result = pdb.execute("drop database `" + name + "`")
        isError = isSqlError(result)
        if isError != None:
            return isError

        users = pdb.query(
            "select Host from mysql.user where User='******' AND Host!='localhost'")
        pdb.execute("drop user '" + username + "'@'localhost'")
        for us in users:
            pdb.execute("drop user '" + username + "'@'" + us[0] + "'")
        pdb.execute("flush privileges")

        # 删除SQLITE
        psdb.where("id=?", (id,)).delete()
        return mw.returnJson(True, '删除成功!')
    except Exception as ex:
        return mw.returnJson(False, '删除失败!' + str(ex))
Exemplo n.º 22
0
def addCollection():
    args = getArgs()
    data = checkArgs(args, ['name'])
    if not data[0]:
        return data[1]

    name = args['name']
    solr_bin = getServerDir() + "/bin/solr"

    retdata = runShell(solr_bin + ' create -c ' + name)
    if retdata[1] != "":
        return mw.returnJson(False, '添加失败!:' + retdata[1])

    sc_path = getServerDir() + "/server/solr/" + name + "/conf/solrconfig.xml"
    sc_path_tpl = getPluginDir() + "/tpl/solrconfig.xml"
    content = mw.readFile(sc_path_tpl)
    mw.writeFile(sc_path, content)

    sd_path = getServerDir() + "/server/solr/" + name + "/conf/db-data-config.xml"
    sd_path_tpl = getPluginDir() + "/tpl/db-data-config.xml"
    content = mw.readFile(sd_path_tpl)
    mw.writeFile(sd_path, content)

    sd_path = getServerDir() + "/server/solr/" + name + "/conf/managed-schema"
    sd_path_tpl = getPluginDir() + "/tpl/managed-schema"
    content = mw.readFile(sd_path_tpl)
    mw.writeFile(sd_path, content)

    return mw.returnJson(True, '添加成功!:' + retdata[0])
Exemplo n.º 23
0
    def addDropAddressApi(self):
        import re
        port = request.form.get('port', '').strip()
        ps = request.form.get('ps', '').strip()

        rep = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$"
        if not re.search(rep, port):
            return mw.returnJson(False, '您输入的IP地址不合法!')
        address = port
        if mw.M('firewall').where("port=?", (address,)).count() > 0:
            return mw.returnJson(False, '您要放屏蔽的IP已存在屏蔽列表,无需重复处理!')
        if self.__isUfw:
            mw.execShell('ufw deny from ' + address + ' to any')
        else:
            if self.__isFirewalld:
                cmd = 'firewall-cmd --permanent --add-rich-rule=\'rule family=ipv4 source address="' + \
                    address + '" drop\''
                mw.execShell(cmd)
            else:
                cmd = 'iptables -I INPUT -s ' + address + ' -j DROP'
                mw.execShell(cmd)

        msg = mw.getInfo('屏蔽IP[{1}]成功!', (address,))
        mw.writeLog("防火墙管理", msg)
        addtime = time.strftime('%Y-%m-%d %X', time.localtime())
        mw.M('firewall').add('port,ps,addtime', (address, ps, addtime))
        self.firewallReload()
        return mw.returnJson(True, '添加成功!')
Exemplo n.º 24
0
    def syncDateApi(self):
        if mw.isAppleSystem():
            return mw.returnJson(True, '开发系统不必同步时间!')

        data = mw.execShell('ntpdate -s time.nist.gov')
        if data[0] == '':
            return mw.returnJson(True, '同步成功!')
        return mw.returnJson(False, '同步失败:' + data[0])
Exemplo n.º 25
0
 def indexSortApi(self):
     sort = request.form.get('ssort', '')
     if sort.strip() == '':
         return mw.returnJson(False, '排序数据不能为空!')
     data = self.setIndexSort(sort)
     if data:
         return mw.returnJson(True, '成功!')
     return mw.returnJson(False, '失败!')
Exemplo n.º 26
0
 def closePanelApi(self):
     filename = 'data/close.pl'
     if os.path.exists(filename):
         os.remove(filename)
         return mw.returnJson(True, '开启成功')
     mw.writeFile(filename, 'True')
     mw.execShell("chmod 600 " + filename)
     mw.execShell("chown root.root " + filename)
     return mw.returnJson(True, '面板已关闭!')
Exemplo n.º 27
0
    def checkApi(self):
        name = request.form.get('name', '')
        if name.strip() == '':
            return mw.returnJson(False, "缺少插件名称!", ())

        infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'
        if not os.path.exists(infoJsonPos):
            return mw.returnJson(False, "配置文件不存在!", ())
        return mw.returnJson(True, "插件存在!", ())
Exemplo n.º 28
0
    def batchPasteApi(self):
        path = request.form.get('path', '').encode('utf-8')
        stype = request.form.get('type', '').encode('utf-8')
        # filename = request.form.get('filename', '').encode('utf-8')
        import shutil
        if not self.checkDir(path):
            return mw.returnJson(False, '请不要花样作死!')
        i = 0
        myfiles = json.loads(session['selected']['data'])
        l = len(myfiles)
        if stype == '1':
            for key in myfiles:
                i += 1
                mw.writeSpeed(key, i, l)
                try:

                    sfile = session['selected']['path'] + '/' + key.encode(
                        'utf-8')
                    dfile = path + '/' + key.encode('utf-8')

                    if os.path.isdir(sfile):
                        shutil.copytree(sfile, dfile)
                    else:
                        shutil.copyfile(sfile, dfile)
                    stat = os.stat(sfile)
                    os.chown(dfile, stat.st_uid, stat.st_gid)
                except:
                    continue
            msg = mw.getInfo('从[{1}]批量复制到[{2}]成功', (
                session['selected']['path'],
                path,
            ))
            mw.writeLog('文件管理', msg)
        else:
            for key in myfiles:
                try:
                    i += 1
                    mw.writeSpeed(key, i, l)

                    sfile = session['selected']['path'] + '/' + key.encode(
                        'utf-8')
                    dfile = path + '/' + key.encode('utf-8')

                    shutil.move(sfile, dfile)
                except:
                    continue
            msg = mw.getInfo('从[{1}]批量移动到[{2}]成功', (
                session['selected']['path'],
                path,
            ))
            mw.writeLog('文件管理', msg)
        mw.writeSpeed(None, 0, 0)
        errorCount = len(myfiles) - i
        del (session['selected'])
        msg = mw.getInfo('批量操作成功[{1}],失败[{2}]', (str(i), str(errorCount)))
        return mw.returnJson(True, msg)
Exemplo n.º 29
0
def getHomePage():
    try:
        port = getPort()
        ip = '127.0.0.1'
        if not mw.isAppleSystem():
            ip = mw.getLocalIp()
        url = 'http://' + ip + ':' + port + '/index.php'
        return mw.returnJson(True, 'OK', url)
    except Exception as e:
        return mw.returnJson(False, '插件未启动!')
Exemplo n.º 30
0
 def setPasswordApi(self):
     password1 = request.form.get('password1', '')
     password2 = request.form.get('password2', '')
     if password1 != password2:
         return mw.returnJson(False, '两次输入的密码不一致,请重新输入!')
     if len(password1) < 5:
         return mw.returnJson(False, '用户密码不能小于5位!')
     mw.M('users').where("username=?", (session['username'],)).setField(
         'password', mw.md5(password1.strip()))
     return mw.returnJson(True, '密码修改成功!')