示例#1
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, '面板已关闭!')
示例#2
0
def initdUinstall():
    if not app_debug:
        os_name = mw.getOs()
        if os_name == 'darwin':
            return "Apple Computer does not support"
    initd_bin = getInitDFile()
    os.remove(initd_bin)
    mw.execShell('chkconfig --del ' + getPluginName())
    return 'ok'
示例#3
0
def nodeLogClearErr():
    args = getArgs()
    data = checkArgs(args, ['pname'])
    if not data[0]:
        return data[1]
    pname = args['pname']
    path = pm2LogDir() + '/logs/' + pname + '-error.log'
    mw.execShell('rm -rf ' + path + '&& touch ' + path)
    return mw.returnJson(True, '清空错误成功')
示例#4
0
def initdUinstall():
    if not app_debug:
        mw.execShell('chkconfig --del ' + getPluginName())

    initd_bin = getInitDFile()

    if os.path.exists(initd_bin):
        os.remove(initd_bin)
    return 'ok'
示例#5
0
def installMod():
    args = getArgs()
    data = checkArgs(args, ['mname'])
    if not data[0]:
        return data[1]

    mname = args['mname']
    mw.execShell(__SR + 'npm install ' + mname + ' -g')
    return mw.returnJson(True, '安装成功!')
示例#6
0
def initdInstall():
    source_bin = initDreplace()
    initd_bin = getInitDFile()
    shutil.copyfile(source_bin, initd_bin)
    mw.execShell('chmod +x ' + initd_bin)

    if not app_debug:
        mw.execShell('chkconfig --add ' + getPluginName())
    return 'ok'
示例#7
0
def initdUinstall():
    if not app_debug:
        if mw.isAppleSystem():
            return "Apple Computer does not support"

    mw.execShell('chkconfig --del ' + getPluginName())
    initd_bin = getInitDFile()
    os.remove(initd_bin)
    return 'ok'
示例#8
0
def getPhpinfo(v):
    checkPhpinfoFile(v)
    sPath = mw.getRootDir() + '/phpinfo/' + v
    mw.execShell("rm -rf " + mw.getRootDir() + '/phpinfo')
    mw.execShell("mkdir -p " + sPath)
    mw.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>')
    url = 'http://127.0.0.1/' + v + '/phpinfo.php'
    phpinfo = mw.httpGet(url)
    os.system("rm -rf " + mw.getRootDir() + '/phpinfo')
    return phpinfo
示例#9
0
def initMysqlPwd():
    time.sleep(5)

    serverdir = getServerDir()

    pwd = mw.getRandomString(16)
    cmd_pass = serverdir + '/bin/mysqladmin -uroot password ' + pwd
    pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
    mw.execShell(cmd_pass)
    return True
示例#10
0
def initConf():
    l2tp_cs = getServerDir() + '/chap-secrets'
    if not os.path.exists(l2tp_cs):
        mw.execShell('cp -rf ' + getPluginDir() +
                     '/tmp/chap-secrets' + ' ' + getServerDir())

    l2tp_is = getServerDir() + '/ipsec.secrets'
    if not os.path.exists(l2tp_is):
        mw.execShell('cp -rf ' + getPluginDir() +
                     '/tmp/ipsec.secrets' + ' ' + getServerDir())
示例#11
0
def initMysqlData():
    datadir = getDataDir()
    if not os.path.exists(datadir + '/mysql'):
        serverdir = getServerDir()
        user = pGetDbUser()
        cmd = 'cd ' + serverdir + ' && ./scripts/mysql_install_db --user='******' --basedir=' + serverdir + ' --ldata=' + datadir
        mw.execShell(cmd)
        return 0
    return 1
示例#12
0
def initdUinstall():
    if not app_debug:
        if mw.isAppleSystem():
            return "Apple Computer does not support"

    _csvn = getServerDir() + '/bin/csvn'
    _csvn_httpd = getServerDir() + '/bin/csvn-httpd'

    ret_csvn = mw.execShell(_csvn + ' remove')
    ret_csvn_httpd = mw.execShell(_csvn_httpd + ' remove')
    return 'ok'
示例#13
0
def mkdirAll():
    content = mw.readFile(getConf())
    rep = 'path\s*=\s*(.*)'
    p = re.compile(rep)
    tmp = p.findall(content)

    for x in tmp:
        if x.find('binlog') != -1:
            mw.execShell('mkdir -p ' + x)
        else:
            mw.execShell('mkdir -p ' + os.path.dirname(x))
