Lock for Plex Google Chrome App

HI iSh0w

I've tried two or three times in the past to get this plugin to work.  Each time i came across the same problem.  the "Unlock" would work, but the "lock" would not.

This weekend I had some time on my hands, so i had a bit of play with the plugin. I figured out it was not a problem with the ".bat" files, as i could run that directly from the OS (windows7, server 2008).  it was a problem with the Python code.  I put a line the Code to make a logger entry everytime it got to the "L0ck" procedure, and i could see in the log, that it was making an entry, for the "unlock" request, but was not triggering when "lock" ing.

This means that the issue had to be here :-

oc.add(DirectoryObject(key=Callback(L0ck, path=BASEPATHL0CK, task='L0cked', query=""), title="L0ck", thumb=R(L0CK_ICON)))	
oc.add(InputDirectoryObject(key=Callback(L0ck, path=BASEPATHUNL0CK, task='UnL0cked'), title="UnL0ck", thumb=R(UNL0CK_ICON), prompt="Enter your password"))
oc.add(DirectoryObject(key=Callback(Updates), title="Update Feed", thumb=R(UPDATES_ICON)))
Return oc

again after some messing around, i made it Lock/unlock by duplicaiting the "unlock" line, and changing the "unlocks" to "locks", this worked, but it asked for  a password everytime. 

So i directed my attention to the first line, and put a value, any value, in the query="" var eg query="1".  and it worked!!

for some reason on my systems, if the query is blank, the code, just won't execute through to the "lock" procedure.

I also changed the SQL that executes when locking and unlocking.  I had a niggle about the need to restart/refresh the client after unlocking/locking.  so I added a Library called "Restricted", added some content into it, and had a play.  what i ended up was this :-

for locking
update metadata_items set library_section_id = 999 where library_section_id = 25

For unlocking
update metadata_items set library_section_id = 25 where library_section_id = 999

this means that after running the lock, there will be nothing in the library "25", and after unlocking the content will be there, No need to refresh/restart the client.  but you do have a Library that will always be empty when the content is locked.

Thought i would share...

Good plugin. thanks for all the hard work.

https://twitter.com/lockforplex/status/663283582832480256

1) First Unl0ck then backup whatever is working!

2) Delete the L0ck.bundle plug-in

3) Re-generate the L0ck plug-in (http://ish0w.github.io/L0ck-for-plex-media-server/)

4) Just follow the instructions on the installation page (do not remove any "quotes" or anything in the terminal commands, this is critical and think this is why you are facing problems, simply copy and paste, if you are running as root, remove the word sudo, that's all)

5) DO NOT change/edit the l0ck.sh and unl0ck.sh files to your current working ones

6) Test

7) If l0ck is not l0cking the section, use Zarquon's method to check/debug the l0ck.sh file

8) If it still does not work, copy/paste plug-in log in pastebin and the lock.sh log in a separate pastebin and share the link of the logs pasted in the pastebin here (Difficult to read the logs via mobile, pastebin is easier, thanks)

/iSh0w

sorry for the delay.

but this also dont work

http://pastebin.com/3KQN6nzC

a error.log isnt there

sorry for the delay.

but this also dont work

http://pastebin.com/3KQN6nzC

a error.log isnt there

Well if the Error.log in the l0ck.sh directory is not there then that usually means the plugin is not calling it.  Does the l0ck.sh and unl0ck.sh work from the terminal?

Zarquon42, what worked for another Ubuntu Server user FYI pl.

/iSh0w

Good to know.

Well if the Error.log in the l0ck.sh directory is not there then that usually means the plugin is not calling it.  Does the l0ck.sh and unl0ck.sh work from the terminal?

it works......

i have change the lock.sh and unlock.sh

sqlite3 /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/com.plexapp.plugins.library.db "$unl0ckplex"

works

./sqlite3 /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/com.plexapp.plugins.library.db "$unl0ckplex"

works not

it works......

i have change the lock.sh and unlock.sh

sqlite3 /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/com.plexapp.plugins.library.db "$unl0ckplex"

works

./sqlite3 /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/com.plexapp.plugins.library.db "$unl0ckplex"

works not

OK so did you do the steps I suggested here: https://forums.plex.tv/topic/119217-rel-parental-control-channel-for-pms/?p=762345

Edit: Nevermind just got your PM.  Try those steps and see if it works.

yes, i did this

yes, i did this

So is every thing working now?

I do it like on the video step by step, but the warning window to open the lock.bat does not come on. I have set the UAC to the max, but still nothing.

https://twitter.com/lockforplex/status/663283582832480256

This is the very best solution I have ever found !!! It works really fine with PMS on my NAS (a Synology) and Plex for Samsung (just in case any user wonders...)  B)

"Unfortunately" (but this is NOT a blame!) when unlocked, libraries are visible for all Plex Clients (PHT, Plex For Samsung, Plex web, ...). So, kids who would start Plex at that moment would have access the libraries.

To mitigate that risk, I have added a "Short Unl0ck" feature to your plugin. It unlocks the libraries only for a few minutes. After that delay, the libraries are automatically re-locked. If a movie has been started in the mean time (at least with Direct Play), it does not stop although the libraries is no unlocked anymore!

My changes can be find in the zip here attached:

- there is a new icon named "shortUnL0ck.png"

- there is a new script named "shortUnl0ck.sh". This one call l0ck.sh after a delay of 10* sec 

