auto(284e8d004cbb): session end @ 2026-06-30T17:30:09 (+1f)

This commit is contained in:
ssw committed 2026-06-30 17:30:10 +08:00
1 parent 01a0706909
commit 06bcbbece1
4 files changed
-127

No files matched your search

Vendored
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
-127
View File
@@ -1,127 +0,0 @@
package jnpf;
import java.io.*;
import java.net.*;
public class Dacli {
private static final String BASE_URL = "http://127.0.0.1:30000";
private static final String TOKEN_FILE = System.getProperty("user.home") + "/.dacli_token";
private String token;
private String appCode = "tds";
public static void main(String[] args) throws Exception {
Dacli cli = new Dacli();
cli.run(args);
}
public void run(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("dacli: login | status | form-list | menu-list | help");
return;
}
String cmd = args[0];
try {
switch (cmd) {
case "login":
doLogin(args[1], args[2], args.length > 3 ? args[3] : "tds");
break;
case "status":
doStatus();
break;
case "form-list":
doGet("/api/visualdev/Base/list");
break;
case "menu-list":
doGet("/api/system/Menu/ModuleBySystem");
break;
default:
System.out.println("Unknown: " + cmd);
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
public void doLogin(String account, String password, String appCode) throws Exception {
this.appCode = appCode;
URL url = new URL(BASE_URL + "/api/oauth/Login");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("App-Code", appCode);
String data = "account=" + account + "&password=" + password +
"&origin=password&grant_type=password&timestamp=0";
conn.getOutputStream().write(data.getBytes("UTF-8"));
String resp = readResponse(conn);
// Parse token from JSON
int tokenStart = resp.indexOf("\"token\":\"");
if (tokenStart >= 0) {
tokenStart += 8;
int tokenEnd = resp.indexOf("\"", tokenStart);
if (tokenEnd > tokenStart) {
this.token = resp.substring(tokenStart, tokenEnd);
saveToken();
System.out.println("Login OK: " + account + " @ " + appCode);
return;
}
}
System.out.println("Login FAILED: " + resp.substring(0, Math.min(resp.length(), 200)));
}
public void doStatus() throws Exception {
loadToken();
System.out.println("appCode=" + appCode + ", token=" + (token != null ? "OK" : "NULL"));
}
public void doGet(String path) throws Exception {
loadToken();
URL url = new URL(BASE_URL + path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("App-Code", appCode);
if (token != null) {
conn.setRequestProperty("Authorization", "bearer " + token);
}
int code = ((HttpURLConnection)conn).getResponseCode();
String resp = readResponse(conn);
System.out.println("Code=" + code + ", Response=" + resp.substring(0, Math.min(resp.length(), 300)));
}
private String readResponse(HttpURLConnection conn) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
sb.append(line);
}
return sb.toString();
}
private void loadToken() throws Exception {
File f = new File(TOKEN_FILE);
if (f.exists()) {
BufferedReader br = new BufferedReader(new FileReader(f));
this.token = br.readLine();
this.appCode = br.readLine();
if (this.appCode == null) this.appCode = "tds";
br.close();
}
}
private void saveToken() throws Exception {
FileWriter fw = new FileWriter(TOKEN_FILE);
fw.write(token + "\n" + appCode);
fw.close();
}
}
BIN
View File
Binary file not shown.