예제 #1
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 public.isAppleSystem():
        public.execShell("sed -i .bak '/^\(" + username + "\)/d' " + path)
    else:
        public.execShell("sed -i '/^\(" + username + "\)/d' " + path)
    # print 'echo "' + username + "    l2tpd    " + password + "      *\" >>"
    # + path
    ret = public.execShell("echo \"" + username +
                           "    l2tpd    " + password + "       *\" >>" + path)
    if ret[1] == '':
        return public.returnJson(True, '修改成功!')
    return public.returnJson(False, '修改失败')
예제 #2
0
def initDreplace():

    ddir = getServerDir() + '/workers'
    if not os.path.exists(ddir):
        sdir = getPluginDir() + '/workers'
        public.execShell('cp -rf ' + sdir + ' ' + getServerDir())

    cfg = getServerDir() + '/db.cfg'
    if not os.path.exists(cfg):
        cfg_tpl = getPluginDir() + '/workers/db.cfg'
        content = public.readFile(cfg_tpl)
        public.writeFile(cfg, content)

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

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

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

    return file_bin
예제 #3
0
def initdUinstall():
    if not app_debug:
        if public.isAppleSystem():
            return "Apple Computer does not support"
    initd_bin = getInitDFile()
    os.remove(initd_bin)
    public.execShell('chkconfig --del ' + getPluginName())
    return 'ok'
예제 #4
0
def initConf():
    l2tp_cs = getServerDir() + '/chap-secrets'
    if not os.path.exists(l2tp_cs):
        public.execShell('cp -rf ' + getPluginDir() +
                         '/tmp/chap-secrets' + ' ' + getServerDir())

    l2tp_is = getServerDir() + '/ipsec.secrets'
    if not os.path.exists(l2tp_is):
        public.execShell('cp -rf ' + getPluginDir() +
                         '/tmp/ipsec.secrets' + ' ' + getServerDir())
예제 #5
0
def initdInstall():
    import shutil
    if not app_debug:
        if public.isAppleSystem():
            return "Apple Computer does not support"

    mysql_bin = initDreplace()
    initd_bin = getInitDFile()
    shutil.copyfile(mysql_bin, initd_bin)
    public.execShell('chmod +x ' + initd_bin)
    public.execShell('chkconfig --add ' + getPluginName())
    return 'ok'
예제 #6
0
def start():

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

    file = initDreplace()

    data = public.execShell(file + ' start')
    if data[1] == '':
        return 'ok'
    return data[1]
예제 #7
0
def start():
    file = initDreplace()

    data = public.execShell(file + ' start')
    if data[1] == '':
        return 'ok'
    return data[1]
예제 #8
0
    def deleteDirApi(self):
        path = request.form.get('path', '').encode('utf-8')
        if not os.path.exists(path):
            return public.returnJson(False, '指定文件不存在!')

        # 检查是否为.user.ini
        if path.find('.user.ini'):
            os.system("chattr -i '" + path + "'")
        try:
            if os.path.exists('data/recycle_bin.pl'):
                if self.mvRecycleBin(path):
                    return public.returnJson(True, '已将文件移动到回收站!')
            public.execShell('rm -rf ' + path)
            public.writeLog('文件管理', '删除文件成功!', (path,))
            return public.returnJson(True, '删除文件成功!')
        except:
            return public.returnJson(False, '删除文件失败!')
예제 #9
0
def stop():
    file = initDreplace()
    data = public.execShell(file + ' stop')
    # cmd = "ps -ef | grep qbittorrent-nox |grep -v grep |awk '{print $2}' | xargs kill"
    # public.execShell(cmd)
    if data[1] == '':
        return 'ok'
    return data[1]
예제 #10
0
def restart():
    if public.isAppleSystem():
        return "Apple Computer does not support"

    data = public.execShell('service xl2tpd restart')
    if data[0] == '':
        return 'ok'
    return data[1]
