示例#1
0
    /**
     * Exporta els registres de la taula seleccionada a un fitxer csv
     *      
     * 
     * @return void (carrega la plantilla per importar/exportar taules)
     */
    public function exportaTaula() {
        // Security check
        //$this->checkCsrfToken();
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('Llicencies::', '::', ACCESS_ADMIN));
        if ($this->request->isPost()) {
            $taula = $this->request->request->get('taula_exp', false);
        }
        if (is_null($taula)) {
            LogUtil::registerError(__('L\'exportació de dades no és possible. No s\'ha especificat cap taula.'));            
        } else {
            $titlerow = DBUtil::getColumnsArray($taula);
            $datarows = DBUtil::selectObjectArray($taula);

            $date = date('_Ymd_Hi');
            FileUtil::exportCSV($datarows, $titlerow, ';', '"', $taula . $date . '.csv');
        
        }
        // Després de exportCSV no executa aquest redirect
        //return system::redirect(ModUtil::url('Llicencies', 'admin', 'ieTables#tabs-2'));
        $this->redirect(ModUtil::url('llicencies', 'admin', 'ieTables'));
    }
示例#2
0
    /**
     * Show the form to export a CSV file of users.
     *
     * Parameters passed via the $args array:
     * --------------------------------------
     * boolean $args['confirmed']       True if the user has confirmed the export.
     * string  $args['exportFile']      Filename of the file to export (optional) (default=users.csv)
     * integer $args['delimiter']       A code indicating the type of delimiter found in the export file. 1 = comma, 2 = semicolon, 3 = colon, 4 = tab.
     * integer $args['exportEmail']     Flag to export email addresses, 1 for yes.
     * integer $args['exportTitles']    Flag to export a title row, 1 for yes.
     * integer $args['exportLastLogin'] Flag to export the last login date/time, 1 for yes.
     * integer $args['exportRegDate']   Flag to export the registration date/time, 1 for yes.
     * integer $args['exportGroups']    Flag to export the group membership, 1 for yes.
     *
     * Parameters passed via GET:
     * --------------------------
     * None.
     *
     * Parameters passed via POST:
     * ---------------------------
     * boolean confirmed       True if the user has confirmed the export.
     * string  exportFile      Filename of the file to export (optional) (default=users.csv)
     * integer delimiter       A code indicating the type of delimiter found in the export file. 1 = comma, 2 = semicolon, 3 = colon, 4 = tab.
     * integer exportEmail     Flag to export email addresses, 1 for yes.
     * integer exportTitles    Flag to export a title row, 1 for yes.
     * integer exportLastLogin Flag to export the last login date/time, 1 for yes.
     * integer exportRegDate   Flag to export the registration date/time, 1 for yes.
     * integer exportGroups    Flag to export the group membership, 1 for yes.
     *
     * Parameters passed via SESSION:
     * ------------------------------
     * None.
     *
     * @param array $args All arguments passed to the function.
     *
     * @return redirect user to the form if confirmed not 1, else export the csv file.
     *
     * @throws Zikula_Exception_Fatal     Thrown if parameters are passed via the $args array, but $args is invalid.
     * @throws Zikula_Exception_Forbidden Thrown if the current user does not have admin access, or method this function was accessed is invalid.
     */
    public function exporter($args)
    {
        // security check
        if (!SecurityUtil::checkPermission('Users::', '::', ACCESS_ADMIN)) {
            throw new Zikula_Exception_Forbidden();
        }

        // get input values. Check for direct function call first because calling function might be either get or post
        if (isset($args) && is_array($args) && !empty($args)) {
            $confirmed  = isset($args['confirmed']) ? $args['confirmed'] : false;
            $exportFile = isset($args['exportFile']) ? $args['exportFile'] : null;
            $delimiter  = isset($args['delimiter']) ? $args['delimiter'] : null;
            $email      = isset($args['exportEmail']) ? $args['exportEmail'] : null;
            $titles     = isset($args['exportTitles']) ? $args['exportTitles'] : null;
            $lastLogin  = isset($args['exportLastLogin']) ? $args['exportLastLogin'] : null;
            $regDate    = isset($args['exportRegDate']) ? $args['exportRegDate'] : null;
            $groups     = isset($args['exportGroups']) ? $args['exportGroups'] : null;
        } elseif (isset($args) && !is_array($args)) {
            throw new Zikula_Exception_Fatal(LogUtil::getErrorMsgArgs());
        } elseif ($this->request->isGet()) {
            $confirmed = false;
        } elseif ($this->request->isPost()) {
            $this->checkCsrfToken();
            $confirmed  = $this->request->request->get('confirmed', false);
            $exportFile = $this->request->request->get('exportFile', null);
            $delimiter  = $this->request->request->get('delimiter', null);
            $email      = $this->request->request->get('exportEmail', null);
            $titles     = $this->request->request->get('exportTitles', null);
            $lastLogin  = $this->request->request->get('exportLastLogin', null);
            $regDate    = $this->request->request->get('exportRegDate', null);
            $groups     = $this->request->request->get('exportGroups', null);
        } else {
            throw new Zikula_Exception_Forbidden();
        }

        if ($confirmed) {
            // get other import values
            $email = (!isset($email) || $email !=='1') ? false : true;
            $titles = (!isset($titles) || $titles !== '1') ? false : true;
            $lastLogin = (!isset($lastLogin) || $lastLogin !=='1') ? false : true;
            $regDate = (!isset($regDate) || $regDate !== '1') ? false : true;
            $groups = (!isset($groups) || $groups !== '1') ? false : true;

            if (!isset($delimiter) || $delimiter == '') {
                $delimiter = 1;
            }
            switch ($delimiter) {
                case 1:
                    $delimiter = ",";
                    break;
                case 2:
                    $delimiter = ";";
                    break;
                case 3:
                    $delimiter = ":";
                    break;
                case 4:
                    $delimiter = chr(9);
            }
            if (!isset($exportFile) || $exportFile == '') {
                $exportFile = 'users.csv';
            }
            if (!strrpos($exportFile, '.csv')) {
                $exportFile .= '.csv';
            }

            $colnames = array();

            //get all user fields
            if (ModUtil::available('Profile')) {
                $userfields = ModUtil::apiFunc('Profile', 'user', 'getallactive');

                foreach ($userfields as $item) {
                    $colnames[] = $item['prop_attribute_name'];
                }
            }

            // title fields
            if ($titles == 1) {
                $titlerow = array('id', 'uname');

                //titles for optional data
                if ($email == 1) {
                    array_push($titlerow, 'email');
                }
                if ($regDate == 1) {
                    array_push($titlerow, 'user_regdate');
                }
                if ($lastLogin == 1) {
                    array_push($titlerow, 'lastlogin');
                }
                if ($groups == 1) {
                    array_push($titlerow, 'groups');
                }

                array_merge($titlerow, $colnames);
            } else {
                $titlerow = array();
            }

            //get all users
            $users = ModUtil::apiFunc($this->name, 'user', 'getAll');

            // get all groups
            $allgroups = ModUtil::apiFunc('Groups', 'user', 'getall');
            $groupnames = array();
            foreach ($allgroups as $groupitem) {
                $groupnames[$groupitem['gid']] = $groupitem['name'];
            }

            // data for csv
            $datarows = array();

            //loop every user gettin user id and username and all user fields and push onto result array.
            foreach ($users as $user) {
                $uservars = UserUtil::getVars($user['uid']);

                $result = array();

                array_push($result, $uservars['uid'], $uservars['uname']);

                //checks for optional data
                if ($email == 1) {
                    array_push($result, $uservars['email']);
                }
                if ($regDate == 1) {
                    array_push($result, $uservars['user_regdate']);
                }
                if ($lastLogin == 1) {
                    array_push($result, $uservars['lastlogin']);
                }

                if ($groups == 1) {
                    $usergroups = ModUtil::apiFunc('Groups', 'user', 'getusergroups',
                                            array('uid'   => $uservars['uid'],
                                                  'clean' => true));

                    $groupstring = "";

                    foreach ($usergroups as $group) {
                        $groupstring .= $groupnames[$group] . chr(124);
                    }

                    $groupstring = rtrim($groupstring, chr(124));


                    array_push($result, $groupstring);
                }

                foreach ($colnames as $colname) {
                    array_push($result, $uservars['__ATTRIBUTES__'][$colname]);
                }

                array_push($datarows, $result);
            }

            //export the csv file
            FileUtil::exportCSV($datarows, $titlerow, $delimiter, '"', $exportFile);
        }

        if (SecurityUtil::checkPermission('Groups::', '::', ACCESS_READ)) {
            $this->view->assign('groups', '1');
        }

        return $this->view->fetch('users_admin_export.tpl');
    }
