/**
  * This method is called, when the widget should generate it's content.
  * Return the complete content using the methods provided by the base class.
  * Do NOT use the toolkit right here!
  * @return string
  */
 public function getWidgetOutput()
 {
     $strReturn = "";
     if (!class_module_system_module::getModuleByName("system")->rightRight3() || !class_carrier::getInstance()->getObjSession()->isSuperAdmin()) {
         return $this->getLang("commons_error_permissions");
     }
     $objFilesystem = new class_filesystem();
     $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/log", array(".log"));
     foreach ($arrFiles as $strName) {
         $objFilesystem->openFilePointer(_projectpath_ . "/log/" . $strName, "r");
         $strLogContent = $objFilesystem->readLastLinesFromFile($this->getFieldValue("nrofrows"));
         $objFilesystem->closeFilePointer();
         $strLogContent = str_replace(array("INFO", "ERROR"), array("INFO   ", "ERROR  "), $strLogContent);
         $arrLogEntries = explode("\r", $strLogContent);
         $strReturn .= $this->objToolkit->getPreformatted($arrLogEntries);
     }
     return $strReturn;
 }
 /**
  * Tries to save the passed file.
  * Therefore, the following post-params should be given:
  * action = fileUpload
  * folder = the folder to store the file within
  * systemid = the filemanagers' repo-id
  * inputElement = name of the inputElement
  *
  * @return string
  * @permissions right1
  */
 protected function actionFileupload()
 {
     $strReturn = "";
     /** @var class_module_mediamanager_repo|class_module_mediamanager_file $objFile */
     $objFile = class_objectfactory::getInstance()->getObject($this->getSystemid());
     /**
      * @var class_module_mediamanager_repo
      */
     $objRepo = null;
     if ($objFile instanceof class_module_mediamanager_file) {
         $strFolder = $objFile->getStrFilename();
         if (!$objFile->rightEdit() || $objFile->getIntType() != class_module_mediamanager_file::$INT_TYPE_FOLDER) {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED);
             $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>";
             return $strReturn;
         }
         $objRepo = class_objectfactory::getInstance()->getObject($objFile->getPrevId());
         while (!$objRepo instanceof class_module_mediamanager_repo) {
             $objRepo = class_objectfactory::getInstance()->getObject($objRepo->getPrevId());
         }
     } elseif ($objFile instanceof class_module_mediamanager_repo) {
         $objRepo = $objFile;
         $strFolder = $objFile->getStrPath();
         if (!$objFile->rightEdit()) {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED);
             $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>";
             return $strReturn;
         }
     } else {
         class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED);
         $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>";
         return $strReturn;
     }
     //Handle the fileupload
     $arrSource = $this->getParam($this->getParam("inputElement"));
     $bitJsonResponse = $this->getParam("jsonResponse") != "";
     $bitPostData = false;
     if (is_array($arrSource)) {
         $strFilename = $arrSource["name"];
     } else {
         $bitPostData = getPostRawData() != "";
         $strFilename = $arrSource;
     }
     $strTarget = $strFolder . "/" . createFilename($strFilename);
     $objFilesystem = new class_filesystem();
     if (!file_exists(_realpath_ . "/" . $strFolder)) {
         $objFilesystem->folderCreate($strFolder, true);
     }
     if ($objFilesystem->isWritable($strFolder)) {
         //Check file for correct filters
         $arrAllowed = explode(",", $objRepo->getStrUploadFilter());
         $strSuffix = uniStrtolower(uniSubstr($strFilename, uniStrrpos($strFilename, ".")));
         if ($objRepo->getStrUploadFilter() == "" || in_array($strSuffix, $arrAllowed)) {
             if ($bitPostData) {
                 $objFilesystem = new class_filesystem();
                 $objFilesystem->openFilePointer($strTarget);
                 $bitCopySuccess = $objFilesystem->writeToFile(getPostRawData());
                 $objFilesystem->closeFilePointer();
             } else {
                 $bitCopySuccess = $objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"]);
             }
             if ($bitCopySuccess) {
                 if ($bitJsonResponse) {
                     $strReturn = json_encode(array('success' => true));
                 } else {
                     $strReturn .= "<message>" . $this->getLang("xmlupload_success") . "</message>";
                 }
                 class_logger::getInstance()->addLogRow("uploaded file " . $strTarget, class_logger::$levelInfo);
                 $objRepo->syncRepo();
             } else {
                 if ($bitJsonResponse) {
                     $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_copyUpload")));
                 } else {
                     $strReturn .= "<message><error>" . $this->getLang("xmlupload_error_copyUpload") . "</error></message>";
                 }
             }
         } else {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST);
             if ($bitJsonResponse) {
                 $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_filter")));
             } else {
                 $strReturn .= "<message><error>" . $this->getLang("xmlupload_error_filter") . "</error></message>";
             }
         }
     } else {
         class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_INTERNAL_SERVER_ERROR);
         if ($bitJsonResponse) {
             $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_notWritable")));
         } else {
             $strReturn .= "<message><error>" . xmlSafeString($this->getLang("xmlupload_error_notWritable")) . "</error></message>";
         }
     }
     if ($bitJsonResponse) {
         //disabled for ie. otherwise the upload won't work due to the headers.
         class_response_object::getInstance()->setStrResponseType(class_http_responsetypes::STR_TYPE_HTML);
         //class_response_object::getInstance()->setStResponseType(class_http_responsetypes::STR_TYPE_JSON);
     }
     @unlink($arrSource["tmp_name"]);
     return $strReturn;
 }
 /**
  * Fetches the latest entries from the current systemlog.
  * The entries can be limited by the optional param latestEntry.
  * If given, only entries created after the passed date will be returned.
  * The format of latestEntry is similar to the date returned, so YYYY-MM-DD HH:MM:SS
  * The structure is returned like:
  * <entries>
  *   <entry>
  *      <level></level>
  *      <date></date>
  *      <session></session>
  *      <content></content>
  *   </entry>
  * </entries>
  *
  * @return string
  * @permissions right3
  */
 protected function actionSystemLog()
 {
     $strReturn = "";
     $intStartDate = false;
     if ($this->getParam("latestEntry") != "") {
         $intStartDate = strtotime($this->getParam("latestEntry"));
     }
     //read the last few lines
     $objFile = new class_filesystem();
     $arrDetails = $objFile->getFileDetails("/system/debug/systemlog.log");
     $intOffset = 0;
     $bitSkip = false;
     if ($arrDetails["filesize"] > 20000) {
         $intOffset = $arrDetails["filesize"] - 20000;
         $bitSkip = true;
     }
     $objFile->openFilePointer("/system/debug/systemlog.log", "r");
     //forward to the new offset, skip entry
     if ($intOffset > 0) {
         $objFile->setFilePointerOffset($intOffset);
     }
     $arrRows = array();
     $strRow = $objFile->readLineFromFile();
     while ($strRow !== false) {
         if (!$bitSkip && trim($strRow) > 0) {
             $arrRows[] = $strRow;
         }
         $bitSkip = false;
         $strRow = $objFile->readLineFromFile();
     }
     $objFile->closeFilePointer();
     $strReturn .= "<entries>\n";
     $arrRows = array_reverse($arrRows);
     foreach ($arrRows as $strSingleRow) {
         //parse entry
         $strDate = uniSubstr($strSingleRow, 0, 19);
         $strSingleRow = uniSubstr($strSingleRow, 20);
         $intTempPos = uniStrpos($strSingleRow, " ");
         $strLevel = uniSubstr($strSingleRow, 0, $intTempPos);
         $strSingleRow = uniSubstr($strSingleRow, $intTempPos + 1);
         $intTempPos = uniStrpos($strSingleRow, ")") + 1;
         $strSession = uniSubstr($strSingleRow, 0, $intTempPos);
         $strLogEntry = uniSubstr($strSingleRow, $intTempPos);
         if ($intStartDate !== false) {
             $intCurDate = strtotime($strDate);
             if ($intStartDate >= $intCurDate) {
                 continue;
             }
         }
         $strReturn .= "\t<entry>\n";
         $strReturn .= "\t\t<level>" . $strLevel . "</level>\n";
         $strReturn .= "\t\t<date>" . $strDate . "</date>\n";
         $strReturn .= "\t\t<session>" . $strSession . "</session>\n";
         $strReturn .= "\t\t<content>" . xmlSafeString(strip_tags($strLogEntry)) . "</content>\n";
         $strReturn .= "\t</entry>\n";
     }
     $strReturn .= "</entries>";
     return $strReturn;
 }
