summaryrefslogblamecommitdiffstats
path: root/application/controllers/GearmanController.php
blob: f6ce9fee9f2befd4a4d1d7499c4f0f01ab107d66 (plain) (tree)
1
2
3
4
5
6
7
8
9




                                                      

                            

                                    


                              
                                                              
                                                                      

                                                                        
                                                                                        


                                                                                                                                                                                                                     





                                                                     
         

                                     
         
 
         
 
                                        
         
                                 





























                                     



                                                  










                                                                                                   
                                                                                                                   


                                                                                           
                         
                 


                                                
                                      
                                    
                                    
                                
                                 

                                                    
                                              
                                           
                                                                                                                                   
                                                                                          


























                                                                             
                                                                               
                  


                                                  
                                                                                           





                                                             
         
 







                                                                                                                                   
                                                                                          







































                                                                                                   
 
 
<?php

class GearmanController extends Zend_Controller_Action
{
	protected $gearmanClient;
	protected $config;
	protected $pbs2host;
	protected $userIDsNamespace;
	protected $acl;

	public function init()
	{
		if (Zend_Auth::getInstance()->hasIdentity()) {
			$bootstrap = $this->getInvokeArg('bootstrap');
			$this->config = $bootstrap->getOptions();
			$this->pbs2host = $this->config['pbs2']['host'];
			$this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
			if(isset($this->userIDsNamespace['apikey'])) {
				$this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
			}
			$this->gearmanClient = new GearmanClient();
			$this->gearmanClient->addServer('127.0.0.1');
		} else {
			$this->_helper->redirector('login', 'auth');
			return;
		}
	}

	public function indexAction()
	{

	}

	public function somepingAction()
	{
		$ipArray = array(
		0 => '132.230.4.1',
		1 => '132.230.4.2',
		2 => '132.230.4.3',
		3 => '132.230.4.4',
		4 => '132.230.4.5',
		5 => '132.230.4.6',
		6 => '132.230.4.7',
		7 => '132.230.4.8',
		8 => '132.230.4.9',
		9 => '132.230.4.10',
		10 => '132.230.4.11',
		11 => '132.230.4.12',
		12 => '132.230.4.13',
		13 => '132.230.4.14',
		14 => '132.230.4.15',
		15 => '132.230.4.16',
		16 => '132.230.4.17',
		17 => '132.230.4.18',
		18 => '132.230.4.19',
		19 => '132.230.4.20',
		20 => '132.230.4.21',
		21 => '132.230.4.22',
		22 => '132.230.4.23',
		23 => '132.230.4.24',
		24 => '132.230.4.25',
		25 => '132.230.4.26',
		26 => '132.230.4.27',
		27 => '132.230.4.28',
		28 => '132.230.4.29',
		29 => '132.230.4.30',
		);

		$ipString = json_encode($ipArray);

		$result = $this->gearmanClient->do("somePing", $ipString, 'somePing');
		if (! $this->gearmanClient->runTasks())
		{
			echo "ERROR " . $gmc->error() . "\n";
			exit;
		}
		$resultsExp = explode('; ', $result);
		if(is_array($resultsExp)) {
			foreach($resultsExp as $result) {
				$resultDecode = json_decode($result);
				$resultDecode->rawoutput = sprintf('%s', $resultDecode->rawoutput);
				$resultDecode->rawoutput = str_replace("\n", "<br />\t", $resultDecode->rawoutput);
				$resultDecode->alive = sprintf('%s', $resultDecode->alive);
				$resultDecode->rc = sprintf('%s', $resultDecode->rc);
				$results[] = $resultDecode;
			}
		}
		$this->view->results = $results;
	}

