From b7515c5d9c5fc3c622376818570c05a03c74fe17 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Sat, 27 May 2017 20:33:11 +0200 Subject: managing-ui: initial commit added possibility to manage uploaded files simple php ui to delete uploaded files --- managing-ui/XMPPClient.php | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 managing-ui/XMPPClient.php (limited to 'managing-ui/XMPPClient.php') diff --git a/managing-ui/XMPPClient.php b/managing-ui/XMPPClient.php new file mode 100644 index 0000000..131b9a4 --- /dev/null +++ b/managing-ui/XMPPClient.php @@ -0,0 +1,96 @@ +defaultPort, getJidLocalPart($jid), ($passwordEncrypted ? $this->decrypt($password) : $password), $this->defaultResource); + } + + public function loginAndGetFileList() { + if ($this->login()) { + $this->getFileList(); + } + } + + public function deleteFile($fileurl) { + if (null == $fileurl || '' == $fileurl) { + throw new XMPPException('Missing fileurl'); + } + $id = $this->getId(); + $this->addIdHandler($id, 'deleteFileIqHandler'); + $xml = "$fileurl"; + $this->send($xml); + } + + private function decrypt($password) { + $e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC); + return $e->decrypt($password, XMPPClient::ENCRYPTION_KEY); + } + + public function login() { + try { + $this->connect(5); + $this->processUntil('session_start', 10); + session_start(); + $_SESSION["authenticated"] = 'yeah'; + $_SESSION["JID"] = $this->basejid; + $e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC); + $encryptedPassword = $e->encrypt($this->password, XMPPClient::ENCRYPTION_KEY); + $_SESSION["PASSWORD"] = $encryptedPassword; + return true; + } catch (XMPPException $e) { + echo $e->getMessage(); + return false; + } + } + + protected function getFileList() { + $id = $this->getId(); + $this->addIdHandler($id, 'fileListIqHandler'); + $this->send(""); + $this->processUntil("list_loaded"); + } + + protected function fileListIqHandler($xml) { + $list = $xml->sub('list'); + $fileList = []; + foreach ($list->subs as $fileXML) { + $file = []; + $file['url'] = $fileXML->sub('url')->data; + $file['timestamp'] = $fileXML->attrs['timestamp']; + $file['to'] = $fileXML->attrs['to']; + $file['from'] = $fileXML->attrs['from']; + $fileInfo = $fileXML->sub('file-info'); + $file['filename'] = $fileInfo->sub('filename')->data; + $file['size'] = $fileInfo->sub('size')->data; + $file['type'] = $fileInfo->sub('content-type')->data; + $fileList[] = $file; + } + $this->event('list_loaded'); + $_SESSION['FILE-LIST'] = $fileList; + header('Location: index.php'); + } + + protected function deleteFileIqHandler($xml) { + $deleted = $xml->sub('deleted'); + if (null != $deleted) { + $data = ['error' => false, 'msg' => 'File successfully deleted']; + } else { + $error = $xml->sub('error'); + $data = ['error' => true, 'msg' => $error->subs[0]->name."\n".$error->sub('text')->data]; + } + sendHttpReturnCodeAndJson(200, $data); + } +} +?> \ No newline at end of file -- cgit v1.2.3