Compare commits

...

9 Commits

Author SHA1 Message Date
Alexander Popov d31f591f52
added mkconfig 2022-05-16 22:58:59 +03:00
Alexander Popov 5511a355d4
add help 2022-05-16 22:43:32 +03:00
Alexander Popov 99331d966b
add color output 2022-05-16 21:18:04 +03:00
Alexander Popov 2f9c1ad76c
update 3party libs 2022-05-16 20:55:40 +03:00
Alexander Popov d2517bb3f2 edit install guide 2021-11-12 14:56:00 +03:00
Alexander Popov 31aeff8191 change output filename 2021-11-12 07:44:58 +03:00
Alexander Popov 011f888601 add travis 2021-08-29 14:17:36 +03:00
Alexander Popov dddaf080a7 add systemd guide 2021-08-29 14:01:50 +03:00
Alexander Popov 34a3395853 fix binary link 2021-08-29 13:50:55 +03:00
9 changed files with 125 additions and 97 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

View File

@ -1,44 +0,0 @@
#!/bin/sh
# Prepating installation
mkdir -p /home/$USER/.local/share/emilecok/vk0nline
mkdir -p /home/$USER/.config/emilecok/vk0nline
if [ -x "$(command -v git)" ]; then
echo Installing distribution via Git...
git clone https://github.com/iiiypuk/vk0nline.git --depth 1 /home/$USER/.local/share/emilecok/vk0nline &> /dev/null
elif [ -x "$(command -v unzip)" ]; then
echo Installing distribution via zip file...
cd /home/$USER/.local/share/emilecok/vk0nline
curl -LsOk https://github.com/iiiypuk/vk0nline/archive/master.zip
unzip master.zip
mv vk0nline-master vk0nline
else
echo Git
fi
cd /home/$USER/.local/share/emilecok/vk0nline
sed -i "s/USERNAME/$USER/" ./systemd/user/vk0nline.service &> /dev/null
chmod 755 ./vk0nline.py
cp -p ./config.json.example /home/$USER/.config/emilecok/vk0nline/config.json &> /dev/null
echo Installing systemd services...
mkdir -p /home/$USER/.config/systemd/user
cd /home/$USER/.config/systemd/user
ln -s /home/$USER/.local/share/emilecok/vk0nline/systemd/user/vk0nline.service . &> /dev/null
ln -s /home/$USER/.local/share/emilecok/vk0nline/systemd/user/vk0nline.timer . &> /dev/null
echo Installation complete.
echo
echo Start script, authorize and save access token
echo :: python /home/$USER/.local/share/emilecok/vk0nline/vk0nline.py
echo
echo Edit configuration file
echo :: by /home/$USER/.config/emilecok/vk0nline/config.json
echo
echo And start \& activate systemd services
echo :: systemctl start vk0nline.\{service,timer\} --user
echo :: systemctl enable vk0nline.\{service,timer\} --user

View File

@ -1,6 +0,0 @@
language: crystal
# Uncomment the following if you'd like Travis to run specs and check code formatting
# script:
# - crystal spec
# - crystal tool format --check

12
HISTORY.md Normal file
View File

@ -0,0 +1,12 @@
## Legend
- 🐛 - Bug
- ✔️ - Fixed
- ❌ - Removed
- - Added
- - Information
- ♻️ - Edited
## 2.0.1 - [16/05/2022]
- - Added colors to output
- - Added help
- - Added `--mkconfig` param to make new config file

View File