示例#3
0
 /**
  * @Route("/exportidslog")
  *
  * Export ids log.
  *
  * @param Request $request
  *
  * @return Response symfony response object
  *
  * @throws AccessDeniedException Thrown if the user doesn't have admin access to the module
  */
 public function exportidslogAction(Request $request)
 {
     // Security check
     if (!SecurityUtil::checkPermission('ZikulaSecurityCenterModule::', '::', ACCESS_EDIT)) {
         throw new AccessDeniedException();
     }
     // get input values
     $confirmed = (int) $request->request->get('confirmed', isset($args['confirmed']) ? $args['confirmed'] : 0);
     if ($confirmed == 1) {
         // export the titles ?
         $exportTitles = $request->request->get('exportTitles', isset($args['exportTitles']) ? $args['exportTitles'] : null);
         $exportTitles = !isset($exportTitles) || $exportTitles !== '1' ? false : true;
         // name of the exported file
         $exportFile = $request->request->get('exportFile', isset($args['exportFile']) ? $args['exportFile'] : null);
         if (!isset($exportFile) || $exportFile == '') {
             $exportFile = 'idslog.csv';
         }
         if (!strrpos($exportFile, '.csv')) {
             $exportFile .= '.csv';
         }
         // delimeter
         $delimiter = $request->request->get('delimiter', isset($args['delimiter']) ? $args['delimiter'] : null);
         if (!isset($delimiter) || $delimiter == '') {
             $delimiter = 1;
         }
         switch ($delimiter) {
             case 1:
                 $delimiter = ",";
                 break;
             case 2:
                 $delimiter = ";";
                 break;
             case 3:
                 $delimiter = ":";
                 break;
             case 4:
                 $delimiter = chr(9);
         }
         // titles
         if ($exportTitles == 1) {
             $titles = array($this->__('Name'), $this->__('Tag'), $this->__('Value'), $this->__('Page'), $this->__('User Name'), $this->__('IP'), $this->__('Impact'), $this->__('PHPIDS filters used'), $this->__('Date'));
         } else {
             $titles = array();
         }
         // get data
         $item_params = array('sorting' => array('date' => 'DESC'));
         $items = ModUtil::apiFunc('ZikulaSecurityCenterModule', 'admin', 'getAllIntrusions', $item_params);
         $objData = array();
         foreach ($items as $item) {
             $dta = $item->toArray();
             $dta['username'] = $dta['user']['uname'];
             $dta['filters'] = unserialize($dta['filters']);
             $dta['date'] = $dta['date']->format('Y-m-d H:i:s');
             unset($dta['user']);
             $objData[] = $dta;
         }
         $data = array();
         $find = array("\r\n", "\n");
         $replace = array("", "");
         foreach ($objData as $key => $idsdata) {
             $filtersused = '';
             foreach ($objData[$key]['filters'] as $filter) {
                 $filtersused .= $filter['id'] . " ";
             }
             $datarow = array($objData[$key]['name'], $objData[$key]['tag'], htmlspecialchars(str_replace($find, $replace, $objData[$key]['value']), ENT_COMPAT, 'UTF-8', false), htmlspecialchars($objData[$key]['page'], ENT_COMPAT, 'UTF-8', false), $objData[$key]['username'], $objData[$key]['ip'], $objData[$key]['impact'], $filtersused, $objData[$key]['date']);
             array_push($data, $datarow);
         }
         // export the csv file
         \FileUtil::exportCSV($data, $titles, $delimiter, '"', $exportFile);
     }
     // fetch output from template
     return new Response($this->view->fetch('Admin/exportidslog.tpl'));
 }
