gboudreau / nest-api

Unofficial Nest Learning Thermostat API
GNU Lesser General Public License v3.0
300 stars 93 forks source link

Multiple users. #120

Closed reppeprd closed 4 years ago

reppeprd commented 4 years ago

I have 2 users using the nest.class.php API. One is a cron the runs using my user ID and the second is an HTML (php) that runs using the Apache user. This causes some confusion with the cache and cookie files in the /tmp directory. to solve this problem I have modified the nest.class.php file to add the current user name to be a part of the cache and cookie file names. now everything appears to working smoothly.

I changes these lines: $this->cookie_file = sys_get_temp_dir() . '/nest_phpcookies' . md5($username . $password); $this->cache_file = sys_get_temp_dir() . '/nest_phpcache' . md5($username . $password);

to be like this: $this->cookie_file = sys_get_temp_dir() . '/nest_phpcookies' . posix_getpwuid(posixgeteuid())['name'] . '' . md5($this->issue_token); $this->cache_file = sys_get_temp_dir() . '/nest_phpcache' . posix_getpwuid(posixgeteuid())['name'] . '' . md5($this->issue_token);

bauzer714 commented 4 years ago

Your before and proposed code changes seem to be affecting the different login types. One based on username and password - the other by issue token.. I'm also not sure I'm following why couldn't share the cache files? Are you also using two different nest logins?

reppeprd commented 4 years ago

This has nothing to do with logging on to the nest server and getting date from the server. That all works very well.

Scenario: 1) No cache files exist 2) The cron job running for user A runs 3) now there are two files in the /tmp directory that are owned by user A with 600 as permissions 4) user B now runs and cannot read the cache files in the /tmp directory but runs anyway then tries to write the two files in the /tmp directory but gets an error because user B does not have permission to write or read the existing files in the /tmp directory

My solution was to add the user id (A or B in this scenario) to the name of the cached files thus both users have their own cashed files in the /tmp directory.