mirror of https://github.com/oupson/FooTerm.git
Update model to look like database, add method to query server list
This commit is contained in:
parent
a04bb393a4
commit
9a145dd94e
|
@ -20,16 +20,16 @@
|
||||||
|
|
||||||
namespace Footerm.Model {
|
namespace Footerm.Model {
|
||||||
public class Server {
|
public class Server {
|
||||||
|
public string name;
|
||||||
public string hostname;
|
public string hostname;
|
||||||
public ushort port;
|
public ushort port;
|
||||||
public string username;
|
public string username;
|
||||||
public string password;
|
|
||||||
|
|
||||||
public Server(string hostname, ushort port, string username, string password) {
|
public Server(string name, string hostname, ushort port, string username) {
|
||||||
|
this.name = name;
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace Footerm {
|
||||||
// Port is invalid
|
// Port is invalid
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on_new_server(new Footerm.Model.Server(hostname, (ushort)port, username, password));
|
// this.on_new_server(new Footerm.Model.Server(hostname, (ushort)port, username, password));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,5 +107,22 @@ namespace Footerm.Services {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Footerm.Model.Server> get_server_list() throws ConfigError {
|
||||||
|
List<Footerm.Model.Server> list = new List<Footerm.Model.Server> ();
|
||||||
|
|
||||||
|
var stm_str = "SELECT (serverId, serverName, serverHostName, serverPort) FROM SERVER";
|
||||||
|
Sqlite.Statement stm;
|
||||||
|
var ec = this.db.prepare_v2(stm_str, stm_str.length, out stm);
|
||||||
|
if (ec != Sqlite.OK) {
|
||||||
|
throw new ConfigError.DATABASE(@"Can't fetch server list: $(db.errcode ()): $(db.errmsg ())");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (stm.step() == Sqlite.ROW) {
|
||||||
|
list.append(new Footerm.Model.Server(stm.column_text(0), stm.column_text(1), (ushort) stm.column_int(2), stm.column_text(3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,8 @@ namespace Footerm {
|
||||||
}
|
}
|
||||||
stdout.printf("\n");
|
stdout.printf("\n");
|
||||||
|
|
||||||
if (session.auth_password(this.server.username, this.server.password) != SSH2.Error.NONE) {
|
// TODO QUERY PASSWORD FROM libsecret
|
||||||
|
if (session.auth_password(this.server.username, null) != SSH2.Error.NONE) {
|
||||||
stdout.printf("\tAuthentication by password failed!\n");
|
stdout.printf("\tAuthentication by password failed!\n");
|
||||||
session.disconnect("Normal Shutdown, Thank you for playing");
|
session.disconnect("Normal Shutdown, Thank you for playing");
|
||||||
session = null;
|
session = null;
|
||||||
|
|
Loading…
Reference in New Issue