示例#1
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, '卸载执行成功!')
示例#2
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, '已将卸载任务添加到队列!')
示例#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, '已将安装任务添加到队列!')
示例#4
0
def initUserInfo():

    data = mw.M('users').where('id=?', (1, )).getField('password')
    if data == '21232f297a57a5a743894a0e4a801fc3':
        pwd = mw.getRandomString(8).lower()
        file_pw = mw.getRunDir() + '/data/default.pl'
        mw.writeFile(file_pw, pwd)
        mw.M('users').where('id=?', (1, )).setField('password', mw.md5(pwd))
示例#5
0
def check502Task():
    try:
        while True:
            if os.path.exists(mw.getRunDir() + '/data/502Task.pl'):
                check502()
            time.sleep(30)
    except:
        time.sleep(30)
        check502Task()
示例#6
0
    def callback(self, name, func, args='', script='index'):
        package = mw.getRunDir() + '/plugins/' + name
        if not os.path.exists(package):
            return (False, "插件不存在!")

        sys.path.append(package)
        eval_str = "__import__('" + script + "')." + func + '(' + args + ')'
        newRet = eval(eval_str)
        if mw.isAppleSystem():
            print('callback', eval_str)

        return (True, newRet)
示例#7
0
def initInitD():
    script = mw.getRunDir() + '/scripts/init.d/mw.tpl'
    script_bin = mw.getRunDir() + '/scripts/init.d/mw'
    # if os.path.exists(script_bin):
    #     return

    content = mw.readFile(script)
    content = content.replace("{$SERVER_PATH}", mw.getRunDir())

    mw.writeFile(script_bin, content)
    mw.execShell('chmod +x ' + script_bin)

    mw.setHostAddr(mw.getLocalIp())

    if not mw.isAppleSystem():
        initd_bin = '/etc/init.d/mw'
        if not os.path.exists(initd_bin):
            import shutil
            shutil.copyfile(script_bin, initd_bin)
            mw.execShell('chmod +x ' + initd_bin)
        # 加入自启动
        mw.execShell('chkconfig --add mw')
示例#8
0
 def setPanelSslApi(self):
     sslConf = mw.getRunDir() + '/data/ssl.pl'
     if os.path.exists(sslConf):
         os.system('rm -f ' + sslConf)
         return mw.returnJson(True, 'SSL已关闭,请使用http协议访问面板!')
     else:
         os.system('pip install cffi==1.10')
         os.system('pip install cryptography==2.1')
         os.system('pip install pyOpenSSL==16.2')
         try:
             if not self.createSSL():
                 return mw.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!<p>请尝试手动安装: pip install pyOpenSSL</p>')
             mw.writeFile(sslConf, 'True')
         except Exception as ex:
             return mw.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!<p>请尝试手动安装: pip install pyOpenSSL</p>')
         return mw.returnJson(True, '开启成功,请使用https协议访问面板!')
示例#9
0
    def run(self, name, func, version, args='', script='index'):
        path = mw.getRunDir() + '/' + self.__plugin_dir + \
            '/' + name + '/' + script + '.py'
        py = 'python ' + path

        if args == '':
            py_cmd = py + ' ' + func + ' ' + version
        else:
            py_cmd = py + ' ' + func + ' ' + version + ' ' + args

        if not os.path.exists(path):
            return ('', '')
        data = mw.execShell(py_cmd)
        # data = os.popen(py_cmd).read()

        if mw.isAppleSystem():
            print 'run', py_cmd
        # print os.path.exists(py_cmd)
        return (data[0].strip(), data[1].strip())
示例#10
0
    def zip(self, sfile, dfile, stype, path):
        if sfile.find(',') == -1:
            if not os.path.exists(path + '/' + sfile):
                return mw.returnMsg(False, '指定文件不存在!')

        try:
            tmps = mw.getRunDir() + '/tmp/panelExec.log'
            if stype == 'zip':
                os.system("cd '" + path + "' && zip '" + dfile + "' -r '" +
                          sfile + "' > " + tmps + " 2>&1")
            else:
                sfiles = ''
                for sfile in sfile.split(','):
                    if not sfile:
                        continue
                    sfiles += " '" + sfile + "'"
                os.system("cd '" + path + "' && tar -zcvf '" + dfile + "' " +
                          sfiles + " > " + tmps + " 2>&1")
            self.setFileAccept(dfile)
            mw.writeLog("文件管理", '文件压缩成功!', (sfile, dfile))
            return mw.returnJson(True, '文件压缩成功!')
        except:
            return mw.returnJson(False, '文件压缩失败!')
示例#11
0
def restartMw():
    time.sleep(1)
    cmd = mw.getRunDir() + '/scripts/init.d/mw restart'
    mw.execShell(cmd)
示例#12
0
def close():
    if not os.path.exists('data/close.pl'):
        return redirect('/')
    data = {}
    data['cmd'] = 'rm -rf ' + mw.getRunDir() + '/data/close.pl'
    return render_template('close.html', data=data)
示例#13
0
 def rememoryApi(self):
     os.system('sync')
     scriptFile = mw.getRunDir() + '/script/rememory.sh'
     mw.execShell("/bin/bash " + scriptFile)
     data = self.getMemInfo()
     return mw.getJson(data)