-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
804 lines (694 loc) · 30.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
#!/usr/bin/env python
#coding:utf-8
# +-------------------------------------------------------------------
# | 宝塔Linux面板
# +-------------------------------------------------------------------
# | Copyright (c) 2015-2017 宝塔软件(http://bt.cn) All rights reserved.
# +-------------------------------------------------------------------
# | Author: 黄文良 <[email protected]>
# +-------------------------------------------------------------------
#------------------------------
# Panel 入口
#------------------------------
import sys,web,io,os
sys.path.append("class/")
import common,public,data,page,db
#关闭调试模式
web.config.debug = False
#启用SSL
if os.path.exists('data/ssl.pl'):
try:
import OpenSSL
from web.wsgiserver import CherryPyWSGIServer
CherryPyWSGIServer.ssl_certificate = "ssl/certificate.pem"
CherryPyWSGIServer.ssl_private_key = "ssl/privateKey.pem"
except Exception,ex:
print ex;
#URL配置
urls = (
'/' , 'panelIndex',
'/site' , 'panelSite',
'/data' , 'panelData',
'/files' , 'panelFiles',
'/ftp' , 'panelFtp',
'/database', 'panelDatabase',
'/firewall', 'panelFirewall',
'/config' , 'panelConfig',
'/crontab' , 'panelCrontab',
'/login' , 'panelLogin',
'/code' , 'panelCode',
'/system' , 'panelSystem',
'/ajax' , 'panelAjax',
'/install' , 'panelInstall',
'/download', 'panelDownload',
'/control' , 'panelControl',
'/soft' , 'panelSoft',
'/cloud' , 'panelCloud',
'/test' , 'panelTest',
'/close' , 'panelClose',
'/plugin' , 'panelPlugin',
'/waf' , 'panelWaf',
'/ssl' , 'panelSSL',
'/api' , 'panelApi',
'/hook' , 'panelHook',
'/pluginApi','panelPluginApi',
'/downloadApi' , 'panelDownloadApi',
'/safe' , 'panelSafe'
)
app = web.application(urls, globals(),autoreload = False)
#初始化SESSION
web.config.session_parameters['cookie_name'] = 'BT_PANEL'
web.config.session_parameters['cookie_domain'] = None
web.config.session_parameters['timeout'] = 3600
web.config.session_parameters['ignore_expiry'] = True
web.config.session_parameters['ignore_change_ip'] = True
web.config.session_parameters['secret_key'] = 'www.bt.cn'
web.config.session_parameters['expired_message'] = 'Session expired'
dbfile = '/dev/shm/session.db';
src_sessiondb = 'data/session.db';
if not os.path.exists(src_sessiondb):
print db.Sql().dbfile('session').create('session');
if not os.path.exists(dbfile): os.system("\\cp -a -r "+src_sessiondb+" " + dbfile);
sessionDB = web.database(dbn='sqlite', db=dbfile)
session = web.session.Session(app, web.session.DBStore(sessionDB,'sessions'), initializer={'login': False});
def session_hook():
session.panelPath = os.path.dirname(__file__);
web.ctx.session = session
app.add_processor(web.loadhook(session_hook))
#获取当前模板
templatesConf = 'data/templates.pl';
if os.path.exists('templates/index.html'): os.system('rm -f templates/*.html');
if not os.path.exists(templatesConf): public.writeFile(templatesConf,'default');
templateName = public.readFile(templatesConf);
#初始化模板引擎
render = web.template.render('templates/' + templateName + '/',base='template',globals={'session': session,'web':web})
class panelIndex(common.panelAdmin):
def GET(self):
import system
data = system.system().GetConcifInfo()
data['siteCount'] = public.M('sites').count()
data['ftpCount'] = public.M('ftps').count()
data['databaseCount'] = public.M('databases').count()
data['lan'] = public.getLan('index')
return render.index(data)
class panelLogin(common.panelSetup):
def GET(self):
if os.path.exists('/www/server/panel/install.pl'): raise web.seeother('/install');
web.ctx.session.lan = public.get_language();
if not hasattr(session,'webname'): session.webname = public.getMsg('NAME');
tmp = web.ctx.host.split(':')
domain = public.readFile('data/domain.conf')
if domain:
if(tmp[0].strip() != domain.strip()):
errorStr = '''
<meta charset="utf-8">
<title>%s</title>
</head><body>
<h1>%s</h1>
<p>%s</p>
<p>%s</p>
<p>%s</p>
<hr>
<address>%s 5.x <a href="http://www.bt.cn/bbs" target="_blank">%s</a></address>
</body></html>
''' % (public.getMsg('PAGE_ERR_TITLE'),public.getMsg('PAGE_ERR_DOMAIN_H1'),public.getMsg('PAGE_ERR_DOMAIN_P1'),public.getMsg('PAGE_ERR_DOMAIN_P2'),public.getMsg('PAGE_ERR_DOMAIN_P3'),public.getMsg('NAME'),public.getMsg('PAGE_ERR_HELP'))
web.header('Content-Type','text/html; charset=utf-8', unique=True)
return errorStr
if os.path.exists('data/limitip.conf'):
iplist = public.readFile('data/limitip.conf')
if iplist:
iplist = iplist.strip();
if not web.ctx.ip in iplist.split(','):
errorStr = '''
<meta charset="utf-8">
<title>%s</title>
</head><body>
<h1>%s</h1>
<p>%s</p>
<p>%s</p>
<p>%s</p>
<hr>
<address>%s 5.x <a href="http://www.bt.cn/bbs" target="_blank">%s</a></address>
</body></html>
''' % (public.getMsg('PAGE_ERR_TITLE'),public.getMsg('PAGE_ERR_IP_H1'),public.getMsg('PAGE_ERR_IP_P1',(web.ctx.ip,)),public.getMsg('PAGE_ERR_IP_P2'),public.getMsg('PAGE_ERR_IP_P3'),public.getMsg('NAME'),public.getMsg('PAGE_ERR_HELP'))
web.header('Content-Type','text/html; charset=utf-8', unique=True)
return errorStr;
get = web.input()
sql = db.Sql()
if hasattr(get,'dologin'):
if web.ctx.session.login != False:
web.ctx.session.login = False;
web.ctx.session.kill();
import time
time.sleep(0.2);
raise web.seeother('/login')
if hasattr(web.ctx.session,'login'):
if web.ctx.session.login == True:
raise web.seeother('/')
if not hasattr(web.ctx.session,'code'):
web.ctx.session.code = False
data = {}
data['lan'] = public.getLan('login')
render = web.template.render('templates/' + templateName + '/',globals={'session': session,'web':web})
if hasattr(get,'safe'):
web.ctx.session.safelogin = get.safe;
return render.login(data)
def POST(self):
post = web.input()
web.ctx.session.lan = public.get_language();
if not (hasattr(post, 'username') or hasattr(post, 'password') or hasattr(post, 'code')):
return public.returnJson(False,'LOGIN_USER_EMPTY');
if self.limitAddress('?') < 1: return public.returnJson(False,'LOGIN_ERR_LIMIT');
post.username = post.username.strip();
password = public.md5(post.password.strip());
sql = db.Sql();
userInfo = sql.table('users').where("id=?",(1,)).field('id,username,password').find()
if hasattr(web.ctx.session,'code'):
if web.ctx.session.code:
if not public.checkCode(post.code):
public.WriteLog('TYPE_LOGIN','LOGIN_ERR_CODE',(userInfo['username'],web.ctx.session.code,web.ctx.ip));
return public.returnJson(False,'CODE_ERR');
try:
if userInfo['username'] != post.username or userInfo['password'] != password:
public.WriteLog('TYPE_LOGIN','LOGIN_ERR_PASS',(userInfo['username'],'******',web.ctx.ip));
num = self.limitAddress('+');
return public.returnJson(False,'LOGIN_USER_ERR',(str(num),));
import time;
login_temp = 'data/login.temp'
if not os.path.exists(login_temp): public.writeFile(login_temp,'');
login_logs = public.readFile(login_temp);
public.writeFile(login_temp,login_logs + web.ctx.ip + '|' + str(int(time.time())) + ',');
web.ctx.session.login = True;
web.ctx.session.username = userInfo['username'];
public.WriteLog('TYPE_LOGIN','LOGIN_SUCCESS',(userInfo['username'],web.ctx.ip));
self.limitAddress('-');
return public.returnJson(True,'LOGIN_SUCCESS');
except:
public.WriteLog('TYPE_LOGIN','LOGIN_ERR_PASS',(userInfo['username'],'******',web.ctx.ip));
num = self.limitAddress('+');
return public.returnJson(False,'LOGIN_USER_ERR',(str(num),));
#IP限制
def limitAddress(self,type):
import time
logFile = 'data/'+web.ctx.ip+'.login';
timeFile = 'data/'+web.ctx.ip+'_time.login';
limit = 6;
outtime = 1800;
try:
#初始化
if not os.path.exists(timeFile): public.writeFile(timeFile,str(time.time()));
if not os.path.exists(logFile): public.writeFile(logFile,'0');
#判断是否解除登陆限制
time1 = long(public.readFile(timeFile).split('.')[0]);
if (time.time() - time1) > outtime:
public.writeFile(logFile,'0');
public.writeFile(timeFile,str(time.time()));
#计数
num1 = int(public.readFile(logFile));
if type == '+':
num1 += 1;
public.writeFile(logFile,str(num1));
if num1 > 1:
web.ctx.session.code = True;
return limit - num1;
#清空
if type == '-':
public.ExecShell('rm -f data/*.login');
web.ctx.session.code = False;
return 1;
return limit - num1;
except:
return limit;
class panelSite(common.panelAdmin):
def GET(self):
data = {}
data['isSetup'] = True;
data['lan'] = public.getLan('site');
if os.path.exists(web.ctx.session.setupPath+'/nginx') == False and os.path.exists(web.ctx.session.setupPath+'/apache') == False: data['isSetup'] = False;
return render.site(data);
def POST(self):
get = web.input()
import panelSite
siteObject = panelSite.panelSite()
defs = ('GetSiteDomains','GetSecurity','SetSecurity','ProxyCache','CloseToHttps','HttpToHttps','SetEdate','SetRewriteTel','GetCheckSafe','CheckSafe','GetDefaultSite','SetDefaultSite','CloseTomcat','SetTomcat','apacheAddPort','AddSite','GetPHPVersion','SetPHPVersion','DeleteSite','AddDomain','DelDomain','GetDirBinding','AddDirBinding','GetDirRewrite','DelDirBinding'
,'UpdateRulelist','SetSiteRunPath','GetSiteRunPath','SetPath','SetIndex','GetIndex','GetDirUserINI','SetDirUserINI','GetRewriteList','SetSSL','SetSSLConf','CreateLet','CloseSSLConf','GetSSL','SiteStart','SiteStop'
,'Set301Status','Get301Status','CloseLimitNet','SetLimitNet','GetLimitNet','SetProxy','GetProxy','ToBackup','DelBackup','GetSitePHPVersion','logsOpen','GetLogsStatus','CloseHasPwd','SetHasPwd','GetHasPwd')
return publicObject(siteObject,defs);
class panelConfig(common.panelAdmin):
def GET(self):
import system
data = system.system().GetConcifInfo();
data['lan'] = public.getLan('config');
return render.config(data);
def POST(self):
import config
configObject = config.config()
defs = ('GetPHPConf','SetPHPConf','GetPanelList','AddPanelInfo','SetPanelInfo','DelPanelInfo','ClickPanelInfo','SetPanelSSL','SetTemplates','Set502','setPassword','setUsername','setPanel','setPathInfo','setPHPMaxSize','getFpmConfig','setFpmConfig','setPHPMaxTime','syncDate','setPHPDisable','SetControl','ClosePanel','AutoUpdatePanel','SetPanelLock')
return publicObject(configObject,defs);
class panelDownload(common.panelAdmin):
def GET(self):
get = web.input()
try:
get.filename = get.filename.encode('utf-8');
import os
fp = open(get.filename,'rb')
size = os.path.getsize(get.filename)
filename = os.path.basename(get.filename)
#输出文件头
web.header("Content-Disposition", "attachment; filename=" +filename);
web.header("Content-Length", size);
web.header('Content-Type','application/octet-stream');
buff = 4096
while True:
fBody = fp.read(buff)
if fBody:
yield fBody
else:
return
except Exception, e:
yield 'Error'
finally:
if fp:
fp.close()
class panelCloud(common.panelAdmin):
def GET(self):
import json
get = web.input()
result = public.ExecShell("python "+web.ctx.session.setupPath + '/panel/script/backup_'+get.filename+'.py download ' + get.name)
raise web.seeother(json.loads(result[0]));
class panelFiles(common.panelAdmin):
def GET(self):
data = {}
data['lan'] = public.getLan('files')
return render.files(data)
def POST(self):
import files
filesObject = files.files()
defs = ('GetSearch','ExecShell','GetExecShellMsg','UploadFile','GetDir','CreateFile','CreateDir','DeleteDir','DeleteFile',
'CopyFile','CopyDir','MvFile','GetFileBody','SaveFileBody','Zip','UnZip',
'GetFileAccess','SetFileAccess','GetDirSize','SetBatchData','BatchPaste',
'DownloadFile','GetTaskSpeed','CloseLogs','InstallSoft','UninstallSoft',
'RemoveTask','ActionTask','Re_Recycle_bin','Get_Recycle_bin','Del_Recycle_bin','Close_Recycle_bin','Recycle_bin')
return publicObject(filesObject,defs);
class panelDatabase(common.panelAdmin):
def GET(self):
pmd = self.get_phpmyadmin_dir();
web.ctx.session.phpmyadminDir = False
if pmd:
web.ctx.session.phpmyadminDir = 'http://' + web.ctx.host.split(':')[0] + ':'+ pmd[1] + '/' + pmd[0];
data = {}
data['isSetup'] = True;
data['mysql_root'] = public.M('config').where('id=?',(1,)).getField('mysql_root');
data['lan'] = public.getLan('database')
if os.path.exists(web.ctx.session.setupPath+'/mysql') == False: data['isSetup'] = False;
return render.database(data)
def POST(self):
import database
databaseObject = database.database()
defs = ('GetRunStatus','SetDbConf','GetDbStatus','BinLog','GetErrorLog','GetMySQLInfo','SetDataDir','SetMySQLPort','AddDatabase','DeleteDatabase','SetupPassword','ResDatabasePassword','ToBackup','DelBackup','InputSql','SyncToDatabases','SyncGetDatabases','GetDatabaseAccess','SetDatabaseAccess')
return publicObject(databaseObject,defs);
def get_phpmyadmin_dir(self):
path = web.ctx.session.setupPath + '/phpmyadmin'
if not os.path.exists(path): return None
phpport = '888';
try:
import re;
if web.ctx.session.webserver == 'nginx':
filename = web.ctx.session.setupPath + '/nginx/conf/nginx.conf';
conf = public.readFile(filename);
rep = "listen\s+([0-9]+)\s*;";
rtmp = re.search(rep,conf);
if rtmp:
phpport = rtmp.groups()[0];
else:
filename = web.ctx.session.setupPath + '/apache/conf/extra/httpd-vhosts.conf';
conf = public.readFile(filename);
rep = "Listen\s+([0-9]+)\s*\n";
rtmp = re.search(rep,conf);
if rtmp:
phpport = rtmp.groups()[0];
except:
pass
for filename in os.listdir(path):
print filename
filepath = path + '/' + filename
if os.path.isdir(filepath):
if filename[0:10] == 'phpmyadmin':
return str(filename),phpport
return None
class panelFtp(common.panelAdmin):
def GET(self):
self.FtpPort()
data = {}
data['isSetup'] = True;
if os.path.exists(web.ctx.session.setupPath+'/pure-ftpd') == False: data['isSetup'] = False;
data['lan'] = public.getLan('ftp')
return render.ftp(data)
def POST(self):
import ftp
ftpObject = ftp.ftp()
defs = ('AddUser','DeleteUser','SetUserPassword','SetStatus','setPort')
return publicObject(ftpObject,defs);
#取端口
def FtpPort(self):
if hasattr(web.ctx.session,'port'):return
import re
try:
file = web.ctx.session.setupPath+'/pure-ftpd/etc/pure-ftpd.conf'
conf = public.readFile(file)
rep = "\n#?\s*Bind\s+[0-9]+\.[0-9]+\.[0-9]+\.+[0-9]+,([0-9]+)"
port = re.search(rep,conf).groups()[0]
except:
port='21'
web.ctx.session.port = port
class panelFirewall(common.panelAdmin):
def GET(self):
data = {}
data['lan'] = public.getLan('firewall')
return render.firewall(data)
def POST(self):
import firewalls
firewallObject = firewalls.firewalls()
defs = ('GetList','AddDropAddress','DelDropAddress','FirewallReload','SetFirewallStatus','AddAcceptPort','DelAcceptPort','SetSshStatus','SetPing','SetSshPort','GetSshInfo')
return publicObject(firewallObject,defs);
class panelCrontab(common.panelAdmin):
def GET(self):
import crontab
data = {}
data['lan'] = public.getLan('crontab')
return render.crontab(data)
def POST(self):
import crontab
crontabObject = crontab.crontab()
defs = ('GetCrontab','AddCrontab','GetDataList','GetLogs','DelLogs','DelCrontab','StartTask')
return publicObject(crontabObject,defs);
class panelCode:
def GET(self):
import vilidate,time
if hasattr(web.ctx.session,'codeTime'):
if (time.time() - web.ctx.session.codeTime) < 0.1:
return public.getMsg('CODE_BOOM');
vie = vilidate.vieCode();
codeImage = vie.GetCodeImage(80,4);
try:
from cStringIO import StringIO
except:
from StringIO import StringIO
out = StringIO();
codeImage[0].save(out, "png")
web.ctx.session.codeStr = public.md5("".join(codeImage[1]).lower())
web.ctx.session.codeTime = time.time()
web.header('Cache-Control', 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
web.header('Pragma', 'no-cache');
web.header('Content-Type','image/png');
return out.getvalue();
class panelSystem(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
import system
sysObject = system.system()
defs = ('ClearSystem','GetNetWorkOld','GetNetWork','GetDiskInfo','GetCpuInfo','GetBootTime','GetSystemVersion','GetMemInfo','GetSystemTotal','GetConcifInfo','ServiceAdmin','ReWeb','RestartServer','ReMemory','RepPanel')
return publicObject(sysObject,defs);
class panelAjax(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
import ajax
ajaxObject = ajax.ajax()
defs = ('GetWarning','SetWarning','CheckLogin','GetSpeed','GetAd','phpSort','ToPunycode','GetBetaStatus','SetBeta','setPHPMyAdmin','delClose','KillProcess','GetPHPInfo','GetQiniuFileList','UninstallLib','InstallLib','SetQiniuAS','GetQiniuAS','GetLibList','GetProcessList','GetNetWorkList','GetNginxStatus','GetPHPStatus','GetTaskCount','GetSoftList','GetNetWorkIo','GetDiskIo','GetCpuIo','CheckInstalled','UpdatePanel','GetInstalled','GetPHPConfig','SetPHPConfig')
return publicObject(ajaxObject,defs);
class panelInstall:
def GET(self):
if not os.path.exists('install.pl'): raise web.seeother('/login');
data = {}
data['status'] = os.path.exists('install.pl');
data['username'] = public.M('users').where('id=?',(1,)).getField('username');
render = web.template.render('templates/' + templateName + '/',globals={'session': session})
return render.install(data);
def POST(self):
if not os.path.exists('install.pl'): raise web.seeother('/login');
get = web.input();
if not hasattr(get,'bt_username'): return '用户名不能为空!';
if not get.bt_username: return '用户名不能为空!'
if not hasattr(get,'bt_password1'): return '密码不能为空!';
if not get.bt_password1: return '密码不能为空!';
if get.bt_password1 != get.bt_password2: return '两次输入的密码不一致,请重新输入!';
public.M('users').where("id=?",(1,)).save('username,password',(get.bt_username,public.md5(get.bt_password1.strip())))
os.remove('install.pl');
data = {}
data['status'] = os.path.exists('install.pl');
data['username'] = get.bt_username;
render = web.template.render( 'templates/' + templateName + '/',globals={'session': session});
return render.install(data);
class panelData(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
dataObject = data.data()
defs = ('setPs','getData','getFind','getKey')
return publicObject(dataObject,defs);
class panelControl(common.panelAdmin):
def GET(self):
data = {}
data['lan'] = public.getLan('control')
return render.control(data)
class panelSoft(common.panelAdmin):
def GET(self):
import system
data = system.system().GetConcifInfo()
data['lan'] = public.getLan('soft')
return render.soft(data)
class panelTest(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
import servertest;
testObject = servertest.serverTest()
defs = ('testCpu','testInt','testFloat','testBubble','testTree','testMem','testDisk','testWorkNet')
return publicObject(testObject,defs);
class panelPlugin(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
import panelPlugin
pluginObject = panelPlugin.panelPlugin()
defs = ('GetCloudWarning','install','unInstall','getPluginList','getPluginInfo','getPluginStatus','setPluginStatus','a','getCloudPlugin','getConfigHtml','savePluginSort')
return publicObject(pluginObject,defs);
class panelWaf(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
import panelWaf
toObject = panelWaf.panelWaf()
defs = ('GetConfig','SetConfigString','SetConfigList','GetWafConf','SetWafConf','SetStatus','updateWaf')
return publicObject(toObject,defs);
class panelSSL(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
import panelSSL
toObject = panelSSL.panelSSL()
defs = ('DelToken','GetToken','GetUserInfo','GetOrderList','GetDVSSL','Completed','SyncOrder','GetSSLInfo','downloadCRT','GetSSLProduct')
result = publicObject(toObject,defs);
return result;
class panelApi(common.panelAdmin):
def GET(self):
return self.funObj()
def POST(self):
return self.funObj()
def funObj(self):
import panelApi
toObject = panelApi.panelApi()
defs = ('GetToken','SetToken','CreateToken','SetTokenStatus')
result = publicObject(toObject,defs);
return result;
class panelHook:
def GET(self):
return self.pobject();
def POST(self):
return self.pobject();
def pobject(self):
get = web.input()
if not os.path.exists('/www/server/panel/plugin/webhook'): return public.getJson(public.returnMsg(False,'请先安装WebHook组件!'));
sys.path.append('/www/server/panel/plugin/webhook');
import webhook_main
return public.getJson(webhook_main.webhook_main().RunHook(get));
#安全登陆接口
class panelSafe:
def GET(self):
return self.pobject();
def POST(self):
return self.pobject();
def pobject(self):
get = web.input()
pluginPath = '/www/server/panel/plugin/safelogin';
if hasattr(get,'check'):
if os.path.exists(pluginPath + '/safelogin_main.py'): return 'True';
return 'False';
get.data = self.check_token(get.data);
if not get.data: return public.returnJson(False,'验证失败');
sys.path.append(pluginPath);
import safelogin_main;
reload(safelogin_main);
s = safelogin_main.safelogin_main();
if not hasattr(s,get.data['action']): return public.returnJson(False,'方法不存在');
defs = ('GetServerInfo','add_ssh_limit','remove_ssh_limit','get_ssh_limit','get_login_log','get_panel_limit','add_panel_limit','remove_panel_limit','close_ssh_limit','close_panel_limit','get_system_info','get_service_info','get_ssh_errorlogin')
if not get.data['action'] in defs: return 'False';
return public.getJson(eval('s.' + get.data['action'] + '(get)'));
#检查Token
def check_token(self,data):
pluginPath = '/www/server/panel/plugin/safelogin/token.pl';
if not os.path.exists(pluginPath): return False;
from urllib import unquote;
from binascii import unhexlify;
from json import loads;
result = unquote(unhexlify(data));
token = public.readFile(pluginPath).strip();
result = loads(result);
if not result: return False;
if result['token'] != token: return False;
return result;
class panelPluginApi:
def GET(self):
get = web.input();
if not public.checkToken(get): return public.returnJson(False,'无效的Token!');
if not self.CheckPlugin(get.name): return public.returnJson(False,'您没有权限访问当前插件!');
return self.funObj();
def POST(self):
get = web.input(backupfile={},data=[]);
if not public.checkToken(get): return public.returnJson(False,'无效的Token!');
if not self.CheckPlugin(get.name): return public.returnJson(False,'您没有权限访问当前插件!');
return self.funObj();
def CheckPlugin(self,name):
try:
infoFile = '/www/server/panel/plugin/' + name + '/info.json';
if not os.path.exists(infoFile): return False;
import json
info = json.loads(public.readFile(infoFile));
if not info['api']: return False;
return True;
except:
return False
def funObj(self):
import panelPlugin
pluginObject = panelPlugin.panelPlugin();
defs = ('install','unInstall','getPluginList','getPluginInfo','getPluginStatus','setPluginStatus','a','getCloudPlugin','getConfigHtml','savePluginSort')
return publicObject(pluginObject,defs);
class panelDownloadApi:
def GET(self):
get = web.input()
if not public.checkToken(get): get.filename = str(time.time());
try:
get.filename = '/www/server/panel/plugin/psync/backup/' + get.filename.encode('utf-8');
import os
fp = open(get.filename,'rb')
size = os.path.getsize(get.filename)
filename = os.path.basename(get.filename)
#输出文件头
web.header("Content-Disposition", "attachment; filename=" + filename);
web.header("Content-Length", size);
web.header('Content-Type','application/octet-stream')
buff = 4096
while True:
fBody = fp.read(buff)
if fBody:
yield fBody
else:
return
except Exception, e:
yield 'Error'
finally:
if fp:
fp.close()
class panelToken:
def GET(self):
import json,time
get = web.input();
tokenFile = 'data/token.json'
if not os.path.exists(self.tokenFile): return json.dumps(public.returnMsg(False,'错误:当前未开启API接口服务!'));
token = json.loads(public.readFile(tokenFile));
if get.access_key != token['access_key'] or get.secret_key != token['secret_key']:
return json.dumps(public.returnMsg(False,'密钥验证失败!'));
tempToken = {}
tempToken['token'] = public.GetRandomString(32);
tempToken['timeout'] = time.time() + 86400;
public.writeFile('data/tempToken.json',json.dumps(tempToken));
tempToken['status'] = True;
return json.dumps(tempToken);
class panelClose:
def GET(self):
if not os.path.exists('data/close.pl'): raise web.seeother('/');
render = web.template.render('templates/' + templateName + '/',globals={'session': session})
data = {}
data['lan'] = public.getLan('close');
return render.close(data)
class panelTest:
def POST(self):
get = web.input(backup={},data=[]);
public.writeFile('test.pl',get['backup'].file.read());
return public.returnJson(True,'OK!')
def publicObject(toObject,defs):
get = web.input(zunfile = {},data = []);
if hasattr(get,'path'):
get.path = get.path.replace('//','/').replace('\\','/');
if get.path.find('->') != -1:
get.path = get.path.split('->')[0].strip();
for key in defs:
if key == get.action:
fun = 'toObject.'+key+'(get)'
if hasattr(get,'html'):
return eval(fun)
else:
return public.getJson(eval(fun))
return public.returnJson(False,'ARGS_ERR')
#定义404错误
def notfound():
errorStr = '''
<meta charset="utf-8">
<title>%s</title>
</head><body>
<h1>%s</h1>
<p>%s</p>
<hr>
<address>%s 5.x <a href="https://www.bt.cn/bbs" target="_blank">%s</a></address>
</body></html>
''' % (public.getMsg('PAGE_ERR_404_TITLE'),public.getMsg('PAGE_ERR_404_H1'),public.getMsg('PAGE_ERR_404_P1'),public.getMsg('NAME'),public.getMsg('PAGE_ERR_HELP'))
return web.notfound(errorStr);
#定义500错误
def internalerror():
errorStr = '''
<meta charset="utf-8">
<title>%s</title>
</head><body>
<h1>%s</h1>
<p>%s</p>
<hr>
</body></html>
''' % (public.getMsg('PAGE_ERR_500_TITLE'),public.getMsg('PAGE_ERR_500_H1'),public.getMsg('PAGE_ERR_500_P1'))
return web.internalerror(errorStr)
#检查环境
def check_system():
sql = db.Sql();
sql.execute("alter TABLE sites add edate integer DEFAULT '0000-00-00'",());
if __name__ == "__main__":
check_system();
app.notfound = notfound
app.internalerror = internalerror
reload(sys)
sys.setdefaultencoding("utf-8")
app.run()