@ -1,35 +1,47 @@
# vk0nline
Утилита для поддержания статуса __Онлайн__ в социальной сети Vk.com.
Включает в себя `systemd` юнит.
![preview](https://raw.githubusercontent.com/iiiypuk/vk0nline/master/.preview.png)
# Будь **ОНЛАЙН** ВКонтакте
## Установка
Активировать автоматический запуск сессии пользователя
```bash
# Изменить параметр ReadWritePaths=/etc /run /var/lib/systemd/linger
nano /usr/lib/systemd/system/systemd-logind.service
# Перезапустить сервисы
systemctl daemon-reload
# Активировать пользователя
mkdir /var/lib/systemd/linger
loginctl enable-linger $USER
Подготавливаем рабочую директорию
mkdir -p /home/$USER/.local/share/emilecok/vk0nline/
wget https://github.com/iiiypuk/vk0nline/blob/master/config.json.example -O /home/$USER/.local/share/emilecok/vk0nline/config.json
wget $BINARY -O /home/$USER/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
chmod +x /home/$USER/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
Подготовка рабочей директории:
```bash
mkdir -p /home/$USER/.local/share/emilecok/vk0nline
cd /home/$USER/.local/share/emilecok/vk0nline
wget https://github.com/iiiypuk/vk0nline/releases/download/2.0.0/vk0nline-2.0.0.linux-x86_64
# Заполняем конфигурационный файл, поля appID и userIds
vi /home/$USER/.local/share/emilecok/vk0nline/config.json
cp config.json.example config.json
vi config.json
# Запускаем, получаем accessToken и запускаем ещё раз
/home/$USER/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
./vk0nline*
```
## Systemd
Активируем автоматический запуск сессии пользователя:
```bash
...
# Изменить параметр ReadWritePaths=/etc /run /var/lib/systemd/linger
nano /usr/lib/systemd/system/systemd-logind.service
# Перезапустить сервисы
systemctl daemon-reload
# Активировать пользователя
mkdir /var/lib/systemd/linger
loginctl enable-linger $USER
```
```bash
# Правим имя пользователя в сервисе
sed -i "s/USERNAME/$USER/" ./systemd/user/vk0nline.service &> /dev/null
mkdir -p /home/$USER/.config/systemd/user &> /dev/null
cd /home/$USER/.config/systemd/user
ln -s /home/$USER/.local/share/emilecok/vk0nline/systemd/user/vk0nline.service . &> /dev/null
ln -s /home/$USER/.local/share/emilecok/vk0nline/systemd/user/vk0nline.timer . &> /dev/null
# Запуск и активация сервисов
systemctl start vk0nline.\{service,timer\} --user
systemctl enable vk0nline.\{service,timer\} --user
```

View File

@ -5,4 +5,14 @@ then
mkdir bin
fi
crystal build --progress --no-debug --release src/vk0nline.cr -o bin/vk0nline.x86_64-lnx
ARCH=`uname -m`
OS=`uname | tr '[:upper:]' '[:lower:]'`
VERSION=`cat shard.yml | grep -m 1 'version: ' | sed -e 's/version: //g'`
if [ "$1" = "all" ]
then
echo "..in progress.."
else
echo "Build $VERSION for `uname` `uname -m`"
crystal build --progress --no-debug --release src/vk0nline.cr -o bin/vk0nline-$VERSION.$OS-$ARCH
fi

View File

@ -1,8 +1,12 @@
version: 2.0
shards:
ameba:
git: https://github.com/crystal-ameba/ameba.git
version: 1.0.0
crest:
git: https://github.com/mamantoha/crest.git
version: 0.27.0
version: 1.2.1
http-client-digest_auth:
git: https://github.com/mamantoha/http-client-digest_auth.git
@ -10,5 +14,5 @@ shards:
http_proxy:
git: https://github.com/mamantoha/http_proxy.git
version: 0.8.0
version: 0.9.0

View File

@ -1,17 +1,21 @@
name: vk0nline
version: 2.0.0
version: 2.0.1
authors:
- Alexander Popov <iiiypuk@iiiypuk.me>
- Alexander Popov <iiiypuk@fastmail.fm>
targets:
src:
main: src/src.cr
vk0nline:
main: src/vk0nline.cr
dependencies:
crest:
github: mamantoha/crest
crystal: 1.0.0
development_dependencies:
ameba:
github: crystal-ameba/ameba
crystal: 1.4.1
license: MIT

View File

@ -1,24 +1,60 @@
require "option_parser"
require "json"
require "colorize"
require "crest"
# program options
begin
OptionParser.parse do |parser|
parser.banner = "Make ONLINE on vk.com\n"
parser.on "--version", "Show version" do
print "vk0nline ".colorize(:green).mode(:bold)
puts "2.0.1".colorize(:yellow)
exit(0)
end
parser.on "--mkconfig", "Make new empty config" do
new_config = {appID: nil, userIds: nil, accessToken: nil}
File.open("config.json.new", "w") do |f|
f.puts new_config.to_json.to_s
end
print "Config saved to "
print "config.json.new".colorize(:yellow).mode(:bold)
puts " file."
exit(0)
end
parser.on "-h", "--help", "Show help" do
puts parser
exit(0)
end
end
rescue ex
puts ex.message, ""
end
begin # JSON::ParseException
json = File.open("config.json") do |file|
JSON.parse(file)
end
rescue
puts "Parse config.json error"
puts "Parse config.json error".colorize(:red)
exit
end
def get_access_token(appId : Int32)
puts "Open this page, and save token to config.json\n\n"
def get_access_token(app_id : Int32)
puts "Open this page, and save token to config.json:".colorize(:yellow)
token_url = "https://oauth.vk.com/authorize?client_id="\
"#{appId}&redirect_uri=vk.com&response_type=token"\
"&display=mobile&v=5.131&revoke=1&state=01010&scope=offline"
token_url = "https://oauth.vk.com/authorize?client_id=" \
"#{app_id}&redirect_uri=vk.com&response_type=token" \
"&display=mobile&v=5.131&revoke=1&state=01010&scope=offline"
puts token_url
puts token_url.colorize(:green).mode(:bold)
end
if json["accessToken"] == nil
@ -26,29 +62,29 @@ if json["accessToken"] == nil
else
response = Crest.get(
"https://api.vk.com/method/account.setOnline",
params: { :voip => "0", :v => "5.131",
:access_token => json["accessToken"].as_s,
:user_ids => json["userIds"].as_i }
params: {:voip => "0", :v => "5.131",
:access_token => json["accessToken"].as_s,
:user_ids => json["userIds"].as_i}
)
status = JSON.parse(response.body)
begin # Missing hash key
if status["error"]
puts status["error"]["error_msg"]
puts "Error code #{status["error"]["error_code"]}"
puts status["error"]["error_msg"].colorize(:yellow).mode(:bold)
puts "Error code #{status["error"]["error_code"]}".colorize(:red)
puts "---"
puts "---".colorize(:dark_gray)
get_access_token(json["appID"].as_i)
end
rescue
# execute if an exception is raised
rescue
# execute if an exception is raised
end
begin # Status set
if status["response"] == 1
puts "Complete!"
puts "Complete!".colorize(:green).mode(:bold)
end
rescue
# execute if an exception is raised