示例#14
0
def initdInstall():
    import shutil
    if not app_debug:
        if mw.isAppleSystem():
            return "Apple Computer does not support"

    source_bin = initDreplace()
    initd_bin = getInitDFile()
    shutil.copyfile(source_bin, initd_bin)
    mw.execShell('chmod +x ' + initd_bin)
    mw.execShell('chkconfig --add ' + getPluginName())
    return 'ok'
示例#15
0
def uninstallMod():
    args = getArgs()
    data = checkArgs(args, ['mname'])
    if not data[0]:
        return data[1]

    mname = args['mname']
    myNot = ['pm2', 'npm']
    if mname in myNot:
        return mw.returnJson(False, '不能卸载[' + mname + ']')
    mw.execShell(__SR + 'npm uninstall ' + mname + ' -g')
    return mw.returnJson(True, '卸载成功!')
示例#16
0
def projectAdd():
    args = getArgs()
    if not 'name' in args:
        return 'project name missing'
    path = getServerDir() + '/bin/svnadmin'
    dest = getServerDir() + '/data/repositories/' + args['name']
    cmd = path + ' create ' + dest
    data = mw.execShell(cmd)
    if data[1] == '':
        mw.execShell('chown -R csvn:csvn ' + dest)
        return 'ok'
    return 'fail'
示例#17
0
def restart():
    shell_cmd = 'service  ' + getPluginName() + ' restart'
    data = mw.execShell(shell_cmd)

    log_file = getLog()
    if os.path.exists(log_file):
        clear_log_cmd = "echo '' > " + log_file
        mw.execShell(clear_log_cmd)

    if data[0] == '':
        return 'ok'
    return data[1]
示例#18
0
def stop():
    if mw.isAppleSystem():
        file = initDreplace()
        data = mw.execShell(file + ' stop')
        if data[1] == '':
            return 'ok'
        return 'fail'

    data = mw.execShell('systemctl stop mongod')
    if data[1] == '':
        return 'ok'
    return 'fail'
示例#19
0
def reload():
    if mw.isAppleSystem():
        file = initDreplace()
        data = mw.execShell(file + ' reload')
        if data[1] == '':
            return 'ok'
        return 'fail'

    data = mw.execShell('systemctl reload mongod')
    if data[1] == '':
        return 'ok'
    return 'fail'
示例#20
0
    def getSshInfoApi(self):
        file = '/etc/ssh/sshd_config'
        conf = mw.readFile(file)
        rep = "#*Port\s+([0-9]+)\s*\n"
        port = re.search(rep, conf).groups(0)[0]

        isPing = True
        try:
            if mw.isAppleSystem():
                isPing = True
            else:
                file = '/etc/sysctl.conf'
                conf = mw.readFile(file)
                rep = "#*net\.ipv4\.icmp_echo_ignore_all\s*=\s*([0-9]+)"
                tmp = re.search(rep, conf).groups(0)[0]
                if tmp == '1':
                    isPing = False
        except:
            isPing = True

        import system_api
        panelsys = system_api.system_api()
        version = panelsys.getSystemVersion()
        if os.path.exists('/usr/bin/apt-get'):
            if os.path.exists('/etc/init.d/sshd'):
                cmd = "service sshd status | grep -P '(dead|stop)'|grep -v grep"
                status = mw.execShell(cmd)
            else:
                cmd = "service ssh status | grep -P '(dead|stop)'|grep -v grep"
                status = mw.execShell(cmd)
        else:
            if version.find(' 7.') != -1:
                cmd = "systemctl status sshd.service | grep 'dead'|grep -v grep"
                status = mw.execShell(cmd)
            else:
                cmd = "/etc/init.d/sshd status | grep -e 'stopped' -e '已停'|grep -v grep"
                status = mw.execShell(cmd)
        if len(status[0]) > 3:
            status = False
        else:
            status = True

        data = {}
        data['port'] = port

        data['status'] = status
        data['ping'] = isPing
        if mw.isAppleSystem():
            data['firewall_status'] = False
        else:
            data['firewall_status'] = self.getFwStatus()
        return mw.getJson(data)
示例#21
0
def stop():
    path = mw.getServerDir() + "/openresty/nginx/conf/waf"
    if os.path.exists(path):
        cmd = 'rm -rf ' + path
        mw.execShell(cmd)

    path = getConf()
    conf = mw.readFile(path)
    conf = conf.replace('include luawaf.conf;', "#include luawaf.conf;")

    mw.writeFile(path, conf)
    mw.restartWeb()
    return 'ok'
