99import base64
1010import json
1111import uuid
12+ import pyzipper
1213from django .conf import settings as _settings
1314from django .db .models import Q
1415from .forms import GenerateForm
1516from .models import GithubRun
1617from PIL import Image
1718from urllib .parse import quote
18- from cryptography .hazmat .primitives import hashes , serialization
19- from cryptography .hazmat .primitives .asymmetric import padding
2019
2120def generator_view (request ):
2221 if request .method == 'POST' :
@@ -48,6 +47,8 @@ def generator_view(request):
4847 installation = form .cleaned_data ['installation' ]
4948 settings = form .cleaned_data ['settings' ]
5049 appname = form .cleaned_data ['appname' ]
50+ if not appname :
51+ appname = "rustdesk"
5152 filename = form .cleaned_data ['exename' ]
5253 compname = form .cleaned_data ['compname' ]
5354 if not compname :
@@ -98,18 +99,22 @@ def generator_view(request):
9899 iconfile = form .cleaned_data .get ('iconfile' )
99100 if not iconfile :
100101 iconfile = form .cleaned_data .get ('iconbase64' )
101- iconlink = save_png (iconfile ,myuuid ,full_url ,"icon.png" )
102+ iconlink_url , iconlink_uuid , iconlink_file = save_png (iconfile ,myuuid ,full_url ,"icon.png" )
102103 except :
103104 print ("failed to get icon, using default" )
104- iconlink = "false"
105+ iconlink_url = "false"
106+ iconlink_uuid = "false"
107+ iconlink_file = "false"
105108 try :
106109 logofile = form .cleaned_data .get ('logofile' )
107110 if not logofile :
108111 logofile = form .cleaned_data .get ('logobase64' )
109- logolink = save_png (logofile ,myuuid ,full_url ,"logo.png" )
112+ logolink_url , logolink_uuid , logolink_file = save_png (logofile ,myuuid ,full_url ,"logo.png" )
110113 except :
111114 print ("failed to get logo" )
112- logolink = "false"
115+ logolink_url = "false"
116+ logolink_uuid = "false"
117+ logolink_file = "false"
113118
114119 ###create the custom.txt json here and send in as inputs below
115120 decodedCustom = {}
@@ -192,21 +197,20 @@ def generator_view(request):
192197 base64_bytes = base64 .b64encode (string_bytes )
193198 encodedCustom = base64_bytes .decode ("ascii" )
194199
195- #github limits inputs to 10, so lump extras into one with json
196- extras = {}
197- extras ['genurl' ] = _settings .GENURL
198- #extras['runasadmin'] = runasadmin
199- extras ['urlLink' ] = urlLink
200- extras ['downloadLink' ] = downloadLink
201- extras ['delayFix' ] = 'true' if delayFix else 'false'
202- extras ['version' ] = version
203- extras ['rdgen' ] = 'true'
204- extras ['cycleMonitor' ] = 'true' if cycleMonitor else 'false'
205- extras ['xOffline' ] = 'true' if xOffline else 'false'
206- extras ['removeNewVersionNotif' ] = 'true' if removeNewVersionNotif else 'false'
207- extras ['compname' ] = compname
208- extras ['androidappid' ] = androidappid
209- extra_input = json .dumps (extras )
200+ # #github limits inputs to 10, so lump extras into one with json
201+ # extras = {}
202+ # extras['genurl'] = _settings.GENURL
203+ # #extras['runasadmin'] = runasadmin
204+ # extras['urlLink'] = urlLink
205+ # extras['downloadLink'] = downloadLink
206+ # extras['delayFix'] = 'true' if delayFix else 'false'
207+ # extras['rdgen'] = 'true'
208+ # extras['cycleMonitor'] = 'true' if cycleMonitor else 'false'
209+ # extras['xOffline'] = 'true' if xOffline else 'false'
210+ # extras['removeNewVersionNotif'] = 'true' if removeNewVersionNotif else 'false'
211+ # extras['compname'] = compname
212+ # extras['androidappid'] = androidappid
213+ # extra_input = json.dumps(extras)
210214
211215 ####from here run the github action, we need user, repo, access token.
212216 if platform == 'windows' :
@@ -223,19 +227,59 @@ def generator_view(request):
223227 url = 'https://api.github.com/repos/' + _settings .GHUSER + '/' + _settings .REPONAME + '/actions/workflows/generator-windows.yml/dispatches'
224228
225229 #url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rustdesk/actions/workflows/test.yml/dispatches'
230+ inputs_raw = {
231+ "server" :server ,
232+ "key" :key ,
233+ "apiServer" :apiServer ,
234+ "custom" :encodedCustom ,
235+ "uuid" :myuuid ,
236+ "iconlink_url" :iconlink_url ,
237+ "iconlink_uuid" :iconlink_uuid ,
238+ "iconlink_file" :iconlink_file ,
239+ "logolink_url" :logolink_url ,
240+ "logolink_uuid" :logolink_uuid ,
241+ "logolink_file" :logolink_file ,
242+ "appname" :appname ,
243+ "genurl" :_settings .GENURL ,
244+ "urlLink" :urlLink ,
245+ "downloadLink" :downloadLink ,
246+ "delayFix" : 'true' if delayFix else 'false' ,
247+ "rdgen" :'true' ,
248+ "cycleMonitor" : 'true' if cycleMonitor else 'false' ,
249+ "xOffline" : 'true' if xOffline else 'false' ,
250+ "removeNewVersionNotif" : 'true' if removeNewVersionNotif else 'false' ,
251+ "compname" : compname ,
252+ "androidappid" :androidappid ,
253+ "filename" :filename
254+ }
255+
256+ temp_json_path = f"data_{ uuid .uuid4 ()} .json"
257+ zip_filename = f"secrets_{ uuid .uuid4 ()} .zip"
258+ zip_path = "temp_zips/%s" % (zip_filename )
259+ Path ("temp_zips" ).mkdir (parents = True , exist_ok = True )
260+
261+ with open (temp_json_path , "w" ) as f :
262+ json .dump (inputs_raw , f )
263+
264+ with pyzipper .AESZipFile (zip_path , 'w' , compression = pyzipper .ZIP_LZMA , encryption = pyzipper .WZ_AES ) as zf :
265+ zf .setpassword (_settings .ZIP_PASSWORD .encode ())
266+ zf .write (temp_json_path , arcname = "secrets.json" )
267+
268+ # 4. Cleanup the plain JSON file immediately
269+ if os .path .exists (temp_json_path ):
270+ os .remove (temp_json_path )
271+
272+ zipJson = {}
273+ zipJson ['url' ] = full_url
274+ zipJson ['file' ] = zip_filename
275+
276+ zip_url = json .dumps (zipJson )
277+
226278 data = {
227- "ref" :"master" ,
279+ "ref" :_settings . GHBRANCH ,
228280 "inputs" :{
229- "server" :server ,
230- "key" :key ,
231- "apiServer" :apiServer ,
232- "custom" :encodedCustom ,
233- "uuid" :myuuid ,
234- "iconlink" :iconlink ,
235- "logolink" :logolink ,
236- "appname" :appname ,
237- "extras" :extra_input ,
238- "filename" :filename
281+ "version" :version ,
282+ "zip_url" :zip_url
239283 }
240284 }
241285 #print(data)
@@ -357,7 +401,7 @@ def startgh(request):
357401 ####from here run the github action, we need user, repo, access token.
358402 url = 'https://api.github.com/repos/' + _settings .GHUSER + '/' + _settings .REPONAME + '/actions/workflows/generator-' + data_ .get ('platform' )+ '.yml/dispatches'
359403 data = {
360- "ref" :"master" ,
404+ "ref" : _settings . GHBRANCH ,
361405 "inputs" :{
362406 "server" :data_ .get ('server' ),
363407 "key" :data_ .get ('key' ),
@@ -400,12 +444,12 @@ def save_png(file, uuid, domain, name):
400444 with open (file_save_path , "wb+" ) as f :
401445 for chunk in file .chunks ():
402446 f .write (chunk )
403- imageJson = {}
404- imageJson ['url' ] = domain
405- imageJson ['uuid' ] = uuid
406- imageJson ['file' ] = name
447+ # imageJson = {}
448+ # imageJson['url'] = domain
449+ # imageJson['uuid'] = uuid
450+ # imageJson['file'] = name
407451 #return "%s/%s" % (domain, file_save_path)
408- return json . dumps ( imageJson )
452+ return domain , uuid , name
409453
410454def save_custom_client (request ):
411455 file = request .FILES ['file' ]
@@ -417,3 +461,37 @@ def save_custom_client(request):
417461 f .write (chunk )
418462
419463 return HttpResponse ("File saved successfully!" )
464+
465+ def cleanup_secrets (request ):
466+ # Pass the UUID as a query param or in JSON body
467+ my_uuid = request .GET .get ('uuid' )
468+
469+ if not my_uuid :
470+ return HttpResponse ("Missing UUID" , status = 400 )
471+
472+ # 1. Find the files in your temp directory matching the UUID
473+ temp_dir = os .path .join ('temp_zips' )
474+
475+ # We look for any file starting with 'secrets_' and containing the uuid
476+ for filename in os .listdir (temp_dir ):
477+ if my_uuid in filename and filename .endswith ('.zip' ):
478+ file_path = os .path .join (temp_dir , filename )
479+ try :
480+ os .remove (file_path )
481+ print (f"Successfully deleted { file_path } " )
482+ except OSError as e :
483+ print (f"Error deleting file: { e } " )
484+
485+ return HttpResponse ("Cleanup successful" , status = 200 )
486+
487+ def get_zip (request ):
488+ filename = request .GET ['filename' ]
489+ #filename = filename+".exe"
490+ file_path = os .path .join ('temp_zips' ,filename )
491+ with open (file_path , 'rb' ) as file :
492+ response = HttpResponse (file , headers = {
493+ 'Content-Type' : 'application/vnd.microsoft.portable-executable' ,
494+ 'Content-Disposition' : f'attachment; filename="{ filename } "'
495+ })
496+
497+ return response
0 commit comments