-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
1121 lines (878 loc) · 41.3 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
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import discord
import os
import sys
import psutil
import time
import re
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix="-", intents=intents)
client.remove_command('help')
version = "0.9"
reqchannel = client.get_channel(insertchannelid)
logs = "[LOGS] "
logstofile = "false" #Should we save the logs? Don't enable
adminrole = "Admin" #Admin Rolename
modrole = "Mod" #Mod Rolename
donatorrole = "Donator" #Donator Rolename
#Giveaway Rolename & Rewards (MiB)
giveaway3 = "1024"
giveaway2 = "512"
giveaway1 = "248"
userrole = "User" #User Rolename (If user dosent have role commands wont work)
suspendedrole = "Suspended" #Not Working
#this will only allow command execution on specific channels
cmdchid = 0000000000000000000 #Change!!!
idprefix = "bot" #ID PREFIX
deleteleave = "true" #Not Working
lxcips = "10." #Do not Change!!
onstartupnet = "50000 50000" #Default Global Network Limit (Kbps)
modperk = "512"
donatorperk = "512"
#Limit of User Creations (bypassable by ADMIN creation)
vpslimit = 2
#User Creation Options
usercpu = "1" #Vcores
userram = "128" #MiB
userdisk = "5" #GiB
if logstofile == "true":
sys.stdout = open('/root/lxcbot/logs.txt', 'w')
os.spawnlp(os.P_NOWAIT, "/root/lxcbot/webserver.py", "webserver.py")
@client.event
async def on_ready():
await client.change_presence(activity=discord.Game(name="-help"))
print("")
os.system("lxc list -f csv")
print("")
print(logs + "Containers List Loaded")
print("")
print(logs + "Bot Loaded Successfully!")
#Function to check if channel is cmdchid
async def commandchannelid(ctx):
return ctx.channel.id == cmdchid
@client.event
async def on_member_remove(member):
if deleteleave == "true":
os.system(f"lxc delete {member.id} --force")
########################################################## - Help Command \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def help(ctx):
logvarcmd = "help"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Help", description="Prefix (-)", color=discord.Color.blue())
embed.add_field(name="createvps (ubuntu/debian)", value=f"Allows you to create 1 vps")
embed.add_field(name="startvps", value=f"Allows you to manage your vps")
embed.add_field(name="stopvps", value=f"Allows you to manage your vps")
embed.add_field(name="restartvps", value=f"Allows you to manage your vps")
embed.add_field(name="deletevps", value=f"Allows you to delete your vps")
embed.add_field(name="regenpass", value=f"Re-Generate vps password")
embed.add_field(name="infovps", value=f"Allows you to see the current Status of your vps")
embed.add_field(name="nodeinfo", value=f"Allows you to see the current usage of the node")
embed.add_field(name="modperks", value=f"This command applies the Moderator perks")
embed.add_field(name="donatorperks", value=f"This command applies the Donator perks")
embed.add_field(name="help", value=f"This Command")
embed.set_footer(text = f"Version: {version}")
await ctx.reply(embed=embed)
########################################################## - Make a Port Request \/
@client.command()
@commands.check(commandchannelid)
async def portreq(ctx, msgrequest):
logvarcmd = "portreq"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Request Sent!", description=f"Message: {msgrequest}", color=discord.Color.blue())
reqembed = discord.Embed(title="Message Recieved!", description=f"Message: {msgrequest}", color=discord.Color.blue())
await ctx.send(embed=embed)
await reqchannel.send(embed=reqembed)
########################################################## - Create a Vps Command & Images \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def createvps(ctx, image):
logvarcmd = "createvps"
#Embed Template
desc = f"""```yaml
ID: {idprefix}{ctx.author.id}
OS: {image}
----------------------
Cpu: {usercpu} Vcores
Ram: {userram} MiB
Disk: {userdisk} GiB
Net: {onstartupnet} Kibps
----------------------```"""
embed = discord.Embed(title="Creation Successfull!", description=desc, color=discord.Color.green())
# Get Count of Current vpses
vpscurrent1 = os.popen("lxc list -f csv | grep CONTAINER -c")
vpscurrentout1 = vpscurrent1.readlines()
for vpscurrent in vpscurrentout1:
vpscurrent = vpscurrent.strip("\n")
#Images
# alpine = "alpine/3.16"
# archlinux = "archlinux"
ubuntu = "ubuntu/jammy/arm64"
debian = "debian/11/cloud/arm64"
#Reply user fetching {using discord API!}
user = await client.fetch_user(ctx.author.id)
if image == "alpine" and int(vpscurrent) <= vpslimit:
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{alpine} {idprefix}{ctx.author.id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {idprefix}{ctx.author.id} root size={userdisk}GB")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {onstartupnet}")
#Set password to container
passgen1 = os.popen(f"bash /root/botvps-discord/passgen.sh")
passgenout1 = passgen1.readlines()
for passgen in passgenout1:
passgen = passgen.strip('\n')
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
os.system(f"lxc exec {idprefix}{ctx.author.id} -- apk add openssh-server")
os.system(f"lxc config device override web-server {idprefix}{ctx.author.id}")
os.system(f"lxc config device override web-server {idprefix}{ctx.author.id}")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- apk add openssh-server")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- wget -O /etc/ssh/sshd_config https://raw.githubusercontent.com/dxomg/sshd_config/main/sshd_config")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- service sshd restart")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- sh -c 'echo 'root:{passgen}' | chpasswd'")
await user.send(f"""```yaml
User: root
Password: {passgen}
- to get ip do -infovps```
Panel: http://panel.vpsbot.ml:8888/""")
await ctx.reply(embed=embed)
elif image == "archlinux" and int(vpscurrent) <= vpslimit:
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{archlinux} {idprefix}{ctx.author.id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {idprefix}{ctx.author.id} root size={userdisk}GB && lxc config device override {idprefix}{ctx.author.id} root size={userdisk}GB") #Double execution else it dosent work, dunno why
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {onstartupnet}")
#Set password to container
passgen1 = os.popen(f"bash /root/botvps-discord/passgen.sh")
passgenout1 = passgen1.readlines()
for passgen in passgenout1:
passgen = passgen.strip('\n')
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
os.system(f"lxc exec {idprefix}{ctx.author.id} -- sh -c 'echo -e Y | pacman -S openssh wget'")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- wget -O /etc/ssh/sshd_config https://raw.githubusercontent.com/dxomg/sshd_config/main/sshd_config")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- systemctl restart sshd")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- sh -c 'echo 'root:{passgen}' | chpasswd'")
await user.send(f"""```yaml
User: root
Password: {passgen}
- to get ip do -infovps```
Panel: http://panel.vpsbot.ml:8888/""")
await ctx.reply(embed=embed)
elif image == "debian" and int(vpscurrent) <= vpslimit:
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{debian} {idprefix}{ctx.author.id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {idprefix}{ctx.author.id} root size={userdisk}GB")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {onstartupnet}")
#Set password to container
passgen1 = os.popen(f"bash /root/botvps-discord/passgen.sh")
passgenout1 = passgen1.readlines()
for passgen in passgenout1:
passgen = passgen.strip('\n')
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
os.system(f"lxc exec {idprefix}{ctx.author.id} -- apt install -qq openssh-server wget -y")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- wget -O /etc/ssh/sshd_config https://raw.githubusercontent.com/vincyxiroff/botvps-discord/main/p/sshd_config")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- systemctl restart sshd")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- sh -c 'echo 'root:{passgen}' | chpasswd'")
await user.send(f"""```yaml
User: root
Password: {passgen}
- to get ip do -infovps```
Panel: http://panel.vpsbot.ml:8888/""")
await ctx.reply(embed=embed)
elif image == "ubuntu" and int(vpscurrent) <= vpslimit:
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{ubuntu} {idprefix}{ctx.author.id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {idprefix}{ctx.author.id} root size={userdisk}GB")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {onstartupnet}")
#Set password to container
passgen1 = os.popen(f"bash /root/botvps-discord/passgen.sh")
passgenout1 = passgen1.readlines()
for passgen in passgenout1:
passgen = passgen.strip('\n')
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
os.system(f"lxc exec {idprefix}{ctx.author.id} -- apt update -y")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- apt install openssh-server wget -y")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- rm /etc/ssh/sshd_config") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
os.system(f"lxc exec {idprefix}{ctx.author.id} -- wget -O /etc/ssh/sshd_config https://raw.githubusercontent.com/vincyxiroff/botvps-discord/main/p/sshd_config")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- systemctl enable ssh --now")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- systemctl restart ssh")
os.system(f"lxc exec {idprefix}{ctx.author.id} -- sh -c 'echo 'root:{passgen}' | chpasswd'")
await user.send(f"""```yaml
User: root
Password: {passgen}
- to get ip do -infovps```
Panel: http://panel.vpsbot.ml:8888/""")
await ctx.reply(embed=embed)
else:
await ctx.reply(f"Incorrect Image Name or Vps Limit Reached ({vpslimit})")
############################# ADMIN version - \/
@client.command()
@commands.has_role(adminrole)
async def admincreatevps(ctx, id, image, cpu, ram, disk, up, down):
logvarcmd = "admincreatevps"
#Options {don't change for admin}
usercpu = cpu
userram = ram
userdisk = disk
desc = f"""```yaml
ID: {id}
OS: {image}
----------------------
Cpu: {cpu} Vcores
Ram: {ram} MiB
Disk: {disk} GiB
Net: {up} {down} Kibps
----------------------```"""
#Embed Template
embed = discord.Embed(title="Creation Successfull!", description=desc, color=discord.Color.green())
#Images
alpine = "alpine/3.16"
archlinux = "archlinux"
ubuntu = "ubuntu/jammy"
debian = "debian/11"
if image == "alpine":
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{alpine} {id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {id} root size={userdisk}GB")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {up} {down}")
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
await ctx.reply(embed=embed)
elif image == "archlinux":
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{archlinux} {id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {id} root size={userdisk}GB && lxc config device override {id} root size={userdisk}GB") #Double execution else it dosent work, dunno why
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {up} {down}")
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
await ctx.reply(embed=embed)
elif image == "debian":
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{debian} {id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {id} root size={userdisk}GB")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {up} {down}")
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
await ctx.reply(embed=embed)
elif image == "ubuntu":
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
await ctx.reply("Creating...")
os.system(f"lxc launch images:{ubuntu} {id} -c limits.cpu={usercpu} -c limits.memory={userram}MiB && lxc config device override {id} root size={userdisk}GB")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {up} {down}")
os.system("rm .ssh/known_hosts") # Remove known_hosts file to prevent Bad Host Key error from paramiko in web panel
await ctx.reply(embed=embed)
else:
await ctx.reply("Incorrect Image Name")
########################################################## - Machine Info Command \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def nodeinfo(ctx):
logvarcmd = "nodeinfo"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Useless vars
cpu = psutil.cpu_percent()
ram = psutil.virtual_memory().percent
swap = psutil.swap_memory().percent
total = (round(ram + swap))/2
temp1 = os.popen("sensors | grep CPU:")
tempout1 = temp1.readlines()
for tempout in tempout1:
tempout = tempout.strip("\n CPU: +")
fan1 = os.popen("sensors | grep Processor")
fanout1 = fan1.readlines()
for fanout in fanout1:
fanout = fanout.strip("\n Processor Fan:")
def uptimeseconds():
return time.time() - psutil.boot_time()
uptime = (round(uptimeseconds() / 3600))
vpsnum1 = os.popen("lxc list -f csv | grep CONTAINER -c")
vpsnumout1 = vpsnum1.readlines()
for vpsnumout in vpsnumout1:
vpsnumout = vpsnumout.strip("\n")
vpsactive1 = os.popen("lxc list -f csv | grep RUNNING -c")
vpsactiveout1 = vpsactive1.readlines()
for vpsactiveout in vpsactiveout1:
vpsactiveout = vpsactiveout.strip("\n")
vpsinactive1 = os.popen("lxc list -f csv | grep STOPPED -c")
vpsinactiveout1 = vpsinactive1.readlines()
for vpsinactiveout in vpsinactiveout1:
vpsinactiveout = vpsinactiveout.strip("\n")
getos1 = os.popen("screenfetch -nN | grep -i 'OS'")
getosout1 = getos1.readlines()
for getosout in getosout1:
getosout = getosout.strip("\n")
getcpu1 = os.popen("screenfetch -nN | grep -i 'CPU'")
getcpuout1 = getcpu1.readlines()
for getcpuout in getcpuout1:
getcpuout = getcpuout.strip("\n")
getram1 = os.popen("screenfetch -nN | grep -i 'RAM'")
getramout1 = getram1.readlines()
for getramout in getramout1:
getramout = getramout.strip("\n")
getuptime1 = os.popen("screenfetch -nN | grep -i 'Uptime'")
getuptimeout1 = getuptime1.readlines()
for getuptimeout in getuptimeout1:
getuptimeout = getuptimeout.strip("\n")
desc = f"""```yaml
{getosout}
{getcpuout}
{getramout}
{getuptimeout}
```"""
#Embed
embed = discord.Embed(title="Node Info", description=desc, color=discord.Color.purple())
embed.add_field(name="**CPU**", value=f"{cpu}%")
embed.add_field(name="**RAM**", value=f"{total}%")
try:
embed.add_field(name="**TEMP**", value=f"{tempout}")
except:
embed.add_field(name="**TEMP**", value=f"-")
try:
embed.add_field(name="**FAN**", value=f"{fanout}")
except:
embed.add_field(name="**FAN**", value=f"-")
embed.add_field(name="**UPTIME**", value=f"{uptime} Hours")
embed.add_field(name="**INSTANCES**", value=f"{vpsnumout}")
embed.add_field(name="**ACTIVE**", value=f"{vpsactiveout}")
embed.add_field(name="**INACTIVE**", value=f"{vpsinactiveout}")
embed.add_field(name="**LIMIT**", value=f"{vpslimit}")
await ctx.reply(embed=embed)
########################################################## - Start Vps Command \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def startvps(ctx):
logvarcmd = "startvps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Start Successfull!", description="Start Vps", color=discord.Color.green())
#Command
os.system(f"lxc start {idprefix}{ctx.author.id}")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {onstartupnet}")
await ctx.reply(embed=embed)
############################# ADMIN version - \/
@client.command()
@commands.has_role(adminrole)
async def adminstartvps(ctx, id):
logvarcmd = "adminstartvps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Start Successfull!", description="Start Vps", color=discord.Color.green())
#Command
os.system(f"lxc start {id}")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {onstartupnet}")
await ctx.reply(embed=embed)
########################################################## - Stop Vps Command \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def stopvps(ctx):
logvarcmd = "stopvps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Stop Successfull!", description="Stop Vps", color=discord.Color.green())
#Command
os.system(f"lxc stop {idprefix}{ctx.author.id}")
await ctx.reply(embed=embed)
############################# ADMIN version - \/
@client.command()
@commands.has_role(adminrole)
async def adminstopvps(ctx, id):
logvarcmd = "adminstopvps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Stop Successfull!", description="Stop Vps", color=discord.Color.green())
#Command
os.system(f"lxc stop {id}")
await ctx.reply(embed=embed)
########################################################## - Restart Vps Command \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def restartvps(ctx):
logvarcmd = "restartvps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Restart Successfull!", description="Restart Vps", color=discord.Color.green())
#Command
os.system(f"lxc stop {idprefix}{ctx.author.id}")
os.system(f"lxc start {idprefix}{ctx.author.id}")
await ctx.reply(embed=embed)
############################# ADMIN version - \/
@client.command()
@commands.has_role(adminrole)
async def adminrestartvps(ctx, id):
logvarcmd = "adminrestartvps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Restart Successfull!", description="Restart Vps", color=discord.Color.green())
#Command
os.system(f"lxc stop {id}")
os.system(f"lxc start {id}")
await ctx.reply(embed=embed)
########################################################## - Delete Vps Command \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def deletevps(ctx):
logvarcmd = "deletevps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Delete Successfull!", description="Delete Vps", color=discord.Color.green())
#Command
os.system(f"lxc delete {idprefix}{ctx.author.id} --force")
await ctx.reply(embed=embed)
############################# ADMIN version - \/
@client.command()
@commands.has_role(adminrole)
async def admindeletevps(ctx, id):
logvarcmd = "admindeletevps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Delete Successfull!", description="Delete Vps", color=discord.Color.green())
#Command
os.system(f"lxc delete {id} --force")
await ctx.reply(embed=embed)
########################################################## - Information Vps Command \/
@client.command()
@commands.has_role(userrole)
@commands.check(commandchannelid)
async def infovps(ctx):
logvarcmd = "infovps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Command
infocpu1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep limits.cpu ")
infocpuout1 = infocpu1.readlines()
for infocpu in infocpuout1:
infocpu = infocpu.strip('\n limits.cpu: "')
infomem1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep limits.memory ")
infomemout1 = infomem1.readlines()
for infomem in infomemout1:
infomem = infomem.strip('\n limits.memory:')
infodisk1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep size ")
infodiskout1 = infodisk1.readlines()
for infodisk in infodiskout1:
infodisk = infodisk.strip('\n size: GB ')
inforunning1 = os.popen(f"lxc info --resources {idprefix}{ctx.author.id} | grep Status")
inforunningout1 = inforunning1.readlines()
for inforunning in inforunningout1:
inforunning = inforunning.strip('\n')
#infoccpu1 = os.popen(f"lxc info --resources {idprefix}{ctx.author.id} | grep -i 'CPU usage (in seconds):'")
#infoccpuout1 = infoccpu1.readlines()
#for infoccpu in infoccpuout1:
# infoccpu = infoccpu.strip('\n CPU usage (in seconds):')
#infoccpun = round(int(infoccpu)/(60*1))
infocreated1 = os.popen(f"lxc info --resources {idprefix}{ctx.author.id} | grep -i 'Created:'")
infocreatedout1 = infocreated1.readlines()
for infocreated in infocreatedout1:
infocreated = infocreated.strip('\n Created: UT')
if inforunning == "Status: STOPPED": # Stupid fix for UnboundLocalError
infolocalip = "Offline"
infocmem = "Offline"
checkvethdone = "Offline"
checknetlimitdone = "Offline"
else:
infolocalip1 = os.popen(f"lxc info --resources {idprefix}{ctx.author.id} | grep -i '{lxcips}'")
infolocalipout1 = infolocalip1.readlines()
for infolocalip in infolocalipout1:
infolocalip = infolocalip.strip('\n inet: (global)')
infolocalip = infolocalip.split('/', 1)[0]
infocmem1 = os.popen(f"lxc info --resources {idprefix}{ctx.author.id} | grep -i 'Memory (current):'")
infocmemout1 = infocmem1.readlines()
for infocmem in infocmemout1:
infocmem = infocmem.strip('\n Memory (current):')
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {idprefix}{ctx.author.id} | grep -i 'veth'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
#Check Network limits
try:
checknetlimit1 = os.popen(f"wondershaper {checkvethdone} | grep -i 'prio 1'")
checknetlimitout1 = checknetlimit1.readlines()
for checknetlimit in checknetlimitout1:
checknetlimit = checknetlimit.strip('\n rate')
checknetlimitdone = checknetlimit.split('rate', 1)[-1]
checknetlimitdone = checknetlimitdone.split('prio', 1)[0]
except:
checknetlimitdone = "Unmetered"
#Description text
desc = f"""```yaml
ID: {idprefix}{ctx.author.id}
{inforunning}
IP: {infolocalip}
Veth: {checkvethdone}
Cpu: Not Working
Ram: {infocmem}
```"""
#Embed
embed = discord.Embed(title="Your VpsInfo", description=desc, color=discord.Color.blue())
embed.add_field(name="Cpu: ", value=f"{infocpu} Vcores")
embed.add_field(name="Ram: ", value=f"{infomem}")
embed.add_field(name="Disk: ", value=f"{infodisk} GB")
embed.add_field(name="Net↿⇂: ", value=f"{checknetlimitdone}")
embed.set_footer(text = f"Created: {infocreated} UTC")
await ctx.reply(embed=embed)
############################# ADMIN version - \/
@client.command()
@commands.has_role(adminrole)
async def admininfovps(ctx, id):
logvarcmd = "infovps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Command
infocpu1 = os.popen(f"lxc config show {id} | grep limits.cpu ")
infocpuout1 = infocpu1.readlines()
for infocpu in infocpuout1:
infocpu = infocpu.strip('\n limits.cpu: "')
infomem1 = os.popen(f"lxc config show {id} | grep limits.memory ")
infomemout1 = infomem1.readlines()
for infomem in infomemout1:
infomem = infomem.strip('\n limits.memory:')
infodisk1 = os.popen(f"lxc config show {id} | grep size ")
infodiskout1 = infodisk1.readlines()
for infodisk in infodiskout1:
infodisk = infodisk.strip('\n size: GB ')
inforunning1 = os.popen(f"lxc info --resources {id} | grep Status")
inforunningout1 = inforunning1.readlines()
for inforunning in inforunningout1:
inforunning = inforunning.strip('\n')
#infoccpu1 = os.popen(f"lxc info --resources {id} | grep -i 'CPU usage (in seconds):'")
#infoccpuout1 = infoccpu1.readlines()
#for infoccpu in infoccpuout1:
# infoccpu = infoccpu.strip('\n CPU usage (in seconds):')
#infoccpun = round(int(infoccpu)/(60*1))
infocreated1 = os.popen(f"lxc info --resources {id} | grep -i 'Created:'")
infocreatedout1 = infocreated1.readlines()
for infocreated in infocreatedout1:
infocreated = infocreated.strip('\n Created: UT')
if inforunning == "Status: STOPPED": # Stupid fix for UnboundLocalError
infolocalip = "Offline"
infocmem = "Offline"
checkvethdone = "Offline"
checknetlimitdone = "Offline"
else:
infolocalip1 = os.popen(f"lxc info --resources {id} | grep -i '{lxcips}'")
infolocalipout1 = infolocalip1.readlines()
for infolocalip in infolocalipout1:
infolocalip = infolocalip.strip('\n inet: (global)')
infolocalip = infolocalip.split('/', 1)[0]
infocmem1 = os.popen(f"lxc info --resources {id} | grep -i 'Memory (current):'")
infocmemout1 = infocmem1.readlines()
for infocmem in infocmemout1:
infocmem = infocmem.strip('\n Memory (current):')
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {id} | grep -i 'host_name'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
#Check Network limits
try:
checknetlimit1 = os.popen(f"wondershaper {checkvethdone} | grep -i 'prio 1'")
checknetlimitout1 = checknetlimit1.readlines()
for checknetlimit in checknetlimitout1:
checknetlimit = checknetlimit.strip('\n rate')
checknetlimitdone = checknetlimit.split('rate', 1)[-1]
checknetlimitdone = checknetlimitdone.split('prio', 1)[0]
except:
checknetlimitdone = "Unmetered"
#Description text
desc = f"""```yaml
ID: {id}
{inforunning}
IP: {infolocalip}
Veth: {checkvethdone}
Cpu: Not Working
Ram: {infocmem}
```"""
#Embed
embed = discord.Embed(title="Your VpsInfo", description=desc, color=discord.Color.blue())
embed.add_field(name="Cpu: ", value=f"{infocpu} Vcores")
embed.add_field(name="Ram: ", value=f"{infomem}")
embed.add_field(name="Disk: ", value=f"{infodisk} GB")
embed.add_field(name="Net↿⇂: ", value=f"{checknetlimitdone}")
embed.set_footer(text = f"Created: {infocreated} UTC")
await ctx.reply(embed=embed)
########################################################## - Execute Commands In Vps \/ - Deprecated use WebSSH panel
# @client.command()
# async def exec(ctx, *, command: str):
# logvarcmd = "exec"
# print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Command
# execcmd1 = os.popen(f"lxc exec {idprefix}{ctx.author.id} -- sh -c '{command}'") # Fix for Vuln Here :))) - to do: fix "" in echo
# execcmdout1 = re.sub(r'\\.',lambda x:{'\\n':'\n','\\t':'\t','\\b':'\b','\\v':'\v'}.get(x[0],x[0]),f'{execcmd1.readlines()}') # Fix for Weird lines
# for execcmd in execcmdout1:
# execcmd = execcmd.strip('\n')
# if int(len(f"{execcmd}")) >= 6000:
# await ctx.reply("Cannot send, output exceeds 6000 lines")
# else:
# #Embed
# embed = discord.Embed(title="Executed!", description=f"```{execcmdout1}```", color=discord.Color.blue())
# await ctx.reply(embed=embed)
############################# ADMIN version - \/
@client.command()
@commands.has_role(adminrole)
async def adminexec(ctx, id, *, command: str):
logvarcmd = "adminexec"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Command
execcmd1 = os.popen(f"lxc exec {id} -- sh -c '{command}'") # Fix for Vuln Here :))) - to do: fix "" in echo
execcmdout1 = re.sub(r'\\.',lambda x:{'\\n':'\n','\\t':'\t','\\b':'\b','\\v':'\v'}.get(x[0],x[0]),f'{execcmd1.readlines()}') # Fix for Weird lines
for execcmd in execcmdout1:
execcmd = execcmd.strip('\n')
#Embed
embed = discord.Embed(title="Executed!", description=f"```{execcmdout1}```", color=discord.Color.blue())
await ctx.reply(embed=embed)
########################################################## - Re-Gen password \/
@client.command()
@commands.check(commandchannelid)
async def regenpass(ctx):
logvarcmd = "regenpass"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Re-Generated", description="Re-Generate VPS password", color=discord.Color.green())
#Fetch users using discord API
user = await client.fetch_user(ctx.author.id)
#Pass Gen using Bash Script
passgen1 = os.popen(f"bash /root/botvps-discord/passgen.sh")
passgenout1 = passgen1.readlines()
for passgen in passgenout1:
passgen = passgen.strip('\n')
os.system(f"lxc exec {idprefix}{ctx.author.id} -- sh -c 'echo 'root:{passgen}' | chpasswd'")
await user.send(f"""```yaml
User: root
Password: {passgen}
- to get ip do -infovps```
Panel: http://panel.vpsbot.ml:8888/""")
await ctx.reply(embed=embed)
########################################################## - Re-Gen password \/ - ADMIN
@client.command()
@commands.has_role(adminrole)
async def adminregenpass(ctx, id):
logvarcmd = "adminregenpass"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Embed
embed = discord.Embed(title="Re-Generated", description="Re-Generate VPS password", color=discord.Color.green())
#Fetch users using discord API
user = await client.fetch_user(ctx.author.id)
#Pass Gen using Bash Script
passgen1 = os.popen(f"bash /root/botvps-discord/passgen.sh")
passgenout1 = passgen1.readlines()
for passgen in passgenout1:
passgen = passgen.strip('\n')
os.system(f"lxc exec {id} -- sh -c 'echo 'root:{passgen}' | chpasswd'")
await user.send(f"""```yaml
User: root
Password: {passgen}
- to get ip do -infovps```
Panel: http://panel.vpsbot.ml:8888/""")
await ctx.reply(embed=embed)
########################################################## - Set Cpu to a Container - ADMIN
@client.command()
@commands.has_role(adminrole)
async def setcpu(ctx, id, vcores):
logvarcmd = "setcpu"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Command
os.system(f"lxc config set {id} limits.cpu={vcores}")
#Embed
embed = discord.Embed(title="Changed Successfully!", description="Change Cpu", color=discord.Color.green())
await ctx.reply(embed=embed)
########################################################## - Set Memory to a Container - ADMIN
@client.command()
@commands.has_role(adminrole)
async def setmem(ctx, id, mib):
logvarcmd = "setmem"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Command
os.system(f"lxc config set {id} limits.memory={mib}MiB")
#Embed
embed = discord.Embed(title="Changed Successfully!", description="Change Memory", color=discord.Color.green())
########################################################## - Set Disk to a Container - ADMIN
@client.command()
@commands.has_role(adminrole)
async def setdisk(ctx, id, disk):
logvarcmd = "setdisk"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Command
os.system(f"lxc config device remove {id} root")
os.system(f"lxc config device override {id} root size={disk}GB")
#Embed
embed = discord.Embed(title="Changed Successfully!", description="Change Disk", color=discord.Color.green())
await ctx.reply(embed=embed)
########################################################## - Set Network {Kbps} to a Container - ADMIN
@client.command()
@commands.has_role(adminrole)
async def setnet(ctx, id, up, down):
logvarcmd = "setnet"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
#Check for veth from id
checkveth1 = os.popen(f"lxc config show {id} | grep -i 'host_name'")
checkvethout1 = checkveth1.readlines()
for checkveth in checkvethout1:
checkveth = checkveth.strip('\n')
checkvethdone = checkveth.split(':', 1)[-1]
os.system(f"wondershaper {checkvethdone} {up} {down}")
#Embed
embed = discord.Embed(title="Changed Successfully!", description="Change Network [Kbps]", color=discord.Color.green())
await ctx.reply(embed=embed)
########################################################## - List of vpses - ADMIN
@client.command()
@commands.has_role(adminrole)
async def listvps(ctx):
logvarcmd = "listvps"
print(f"{logs}User {ctx.author.id} executed {logvarcmd}")
list1 = os.popen(f"lxc list -f csv | grep bot")
listout1 = re.sub(r'\\.',lambda x:{'\\n':'\n','\\t':'\t','\\b':'\b','\\v':'\v'}.get(x[0],x[0]),f'{list1.readlines()}')
#Embed
embed = discord.Embed(title="Vps List", description=f"```{listout1}```", color=discord.Color.green())
await ctx.reply(embed=embed)