3
/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
4
* Copyright (C) 2003-2004 Martin Baehr
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
* $Id: applauncher,v 1.1.1.1 2006/03/27 12:40:19 exodusd Exp $
23
constant cvs_version="$Id: applauncher,v 1.1.1.1 2006/03/27 12:40:19 exodusd Exp $";
26
#include </usr/lib/steam/server/include/classes.h>
29
inherit "/usr/lib/steam/config";
30
inherit "/usr/lib/steam/server/base/xml_parser";
32
// #include "/usr/lib/steam/server/include/attributes.h"
34
#define USER_WORKROOM 614
35
#define GROUP_WORKROOM 800
36
#define CLASS_EXIT (1<<7)
38
static object oInstall;
40
object find_object(int id)
42
if ( objectp(oInstall) )
43
oInstall->find_object(id);
47
object get_xsl(object conn, object xslxml)
50
xslxml->get_identifier()[..sizeof(xslxml->get_identifier())-9]+
55
object env=conn->send_cmd(xslxml, "get_environment");
56
array inv=conn->send_cmd(env, "get_inventory_by_class", CLASS_DOCXSL);
57
map(inv, lambda(object obj)
59
if(obj->get_identifier()==xslname)
65
void upload(object conn, object editor, string file, int last_mtime, object obj, object xslobj)
67
int new_mtime=file_stat(file)->mtime;
68
if(new_mtime > last_mtime)
71
mixed result=conn->send_cmd(obj, "set_content", Stdio.read_file(file));
72
string message=sprintf("%s: upload: %O", file, result);
73
Stdio.append_file("/tmp/applauncher.log", message+"\n");
74
Process.create_process(({ "screen", "-X", "wall", message }));
77
result=conn->send_cmd(xslobj, "load_xml_structure");
78
message=sprintf("%s: load xml struct: %O", file, result);
79
Stdio.append_file("/tmp/applauncher.log", message+"\n");
80
Process.create_process(({ "screen", "-X", "wall", message }));
84
call_out(upload, 1, conn, editor, file, new_mtime, obj, xslobj);
88
array edit(object conn, object obj)
90
string dir="/tmp/"+(MIME.encode_base64(Crypto.randomness.pike_random()->read(10), 1)-("/"))+System.getpid();
91
string filename=obj->get_object_id()+"-"+obj->get_identifier();
94
string content=conn->send_cmd(obj, "get_content");
95
//werror("%O\n", content);
96
Stdio.write_file(dir+"/"+filename, content, 0600);
98
//array command=({ "screen", "-X", "screen", "vi", dir+"/"+filename });
99
array command=({ "vim", "--servername", "VIM", "--remote-wait", dir+"/"+filename });
100
object editor=Process.create_process(command,
101
([ "cwd":dir, "env":getenv() ]));
102
return ({ editor, dir+"/"+filename });
105
int main(int argc, array argv)
109
write("need a sal file\n");
113
mapping sal=init_file(argv[1]);
115
if(getenv()->DISPLAY)
116
return gtkmain(argv, sal);
118
return consolemain(argv, sal);
121
int consolemain(array (string) argv, mapping sal)
124
Stdio.Readline readln = Stdio.Readline(Stdio.stdin);
125
write("%s@%s:%s\n", sal->userName, sal->hostname, sal->fileName);
126
readln->set_echo( 0 );
127
string pw=readln->read("enter passwd: ");
128
readln->set_echo( 1 );
129
return main2(sal->userName, pw, sal);
132
int gtkmain(array (string) argv, mapping sal)
135
get_login(sprintf("%s: %s", sal->hostname, sal->fileName), sal->userName, main2, sal);
139
int main2(string username, string passwd, mapping sal)
141
object conn=init_steam(username, passwd, sal);
145
object obj = conn->find_object((int)sal->objectID);
148
if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml")
149
xslobj=get_xsl(conn, obj);
153
[editor, file]=edit(conn, obj);
155
//while(!(status=editor->status()))
157
if(!editor->status())
158
call_out(upload, 1, conn, editor, file, file_stat(file)->mtime, obj, xslobj);
160
// signal(signum("SIGINT"), prompt);
164
mapping init_file(string file)
168
foreach(Stdio.read_file(file)/"\n"-({""}), string option)
170
sal[(option/" = ")[0]]=(option/" = ")[1];
175
object init_steam(string username, string passwd, mapping sal)
179
string server_path = "/usr/lib/steam";
180
string config_path = "/etc/steam/";
182
master()->add_include_path(server_path+"/server/include");
183
master()->add_program_path(server_path+"/server/");
184
master()->add_program_path(server_path+"/conf/");
185
master()->add_program_path(server_path+"/server/net/coal/");
186
add_constant("find_object", find_object);
187
read_configs(config_path+"/config.txt");
189
conn = ((program)"connection.pike")();
194
conn->start(sal->hostname, (int)sal->usedPort, username, passwd);
198
werror("Login failed: %s\n", error[0]);