edit._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  * Copyright (C) 2003-2004 Martin Baehr
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: debug.pike.in,v 1.1 2009/09/28 14:19:52 nicke Exp $
19  */
20 inherit "applauncher.pike";
21 //inherit "/usr/local/lib/steam/server/modules/groups.pike";
22 class edit : public applauncher.pike{
23 public:
24 
25 
26 
27 void ping(string host, string port, string user, string|void pw)
28 {
29  call_out(ping, 10, host, port, user, pw);
30  mixed a = conn->send_command(14, 0);
31  if (a=="sTeam connection lost.")
32  {
33  conn = ((program)"client_base.pike")();
34  conn->close();
35  if (conn->connect_server(host, port) && user != "guest")
36  {
37  if(conn->send_command(14,0)!="sTeam connection lost.")
38  {
39  conn->login(user, pw, 1);
40  _Server=conn->SteamObj(0);
41  user_obj = _Server->get_module("users")->lookup(options->user);
42  gp = user_obj->get_groups();
43  get_file_object();
44  update(file);
45  }
46  }
47  }
48 }
49 
50 object conn;
51 mapping conn_options = ([]);
52 object _Server,user_obj,file;
53 array gp;
54 
55 int main(int argc, array argv)
56 {
57 
58 
59 // program pGroup = (program)"/classes/Group.pike";
60  mapping options=init(argv);
61 // gp=_Server->get_module("groups")->lookup("helloworld");
62  _Server=conn->SteamObj(0);
63  user_obj = _Server->get_module("users")->lookup(options->user);
64  gp = user_obj->get_groups();
65 
66 /* WORKING AND GIVING GROUP OBJECTS AND NAMES */
67  int i = 1;
68  write("Listing all groups : \n\n");
69  foreach(gp, object obj) {
70  write("Group "+i+" : "+obj->get_group_name()+".\n");
71  i=i+1;
72  }
73 
74 // groups_pgm = ((program)"/usr/local/lib/steam/server/modules/groups.pike")();
75 // gp= _Server->get_module("groups")->lookup(1);
76 /* gp=_Server->get_module("filepath:tree")->path_to_object("/home/WikiGroups");
77 // write(gp->get_group_name());
78  */
79 // mystr = gp->get_group_name();
80 // write(mystr);
81 // array gps = ({ "Admin" , "coder" , "help" , "PrivGroups" , "WikiGroups" , "sTeam" });
82  get_file_object();
83  return applaunch(file,demo);
84 }
85 
86 void demo(){}
87 
88 void get_file_object()
89 {
90  int len = sizeof(gp);
91  if ((string)(int)options->file == options->file)
92  file = conn->find_object(options->file);
93  else if (options->file[0] == '/')
94  file = _Server->get_module("filepath:tree")->path_to_object(options->file);
95  else // FIXME: try to find out how to use relative paths
96  {
97  string a = options->file;
98  int tmp_len = 0;
99  while(!file && tmp_len!=(len+2)){
100  write("Checking in "+(string)a+"\n");
101  file = _Server->get_module("filepath:tree")->path_to_object(a);
102  if(tmp_len<len)
103  {
104  string gp_name = gp[tmp_len]->get_group_name();
105  if(gp_name[.. 10] == "WikiGroups.")
106  {
107  gp_name=gp_name[11 ..];
108  a = "/wiki/"+gp_name+"/"+options->file;
109  }
110  else
111  {
112  a="/home/"+gp_name+"/"+options->file;
113  }
114  }
115  tmp_len=tmp_len+1;
116  }
117  }
118  if (file->get_class() == "Link")
119  file = file->get_link_object();
120 }
121 
122  mapping options = ([ ]);
123 mapping init(array argv)
124 {
125 
126  array opt=Getopt.find_all_options(argv,aggregate(
127  ({"host",Getopt.HAS_ARG,({"-h","--host"})}),
128  ({"user",Getopt.HAS_ARG,({"-u","--user"})}),
129  ({"port",Getopt.HAS_ARG,({"-p","--port"})}),
130  ));
131 
132  foreach(opt, array option)
133  {
134  options[option[0]]=option[1];
135  }
136  if(!options->host)
137  options->host="127.0.0.1";
138  if(!options->user)
139  options->user="root";
140  if(!options->port)
141  options->port=1900;
142  else
143  options->port=(int)options->port;
144 
145  options->file = argv[-1];
146 
147  string server_path = "/usr/local/lib/steam";
148 
149  master()->add_include_path(server_path+"/server/include");
150  master()->add_program_path(server_path+"/server/");
151  master()->add_program_path(server_path+"/server/modules/groups.pike");
152  master()->add_program_path(server_path+"/conf/");
153  master()->add_program_path(server_path+"/spm/");
154  master()->add_program_path(server_path+"/server/net/coal/");
155 
156  conn = ((program)"client_base.pike")();
157 // groups_pgm = ((program)"groups.pike")();
158  int start_time = time();
159 
160  werror("Connecting to sTeam server...\n");
161  while ( !conn->connect_server(options->host, options->port) )
162  {
163  if ( time() - start_time > 120 )
164  {
165  throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()}));
166  }
167  werror("Failed to connect... still trying ... (server running ?)\n");
168  sleep(10);
169  }
170 
171  if(lower_case(options->user) == "guest")
172  {
173  ping(options->host, options->port, options->user);
174  return options;
175  }
176 
177  mixed err;
178  string pw;
179  int tries=3;
180  //readln->set_echo( 0 );
181  do
182  {
183  pw = Input.read_password( sprintf("Password for %s@%s", options->user,
184  options->host), "steam" );
185 // pw ="steam";
186  //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host));
187  }
188  while((err = catch(conn->login(options->user, pw, 1))) && --tries);
189  //readln->set_echo( 1 );
190 
191  if ( err != 0 )
192  {
193  werror("Failed to log in!\nWrong Password!\n");
194  exit(1);
195  }
196  ping(options->host, options->port, options->user, pw);
197  return options;
198 }
199 
200 
201 
202 };