Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sun, wax & wings. added whatsapp login #196

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
896ca13
sun, wax & wings. added whatsapp login
edospadoni Feb 25, 2020
1601de8
deploy. added new whatsapp vars
edospadoni Feb 26, 2020
9cb01f4
wax & wings. fixed quota alert threshold
edospadoni Feb 26, 2020
0274d01
wings build. added default img
edospadoni Feb 26, 2020
d5f7b22
wings. added config for whatsapp number
edospadoni Feb 26, 2020
fbdb849
icarodb. update default for whatsapp messages
edospadoni Feb 26, 2020
e46079b
deploy. added whatsapp number config in wings
edospadoni Feb 26, 2020
e69a198
wings. changed config path
edospadoni Feb 26, 2020
d9ce5f9
wings. remove bad style in error messages
edospadoni Feb 27, 2020
c44f7e5
wings. added short_code in WA login
edospadoni Feb 27, 2020
a163609
wings. added fixed background
edospadoni Feb 27, 2020
63b6699
dedalo. rework curl logic of temporary.chi
Amygos Feb 27, 2020
fe0bad2
dedalo. temporary.chi, handle missing username
Amygos Feb 27, 2020
fa9e61d
dedalo. add http_body() function to temporary.chi
Amygos Feb 27, 2020
c2bf8d4
wax. add json output to temporary stage
Amygos Feb 27, 2020
a33350f
dedalo. temporary.chi request a json response
Amygos Feb 27, 2020
e8f6c91
wax. make shortener service more generic
Amygos Feb 27, 2020
3a42a20
wax. use a short code for WhatsApp auth
Amygos Feb 27, 2020
d9a0f5b
dedalo. use json api for temporary session
Amygos Feb 28, 2020
92081d5
wax. use new whatsapp login
edospadoni Mar 22, 2022
9e76255
sun-ui. fix bad vuejs syntax
edospadoni Mar 22, 2022
a65dae1
sun, wax & wings. fix new temp mode for whatsapp
edospadoni Mar 29, 2022
9ef0bf2
wings. added missing closing div
edospadoni Apr 4, 2022
43794a2
Revert "icaro. removed google social login"
edospadoni Apr 4, 2022
ebabe25
sun, wax & wings. added google login
edospadoni Apr 4, 2022
18311e9
wings: fix temp session for whatsapp
edospadoni Jan 21, 2025
2a7eea4
fixup
edospadoni Jan 21, 2025
4dbbad4
fixup
edospadoni Jan 21, 2025
cd6050c
wax & wings. fix for whatsapp login
edospadoni Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ade/ade-api/methods/shortener.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import (
func GetLongUrl(c *gin.Context) {
hash := c.Param("hash")

shortUrl := wax_utils.GetShortUrlByHash(hash)
hashData := wax_utils.GetDataByHash(hash)

if shortUrl.Id > 0 {
c.Redirect(http.StatusFound, shortUrl.LongUrl)
if hashData.Id > 0 {
c.Redirect(http.StatusFound, hashData.LongUrl)
return
} else {
c.JSON(http.StatusNotFound, gin.H{"message": "Shortener hash not found!"})
Expand Down
1 change: 1 addition & 0 deletions dedalo/template/chilli.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ${HS_MAXCLIENTS:+"maxclients "$HS_MAXCLIENTS""}

include /opt/icaro/dedalo/walled_gardens/local.conf
include /opt/icaro/dedalo/walled_gardens/facebook.conf
include /opt/icaro/dedalo/walled_gardens/google.conf
include /opt/icaro/dedalo/walled_gardens/linkedin.conf
include /opt/icaro/dedalo/walled_gardens/instagram.conf
include /opt/icaro/dedalo/walled_gardens/wifi4eu.conf
Expand Down
3 changes: 3 additions & 0 deletions dedalo/walled_gardens/google.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
uamdomain accounts.google.com
uamdomain ssl.gstatic.com
uamdomain fonts.gstatic.com
42 changes: 29 additions & 13 deletions dedalo/www/temporary.chi
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,64 @@ http_header ()
echo Connection: close
echo Cache: none
echo Access-Control-Allow-Origin: "$HS_ALLOW_ORIGINS"
echo Content: application/json

}

http_body ()
{
echo
echo $1
}

if [ "$AUTHENTICATED" != "1" ]
then
HS_DIGEST=$(echo -n "$HS_SECRET$HS_UUID" | md5sum | awk '{print $1}')
AP_MAC=$(cat /sys/class/net/$HS_INTERFACE/address | tr ':' '-' | awk '{print toupper($0)}')

http_req=$(printf "%s?digest=%s&uuid=%s&stage=temporary&status=new&user=%s&mac=%s&sessionid=%s&ap=%s&nasid=%s" \
http_req=$(printf "%s?digest=%s&uuid=%s&stage=temporary&status=new-json&mac=%s&sessionid=%s&ap=%s&nasid=%s&short_code=%s&uamip=%s" \
$HS_AAA_URL \
$HS_DIGEST \
$HS_UUID \
$FORM_username \
$REMOTE_MAC \
$CHI_SESSION_ID \
$AP_MAC \
$HS_ID )
$HS_ID \
${FORM_short_code:-false} \
$(ip -o -4 addr list tun-dedalo | awk '{print $4}' | cut -d/ -f1)
)

if [ -n "$FORM_username" ]
then
http_req=${http_req}&user=$FORM_username
fi

http_res=$(curl -s -w ",%{http_code}" "$http_req")
http_res=$(curl -s -L --fail "$http_req")

if [ "$?" == "0" ]
then
sessiontimeout=$(echo "$http_res" | cut -d ',' -f 1)
http_code=$(echo "$http_res" | cut -d ',' -f 2)
sessiontimeout=$(echo "$http_res" | jq '.sessiontimeout')

if [ "$http_code" == "200" ]
then
dedalo query authorize mac "$REMOTE_MAC" username "temporary" sessiontimeout "$sessiontimeout"

http_header 200
short_code=$(echo "$http_res" | jq -Mcr '. | select(.short_code != null)| .short_code')

dedalo query authorize mac "$REMOTE_MAC" username "temporary" sessiontimeout "$sessiontimeout"
http_header 200

else
http_header 403
if [ -n "$short_code" ]
then
http_body $(jq -Mcr -n --arg short_code $short_code '{"short_code":$short_code}')
fi

elif [ "$?" == "22" ]
then
http_header 403

else
http_header 500
fi

else

http_header 404

fi
Expand Down
1 change: 1 addition & 0 deletions deploy/ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ icaro:
twilio_auth_token: "TwilioAuthToken"
twilio_service_sid: "TwilioServiceSID"
sms_send_quota_alert: false
whatsapp_number: "TwilioWhatsappNumber"
email_from: "[email protected]"
email_smtp_host: "EmailSMTPHost"
email_smtp_port: "25"
Expand Down
6 changes: 6 additions & 0 deletions deploy/ansible/roles/icaro/tasks/wings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
dest: /opt/icaro/wings/
remote_src: yes

- name: Copy Wings config
template:
src: wings_config.js.j2
dest: /opt/icaro/wings/static/config/config.js
when: icaro.wax is defined

- name: Remove temp files
file:
path:
Expand Down
3 changes: 3 additions & 0 deletions deploy/ansible/roles/icaro/templates/wings_config.js.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const CONFIG = {
WHATSAPP_NUMBER: '{{ icaro.wax.whatsapp_number | default('<YOUR_WHATSAPP_NUMBER>') }}'
}
32 changes: 28 additions & 4 deletions deploy/ansible/roles/icarodb/files/icaro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,17 @@ CREATE TABLE subscription_plans (
price decimal(5,2),
period integer default null,
included_sms integer not null,
included_whatsapp integer not null,
max_units integer not null,
advanced_report boolean default false,
wings_customization boolean default false,
social_analytics boolean default false
);

INSERT INTO subscription_plans VALUES (1, 'free', 'Free', 'Free limited plan', 0.00, 365, 0, 1, false, false, false);
INSERT INTO subscription_plans VALUES (2, 'basic', 'Basic', 'Basic plan', 0.00, 365, 500, 1, true, false, false);
INSERT INTO subscription_plans VALUES (3, 'standard', 'Standard', 'Standard lan', 0.00, 365, 1000, 10, true, true, false);
INSERT INTO subscription_plans VALUES (4, 'premium', 'Premium', 'Premium plan', 0.00, 3650, 2000, 100, true, true, true);
INSERT INTO subscription_plans VALUES (1, 'free', 'Free', 'Free limited plan', 0.00, 365, 0, 0, 1, false, false, false);
INSERT INTO subscription_plans VALUES (2, 'basic', 'Basic', 'Basic plan', 0.00, 365, 500, 5000, 1, true, false, false);
INSERT INTO subscription_plans VALUES (3, 'standard', 'Standard', 'Standard lan', 0.00, 365, 1000, 10000, 10, true, true, false);
INSERT INTO subscription_plans VALUES (4, 'premium', 'Premium', 'Premium plan', 0.00, 3650, 2000, 20000, 100, true, true, true);

CREATE TABLE subscriptions (
id serial not null primary key,
Expand All @@ -329,6 +330,17 @@ CREATE TABLE `account_sms_counts` (
PRIMARY KEY(`id`)
);

CREATE TABLE `account_whatsapp_counts` (
`id` serial,
`account_id` bigint unsigned NOT NULL,
`whatsapp_max_count` bigint unsigned,
`whatsapp_count` bigint unsigned,
`whatsapp_threshold` bigint DEFAULT 0,
FOREIGN KEY (`account_id`) REFERENCES accounts(`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
UNIQUE KEY (`account_id`),
PRIMARY KEY(`id`)
);

CREATE TABLE `hotspot_sms_counts` (
`id` serial,
`hotspot_id` bigint unsigned NOT NULL,
Expand All @@ -341,6 +353,18 @@ CREATE TABLE `hotspot_sms_counts` (
PRIMARY KEY(`id`)
);

CREATE TABLE `hotspot_whatsapp_counts` (
`id` serial,
`hotspot_id` bigint unsigned NOT NULL,
`unit_id` bigint unsigned NOT NULL,
`number` varchar(200) NOT NULL,
`reset` tinyint NOT NULL,
`sent` datetime,
FOREIGN KEY (`hotspot_id`) REFERENCES hotspots(`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
FOREIGN KEY (`unit_id`) REFERENCES units(`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
PRIMARY KEY(`id`)
);

/* -------------------- */

/* URL SHORTENER */
Expand Down
13 changes: 13 additions & 0 deletions deploy/ansible/roles/wax/templates/wax-conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ icaro.wax.twilio_service_sid is defined %}
"link": "http://{{ icaro.hostname }}/wings/login/sms",
"send_quota_alert": {{ icaro.wax.sms_send_quota_alert | lower }}

{% endif %}
},
"whatsapp": {
{% if icaro.wax.twilio_account_sid is defined and
icaro.wax.twilio_auth_token is defined and
icaro.wax.twilio_service_sid is defined %}
"number": "{{ icaro.wax.whatsapp_number }}"
"account_sid": "{{ icaro.wax.twilio_account_sid }}",
"auth_token": "{{ icaro.wax.twilio_auth_token }}",
"service_sid": "{{ icaro.wax.twilio_service_sid }}",
"link": "http://{{ icaro.hostname }}/wings/login/whatsapp",
"send_quota_alert": {{ icaro.wax.sms_send_quota_alert | lower }}

{% endif %}
},
"email": {
Expand Down
1 change: 1 addition & 0 deletions docs/_docs/captive.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Login type after the voucher check:
* Facebook
* Like Gate not mandatory with timeout option (avoid to put like if you waiting for N seconds) (**Not yet implemented**)
* FB Checkin (**Not yet implemented**)
* Google
* Instagram
* Linkedin
* Twitter (**Not yet implemented**)
Expand Down
12 changes: 12 additions & 0 deletions docs/_docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ CREATE TABLE `disclaimers_accounts` (
## Social
For the social logins, each platforms as its application registration process, here the links to create new apps for:
- **Facebook**: [create new app](https://developers.facebook.com/apps)
- **Google+**: [create new app](https://console.cloud.google.com/home/dashboard)
- **LinkedIn**: [create new app](https://www.linkedin.com/developer/apps)
- **Instagram**: [create new app](https://www.instagram.com/developer/)

Expand All @@ -129,6 +130,11 @@ After the registration insert your variables inside the file `/opt/icaro/wax/con
"client_secret": "fb_client_secret",
"redirect_uri": "https://<icaro_instance>/wings/login/facebook"
},
"google": {
"client_id": "gl_client_id",
"client_secret": "gl_client_secret",
"redirect_uri": "http://<icaro_instance>/wings/login/google"
},
"linkedin": {
"client_id": "li_client_id",
"client_secret": "li_client_secret",
Expand Down Expand Up @@ -210,6 +216,12 @@ This variables are common to all backends:
* `FACEBOOK_CLIENT_SECRET` Facebook Oauth2 Client Secret
* `FACEBOOK_REDIRECT_URL` Facebook Redirect URL

##### Google+

* `GOOGLE_CLIENT_ID` Google+ Oauth2 Client ID
* `GOOGLE_CLIENT_SECRET` Google+ Oauth2 Client Secret
* `GOOGLE_CLIENT_REDIRECT_URL` Google+ Oauth2 Redirect URL

##### LinkedIn

* `LINKEDIN_CLIENT_ID` LinkedIn Oauth2 Client ID
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/nethesis/icaro
go 1.15

require (
github.com/ajg/form v1.5.1 // indirect
github.com/appleboy/gofight/v2 v2.1.2
github.com/avct/uasurfer v0.0.0-20180817072212-dc0ec4fd1e87
github.com/fatih/structs v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7h
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down
28 changes: 28 additions & 0 deletions sun/sun-api/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func Init(ConfigFilePtr *string) {
if os.Getenv("FACEBOOK_REDIRECT_URL") != "" {
Config.AuthSocial.Facebook.RedirectURI = os.Getenv("FACEBOOK_REDIRECT_URL")
}
if os.Getenv("GOOGLE_CLIENT_ID") != "" {
Config.AuthSocial.Google.ClientId = os.Getenv("GOOGLE_CLIENT_ID")
}
if os.Getenv("GOOGLE_CLIENT_SECRET") != "" {
Config.AuthSocial.Google.ClientSecret = os.Getenv("GOOGLE_CLIENT_SECRET")
}
if os.Getenv("GOOGLE_CLIENT_REDIRECT_URL") != "" {
Config.AuthSocial.Google.RedirectURI = os.Getenv("GOOGLE_REDIRECT_URL")
}
if os.Getenv("LINKEDIN_CLIENT_ID") != "" {
Config.AuthSocial.LinkedIn.ClientId = os.Getenv("LINKEDIN_CLIENT_ID")
}
Expand Down Expand Up @@ -165,6 +174,25 @@ func Init(ConfigFilePtr *string) {
Config.Endpoints.Sms.SendQuotaAlert, _ = strconv.ParseBool(os.Getenv("SMS_SEND_QUOTA_ALERT"))
}

if os.Getenv("WHATSAPP_NUMBER") != "" {
Config.Endpoints.Whatsapp.Number = os.Getenv("WHATSAPP_NUMBER")
}
if os.Getenv("WHATSAPP_ACCOUNT_SID") != "" {
Config.Endpoints.Whatsapp.AccountSid = os.Getenv("WHATSAPP_ACCOUNT_SID")
}
if os.Getenv("WHATSAPP_AUTH_TOKEN") != "" {
Config.Endpoints.Whatsapp.AuthToken = os.Getenv("WHATSAPP_AUTH_TOKEN")
}
if os.Getenv("WHATSAPP_SERVICE_SID") != "" {
Config.Endpoints.Whatsapp.ServiceSid = os.Getenv("WHATSAPP_SERVICE_SID")
}
if os.Getenv("WHATSAPP_LOGIN_LINK") != "" {
Config.Endpoints.Whatsapp.Link = os.Getenv("WHATSAPP_LOGIN_LINK")
}
if os.Getenv("WHATSAPP_SEND_QUOTA_ALERT") != "" {
Config.Endpoints.Whatsapp.SendQuotaAlert, _ = strconv.ParseBool(os.Getenv("WHATSAPP_SEND_QUOTA_ALERT"))
}

if os.Getenv("EMAIL_FROM") != "" {
Config.Endpoints.Email.From = os.Getenv("EMAIL_FROM")
}
Expand Down
4 changes: 4 additions & 0 deletions sun/sun-api/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ package defaults
var HotspotPreferences = map[string]string{
"user_expiration_days": "30",
"temp_session_duration": "300",
"whatsapp_login": "true",
"whatsapp_login_max": "0",
"whatsapp_login_threshold": "0",
"facebook_login": "true",
"facebook_login_page": "",
"google_login": "true",
"linkedin_login": "true",
"instagram_login": "true",
"sms_login": "true",
Expand Down
10 changes: 10 additions & 0 deletions sun/sun-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func DefineAPI(router *gin.Engine) {
smsStats.GET("/hotspots", methods.StatsSMSTotalSentForHotspot)
smsStats.GET("/hotspots/:hotspot_id", methods.StatsSMSTotalSentForHotspotByHotspot)

whatsappStats := stats.Group("/whatsapp")
whatsappStats.GET("/accounts", methods.StatsWhatsappTotalForAccount)
whatsappStats.GET("/accounts/:account_id", methods.StatsWhatsappTotalForAccount)
whatsappStats.POST("/accounts/:account_id", methods.UpdateWhatsappTotalForAccount)
whatsappStats.PUT("/accounts/:account_id", methods.UpdateWhatsappThresholdForAccount)
whatsappStats.GET("/hotspots", methods.StatsWhatsappTotalSentForHotspot)
whatsappStats.GET("/hotspots/:hotspot_id", methods.StatsWhatsappTotalSentForHotspotByHotspot)

reportStats := stats.Group("/reports")
reportStats.GET("/current/graph", methods.GetCurrentSessions)
reportStats.GET("/sessions/graph", methods.GetHistorySessions)
Expand All @@ -165,6 +173,8 @@ func DefineAPI(router *gin.Engine) {
reportStats.GET("/avg_conn_duration/graph", methods.GetHistoryAvgConnDuration)
reportStats.GET("/sms_year/graph", methods.GetHistorySMSYear)
reportStats.GET("/sms_history/graph", methods.GetHistorySMSHistory)
reportStats.GET("/whatsapp_year/graph", methods.GetHistoryWhatsappYear)
reportStats.GET("/whatsapp_history/graph", methods.GetHistoryWhatsappHistory)
reportStats.GET("/account_types_graph/graph", methods.GetAccountTypeGraph)
reportStats.GET("/account_types_pie/graph", methods.GetAccountTypePie)
}
Expand Down
Loading
Loading