Create AD Users from a client Computer (remotely) - python

Is there a simpler way to establish a connection to Active directory from a client computer? Ideally I would like to create AD users from an MS Access db on a client computer. The Client and DC Server are located locally. I have explored different ways to accomplish this using VBA and Python but never seem to establish a connection to our Active Directory even to pull simple user information. Do I need to install the LDAP on the sever or is there another way without installing anything on server. Any help would be greatly appreciated.

Active Directory supports an LDAP dialect. You don't need to "install LDAP" to make LDAP requests or create users. You just need permission. If you can't even pull data, you're doing something wrong, and you need to fix that. Perhaps you could post some code?
To pull information from AD into Access using VBA, you can use ADO or LDAP or WMI objects, amongst others:
GetObject("ADO ...
or
GetObject("LDAP ...
or
GetObject("WMI ...
To create new users in Access VBA, you could do something like
Set root = GetObject("LDAP://rootDSE")
Set obj = GetObject("LDAP://CN=Users," & Root.Get("defaultNamingContext"))
Set NewUser = obj.Create("User", "cn=" & strNewUser)
NewUser.Put "sAMAccountName", strNewUser
NewUser.Put "sn", strNewUser
NewUser.Put "displayName", strNewUser
NewUser.SetInfo
NewUser.SetPassword "password"

Related

Where to store tns, username and password for a oracle DB connection in Unix to use with Python and R

i'm quite new to use unix and i'm stuck with this problem.
I have a linux machine with R/RStudio and Python/Anaconda installed.
I have given this machine access to hostname, port and service of my DB.
Now i have to create some sort of configuration file where i can store the username and password of the schema i want this machine to use to get access to db and query it through python or R.
This configuration file must secure the password so noone will know it outside the creator of the config file, other users will use r and python to connect to db via some library usinfg the credentials in this config file.
How can i achieve this? Sorry if i have sayd something wrong.
If you know some other methods to achieve this kind of security level please explain

How to avoid storing the username and password as part of the connection string

Situation
My team works with a NFS. I've written a python script that connects to a database. People execute my python script and based some values associated with their userid in our backend mongodb database the script performs certain actions for them
My question
I have a mongodb connection string like so
database_client = MongoClient("mongodb://<myusername>:<mypassword>#serverip:port/DBName")
The problem is that anyone can simply read the py script and figure out what my username and password are.
What is not an option
Making the Python script and opaque executable is not allowed. Not to mention it doesn't protect my credentials from leaking to other members of the tram who work on the same codebase. Nor is making the db world editable/readable. All requests to edit the db must go through an authorized account and only through the API provided by the script.
Is there a way to do this/what should I be doing instead?
Edit: I am NOT using Heroku. I'm behind a company firewall and the mongoDB server is a machine with an IP on the company network
One idea is to read the username and password from a configuration file1 such as
[topsecret]
user = foo
password = bar
This way you can share the code with anyone and they will be able to execute it only if they have the valid configuration file.
1 You can use the configparser module https://docs.python.org/3.4/library/configparser.html to parse configuration files such as above.

connection times out when trying to connect to mongodb atlas with python

I'm trying to connect to my mongodb atlas cluster but i keep getting timed out as soon as i try to do something with my db.
The db i use was created in mongoshell and also the collection i checked their existence in mongodb compass
ERROR
pymongo.errors.ServerSelectionTimeoutError: projekt-shard-00-01-rk7ft.mongodb.net:27017: timed out,projekt-shard-00-00-rk7ft.mongodb.net:27017: timed out,projekt-shard-00-02-rk7ft.mongodb.net:27017: timed out
CODE
client = MongoClient("""mongodb://user:password#projekt-shard-00-00-rk7ft.mongodb.net:27017,projekt-shard-00-01-rk7ft.mongodb.net:27017,projekt-shard-00-02-rk7ft.mongodb.net:27017/projekt?ssl=true&replicaSet=projekt-shard-0&authSource=admin""")
client.projekt.category.insert_one({type : "pants"}).inserted_id
SO the problem is with your IP Address,
GO to the Network Access panel in MongoDB Atlas
In the IP Access List section, you will find all your IP addresses
Click on edit tab for the current IP address you are using
There change the setting to ALLOW ACCESS FROM ANYWHERE
That's it, it will work!
I was having this issue for hours. It's odd that it seems to be a connection issue, but it's not throwing a bad auth or anything, just this timeout. The client object seems to be actually created (I could print its properties). I kept playing around and this somehow worked:
In the MongoDB GUI, navigate to Database Access
Add a test user with the same read/write permissions to everything as the initial user created upon setup
Change the connection string in Python to the new user's username + password
Run the code
For me it finally connected and inserted successfully. After this, the original user's connection string now worked, so I deleted the test user.
I can't identify the root cause of this issue, but it seems like the Database Users table just needed some kind of action performed on it to refresh and begin accepting user connections.
Anybody looking for a solution, if you are trying to access Atlas instance from out in the wild, check the "Network Access" tab, as i think you have to whitelist either all, or specific IP addresses

Using Database with Pyside and Socket

I am working on my Python project using PySide as my Ui language. My projet is a game which require an internet connection to update the users'score and store in the database.
My problem is how can I store my database in the internet. I mean that all users can access this information when they are connected to an internet (when they are playing my game) and the information/database must be updated all the time.
I am not sure which database is the most appropriate, how to store this information/database in the internet, how to access this information.
I am using Python and PySide.
For the database, I currently use PySide.QtSql .
Thank you for answer(s) or suggestion(s).
I'm not familiar with PySide .. but the idea is
you need to build a function that when internet connection is available it should synchronize your local database with online database and in the server-side you need to build a script that can handle requests ( POST / GET ) to receive the scores and send it to database and I suggest MySQL ..
Hope that helps

how do i create a database in psycopg2 and do i need to?

I'm create a blog using django.
I'm getting an 'operational error: FATAL: role "[database user]" does not exist.
But i have not created any database yet, all i have done is filled in the database details in setting.py.
Do i have to create a database using psycopg2? If so, how do i do it?
Is it:
python
import psycopg2
psycopg2.connect("dbname=[name] user=[user]")
Thanks in advance.
before connecting to database, you need to create database, add user, setup access for user you selected.
Reffer to installation/configuration guides for Postgres.
Generally, you would create the database externally before trying to hook it up with Django.
Is this your private server? If so, there are command-line tools you can use to set up a PostgreSQL user and create a database.
If it is a shared hosting situation, you would use CPanel or whatever utility your host provides to do this. For example, when I had shared hosting, I was issued a database user and password by the hosting administrator. Perhaps you were too.
Once you have this set up, there are places in your settings.py file to put your username and password credentials, and the name of the database.

Categories