예제 #11
0
 def setFileAccept(self, filename):
     auth = 'www:www'
     if public.getOs() == 'darwin':
         user = public.execShell(
             "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
         auth = user + ':staff'
     os.system('chown -R ' + auth + ' ' + filename)
     os.system('chmod -R 755 ' + filename)
예제 #12
0
def addUser():
    if public.isAppleSystem():
        return public.returnJson(False, "Apple Computer does not support")

    args = getArgs()
    data = checkArgs(args, ['username'])
    if not data[0]:
        return data[1]
    ret = public.execShell('echo ' + args['username'] + '|l2tp -a')
    if ret[1] == '':
        return public.returnJson(True, '添加成功!:' + ret[0])
    return public.returnJson(False, '添加失败:' + ret[0])
예제 #13
0
    def writeShell(self, config):
        u_file = '/var/spool/cron/crontabs/root'
        if not os.path.exists(u_file):
            file = '/var/spool/cron/root'
            if public.isAppleSystem():
                file = '/etc/crontab'
        else:
            file = u_file

        if not os.path.exists(file):
            public.writeFile(file, '')
        conf = public.readFile(file)
        conf += config + "\n"
        if public.writeFile(file, conf):
            if not os.path.exists(u_file):
                public.execShell("chmod 600 '" + file +
                                 "' && chown root.root " + file)
            else:
                public.execShell("chmod 600 '" + file +
                                 "' && chown root.crontab " + file)
            return True
        return public.returnJson(False, '文件写入失败,请检查是否开启系统加固功能!')
예제 #14
0
 def crondReload(self):
     if public.isAppleSystem():
         if os.path.exists('/etc/crontab'):
             pass
             # public.execShell('/usr/sbin/cron restart')
     else:
         if os.path.exists('/etc/init.d/crond'):
             public.execShell('/etc/init.d/crond reload')
         elif os.path.exists('/etc/init.d/cron'):
             public.execShell('service cron restart')
         else:
             public.execShell("systemctl reload crond")
예제 #15
0
def initInitD():
    script = public.getRunDir() + '/scripts/init.d/mw.tpl'
    script_bin = public.getRunDir() + '/scripts/init.d/mw'
    # if os.path.exists(script_bin):
    #     return

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

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

    if not public.isAppleSystem():
        initd_bin = '/etc/init.d/mw'
        if not os.path.exists(initd_bin):
            import shutil
            shutil.copyfile(script_bin, initd_bin)
            public.execShell('chmod +x ' + initd_bin)
        #加入自启动
        public.execShell('chkconfig --add mw')
예제 #16
0
def reload():
    data = public.execShell('service xl2tpd reload')
    if data[0] == '':
        return 'ok'
    return data[1]
예제 #17
0
def status():
    cmd = "ps -ef|grep xl2tpd |grep -v grep | grep -v python | awk '{print $2}'"
    data = public.execShell(cmd)
    if data[0] == '':
        return 'stop'
    return 'start'
예제 #18
0
    def getShell(self, param):
        # try:
        stype = param['stype']
        if stype == 'toFile':
            shell = param.sFile
        else:
            head = "#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n"
            log = '.log'

            wheres = {
                'path':
                head + "python " + public.getServerDir() +
                "/mdserver-web/scripts/backup.py path " + param['sname'] +
                " " + str(param['save']),
                'site':
                head + "python " + public.getServerDir() +
                "/mdserver-web/scripts/backup.py site " + param['sname'] +
                " " + str(param['save']),
                'database':
                head + "python " + public.getServerDir() +
                "/mdserver-web/scripts/backup.py database " + param['sname'] +
                " " + str(param['save']),
                'logs':
                head + "python " + public.getServerDir() +
                "/mdserver-web/scripts/logs_backup.py " + param['sname'] +
                log + " " + str(param['save']),
                'rememory':
                head + "/bin/bash " + public.getServerDir() +
                '/mdserver-web/scripts/rememory.sh'
            }
            if param['backup_to'] != 'localhost':
                cfile = public.getServerDir(
                ) + "/mdserver-web/plugin/" + param['backup_to'] + "/" + param[
                    'backup_to'] + "_main.py"
                if not os.path.exists(cfile):
                    cfile = public.getServerDir() + "/mdserver-web/script/backup_" + \
                        param['backup_to'] + ".py"
                wheres = {
                    'path':
                    head + "python " + cfile + " path " + param['sname'] +
                    " " + str(param['save']),
                    'site':
                    head + "python " + cfile + " site " + param['sname'] +
                    " " + str(param['save']),
                    'database':
                    head + "python " + cfile + " database " + param['sname'] +
                    " " + str(param['save']),
                    'logs':
                    head + "python " + public.getServerDir() +
                    "/mdserver-web/scripts/logs_backup.py " + param['sname'] +
                    log + " " + str(param['save']),
                    'rememory':
                    head + "/bin/bash " + public.getServerDir() +
                    '/mdserver-web/scripts/rememory.sh'
                }
            try:
                shell = wheres[stype]
            except:
                if stype == 'toUrl':
                    shell = head + "curl -sS --connect-timeout 10 -m 60 '" + \
                        param['urladdress'] + "'"
                else:
                    shell = head + param['sbody'].replace("\r\n", "\n")

                shell += '''
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
'''
        cronPath = public.getServerDir() + '/cron'
        if not os.path.exists(cronPath):
            public.execShell('mkdir -p ' + cronPath)
        if not 'echo' in param:
            cronName = public.md5(public.md5(str(time.time()) + '_mw'))
        else:
            cronName = param['echo']
        file = cronPath + '/' + cronName
        public.writeFile(file, self.checkScript(shell))
        public.execShell('chmod 750 ' + file)
        return cronName
예제 #19
0
def status():
    data = public.execShell(
        "ps -ef|grep qbittorrent_worker | grep -v grep | awk '{print $2}'")
    if data[0] == '':
        return 'stop'
    return 'start'
예제 #20
0
 def getDirSize(self, path):
     if public.getOs() == 'darwin':
         tmp = public.execShell('du -sh ' + path)
     else:
         tmp = public.execShell('du -sbh ' + path)
     return tmp
예제 #21
0
def reload():
    file = initDreplace()
    data = public.execShell(file + ' reload')
    if data[1] == '':
        return 'ok'
    return 'fail'
예제 #22
0
def status():
    data = public.execShell(
        "ps -ef|grep \"simdht_worker.py\" | grep -v grep | awk '{print $2}'")
    if data[0] == '':
        return 'stop'
    return 'start'