Как назначить WM_CLASS при запуске приложения

Выполните команду sudo ifconfig . Он должен вернуть список подключений, одним из которых будет что-то вроде tun0 , которое является вашим VPN-туннелем. В блоке tun0 будет inet-адрес xxx.xxx.xxx.xxx .

Возьмите этот адрес inet и добавьте его или отредактируйте файл .rtorrent.rc (который, вероятно, находится в вашем каталоге / home ) так, чтобы он читался :

bind = xxx.xxx.xxx.xxx

(Очевидно, вы будете вводить числа, а не xxx.xxx.xxx.xxx ).

Это утомительно делать каждый раз, когда вы подключаетесь, но разоблачение вашего фактического IP-адреса является реальной проблемой, если у вашего VPN истекло время ожидания, и вы были переведены на ваш реальный IP-адрес, пока ваш rtorrent все еще работает.

Я пишу сценарий, чтобы делать это автоматически при каждой загрузке. Если это сработает, я попробую вернуться и выложить это.

как и было обещано, вот сценарий, который сделает это за вас. Нецелесообразно запускать его при загрузке, если вы не запускаете свой vpn при загрузке, поэтому вы должны запускать его вручную с правами root или с помощью sudo из каталога, в котором находится ваш .rtorrent.rc, после запуска вашего vpn и до запуска rtorrent.

извините, что опубликовал что-то, для чего требуются привилегии суперпользователя, никогда не запускайте ничего из форума с запросом суперпользователя, если вы сами не проверите это в целях безопасности. Сценарий

проанализирует ваш вывод ifconfig в поисках IP-адреса, связанного со строкой 'tun', и запишет его как оператор привязки в последнюю строку вашего файла .rtorrent.rc.

тем временем он сначала создает каталог с именем .svrtvpn, где хранит до десяти резервных копий существующего файла .rtorrent.rc, затем удаляет все другие операторы привязки из вашего файла .rtorrent.rc, а затем записывает обнаруженный IP-адрес vpn для привязки в последнюю строку в вашем .rtorrent.rc file

я очень ленив, поэтому было легче потратить время на написание скрипта и просто вызвать его быстро, чем на десять дополнительных секунд, чтобы вручную обнаруживать и записывать привязку каждый раз, когда я запускаю vpn. # ! / bin / bash

#svrtvpn.sh ver 0.3  "shadowvision rtorrent vpn" 01-05-2016 @ shadowvision.com/org
#a simple script to set your .rtorrent.rc bind to the ip address your vpn is using so that if your vpn gets disconnected, rtorrent will stop and you wont be unmasked
#WARNING WARNING WARNING WARNING under some circumstances it erases parts or even the entire .rtorrent file, but it makes a backup first so namaste :)
#this seems to happen if there arent any bind addresses to start with so the script will append a bogus one before it does anything else.

#syntax before starting rtorrent, run as root from the directory where your .rtorrent.rc is, follow the prompt and enter your linux user name that you will be running rtorrent as.

#provide help
if [ "$1" = "help" ]; then
echo "  use: before starting rtorrent, run as root from the directory where your .rtorrent.rc is."
echo "  script is dependent on ifconfig returning the vpn connection as 'tun'.  if that isnt what your connection is called you will have to manually change it inside the script"
echo "  svrtvpn.sh saves your existing .rtorrent.rc file in a directory called .svrtvpn with the extension of the epoch time in seconds. the last ten backups are saved."
echo "  if you use this script, the bind = address will always be the last line of your .rtorrent.rc file"
echo "  svrtvpn.sh ver 0.3  "shadowvision rtorrent vpn" 01-05-2016 @ shadowvision.com/org"
echo "  a simple script to set your .rtorrent.rc bind to the ip address your vpn is using so that if your vpn gets disconnected, rtorrent will stop and you wont be unmasked"
echo "  shadowvision makes no claims as to the usability of this script on your system, it was tested on kali linux with network manager and PIA 'private internet access'"
exit
fi

