-
Notifications
You must be signed in to change notification settings - Fork 2
/
jyexchange.py
3417 lines (1938 loc) · 97.3 KB
/
jyexchange.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
# -*- coding: utf-8 -*-
# J.Y. Exchange
# Using pyGTK and python 2.7 not 3 lol
import gtk
import threading
import os
import commands
import socket
import random
import glib
import datetime
import pango
import zipfile
import time
import sys
VERSION = 1.41 # A software version for the updater
def main_quit(widget):
cs1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cs1.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
cs1.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
serverip = commands.getoutput("hostname -I")
cs1.sendto("!JYESB ["+machinename.get_text()+"] "+serverip+" OUT", ('255.255.255.255', 54545))
gtk.main_quit()
exit()
#ZIP DEFS
def zip_folder(folder_path, output_path):
"""Zip the contents of an entire folder (with that folder included
in the archive). Empty subfolders will be included in the archive
as well.
"""
parent_folder = os.path.dirname(folder_path)
# Retrieve the paths of the folder contents.
contents = os.walk(folder_path)
try:
zip_file = zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED)
for root, folders, files in contents:
# Include all subfolders, including empty ones.
for folder_name in folders:
absolute_path = os.path.join(root, folder_name)
relative_path = absolute_path.replace(parent_folder + '/',
'')
zip_file.write(absolute_path, relative_path)
for file_name in files:
absolute_path = os.path.join(root, file_name)
relative_path = absolute_path.replace(parent_folder + '/',
'')
zip_file.write(absolute_path, relative_path)
except IOError, message:
print message
sys.exit(1)
except OSError, message:
print message
sys.exit(1)
except zipfile.BadZipfile, message:
print message
sys.exit(1)
finally:
zip_file.close()
#ok let's make our window
mainwindow = gtk.Window()
mainwindow.connect("destroy", main_quit)
mainwindow.set_title("J.Y. EXCHANGE "+str(VERSION))
mainwindow.set_default_size(500, 500)
mainwindow.set_position(gtk.WIN_POS_CENTER)
#mainwindow.maximize()
gtk.window_set_default_icon_from_file("py_data/icon.png")
box1 = gtk.VBox(False, 5)
#paaned I guess
vpaned = gtk.VPaned()
mainwindow.add(vpaned)
# "J.Y. EXCHANGE console... No input... Outpur only"
CONSOLEBOX = gtk.VBox(False)
CONSOLEBOX.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black"))
def treeview_changed(widget, thatsecondone):
global consolescroller
adj = consolescroller.get_vadjustment()
adj.set_value( adj.upper - adj.page_size )
consolescroller = gtk.ScrolledWindow()
consolescroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
consolescroller.set_size_request(100, 100)
consolescroller.set_shadow_type(gtk.SHADOW_NONE)
CONSOLEBOX.pack_start(consolescroller, True)
vpaned.pack1(box1, True, False)
vpaned.pack2(CONSOLEBOX, True, False)
def Print(text, error=False):
global console
global consoleview
text = str(text)
if text.find("\n") > 0:
text = text.replace("\n", "\n ")
end = console.get_end_iter()
hour = str(datetime.datetime.now().hour)
minute = str(datetime.datetime.now().minute)
second = str(datetime.datetime.now().second)
if len(hour) == 1:
hour = "0"+hour
if len(minute) == 1:
minute = "0"+minute
if len(second) == 1:
second = "0"+second
time = hour+":"\
+minute+":"\
+second
tmp = "["+time+"] "+text+"\n"
global e_tag
global m_tag
global r_tag
global h_tag
tag = False
tagging = False
if error == True:
tag = e_tag
tagging = True
print "\033[91m"+tmp[:-1].replace("<h>", "\033[94m")+"\033[m"
elif error == "m":
tag = m_tag
tagging = True
print "\033[93m"+tmp[:-1]+"\033[m"
elif error == "r":
tag = r_tag
tagging = True
print "\033[93m"+tmp[:-1]+"\033[m"
elif error == "h":
tag = h_tag
tagging = True
print "\033[94m"+tmp[:-1]+"\033[m"
#COMPLICATED MARCKUPS
if tmp.find("<h>") > 0:
tmp = text.split("<h>",1)
tmp[0] = "["+time+"] "+tmp[0]
if tagging == True:
console.insert_with_tags(end, tmp[0], tag)
console.insert_with_tags(end, tmp[1]+"\n", h_tag)
else:
console.insert(end, tmp[0])
console.insert_with_tags(end, tmp[1]+'\n', h_tag)
tagging = None
if tagging == True:
console.insert_with_tags(end, tmp, tag)
elif tagging == None:
pass
else:
console.insert(end, tmp)
print "\033[92m"+tmp[:-1]+"\033[m"
consoleview = gtk.TextView()
consoleview.set_editable(False)
consoleview.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("black"))
consoleview.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#00AA00"))
fontdesc = pango.FontDescription("Courier Bold")
consoleview.modify_font(fontdesc)
consoleview.connect("size-allocate", treeview_changed)
console = consoleview.get_buffer()
console.set_text("")
e_tag = console.create_tag("colored", foreground="#FF0000")
m_tag = console.create_tag("message", foreground="#AAAA00")
r_tag = console.create_tag("recieved", foreground="#FFFF00")
h_tag = console.create_tag("help", foreground="#2222FF")
##little console intpu thing
INPUTBOX = gtk.HBox(False)
def consoleinput(widget):
hour = str(datetime.datetime.now().hour)
minute = str(datetime.datetime.now().minute)
second = str(datetime.datetime.now().second)
if len(hour) == 1:
hour = "0"+hour
if len(minute) == 1:
minute = "0"+minute
if len(second) == 1:
second = "0"+second
time = hour+":"\
+minute+":"\
+second
text = widget.get_text()
global client
Print("INPUTED COMMAND: ["+text+"]", "m")
# SAY: sending a message
if text.startswith("SAY:"):
widget.set_text("SAY: ")
widget.set_position(-1)
if not text[5:]:
Print("COMMAND [SAY:] ERROR! [NO SENDING ARGUMENT]", True)
return
try:
client.send(text)
#Print("SENT: "+text[5:], "m")
except:
Print("CONNECTION ERROR", True)
elif text.startswith("UPDATE"):
update()
widget.set_text("")
elif text.startswith("BNAME: "):
machinename.set_text(text[7:])
widget.set_text("")
elif text.startswith("ADD: "):
if os.path.exists(text[5:]):
if ["file://"+text[5:], text[5:][text[5:].rfind("/")+1:]] not in upfiles:
upfiles.append(["file://"+text[5:], text[5:][text[5:].rfind("/")+1:], uplock])
if not duringscript:
refrashuploads()
else:
Print("PATH ["+text[5:]+"] DOES NOT EXIST", True)
widget.set_text("")
elif text.startswith("DEL: "):
try:
if int(text[5:]) > 0:
try:
del upfiles[int(text[5:])]
Print("ITEM NUMBER ["+text[5:]+"] WAS REMOVED")
refrashuploads()
except:
Print("CANNOT REMOVE THE ITEM", True)
else:
Print("CANNOT REMOVE LOCAL UPDATE", True)
except:
Print("SYNTAX ERROR, PROBABLY ARGUMENT IS NOT A NUMBER", True)
widget.set_text("")
elif text == "UPFILES":
for num, item in enumerate(upfiles):
l = "UNLOCKED"
if item[-1] == True:
l = "LOCKED"
if num > 0:
Print(str(num)+ " " +item[1]+" "+l)
else:
Print("0 LOCAL UPDATE FILE", "m")
widget.set_text("")
elif text.startswith("SNAKE"):
Print("THE BITCHY PYTHON", True)
import snake
widget.set_text("")
# CONNECT
elif text.startswith("DIP: "):
dipentry.set_text(text[5:])
widget.set_text("")
elif text.startswith("DPORT: "):
dportentry.set_text(text[7:])
widget.set_text("")
elif text == "CONNECT":
global CONNECTED
if CONNECTED == False:
ONuprefresh(True)
else:
Print("ALREADY CONNECTED", True)
widget.set_text("")
elif text.startswith("CONNECT TO: "):
import time as thetime
thetime.sleep(2)
found = False
for item in recvmach:
if text[len("CONNECT TO:")+1:] == item[item.find("[")+1:item.rfind("]")]:
ip, port = item[item.rfind("]")+2:].split(" ")
dipentry.set_text(ip)
dportentry.set_text(port)
found = True
Print("CONNECTED SUCCESSFULY TO ["+text[len("CONNECT TO:")+1:]+"]")
ONuprefresh(True)
if found == False:
Print("THERE IS NO SUCH NAME AS ["+text[len("CONNECT TO:")+1:]+"]", True)
import time as thetime
thetime.sleep(2)
elif text.startswith("DESTINATION: "):
dfolrerentry.set_text(text[len("DESTINATION: "):])
elif text.startswith("GET: "):
while DOWNLOADING == True:
if DOWNLOADING == False:
break
try:
for num, item in enumerate(dfiles):
url, name, lock, folder, percent = item
if num == int(text[5:]):
REQUEST_DOWLOAD(url)
except:
raise
Print("SYNTAX ERROR (PROBABLY ARGUMENT IS NOT A NUMBER)", True)
elif text.startswith("WAIT FOR: "):
Print("WAITING FOR "+text[len("WAIT FOR: "):]+" ...")
while gtk.events_pending():
gtk.main_iteration_do(False)
found = False
while found == False:
for item in recvmach:
if text[len("WAIT FOR: "):] == item[item.find("[")+1:item.rfind("]")]:
found = True
Print ("THE NAME ["+text[len("WAIT FOR: "):]+"] IS FOUND")
widget.set_text("")
elif text == "EXIT":
main_quit(True)
elif text.startswith("HELP"):
Print("HELP! \n"\
+"\nThe JYEXCHANGE since version 1.3 supports scripting\n"\
+"for that you can write a file with console commands listed\n"\
+"down. Similar to Bash / sh scripts. And save the file with an extension .jyes\n"\
+"\nTo run the .jyes scripts. You need to set it's path in the ternimal\n"\
+"such as [python jyexchenge.py /home/yourname/Desktop/yourscript.jyes]\n\n"\
+"ADD: argument - add a path (file or folder) to the upload list\n"\
+"DEL: number - remove the item from upload by it's number in the list\n"\
+"UPFILES - output into console the list of the upload files\n"\
+"BNAME: argument - Change Broadcast name\n"\
+"SAY: argument - sending message\n"\
+"DIP: argument - changing Download IP for the connection\n"\
+"DPORT: argument - changing Download PORT for the connection\n"\
+"CONNECT - connecting to IP, PORT specified at the top\n"\
+"WAIT FOR: argument- halt the system intil a particular name broadcasted\n"\
+"CONNECT TO: argum - connection to specified username, recieved from broadcast\n"\
+"DESTINATION: argu - change the download folder\n"\
+"GET: number - download a given item from the download list\n"\
+"UPDATE - update the software using github link\n"\
+"SNAKE - play snake (works just ones during runtime)\n"\
+"PYTHON: argument - executes python command and returns the value\n"\
+"SAVE - saving text from this console to .txt file at\n"\
+" a directory specified for Dowloading.\n"\
+"SAVE TO: argument - saving text from this conlose to custom directory"\
+"EXIT - exit the software", "h" )
widget.set_text("")
elif text.startswith("PYTHON:"):
widget.set_text("PYTHON: ")
widget.set_position(-1)
for k, v in list(globals().iteritems()):
if k in text:
for i in ["=", "del","append"]:
if i in text:
Print("PYTHON: ERROR [ATTEMPT TO MODIFY PROGRAM DATA STOPPED]", True)
return
if not text[8:]:
Print("COMMAND [PYTHON:] ERROR! [NO ARGUMENT]", True)
return
try:
Print( "PYTHON: "+str(eval(text[8:])))
except:
Print("PYTHON: ERROR", True)
raise
elif text.startswith("SAVE"):
path = dfolrerentry.get_text()
if text.startswith("SAVE TO:"):
if not text[9:]:
Print("FORGOT TO TYPE IN A PATH", True)
return
path = text[9:]
elif text == "SAVE":
path = dfolrerentry.get_text()
if not os.path.exists(path):
try:
os.makedirs(path)
except:
Print("ERROR! UNABLE TO MAKE DIRECTORY ["+path+"]", True)
return
filename = "/"+str(datetime.datetime.now()).replace(" ", "_").replace(".","_")+"_CONSOLE_LOG.txt"
savelog = open(path+filename, "w")
savelog.write("J.Y.EXCHANGE SAVED LOG ["+text+"]\n")
savelog.write("VERSION "+str(VERSION)+"\n\n")
savelog.write("TIME: "+str(datetime.datetime.now())+"\n\n")
start = console.get_start_iter()
end = console.get_end_iter()
consoletext = str( console.get_text(start, end) )
savelog.write(consoletext)
savelog.close()
Print("SAVED TO: "+path+filename)
widget.set_text("")
else:
if text.find(" ") > 0:
Print("ERROR! COMMAND: ["+text[:text.find(" ")]+"] IS UNKNOWN\nTRY <h>HELP", True)
else:
Print("ERROR! COMMAND: ["+text+"] IS UNKNOWN\nTRY <h>HELP", True)
widget.set_text("")
def sayyellow(widget):
text = text = widget.get_text()
if text == "SAY:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("SAY: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text.startswith("EXIT"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FF0000"))
elif text.startswith("DIP:"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("DPORT:"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("DESTINATION: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text == "CONNECT":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text == "CONNECT TO:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("CONNECT TO: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text.startswith("HELP"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#2222FF"))
elif text.startswith("UPDATE"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("UPFILES"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text == "WAIT FOR:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("WAIT FOR: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text == "DEL:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("DEL: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text == "ADD:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("ADD: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text == "BNAME:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("BNAME: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text.startswith("SNAKE"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text == "PYTHON:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("PYTHON: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text == "SAVE":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text == "SAVE TO:":
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#AAAA00"))
elif text.startswith("SAVE TO: "):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFF00"))
elif text.startswith("SAVE"):
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#555500"))
else:
widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#00AA00"))
INPUT = gtk.Entry()
INPUT.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("black"))
INPUT.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#00AA00"))
INPUT.modify_font(fontdesc)
INPUT.set_has_frame(False)
INPUT.connect("activate", consoleinput)
INPUT.connect("changed", sayyellow)
INPUTBOX.pack_end(INPUT, True)
CONSOLEBOX.pack_end(INPUTBOX, False)
consolescroller.add_with_viewport(consoleview)
Print("START UP")
### place ultra main tools here
settingsframe = gtk.Frame("Settings")
box1.pack_start(settingsframe, False)
settingsbox = gtk.HBox(False)
settingsframe.add(settingsbox)
ticks_frame = gtk.Frame("Server Tick")
settingsbox.pack_start(ticks_frame, False)
tickbox = gtk.HBox(False)
ticks_frame.add(tickbox)
tickl1 = gtk.Label("Each")
tickl2 = gtk.Label("ms")
tickbox.pack_start(tickl1, False)
TICKSPEED = 100
def onupdatetick(widget):
global TICKSPEED
TICKSPEED = int(widget.get_value())
tickadj = gtk.Adjustment(1.0, 1.0, 500.0, 1.0, 5.0, 0.0)
ticksbutton = gtk.SpinButton(tickadj, 0, 0)
ticksbutton.set_value(TICKSPEED)
ticksbutton.connect("value-changed", onupdatetick)
ticksbutton.set_wrap(True)
tickbox.pack_start(ticksbutton)
tickbox.pack_end(tickl2, False)
updateframe = gtk.Frame("Local Update")
settingsbox.pack_end(updateframe, False)
updatebox = gtk.HBox(False)
updateframe.add(updatebox)
updatelabel = gtk.Label("Version :"+str(VERSION)+" Avalable: Non ")
updatebox.pack_start(updatelabel, False)
lupdate = gtk.Button()
updateicon = gtk.Image()
updateicon.set_from_file("py_data/icons/save.png")
updateblabel = gtk.Label("Localy Update")
updatebuttonbox = gtk.HBox()
updatebuttonbox.pack_start(updateicon, False)
updatebuttonbox.pack_start(updateblabel, False)
lupdate.add(updatebuttonbox)
lupdate.set_tooltip_text("Dowloading Avalable Version and updates to it\nRequire restart of the programm")
lupdate.set_sensitive(False)
updatebox.pack_start(lupdate, False)
globalupdateframe = gtk.Frame("GitHub Update")
settingsbox.pack_end(globalupdateframe, True)
def on_updatelist(widget):
updwin = gtk.Window()
updwin.set_title("Updates Log ["+os.getcwd()+"/LUPDATES]")
updwin.set_position(gtk.WIN_POS_CENTER)
updbox = gtk.VBox(False)
updwin.add(updbox)
updscroll = gtk.ScrolledWindow()
updscroll.set_size_request(800,400)
updatefile = open("LUPDATES", "r")
updatefile = updatefile.read()
updbox2 = gtk.VBox(False)
updscroll.add_with_viewport(updbox2)
def forLNK(w, link):
os.system("xdg-open "+link)
for x, i in enumerate(updatefile.split("\n")):
n = str(x)
import urllib2
if i.startswith("!"):
if i.startswith("!IMG "):
tmpimage = urllib2.urlopen(i[5:])
tmpimagefile = open("py_data/tmp_update_picture.png", "w")
tmpimagefile.write(tmpimage.read())
tmpimagefile.close()
com = "updateimage"+n+" = gtk.Image()"
exec(com) in globals(), locals()
com = "updateimage"+n+".set_from_file('py_data/tmp_update_picture.png')"
exec(com) in globals(), locals()
com = "updbox2.pack_start(updateimage"+n+", False)"
exec(com) in globals(), locals()
elif i.startswith("!LNK "):
link = i[i.find(" ")+1: i.find("[")-1]
#print link
buttonname = i[i.find("[")+1: i.find("]")]
#print buttonname
com = "updateLNKbutton"+n+" = gtk.Button('"+buttonname+"')"
exec(com) in globals(), locals()
com = "updateLNKbutton"+n+".set_tooltip_text('"+link+"')"
exec(com) in globals(), locals()
com = "updateLNKbutton"+n+".connect('clicked', forLNK, '"+link+"')"
exec(com) in globals(), locals()
com = "updbox2.pack_start(updateLNKbutton"+n+", False)"
exec(com) in globals(), locals()
else:
uplabel = gtk.Label(i)
uplabel.modify_font(pango.FontDescription("Monospace"))
updbox2.pack_start(uplabel, False)
updbox.pack_start(updscroll, False)
updwin.show_all()
gitdatebox = gtk.HBox(False)
globalupdateframe.add(gitdatebox)
updateslist = gtk.Button()
updateslisticon = gtk.Image()
updateslisticon.set_from_file("py_data/icons/unknown.png")
updateslistbox = gtk.HBox(False)
updateslist.add(updateslistbox)
updateslistbox.pack_start(updateslisticon, False)
updateslistbox.pack_start(gtk.Label("Local Version Features"), True)
updateslist.connect("clicked", on_updatelist)
gitdatebox.pack_start(updateslist)
def on_globalupdate(w):
w.set_sensitive(False)
while gtk.events_pending():
gtk.main_iteration_do(False)
updatefunction()
globalupdate.set_sensitive(True)
globalupdate = gtk.Button()
globalupdatebox = gtk.HBox(False)
globalupdateicon = gtk.Image()
globalupdateicon.set_from_file("py_data/icons/save.png")
globalupdatebox.pack_start(globalupdateicon, False)
globalupdatebox.pack_start(gtk.Label("GitHub Update"), True)
globalupdate.add(globalupdatebox)
globalupdate.connect("clicked", on_globalupdate)
gitdatebox.pack_start(globalupdate)
bigbox = gtk.HPaned()
box1.pack_start(bigbox)
serverbox = gtk.VBox(False)
bigbox.pack1(serverbox, True, False)
serverframe = gtk.Frame("Upload")
serverbox.pack_start(serverframe)
upt1box = gtk.VBox(False)
serverframe.add(upt1box)
upsockettools = gtk.HBox(False)
upt1box.pack_start(upsockettools, False)
upsbox = None
#RELOAD SOCKET BUTTON
def socksetrefresh(widget):
global upsbox
global upsockettools
upsbox.destroy()
upsbox = gtk.HBox(False)
upsockettools.pack_start(upsbox)
upsocketsettings()
upsbox.show_all()
# to make it work lol
def glibrefrservsocketthreadsshit():
socksetrefresh(True)
glib.timeout_add(TICKSPEED, glibrefrservsocketthreadsshit)
glib.timeout_add(1, glibrefrservsocketthreadsshit)
upsbox = gtk.HBox(False)
upsockettools.pack_start(upsbox)
upport = random.randint(1000, 10000)
curwpf = "file://"+os.getcwd()+"/"+__file__
upfiles = [[curwpf, str(VERSION), False ]]
uplock = False
serverdone = False
def servering():
global upport
server = socket.socket()
while True:
Print("TRYING MAKING SERVER AT PORT: "+str(upport))
try:
server.bind(("",upport))
global upportentry
try:
upportentry.set_text(str(upport))
except:
pass
global serverdone
serverdone = True
break
except:
old = upport
upport = random.randint(1000, 10000)
Print( "PORT "+str(old)+" FAILED: REFUSED CONNECTION! NEW PORT:"+str(upport), True )
#raise
if True:
if serverdone == True:
server.listen(1)
import commands
serverip = commands.getoutput("hostname -I")
if serverip not in ["", " ", "\n", " \n"]:
Print( "CONNECTION ESTABLISHED! SERVER STARTED")
else:
Print( "SERVER BINED BUT NO INTERNET CONNECTION. WAITING FOR CONNECTION", True)
c, addr = server.accept()
Print( "CLIENT HAS CONNECTED : [ IP: " +str(addr[0]) + " PORT: "+str(addr[1])+ "]")
cs1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cs1.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
cs1.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
serverip = commands.getoutput("hostname -I")
cs1.sendto("!JYESB ["+machinename.get_text()+"] "+serverip+" OUT", ('255.255.255.255', 54545))
broadcheck.set_sensitive(False)
broadcheck.set_active(False)
broadcastallow = False
# MAIN SERVER TALK