Indefero

Indefero Commit Details


Date:2010-08-13 04:20:03 (14 years 4 months ago)
Author:Thomas Keller
Branch:develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:31e81118ddc6629995d0a3d0c0851b7a697b19e2
Parents: e47d51d14ce6b97bfa9c244e41fbef9c9d3582fb
Message:Follow IDFs coding standards and tweak opening curly braces as well as quoting where possible

Changes:

File differences

src/IDF/Form/UserAccount.php
210210
211211
212212
213
214
213
215214
216215
217216
218
219
217
220218
221
222
219
223220
224221
225222
226223
227224
228225
229
230
226
231227
232228
233229
234230
235231
236232
237
238
233
239234
240235
241236
......
243238
244239
245240
246
247
248
249
241
242
250243
251244
252245
253246
254247
255248
256
257
249
258250
259251
260252
......
264256
265257
266258
267
268
259
269260
270261
271262
......
279270
280271
281272
282
283
273
284274
285
286
275
287276
288277
289
290
278
291279
292280
293281
public static function checkPublicKey($key, $type, $user=0)
{
$key = trim($key);
if (strlen($key) == 0)
{
if (strlen($key) == 0) {
return '';
}
if ($type == 'ssh')
{
if ($type == 'ssh') {
$key = str_replace(array("\n", "\r"), '', $key);
if (!preg_match('#^ssh\-[a-z]{3}\s\S+\s\S+$#', $key))
{
if (!preg_match('#^ssh\-[a-z]{3}\s\S+\s\S+$#', $key)) {
throw new Pluf_Form_Invalid(
__('The format of the key is not valid. It must start '.
'with ssh-dss or ssh-rsa, a long string on a single '.
'line and at the end a comment.')
);
}
if (Pluf::f('idf_strong_key_check', false))
{
if (Pluf::f('idf_strong_key_check', false)) {
$tmpfile = Pluf::f('tmp_folder', '/tmp').'/'.$user.'-key';
file_put_contents($tmpfile, $key, LOCK_EX);
$cmd = Pluf::f('idf_exec_cmd_prefix', '').
'ssh-keygen -l -f '.escapeshellarg($tmpfile).' > /dev/null 2>&1';
exec($cmd, $out, $return);
unlink($tmpfile);
if ($return != 0)
{
if ($return != 0) {
throw new Pluf_Form_Invalid(
__('Please check the key as it does not appears '.
'to be a valid key.')
}
}
}
else if ($type == 'mtn')
{
if (!preg_match('#^\[pubkey [^\]]+\]\s*\S+\s*\[end\]$#', $key))
{
else if ($type == 'mtn') {
if (!preg_match('#^\[pubkey [^\]]+\]\s*\S+\s*\[end\]$#', $key)) {
throw new Pluf_Form_Invalid(
__('The format of the key is not valid. It must start '.
'with [pubkey KEYNAME], contain a long string on a single '.
'line and end with [end] in the final third line.')
);
}
if (Pluf::f('idf_strong_key_check', false))
{
if (Pluf::f('idf_strong_key_check', false)) {
// if monotone can read it, it should be valid
$mtn_opts = implode(' ', Pluf::f('mtn_opts', array()));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').
fwrite($fp, $key);
$return = pclose($fp);
if ($return != 0)
{
if ($return != 0) {
throw new Pluf_Form_Invalid(
__('Please check the key as it does not appears '.
'to be a valid key.')
}
// If $user, then check if not the same key stored
if ($user)
{
if ($user) {
$ruser = Pluf::factory('Pluf_User', $user);
if ($ruser->id > 0)
{
if ($ruser->id > 0) {
$sql = new Pluf_SQL('content=%s AND type=%s', array($key, $type));
$keys = Pluf::factory('IDF_Key')->getList(array('filter' => $sql->gen()));
if (count($keys) > 0)
{
if (count($keys) > 0) {
throw new Pluf_Form_Invalid(
__('You already have uploaded this key.')
);
src/IDF/Key.php
184184
185185
186186
187
188
187
189188
190189
191190
public static function getAvailableKeyTypes()
{
$key_types = array(__("SSH") => 'ssh');
if (array_key_exists('mtn', Pluf::f('allowed_scm', array())))
{
if (array_key_exists('mtn', Pluf::f('allowed_scm', array()))) {
$key_types[__("monotone")] = 'mtn';
}
return $key_types;
src/IDF/Scm/Monotone.php
5454
5555
5656
57
58
57
5958
6059
6160
......
7473
7574
7675
77
76
7877
7978
8079
......
9291
9392
9493
95
94
9695
9796
9897
9998
10099
101100
102
103
101
104102
105103
106104
......
123121
124122
125123
126
127
124
128125
129126
130127
......
142139
143140
144141
145
142
146143
147144
148145
......
157154
158155
159156
160
161
157
162158
163
164
159
165160
166161
167
168
169
162
163
170164
171165
172166
......
174168
175169
176170
177
178
171
179172
180173
181174
......
184177
185178
186179
187
188
180
189181
190
191
192
182
183
193184
194185
195186
......
197188
198189
199190
200
201
191
202192
203193
204194
205195
206196
207
208
197
209198
210199
211200
......
234223
235224
236225
237
238
239
226
227
240228
241229
242230
243
244
231
245232
246
247
233
248234
249
250
235
251236
252237
253238
254239
255
256
257
258
240
241
259242
260243
261244
......
282265
283266
284267
285
286
268
287269
288270
289271
290
291
272
292273
293274
294275
......
306287
307288
308289
309
290
310291
311292
312293
313294
314295
315296
316
317
318
319
320
321
297
298
299
322300
323301
324302
......
333311
334312
335313
336
314
337315
338316
339317
......
341319
342320
343321
344
345
322
346323
347324
348325
349
326
350327
351328
352329
353
354
330
355331
356
357
332
358333
359
360
334
361335
362336
363337
364
365
338
366339
367340
368
369
341
370342
371343
372344
......
385357
386358
387359
388
360
389361
390362
391363
......
394366
395367
396368
397
398
369
399370
400371
401372
402373
403
374
404375
405376
406377
407378
408379
409380
410
411
412
381
382
413383
414384
415385
......
421391
422392
423393
424
425
426
394
395
427396
428397
429398
430399
431
400
432401
433402
434403
435404
436405
437
438
406
439407
440408
441409
......
482450
483451
484452
485
486
453
487454
488
489
455
490456
491457
492458
493
494
495
459
460
496461
497462
498463
......
502467
503468
504469
505
506
470
507471
508472
509473
510
474
511475
512476
513477
......
527491
528492
529493
530
531
494
532495
533496
534497
......
558521
559522
560523
561
524
562525
563526
564527
565528
566529
567
568
569
530
531
570532
571533
572534
......
576538
577539
578540
579
580
541
581542
582543
583544
584545
585546
586547
587
548
588549
589550
590551
......
593554
594555
595556
596
597
557
598558
599559
600560
......
619579
620580
621581
622
623
582
624583
625584
626585
627
586
628587
629588
630589
......
637596
638597
639598
640
641
599
642600
643601
644602
......
647605
648606
649607
650
651
652
608
609
653610
654611
655612
656
657
658
613
614
659615
660616
661617
662
663
618
619
664620
665621
666622
......
676632
677633
678634
679
635
680636
681637
682638
......
697653
698654
699655
700
701
702
656
657
703658
704659
705660
......
707662
708663
709664
710
665
711666
712667
713668
714669
715670
716
717
718
671
672
719673
720674
721675
......
731685
732686
733687
734
735
736
737
738
688
689
690
739691
740692
741693
......
743695
744696
745697
746
747
698
748699
749700
750701
751702
752
753
703
754704
755705
756706
......
771721
772722
773723
774
724
775725
776726
777727
// FIXME: this obviously won't work with remote databases - upstream
// needs to implement mtn db info in automate at first
$repo = sprintf(Pluf::f('mtn_repositories'), $this->project->shortname);
if (!file_exists($repo))
{
if (!file_exists($repo)) {
return 0;
}
{
try
{
$out = $this->stdio->exec(array("interface_version"));
$out = $this->stdio->exec(array('interface_version'));
return floatval($out) >= self::$MIN_INTERFACE_VERSION;
}
catch (IDF_Scm_Exception $e) {}
}
// FIXME: we could / should introduce handling of suspended
// (i.e. dead) branches here by hiding them from the user's eye...
$out = $this->stdio->exec(array("branches"));
$out = $this->stdio->exec(array('branches'));
// note: we could expand each branch with one of its head revisions
// here, but these would soon become bogus anyway and we cannot
// map multiple head revisions here either, so we just use the
// selector as placeholder
$res = array();
foreach (preg_split("/\n/", $out, -1, PREG_SPLIT_NO_EMPTY) as $b)
{
foreach (preg_split("/\n/", $out, -1, PREG_SPLIT_NO_EMPTY) as $b) {
$res["h:$b"] = $b;
}
$branch = "*";
}
if (count($this->_resolveSelector("h:$branch")) == 0)
{
if (count($this->_resolveSelector("h:$branch")) == 0) {
throw new IDF_Scm_Exception(
"Branch $branch is empty"
);
*/
private function _resolveSelector($selector)
{
$out = $this->stdio->exec(array("select", $selector));
$out = $this->stdio->exec(array('select', $selector));
return preg_split("/\n/", $out, -1, PREG_SPLIT_NO_EMPTY);
}
$pos = 0;
$stanzas = array();
while ($pos < strlen($in))
{
while ($pos < strlen($in)) {
$stanza = array();
while ($pos < strlen($in))
{
while ($pos < strlen($in)) {
if ($in[$pos] == "\n") break;
$stanzaLine = array("key" => "", "values" => array(), "hash" => null);
while ($pos < strlen($in))
{
$stanzaLine = array('key' => '', 'values' => array(), 'hash' => null);
while ($pos < strlen($in)) {
$ch = $in[$pos];
if ($ch == '"' || $ch == '[') break;
++$pos;
$stanzaLine['key'] .= $ch;
}
if ($in[$pos] == '[')
{
if ($in[$pos] == '[') {
++$pos; // opening square bracket
$stanzaLine['hash'] = substr($in, $pos, 40);
$pos += 40;
else
{
$valCount = 0;
while ($in[$pos] == '"')
{
while ($in[$pos] == '"') {
++$pos; // opening quote
$stanzaLine['values'][$valCount] = "";
while ($pos < strlen($in))
{
$stanzaLine['values'][$valCount] = '';
while ($pos < strlen($in)) {
$ch = $in[$pos]; $pr = $in[$pos-1];
if ($ch == '"' && $pr != '\\') break;
++$pos;
}
++$pos; // closing quote
if ($in[$pos] == ' ')
{
if ($in[$pos] == ' ') {
++$pos; // space
++$valCount;
}
}
for ($i = 0; $i <= $valCount; $i++)
{
for ($i = 0; $i <= $valCount; $i++) {
$stanzaLine['values'][$i] = str_replace(
array("\\\\", "\\\""),
array("\\", "\""),
{
static $certCache = array();
if (!array_key_exists($rev, $certCache))
{
$out = $this->stdio->exec(array("certs", $rev));
if (!array_key_exists($rev, $certCache)) {
$out = $this->stdio->exec(array('certs', $rev));
$stanzas = self::_parseBasicIO($out);
$certs = array();
foreach ($stanzas as $stanza)
{
foreach ($stanzas as $stanza) {
$certname = null;
foreach ($stanza as $stanzaline)
{
foreach ($stanza as $stanzaline) {
// luckily, name always comes before value
if ($stanzaline['key'] == "name")
{
if ($stanzaline['key'] == 'name') {
$certname = $stanzaline['values'][0];
continue;
}
if ($stanzaline['key'] == "value")
{
if (!array_key_exists($certname, $certs))
{
if ($stanzaline['key'] == 'value') {
if (!array_key_exists($certname, $certs)) {
$certs[$certname] = array();
}
private function _getUniqueCertValuesFor($revs, $certName, $prefix)
{
$certValues = array();
foreach ($revs as $rev)
{
foreach ($revs as $rev) {
$certs = $this->_getCerts($rev);
if (!array_key_exists($certName, $certs))
continue;
foreach ($certs[$certName] as $certValue)
{
foreach ($certs[$certName] as $certValue) {
$certValues[] = "$prefix$certValue";
}
}
private function _getLastChangeFor($file, $startrev)
{
$out = $this->stdio->exec(array(
"get_content_changed", $startrev, $file
'get_content_changed', $startrev, $file
));
$stanzas = self::_parseBasicIO($out);
// FIXME: we only care about the first returned content mark
// everything else seem to be very, very rare cases
foreach ($stanzas as $stanza)
{
foreach ($stanza as $stanzaline)
{
if ($stanzaline['key'] == "content_mark")
{
foreach ($stanzas as $stanza) {
foreach ($stanza as $stanzaline) {
if ($stanzaline['key'] == 'content_mark') {
return $stanzaline['hash'];
}
}
{
$revs = $this->_resolveSelector($commit);
if (count($revs) == 0) return array();
return $this->_getUniqueCertValuesFor($revs, "branch", "h:");
return $this->_getUniqueCertValuesFor($revs, 'branch', 'h:');
}
/**
*/
public function getTags()
{
if (isset($this->cache['tags']))
{
if (isset($this->cache['tags'])) {
return $this->cache['tags'];
}
$out = $this->stdio->exec(array("tags"));
$out = $this->stdio->exec(array('tags'));
$tags = array();
$stanzas = self::_parseBasicIO($out);
foreach ($stanzas as $stanza)
{
foreach ($stanzas as $stanza) {
$tagname = null;
foreach ($stanza as $stanzaline)
{
foreach ($stanza as $stanzaline) {
// revision comes directly after the tag stanza
if ($stanzaline['key'] == "tag")
{
if ($stanzaline['key'] == 'tag') {
$tagname = $stanzaline['values'][0];
continue;
}
if ($stanzaline['key'] == "revision")
{
if ($stanzaline['key'] == 'revision') {
// FIXME: warn if multiple revisions have
// equally named tags
if (!array_key_exists("t:$tagname", $tags))
{
if (!array_key_exists("t:$tagname", $tags)) {
$tags["t:$tagname"] = $tagname;
}
break;
{
$revs = $this->_resolveSelector($commit);
if (count($revs) == 0) return array();
return $this->_getUniqueCertValuesFor($revs, "tag", "t:");
return $this->_getUniqueCertValuesFor($revs, 'tag', 't:');
}
/**
public function getTree($commit, $folder='/', $branch=null)
{
$revs = $this->_resolveSelector($commit);
if (count($revs) == 0)
{
if (count($revs) == 0) {
return array();
}
$out = $this->stdio->exec(array(
"get_manifest_of", $revs[0]
'get_manifest_of', $revs[0]
));
$files = array();
$stanzas = self::_parseBasicIO($out);
$folder = $folder == '/' || empty($folder) ? '' : $folder.'/';
foreach ($stanzas as $stanza)
{
if ($stanza[0]['key'] == "format_version")
foreach ($stanzas as $stanza) {
if ($stanza[0]['key'] == 'format_version')
continue;
$path = $stanza[0]['values'][0];
$file['fullpath'] = $path;
$file['efullpath'] = self::smartEncode($path);
if ($stanza[0]['key'] == "dir")
{
$file['type'] = "tree";
if ($stanza[0]['key'] == 'dir') {
$file['type'] = 'tree';
$file['size'] = 0;
}
else
{
$file['type'] = "blob";
$file['type'] = 'blob';
$file['hash'] = $stanza[1]['hash'];
$file['size'] = strlen($this->getFile((object)$file));
}
$rev = $this->_getLastChangeFor($file['fullpath'], $revs[0]);
if ($rev !== null)
{
if ($rev !== null) {
$file['rev'] = $rev;
$certs = $this->_getCerts($rev);
$scm = IDF_Scm::get($project);
$branch = $scm->getMainBranch();
if (!empty($commit))
{
if (!empty($commit)) {
$revs = $scm->_resolveSelector($commit);
if (count($revs) > 0)
{
if (count($revs) > 0) {
$certs = $scm->_getCerts($revs[0]);
// for the very seldom case that a revision
// has no branch certificate
if (count($certs['branch']) == 0)
{
$branch = "*";
if (count($certs['branch']) == 0) {
$branch = '*';
}
else
{
}
$remote_url = Pluf::f('mtn_remote_url', '');
if (empty($remote_url))
{
if (empty($remote_url)) {
return '';
}
return sprintf($remote_url, $project->shortname)."?".$branch;
return sprintf($remote_url, $project->shortname).'?'.$branch;
}
/**
*/
public static function factory($project)
{
if (!array_key_exists($project->shortname, self::$instances))
{
if (!array_key_exists($project->shortname, self::$instances)) {
self::$instances[$project->shortname] =
new IDF_Scm_Monotone($project);
}
return false;
$out = $this->stdio->exec(array(
"get_manifest_of", $revs[0]
'get_manifest_of', $revs[0]
));
$files = array();
$stanzas = self::_parseBasicIO($out);
foreach ($stanzas as $stanza)
{
if ($stanza[0]['key'] == "format_version")
foreach ($stanzas as $stanza) {
if ($stanza[0]['key'] == 'format_version')
continue;
$path = $stanza[0]['values'][0];
$file = array();
$file['fullpath'] = $path;
if ($stanza[0]['key'] == "dir")
{
if ($stanza[0]['key'] == "dir") {
$file['type'] = "tree";
$file['hash'] = null;
$file['size'] = 0;
}
else
{
$file['type'] = "blob";
$file['type'] = 'blob';
$file['hash'] = $stanza[1]['hash'];
$file['size'] = strlen($this->getFile((object)$file));
}
$file['file'] = $pathinfo['basename'];
$rev = $this->_getLastChangeFor($file['fullpath'], $revs[0]);
if ($rev !== null)
{
if ($rev !== null) {
$file['rev'] = $rev;
$certs = $this->_getCerts($rev);
public function getFile($def, $cmd_only=false)
{
// this won't work with remote databases
if ($cmd_only)
{
if ($cmd_only) {
throw new Pluf_Exception_NotImplemented();
}
return $this->stdio->exec(array("get_file", $def->hash));
return $this->stdio->exec(array('get_file', $def->hash));
}
/**
*/
private function _getDiff($target, $source = null)
{
if (empty($source))
{
if (empty($source)) {
$source = "p:$target";
}
$targets = $this->_resolveSelector($target);
$sources = $this->_resolveSelector($source);
if (count($targets) == 0 || count($sources) == 0)
{
return "";
if (count($targets) == 0 || count($sources) == 0) {
return '';
}
// if target contains a root revision, we cannot produce a diff
if (empty($sources[0]))
{
return "";
if (empty($sources[0])) {
return '';
}
return $this->stdio->exec(
array("content_diff"),
array("r" => array($sources[0], $targets[0]))
array('content_diff'),
array('r' => array($sources[0], $targets[0]))
);
}
$certs = $this->_getCerts($revs[0]);
// FIXME: this assumes that author, date and changelog are always given
$res['author'] = implode(", ", $certs['author']);
$res['author'] = implode(', ', $certs['author']);
$dates = array();
foreach ($certs['date'] as $date)
*/
public function isCommitLarge($commit=null)
{
if (empty($commit))
{
$commit = "h:"+$this->getMainBranch();
if (empty($commit)) {
$commit = 'h:'.$this->getMainBranch();
}
$revs = $this->_resolveSelector($commit);
return false;
$out = $this->stdio->exec(array(
"get_revision", $revs[0]
'get_revision', $revs[0]
));
$newAndPatchedFiles = 0;
$stanzas = self::_parseBasicIO($out);
foreach ($stanzas as $stanza)
{
if ($stanza[0]['key'] == "patch" || $stanza[0]['key'] == "add_file")
foreach ($stanzas as $stanza) {
if ($stanza[0]['key'] == 'patch' || $stanza[0]['key'] == 'add_file')
$newAndPatchedFiles++;
}
$initialBranches = array();
$logs = array();
while (!empty($horizont) && $n > 0)
{
if (count($horizont) > 1)
{
$out = $this->stdio->exec(array("toposort") + $horizont);
while (!empty($horizont) && $n > 0) {
if (count($horizont) > 1) {
$out = $this->stdio->exec(array('toposort') + $horizont);
$horizont = preg_split("/\n/", $out, -1, PREG_SPLIT_NO_EMPTY);
}
$certs = $this->_getCerts($rev);
// read in the initial branches we should follow
if (count($initialBranches) == 0)
{
if (count($initialBranches) == 0) {
$initialBranches = $certs['branch'];
}
// only add it to our log if it is on one of the initial branches
if (count(array_intersect($initialBranches, $certs['branch'])) > 0)
{
if (count(array_intersect($initialBranches, $certs['branch'])) > 0) {
--$n;
$log = array();
$logs[] = (object)$log;
}
$out = $this->stdio->exec(array("parents", $rev));
$out = $this->stdio->exec(array('parents', $rev));
$horizont += preg_split("/\n/", $out, -1, PREG_SPLIT_NO_EMPTY);
}
src/IDF/Scm/Monotone/Stdio.php
7070
7171
7272
73
73
7474
7575
7676
7777
7878
79
80
79
8180
8281
8382
8483
8584
86
87
85
8886
8987
9088
9189
9290
9391
94
95
92
9693
9794
9895
......
10198
10299
103100
104
105
106
101
102
103
107104
108105
109
106
110107
111108
112109
113110
114
115
116
111
112
117113
118114
119115
......
154150
155151
156152
157
158
153
159154
160
155
161156
162157
163158
164
165
159
166160
167161
168162
......
179173
180174
181175
182
183
176
184177
185178
186179
......
191184
192185
193186
194
195
187
188
196189
197190
198191
......
208201
209202
210203
211
212
213
214
215
216
204
205
206
207
217208
218209
219210
220
221
222
223
211
212
213
224214
225215
226
216
227217
228218
229
230
231
232
219
220
221
233222
234223
235224
236
237
225
238226
239227
240228
......
250238
251239
252240
253
254
241
255242
256243
257
244
258245
259246
260247
......
273260
274261
275262
276
277
263
278264
279265
280266
281267
282268
283
284
269
285270
286
287
271
288272
289273
290274
291275
292276
293277
294
295
278
296279
297280
298281
......
307290
308291
309292
310
311
293
312294
313
314
295
296
315297
316298
317299
318300
319301
320
321
302
322303
323304
324305
325306
326
327
307
328308
329309
330310
......
340320
341321
342322
343
344
323
345324
346325
347
326
348327
349328
350329
if (is_resource($this->proc))
$this->stop();
$remote_db_access = Pluf::f('mtn_db_access', 'remote') == "remote";
$remote_db_access = Pluf::f('mtn_db_access', 'remote') == 'remote';
$cmd = Pluf::f('idf_exec_cmd_prefix', '') .
Pluf::f('mtn_path', 'mtn') . ' ';
$opts = Pluf::f('mtn_opts', array());
foreach ($opts as $opt)
{
foreach ($opts as $opt) {
$cmd .= sprintf('%s ', escapeshellarg($opt));
}
// FIXME: we might want to add an option for anonymous / no key
// access, but upstream bug #30237 prevents that for now
if ($remote_db_access)
{
if ($remote_db_access) {
$host = sprintf(Pluf::f('mtn_remote_url'), $this->project->shortname);
$cmd .= sprintf('automate remote_stdio %s', escapeshellarg($host));
}
else
{
$repo = sprintf(Pluf::f('mtn_repositories'), $this->project->shortname);
if (!file_exists($repo))
{
if (!file_exists($repo)) {
throw new IDF_Scm_Exception(
"repository file '$repo' does not exist"
);
}
$descriptors = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$env = array("LANG" => "en_US.UTF-8");
$env = array('LANG' => 'en_US.UTF-8');
$this->proc = proc_open($cmd, $descriptors, $this->pipes,
null, $env);
if (!is_resource($this->proc))
{
throw new IDF_Scm_Exception("could not start stdio process");
if (!is_resource($this->proc)) {
throw new IDF_Scm_Exception('could not start stdio process');
}
$this->_checkVersion();
$read, $write = null, $except = null, 0, 20000
);
if ($streamsChanged === false)
{
if ($streamsChanged === false) {
throw new IDF_Scm_Exception(
"Could not select() on read pipe"
'Could not select() on read pipe'
);
}
if ($streamsChanged == 0)
{
if ($streamsChanged == 0) {
return false;
}
$this->_waitForReadyRead();
$version = fgets($this->pipes[1]);
if ($version === false)
{
if ($version === false) {
throw new IDF_Scm_Exception(
"Could not determine stdio version, stderr is:\n".
$this->_readStderr()
$m[1] != self::$SUPPORTED_STDIO_VERSION)
{
throw new IDF_Scm_Exception(
"stdio format version mismatch, expected '".
self::$SUPPORTED_STDIO_VERSION."', got '".@$m[1]."'"
'stdio format version mismatch, expected "'.
self::$SUPPORTED_STDIO_VERSION.'", got "'.@$m[1].'"'
);
}
*/
private function _write(array $args, array $options = array())
{
$cmd = "";
if (count($options) > 0)
{
$cmd = "o";
foreach ($options as $k => $vals)
{
$cmd = '';
if (count($options) > 0) {
$cmd = 'o';
foreach ($options as $k => $vals) {
if (!is_array($vals))
$vals = array($vals);
foreach ($vals as $v)
{
$cmd .= strlen((string)$k) . ":" . (string)$k;
$cmd .= strlen((string)$v) . ":" . (string)$v;
foreach ($vals as $v) {
$cmd .= strlen((string)$k) . ':' . (string)$k;
$cmd .= strlen((string)$v) . ':' . (string)$v;
}
}
$cmd .= "e ";
$cmd .= 'e ';
}
$cmd .= "l";
foreach ($args as $arg)
{
$cmd .= strlen((string)$arg) . ":" . (string)$arg;
$cmd .= 'l';
foreach ($args as $arg) {
$cmd .= strlen((string)$arg) . ':' . (string)$arg;
}
$cmd .= "e\n";
if (!fwrite($this->pipes[0], $cmd))
{
if (!fwrite($this->pipes[0], $cmd)) {
throw new IDF_Scm_Exception("could not write '$cmd' to process");
}
private function _readStderr()
{
$err = "";
while (($line = fgets($this->pipes[2])) !== false)
{
while (($line = fgets($this->pipes[2])) !== false) {
$err .= $line;
}
return empty($err) ? "<empty>" : $err;
return empty($err) ? '<empty>' : $err;
}
/**
$output = "";
$errcode = 0;
while (true)
{
while (true) {
if (!$this->_waitForReadyRead())
continue;
$data = array(0,"",0);
$idx = 0;
while (true)
{
while (true) {
$c = fgetc($this->pipes[1]);
if ($c === false)
{
if ($c === false) {
throw new IDF_Scm_Exception(
"No data on stdin, stderr is:\n".
$this->_readStderr()
);
}
if ($c == ':')
{
if ($c == ':') {
if ($idx == 2)
break;
}
// sanity
if ($this->cmdnum != $data[0])
{
if ($this->cmdnum != $data[0]) {
throw new IDF_Scm_Exception(
"command numbers out of sync; ".
"expected {$this->cmdnum}, got {$data[0]}"
'command numbers out of sync; expected '.
$this->cmdnum .', got '. $data[0]
);
}
$toRead = $data[2];
$buffer = "";
while ($toRead > 0)
{
while ($toRead > 0) {
$buffer .= fread($this->pipes[1], $toRead);
$toRead = $data[2] - strlen($buffer);
}
switch ($data[1])
{
switch ($data[1]) {
case 'w':
case 'p':
case 't':
}
}
if ($errcode != 0)
{
if ($errcode != 0) {
throw new IDF_Scm_Exception(
"command '{$this->lastcmd}' returned error code $errcode: ".
implode(" ", $this->oob['e'])
implode(' ', $this->oob['e'])
);
}
src/IDF/Scm/Monotone/Usher.php
4242
4343
4444
45
46
45
46
4747
4848
49
49
5050
5151
5252
......
6767
6868
6969
70
71
70
71
7272
7373
74
74
7575
76
77
78
76
77
7978
80
81
82
79
80
81
8382
8483
8584
......
9695
9796
9897
99
98
10099
101100
102101
......
110109
111110
112111
113
114
112
113
115114
116
117
115
116
118117
119118
120119
......
143142
144143
145144
146
145
147146
148147
149148
......
156155
157156
158157
159
158
160159
161160
162161
......
166165
167166
168167
169
168
170169
171170
172171
......
176175
177176
178177
179
178
180179
181180
182181
......
186185
187186
188187
189
188
190189
191190
192191
193192
194193
195
196
197
194
195
198196
199197
200198
201199
202
200
203201
204202
205
206
207
203
204
208205
209206
210
211
212
207
208
213209
214210
215211
216
217
212
218213
219214
220215
221216
222217
223
224
225
218
219
226220
227
228
221
222
229223
230224
231225
232
233
234
235
226
227
228
236229
237230
238231
239232
240233
241
242
234
243235
244236
245237
*/
public static function getServerList($state = null)
{
$conn = self::_triggerCommand("LIST $state");
if ($conn == "none")
$conn = self::_triggerCommand('LIST '.$state);
if ($conn == 'none')
return array();
return preg_split("/[ ]/", $conn);
return preg_split('/[ ]/', $conn);
}
/**
*/
public static function getConnectionList($server = null)
{
$conn = self::_triggerCommand("LISTCONNECTIONS $server");
if ($conn == "none")
$conn = self::_triggerCommand('LISTCONNECTIONS '.$server);
if ($conn == 'none')
return array();
$single_conns = preg_split("/[ ]/", $conn);
$single_conns = preg_split('/[ ]/', $conn);
$ret = array();
foreach ($single_conns as $conn)
{
preg_match("/\(\w+\)([^:]):(\d+)/", $conn, $matches);
foreach ($single_conns as $conn) {
preg_match('/\(\w+\)([^:]):(\d+)/', $conn, $matches);
$ret[$matches[1]][] = (object)array(
"server" => $matches[1],
"address" => $matches[2],
"port" => $matches[3],
'server' => $matches[1],
'address' => $matches[2],
'port' => $matches[3],
);
}
*/
public static function getStatus($server = null)
{
return self::_triggerCommand("STATUS $server");
return self::_triggerCommand('STATUS '.$server);
}
/**
*/
public static function matchServer($host, $pattern)
{
$ret = self::_triggerCommand("MATCH $host $pattern");
if (preg_match("/^OK: (.+)/", $ret, $m))
$ret = self::_triggerCommand('MATCH '.$host.' '.$pattern);
if (preg_match('/^OK: (.+)/', $ret, $m))
return $m[1];
preg_match("/^ERROR: (.+)/", $ret, $m);
throw new IDF_Scm_Exception("could not match server: ".$m[1]);
preg_match('/^ERROR: (.+)/', $ret, $m);
throw new IDF_Scm_Exception('could not match server: '.$m[1]);
}
/**
*/
public static function startServer($server)
{
return self::_triggerCommand("START $server");
return self::_triggerCommand('START '.$server);
}
/**
*/
public static function killServer($server)
{
return self::_triggerCommand("KILL_NOW $server") == "ok";
return self::_triggerCommand('KILL_NOW '.$server) == 'ok';
}
/**
*/
public static function shutDown()
{
return self::_triggerCommand("SHUTDOWN") == "ok";
return self::_triggerCommand('SHUTDOWN') == 'ok';
}
/**
*/
public static function startUp()
{
return self::_triggerCommand("STARTUP") == "ok";
return self::_triggerCommand('STARTUP') == 'ok';
}
/**
*/
public static function reload()
{
return self::_triggerCommand("RELOAD") == "ok";
return self::_triggerCommand('RELOAD') == 'ok';
}
private static function _triggerCommand($cmd)
{
$uc = Pluf::f('mtn_usher');
if (empty($uc['host']))
{
throw new IDF_Scm_Exception("usher host is empty");
if (empty($uc['host'])) {
throw new IDF_Scm_Exception('usher host is empty');
}
if (!preg_match('/^\d+$/', $uc['port']) ||
$uc['port'] == 0)
{
throw new IDF_Scm_Exception("usher port is invalid");
throw new IDF_Scm_Exception('usher port is invalid');
}
if (empty($uc['user']))
{
throw new IDF_Scm_Exception("usher user is empty");
if (empty($uc['user'])) {
throw new IDF_Scm_Exception('usher user is empty');
}
if (empty($uc['pass']))
{
throw new IDF_Scm_Exception("usher pass is empty");
if (empty($uc['pass'])) {
throw new IDF_Scm_Exception('usher pass is empty');
}
$sock = @fsockopen($uc['host'], $uc['port'], $errno, $errstr);
if (!$sock)
{
if (!$sock) {
throw new IDF_Scm_Exception(
"could not connect to usher: $errstr ($errno)"
);
}
fwrite($sock, "USERPASS {$uc['user']} {$uc['pass']}\n");
if (feof($sock))
{
fwrite($sock, 'USERPASS '.$uc['user'].' '.$uc['pass'].'\n');
if (feof($sock)) {
throw new IDF_Scm_Exception(
"usher closed the connection - probably wrong admin ".
"username or password"
'usher closed the connection - probably wrong admin '.
'username or password'
);
}
fwrite($sock, "$cmd\n");
$out = "";
while (!feof($sock))
{
fwrite($sock, $cmd.'\n');
$out = '';
while (!feof($sock)) {
$out .= fgets($sock);
}
fclose($sock);
$out = rtrim($out);
if ($out == "unknown command")
{
if ($out == 'unknown command') {
throw new IDF_Scm_Exception("unknown command: $cmd");
}
src/IDF/Tests/TestMonotone.php
5555
5656
5757
58
59
58
6059
6160
6261
63
64
62
6563
6664
6765
......
7068
7169
7270
73
74
71
7572
7673
7774
......
10299
103100
104101
105
106
107
108
109
110
102
103
104
111105
112106
113107
......
123117
124118
125119
126
127
120
128121
129122
130123
$pipes,
$dir);
if (!is_resource($process))
{
if (!is_resource($process)) {
throw new Exception("could not create process");
}
if (!empty($stdin))
{
if (!empty($stdin)) {
fwrite($pipes[0], $stdin);
fclose($pipes[0]);
}
fclose($pipes[1]);
$ret = proc_close($process);
if ($ret != 0)
{
if ($ret != 0) {
throw new Exception(
"call ended with a non-zero error code (complete cmdline was: ".
implode(" ", $cmdline).")"
if (is_dir($dirname))
$dir_handle=opendir($dirname);
while ($file = readdir($dir_handle))
{
if ($file!="." && $file!="..")
{
if (!is_dir($dirname."/".$file))
{
while ($file = readdir($dir_handle)) {
if ($file!="." && $file!="..") {
if (!is_dir($dirname."/".$file)) {
unlink ($dirname."/".$file);
continue;
}
public function setUp()
{
if (is_dir($this->tmpdir))
{
if (is_dir($this->tmpdir)) {
self::deleteRecursive($this->tmpdir);
}
src/IDF/Views/Admin.php
324324
325325
326326
327
328
327
329328
330329
331330
......
352351
353352
354353
355
356
357
358
354
355
359356
360357
361358
362359
363
364
360
365361
366362
367363
368
369
364
370365
371366
372367
......
399394
400395
401396
402
403
397
404398
405399
406400
407401
408
409
402
410403
411404
412405
413406
414
415
407
416408
417409
418410
419
420
411
421412
422413
423414
......
440431
441432
442433
443
444
434
445435
446436
447437
448438
449439
450440
451
452
441
453442
454443
455444
{
$title = __('Usher management');
$servers = array();
foreach (IDF_Scm_Monotone_Usher::getServerList() as $server)
{
foreach (IDF_Scm_Monotone_Usher::getServerList() as $server) {
$servers[] = (object)array(
"name" => $server,
"status" => IDF_Scm_Monotone_Usher::getStatus($server),
$title = __('Usher control');
$action = $match[1];
if (!empty($action))
{
if (!in_array($action, array("reload", "shutdown", "startup")))
{
if (!empty($action)) {
if (!in_array($action, array('reload', 'shutdown', 'startup'))) {
throw new Pluf_HTTP_Error404();
}
$msg = null;
if ($action == "reload")
{
if ($action == 'reload') {
IDF_Scm_Monotone_Usher::reload();
$msg = __('Usher configuration has been reloaded');
}
else if ($action == "shutdown")
{
else if ($action == 'shutdown') {
IDF_Scm_Monotone_Usher::shutDown();
$msg = __('Usher has been shut down');
}
public function usherServerControl($request, $match)
{
$server = $match[1];
if (!in_array($server, IDF_Scm_Monotone_Usher::getServerList()))
{
if (!in_array($server, IDF_Scm_Monotone_Usher::getServerList())) {
throw new Pluf_HTTP_Error404();
}
$action = $match[2];
if (!in_array($action, array("start", "stop", "kill")))
{
if (!in_array($action, array('start', 'stop', 'kill'))) {
throw new Pluf_HTTP_Error404();
}
$msg = null;
if ($action == "start")
{
if ($action == 'start') {
IDF_Scm_Monotone_Usher::startServer($server);
$msg = sprintf(__('The server "%s" has been started'), $server);
}
else if ($action == "stop")
{
else if ($action == 'stop') {
IDF_Scm_Monotone_Usher::stopServer($server);
$msg = sprintf(__('The server "%s" has been stopped'), $server);
}
public function usherServerConnections($request, $match)
{
$server = $match[1];
if (!in_array($server, IDF_Scm_Monotone_Usher::getServerList()))
{
if (!in_array($server, IDF_Scm_Monotone_Usher::getServerList())) {
throw new Pluf_HTTP_Error404();
}
$title = sprintf(__('Open connections for "%s"'), $server);
$connections = IDF_Scm_Monotone_Usher::getConnectionList($server);
if (count($connections) == 0)
{
if (count($connections) == 0) {
$request->user->setMessage(sprintf(
__('no connections for server "%s"'), $server
));

Archive Download the corresponding diff file

Page rendered in 0.13476s using 13 queries.