#first check to see if you have a .rtorrent.rc file.  if you dont it tells you so and exits.
RTORRENTFILE=./.rtorrent.rc
if [ ! -f "$RTORRENTFILE" ]; then
    echo "You dont have  .rtorrent.rc in this directory, script will now exit!"
    exit
fi

# set your backup directory variable
SVDIR=.svrtvpn

#tell the user its using a backup directory
if [ -d "$SVDIR" ]; then
  echo "using existing $SVDIR directory for backups.  your your last ten backups will be saved here."


#now make your .svrtvpn directory where your backups are stored if it doesnt already exist
else
mkdir -p $SVDIR
echo "created a directory called $SVDIR, your last ten .rtorrent.rc backups are stored here."
fi


#first find out what user you are running as, the script sets the ownership of .rtorrent.rc to this user at the end

SVUSER=$(ls -ld .rtorrent.rc | awk '{print $3}')
echo "your .rtorrent.rc file is owned by $SVUSER , it should remain read/write by that user and read for everyone else at the end of this script."
#copy your .rtorrent.rc to a backup file with the seconds of epoch time as the extension.
cp .rtorrent.rc ./$SVDIR/.rtorrent.rc.$(date +"%s")

#append a bogus ip bind so that the script wont erase your entire file
echo "bind = 999.999.999.999" >> .rtorrent.rc


#find out what your current vpn ip is, and if you dont have one, exit. as long as you didnt previously have a valid ip entered rtorrent wont start.
if $( ifconfig |grep -q -A1 tun); then
VPNIP=$(ifconfig |grep -A1 tun |grep inet | grep  -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)

#find any bind addresses in the file so we can delete them
DELINE=$(cat .rtorrent.rc |grep   bind | grep  '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | grep -v \# |grep -v \:)

#delete old bind addresses by tediously copying everything but found addresses to a temp file then back to the original file.
cat .rtorrent.rc |grep -v "$DELINE" > ./$SVDIR/.rtorrent.xx
cat ./$SVDIR/.rtorrent.xx > .rtorrent.rc

#add the vpn ip to the end of your file
echo "bind =" "$VPNIP" >> .rtorrent.rc

#make sure ownerships and read perms are sane
chown $SVUSER .rtorrent.rc
chmod u+rw .rtorrent.rc
chmod a+r .rtorrent.rc
chown -R $SVUSER $SVDIR
chmod -R a+r $SVDIR

#only save last ten backups, note the number is set to 13 because the three files . .. and .xx file arent backups
cd $SVDIR

ls -tra | head -n -13 | xargs --no-run-if-empty rm

cd -
else

#if you got to here it didnt work so set a bogus bind address so rtorrent wont start
VPNIP=999.999.999.999

#just like above find any old bind addresses so we can remove them
DELINE=$(cat .rtorrent.rc |grep   bind | grep  '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | grep -v \# |grep -v \:)
cat .rtorrent.rc |grep -v "$DELINE" > ./$SVDIR/.rtorrent.xx
cat ./$SVDIR/.rtorrent.xx > .rtorrent.rc

#set the bogus address
echo "bind =" "$VPNIP" >> .rtorrent.rc

#reset sane perms
chown $SVUSER .rtorrent.rc
chmod u+rw .rtorrent.rc
chmod a+r .rtorrent.rc
chown -R $SVUSER $SVDIR
chmod -R a+r $SVDIR

#tell us what happened
echo "you are not connected to a vpn, this wont work"
echo "your bind address has been set to 999.999.999.999"
fi
29
18.01.2019, 03:20
1 ответ

Эта запись гарантирует, что rootможет выполняться sudo. Если вы закомментируете это,

sudo ls

запустить как rootне удастся.

Это удобно :это означает, что пользователи могут запускать sudoкоманды, не слишком задумываясь о вещах, т.е. они будут работать одинаково независимо от того, запущены ли они какsudo-включенные user илиroot(хорошая ли это идея — другой вопрос ). Это также означает, что сценарии могут использовать sudoдля запроса привилегий rootи по-прежнему работать без проблем, когда они запускаются напрямую как root.

45
27.01.2020, 19:38

Теги

Похожие вопросы