- I have updated __init__.py to use those new artifacts.

* 10 is enough for testing purpose with PHT. As soon as libraries unlocked, I restart PHT to validate that the libraries are indeed unlocked. Immediately, I turn off PHT and restart it after a few second to validate that the libraries are now re-locked...

NB.: the other changes in l0ck.sh and unl0ck.sh are related to my Synology (I.e.: use the right path)... 

By any chance, but ONLY if this is of any interest for other users, would it be possible to add an option in your generator to get this "Short Unlock" feature (with possibly a customizable delay) ??? So, when I will update your plugin on my PMS, I won't have to reapply my patch  :unsure: .

The only issue is with the Plex Web Client... as the unlock icon cannot be displayed, I have no idea how I could do a "short unlock" from there ?!

V.

Here is a quick and dirty version that supports the Plex Web Client...

I used two DirectoryObject for the two "unlocks" and redirect them to two distinct InputDirectoryObject. I.e.:

- On the 1st screen, the user has to select "L0ck", "Unl0ck", "Short Unl0ck" or "Update Feed" 

- If he selects "Unlo0ck" or "Short Unl0ck",  

- within Plex Web Client, the user has next a 2nd screen with a message asking to type his password in the search box + hit enter.

- within other clients, the user has a 2nd screen where he must click on "Enter password". Finally, he get the prompt for his password

If I could find how to detect the type of client, I could add a check on that to use this "redirection" only for the Web Client...

That being said, although not user friendly, it works for Plex Home Theater, Plex Web Client and Plex for Samsung...

Here attached my changes (still with path for Synlogy, my libraries and a password: 1234)

Here is a quick and dirty version that supports the Plex Web Client...

I used two DirectoryObject for the two "unlocks" and redirect them to two distinct InputDirectoryObject. I.e.:

- On the 1st screen, the user has to select "L0ck", "Unl0ck", "Short Unl0ck" or "Update Feed" 

- If he selects "Unlo0ck" or "Short Unl0ck",  

- within Plex Web Client, the user has next a 2nd screen with a message asking to type his password in the search box + hit enter.

- within other clients, the user has a 2nd screen where he must click on "Enter password". Finally, he get the prompt for his password

If I could find how to detect the type of client, I could add a check on that to use this "redirection" only for the Web Client...

That being said, although not user friendly, it works for Plex Home Theater, Plex Web Client and Plex for Samsung...

Here attached my changes (still with path for Synlogy, my libraries and a password: 1234)

This is good work:

One thing I noticed is you could make some changes to your shortUnl0ck.sh  I changed it to make it work with anyones install and added a capability to very the relock delay.

 #!/bin/bash

cd “${0%/*}”

sh ./unl0ck.sh
(sleep ${1:-120} ; sh ./l0ck.sh ) &

exit;

EDIT: Forgot to add the cd command. Fixed. Note this CD takes you to the script directory and could be used in the l0ck.sh and unl0ck.sh scripts as well.

If I could find how to detect the type of client, I could add a check on that to use this "redirection" only for the Web Client...

Could you use Client.Platform to detect the client.  See https://dev.plexapp.com/docs/api/runtimekit.html

Could you use Client.Platform to detect the client.  See https://dev.plexapp.com/docs/api/runtimekit.html

Actually what you want is Client.Product (there isn't and documentation but I found a reference on Google and tried it.)

if Client.Product and Client.Product in ('Plex Web') :
        DoSomething
else :
        DoSomethingElse

Great! 

I will adapt the __init__.py this evening (GMT+1)...

10.000 thx! 

That's ok (; as long as it l0cks / unl0cks?!


/iSh0w


Sent from my iPhone using Tapatalk

On the video, i see Locked, but it did not work for me.

https://twitter.com/lockforplex/status/663283582832480256

Zarquon, I have included your tips and tricks ;)

NB: I found that I had to check both for Client.Product 'Web Client' and 'Plex Web'.

[After deleting all my plugins and restarting PMS, I arrived indeed on a dashboard with a layout that I never saw before...

And the Product was 'Web Client'...]

if Client.Product and Client.Product in ('Plex Web', 'Web Client') :
   DoSomething
else :
   DoSomethingElse

So:

- I use now the "current path" in all the shell scripts.

- the plugin detects if it's a web client or not, offering the most "user friendly experience" depending on the Client Product  :)

- I have set a default delay in a Defaults.json file + used the API Prefs to pass the value to the script ShortUnl0ck....

- and added a settings icon to change that value ;)

 

I have also improved a bit (IMHO) the user experience : If one types a wrong password when trying to unlock, no need to come back to the previous screen to retry.

This is especially convenient for the web client as one can retype immediately in the search box. Within PHT, you won't spare a hit.

Unfortunately, I ended by putting a mess in the plugin with the @routes...

In the Web Client, everything worked fine, but in PHT, the "Lock" button didn't work anymore...

The only solution I found was to remove the route on the function 'L0ck' ... I wonder how to fix this issue properly.

It's most probably because I call that method from various "routes" ? (I am not yet comfortable with that principle)...

Next step:

- if possible, return to the home/main screen directly after unlocking/locking (without navigating back to quite the plugin) <= still didn't find how to do that

iSh0w, if you could validate my change... I am really not yet comfortable with the Plex API and would benefit of some feedback.

By the way, shouldn't I post in the Dev thread instead ?  :wacko:  :huh: