def __init__(self, download_dir='/tmp/download/'): super(DouyinDownloader, self).__init__() # self.arg = arg self.downloadCount = 0 self.uploadCount = 0 if download_dir.endswith('/'): self.downloadDir = download_dir else: self.downloadDir = download_dir + '/' # redis connect self.redisClient = redis.StrictRedis(host='115.159.157.98', port=17379, db=0, password='******') # mysql self.mysqlDB = Database(host='localhost', user='******', passwd='zx#Video2018', database='video') # nextcloud self.oc = owncloud.Client('http://127.0.0.1:18080') self.oc.login('zhangxu', 'zx@12346') self.oc.logout() self.oc2 = owncloud.Client('http://115.29.34.236:18181') self.oc2.login('zhangxu', 'zx@12346') self.oc2.logout()
def post(self): client_url = self.request.get('client_url') username = self.request.get('username') password = self.request.get('password') paths = self.request.get('paths') # list of [remote_path, category, filename] paths = json.loads(paths)['root'] # Connecting to the NextCloud Server c = owncloud.Client(client_url) c.login(username, password) # Save each item in the list of files into the local directory in the same structure for remote_path, category, filename in paths: if category in categories: local_path = os.path.join(data_root_dir, category, os.path.basename(filename)) local_dir = os.path.dirname(local_path) if not os.path.exists(local_dir): os.makedirs(local_dir) c.get_file(remote_path, local_path) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'status': 'OK'}))
def changing_nexcloud_user_password(sender, **kwargs): # Change user password on the nextcloud server _user = kwargs['user'] _pass = kwargs['password'] _admin = NEXTCLOUD_ADMIN _admin_key = NEXTCLOUD_PASSWORD _url = ('http', 'https')[NEXTCLOUD_USE_HTTPS is True] + '://' + NEXTCLOUD_HOST nc = NextCloudCLI.Client(_url, verify_certs=NEXTCLOUD_SSL_IS_SIGNED) _err = ['login', 'set_user_attribute password'] try: nc.login(_admin, _admin_key) _err.pop(0) nc.set_user_attribute(_user.username, 'password', _pass) nc.logout() except NextCloudCLI.HTTPResponseError as e: logger.debug('changing_nexcloud_user_password: %s HTTP Error %d' % (_err[0], e.status_code)) except requests.exceptions.ConnectionError as e: logger.debug( 'changing_nexcloud_user_password: %s Connection Error: %s' % (_err[0], e)) except NextCloudCLI.OCSResponseError as e: logger.debug( 'changing_nexcloud_user_password: %s OCSResponse Error %d' % (_err[0], e.status_code)) else: logger.debug('Changing user %s password success' % _user.username)
def setUp(self): self.temp_dir = tempfile.gettempdir() + '/pyocclient_test%s-%s/' % ( int(time.time()), random.randint(1, 1000)) os.mkdir(self.temp_dir) self.client = owncloud.Client( Config['owncloud_url'], dav_endpoint_version=self.get_dav_endpoint_version()) self.client.login(Config['owncloud_login'], Config['owncloud_password']) self.test_root = Config['test_root'] if not self.test_root[-1] == '/': self.test_root += '/' if not self.test_root[0] == '/': self.test_root = '/' + self.test_root self.client.mkdir(self.test_root) self.share2user = Config['owncloud_share2user'] self.share2userPwd = 'Avcpwd4l!' self.test_group = Config['test_group'] try: self.client.create_user(self.share2user, self.share2userPwd) except: pass try: self.client.create_group(self.test_group) except: pass
def load_dataset(request, pk): """ This needs to be fixed to run asynchronously, incase of a very large dataset, actually... would that even matter? Maybe there's a better wy to do this whole secret crypto key thing, I still don't feel like it's secure enough """ CRYPTO_KEY = os.environ.get("CRYPTO_KEY") cipher_end = Fernet(CRYPTO_KEY) # bring in the dataset by pk dataset = Dataset.objects.get(pk=pk) # this would probably go better with a little loop or something bytes_user = dataset.dataset_user.encode("utf-8") bytes_password = dataset.dataset_password.encode("utf-8") decrypted_user = cipher_end.decrypt(bytes_user).decode("utf-8") decrypted_password = cipher_end.decrypt(bytes_password).decode("utf-8") # use owncloud stuff, if the owncloud thing is true if dataset.owncloud: # owncloud, instead of requests. oc = owncloud.Client(dataset.owncloud_instance) oc.login(decrypted_user, decrypted_password) data = oc.get_file_contents(dataset.owncloud_path) else: data = requests.get(dataset.url, auth=(decrypted_user, decrypted_password)).content return HttpResponse(data)
def _process(self, parameters): import owncloud param = parameters['input'][0] name_dir = "enes_usecase" if isinstance(param, str): src_path = parameters['input'][0] upload_path = name_dir + "/" + parameters['input'][1] else: param_keys = parameters['input'][0].keys() src_path = param[param_keys[-2]]['out_file'] upload_path = remove_absolute_path(src_path, '/') upload_path = name_dir + "/" + upload_path oc = owncloud.Client('https://b2drop.eudat.eu') oc.login(self.username, self.password) oc.put_file(upload_path, src_path) link_info = oc.share_file_with_link(upload_path) #update_monitoring_file(self.name, special_info=link_info) print("Shared linked is: " + link_info.get_link())
def deactivating_nexcloud_user(sender, **kwargs): # Remove member on the nextcloud server _user = kwargs['user'] _admin = NEXTCLOUD_ADMIN _admin_key = NEXTCLOUD_PASSWORD _url = ('http', 'https')[NEXTCLOUD_USE_HTTPS is True] + '://' + NEXTCLOUD_HOST nc = NextCloudCLI.Client(_url, verify_certs=NEXTCLOUD_SSL_IS_SIGNED) _err = ['login', 'deactivate_user'] try: nc.login(_admin, _admin_key) _err.pop(0) nc.make_ocs_request('PUT', 'cloud/users', _user.username + '/disable') nc.logout() except NextCloudCLI.HTTPResponseError as e: logger.debug('removing_nexcloug_user: %s HTTP Error %d' % (_err[0], e.status_code)) except requests.exceptions.ConnectionError as e: logger.debug('removing_nexcloug_user: %s Connection Error: %s' % (_err[0], e)) except NextCloudCLI.OCSResponseError as e: logger.debug('removing_nexcloug_user: %s OCSResponse Error %d' % (_err[0], e.status_code)) else: logger.debug('Removing user %s success' % _user.username)
def back_up(context: CallbackContext) -> None: """ Flushes the data to pickle file and uploads them to the OwnCloud/NextCloud instance as specified in the config file. Args: context: The context as provided by the :class:`telegram.ext.Dispatcher`. """ context.dispatcher.update_persistence() context.dispatcher.persistence.flush() client = owncloud.Client(URL) client.login(USERNAME, PASSWORD) try: client.mkdir(PATH) except owncloud.HTTPResponseError: pass base = 'akanamen_db_{}_data' for extension in ['bot', 'chat', 'user']: file_name = base.format(extension) client.put_file(f'{PATH}/{dtm.datetime.now().isoformat()}_{file_name}', file_name) client.logout()
def setUp(self): self.temp_dir = tempfile.gettempdir() + '/pyocclient_test%s/' % int( time.time()) os.mkdir(self.temp_dir) self.client = owncloud.Client(Config['owncloud_url'], single_session=Config['single_session']) self.client.login(Config['owncloud_login'], Config['owncloud_password']) self.test_root = Config['test_root'] if not self.test_root[-1] == '/': self.test_root += '/' if not self.test_root[0] == '/': self.test_root = '/' + self.test_root self.client.mkdir(self.test_root) self.share2user = Config['owncloud_share2user'] self.test_group = Config['test_group'] try: self.client.create_user(self.share2user, 'share') except: pass try: self.client.create_group(self.test_group) except: pass
def errpage(request, mvolfolder_name): breadcrumbs = breadcrumbsbase + [{ "href": "/workflowautomator/mvolreport", "text": "Mvol Report" }, { "href": "/workflowautomator/mvolreport/invalid", "text": "invalid" }] oc = owncloud.Client(OWNCLOUD_WEB_SERVICE) oc.login(OWNCLOUD_USERNAME, OWNCLOUD_PASSWORD) newdirectorytitle = 'IIIF_Files/' + '/'.join(mvolfolder_name.split("-")) errors = [] for entry in oc.list(oc.file_info(newdirectorytitle).get_path()): if entry.get_name() == 'invalid': errorsfile = oc.get_file(entry, 'workflowautomator/data/invalid') print(errorsfile) f = open("workflowautomator/data/invalid") for line in f: errors = errors + [line] f.close() break context = { 'name': mvolfolder_name, 'errarray': errors, "breadcrumbs": breadcrumbs } return render(request, 'workflowautomator/errpage.html', context)
def main(): print("[INFO]\tReading config.json file.") config = "" with open('config.json', 'r') as json_data: config = json.load(json_data) check_config(config) # TODO: checksums print("[INFO]\tGetting all subpaths.") files_paths = getAllSubpaths(config['files']) print("[INFO]\tCreating temporary directory tree.") tmp_dir_path = createTmpTree(files_paths) print("[INFO]\tCreating achive.") archive_path = makeArchive(tmp_dir_path) print("[INFO]\tSending to server.") oc = owncloud.Client("%s://%s:%s" % (config["protocol"], config["host"], config["port"]), verify_certs=getVerifyCerts(config['verifyCerts'])) oc.login(config["login"], config["passwd"]) oc.put_file(os.path.join(config["remoteDir"], archive_path.split("/")[-1]), archive_path) oc.logout() print("[INFO]\tDone.")
def _login(fname, user, password_path) -> None: sleep_duration = 15 config.oc = owncloud.Client("https://b2drop.eudat.eu/") with open(password_path, "r") as content_file: password = content_file.read().strip() for _ in range(config.RECONNECT_ATTEMPTS): try: status_str = f"Trying to login into owncloud user={user} ..." with cfg.console.status(status_str): # may take few minutes to connect config.oc.login(user, password) password = "" f = open(fname, "wb") pickle.dump(config.oc, f) f.close() log(f" {status_str} {ok()}") return except Exception as e: log(str(e)) if "Errno 110" in str(e) or "Connection timed out" in str(e): log(f"warning: sleeping for {sleep_duration} seconds to overcome the max retries that exceeded") sleep_timer(sleep_duration) else: terminate("Could not connect into [blue]eudat using config.oc.login()[/blue]") logging.error("E: user is None object") terminate()
def __init__(self, username: str, password: str, watch_folder: str, destination_folder: str, host: str, debug: bool = False, scanning_interval: int = 1, template: str = "{artist}/{album}/{title}.mp3"): super().__init__(watch_folder=watch_folder, target_folder=destination_folder, debug=debug, recursive=True, thread_name="Main thread of owncloud watcher", scanning_interval=scanning_interval, template=template) self._username = username self._host = host self._oc = owncloud.Client(host) _wait = 5 while True: try: self._oc.login(user_id=username, password=password) break except owncloud.owncloud.HTTPResponseError as e: logging.error( f"Got Connection Error while connection to owncloud. Waiting {_wait}min for retry. " f"HTTP-Error: {e.status_code}") time.sleep(_wait * 60) logging.info( f"Connected to owncloud {host}. Host runs version {self._oc.get_version()}" )
def main(argv): args = setup_cmdline_parser() assert args.root is not None assert args.config_file is not None if not os.path.exists(args.config_file): print('Config file {} not found!'.format(args.config_file)) sys.exit(-1) with open(args.config_file) as json_file: data = json.load(json_file) url = data['url'] login = data['user'] app_key = data['app_key'] oc = owncloud.Client(url) oc.login(login, app_key) if not os.path.exists(args.student_file): print('Student file {} not found!'.format(args.student_file)) sys.exit(-1) if args.exam: students = read_students_exam(args.student_file) else: students = read_students(args.student_file) use_group, group_ids = check_group(students) group_dirs = None if use_group: group_dirs = {g: { 'path': os.path.join(args.root, 'group_{:02d}'.format(g)), 'created': False, 'link': None } for g in group_ids} for k,v in students.items(): if use_group: group_id = v['group'] if not group_dirs[group_id]['created']: _create_dir(oc, group_dirs[group_id]['path']) link = _share(oc, group_dirs[group_id]['path']) group_dirs[group_id]['created']=True group_dirs[group_id]['link']=link v['link'] = link else: v['link'] = group_dirs[group_id]['link'] v['path'] = group_dirs[group_id]['path'] else: student_dir = os.path.join(args.root, '{}'.format(str(k))) _create_dir(oc, student_dir) link = _share(oc, student_dir) v['link'] = link v['path'] = student_dir if args.out_file is not None: pickle.dump( students, open( args.out_file, "wb" ) )
def connect(): global session if not os.path.isfile(configfile): print( bcolors.YELLOW + "--- Initial Client Setup ---\n\nNOTE: Please enter full URI for server name.\nExample: https://myserver.com/nextcloud\nFor security reasons, please do not use your plaintext password for this utility. You should generate an App password from your NextCloud settings page.\n" + bcolors.DEFAULT) servername_input = input('Server URI: ') username_input = input('Username: '******'w') Config.add_section('Config') Config.set('Config', 'servername', servername_input) Config.set('Config', 'username', username_input) Config.set('Config', 'password_base64', password_encoded.decode("utf-8")) Config.write(cfgfile) cfgfile.close() cfguser = ConfigSectionMap("Config")['username'] cfgpass_encoded = ConfigSectionMap("Config")['password_base64'] servername = ConfigSectionMap("Config")['servername'] cfgpass = base64.b64decode(cfgpass_encoded) session = nclib.Client(servername) session.login(cfguser, cfgpass)
def login_b2drop(): import owncloud username = PARAM_B2DROP['username'] password = PARAM_B2DROP['password'] oc = owncloud.Client('https://b2drop.eudat.eu') oc.login(username, password) return oc
def archive(self, files): url = os.environ['CRONOHUB_OWNCLOUD_URL'] user = os.environ['CRONOHUB_OWNCLOUD_USERNAME'] password = os.environ['CRONOHUB_OWNCLOUD_PASSWORD'] self.ownClient = owncloud.Client(url) self.ownClient.login(user, password) with Pool(5) as p: p.map(self.upload, files)
def unrec_video(): login = '******' password = '******' url_nextcloud = 'https://cloud.aymeric-mai.fr/' datetime.datetime.now().timestamp() timestamp = datetime.datetime.now() annee = timestamp.strftime('%Y') semaine = timestamp.strftime('%V le %m.%y') con = sqlite3.connect("/srv/aeve-rec-session/back/bdd/rec_bdd.db") cur = con.cursor() f = open('/srv/aeve-rec-session/back/temp_var/out.ser', "rb") unpickler = pickle.Unpickler(f) pid = unpickler.load() file_source = unpickler.load() file_name = unpickler.load() f.close() try: os.killpg(pid, signal.SIGTERM) except ProcessLookupError: pass # Use owncloud library for create dir of file mp4 oc = owncloud.Client(url_nextcloud) oc.login(login, password) path_dest = '/Simon/Vidéos-Simon/' + annee + '/Semaine-' + semaine + '' url_path_nextcloud_temp = url_nextcloud + 'remote.php/dav/files/' + login + '' + path_dest + '/' + file_name + '' url_path_nextcloud = url_path_nextcloud_temp.replace(' ', '%20') try: oc.mkdir('Simon/Vidéos-Simon/' + annee + '') except: pass try: oc.mkdir('Simon/Vidéos-Simon/' + annee + '/Semaine-' + semaine + '') except: pass cmdbase = 'curl -u ' + login + ':' + password + ' -T "' + file_source + '" ' + url_path_nextcloud print(cmdbase) subprocess.Popen(cmdbase, shell=True) # Pour une utilisation de la library python # oc.drop_file('/home/aymeric/Codage/AEVE-REC-API/app/test.txt') cur.execute("UPDATE rec SET status = 0") con.commit() con.close() # Supprimer le fichier vidéo temporaire #if os.path.exists(file_source): # os.remove(file_source) return file_source
def adding_nexcloud_user(sender, **kwargs): # Add new member on the nextcloud server _user = kwargs['user'] _pass = NEXTCLOUD_USER_DEFAULT_PASSWORD or randomStringDigits() _admin = NEXTCLOUD_ADMIN _admin_key = NEXTCLOUD_PASSWORD _url = '%s://%s' % ( ('http', 'https')[NEXTCLOUD_USE_HTTPS is True], NEXTCLOUD_HOST) nc = NextCloudCLI.Client(_url, verify_certs=NEXTCLOUD_SSL_IS_SIGNED) _err = [ 'login', 'create_user', 'enable_user', 'add_user_to_group', 'set_user_attribute quota' ] try: nc.login(_admin, _admin_key) _err.pop(0) try: if NEXTCLOUD_USER_SEND_EMAIL_PASSWORD is True: nc.make_ocs_request('POST', nc.OCS_SERVICE_CLOUD, 'users', data={ 'email': _user.email, 'userid': _user.username }) else: nc.create_user(_user.username, _pass) _err.pop(0) except NextCloudCLI.OCSResponseError as e: if e.status_code == 102: _err.pop(0) nc.make_ocs_request('PUT', 'cloud/users', _user.username + '/enable') else: raise e _err.pop(0) if NEXTCLOUD_USER_GROUP is not None: nc.add_user_to_group(_user.username, NEXTCLOUD_USER_GROUP) _err.pop(0) if NEXTCLOUD_USER_QUOTA is not None: nc.set_user_attribute(_user.username, 'quota', NEXTCLOUD_USER_QUOTA) nc.logout() except NextCloudCLI.HTTPResponseError as e: logger.debug('adding_nexcloug_user: %s HTTP Error %d' % (_err[0], e.status_code)) except requests.exceptions.ConnectionError as e: logger.debug('adding_nexcloug_user: %s Connection Error: %s' % (_err[0], e)) except NextCloudCLI.OCSResponseError as e: logger.debug('adding_nexcloug_user: %s OCSResponse Error %d' % (_err[0], e.status_code)) else: logger.debug('Adding user %s success' % _user.username)
def plant(directory, mode): oc = owncloud.Client(OWNCLOUD_WEB_SERVICE) oc.login(OWNCLOUD_USERNAME, OWNCLOUD_PASSWORD) for p in get_mvol_mmdd_directories(oc, ("/IIIF_Files/" + directory).replace( '-', '/')): print(p) runutil(oc, oc.file_info(p), mode)
def __init__(self, camunda_url): self.camunda_url = camunda_url self.engine = self.camunda_url+"/engine-rest" self.result_set = [] self.test_status = True try: self.oc_client = owncloud.Client("http://owncloud:8080") self.oc_client.login("demo","demo") except Exception as e: logger.error(f"Error when creating cloud instance: {e}")
def main(): load_dotenv() oc = owncloud.Client(os.getenv("NC_URL")) oc.login(os.getenv("NC_USERNAME"), os.getenv("NC_PASSWORD")) for arg in sys.argv[1:]: oc.put_file(f"{os.getenv('NC_UPLOAD_DIRECTORY')}/{ntpath.basename(arg)}", arg) link = oc.share_file_with_link( f"{os.getenv('NC_UPLOAD_DIRECTORY')}/{ntpath.basename(arg)}" ) print(f"{link.get_link()}/preview")
def setUp(self): self.temp_dir = tempfile.gettempdir() + '/pyocclient_test%s/' % int(time.time()) os.mkdir(self.temp_dir) self.client = owncloud.Client(Config['owncloud_url']) self.client.login(Config['owncloud_login'], Config['owncloud_password']) self.test_root = Config['test_root'] if not self.test_root[-1] == '/': self.test_root += '/' if not self.test_root[0] == '/': self.test_root = '/' + self.test_root self.client.mkdir(self.test_root)
def File(file): oc = owncloud.Client('https://cloud.atriox.io') oc.login('sublime', 'BlueeYes2122!') fileName = os.path.basename(file) uploadDir = "123" try: oc.put_file(uploadDir + "/" + fileName, file) link_info = oc.share_file_with_link(uploadDir + "/" + fileName) return (link_info.get_link() + "/preview") except: print("Please pass a path to a file")
def owncloud_add_user_account(auth, **kwargs): """ Verifies new external account credentials and adds to user's list This view expects `host`, `username` and `password` fields in the JSON body of the request. """ # Ensure that ownCloud uses https host_url = request.json.get('host') host = furl() host.host = host_url.rstrip('/').replace('https://', '').replace('http://', '') host.scheme = 'https' username = request.json.get('username') password = request.json.get('password') try: oc = owncloud.Client(host.url, verify_certs=settings.USE_SSL) oc.login(username, password) oc.logout() except requests.exceptions.ConnectionError: return { 'message': 'Invalid ownCloud server.' }, http_status.HTTP_400_BAD_REQUEST except owncloud.owncloud.HTTPResponseError: return { 'message': 'ownCloud Login failed.' }, http_status.HTTP_401_UNAUTHORIZED provider = OwnCloudProvider(account=None, host=host.url, username=username, password=password) try: provider.account.save() except ValidationError: # ... or get the old one provider.account = ExternalAccount.objects.get( provider=provider.short_name, provider_id='{}:{}'.format(host.url, username).lower()) if provider.account.oauth_key != password: provider.account.oauth_key = password provider.account.save() user = auth.user if not user.external_accounts.filter(id=provider.account.id).exists(): user.external_accounts.add(provider.account) user.get_or_add_addon('owncloud', auth=auth) user.save() return {}
def getSupportedDavVersion(): # connect just to check supported DAV version client = owncloud.Client(Config['owncloud_url']) client.login(Config['owncloud_login'], Config['owncloud_password']) caps = client.get_capabilities() dav_version = None if 'dav' in caps and 'chunking' in caps['dav']: dav_version = float(caps['dav']['chunking']) return dav_version
def __init__(self, host, oc_user, oc_password, number_users, number_groups): logging.basicConfig(level=logging.ERROR) self.logger = logging.getLogger(__name__) self.oc = owncloud.Client(host) self.users = {} self.groups = [] self.users_groups = {} self.oc_user = oc_user self.oc_password = oc_password self.fill_users_array(number_users) self.fill_groups_array(number_groups)
def __upload2owncloud(self): oc = owncloud.Client(self.config["pag"]["owncloud_internal_url"]) oc.login(self.config["pag"]["owncloud_user"], self.config["pag"]["owncloud_password"]) oc.put_file(os.path.basename(self.filename), self.filename) link_info = oc.share_file_with_link(os.path.basename(self.filename)) self.link = link_info.get_link().replace( self.config["pag"]["owncloud_internal_url"], self.config["pag"]["owncloud_external_url"]) self.link += "/download" os.remove(self.filename) return
def nclink(update, context): """Send a message when the command /nclink is issued.""" oc = owncloud.Client(NEXTCLOUD_URL) oc.login(NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD) if oc.is_shared('Documents'): link_info = oc.get_shares('Documents') sharingLink = link_info[0].get_link() else: link_info = oc.share_file_with_link('Documents') sharingLink = link_info.get_link() update.message.reply_text(sharingLink)
def upload_to_nextcloud(self, data): oc = owncloud.Client(self._settings.get(["server_address"])) try: oc.login(self._settings.get(["username"]), self._settings.get(["password"])) oc.put_file(self._settings.get(["dir_path"]) + data["movie_basename"], data["movie"]) self._logger.info( "Uploaded timelapse: %s to %s" % (data["movie_basename"], self._settings.get(["server_address"]))) except Exception as e: self._logger.error("Unable to upload timelaps: " + str(e)) return if self._settings.get(["delete"]): os.remove(data["movie"]) self._logger.info("Deleted local Timelapse: %s" % data["movie_basename"])