mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-04 08:54:39 +00:00
Add notification config in seafile.conf (#593)
Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
@@ -35,14 +35,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadNotifConfig() {
|
func loadNotifConfig() {
|
||||||
notifyConfPath := filepath.Join(configDir, "notification.conf")
|
notifyConfPath := filepath.Join(configDir, "seafile.conf")
|
||||||
|
|
||||||
config, err := ini.Load(notifyConfPath)
|
config, err := ini.Load(notifyConfPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load notification.conf: %v", err)
|
log.Fatalf("Failed to load notification.conf: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
section, err := config.GetSection("general")
|
section, err := config.GetSection("notification")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("No general section in seafile.conf.")
|
log.Fatal("No general section in seafile.conf.")
|
||||||
}
|
}
|
||||||
@@ -65,11 +65,11 @@ func loadNotifConfig() {
|
|||||||
logLevel = key.String()
|
logLevel = key.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if key, err := section.GetKey("private_key"); err == nil {
|
if key, err := section.GetKey("jwt_private_key"); err == nil {
|
||||||
privateKey = key.String()
|
privateKey = key.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if key, err := section.GetKey("notification_token"); err == nil {
|
if key, err := section.GetKey("seafile_auth_token"); err == nil {
|
||||||
notifToken = key.String()
|
notifToken = key.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,7 +44,9 @@ seafile_session_new(const char *central_config_dir,
|
|||||||
GKeyFile *config;
|
GKeyFile *config;
|
||||||
GKeyFile *ccnet_config;
|
GKeyFile *ccnet_config;
|
||||||
SeafileSession *session = NULL;
|
SeafileSession *session = NULL;
|
||||||
char *notif_url = NULL;
|
gboolean notif_enabled = FALSE;
|
||||||
|
char *notif_server = NULL;
|
||||||
|
int notif_port = 8083;
|
||||||
char *notif_token = NULL;
|
char *notif_token = NULL;
|
||||||
char *private_key = NULL;
|
char *private_key = NULL;
|
||||||
|
|
||||||
@@ -126,18 +128,24 @@ seafile_session_new(const char *central_config_dir,
|
|||||||
g_free (type);
|
g_free (type);
|
||||||
}
|
}
|
||||||
|
|
||||||
notif_url = g_key_file_get_string (config,
|
notif_enabled = g_key_file_get_boolean (config,
|
||||||
"notification", "notification_url",
|
"notification", "enabled",
|
||||||
|
NULL);
|
||||||
|
if (notif_enabled) {
|
||||||
|
notif_server = g_key_file_get_string (config,
|
||||||
|
"notification", "host",
|
||||||
|
NULL);
|
||||||
|
notif_port = g_key_file_get_integer (config,
|
||||||
|
"notification", "port",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
notif_token = g_key_file_get_string (config,
|
notif_token = g_key_file_get_string (config,
|
||||||
"notification", "notification_token",
|
"notification", "seafile_auth_token",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
private_key = g_key_file_get_string (config,
|
private_key = g_key_file_get_string (config,
|
||||||
"notification", "private_key",
|
"notification", "jwt_private_key",
|
||||||
NULL);
|
NULL);
|
||||||
if (private_key) {
|
|
||||||
session->private_key = private_key;
|
session->private_key = private_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,16 +230,20 @@ seafile_session_new(const char *central_config_dir,
|
|||||||
if (!session->org_mgr)
|
if (!session->org_mgr)
|
||||||
goto onerror;
|
goto onerror;
|
||||||
|
|
||||||
if (notif_url != NULL && notif_token != NULL) {
|
if (notif_enabled && notif_server != NULL && notif_token != NULL) {
|
||||||
session->notif_mgr = seaf_notif_manager_new (session, notif_url, notif_token);
|
char notif_url[128];
|
||||||
if (!session->notif_mgr)
|
g_sprintf (notif_url, "%s:%d", notif_server, notif_port);
|
||||||
|
session->notif_mgr = seaf_notif_manager_new (session, g_strdup (notif_url), notif_token);
|
||||||
|
if (!session->notif_mgr) {
|
||||||
|
g_free (notif_url);
|
||||||
goto onerror;
|
goto onerror;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
|
|
||||||
onerror:
|
onerror:
|
||||||
g_free (notif_url);
|
g_free (notif_server);
|
||||||
g_free (notif_token);
|
g_free (notif_token);
|
||||||
g_free (private_key);
|
g_free (private_key);
|
||||||
free (abs_seafile_dir);
|
free (abs_seafile_dir);
|
||||||
|
Reference in New Issue
Block a user