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() {
|
||||
notifyConfPath := filepath.Join(configDir, "notification.conf")
|
||||
notifyConfPath := filepath.Join(configDir, "seafile.conf")
|
||||
|
||||
config, err := ini.Load(notifyConfPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load notification.conf: %v", err)
|
||||
}
|
||||
|
||||
section, err := config.GetSection("general")
|
||||
section, err := config.GetSection("notification")
|
||||
if err != nil {
|
||||
log.Fatal("No general section in seafile.conf.")
|
||||
}
|
||||
@@ -65,11 +65,11 @@ func loadNotifConfig() {
|
||||
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()
|
||||
}
|
||||
|
||||
if key, err := section.GetKey("notification_token"); err == nil {
|
||||
if key, err := section.GetKey("seafile_auth_token"); err == nil {
|
||||
notifToken = key.String()
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,9 @@ seafile_session_new(const char *central_config_dir,
|
||||
GKeyFile *config;
|
||||
GKeyFile *ccnet_config;
|
||||
SeafileSession *session = NULL;
|
||||
char *notif_url = NULL;
|
||||
gboolean notif_enabled = FALSE;
|
||||
char *notif_server = NULL;
|
||||
int notif_port = 8083;
|
||||
char *notif_token = NULL;
|
||||
char *private_key = NULL;
|
||||
|
||||
@@ -126,18 +128,24 @@ seafile_session_new(const char *central_config_dir,
|
||||
g_free (type);
|
||||
}
|
||||
|
||||
notif_url = g_key_file_get_string (config,
|
||||
"notification", "notification_url",
|
||||
notif_enabled = g_key_file_get_boolean (config,
|
||||
"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);
|
||||
|
||||
notif_token = g_key_file_get_string (config,
|
||||
"notification", "notification_token",
|
||||
"notification", "seafile_auth_token",
|
||||
NULL);
|
||||
|
||||
private_key = g_key_file_get_string (config,
|
||||
"notification", "private_key",
|
||||
"notification", "jwt_private_key",
|
||||
NULL);
|
||||
if (private_key) {
|
||||
session->private_key = private_key;
|
||||
}
|
||||
|
||||
@@ -222,16 +230,20 @@ seafile_session_new(const char *central_config_dir,
|
||||
if (!session->org_mgr)
|
||||
goto onerror;
|
||||
|
||||
if (notif_url != NULL && notif_token != NULL) {
|
||||
session->notif_mgr = seaf_notif_manager_new (session, notif_url, notif_token);
|
||||
if (!session->notif_mgr)
|
||||
if (notif_enabled && notif_server != NULL && notif_token != NULL) {
|
||||
char notif_url[128];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return session;
|
||||
|
||||
onerror:
|
||||
g_free (notif_url);
|
||||
g_free (notif_server);
|
||||
g_free (notif_token);
|
||||
g_free (private_key);
|
||||
free (abs_seafile_dir);
|
||||
|
Reference in New Issue
Block a user