sandiz / rs-manager

Stats Manager for Rocksmith - Manage Playlists, Stats, Setlists and more!
https://sandiz.github.io/rs-manager/
GNU General Public License v3.0
52 stars 8 forks source link

[MAC] No password rocksniffing #45

Closed JustinAiken closed 5 years ago

JustinAiken commented 5 years ago

Okay, so if we make a file like this:

src/tools/rocksniff:

#! /usr/bin/env bash

# Run a command in the background.
_evalBg() {
  eval "$@" &>/dev/null &disown;
}

rocksniff_off() {
  pids=$(rocksniff_pids)
  if [ -n "$pids" ]; then
    kill -9 $pids
  fi
}

rocksniff_pids() {
  ps aux | grep RockSniffer.exe | grep -v grep | awk '{print $2}'
}

rocksniff_on() {
  rocksniff_off
  cmd='/Library/Frameworks/Mono.framework/Commands/mono "/Applications/Rocksmith Manager.app/Contents/Resources/app/src/tools/RockSniffer/RockSniffer.exe"'
  _evalBg "${cmd}";
}

case $1 in
   "on") rocksniff_on &;;
   "off") rocksniff_off;;
   "pids") echo $(rocksniff_pids);;
   *) echo "invalid usage!" && exit 1;;
esac

And then replace the "on" command for mac with:

-      this.rssniffer = `bash -c "${killcmd}; cd '${cwd}'; /Library/Frameworks/Mono.framework/Commands/mono RockSniffer.exe"`
+      this.rssniffer = `/Applications/Rocksmith Manager.app/Contents/Resources/app/src/tools/RockSniffer/rocksniff on`

..and something similar for the "stop tracking"...

We should keep about the same functionality, but now we have a single command rocksniff.

Then if one edits their local sudors file to add:

%staff ALL=(ALL) NOPASSWD: /Applications/Rocksmith Manager.app/Contents/Resources/app/src/tools/RockSniffer/rocksniff

They should not get prompted to enter the password when clicking "Start Tracking" or "Stop Tracking"..

But the downside is, it means we can't dynamically find the rocksniff script or the RockSniffer.exe - it gets hardcoded to RSManager being installed to /Applications

What do you think about this idea?

sandiz commented 5 years ago

let me try this out and get back to you.. i hate the password prompt too, if its possible to get rid of it that would be killer!

sandiz commented 5 years ago

hi @JustinAiken

i added support for passwordless rslive to v1.7.4. Can you try it out and let me know if it works!

you'll have to check this setting:

my sudoers for reference:

[I] /e/sudoers.d sudo cat rocksniffer
Password:
%staff ALL=(ALL) NOPASSWD: /Users/sandi/Projects/rs-manager/release-builds/Rocksmith\ Manager-darwin-x64/Rocksmith\ Manager.app/Contents/Resources/app/src/tools/rocksniff_mac, /Users/sandi/Projects/rs-manager/src/tools/rocksniff_mac
[I] /e/sudoers.d
sandiz commented 5 years ago

thanks for initial legwork on this! i wasn't sure if it was possible to whitelist single applications

the bash script also makes the code neater and easy to debug!! 🍻

JustinAiken commented 5 years ago

Can you try it out and let me know if it works!

$ sudo /Applications/Rocksmith\ Manager.app/Contents/Resources/app/src/tools/rocksniff_mac on
$ sudo /Applications/Rocksmith\ Manager.app/Contents/Resources/app/src/tools/rocksniff_mac pids
13684

$ ps aux | grep 13684
root             13684   2.1  0.2  4464912  41564 s005  S     4:01PM   0:00.77 /Library/Frameworks/Mono.framework/Commands/mono RockSniffer.exe

$ sudo /Applications/Rocksmith\ Manager.app/Contents/Resources/app/src/tools/rocksniff_mac off
$ sudo /Applications/Rocksmith\ Manager.app/Contents/Resources/app/src/tools/rocksniff_mac pids
sandiz commented 5 years ago

did you check the passwordless setting ? it picks up window.exec / window.sudo.exec based on that setting

JustinAiken commented 5 years ago

.... I totally missed that setting 😛

Nevermind, it does work perfectly!

sandiz commented 5 years ago

sweeet, window.sudo.exec always shows the dialog irrespective of sudoers which is lame..

i used this setting to workaround the issue... thanks for testing! closing this issue as fixed! no more password prompts yay!!!!

JustinAiken commented 5 years ago

Can also take it one step further with Hammerspoon (which I'm currently using to push enter to get through the menus for me 😛)

Set up a little script like:

function applicationWatcher(appName, eventType, appObject)
  if (appName == "Rocksmith2014") then
    if (eventType == hs.application.watcher.launched) then
      os.execute('/usr/bin/sudo -n "/Applications/Rocksmith Manager.app/Contents/Resources/app/src/tools/rocksniff_mac" on')
      hs.alert.show("Rocksniffing On...")
    elseif (eventType == hs.application.watcher.terminated) then
      os.execute('/usr/bin/sudo -n "/Applications/Rocksmith Manager.app/Contents/Resources/app/src/tools/rocksniff_mac" off')
      hs.alert.show("Killed RockSniffer!")
    end
  end 
end

local appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()

And it'll start/stop RockSniffer whenever you start/stop Rocksmith.

Commented that bit out for now.. but once RockSniffer gets a bit more reliable, the dream is to have it record every note I ever play, and constantly dump stats 😀

sandiz commented 5 years ago

oooh, just gets better and better!! downloading hammerspoon now!

one thing i would really love is a play button or similar which would take me directly to the song options panel with that song selected... havent found the pointer which controls that yet, so still a dream...