Subversion Repositories Koakuma

Rev

Rev 11 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 17
Line 1... Line 1...
1
# $Id: rpc.tcl 11 2024-10-02 00:56:50Z nishi $
1
# $Id: rpc.tcl 17 2024-10-02 07:31:01Z nishi $
2
package require http
2
package require http
3
package require base64
3
package require base64
4
package require term::ansi::ctrl::unix
4
package require term::ansi::ctrl::unix
5
 
5
 
6
catch {
6
catch {
Line 14... Line 14...
14
	set RPC_URL "$env(KOAKUMA_RPC)"
14
	set RPC_URL "$env(KOAKUMA_RPC)"
15
}
15
}
16
set RPC_URL "[regsub {/+$} "$RPC_URL" ""]"
16
set RPC_URL "[regsub {/+$} "$RPC_URL" ""]"
17
 
17
 
18
namespace eval rpc {
18
namespace eval rpc {
-
 
19
	set username ""
-
 
20
	set password ""
19
	proc require-auth {} {
21
	proc require-auth {} {
20
		global RPC_URL
22
		global RPC_URL
21
		set tok [::http::geturl "$RPC_URL"]
23
		set tok [::http::geturl "$RPC_URL"]
22
		set code [::http::ncode $tok]
24
		set code [::http::ncode $tok]
23
		::http::cleanup $tok
25
		::http::cleanup $tok
Line 27... Line 29...
27
			return -1
29
			return -1
28
		} else {
30
		} else {
29
			return 0
31
			return 0
30
		}
32
		}
31
	}
33
	}
-
 
34
	proc set-username {us} {
-
 
35
		global username
32
	set username ""
36
		set ::rpc::username "$us"
-
 
37
	}
-
 
38
	proc set-password {pw} {
-
 
39
		global password
33
	set password ""
40
		set ::rpc::password "$pw"
-
 
41
	}
34
	proc ask-auth {} {
42
	proc ask-auth {} {
35
		global username
43
		global username
36
		global password
44
		global password
37
		puts -nonewline "Username: "
45
		puts -nonewline "Username: "
38
		flush stdout
46
		flush stdout