示例#4
0
    public function exportToCsv($args){
        $optFields = $args['optFields'];        
        $d = date('_Ymd_Hi') ;
        $filename  = $args['filename'];//="")?$args['filename']:"exportUsers" .  $d. '.csv';
        $delimiter = isset($args['delimiter'])?$args['delimiter'] : ';';
        $titlerow = array();
        $groups = false;
        $titlerow[] ="uname";
        $sql = "SELECT uid, uname";
        foreach ($optFields as $key => $value) {
            if ($value) {
                if ($key != "export_groups") $sql .= ",". $key; 
                // generate CSV header line
                switch ($key) {
                    case "activated" :
                        $titlerow[] ="activated";
                        break;
                    case "email":
                        $titlerow[] ="email";
                        break;
                    case "iw_nom":
                        $titlerow[] ="firstname";
                        break;
                    case "iw_cognom1":
                        $titlerow[] ="lastname1";
                        break;
                    case "iw_cognom2":
                        $titlerow[] ="lastname2";
                        break;
                    case "iw_naixement":
                        $titlerow[] ="birthdate";
                        break;
                    case "iw_sex":
                        $titlerow[] ="gender";
                        break;
                    case "export_groups":
                        $titlerow[] ="in";
                        $groups = true;
                        break;                    
                }
            }
        }
        $sql.= " FROM users, IWusers WHERE uid = iw_uid";
        // Get users info
        $rs = DBUtil::executeSQL($sql);
        $rsm = DBUtil::marshallObjects($rs);
        // Get groups from every user
//        if ($groups) {
        foreach ($rsm as $key => $user){
            if ($groups) {
                // Get all groups
                $rsm[$key]['in'] = UserUtil::getGroupListForUser($user['uid'], "|"); 
            }
            // Remove uid field
            array_splice($rsm[$key], 0, 1);
        }
        $result = array();
        FileUtil::exportCSV($rsm, $titlerow, $delimiter, '"', $filename);
        return true; //$result;
    }