	public function bootAction() {
		$eventName = 'test';
		$eventOS = 'testOS';
		$updateRate = 1;
		$clients = array(
			'eventName' => $eventName,
			'updateRate' => $updateRate,
			'eventOS' => $eventOS,
			'clients' => array(
		0 => array('id' => '1', 'ip' =>'132.230.4.24', 'mac' =>'00:13:72:C7:FD:A1'), //PC im HiWi-Raum rechts auf dem Tisch
		/*		1 => array('id' => '2', 'ip' =>'132.230.4.2', 'mac' =>''),
		2 => array('id' => '3', 'ip' =>'132.230.4.3', 'mac' =>''),
		3 => array('id' => '4', 'ip' =>'132.230.4.4', 'mac' =>''),
		4 => array('id' => '5', 'ip' =>'132.230.4.5', 'mac' =>''),
		5 => array('id' => '6', 'ip' =>'132.230.4.6', 'mac' =>''),
		6 => array('id' => '7', 'ip' =>'132.230.4.7', 'mac' =>''),
		7 => array('id' => '8', 'ip' =>'132.230.4.8', 'mac' =>''),
		8 => array('id' => '9', 'ip' =>'132.230.4.9', 'mac' =>''),
		9 => array('id' => '10', 'ip' =>'132.230.4.10', 'mac' =>''),
		10 => array('id' => '11', 'ip' =>'132.230.4.11', 'mac' =>''),
		11 => array('id' => '12', 'ip' =>'132.230.4.12', 'mac' =>''),
		12 => array('id' => '13', 'ip' =>'132.230.4.13', 'mac' =>''),
		13 => array('id' => '14', 'ip' =>'132.230.4.14', 'mac' =>''),
		14 => array('id' => '15', 'ip' =>'132.230.4.15', 'mac' =>''),
		15 => array('id' => '16', 'ip' =>'132.230.4.16', 'mac' =>''),
		16 => array('id' => '17', 'ip' =>'132.230.4.17', 'mac' =>''),
		17 => array('id' => '18', 'ip' =>'132.230.4.18', 'mac' =>''),
		18 => array('id' => '19', 'ip' =>'132.230.4.19', 'mac' =>''),
		19 => array('id' => '20', 'ip' =>'132.230.4.20', 'mac' =>''),
		20 => array('id' => '21', 'ip' =>'132.230.4.21', 'mac' =>''),
		21 => array('id' => '22', 'ip' =>'132.230.4.22', 'mac' =>''),
		22 => array('id' => '23', 'ip' =>'132.230.4.23', 'mac' =>''),
		23 => array('id' => '24', 'ip' =>'132.230.4.24', 'mac' =>''),
		24 => array('id' => '25', 'ip' =>'132.230.4.25', 'mac' =>''),
		25 => array('id' => '26', 'ip' =>'132.230.4.26', 'mac' =>''),
		26 => array('id' => '27', 'ip' =>'132.230.4.27', 'mac' =>''),
		27 => array('id' => '28', 'ip' =>'132.230.4.28', 'mac' =>''),
		28 => array('id' => '29', 'ip' =>'132.230.4.29', 'mac' =>''),
		29 => array('id' => '30', 'ip' =>'132.230.4.30', 'mac' =>''),*/
		),
		);
			
		$ipString = json_encode($clients);
		$result = $this->gearmanClient->do("boot", $ipString, 'boot' . $eventName);
		if (! $this->gearmanClient->runTasks())
		{
			echo "ERROR " . $gmc->error() . "\n";
			exit;
		}
		$this->view->result = $result;
	}

	public function shutdownAction() {
		$eventName = 'test';
		$updateRate = 1;
		$clients = array(
			'eventName' => $eventName,
			'updateRate' => $updateRate,
			'clients' => array(
		0 => array('id' => '1', 'ip' =>'132.230.4.24', 'mac' =>'00:13:72:C7:FD:A1'), //PC im HiWi-Raum rechts auf dem Tisch
		/*		1 => array('id' => '2', 'ip' =>'132.230.4.2', 'mac' =>''),
		2 => array('id' => '3', 'ip' =>'132.230.4.3', 'mac' =>''),
		3 => array('id' => '4', 'ip' =>'132.230.4.4', 'mac' =>''),
		4 => array('id' => '5', 'ip' =>'132.230.4.5', 'mac' =>''),
		5 => array('id' => '6', 'ip' =>'132.230.4.6', 'mac' =>''),
		6 => array('id' => '7', 'ip' =>'132.230.4.7', 'mac' =>''),
		7 => array('id' => '8', 'ip' =>'132.230.4.8', 'mac' =>''),
		8 => array('id' => '9', 'ip' =>'132.230.4.9', 'mac' =>''),
		9 => array('id' => '10', 'ip' =>'132.230.4.10', 'mac' =>''),
		10 => array('id' => '11', 'ip' =>'132.230.4.11', 'mac' =>''),
		11 => array('id' => '12', 'ip' =>'132.230.4.12', 'mac' =>''),
		12 => array('id' => '13', 'ip' =>'132.230.4.13', 'mac' =>''),
		13 => array('id' => '14', 'ip' =>'132.230.4.14', 'mac' =>''),
		14 => array('id' => '15', 'ip' =>'132.230.4.15', 'mac' =>''),
		15 => array('id' => '16', 'ip' =>'132.230.4.16', 'mac' =>''),
		16 => array('id' => '17', 'ip' =>'132.230.4.17', 'mac' =>''),
		17 => array('id' => '18', 'ip' =>'132.230.4.18', 'mac' =>''),
		18 => array('id' => '19', 'ip' =>'132.230.4.19', 'mac' =>''),
		19 => array('id' => '20', 'ip' =>'132.230.4.20', 'mac' =>''),
		20 => array('id' => '21', 'ip' =>'132.230.4.21', 'mac' =>''),
		21 => array('id' => '22', 'ip' =>'132.230.4.22', 'mac' =>''),
		22 => array('id' => '23', 'ip' =>'132.230.4.23', 'mac' =>''),
		23 => array('id' => '24', 'ip' =>'132.230.4.24', 'mac' =>''),
		24 => array('id' => '25', 'ip' =>'132.230.4.25', 'mac' =>''),
		25 => array('id' => '26', 'ip' =>'132.230.4.26', 'mac' =>''),
		26 => array('id' => '27', 'ip' =>'132.230.4.27', 'mac' =>''),
		27 => array('id' => '28', 'ip' =>'132.230.4.28', 'mac' =>''),
		28 => array('id' => '29', 'ip' =>'132.230.4.29', 'mac' =>''),
		29 => array('id' => '30', 'ip' =>'132.230.4.30', 'mac' =>''),*/
		),
		);
			
		$ipString = json_encode($clients);
		$result = $this->gearmanClient->do("shutdown", $ipString, 'shutdown' . $eventName);
		if (! $this->gearmanClient->runTasks())
		{
			echo "ERROR " . $gmc->error() . "\n";
			exit;
		}
		$this->view->result = $result;
	}

}