class Metric_Services(models.Model): id_customer = models.IntegerField() id_service = models.IntegerField() information_connect = models.CharField(max_length=250, blank=True) max_storage = models.IntegerField() username_account = models.CharField(max_length=250, blank=True) # 0: Azure Blob Storage; 1: đang cập nhật is_service = models.IntegerField() # 0: Chưa sử dụng; 1: Đã sử dụng status = models.IntegerField(default=0) #0: tạo trên agent: 1: tạo tạo web server type = models.IntegerField(default=0) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): new = Metric_Services.objects.create( id_customer=kwargs['id_customer'], id_service=kwargs['id_service'], information_connect=kwargs['information_connect'], max_storage=kwargs['max_storage'], username_account=kwargs['username_account'], type=1, is_service=0, status=0, ) return new.id
class bytesave_cycle(models.Model): id_customer = models.IntegerField() #Tổng số máy sử dụng bytesave_amount_used = models.IntegerField(default=1) # Thời hạn sừ dụng bytesave_duration = models.IntegerField(null=True, blank=True) # 0: tháng; 1: năm bytesave_time_type = models.IntegerField(default=1) bytesave_start_date = models.IntegerField( null=True, default=Timer.get_timestamp_now()) bytesave_expiration_date = models.IntegerField( null=True, default=Timer.get_timestamp_now()) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): bytesave_cycle.objects.create( id_customer=kwargs['id_customer'], bytesave_amount_used=kwargs['bytesave_amount_used'], bytesave_duration=kwargs['bytesave_duration'], bytesave_time_type=kwargs['bytesave_time_type'], bytesave_start_date=kwargs['bytesave_start_date'], bytesave_expiration_date=kwargs['bytesave_expiration_date'], )
class Agents(models.Model): id_customer = models.IntegerField() id_customer_bytesave = models.IntegerField(default=0) os = models.CharField(max_length=250, blank=True, null=True) serial_number = models.CharField(max_length=250, blank=True, null=True) ip_public = models.CharField(max_length=250, blank=True, null=True) ip_private = models.CharField(max_length=250, blank=True, null=True) name_computer = models.CharField(max_length=250, blank=True, null=True) #agent duy trì đăng nhập #0: khong #1: co duy trì is_logged = models.IntegerField(default=1) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): new = Agents.objects.create( id_customer=kwargs['id_customer'], id_customer_bytesave=kwargs['id_customer_bytesave'], os=kwargs['os'], serial_number=kwargs['serial_number'], ip_public=kwargs['ip_public'], ip_private=kwargs['ip_private'], name_computer=kwargs['name_computer'], ) return new.id
class Versions(models.Model): name = models.CharField(max_length=100, blank=True) description = models.CharField(max_length=250, blank=True) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): Versions.objects.create( name=kwargs['name'], description=kwargs['description'], is_del=0, )
class log_contents(models.Model): log_content = models.CharField(max_length=500, blank=True) function = models.CharField(max_length=250, blank=True) status = models.CharField(max_length=250, blank=True) time_log = models.IntegerField(default=Timer.get_timestamp_now()) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): log_contents.objects.create( log_content=kwargs['log_content'], function=kwargs['function'], status=kwargs['status'], )
def information_bytesave(request, serial_number, email_loggin): if request.method == 'GET': try: data = [] item = Customers.objects.filter(~Q(is_del=1)).get( email=email_loggin) name_version = Versions.objects.get( id=item.id_version ).name if item.id_version != 0 else Versions.objects.all()[0].name #item_cycle = bytesave_cycle.objects.filter(id_customer=item.id).order_by('-id')[0] bytesave_expiration_date = 0 # Kiểm tra chu kì: # get list chu kì có time hết hạn > time.now(): nếu count() = 0 thì return tài khaorn đã hết hạn item_cycles = bytesave_cycle.objects.filter(~Q(is_del=1)).filter( id_customer=item.id).filter( bytesave_expiration_date__gte=Timer.get_timestamp_now()) if item_cycles.count() > 0: bytesave_expiration_date = item_cycles.first( ).bytesave_expiration_date # Tìm tổng số máy được sử dụng number_used = 0 for item_cycle in item_cycles: if item_cycle.bytesave_start_date > Timer.get_timestamp_now(): continue if item_cycle.bytesave_start_date <= Timer.get_timestamp_now(): number_used += item_cycle.bytesave_amount_used items_agents_logged = Agents.objects.filter( id_customer=item.id).filter(is_logged=1).filter(~Q(is_del=1)) if number_used < items_agents_logged.count(): bytesave_expiration_date = 0 data.append({ 'name_version': name_version, 'bytesave_expiration_date': bytesave_expiration_date, }) return JsonResponse({ 'status': 'true', 'countdata': 1, 'data': data }) except Exception as e: return JsonResponse({ 'status': 'false', 'countdata': 0, 'data': [], 'error': str(e) }) return JsonResponse({'status': 'false', 'countdata': 0, 'data': data})
def create_metric_service_agent(request): if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) id_metric_service = form.get('id_ser') serial_number = form.get('serial_number') if id_metric_service == '0' or id_metric_service == '': # thêm mới try: Metric_Services.create( **{ 'id_customer': Agents.objects.get( serial_number=serial_number).id_customer, 'id_service': form.get('id_service_s'), 'information_connect': form.get('information_connect'), 'max_storage': form.get('max_storage'), 'username_account': form.get('username_account'), 'type': 1, }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'string_error': e }) else: # Chỉnh sửa try: item = Metric_Services.objects.get(id=id_metric_service) item.id_customer = id item.id_service = form.get('id_service_s') item.information_connect = form.get('information_connect') item.max_storage = form.get('max_storage') item.username_account = form.get('username_account') item.time_update_at = Timer.get_timestamp_now() item.save() return JsonResponse({ 'status': 'true', 'msg': 'Chỉnh sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'string_error': e }) return None
class Customers(models.Model): id_loggin = models.IntegerField(default=0) id_version = models.IntegerField(default=1) name = models.CharField(max_length=250) email = models.CharField(max_length=250) # 0: cá nhân; 1: doanh nghiệp type = models.IntegerField(default=1) phone_number = models.CharField(max_length=250, blank=True, null=True) # thành phố lưu theo int city = models.IntegerField(default=1) address = models.CharField(max_length=250, blank=True, null=True) tax_code = models.CharField(max_length=250, blank=True, null=True) website = models.CharField(max_length=250, blank=True, null=True) fax = models.CharField(max_length=250, blank=True, null=True) # người đại diện pháp luật legal_representative = models.CharField(max_length=250, blank=True, null=True) scale = models.IntegerField(default=1) # lĩnh vức field = models.IntegerField(default=1) # 0: không ký hợp đồng nâng cấp; 1: ký hợp đồng nâng cấp is_upgrade_version = models.IntegerField(default=0) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): Customers.objects.create( id_loggin=kwargs['id_loggin'], id_version=kwargs['id_version'], name=kwargs['name'], email=kwargs['email'], type=kwargs['type'], phone_number=kwargs['phone_number'], city=kwargs['city'], address=kwargs['address'], tax_code=kwargs['tax_code'], website=kwargs['website'], fax=kwargs['fax'], legal_representative=kwargs['legal_representative'], scale=kwargs['scale'], field=kwargs['field'], is_upgrade_version=kwargs['is_upgrade_version'], )
class Loggin(models.Model): email = models.CharField(max_length=250) name = models.CharField(max_length=250, null=True) pwd = models.CharField(max_length=250, null=True) # 0: admin; 1: nhân viên type = models.IntegerField(default=1, null=True) # 0: không khóa; 1: khóa is_lock = models.IntegerField(default=0) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): Loggin.objects.create( email=kwargs['email'], name=kwargs['name'], pwd=kwargs['pwd'], type=kwargs['type'], )
class setting_bytesave(models.Model): id_agent = models.IntegerField() server_mail = models.CharField(max_length=250, blank=True) port = models.CharField(max_length=250, blank=True) mail_send = models.CharField(max_length=250, blank=True) mail_send_pwd = models.CharField(max_length=250, blank=True, null=True) subject = models.CharField(max_length=250, blank=True, null=True) is_ssl = models.IntegerField(default=1) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): setting_bytesave.objects.create( id_agent=kwargs['id_agent'], server_mail=kwargs['server_mail'], port=kwargs['port'], mail_send=kwargs['mail_send'], mail_send_pwd=kwargs['mail_send_pwd'], subject=kwargs['subject'], )
class connect_bytesave(models.Model): id_agent = models.IntegerField() id_customer = models.IntegerField(default=0) id_metric_service = models.IntegerField() name = models.CharField(max_length=250, blank=True) #type:#Chưa sử dụng để làm gì hết :D type = models.IntegerField() is_del = models.IntegerField(default=0) time_check_at = models.IntegerField(default=Timer.get_timestamp_now()) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): connect_bytesave.objects.create( id_agent=kwargs['id_agent'], id_customer=kwargs['id_customer'], id_metric_service=kwargs['id_metric_service'], name=kwargs['name'], type=kwargs['type'], is_del=0, )
class backup_bytesave(models.Model): id_agent = models.IntegerField() id_connect_bytesave = models.IntegerField() name = models.CharField(max_length=250, blank=True) local_path = models.CharField(max_length=250, blank=True) container_name = models.CharField(max_length=250, blank=True) email = models.CharField(max_length=250, blank=True, null=True) #Định dạng chuỗi time: #dayofweek|hour:minute #dayofweek: 0,1,2,3,4,5,6 tương tự từ thứ 2 đến chủ nhật #hour:minute: ví dụ: 13:20,15:12 time_delete = models.IntegerField() time_delete_file_in_LastVersion = models.IntegerField(default=30) time = models.CharField(max_length=250, blank=True, null=True) # Giới hạn hệ thống xử lí luồng max max_concurrency = models.IntegerField(default=10) #0:file; 1:folder is_folder = models.IntegerField() time_last_run = models.IntegerField(null=True) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): backup_bytesave.objects.create( id_agent=kwargs['id_agent'], id_connect_bytesave=kwargs['id_connect_bytesave'], name=kwargs['name'], local_path=kwargs['local_path'], container_name=kwargs['container_name'], email=kwargs['email'], time_delete=kwargs['time_delete'], time_delete_file_in_LastVersion=kwargs[ 'time_delete_file_in_LastVersion'], time=kwargs['time'], is_folder=kwargs['is_folder'], time_last_run=0, is_del=0, )
class Customer_Represent(models.Model): id_customer = models.IntegerField() name = models.CharField(max_length=250, blank=True) phone_number = models.CharField(max_length=250, blank=True) # chức vụ người đại diện position = models.CharField(max_length=250, blank=True) email = models.CharField(max_length=250, blank=True) # 0: đầu mối liên hệ; 1: còn liên hệ; 2: dừng liên hệ type = models.IntegerField(null=True) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): Customer_Represent.objects.create( id_customer=kwargs['id_customer'], name=kwargs['name'], phone_number=kwargs['phone_number'], position=kwargs['position'], email=kwargs['email'], type=kwargs['type'], )
def Save_Customer_Represent(request, id): a = 0 if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) id_customer = form.get('id_customer', 0) if id == 0: # thêm mới try: Customer_Represent.create( **{ 'id_customer': form.get('id_customer'), 'name': form.get('represent_name'), 'phone_number': form.get('represent_phone_number'), 'position': form.get('represent_position'), 'email': form.get('represent_email'), 'type': form.get('represent_type'), }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'string_error': e }) else: # Chỉnh sửa try: item = Customer_Represent.objects.get(id=id) item.id_customer = form.get('id_customer') item.name = form.get('represent_name') item.phone_number = form.get('represent_phone_number') item.position = form.get('represent_position') item.email = form.get('represent_email') item.type = form.get('represent_type') item.time_update_at = Timer.get_timestamp_now() item.save() return JsonResponse({ 'status': 'true', 'msg': 'Chỉnh sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'string_error': e }) return None
class Customer_ByteSave(models.Model): id_customer = models.IntegerField() bytesave_email = models.CharField(max_length=250, null=True, blank=True) bytesave_pwd = models.CharField(max_length=250, null=True, blank=True) # is_logged = models.IntegerField(default=1) is_del = models.IntegerField(default=0) bytesave_use_start_date = models.CharField(max_length=250, blank=True, null=True) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now()) def create(**kwargs): Customer_ByteSave.objects.create( id_customer=kwargs['id_customer'], bytesave_email=kwargs['bytesave_email'], bytesave_pwd=kwargs['bytesave_pwd'], bytesave_use_start_date=kwargs['bytesave_use_start_date'], #bytesave_amount_used=kwargs['bytesave_amount_used'], # bytesave_duration=kwargs['bytesave_duration'], # bytesave_time_type=kwargs['bytesave_time_type'], # bytesave_expiration_date=kwargs['bytesave_expiration_date'], )
def check_ex_date(request, serial_number): if request.method == 'GET': try: item = Agents.objects.filter(~Q(is_del=1)).filter( is_logged=1).filter(serial_number=serial_number).first() item_bytesave_customer = Customer_ByteSave.objects.filter(~Q( is_del=1)).get(id_customer=item.id_customer) if float(item_bytesave_customer.bytesave_expiration_date ) > Timer.get_timestamp_now(): return JsonResponse({'status': 'true', 'msg': 'thành công!'}) else: return JsonResponse({ 'status': 'false', 'msg': 'không thành công!' }) except Exception as e: return JsonResponse({'status': 'false', 'msg': str(e)})
def Load_data(request, id): if request.method == 'GET': try: data = [] countdata = 0 countdata_represent = 0 i = 0 if id == 0: for item in Customers.objects.all().filter( (~Q(is_del=1))).order_by('-id'): data_represent = [] i = i + 1 item_customer_bytesave = Customer_ByteSave.objects.filter( id_customer=item.id)[0] status = 0 # if item_customer_bytesave.bytesave_expiration_date != '' and item_customer_bytesave.bytesave_expiration_date != None: # if float(item_customer_bytesave.bytesave_expiration_date) < Timer.get_timestamp_now(): # status = 2 # else:status = 1 item_customer_represent = Customer_Represent.objects.filter( id_customer=item.id).filter((~Q(is_del=1))) if item_customer_represent.count() > 0: stt = 0 for item_represent in item_customer_represent: data_represent.append({ 'stt': stt + 1, 'id': item_represent.id, 'id_customer': item_represent.id_customer, 'name': item_represent.name, 'phone_number': item_represent.phone_number, 'position': item_represent.position, 'email': item_represent.email, 'type': item_represent.type, 'is_del': item_represent.is_del, 'time_create_at': item_represent.time_create_at, 'time_update_at': item_represent.time_update_at, }) countdata_represent += 1 stt += 1 data.append({ 'id': item.id, 'stt': i, 'id_loggin': item.id_loggin, 'id_version': item.id_version, 'customer_bytesave': { 'id': item_customer_bytesave.id, 'bytesave_email': item_customer_bytesave.bytesave_email if item_customer_bytesave.bytesave_email != None else '', 'bytesave_pwd': item_customer_bytesave.bytesave_pwd, # 'bytesave_amount_used': item_customer_bytesave.bytesave_amount_used, # 'bytesave_duration': item_customer_bytesave.bytesave_duration, 'bytesave_use_start_date': item_customer_bytesave.bytesave_use_start_date, # 'bytesave_time_type': item_customer_bytesave.bytesave_time_type, #'bytesave_expiration_date': Convert_timestamp( item_customer_bytesave.bytesave_expiration_date), }, 'name': item.name, 'email': item.email, 'type': item.type, 'phone_number': item.phone_number, 'city': item.city, 'address': item.address, 'tax_code': item.tax_code, 'website': item.website, 'fax': item.fax, 'legal_representative': item.legal_representative, 'scale': item.scale, 'field': item.field, 'is_upgrade_version': item.is_upgrade_version, 'time_create_at': item.time_create_at, 'time_update_at': item.time_update_at, 'customer_represent': data_represent, 'countdata_represent': countdata_represent, 'status': status, }) else: item = Customers.objects.get(id=id) data_represent = [] item_customer_bytesave = Customer_ByteSave.objects.filter( id_customer=item.id)[0] status = 0 # if item_customer_bytesave.bytesave_expiration_date != '' and item_customer_bytesave.bytesave_expiration_date != None: # a =Timer.get_timestamp_now # if float(item_customer_bytesave.bytesave_expiration_date) < Timer.get_timestamp_now(): # status = 2 # else: # status = 1 item_customer_represent = Customer_Represent.objects.filter( id_customer=item.id).filter((~Q(is_del=1))) if item_customer_represent.count() > 0: stt = 0 for item_represent in item_customer_represent: data_represent.append({ 'stt': stt + 1, 'id': item_represent.id, 'id_customer': item_represent.id_customer, 'name': item_represent.name, 'phone_number': item_represent.phone_number, 'position': item_represent.position, 'email': item_represent.email, 'type': item_represent.type, 'is_del': item_represent.is_del, 'time_create_at': item_represent.time_create_at, 'time_update_at': item_represent.time_update_at, }) countdata_represent += 1 stt += 1 item_bytesave_cycle = bytesave_cycle.objects.filter( id_customer=item.id).filter((~Q(is_del=1))) data_cycle = [] countdata_cycle = 0 if item_bytesave_cycle.count() > 0: stt = 0 for item_cycle in item_bytesave_cycle: data_cycle.append({ 'stt': stt + 1, 'id': item_cycle.id, 'id_customer': item_cycle.id_customer, 'bytesave_amount_used': item_cycle.bytesave_amount_used, 'bytesave_duration': str(item_cycle.bytesave_duration) + (' tháng' if item_cycle.bytesave_time_type == 0 else ' năm'), 'bytesave_time_type': item_cycle.bytesave_time_type, 'bytesave_start_date': Convert_timestamp(item_cycle.bytesave_start_date), 'bytesave_expiration_date': Convert_timestamp( item_cycle.bytesave_expiration_date), }) countdata_cycle += 1 stt += 1 date_start = Convert_timestamp( item_customer_bytesave.bytesave_use_start_date) date_start = datetime.strptime(date_start, "%d/%m/%Y") date_start = convert_string_date_format(date_start) date_start = datetime.strptime(date_start, "%Y-%m-%d") data.append({ 'stt': i, 'id': item.id, 'id_loggin': item.id_loggin, 'id_version': item.id_version, 'customer_bytesave': { 'id': item_customer_bytesave.id, 'bytesave_email': item_customer_bytesave.bytesave_email if item_customer_bytesave.bytesave_email != None else '', 'bytesave_pwd': item_customer_bytesave.bytesave_pwd, #'bytesave_amount_used': item_customer_bytesave.bytesave_amount_used, #'bytesave_duration': item_customer_bytesave.bytesave_duration, 'bytesave_use_start_date': date_start, #'bytesave_time_type': item_customer_bytesave.bytesave_time_type, #'bytesave_expiration_date': Convert_timestamp( item_customer_bytesave.bytesave_expiration_date), }, 'name': item.name, 'email': item.email, 'type': item.type, 'phone_number': item.phone_number, 'city': item.city, 'address': item.address, 'tax_code': item.tax_code, 'website': item.website, 'fax': item.fax, 'legal_representative': item.legal_representative, 'scale': item.scale, 'field': item.field, 'is_upgrade_version': item.is_upgrade_version, 'time_create_at': item.time_create_at, 'time_update_at': item.time_update_at, 'customer_represent': data_represent, 'countdata_represent': countdata_represent, 'data_cycle': data_cycle, 'countdata_cycle': countdata_cycle, 'status': status, }) countdata = Customers.objects.all().count() return JsonResponse({ 'status': 'true', 'countdata': countdata, 'data': data }) except Exception as e: return JsonResponse({ 'status': 'false', 'countdata': 0, 'data': [], 'string_error': e }) if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) is_upgrade_version = 0 if form.get('is_upgrade_version') == 'on': is_upgrade_version = 1 id = form.get('id', 0) if id == '0': # thêm mới try: Customers.create( **{ 'id_loggin': 0, 'id_version': Versions.objects.filter(~Q(is_del=1)).first().id, 'name': form.get('name'), 'email': form.get('email'), 'type': form.get('type'), 'phone_number': form.get('phone_number'), 'city': form.get('city'), 'address': form.get('address'), 'tax_code': form.get('tax_code'), 'website': form.get('website'), 'fax': form.get('fax'), 'legal_representative': form.get('legal_representative'), 'scale': form.get('scale'), 'field': form.get('field'), 'is_upgrade_version': is_upgrade_version, }) id_customer_max = Customers.objects.all().order_by("-id")[0].id # str_time_start = form.get('date_start_used').replace('-', '/') # date = datetime.strptime(str_time_start, "%Y/%m/%d") pwd = genpwd(12) Customer_ByteSave.create( **{ 'id_customer': id_customer_max, 'bytesave_email': form.get('email'), 'bytesave_pwd': encryption(pwd), 'bytesave_use_start_date': Timer.get_timestamp_now(), # 'bytesave_amount_used': form.get('bytesave_amount_used'), # 'bytesave_duration': form.get('bytesave_duration'), # 'bytesave_time_type': form.get('bytesave_time_type'), # 'bytesave_expiration_date': form.get('bytesave_expiration_date'), }) notification_customer_bytesave('[ByteSave]', form.get('email'), pwd, form.get('email')) if int(form.get('CountRowNDD')) > 0: for i in range(1, int(form.get('CountRowNDD')) + 1): Customer_Represent.create( **{ 'id_customer': id_customer_max, 'name': form.get('represent_name' + str(i)), 'phone_number': form.get('represent_phone_number' + str(i)), 'position': form.get('represent_position' + str(i)), 'email': form.get('represent_email' + str(i)), 'type': form.get('represent_type' + str(i)), }) if int(form.get('CountRowService')) > 0: for i in range(1, int(form.get('CountRowService')) + 1): id_metric = Metric_Services.create( **{ 'id_customer': id_customer_max, 'id_service': form.get('id_service' + str(i)), 'information_connect': form.get('information_connect' + str(i)), 'max_storage': form.get('max_storage' + str(i)), 'username_account': form.get('username_account' + str(i)), 'type': form.get('represent_type' + str(i)), }) connect_bytesave.create( **{ 'name': 'Connection ' + form.get('max_storage' + str(i)), 'id_customer': id_customer_max, 'id_agent': 0, 'id_metric_service': id_metric, 'type': 0, }) if int(form.get('CountRowChuki')) > 0: for i in range(1, int(form.get('CountRowChuki')) + 1): # date_end = add_months(date, int(form.get('bytesave_duration' + str(i))) if form.get( # 'bytesave_time_type' + str(i)) == '0' else (int(form.get('bytesave_duration' + str(i))) * 12)) date_start = datetime.strptime( (form.get('date_start_used' + str(i))).replace( '-', '/'), '%d/%m/%Y') date_end = datetime.strptime( (form.get('date_end_used' + str(i))).replace( '-', '/'), '%d/%m/%Y') bytesave_cycle.create( **{ 'id_customer': id_customer_max, 'bytesave_amount_used': form.get('bytesave_amount_used' + str(i)), 'bytesave_duration': form.get('bytesave_duration' + str(i)), 'bytesave_time_type': form.get('bytesave_time_type' + str(i)), 'bytesave_start_date': date_start.timestamp(), 'bytesave_expiration_date': date_end.timestamp(), }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!', 'id': id_customer_max }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'string_error': e }) else: try: item = Customers.objects.get(id=id) item.name = form.get('name') item.email = form.get('email') item.scale = form.get('scale') item.field = form.get('field') item.city = form.get('city') item.time_update_at = Timer.get_timestamp_now() item.is_upgrade_version = is_upgrade_version item.type = form.get('type') item.phone_number = form.get('phone_number') item.address = form.get('address') item.tax_code = form.get('tax_code') item.website = form.get('website') item.fax = form.get('fax') item.legal_representative = form.get('legal_representative') item.save() item_bytesave = Customer_ByteSave.objects.get(id_customer=id) item_bytesave.bytesave_email = form.get('email') item_bytesave.save() return JsonResponse({ 'status': 'true', 'msg': 'Chỉnh sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'string_error': e }) return None
def Load_data(request, id): if request.method == 'GET': try: data = [] countdata = 0 if id == 0: for item in Metric_Services.objects.filter(type=1).filter( (~Q(is_del=1))): countdata = 1 data.append({ 'id': item.id, 'id_customer': item.id_customer, 'name_customer': Customers.objects.get(id=item.id_customer).name, 'id_service': item.id_service, 'name_service': Service.objects.get(id=item.id_service).name, 'information_connect': item.information_connect, 'max_storage': item.max_storage, 'username_account': item.username_account, 'status': item.status, 'time_create_at': item.time_create_at, 'time_update_at': item.time_update_at, }) countdata += 1 else: # id != 0: là lấy ra các metric_service của khách hàng có id đó for item in Metric_Services.objects.filter( id_customer=id).filter(~Q(is_del=1)).filter(type=1): countdata = 1 data.append({ 'id': item.id, 'id_customer': item.id_customer, 'name_customer': Customers.objects.get(id=item.id_customer).name, 'id_service': item.id_service, 'name_service': Service.objects.get(id=item.id_service).name, 'information_connect': item.information_connect, 'max_storage': item.max_storage, 'username_account': item.username_account, 'status': item.status, 'time_create_at': item.time_create_at, 'time_update_at': item.time_update_at, }) countdata += 1 return JsonResponse({ 'status': 'true', 'countdata': countdata, 'data': data }) except Exception as e: return JsonResponse({ 'status': 'false', 'countdata': 0, 'data': [], 'string_error': e }) if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) is_upgrade_version = 0 id_metric_service = form.get('id_ser', 0) if id_metric_service == '0' or id_metric_service == '': # thêm mới try: id_metric = Metric_Services.create( **{ 'id_customer': id, 'id_service': form.get('id_service_s'), 'information_connect': form.get('information_connect'), 'max_storage': form.get('max_storage'), 'username_account': form.get('username_account'), 'type': 1, }) connect_bytesave.create( **{ 'name': 'Connection ' + form.get('max_storage'), 'id_customer': id, 'id_agent': 0, 'id_metric_service': id_metric, 'type': 0, }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'string_error': e }) else: # Chỉnh sửa try: item = Metric_Services.objects.get(id=id_metric_service) item.id_customer = id item.id_service = form.get('id_service_s') item.information_connect = form.get('information_connect') item.max_storage = form.get('max_storage') item.username_account = form.get('username_account') item.time_update_at = Timer.get_timestamp_now() item.save() return JsonResponse({ 'status': 'true', 'msg': 'Chính sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'string_error': e }) return None
def load_data_setting_bytesave(request, id, serial_number, email_loggin): if request.method == 'GET': try: data = [] item_customer = Customer_ByteSave.objects.get( bytesave_email=email_loggin) countdata = 0 for item in setting_bytesave.objects.filter( id_agent=Agents.objects.filter(~Q(is_del=1)).filter( serial_number=serial_number).get( id_customer=item_customer.id_customer).id).filter( ~Q(is_del=1)): countdata = 1 data.append({ 'id': item.id, 'id_agent': item.id_agent, 'server_mail': item.server_mail, 'port': item.port, 'mail_send': item.mail_send, 'mail_send_pwd': item.mail_send_pwd, 'subject': item.subject, 'is_ssl': item.is_ssl, 'time_create_at': item.time_create_at, 'time_update_at': item.time_update_at, }) countdata += 1 return JsonResponse({ 'status': 'true', 'countdata': countdata, 'data': data }) except Exception as e: return JsonResponse({ 'status': 'false', 'countdata': 0, 'data': [], 'error': str(e) }) return JsonResponse({ 'status': 'false', 'countdata': countdata, 'data': data }) if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) if id == 0: # thêm mới try: item_customer = Customer_ByteSave.objects.get( bytesave_email=email_loggin) id_agent = Agents.objects.filter(~Q(is_del=1)).filter( serial_number=serial_number).get( id_customer=item_customer.id_customer).id setting_bytesave.create( **{ 'id_agent': id_agent, 'server_mail': form.get('server_mail'), 'port': form.get('port'), 'mail_send': form.get('mail_send'), 'mail_send_pwd': form.get('mail_send_pwd'), 'subject': form.get('subject'), }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'error': str(e) }) else: # chỉnh sửa try: item = setting_bytesave.objects.filter( (~Q(is_del=1))).get(id=id) item.id_agent = form.get('id_agent') item.server_mail = form.get('server_mail') item.port = form.get('port') item.mail_send = form.get('mail_send') item.mail_send_pwd = form.get('mail_send_pwd') item.subject = form.get('subject') item.time_update_at = Timer.get_timestamp_now() item.save() return JsonResponse({ 'status': 'true', 'msg': 'Chỉnh sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'error': str(e) }) return None
def load_data(request): if request.method == 'GET': try: data = [] countdata = 0 for item in Loggin.objects.all().filter((~Q(is_del=1))): countdata = 1 data.append({ 'id': item.id, 'name': item.name, 'email': item.email, 'type': item.type, }) countdata += 1 return JsonResponse({ 'status': 'true', 'countdata': countdata, 'data': data }) except Exception as e: return JsonResponse({ 'status': 'false', 'countdata': 0, 'data': [], 'string_error': e }) if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) id = form.get('id', 0) if id == '0' or id == '': # thêm mới try: Loggin.create( **{ 'email': form.get('email'), 'name': form.get('name'), 'pwd': encryption(form.get('pwd')), 'type': form.get('type'), }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'string_error': e }) else: # Chỉnh sửa try: item = Loggin.objects.get(id=int(id)) item.email = form.get('email') item.name = form.get('name') item.pwd = encryption(form.get('pwd')) item.type = form.get('type') item.time_update_at = Timer.get_timestamp_now() item.save() return JsonResponse({ 'status': 'true', 'msg': 'Chính sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'string_error': e }) return None
def loggin_bytesave(request): if request.method == 'POST': try: data = json.dumps(request.POST) form = json.loads(data) email = form.get('email') pwd = encryption(form.get('pwd')) serial_number = form.get('serial_number') item = Customer_ByteSave.objects.filter( bytesave_email=email).filter(~Q(is_del=1)) if item.count() == 0: return JsonResponse({ 'status': 'false', 'msg': 'Email nhập không chính xác!' }) item = Customer_ByteSave.objects.filter( bytesave_email=email).filter( bytesave_pwd=pwd).filter(~Q(is_del=1)) if item.count() == 0: return JsonResponse({ 'status': 'false', 'msg': 'Mật khẩu nhập không chính xác!' }) #item = Agents.objects.filter(serial_number=serial_number).filter(~Q(is_del=1)) #if item.count() > 0: # item = Agents.objects.filter(~Q(is_del=1)).get(serial_number=serial_number) # item.is_logged = 1 # item.save() # return JsonResponse({'status': 'true', 'msg': 'Đăng nhập thành công!'}) item = Customer_ByteSave.objects.filter(~Q(is_del=1)).get( bytesave_email=email) #Kiểm tra chu kì: #get list chu kì có time hết hạn > time.now(): nếu count() = 0 thì return tài khaorn đã hết hạn item_cycles = bytesave_cycle.objects.filter(~Q(is_del=1)).filter( id_customer=item.id_customer).filter( bytesave_expiration_date__gte=Timer.get_timestamp_now()) if item_cycles.count() == 0: return JsonResponse({ 'status': 'false', 'msg': 'Tài khoản đã hết hạn sử dụng!', 'email_loggin': email }) #Tìm tổng số máy được sử dụng number_used = 0 for item_cycle in item_cycles: if item_cycle.bytesave_start_date > Timer.get_timestamp_now(): continue if item_cycle.bytesave_start_date <= Timer.get_timestamp_now(): number_used += item_cycle.bytesave_amount_used # nếu số mày =0 là tài khoản chưa đến ngày bắt đầu sử dụng if number_used == 0: return JsonResponse({ 'status': 'false', 'msg': 'Tài khoản chưa được kích hoạt!', 'email_loggin': email }) items_agents_logged = Agents.objects.filter( id_customer=item.id_customer).filter( is_logged=1).filter(~Q(is_del=1)) if number_used <= items_agents_logged.count(): return JsonResponse({ 'status': 'false', 'msg': 'Tài khoản đã hết phiên đăng nhập!', 'email_loggin': email }) items_agents = Agents.objects.filter( id_customer=item.id_customer).filter( serial_number=serial_number).filter(~Q(is_del=1)) # Kiểm tra đã có agent đăng nhập nào chưa.nếu chưa thì đi thêm mới agnet : if items_agents.count() == 0: os = form.get('os') ip_public = form.get('ip_public') ip_private = form.get('ip_private') name_computer = form.get('name_computer') create_agent_when_loggin(item.id, item.id_customer, os, serial_number, ip_public, ip_private, name_computer) return JsonResponse({ 'status': 'true', 'msg': 'Đăng nhập thành công!', 'email_loggin': email }) #item_cycles = bytesave_cycle.objects.filter(~Q(is_del=1)).filter(bytesave_amount_used) < float(Timer.get_timestamp_now())) check_serial_number_in_agents = Agents.objects.filter( serial_number=serial_number).filter( id_customer=item.id_customer).filter(~Q(is_del=1)).filter( is_logged=0).first() if check_serial_number_in_agents != None: # item_serial_number = Agents.objects.filter(~Q(is_del=1)).filter(is_logged=0).get(serial_number=serial_number) check_serial_number_in_agents.is_logged = 1 check_serial_number_in_agents.save() return JsonResponse({ 'status': 'true', 'msg': 'Đăng nhập thành công!', 'email_loggin': email }) # if items_agent.count() > item.bytesave_amount_used: # return JsonResponse({'status': 'false', 'msg': 'Tài khoản đã được sử dụng hết phiên đăng nhập!'}) # if item.bytesave_expiration_date != None: # if float(item.bytesave_expiration_date) < Timer.get_timestamp_now(): # return JsonResponse({'status': 'false', 'msg': 'Tài khoản đã hết hạn sử dụng!'}) # today = datetime.today() # if items_agent.count() ==0: # if item.bytesave_time_type == 0: # item.bytesave_expiration_date = str(datetime(today.year , today.month + item.bytesave_duration, 1).timestamp()) # else: # item.bytesave_expiration_date = str(datetime(today.year + item.bytesave_duration , today.month , 1).timestamp()) # item.bytesave_use_start_date = today.timestamp() # item.save() # os = form.get('os') # ip_public = form.get('ip_public') # ip_private = form.get('ip_private') # name_computer = form.get('name_computer') # create_agent_when_loggin(item.id,item.id_customer,os,serial_number,ip_public,ip_private,name_computer) return JsonResponse({ 'status': 'true', 'msg': 'Đăng nhập thành công!', 'email_loggin': email }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Đăng nhập không thành công!' })
class Service(models.Model): name = models.CharField(max_length=100, blank=True) description = models.CharField(max_length=250, blank=True) is_del = models.IntegerField(default=0) time_create_at = models.IntegerField(default=Timer.get_timestamp_now()) time_update_at = models.IntegerField(default=Timer.get_timestamp_now())
def load_data_bytesave_backup(request, serial_number, email): if request.method == 'GET': try: data = [] countdata = 0 item_customer = Customer_ByteSave.objects.filter( (~Q(is_del=1))).get(bytesave_email=email) item_agent = Agents.objects.filter( (~Q(is_del=1))).filter(serial_number=serial_number).get( id_customer=item_customer.id_customer) for item in backup_bytesave.objects.filter( id_agent=item_agent.id).filter(~Q(is_del=1)): countdata = 1 data.append({ 'id': item.id, 'id_agent': item.id_agent, 'id_connect_bytesave': item.id_connect_bytesave, 'connect_bytesave_name': connect_bytesave.objects.filter(~Q(is_del=1)).get( id=item.id_connect_bytesave).name, 'connect_bytesave_username_account': Metric_Services.objects.filter(~Q(is_del=1)).get( id=connect_bytesave.objects.filter(~Q(is_del=1)).get( id=item.id_connect_bytesave).id_metric_service). username_account, 'name': item.name, 'local_path': item.local_path, 'container_name': item.container_name, 'time': item.time, 'time_delete': item.time_delete, 'time_delete_file_in_LastVersion': item.time_delete_file_in_LastVersion, 'email': item.email, 'is_folder': item.is_folder, 'time_create_at': item.time_create_at, 'time_update_at': item.time_update_at, }) countdata += 1 return JsonResponse({ 'status': 'true', 'countdata': countdata, 'data': data }) except Exception as e: return JsonResponse({ 'status': 'false', 'countdata': 0, 'data': [], 'error': str(e) }) return JsonResponse({ 'status': 'true', 'countdata': countdata, 'data': data }) if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) item_customer = Customer_ByteSave.objects.filter( (~Q(is_del=1))).get(bytesave_email=email) if form.get('id') == '0': # thêm mới try: backup_bytesave.create( **{ 'id_agent': Agents.objects.filter(~Q(is_del=1)).filter( is_logged=1).get( id_customer=item_customer.id_customer).id, 'id_connect_bytesave': form.get('id_connect_bytesave'), 'name': form.get('name'), 'local_path': form.get('local_path').replace('-', '\\'), 'container_name': form.get('container_name'), 'email': form.get('email') if form.get('email') != '0' else '', 'time_delete': form.get('time_delete'), 'time_delete_file_in_LastVersion': form.get('time_delete_file_in_LastVersion'), 'time': form.get('time'), 'is_folder': form.get('is_folder'), }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'error': str(e) }) else: # chỉnh sửa try: item = backup_bytesave.objects.filter( (~Q(is_del=1))).get(id=int(form.get('id'))) item.id_connect_bytesave = form.get('id_connect_bytesave') item.name = form.get('name') item.local_path = str( form.get('local_path').replace('-', '\\')) item.container_name = form.get('container_name') item.email = form.get('email') item.time_delete = form.get('time_delete') item.time_delete_file_in_LastVersion = form.get( 'time_delete_file_in_LastVersion') item.time = form.get('time') item.is_folder = form.get('is_folder') item.time_update_at = Timer.get_timestamp_now() item.save() return JsonResponse({ 'status': 'true', 'msg': 'Chỉnh sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'error': str(e) }) return None
def load_data_verrsion(request): if request.method == 'GET': try: data = [] countdata = 0 for item in Versions.objects.all().filter((~Q(is_del=1))): countdata = 1 data.append({ 'id': item.id, 'name': item.name, 'description': item.description, 'time_create_at': item.time_create_at, 'time_update_at': item.time_update_at, }) countdata += 1 return JsonResponse({ 'status': 'true', 'countdata': countdata, 'data': data }) except Exception as e: return JsonResponse({ 'status': 'false', 'countdata': 0, 'data': [], 'string_error': e }) if request.method == 'POST': data = json.dumps(request.POST) form = json.loads(data) id_version = form.get('id_version', 0) if id_version == '0' or id_version == '': # thêm mới try: Versions.create( **{ 'name': form.get('name'), 'description': form.get('description'), }) return JsonResponse({ 'status': 'true', 'msg': 'Thêm mới thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Thêm mới không thành công!', 'string_error': e }) else: # Chỉnh sửa try: item = Versions.objects.get(id=id_version) item.name = form.get('name') item.description = form.get('description') item.time_update_at = Timer.get_timestamp_now() item.save() return JsonResponse({ 'status': 'true', 'msg': 'Chính sửa thành công!' }) except Exception as e: return JsonResponse({ 'status': 'false', 'msg': 'Chỉnh sửa không thành công!', 'string_error': e }) return None