示例#22
0
def initdInstall():
    import shutil
    if not app_debug:
        os_name = mw.getOs()
        if os_name == 'darwin':
            return "Apple Computer does not support"

    mem_bin = initDreplace()
    initd_bin = getInitDFile()
    shutil.copyfile(mem_bin, initd_bin)
    mw.execShell('chmod +x ' + initd_bin)
    mw.execShell('chkconfig --add ' + getPluginName())
    return 'ok'
示例#23
0
def pm2VerList():
    # 获取Node版本列表
    import re
    result = {}
    rep = 'v\d+\.\d+\.\d+'

    cmd = __SR + ' nvm ls-remote|grep -v v0|grep -v iojs'
    # print cmd
    tmp = mw.execShell(cmd)
    result['list'] = re.findall(rep, tmp[0])
    tmp = mw.execShell(__SR + "nvm version")
    result['version'] = tmp[0].strip()
    return mw.returnJson(True, 'ok', result)
示例#24
0
def projectScriptUnload():
    args = getArgs()
    if not 'pname' in args:
        return 'project name missing'

    post_commit_file = getServerDir() + '/data/repositories/' + '/' + \
        args['pname'] + '/hooks/post-commit'
    mw.execShell('rm -f ' + post_commit_file)

    commit_file = getServerDir() + '/data/repositories/' + '/' + \
        args['pname'] + '/hooks/commit'
    mw.execShell('rm -f ' + commit_file)
    return 'ok'
示例#25
0
def start():

    cmd = "ps -ef | grep qbittorrent-nox |grep -v grep |awk '{print $2}'"
    ret = mw.execShell(cmd)
    if ret[0] == '':
        mw.execShell('qbittorrent-nox -d')

    file = initDreplace()

    data = mw.execShell(file + ' start')
    if data[1] == '':
        return 'ok'
    return data[1]
示例#26
0
def delFtp():
    args = getArgs()
    if not 'id' in args:
        return 'ftp_username missing'

    if not 'username' in args:
        return 'username missing'

    mw.execShell(getServerDir() + '/bin/pure-pw userdel ' + args['username'])
    pftpReload()
    conn = pftpDB()
    conn.where("id=?", (args['id'], )).delete()
    mw.writeLog('TYPE_FTP', 'FTP_DEL_SUCCESS', (args['username'], ))
    return 'ok'
示例#27
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))
示例#28
0
def initdInstall():
    import shutil
    if not app_debug:
        if mw.isAppleSystem():
            return "Apple Computer does not support"

    _csvn = getServerDir() + '/bin/csvn'
    _csvn_httpd = getServerDir() + '/bin/csvn-httpd'

    ret_csvn = mw.execShell(_csvn + ' install')
    ret_csvn_httpd = mw.execShell(_csvn_httpd + ' install')
    if ret_csvn[1] == '' and ret_csvn_httpd[1] == '':
        return 'ok'
    return 'fail'
示例#29
0
def initDreplace():

    file_tpl = getInitDTpl()
    service_path = os.path.dirname(os.getcwd())

    initD_path = getServerDir() + '/init.d'

    file_bin = initD_path + '/' + getPluginName()
    if not os.path.exists(initD_path):
        os.mkdir(initD_path)

        # initd replace
        content = mw.readFile(file_tpl)
        content = content.replace('{$SERVER_PATH}', service_path)
        mw.writeFile(file_bin, content)
        mw.execShell('chmod +x ' + file_bin)

    aria2_path = getServerDir() + '/aria2'
    mw.execShell('mkdir -p /tmp/download')
    if not os.path.exists(aria2_path):

        mw.execShell('mkdir -p ' + aria2_path)
        mw.execShell('touch ' + aria2_path + '/aria2.session')

        path = getPluginDir() + "/conf/aria2.conf"
        content = mw.readFile(path)
        content = content.replace('{$SERVER_PATH}', aria2_path)

        mw.writeFile(aria2_path + '/aria2.conf', content)

    return file_bin
示例#30
0
def projectListDel():
    args = getArgs()
    if not 'name' in args:
        return 'missing name!'

    file = getServerDir() + '/' + args['name'] + '.json'
    if os.path.exists(file):
        content = mw.readFile(file)
        contentObj = json.loads(content)
        asyncUser = contentObj['client_email']
        cmd = getServerDir() + '/google-cloud-sdk/bin/'
        mw.execShell(cmd + 'gcloud auth revoke ' + asyncUser)
        mw.execShell('rm -rf ' + file)
    return 'ok'