File indexing completed on 2024-12-22 05:33:15
0001 <?php 0002 /* 0003 * on this file gfx inclusion is useless as gfx is already running 0004 */ 0005 0006 class StatusController extends EController 0007 { 0008 0009 private $example_contentid; 0010 0011 public function logout() 0012 { 0013 EProtect::logout(); 0014 } 0015 0016 public function index($args) 0017 { 0018 EStructure::view("header"); 0019 0020 if(!isset($args[0])){ 0021 echo '<h3>OCS Actions</h3>'; 0022 echo '<p>If you put your server in production or experience malfunctionings, you better regenerate providers.xml!<br> 0023 <a href="/admin/steps/step2">CONFIGURE OCS SERVER</a></p>'; 0024 echo '<p>Change password for accessing admin panel.<br> 0025 <a href="/admin/steps/step3">CHANGE PASSWORD</a></p>'; 0026 0027 } 0028 0029 EStructure::view("footer"); 0030 } 0031 0032 public function database($args) 0033 { 0034 EStructure::view("header"); 0035 0036 if(!isset($args[0])){ 0037 echo '<h3>Database</h3>'; 0038 echo '<p>If you just copied your ocs-server files to an other server, you would like to reconfigure database.<br> 0039 <a href="/admin/steps/step1">CONFIGURE DATABASE</a></p>'; 0040 echo '<p>If you have a broken/unconsistent database running, you can attempt resetting your database.<br> 0041 <a href="/admin/status/database/reset">RESET DATABASE</a></p>'; 0042 echo '<p>If you want to run sanity tests on your database you should install default data.<br> 0043 This is not reccomended on production and generally useful only for developers.<br> 0044 <a href="/admin/status/database/testdata">INSTALL TEST DATA</a></p>'; 0045 0046 } 0047 0048 if(isset($args[0])){ 0049 echo '<hr>'; 0050 if($args[0]=='reset'){ 0051 echo '<h3>Database</h3>'; 0052 echo 'Resetting...Done!<br>'; 0053 echo 'Are you willing to execute tests? You better <a href="/admin/status/database/testdata">install default data</a>'; 0054 echo '<br><a href="/admin/status/database">Back to database panel</a>'; 0055 0056 //using ocstest external library in /admin/libs 0057 OCSTest::reset_ocs_database(); 0058 0059 } else if($args[0]=='testdata'){ 0060 echo '<p>adding test/password user..........'; 0061 $postdata = array( 0062 "login" => "test", 0063 "password" => "password", 0064 "email" => "bababa@bebebe.bu", 0065 "firstname" => "cavolf", 0066 "lastname" => "chiappe" 0067 ); 0068 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0069 $check = $client->post("v1/person/add",$postdata); 0070 $this->_statuscode_test($check, $client); 0071 echo '<a href="/admin/status/database">Back to database panel</a>'; 0072 } 0073 } 0074 0075 EStructure::view("footer"); 0076 } 0077 0078 public function categories($args) 0079 { 0080 EStructure::view("header"); 0081 0082 $categories_path = ELoader::$prev_path.'/config/ocs_categories.conf.php'; 0083 0084 $cf = new EConfigFile(); 0085 $cf->set_abs_file($categories_path); 0086 //$cf->del('4'); 0087 //$cf->save(); 0088 0089 if(isset($args[0])){ 0090 $key = EHeaderDataParser::get('key'); 0091 $value = EHeaderDataParser::get('value'); 0092 0093 if(!empty($key)){ 0094 if($args[0]=='mod'){ 0095 $cf->set($key,$value); 0096 $cf->save(); 0097 header("location: /admin/status/categories"); 0098 } 0099 if($args[0]=='del'){ 0100 $cf->del($key); 0101 $cf->save(); 0102 header("location: /admin/status/categories"); 0103 } 0104 } 0105 } 0106 0107 echo '<h3>Categories</h3>'; 0108 echo '<p>Current OCS categories on server:</p>'; 0109 0110 $data = $cf->get_data(); 0111 0112 echo "<ul>"; 0113 foreach($data as $key => $value){ 0114 echo "<li>$key | $value</li>"; 0115 } 0116 echo "</ul>"; 0117 0118 echo ' <form action="/admin/status/categories/mod" method="get"> 0119 <input type="text" name="key" placeholder="key"><input type="text" name="value" placeholder="value"> 0120 <input type="submit" value="modify/add category"></form> '; 0121 0122 echo ' <form action="/admin/status/categories/del" method="get"> 0123 <input type="text" name="key" placeholder="key"> 0124 <input type="submit" value="delete category"></form> '; 0125 0126 EStructure::view("footer"); 0127 } 0128 0129 private function _statuscode_test($data, $client) 0130 { 0131 ob_start(); 0132 var_dump($data); 0133 $a=ob_get_contents(); 0134 ob_end_clean(); 0135 if(isset($data["ocs"]["meta"]["statuscode"])){ 0136 echo '<span style="color:green">ok!</span>(statuscode:'.$data["ocs"]["meta"]["statuscode"].')'; 0137 echo '<a onclick="alert(\''; 0138 echo str_replace("lkjjjnnh", "\\n", addslashes(htmlspecialchars(str_replace("\n", "lkjjjnnh", $a)))); 0139 echo '\')">[show full response]</a></p>'; 0140 } else { 0141 echo '<span style="color:red">failed!</span></p>'; 0142 ELog::pd($client->get_last_raw_result()); 0143 } 0144 } 0145 0146 public function test() 0147 { 0148 $total_time = 0; 0149 0150 EStructure::view("header"); 0151 0152 ETime::measure_from(); 0153 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0154 0155 echo '<h3>Sanity OCS test</h3>'; 0156 0157 echo '<p>config..........'; 0158 $check = $client->get("v1/config"); 0159 $this->_statuscode_test($check, $client); 0160 $time = ETime::measure_to(); $total_time += $time; 0161 echo "( $time )"; 0162 0163 ETime::measure_from(); 0164 echo '<p>person/check..........'; 0165 $postdata = array( "login" => "test", "password" => "password" ); 0166 $check = $client->post("v1/person/check",$postdata); 0167 $this->_statuscode_test($check, $client); 0168 $time = ETime::measure_to(); $total_time += $time; 0169 echo "( $time )"; 0170 0171 ETime::measure_from(); 0172 echo '<p>person/add..........'; 0173 $postdata = array( 0174 "login" => "cavolfiore", 0175 "password" => "cavolfiore", 0176 "email" => "bababa@bebebe.bu", 0177 "firstname" => "cavolf", 0178 "lastname" => "chiappe" 0179 ); 0180 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0181 $check = $client->post("v1/person/add",$postdata); 0182 $this->_statuscode_test($check, $client); 0183 $time = ETime::measure_to(); $total_time += $time; 0184 echo "( $time )"; 0185 0186 ETime::measure_from(); 0187 echo '<p>person/data..........'; 0188 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0189 $client->set_auth_info("test","password"); 0190 $check = $client->get("v1/person/data"); 0191 $this->_statuscode_test($check, $client); 0192 $time = ETime::measure_to(); $total_time += $time; 0193 echo "( $time )"; 0194 0195 ETime::measure_from(); 0196 echo '<p>person/data?name=cavol&page=1&pagesize=10..........'; 0197 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0198 $client->set_auth_info("test","password"); 0199 $check = $client->get("v1/person/data?name=cavol&page=1&pagesize=10"); 0200 $this->_statuscode_test($check, $client); 0201 $time = ETime::measure_to(); $total_time += $time; 0202 echo "( $time )"; 0203 0204 ETime::measure_from(); 0205 echo '<p>person/data/[login]..........'; 0206 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0207 $client->set_auth_info("test","password"); 0208 $check = $client->get("v1/person/data/cavolfiore"); 0209 $this->_statuscode_test($check, $client); 0210 $time = ETime::measure_to(); $total_time += $time; 0211 echo "( $time )"; 0212 0213 ETime::measure_from(); 0214 echo '<p>person/self..........'; 0215 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0216 $client->set_auth_info("test","password"); 0217 $check = $client->get("v1/person/self"); 0218 $this->_statuscode_test($check, $client); 0219 $time = ETime::measure_to(); $total_time += $time; 0220 echo "( $time )"; 0221 0222 ETime::measure_from(); 0223 echo '<p>content/add..........'; 0224 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0225 $postdata = array( 0226 "name" => "esempio", 0227 "type" => "0", 0228 "downloadname1" => "downloadname1", 0229 "downloadlink1" => "downloadlink1", 0230 "description" => "description", 0231 "summary" => "summary", 0232 "version" => "version", 0233 "changelog" => "changelog", 0234 "personid" => "test" 0235 ); 0236 $client->set_auth_info("test","password"); 0237 $check = $client->post("v1/content/add",$postdata); 0238 $contentid = $this->example_contentid = $check['ocs']['data']['content'][0]['id']; 0239 $this->_statuscode_test($check, $client); 0240 $time = ETime::measure_to(); $total_time += $time; 0241 echo "( $time )"; 0242 0243 ETime::measure_from(); 0244 echo '<p>content/categories..........'; 0245 $check = $client->get("v1/content/categories"); 0246 $this->_statuscode_test($check, $client); 0247 $time = ETime::measure_to(); $total_time += $time; 0248 echo "( $time )"; 0249 0250 ETime::measure_from(); 0251 echo '<p>content/licenses..........'; 0252 $check = $client->get("v1/content/licenses"); 0253 $this->_statuscode_test($check, $client); 0254 $time = ETime::measure_to(); $total_time += $time; 0255 echo "( $time )"; 0256 0257 ETime::measure_from(); 0258 echo '<p>content/data..........'; 0259 $check = $client->get("v1/content/data"); 0260 $this->_statuscode_test($check, $client); 0261 $time = ETime::measure_to(); $total_time += $time; 0262 echo "( $time )"; 0263 0264 ETime::measure_from(); 0265 echo '<p>content/data?search=esem..........'; 0266 $check = $client->get("v1/content/data?search=esem"); 0267 $this->_statuscode_test($check, $client); 0268 $time = ETime::measure_to(); $total_time += $time; 0269 echo "( $time )"; 0270 0271 ETime::measure_from(); 0272 echo '<p>content/data/[contentid]..........'; 0273 $check = $client->get("v1/content/data/$contentid"); 0274 $this->_statuscode_test($check, $client); 0275 $time = ETime::measure_to(); $total_time += $time; 0276 echo "( $time )"; 0277 0278 ETime::measure_from(); 0279 echo '<p>content/download/[contentid]/1..........'; 0280 $check = $client->get("v1/content/download/$contentid/1"); 0281 $this->_statuscode_test($check, $client); 0282 $time = ETime::measure_to(); $total_time += $time; 0283 echo "( $time )"; 0284 0285 ETime::measure_from(); 0286 echo '<p>content/vote/[contentid]..........'; 0287 $id = intval($contentid); 0288 $rate = floatval(1); 0289 0290 $postdata = array( 0291 "vote" => $rate 0292 ); 0293 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0294 $client->set_auth_info("test","password"); 0295 $client->set_post_data($postdata); 0296 $check = $client->post("v1/content/vote/$id"); 0297 $this->_statuscode_test($check, $client); 0298 $time = ETime::measure_to(); $total_time += $time; 0299 echo "( $time )"; 0300 0301 ETime::measure_from(); 0302 echo '<p>content/edit/[contentid]..........'; 0303 $postdata = array( 0304 "name" => "esempiomod", 0305 "summary" => "summarymod", 0306 "downloadname1" => "downloadname1mod", 0307 "downloadlink1" => "downloadlink1mod", 0308 "description" => "descriptionmod", 0309 "version" => "versionmod", 0310 "changelog" => "changelogmod" 0311 ); 0312 0313 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0314 $client->set_auth_info("test","password"); 0315 $client->set_post_data($postdata); 0316 $check = $client->post("v1/content/edit/$id"); 0317 $this->_statuscode_test($check, $client); 0318 $time = ETime::measure_to(); $total_time += $time; 0319 echo "( $time )"; 0320 0321 ETime::measure_from(); 0322 echo '<p>[get] activity..........'; 0323 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0324 $client->set_auth_info("test","password"); 0325 $check = $client->get("v1/activity"); 0326 $this->_statuscode_test($check, $client); 0327 $time = ETime::measure_to(); $total_time += $time; 0328 echo "( $time )"; 0329 0330 ETime::measure_from(); 0331 echo '<p>[post] activity..........'; 0332 $postdata = array( 0333 "message" => "coding is fun" 0334 ); 0335 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0336 $client->set_auth_info("test","password"); 0337 $client->set_post_data($postdata); 0338 $check = $client->post("v1/activity"); 0339 $this->_statuscode_test($check, $client); 0340 $time = ETime::measure_to(); $total_time += $time; 0341 echo "( $time )"; 0342 0343 ETime::measure_from(); 0344 echo '<p>fan/add..........'; 0345 $postdata = array("idcontent"=>$contentid); 0346 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0347 $client->set_auth_info("test","password"); 0348 $client->set_post_data($postdata); 0349 $check = $client->post("v1/fan/add/$id"); 0350 $this->_statuscode_test($check, $client); 0351 $time = ETime::measure_to(); $total_time += $time; 0352 echo "( $time )"; 0353 0354 ETime::measure_from(); 0355 echo '<p>fan/data/[contentid]..........'; 0356 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0357 $client->set_auth_info("test","password"); 0358 $check = $client->get("v1/fan/data/$id"); 0359 $this->_statuscode_test($check, $client); 0360 $time = ETime::measure_to(); $total_time += $time; 0361 echo "( $time )"; 0362 0363 echo '<p>fan/status/[contentid]..........'; 0364 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0365 $client->set_auth_info("test","password"); 0366 $check = $client->get("v1/fan/status/$id"); 0367 $this->_statuscode_test($check, $client); 0368 $time = ETime::measure_to(); $total_time += $time; 0369 echo "( $time )"; 0370 0371 echo '<p>fan/remove..........'; 0372 $postdata = array("idcontent"=>$contentid); 0373 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0374 $client->set_auth_info("test","password"); 0375 $client->set_post_data($postdata); 0376 $check = $client->post("v1/fan/remove/$id"); 0377 $this->_statuscode_test($check, $client); 0378 $time = ETime::measure_to(); $total_time += $time; 0379 echo "( $time )"; 0380 0381 echo '<p>comments/add..........'; 0382 $postdata = array( 0383 "type" => "1", 0384 "content" => $id, 0385 "content2" => "1", 0386 "parent" => "0", 0387 "subject" => "subject", 0388 "message" => "message" 0389 ); 0390 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0391 $client->set_auth_info("test","password"); 0392 $client->set_post_data($postdata); 0393 $check = $client->post("v1/comments/add"); 0394 $this->_statuscode_test($check, $client); 0395 $time = ETime::measure_to(); $total_time += $time; 0396 echo "( $time )"; 0397 0398 echo '<p>comments/data/[type]/[contentid1]/[contentid2]..........'; 0399 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0400 //$client->set_auth_info("test","password"); 0401 $check = $client->get("v1/comments/data/1/$id/1&page=1&pagesize=10"); 0402 $this->_statuscode_test($check, $client); 0403 $time = ETime::measure_to(); $total_time += $time; 0404 echo "( $time )"; 0405 0406 //deleting content used for tests 0407 0408 echo '<p>content/delete/[contentid]..........'; 0409 $postdata = array( 0410 "contentid" => $id 0411 ); 0412 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0413 $client->set_auth_info("test","password"); 0414 $client->set_post_data($postdata); 0415 $check = $client->post("v1/content/delete/$id"); 0416 $this->_statuscode_test($check, $client); 0417 $time = ETime::measure_to(); $total_time += $time; 0418 echo "( $time )"; 0419 0420 /* 0421 * TODO: add to OCS specs more returncodes than just 100 0422 */ 0423 echo '<p>friend/data/[personid]..........'; 0424 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0425 $client->set_auth_info("test","password"); 0426 $check = $client->get("v1/friend/data/cavolfiore"); 0427 $this->_statuscode_test($check, $client); 0428 $time = ETime::measure_to(); $total_time += $time; 0429 echo "( $time )"; 0430 0431 /* 0432 * TODO: add to OCS specs more returncodes than just 100 0433 */ 0434 echo '<p>friend/receivedinvitations..........'; 0435 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0436 $client->set_auth_info("test","password"); 0437 $check = $client->get("v1/friend/receivedinvitations"); 0438 $this->_statuscode_test($check, $client); 0439 $time = ETime::measure_to(); $total_time += $time; 0440 echo "( $time )"; 0441 0442 /* 0443 * TODO: add to OCS specs more returncodes than just 100 0444 */ 0445 echo '<p>friend/invite/[personid]..........'; 0446 $postdata = array( 0447 "message" => "would you be my friend?" 0448 ); 0449 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0450 $client->set_auth_info("test","password"); 0451 $client->set_post_data($postdata); 0452 $check = $client->post("v1/friend/invite/cavolfiore "); 0453 $this->_statuscode_test($check, $client); 0454 $time = ETime::measure_to(); $total_time += $time; 0455 echo "( $time )"; 0456 0457 echo '<p>friend/approve/[personid]..........'; 0458 $postdata = array( 0459 "message" => "would you be my friend?" 0460 ); 0461 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0462 $client->set_auth_info("cavolfiore","cavolfiore"); 0463 $client->set_post_data($postdata); 0464 $check = $client->post("v1/friend/approve/test"); 0465 $this->_statuscode_test($check, $client); 0466 $time = ETime::measure_to(); $total_time += $time; 0467 echo "( $time )"; 0468 0469 echo '<p>friend/decline/[personid]..........'; 0470 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0471 $client->set_auth_info("cavolfiore","cavolfiore"); 0472 $check = $client->post("v1/friend/decline/test"); 0473 $this->_statuscode_test($check, $client); 0474 $time = ETime::measure_to(); $total_time += $time; 0475 echo "( $time )"; 0476 0477 echo '<p>friend/cancel/[personid]..........'; 0478 $client = new OCSClient(EConfig::$data["ocs"]["host"]); 0479 $client->set_auth_info("cavolfiore","cavolfiore"); 0480 $check = $client->post("v1/friend/cancel/test"); 0481 $this->_statuscode_test($check, $client); 0482 $time = ETime::measure_to(); $total_time += $time; 0483 echo "( $time )<br>"; 0484 0485 echo "This OCS test took: $total_time"; 0486 0487 EStructure::view("footer"); 0488 } 0489 0490 } 0491 0492 ?>