Compare commits
19 Commits
Author | SHA1 | Date |
---|---|---|
Alexander Popov | d31f591f52 | |
Alexander Popov | 5511a355d4 | |
Alexander Popov | 99331d966b | |
Alexander Popov | 2f9c1ad76c | |
Alexander Popov | d2517bb3f2 | |
Alexander Popov | 31aeff8191 | |
Alexander Popov | 011f888601 | |
Alexander Popov | dddaf080a7 | |
Alexander Popov | 34a3395853 | |
Alexander Popov | 7e77d85988 | |
Alexander Popov | ff9f7730c8 | |
Alexander Popov | 9c774e0460 | |
Alexander Popov | becda71b3a | |
Alexander Popov | 1c3f743d5c | |
Alexander Popov | 99a065b81b | |
Alexander Popov | 09ca61e016 | |
Alexander Popov | 6950e5f050 | |
Alexander Popov | b90d12ca89 | |
Alexander Popov | 95a8889cbf |
|
@ -0,0 +1,9 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*.cr]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
trim_trailing_whitespace = true
|
|
@ -1 +1,7 @@
|
||||||
|
/docs/
|
||||||
|
/lib/
|
||||||
|
/bin/
|
||||||
|
/.shards/
|
||||||
|
*.dwarf
|
||||||
|
|
||||||
config.json
|
config.json
|
||||||
|
|
BIN
.preview.png
BIN
.preview.png
Binary file not shown.
Before Width: | Height: | Size: 8.4 KiB |
|
@ -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
|
37
LICENSE
37
LICENSE
|
@ -1,24 +1,21 @@
|
||||||
This is free and unencumbered software released into the public domain.
|
The MIT License (MIT)
|
||||||
|
|
||||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
Copyright (c) 2021 Alexander Popov <iiiypuk@iiiypuk.me>
|
||||||
distribute this software, either in source code form or as a compiled
|
|
||||||
binary, for any purpose, commercial or non-commercial, and by any
|
|
||||||
means.
|
|
||||||
|
|
||||||
In jurisdictions that recognize copyright laws, the author or authors
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software dedicate any and all copyright interest in the
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
software to the public domain. We make this dedication for the benefit
|
in the Software without restriction, including without limitation the rights
|
||||||
of the public at large and to the detriment of our heirs and
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
successors. We intend this dedication to be an overt act of
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
relinquishment in perpetuity of all present and future rights to this
|
furnished to do so, subject to the following conditions:
|
||||||
software under copyright law.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
The above copyright notice and this permission notice shall be included in
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
all copies or substantial portions of the Software.
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
||||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||||
OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
For more information, please refer to <http://unlicense.org>
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
68
README.md
68
README.md
|
@ -1,45 +1,47 @@
|
||||||
|
# Будь **ОНЛАЙН** ВКонтакте
|
||||||
|
|
||||||
# vk.com set online status service
|
## Установка
|
||||||
Набор скриптов для поддержания статуса __Онлайн__ в социальной сети Vk.com
|
|
||||||
![preview](https://raw.githubusercontent.com/iiiypuk/vk0nline/master/.preview.png)
|
|
||||||
Набор включает в себя скрипт на `Python` и юнит для `systemd`.
|
|
||||||
|
|
||||||
## Установка:
|
Подготовка рабочей директории:
|
||||||
+ Скачать и распаковать набор скриптов, например в `/home/$USER/.vk0nline`
|
```bash
|
||||||
+ Создать директорию для юнитов systemd: `mkdir -p ~/.config/systemd/user`
|
mkdir -p /home/$USER/.local/share/emilecok/vk0nline
|
||||||
и перейти в неё: `cd ~/.config/systemd/user`
|
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
|
||||||
```
|
|
||||||
ln -s /home/user_name/.vk0nline/systemd/user/vk0nline.service .
|
# Заполняем конфигурационный файл, поля appID и userIds
|
||||||
ln -s /home/user_name/.vk0nline/systemd/user/vk0nline.timer .
|
cp config.json.example config.json
|
||||||
```
|
vi config.json
|
||||||
+ Изменить настройки скрипта и сделать его исполняемым:
|
|
||||||
```
|
# Запускаем, получаем accessToken и запускаем ещё раз
|
||||||
cd ~/.vk0nline/
|
./vk0nline*
|
||||||
mv config.json.example config.json
|
|
||||||
chmod 755 ./vk0nline.py
|
|
||||||
edit config.json
|
|
||||||
```
|
|
||||||
+ Прописать полный путь к файлу конфигурации в скрипте:
|
|
||||||
```python
|
|
||||||
# EDIT IT
|
|
||||||
with open('./config.json', 'r', encoding='utf-8') as f:
|
|
||||||
```
|
|
||||||
+ Прописать полный путь к файлу скрипта в сервисе systemd:
|
|
||||||
`edit ~/.config/systemd/user/vk0nline.service`
|
|
||||||
`ExecStart=/full/path/to/vk0nline.py`
|
|
||||||
+ Активируем автоматический запуск сессии пользователя
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Systemd
|
||||||
|
Активируем автоматический запуск сессии пользователя:
|
||||||
|
```bash
|
||||||
# Изменить параметр ReadWritePaths=/etc /run /var/lib/systemd/linger
|
# Изменить параметр ReadWritePaths=/etc /run /var/lib/systemd/linger
|
||||||
nano /usr/lib/systemd/system/systemd-logind.service
|
nano /usr/lib/systemd/system/systemd-logind.service
|
||||||
|
|
||||||
# Перезапустить сервисы
|
# Перезапустить сервисы
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
# Активировать пользователя
|
# Активировать пользователя
|
||||||
mkdir /var/lib/systemd/linger
|
mkdir /var/lib/systemd/linger
|
||||||
loginctl enable-linger $USER
|
loginctl enable-linger $USER
|
||||||
```
|
```
|
||||||
+ Активируем и запускаем скрипт:
|
|
||||||
```
|
```bash
|
||||||
systemctl start vk0nline.{service,timer} --user
|
# Правим имя пользователя в сервисе
|
||||||
systemctl enable vk0nline.{service,timer} --user
|
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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if ! [[ -d ./bin/ ]]
|
||||||
|
then
|
||||||
|
mkdir bin
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
|
@ -1,7 +1,5 @@
|
||||||
{
|
{
|
||||||
"clientId": 1,
|
"appID": 6954184,
|
||||||
"secureKey": "",
|
"userIds": 69040735,
|
||||||
"serviceKey": "",
|
"accessToken": null
|
||||||
"accessToken": "",
|
|
||||||
"userIds": ""
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
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: 1.2.1
|
||||||
|
|
||||||
|
http-client-digest_auth:
|
||||||
|
git: https://github.com/mamantoha/http-client-digest_auth.git
|
||||||
|
version: 0.6.0
|
||||||
|
|
||||||
|
http_proxy:
|
||||||
|
git: https://github.com/mamantoha/http_proxy.git
|
||||||
|
version: 0.9.0
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
name: vk0nline
|
||||||
|
version: 2.0.1
|
||||||
|
|
||||||
|
authors:
|
||||||
|
- Alexander Popov <iiiypuk@fastmail.fm>
|
||||||
|
|
||||||
|
targets:
|
||||||
|
vk0nline:
|
||||||
|
main: src/vk0nline.cr
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
crest:
|
||||||
|
github: mamantoha/crest
|
||||||
|
|
||||||
|
development_dependencies:
|
||||||
|
ameba:
|
||||||
|
github: crystal-ameba/ameba
|
||||||
|
|
||||||
|
crystal: 1.4.1
|
||||||
|
|
||||||
|
license: MIT
|
|
@ -0,0 +1,92 @@
|
||||||
|
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".colorize(:red)
|
||||||
|
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
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=" \
|
||||||
|
"#{app_id}&redirect_uri=vk.com&response_type=token" \
|
||||||
|
"&display=mobile&v=5.131&revoke=1&state=01010&scope=offline"
|
||||||
|
|
||||||
|
puts token_url.colorize(:green).mode(:bold)
|
||||||
|
end
|
||||||
|
|
||||||
|
if json["accessToken"] == nil
|
||||||
|
get_access_token(json["appID"].as_i)
|
||||||
|
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}
|
||||||
|
)
|
||||||
|
|
||||||
|
status = JSON.parse(response.body)
|
||||||
|
|
||||||
|
begin # Missing hash key
|
||||||
|
if status["error"]
|
||||||
|
puts status["error"]["error_msg"].colorize(:yellow).mode(:bold)
|
||||||
|
puts "Error code #{status["error"]["error_code"]}".colorize(:red)
|
||||||
|
|
||||||
|
puts "---".colorize(:dark_gray)
|
||||||
|
|
||||||
|
get_access_token(json["appID"].as_i)
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
# execute if an exception is raised
|
||||||
|
end
|
||||||
|
|
||||||
|
begin # Status set
|
||||||
|
if status["response"] == 1
|
||||||
|
puts "Complete!".colorize(:green).mode(:bold)
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
# execute if an exception is raised
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,9 +1,10 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=vk.com set online status service
|
Description=vk.com set online status service
|
||||||
|
After=network.target network-online.target nss-lookup.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/full/path/to/vk0nline.py
|
ExecStart=/home/USERNAME/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|
51
vk0nline.py
51
vk0nline.py
|
@ -1,51 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
__author__ = 'Alexander Popov'
|
|
||||||
__copyright__ = '2019 by iiiypuk'
|
|
||||||
__credits__ = ['Alexander Popov']
|
|
||||||
__license__ = 'Unlicense'
|
|
||||||
__version__ = '1.0.0'
|
|
||||||
__maintainer__ = 'Alexander Popov'
|
|
||||||
__email__ = 'iiiypuk@fastmail.fm'
|
|
||||||
__status__ = 'Production'
|
|
||||||
|
|
||||||
# EDIT IT
|
|
||||||
with open('./config.json', 'r', encoding='utf-8') as f:
|
|
||||||
_C = json.load(f)
|
|
||||||
|
|
||||||
def getStatus():
|
|
||||||
response = requests.get('https://api.vk.com/method/users.get?' + \
|
|
||||||
'fields=online,last_seen&v=5.95' + \
|
|
||||||
'&access_token={key}&user_ids={user}'.format(
|
|
||||||
key=_C['serviceKey'], user=_C['userIds']))
|
|
||||||
|
|
||||||
userLoginTime = json.loads(response.content.decode('utf-8'))['response'][0]['last_seen']['time']
|
|
||||||
userOnline = json.loads(response.content.decode('utf-8'))['response'][0]['online']
|
|
||||||
|
|
||||||
return([userOnline, userLoginTime])
|
|
||||||
|
|
||||||
def setOnline():
|
|
||||||
response = requests.get('https://api.vk.com/method/account.setOnline' + \
|
|
||||||
'?voip=0&v=5.95&access_token={key}'.format(key=_C['accessToken']) + \
|
|
||||||
'&user_ids={user}'.format(user=_C['userIds']))
|
|
||||||
content = json.loads(response.content.decode('utf-8'))
|
|
||||||
|
|
||||||
if 'error' in content:
|
|
||||||
if 5 == content['error']['error_code']: # User authorization failed
|
|
||||||
print('User authorization failed.\nOpen this link in browser, and copy access token.')
|
|
||||||
print('https://oauth.vk.com/authorize?client_id={appid}'.format(appid=_C['clientId']) + \
|
|
||||||
'&redirect_uri=vk.com&display=mobile&response_type=' + \
|
|
||||||
'token&v=5.95&revoke=1&state=01010&scope=offline')
|
|
||||||
else:
|
|
||||||
print('Error: {}.'.format(content['error']['error_code']))
|
|
||||||
elif 'response' in content:
|
|
||||||
if 1 == content['response']:
|
|
||||||
print('Ok!')
|
|
||||||
onlineStatus, lastSeen = getStatus()
|
|
||||||
print(onlineStatus, datetime.fromtimestamp(lastSeen).strftime('%Y-%m-%d %H:%M:%S'))
|
|
||||||
|
|
||||||
if __name__ == "__main__": setOnline()
|
|
Loading…
Reference in New Issue