示例#5
0
 /**
  * Exporta un csv amb tota la informació de les entitats-gtaf/grups d'entitats-gtaf que té Sirius
  * 
  *
  * @return void Retorna a la funció *gtafEntitiesGest* amb els missatges d'execució
  */
 public function exportGtafEntities() {
     if (!SecurityUtil::checkPermission('Cataleg::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     $case = FormUtil::getPassedValue('case',null,'GET');
     if ($case == 'entities') {
         $taula = 'cataleg_gtafEntities';
         $fitxer = 'exportaGtafEntitats.csv';
     } elseif ($case == 'groups') {
         $taula = 'cataleg_gtafGroups';
         $fitxer = 'exportaGtafGrups.csv';
     } else {
         LogUtil::registerError($this->__('La petició no és vàlida'));
         return system::redirect(ModUtil::url('Cataleg', 'admin', 'gtafEntitiesGest'));
     }
     $titlerow = DBUtil::getColumnsArray($taula);
     $datarows = DBUtil::selectObjectArray($taula);
     FileUtil::exportCSV($datarows, $titlerow, ';', '"', $fitxer);
     return system::redirect(ModUtil::url('Cataleg', 'admin', 'gtafEntitiesGest'));
 }
示例#6
0
    /**
     * Export ids log.
     *
     * @return string
     */
    public function exportidslog()
    {
        // Security check
        if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_EDIT)) {
            return LogUtil::registerPermissionError();
        }

        // get input values
        $confirmed = (int)FormUtil::getPassedValue('confirmed', (isset($args['confirmed']) ? $args['confirmed'] : 0), 'POST');

        if ($confirmed == 1) {

            // export the titles ?
            $exportTitles = FormUtil::getPassedValue('exportTitles', (isset($args['exportTitles']) ? $args['exportTitles'] : null), 'POST');
            $exportTitles = (!isset($exportTitles) || $exportTitles !== '1') ? false : true;

            // name of the exported file
            $exportFile = FormUtil::getPassedValue('exportFile', (isset($args['exportFile']) ? $args['exportFile'] : null), 'POST');
            if (!isset($exportFile) || $exportFile == '') {
                $exportFile = 'idslog.csv';
            }
            if (!strrpos($exportFile, '.csv')) {
                $exportFile .= '.csv';
            }

            // delimeter
            $delimiter = FormUtil::getPassedValue('delimiter', (isset($args['delimiter']) ? $args['delimiter'] : null), 'POST');
            if (!isset($delimiter) || $delimiter == '') {
                $delimiter = 1;
            }
            switch ($delimiter) {
                case 1:
                    $delimiter = ",";
                    break;
                case 2:
                    $delimiter = ";";
                    break;
                case 3:
                    $delimiter = ":";
                    break;
                case 4:
                    $delimiter = chr(9);
            }

            // titles
            if ($exportTitles == 1) {
                $titles = array(
                        $this->__('Name'),
                        $this->__('Tag'),
                        $this->__('Value'),
                        $this->__('Page'),
                        $this->__('User Name'),
                        $this->__('IP'),
                        $this->__('Impact'),
                        $this->__('PHPIDS filters used'),
                        $this->__('Date')
                );
            } else {
                $titles = array();
            }


            // actual data
            $sort = 'ids_date DESC';
            $class = 'SecurityCenter_DBObject_IntrusionArray';
            $objArray = new $class();
            $objData = $objArray->get('', $sort);

            $data = array();
            $find = array("\r\n", "\n");
            $replace = array("", "");

            foreach ($objData as $key => $idsdata) {
                $objData[$key]['filters'] = unserialize($objData[$key]['filters']);

                $filtersused = '';
                foreach ($objData[$key]['filters'] as $filter) {
                    $filtersused .= $filter['id'] . " ";
                }

                $datarow = array(
                        $objData[$key]['name'],
                        $objData[$key]['tag'],
                        htmlspecialchars(str_replace($find, $replace, $objData[$key]['value']), ENT_COMPAT, 'UTF-8', false),
                        htmlspecialchars($objData[$key]['page'], ENT_COMPAT, 'UTF-8', false),
                        $objData[$key]['username'],
                        $objData[$key]['ip'],
                        $objData[$key]['impact'],
                        $filtersused,
                        $objData[$key]['date']
                );

                array_push($data, $datarow);
            }

            // export the csv file
            FileUtil::exportCSV($data, $titles, $delimiter, '"', $exportFile);
        }

        // fetch output from template
        return $this->view->fetch('securitycenter_admin_exportidslog.tpl');
    }