public function executeJson(sfWebRequest $request) { $etva_service = EtvaServicePeer::retrieveByPK($request->getParameter('id')); if (!$etva_service) { $msg = array('success' => false, 'error' => 'No service with specified id', 'info' => 'No service with specified id'); $result = $this->setJsonError($msg); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); } $etva_server = $etva_service->getEtvaServer(); $agent_tmpl = $etva_server->getAgentTmpl(); $service_tmpl = $etva_service->getNameTmpl(); $method = $request->getParameter('method'); $mode = $request->getParameter('mode'); $params = json_decode($request->getParameter('params'), true); if (!$params) { $params = array(); } $dispatcher_tmpl = $agent_tmpl . '_' . $service_tmpl; if (method_exists($this, $dispatcher_tmpl)) { $ret = call_user_func_array(array($this, $dispatcher_tmpl), array($etva_server, $method, $params, $mode)); if ($ret['success']) { $result = json_encode($ret); } else { $result = $this->setJsonError($ret); } } else { $info = array('success' => false, 'error' => 'No method implemented! ' . $dispatcher_tmpl); $result = $this->setJsonError($info); } // $result = json_encode($ret); $this->getResponse()->setHttpHeader('Content-type', 'application/json; charset=utf-8'); $this->getResponse()->setHttpHeader("X-JSON", '()'); return $this->renderText($result); }
public function executeJsonGetServer(sfWebRequest $request) { $etva_service = EtvaServicePeer::retrieveByPK($request->getParameter('id')); if (!$etva_service) { $msg = array('success' => false, 'error' => 'No service with specified id', 'info' => 'No service with specified id'); $result = $this->setJsonError($msg); return $this->renderText($result); } $etva_server = $etva_service->getEtvaServer(); $server_array = $etva_server->toArray(BasePeer::TYPE_FIELDNAME); $result = array('success' => true, 'data' => $server_array); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); $return = json_encode($result); return $this->renderText($return); }
public function executeJsonNoWait(sfWebRequest $request) { $service_id = $request->getParameter('id'); $etva_service = EtvaServicePeer::retrieveByPK($request->getParameter('id')); if (!$etva_service) { $msg_i18n = $this->getContext()->getI18N()->__('No service with specified id', array()); $msg = array('success' => false, 'error' => $msg_i18n, 'info' => $msg_i18n); $result = $this->setJsonError($msg); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); } $etva_server = $etva_service->getEtvaServer(); $method = $request->getParameter('method'); $params = json_decode($request->getParameter('params'), true); if (!$params) { $params = array(); } $etva_server->setSoapTimeout(5); // send soap request $response = $etva_server->soapSend($method, $params); if (!$response['success'] && $response['faultactor'] != 'socket_read') { $result = json_decode($response); } else { $msg_i18n = $this->getContext()->getI18N()->__('Change IP ok.', array()); $res = array('success' => true, 'agent' => $response['agent'], 'response' => $msg_i18n); $result = json_decode($res); } $this->getResponse()->setHttpHeader('Content-type', 'application/json; charset=utf-8'); $this->getResponse()->setHttpHeader("X-JSON", '()'); return $this->renderText($result); }