Пример #4
0
 /**
  * Returns the complete log-file as one string
  *
  * @return string
  */
 public function getPhpLogFileContent()
 {
     $objFile = new class_filesystem();
     $objFile->openFilePointer("/project/log/php.log", "r");
     return $objFile->readLastLinesFromFile(25);
 }
 /**
  * Fetches the entries from the system-log an prints them as preformatted text
  *
  * @return string
  * @autoTestable
  * @permissions right3
  */
 protected function actionSystemlog()
 {
     //load logfiles available
     $objFilesystem = new class_filesystem();
     $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/log", array(".log"));
     $arrTabs = array();
     foreach ($arrFiles as $strName) {
         $objFilesystem->openFilePointer(_projectpath_ . "/log/" . $strName, "r");
         $strLogContent = $objFilesystem->readLastLinesFromFile(20);
         $strLogContent = str_replace(array("INFO", "ERROR"), array("INFO   ", "ERROR  "), $strLogContent);
         $arrLogEntries = explode("\r", $strLogContent);
         $objFilesystem->closeFilePointer();
         $arrTabs[$strName] = $this->objToolkit->getPreformatted($arrLogEntries);
     }
     return $this->objToolkit->getTabbedContent($arrTabs);
 }
Пример #6
0
 /**
  * Writes the current array of data to the given csv-file or directly to the browser.
  * Make sure to have set all needed values before, otherwise
  * an exception is thrown
  *
  * @return bool
  *
  * @param bool $bitStreamToBrowser
  * @param bool $bitExcludeHeaders skip the header-row in the output, generated based on the mapping
  *
  * @throws class_exception
  */
 public function writeArrayToFile($bitStreamToBrowser = false, $bitExcludeHeaders = false)
 {
     //all needed values set before?
     if ($this->arrData != null && $this->arrMapping != null && $this->strFilename != null) {
         //create file-content. use a file-pointer to avoid max-mem-errors
         $objFilesystem = new class_filesystem();
         //open file
         if ($bitStreamToBrowser) {
             class_response_object::getInstance()->addHeader('Pragma: private');
             class_response_object::getInstance()->addHeader('Cache-control: private, must-revalidate');
             class_response_object::getInstance()->setStrResponseType(class_http_responsetypes::STR_TYPE_CSV);
             class_response_object::getInstance()->addHeader("Content-Disposition: attachment; filename=" . saveUrlEncode(trim(basename($this->strFilename))));
             class_response_object::getInstance()->sendHeaders();
         } else {
             $objFilesystem->openFilePointer($this->strFilename);
         }
         //the first row should contain the row-names
         if (!$bitExcludeHeaders) {
             $strRow = "";
             foreach ($this->arrMapping as $strTagetCol) {
                 //add enclosers?
                 if ($this->strTextEncloser != null) {
                     $strTagetCol = $this->strTextEncloser . $strTagetCol . $this->strTextEncloser;
                 }
                 $strRow .= $strTagetCol . $this->strDelimiter;
             }
             //remove last delimiter, eol
             $strRow = uniSubstr($strRow, 0, uniStrlen($this->strDelimiter) * -1);
             //add a linebreak
             $strRow .= "\n";
             //write header to file
             if ($bitStreamToBrowser) {
                 echo $strRow;
             } else {
                 $objFilesystem->writeToFile($strRow);
             }
         }
         //iterate over the data array to write it to the file
         foreach ($this->arrData as $arrOneRow) {
             $strRow = "";
             foreach ($this->arrMapping as $strSourceCol => $strTargetCol) {
                 if (isset($arrOneRow[$strSourceCol])) {
                     $strEntry = $arrOneRow[$strSourceCol];
                     //escape the delimiter maybe occuring in the text
                     $strEntry = uniStrReplace($this->strDelimiter, "\\" . $this->strDelimiter, $strEntry);
                     //add enclosers?
                     if ($this->strTextEncloser != null) {
                         $strEntry = $this->strTextEncloser . $strEntry . $this->strTextEncloser;
                     }
                 } else {
                     $strEntry = "";
                 }
                 $strRow .= $strEntry . $this->strDelimiter;
             }
             //remove last delimiter, eol
             $strRow = uniSubstr($strRow, 0, uniStrlen($this->strDelimiter) * -1);
             //add linebreak
             $strRow .= "\n";
             //and write to file
             if ($bitStreamToBrowser) {
                 echo $strRow;
             } else {
                 $objFilesystem->writeToFile($strRow);
             }
         }
         //and close the filepointer...
         if (!$bitStreamToBrowser) {
             $objFilesystem->closeFilePointer();
         }
         if ($bitStreamToBrowser) {
             flush();
             die;
         }
         return true;
     } else {
         throw new class_exception("can't proceed, needed values missing", class_exception::$level_ERROR);
     }
 }