From 8875ff5e1becd4ba6dce604eebf400f32fb36643 Mon Sep 17 00:00:00 2001 From: lins05 Date: Mon, 28 Jan 2013 15:45:52 +0800 Subject: [PATCH] [client] edit server address of a repo If the ccnet-server address is changed (either address or port is changed), on the client side the user should edit the repo's server address/port accorodingly. --- common/rpc-service.c | 78 ++++++++++++++++++++++++ daemon/repo-mgr.c | 32 ++++++++++ daemon/repo-mgr.h | 6 +- daemon/seaf-daemon.c | 15 +++++ gui/common/applet-common.c | 6 ++ include/seafile-rpc.h | 14 +++++ python/seafile/rpcclient.py | 15 +++++ web/i18n/zh_CN/LC_MESSAGES/messages.po | 82 ++++++++++++++++++-------- web/main.py | 13 +++- web/static/css/ccnet.css | 30 ++++++++++ web/templates/repo.html | 65 ++++++++++++++++++++ 11 files changed, 330 insertions(+), 26 deletions(-) diff --git a/common/rpc-service.c b/common/rpc-service.c index b5bc8d3b..3f0dc8d8 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -1075,6 +1075,84 @@ seafile_get_repo_property (const char *repo_id, return value; } +char * +seafile_get_repo_relay_address (const char *repo_id, + GError **error) +{ + char *relay_addr = NULL; + + if (!repo_id) { + g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty"); + return NULL; + } + + seaf_repo_manager_get_repo_relay_info (seaf->repo_mgr, repo_id, + &relay_addr, NULL); + + return relay_addr; +} + +char * +seafile_get_repo_relay_port (const char *repo_id, + GError **error) +{ + char *relay_port = NULL; + + if (!repo_id) { + g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty"); + return NULL; + } + + seaf_repo_manager_get_repo_relay_info (seaf->repo_mgr, repo_id, + NULL, &relay_port); + + return relay_port; +} + +int +seafile_update_repo_relay_info (const char *repo_id, + const char *new_addr, + const char *new_port, + GError **error) +{ + if (!repo_id || !new_addr || !new_port) { + g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty"); + return -1; + } + + int port = atoi(new_port); + if (port <= 0 || port > 65535) { + g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid port"); + return -1; + } + + SeafRepo *repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id); + if (!repo) { + return -1; + } + + CcnetPeer *relay = ccnet_get_peer (seaf->ccnetrpc_client, repo->relay_id); + if (!relay) { + GString *buf = g_string_new(NULL); + g_string_append_printf (buf, "add-relay --id %s --addr %s:%s", + repo->relay_id, new_addr, new_port); + + ccnet_send_command (seaf->session, buf->str, NULL, NULL); + g_string_free (buf, TRUE); + } else { + if (g_strcmp0(relay->public_addr, new_addr) != 0 || + relay->public_port != (uint16_t)port) { + ccnet_update_peer_address (seaf->ccnetrpc_client, repo->relay_id, + new_addr, port); + } + + g_object_unref (relay); + } + + return seaf_repo_manager_update_repo_relay_info (seaf->repo_mgr, repo, + new_addr, new_port); +} + int seafile_calc_dir_size (const char *path, GError **error) { diff --git a/daemon/repo-mgr.c b/daemon/repo-mgr.c index d2bb528a..37126c20 100644 --- a/daemon/repo-mgr.c +++ b/daemon/repo-mgr.c @@ -3123,3 +3123,35 @@ seaf_repo_manager_get_repo_relay_info (SeafRepoManager *mgr, if (relay_port && port) *relay_port = port; } + +int +seaf_repo_manager_update_repo_relay_info (SeafRepoManager *mgr, + SeafRepo *repo, + const char *new_addr, + const char *new_port) +{ + GList *ptr, *repos = seaf_repo_manager_get_repo_list (seaf->repo_mgr, 0, -1); + SeafRepo *r; + for (ptr = repos; ptr; ptr = ptr->next) { + r = ptr->data; + if (g_strcmp0(r->relay_id, repo->relay_id) != 0) + continue; + + char *relay_addr = NULL; + char *relay_port = NULL; + seaf_repo_manager_get_repo_relay_info (seaf->repo_mgr, r->id, + &relay_addr, &relay_port); + if (g_strcmp0(relay_addr, new_addr) != 0 || + g_strcmp0(relay_port, new_port) != 0) { + seaf_repo_manager_set_repo_relay_info (seaf->repo_mgr, r->id, + new_addr, new_port); + } + + g_free (relay_addr); + g_free (relay_port); + } + + g_list_free (repos); + + return 0; +} diff --git a/daemon/repo-mgr.h b/daemon/repo-mgr.h index 94377585..913dce85 100644 --- a/daemon/repo-mgr.h +++ b/daemon/repo-mgr.h @@ -343,5 +343,9 @@ seaf_repo_manager_add_recheckout_task (SeafRepoManager *mgr, CheckoutTask * seaf_repo_manager_get_checkout_task (SeafRepoManager *mgr, const char *repo_id); - +int +seaf_repo_manager_update_repo_relay_info (SeafRepoManager *mgr, + SeafRepo *repo, + const char *new_addr, + const char *new_port); #endif diff --git a/daemon/seaf-daemon.c b/daemon/seaf-daemon.c index 01032c35..9d4538fb 100644 --- a/daemon/seaf-daemon.c +++ b/daemon/seaf-daemon.c @@ -128,6 +128,21 @@ start_rpc_service (CcnetClient *client) "seafile_get_repo_property", searpc_signature_string__string_string()); + searpc_server_register_function ("seafile-rpcserver", + seafile_get_repo_relay_address, + "seafile_get_repo_relay_address", + searpc_signature_string__string()); + + searpc_server_register_function ("seafile-rpcserver", + seafile_get_repo_relay_port, + "seafile_get_repo_relay_port", + searpc_signature_string__string()); + + searpc_server_register_function ("seafile-rpcserver", + seafile_update_repo_relay_info, + "seafile_update_repo_relay_info", + searpc_signature_int__string_string_string()); + searpc_server_register_function ("seafile-rpcserver", seafile_disable_auto_sync, "seafile_disable_auto_sync", diff --git a/gui/common/applet-common.c b/gui/common/applet-common.c index b6a9e9e8..cfc9ebf7 100644 --- a/gui/common/applet-common.c +++ b/gui/common/applet-common.c @@ -173,6 +173,12 @@ handle_seafile_notification (char *type, char *content) char buf[1024]; if (strcmp(type, "transfer") == 0) { + if (applet->auto_sync_disabled) { + /* When auto sync is disabled but there is clone task running, + * applet can still get "transfer" notification, but we don't + * rotate the icon */ + return; + } trayicon_rotate (TRUE); if (content == NULL) { diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index cfedb42c..e5432b91 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -124,6 +124,20 @@ seafile_get_repo_property (const char *repo_id, const char *key, GError **error); +char * +seafile_get_repo_relay_address (const char *repo_id, + GError **error); + +char * +seafile_get_repo_relay_port (const char *repo_id, + GError **error); + +int +seafile_update_repo_relay_info (const char *repo_id, + const char *new_addr, + const char *new_port, + GError **error); + int seafile_disable_auto_sync (GError **error); int seafile_enable_auto_sync (GError **error); diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index dbeac9c4..4f8df2e0 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -168,6 +168,21 @@ class SeafileRpcClient(ccnet.RpcClientBase): pass get_repo_property = seafile_get_repo_property + @searpc_func("string", ["string"]) + def seafile_get_repo_relay_address(repo_id): + pass + get_repo_relay_address = seafile_get_repo_relay_address + + @searpc_func("string", ["string"]) + def seafile_get_repo_relay_port(repo_id): + pass + get_repo_relay_port = seafile_get_repo_relay_port + + @searpc_func("int", ["string", "string", "string"]) + def seafile_update_repo_relay_info(repo_id, addr, port): + pass + update_repo_relay_info = seafile_update_repo_relay_info + @searpc_func("int", ["string", "string"]) def seafile_set_repo_token(repo_id, token): pass diff --git a/web/i18n/zh_CN/LC_MESSAGES/messages.po b/web/i18n/zh_CN/LC_MESSAGES/messages.po index c2d429e0..4bb3be8e 100644 --- a/web/i18n/zh_CN/LC_MESSAGES/messages.po +++ b/web/i18n/zh_CN/LC_MESSAGES/messages.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2013-01-16 20:21+CST\n" +"POT-Creation-Date: 2013-02-01 10:10+CST\n" "PO-Revision-Date: 2012-11-04 11:07+0800\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -15,44 +15,44 @@ msgstr "" "Content-Transfer-Encoding: UTF-8\n" "Generated-By: pygettext.py 1.5\n" -#: main.py:576 main.py:698 +#: main.py:580 main.py:702 msgid "You must choose a local directory" msgstr "你必须指定一个本地目录" -#: main.py:578 main.py:700 +#: main.py:582 main.py:704 msgid "Password can not be empty" msgstr "密码不能为空" -#: main.py:580 main.py:702 +#: main.py:584 main.py:706 msgid "Invalid Repo ID" msgstr "资料库ID格式不正确" -#: main.py:615 main.py:734 +#: main.py:619 main.py:738 msgid "Invalid local directory" msgstr "不是合法的本地目录" -#: main.py:617 main.py:736 +#: main.py:621 main.py:740 msgid "" "The local directory you chose is in sync with another repo. Please choose " "another one." msgstr "你所指定的本地目录已经与其他资料库同步,请指定其他本地目录" -#: main.py:619 main.py:738 +#: main.py:623 main.py:742 msgid "" "The local directory you chose cannot be under or includes a system directory " "of seafile." msgstr "本地目录的路径不能处在 Seafile 系统目录下,或者包含 Seafile 系统目录" -#: main.py:621 main.py:740 +#: main.py:625 main.py:744 msgid "" "The local directory you chose cannot be under or includes another library." msgstr "本地目录的路径不能处在其他资料库目录下,或者包含其他资料库目录" -#: main.py:623 main.py:742 +#: main.py:627 main.py:746 msgid "Incorrect password." msgstr "密码错误" -#: main.py:625 main.py:744 templates/clone_tasks.html:69 +#: main.py:629 main.py:748 templates/clone_tasks.html:69 msgid "Internal error." msgstr "内部错误" @@ -148,7 +148,7 @@ msgstr "合并更改失败" msgid "Incorrect password. Please download again." msgstr "密码错误。请重新下载。" -#: templates/clone_tasks.html:76 templates/repo.html:93 +#: templates/clone_tasks.html:76 templates/repo.html:94 msgid "Cancel" msgstr "取消" @@ -359,58 +359,92 @@ msgstr "操作" msgid "Sync Now" msgstr "立即同步" -#: templates/repo.html:19 templates/repo.html:92 +#: templates/repo.html:19 templates/repo.html:93 msgid "Unsync" msgstr "解除同步" -#: templates/repo.html:31 +#: templates/repo.html:20 +msgid "Edit server address" +msgstr "编辑服务器地址" + +#: templates/repo.html:32 msgid "Encrypted" msgstr "已加密" -#: templates/repo.html:39 +#: templates/repo.html:40 msgid "Local Path:" msgstr "本地路径:" -#: templates/repo.html:42 +#: templates/repo.html:43 msgid "Sync Info" msgstr "同步信息" -#: templates/repo.html:46 +#: templates/repo.html:47 msgid "Server: " msgstr "服务器:" -#: templates/repo.html:52 +#: templates/repo.html:53 msgid "Password: " msgstr "密码:" -#: templates/repo.html:53 +#: templates/repo.html:54 msgid "Show" msgstr "显示" -#: templates/repo.html:59 templates/repo.html:61 +#: templates/repo.html:60 templates/repo.html:62 msgid "Auto Sync: " msgstr "自动同步:" -#: templates/repo.html:74 templates/repo.html:76 +#: templates/repo.html:75 templates/repo.html:77 msgid "transfered" msgstr "已完成" -#: templates/repo.html:79 +#: templates/repo.html:80 msgid "rate" msgstr "速率" -#: templates/repo.html:79 +#: templates/repo.html:80 msgid "s" msgstr "秒" -#: templates/repo.html:85 +#: templates/repo.html:86 msgid "Library transfer error:" msgstr "资料库传输出错:" -#: templates/repo.html:91 +#: templates/repo.html:92 msgid "Really want to unsync this library?" msgstr "确定要解除同步?" +#: templates/repo.html:98 +msgid "Edit Server address" +msgstr "编辑服务器地址" + +#: templates/repo.html:100 +msgid "Warning:" +msgstr "警告:" + +#: templates/repo.html:100 +msgid "" +"You should only edit the server address when you're sure the server has used " +"a new address. Otherwise it may make the libraries unable to be " +"synchronized. After edit the address, you should restart seafile for the " +"changes to take effect." +msgstr "" +"仅当服务器的地址确实发生了改变时,你才应该在这里编辑它。否则将可能导致你的资" +"料库无法同步。修改地址后,请重启 Seafile 以使其生效。" + +#: templates/repo.html:104 +msgid "server name" +msgstr "服务器" + +#: templates/repo.html:109 +msgid "server address" +msgstr "地址" + +#: templates/repo.html:113 +msgid "server port" +msgstr "端口" + #: templates/repo_download.html:8 templates/repo_sync.html:8 msgid "Library already exists." msgstr "该资料库已存在。" diff --git a/web/main.py b/web/main.py index 685e5473..1fa2f06d 100644 --- a/web/main.py +++ b/web/main.py @@ -223,11 +223,15 @@ class repo: relay = get_relay_of_repo(repo) + relay_addr = seafile_rpc.get_repo_relay_address(repo_id) + relay_port = seafile_rpc.get_repo_relay_port(repo_id) + return render.repo(repo=repo, recent_commits=recent_commits, relay=relay, + relay_addr=relay_addr, + relay_port=relay_port, **default_options) - def GET(self): inputs = web.webapi.input(repo='') @@ -430,6 +434,13 @@ class repo_operation: passwd = web.webapi.input(passwd="").passwd if passwd: seafile_rpc.set_repo_passwd(repo.props.id, passwd) + + elif op == 'edit-relay': + inputs = web.webapi.input(relay_addr='', relay_port='') + if inputs.relay_addr and inputs.relay_port: + seafile_rpc.update_repo_relay_info(repo_id, + inputs.relay_addr, + inputs.relay_port) referer = web.ctx.env.get('HTTP_REFERER', '/home/') raise web.seeother(referer) diff --git a/web/static/css/ccnet.css b/web/static/css/ccnet.css index 7f08bd21..abb9cc63 100644 --- a/web/static/css/ccnet.css +++ b/web/static/css/ccnet.css @@ -307,3 +307,33 @@ a.relay-link { #set-sync-btn { vertical-align:middle; } + +#edit-relay-form h2 { + margin: 5px 0 10px 0; +} + +#edit-relay-form .warning { + width: 400px; + margin-bottom: 10px; +} + +#edit-relay-form label { + display: block; + float: left; + width: 7em; + text-align: right; + margin-right: 10px; +} + +#edit-relay-form input { + padding: 3px; +} + +#edit-relay-form .form-row { + margin-bottom: 5px; +} + +#edit-relay-submit { + float: right; + margin-right: 20px; +} \ No newline at end of file diff --git a/web/templates/repo.html b/web/templates/repo.html index 2482caf3..b0739aeb 100644 --- a/web/templates/repo.html +++ b/web/templates/repo.html @@ -17,6 +17,7 @@ @@ -92,6 +93,29 @@ + +
+

${_("Edit Server address")}

+

+ ${_("Warning:")} ${_("You should only edit the server address when you're sure the server has used a new address. Otherwise it may make the libraries unable to be synchronized. After edit the address, you should restart seafile for the changes to take effect.")} +

+ % if relay and relay.name: +
+ + ${relay.name} +
+ % endif +
+ + +
+
+ + +
+

+ + @@ -108,6 +132,47 @@ $("#delete").click(function() { return false; }); +$('#edit-relay').click(function() { + $("#edit-relay-form").modal({appendTo: "#main"}); + return false; +}); + +$('#edit-relay-form').submit(function() { + var addr = $('input[name="relay_addr"]').val(); + var port = $('input[name="relay_port"]').val(); + var addr_re = /^[a-z0-9-]+(\.[a-z0-9-]+)+$/; + var port_re = /^[\d]+$/; + + var show_error = function(msg) { + $('#edit-relay-error').html(msg); + $("#simplemodal-container").css({'height':'auto'}); + }; + + if (!addr) { + show_error('${_("server address can not be empty")}'); + return false; + } else if (!addr_re.test(addr)) { + show_error('${_("server address is invalid")}'); + return false; + } + + if (!port) { + show_error('${_("server port can not be empty")}'); + return false; + } else if (!port_re.test(port)) { + show_error('${_("server port is invalid")}'); + return false; + } else { + port = Number(port); + if (isNaN(port) || port < 0 || port > 65535) { + show_error('${_("server port is invalid")}'); + return false; + } + } + + return true; +}); + // revert dialog var revert_commit = ""; $("a.revert-link").bind('click', function() {