1: | <?php |
2: | declare(strict_types=1); |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | class Demo_Module extends Module_Skeleton |
21: | { |
22: | protected $exportedFunctions = |
23: | array('*' => PRIVILEGE_ALL,); |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | public function test_tail($cnt = 20, $timing = 0.5) |
34: | { |
35: | if (!is_debug()) { |
36: | return error('test_tail may not be used in production'); |
37: | } |
38: | if (!IS_CLI) { |
39: | return $this->query('demo_test_tail', $cnt, $timing); |
40: | } |
41: | $tail = Util_Process_Tee::watch(new Util_Process); |
42: | $script = 'echo ' . date('r') . '; for (( C=' . $cnt . '0; C > 0; C-- )) ; do echo $C; usleep ' . ($timing * 100000) . '; done'; |
43: | $tail->exec($script); |
44: | $script = 'echo ' . date('r') . '; for (( C=0; C < ' . $cnt . ' ; C++ )) ; do echo $C; usleep ' . ($timing * 1000000) . '; done ; echo `date`'; |
45: | $tail->exec($script); |
46: | |
47: | return true; |
48: | } |
49: | |
50: | public function test_tail2($cnt = 20, $timing = 0.5) |
51: | { |
52: | if (!is_debug()) { |
53: | return error('test_tail may not be used in production'); |
54: | } |
55: | if (!IS_CLI) { |
56: | return $this->query('demo_test_tail2', $cnt, $timing); |
57: | } |
58: | $p = new Util_Process(); |
59: | $proc = Util_Process_Tee::auto($p); |
60: | $script = 'echo ' . date('r') . '; for (( C=' . $cnt . '0; C > 0; C-- )) ; do echo $C; usleep ' . ($timing * 10000) . '; done'; |
61: | $proc->exec($script); |
62: | $script = 'echo ' . date('r') . '; for (( C=0; C < ' . $cnt . ' ; C++ )) ; do echo $C; usleep ' . ($timing * 10000) . '; done ; echo `date`'; |
63: | $proc->exec($script); |
64: | $p = null; |
65: | sleep(10); |
66: | } |
67: | |
68: | public function test_tail3() |
69: | { |
70: | if (!is_debug()) { |
71: | return error('test_tail may not be used in production'); |
72: | } |
73: | $proc = Util_Process_Tee::auto(new Util_Process()); |
74: | $proc->exec('idontexist'); |
75: | $proc->log('Testing!'); |
76: | $proc->exec('whoami'); |
77: | |
78: | return true; |
79: | } |
80: | |
81: | public function test_error($message = 'generic error') |
82: | { |
83: | return error($message); |
84: | } |
85: | |
86: | public function test1() |
87: | { |
88: | return Util_Process::exec('test.sh'); |
89: | } |
90: | |
91: | public function test_backend_error($message = 'abcdef') |
92: | { |
93: | if (!IS_CLI) { |
94: | return $this->query('demo_test_backend_error', $message); |
95: | } |
96: | |
97: | return error($message); |
98: | |
99: | } |
100: | |
101: | public function test_sudo() |
102: | { |
103: | if (!IS_CLI) { |
104: | return $this->query('demo_test_sudo'); |
105: | } |
106: | |
107: | return Util_Process_Sudo::exec('echo whoami: `whoami`'); |
108: | } |
109: | |
110: | |
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | public function test_array($arg1, $arg2 = null) |
122: | { |
123: | return array('ret1' => 80, 'ret2' => 10, 'ret3' => $arg2 + $arg1); |
124: | } |
125: | |
126: | |
127: | |
128: | |
129: | |
130: | |
131: | |
132: | |
133: | |
134: | |
135: | |
136: | |
137: | public function test_exception($trigger = false) |
138: | { |
139: | if ($trigger) { |
140: | return new SocketError('This is another test for objects'); |
141: | } else { |
142: | return true; |
143: | } |
144: | } |
145: | |
146: | |
147: | |
148: | |
149: | |
150: | |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | public function test_scalar($arg1, $arg2) |
157: | { |
158: | return $arg1 + $arg2; |
159: | } |
160: | |
161: | |
162: | |
163: | public function test_basic() |
164: | { |
165: | return 'Hello World!'; |
166: | } |
167: | |
168: | public function test_account_metadata() |
169: | { |
170: | return $this->getServiceValue('sendmail', 'mailserver'); |
171: | } |
172: | } |
173: | |
174: | ?> |
175: | |