mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 01:29:26 +08:00
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
runtime: php55
|
||||
api_version: 1
|
||||
threadsafe: true
|
||||
|
||||
handlers:
|
||||
- url: /.*
|
||||
script: helloworld.php
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
echo 'Hello, GAE!';
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
@@ -1,27 +0,0 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="readme();">插件说明</p>
|
||||
<p onclick="projectList();">项目列表</p>
|
||||
</div>
|
||||
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=gae&f=js/gae.js");
|
||||
resetPluginWinWidth(720);
|
||||
readme();
|
||||
function readme(){
|
||||
var html = '<p>开发文档:https://cloud.google.com/sdk/docs/</p>';
|
||||
html += '<p>* 注意:本插件通过Google <a class="btlink" target="_blank" href="https://cloud.google.com/sdk/docs/scripting-gcloud">JSON 格式</a>赋权免交互式</p>';
|
||||
html += '<p>* 注意:添加:gcloud auth activate-service-account --key-file [KEY_FILE]</p>';
|
||||
html += '<p>* 注意:设置后,一般同步项目命令:gcloud app deploy << y</p>';
|
||||
html += '<p>* 注意:可以查看命令,把命令加入到脚本中...自动更新。</p>';
|
||||
$('.bt-w-main .soft-man-con').html(html);
|
||||
}
|
||||
</script>
|
||||
@@ -1,240 +0,0 @@
|
||||
# coding: utf-8
|
||||
|
||||
import time
|
||||
import random
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'gae'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
|
||||
return tmp
|
||||
|
||||
|
||||
def status():
|
||||
return 'start'
|
||||
|
||||
|
||||
def getAllProjectList(search):
|
||||
path = mw.getWwwDir()
|
||||
dlist = []
|
||||
if os.path.exists(path):
|
||||
for filename in os.listdir(path):
|
||||
tmp = {}
|
||||
filePath = path + '/' + filename
|
||||
if os.path.isdir(filePath):
|
||||
if search == '':
|
||||
tmp['name'] = filename
|
||||
tmp['dir'] = filePath
|
||||
dlist.append(tmp)
|
||||
else:
|
||||
if filename.find(search) != -1:
|
||||
tmp['name'] = filename
|
||||
tmp['dir'] = filePath
|
||||
dlist.append(tmp)
|
||||
return dlist
|
||||
|
||||
|
||||
def checkProjectListIsSet(data):
|
||||
dlen = len(data)
|
||||
for x in range(dlen):
|
||||
path = getServerDir() + '/' + data[x]['name'] + '.json'
|
||||
if os.path.exists(path):
|
||||
if os.path.getsize(path) == 0:
|
||||
data[x]['isset'] = False
|
||||
else:
|
||||
data[x]['isset'] = True
|
||||
else:
|
||||
data[x]['isset'] = False
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def projectListEdit():
|
||||
args = getArgs()
|
||||
if not 'name' in args:
|
||||
return 'missing name!'
|
||||
|
||||
file = getServerDir() + '/' + args['name'] + '.json'
|
||||
if not os.path.exists(file):
|
||||
mw.execShell('touch ' + file)
|
||||
return file
|
||||
|
||||
|
||||
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'
|
||||
|
||||
|
||||
def checkUserExist(cmd, user):
|
||||
data = mw.execShell(cmd + 'gcloud auth list | grep ' + user)
|
||||
if data[0] == '':
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def projectListAsync():
|
||||
import subprocess
|
||||
args = getArgs()
|
||||
if not 'name' in args:
|
||||
return 'missing name!'
|
||||
|
||||
file = getServerDir() + '/' + args['name'] + '.json'
|
||||
if not os.path.exists(file):
|
||||
return 'not configured file!'
|
||||
|
||||
content = mw.readFile(file)
|
||||
contentObj = json.loads(content)
|
||||
asyncUser = contentObj['client_email']
|
||||
cmd = getServerDir() + '/google-cloud-sdk/bin/'
|
||||
projectDir = mw.getWwwDir() + '/' + args['name']
|
||||
|
||||
if not checkUserExist(cmd, asyncUser):
|
||||
mw.execShell(
|
||||
cmd + 'gcloud auth activate-service-account --key-file ' + file)
|
||||
|
||||
pName = contentObj['project_id']
|
||||
setUserCmd = cmd + 'gcloud config set account ' + asyncUser
|
||||
setUserCmd += ' && ' + cmd + 'gcloud config set project ' + pName
|
||||
asyncCmd = setUserCmd + ' && cd ' + projectDir + \
|
||||
' && ' + cmd + 'gcloud app deploy << y'
|
||||
|
||||
taskAdd = (None, 'gae[async]',
|
||||
'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), asyncCmd)
|
||||
mw.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectListCmd():
|
||||
args = getArgs()
|
||||
if not 'name' in args:
|
||||
return 'missing name!'
|
||||
|
||||
file = getServerDir() + '/' + args['name'] + '.json'
|
||||
if not os.path.exists(file):
|
||||
return 'not configured file!'
|
||||
|
||||
content = mw.readFile(file)
|
||||
contentObj = json.loads(content)
|
||||
asyncUser = contentObj['client_email']
|
||||
cmd = getServerDir() + '/google-cloud-sdk/bin/'
|
||||
pName = contentObj['project_id']
|
||||
projectDir = mw.getWwwDir() + '/' + args['name']
|
||||
|
||||
setUserCmd = 'sudo ' + cmd + 'gcloud config set account ' + asyncUser
|
||||
setUserCmd += ' && sudo ' + cmd + 'gcloud config set project ' + pName
|
||||
asyncCmd = setUserCmd + ' && sudo cd ' + projectDir + \
|
||||
' && sudo ' + cmd + 'gcloud app deploy <<y'
|
||||
return asyncCmd
|
||||
|
||||
|
||||
def projectListUrl():
|
||||
args = getArgs()
|
||||
if not 'name' in args:
|
||||
return 'missing name!'
|
||||
|
||||
file = getServerDir() + '/' + args['name'] + '.json'
|
||||
if not os.path.exists(file):
|
||||
return 'not configured file!'
|
||||
|
||||
content = mw.readFile(file)
|
||||
contentObj = json.loads(content)
|
||||
asyncUser = contentObj['client_email']
|
||||
plist = asyncUser.split('@')
|
||||
|
||||
url = 'https://' + plist[0] + '.appspot.com'
|
||||
return url
|
||||
|
||||
|
||||
def projectList():
|
||||
args = getArgs()
|
||||
|
||||
page = 1
|
||||
page_size = 10
|
||||
search = ''
|
||||
if 'page' in args:
|
||||
page = int(args['page'])
|
||||
|
||||
if 'page_size' in args:
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
if 'search' in args:
|
||||
search = args['search']
|
||||
|
||||
dlist = getAllProjectList(search)
|
||||
dlist_sum = len(dlist)
|
||||
|
||||
start = (page - 1) * page_size
|
||||
ret_data = dlist[start:start + page_size]
|
||||
ret_data = checkProjectListIsSet(ret_data)
|
||||
|
||||
data = {}
|
||||
data['data'] = ret_data
|
||||
data['list'] = mw.getPage(
|
||||
{'count': dlist_sum, 'p': page, 'row': 10, 'tojs': 'projectList'})
|
||||
return mw.getJson(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print(status())
|
||||
elif func == 'project_list':
|
||||
print(projectList())
|
||||
elif func == 'project_list_edit':
|
||||
print(projectListEdit())
|
||||
elif func == 'project_list_del':
|
||||
print(projectListDel())
|
||||
elif func == 'project_list_async':
|
||||
print(projectListAsync())
|
||||
elif func == 'project_list_cmd':
|
||||
print(projectListCmd())
|
||||
elif func == 'project_list_url':
|
||||
print(projectListUrl())
|
||||
else:
|
||||
print('error')
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"title":"GAE",
|
||||
"tip":"soft",
|
||||
"name":"gae",
|
||||
"ps":"GAE是Google用于WEB应用程序的开发和托管的平台",
|
||||
"versions": "0.1",
|
||||
"shell":"install.sh",
|
||||
"checks":"server/gae",
|
||||
"path":"server/gae",
|
||||
"author":"mdserver-web",
|
||||
"home":"https://github.com/midoks/mdserver-web",
|
||||
"date":"2018-11-30",
|
||||
"pid":"5"
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
Install_gae()
|
||||
{
|
||||
mkdir -p ${serverPath}/gae
|
||||
mkdir -p ${serverPath}/source/gae
|
||||
|
||||
os=`uname`
|
||||
if [ "Darwin" == "$os" ];then
|
||||
file=google-cloud-sdk-218.0.0-darwin-x86_64.tar.gz
|
||||
else
|
||||
file=google-cloud-sdk-218.0.0-linux-x86_64.tar.gz
|
||||
fi
|
||||
|
||||
if [ ! -f $serverPath/source/gae/$file ];then
|
||||
wget -O $serverPath/source/gae/$file https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/$file
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/source/gae/google-cloud-sdk ];then
|
||||
cd $serverPath/source/gae && tar zxvf $file
|
||||
fi
|
||||
|
||||
cp -r $serverPath/source/gae/google-cloud-sdk ${serverPath}/gae
|
||||
|
||||
|
||||
|
||||
echo "${1}" > ${serverPath}/gae/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_gae()
|
||||
{
|
||||
rm -rf ${serverPath}/gae
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_gae $2
|
||||
else
|
||||
Uninstall_gae $2
|
||||
fi
|
||||
@@ -1,164 +0,0 @@
|
||||
function gaePost(method,args,callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'gae', func:method, args:JSON.stringify(args)}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function projectList(page, search){
|
||||
var _data = {};
|
||||
_data['page_size'] = 10;
|
||||
if (typeof(search) != 'undefined'){
|
||||
_data['search'] = search;
|
||||
}
|
||||
|
||||
if (typeof(page) != 'undefined'){
|
||||
_data['page'] = page;
|
||||
setCookie('gaeProjectListPage',page);
|
||||
} else {
|
||||
_data['page'] = 1;
|
||||
cookie_page = getCookie('gaeProjectListPage')
|
||||
if (cookie_page >0){
|
||||
_data['page'] = cookie_page;
|
||||
}
|
||||
}
|
||||
|
||||
gaePost('project_list', _data, function(data){
|
||||
|
||||
var rdata = $.parseJSON($.trim(data.data));
|
||||
// console.log(rdata);
|
||||
|
||||
content = '<div><input class="bt-input-text mr5" type="text" placeholder="查找项目" id="project_find" style="height: 28px; border-radius: 3px;width: 435px;">';
|
||||
content += '<button class="btn btn-success btn-sm" onclick="projectListFind();">查找</button></div>';
|
||||
|
||||
content += '<div class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
|
||||
content += '<thead><tr>';
|
||||
content += '<th>项目名</th>';
|
||||
content += '<th>地址</th>';
|
||||
content += '<th>操作(<a class="btlink" target="_blank" href="https://console.cloud.google.com/">官方地址</a>)</th>';
|
||||
content += '</tr></thead>';
|
||||
content += '<tbody>';
|
||||
|
||||
|
||||
ulist = rdata.data;
|
||||
for (i in ulist){
|
||||
setName = ulist[i]['isset'] ? '已设置' : '设置';
|
||||
content += '<tr><td>'+ulist[i]['name']+'</td>'+
|
||||
'<td>'+ulist[i]['dir']+'</td><td>'+
|
||||
'<a class="btlink" onclick="gaeSetProject(\''+ulist[i]['name']+'\','+ulist[i]['isset']+')">'+setName+'</a> | ' +
|
||||
'<a class="btlink" onclick="gaeAsyncProject(\''+ulist[i]['name']+'\')">同步</a> | ' +
|
||||
'<a class="btlink" target="_blank" onclick="gaeProjectCmd(\''+ulist[i]['name']+'\')">命令</a> | ' +
|
||||
'<a class="btlink" target="_blank" onclick="gaeProjectUrl(\''+ulist[i]['name']+'\')">访问</a>' +
|
||||
'</td></tr>';
|
||||
}
|
||||
|
||||
content += '</tbody>';
|
||||
content += '</table></div>';
|
||||
|
||||
page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata.list;
|
||||
page += '</div></ul></div>';
|
||||
|
||||
content += page;
|
||||
$(".soft-man-con").html(content);
|
||||
});
|
||||
}
|
||||
|
||||
function projectListFind(){
|
||||
var search = $('#project_find').val();
|
||||
if (search == ''){
|
||||
layer.msg('查找字符不能为空!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
projectList(1, search);
|
||||
}
|
||||
|
||||
function gaeSetProject(pname,isset){
|
||||
var html = '';
|
||||
if (isset){
|
||||
html += '<button onclick="gaeProjectDel(\''+pname+'\')" class="btn btn-default btn-sm">删除</button>';
|
||||
}
|
||||
html += '<button onclick="gaeProjectEdit(\''+pname+'\')" class="btn btn-default btn-sm">编辑</button>';
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '['+ pname +']密钥设置',
|
||||
area: '240px',
|
||||
content:'<div class="change-default pd20">'+html+'</div>'
|
||||
});
|
||||
}
|
||||
|
||||
function gaeProjectEdit(pname){
|
||||
gaePost('project_list_edit', {'name':pname}, function(data){
|
||||
onlineEditFile(0,data.data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function gaeProjectDel(pname){
|
||||
gaePost('project_list_del', {'name':pname}, function(data){
|
||||
showMsg('删除成功!',function(){
|
||||
$('.layui-layer-close1').click();
|
||||
projectList();
|
||||
},{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
});
|
||||
}
|
||||
|
||||
function gaeAsyncProject(pname){
|
||||
gaePost('project_list_async', {'name':pname}, function(data){
|
||||
if (data.data !='ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
} else {
|
||||
layer.msg('加入任务,请自行观察!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
$('.layui-layer-close1').click();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function stringToEntity(str,radix){
|
||||
let arr=[]
|
||||
//返回的字符实体默认10进制,也可以选择16进制
|
||||
radix=radix||0
|
||||
for(let i=0;i<str.length;i++){
|
||||
arr.push((!radix?'&#'+str.charCodeAt(i):'&#x'+str.charCodeAt(i).toString(16))+';')
|
||||
}
|
||||
let tmp=arr.join('')
|
||||
// console.log(`'${str}' 转实体为 '${tmp}'`)
|
||||
return tmp
|
||||
}
|
||||
|
||||
function gaeProjectCmd(pname){
|
||||
gaePost('project_list_cmd', {'name':pname}, function(data){
|
||||
var data_str = data.data;
|
||||
if (data_str.indexOf('gcloud') !== -1){
|
||||
layer.msg(stringToEntity(data.data),{icon:1,time:5000,shade: [0.3, '#000']});
|
||||
} else {
|
||||
layer.msg(data.data,{icon:0,time:5000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function gaeProjectUrl(pname){
|
||||
gaePost('project_list_url', {'name':pname}, function(data){
|
||||
var data_str = data.data;
|
||||
if (data_str.indexOf('appspot.com') !== -1){
|
||||
window.open(data.data);
|
||||
} else {
|
||||
layer.msg(data.data,{icon:0,time:5000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user