-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from centosadmin/develop
Develop
- Loading branch information
Showing
39 changed files
with
543 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,11 @@ This plugin provides common stuff to build redmine plugins that involve Slack/Te | |
* Ruby 2.3+ | ||
* Redmine 3.4+ | ||
|
||
### Upgrade from 0.2.0 to 0.3+ | ||
|
||
From 0.3.0 proxy settings are unified for tdlib and bot and there is support for multiple proxies. | ||
If you have used proxies before, you should reassign it on plugin settings page. | ||
|
||
### Upgrade from 0.1.0 to 0.2+ | ||
|
||
Webhook URL is changed in 0.2.0 because of webhook secret. You need to reinitialize webhook from plugin settings page. | ||
|
@@ -22,6 +27,21 @@ Telegram support includes: | |
* Common client commands that utilize [tdlib-ruby](https://github.com/centosadmin/tdlib-ruby) | ||
* [Telegram Login](https://core.telegram.org/widgets/login) to connect Redmine and Telegram accounts | ||
|
||
|
||
### Proxy | ||
|
||
You can set proxy pool on plugin settings page. Proxies are gonna be monitored for availability, and first working proxy will be taken for every request. | ||
|
||
Proxy format is same to curl: | ||
|
||
```bash | ||
http://user:[email protected]:3128 | ||
socks5://user:[email protected]:9050 | ||
``` | ||
|
||
Only SOCKS5 and HTTP proxies are supported. | ||
Note that tdlib supports only SOCKS5 proxies, so you should add at least one SOCKS5 proxy if you want tdlib to be proxied. | ||
|
||
### Tdlib | ||
In order to use tdlib client you need compiled [TDLib](https://github.com/tdlib/td). | ||
|
||
|
@@ -45,6 +65,8 @@ To make telegram client working you should follow steps: | |
* Go to the plugin settings page | ||
* Press "Authorize Telegram client" button and follow instructions | ||
|
||
**IMPORTANT:** 2FA is not supported at the moment | ||
|
||
### Bot API | ||
|
||
It is necessary to register a bot and get its token. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class TelegramProxiesController < ApplicationController | ||
before_action :check_admin | ||
|
||
def index | ||
@proxies = TelegramProxy.all | ||
|
||
respond_to do |format| | ||
format.js | ||
end | ||
end | ||
|
||
def new | ||
@proxy = TelegramProxy.new | ||
|
||
respond_to do |format| | ||
format.js | ||
end | ||
end | ||
|
||
def update | ||
params[:proxies].each do |params| | ||
id, proxy_params = params[:id], filter_params(params) | ||
proxy = id.present? ? TelegramProxy.find(id) : TelegramProxy.new | ||
proxy.assign_attributes(proxy_params) | ||
proxy.save | ||
end | ||
|
||
respond_to do |format| | ||
format.js | ||
end | ||
end | ||
|
||
def destroy | ||
@proxy = TelegramProxy.find(params[:id]) | ||
@proxy.destroy | ||
|
||
respond_to do |format| | ||
format.js | ||
end | ||
end | ||
|
||
private | ||
|
||
def check_admin | ||
raise Unauthorized unless User.current.admin? | ||
end | ||
|
||
def filter_params(params) | ||
params.permit(:url) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class TelegramProxy < ActiveRecord::Base | ||
enum protocol: %i[http socks5] | ||
|
||
validates_presence_of :host, :port, :protocol | ||
|
||
scope :alive, -> { where(alive: true) } | ||
|
||
def assign_attributes(new_attributes) | ||
attributes = new_attributes.stringify_keys | ||
url = attributes.delete('url') | ||
return super unless url | ||
|
||
uri = URI(url) | ||
|
||
protocol = uri.scheme.in?(self.class.protocols.keys) ? uri.scheme : nil | ||
|
||
super(attributes.merge(user: uri.user, password: uri.password, host: uri.host, port: uri.port, protocol: protocol)) | ||
end | ||
|
||
def url | ||
return '' unless host.present? | ||
"#{protocol}://#{user ? "#{[user, password.to_s].join(':')}@" : ''}#{[host, port].join(':')}" | ||
end | ||
|
||
def check! | ||
status = | ||
begin | ||
connection.get('/').status | ||
rescue Faraday::ClientError | ||
nil | ||
end | ||
update(alive: status == 200) | ||
end | ||
|
||
private | ||
|
||
def connection | ||
Faraday.new('https://telegram.org') do |conn| | ||
conn.adapter(:patron) { |adapter| adapter.proxy = url } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
<%= render partial: 'settings/redmine_bots/deprecation_warning' %> | ||
|
||
<% tabs = [ | ||
{name: 'slack', partial: 'settings/redmine_bots/slack', label: 'redmine_bots.label.slack'}, | ||
{name: 'telegram', partial: 'settings/redmine_bots/telegram', label: 'redmine_bots.label.telegram'}, | ||
] %> | ||
|
||
<%= render_tabs tabs %> | ||
|
||
<script> | ||
$(".toggle-password").click(function() { | ||
var input = $($(this).attr("toggle")); | ||
if (input.attr("type") == "password") { | ||
$(this).text('[Скрыть]'); | ||
input.attr("type", "text"); | ||
} else { | ||
$(this).text('[Показать]'); | ||
input.attr("type", "password"); | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% if Redmine::Plugin.installed?('redmine_bots') %> | ||
<% if RedmineBots.deprecated_plugins.present? %> | ||
<h1 style="text-align: center"> | ||
!!! <%= "#{t 'redmine_bots.settings.deprecated_plugins'}#{RedmineBots.deprecated_plugins.join(', ')}" %> !!! | ||
</h1> | ||
<% end %> | ||
<% else %> | ||
<h1 style="text-align: center"> | ||
!!! <a href="https://github.com/centosadmin/redmine_bots" target="_blank">redmine_bots</a> not found !!! | ||
</h1> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<p id="<%= dom_id(proxy) %>"> | ||
<%= hidden_field_tag 'proxies[][id]', proxy.id %> | ||
<%= text_field_tag 'proxies[][url]', proxy.url, style: 'width: 50%' %> | ||
|
||
<% unless proxy.new_record? %> | ||
<%= link_to l(:button_delete), telegram_proxy_destroy_path(id: proxy.id), remote: true, method: :delete %> | ||
<% end %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%= form_tag telegram_proxies_path, remote: true, format: :js do %> | ||
<div id="telegram-proxies" class=""> | ||
<% @proxies.each do |proxy| %> | ||
<%= render partial: 'item', locals: { proxy: proxy } %> | ||
<% end %> | ||
</div> | ||
|
||
<div> | ||
<%= link_to l(:button_add), telegram_proxy_new_path, remote: true %> | ||
</div> | ||
|
||
<p> | ||
<%= submit_tag l(:button_save) %> | ||
</p> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('#<%= dom_id(@proxy) %>').remove(); |
Oops, something went wrong.