Passed
Push — development ( c3b866...650a11 )
by Nils
08:20
created
sources/checks.php 1 patch
Switch Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -50,23 +50,23 @@
 block discarded – undo
50 50
 Handle CASES
51 51
  */
52 52
 switch (filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING)) {
53
-case "checkSessionExists":
54
-    // Case permit to check if SESSION is still valid
55
-    session_start();
56
-    if (isset($_SESSION['CPM']) === true) {
57
-        echo "1";
58
-    } else {
59
-        // In case that no session is available
60
-        // Force the page to be reloaded and attach the CSRFP info
61
-
62
-        // Load CSRFP
63
-        $csrfp_array = include '../includes/libraries/csrfp/libs/csrfp.config.php';
64
-
65
-        // Send back CSRFP info
66
-        echo $csrfp_array['CSRFP_TOKEN'].";".filter_input(INPUT_POST, $csrfp_array['CSRFP_TOKEN'], FILTER_SANITIZE_STRING);
67
-    }
53
+    case "checkSessionExists":
54
+        // Case permit to check if SESSION is still valid
55
+        session_start();
56
+        if (isset($_SESSION['CPM']) === true) {
57
+            echo "1";
58
+        } else {
59
+            // In case that no session is available
60
+            // Force the page to be reloaded and attach the CSRFP info
61
+
62
+            // Load CSRFP
63
+            $csrfp_array = include '../includes/libraries/csrfp/libs/csrfp.config.php';
64
+
65
+            // Send back CSRFP info
66
+            echo $csrfp_array['CSRFP_TOKEN'].";".filter_input(INPUT_POST, $csrfp_array['CSRFP_TOKEN'], FILTER_SANITIZE_STRING);
67
+        }
68 68
 
69
-    break;
69
+        break;
70 70
 }
71 71
 
72 72
 /**
Please login to merge, or discard this patch.
sources/export.queries.php 1 patch
Switch Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -452,23 +452,23 @@  discard block
 block discarded – undo
452 452
             break;
453 453
 
454 454
     //CASE export in HTML format
455
-    case "export_to_html_format":
456
-        // step 1:
457
-        // - prepare export file
458
-        // - get full list of objects id to export
459
-        include $SETTINGS['cpassman_dir'].'/includes/config/include.php';
460
-        include_once $SETTINGS['cpassman_dir'].'/includes/libraries/Encryption/GibberishAES/GibberishAES.php';
461
-        $idsList = array();
462
-        $objNumber = 0;
463
-
464
-        foreach (explode(';', $post_ids) as $id) {
465
-            if (in_array($id, $_SESSION['forbiden_pfs']) === false
466
-                && in_array($id, $_SESSION['groupes_visibles']) === true
467
-                && (in_array($id, $_SESSION['no_access_folders']) === false)
468
-            ) {
469
-                // count elements to display
470
-                $result = DB::query(
471
-                    "SELECT i.id AS id, i.label AS label, i.restricted_to AS restricted_to, i.perso AS perso
455
+        case "export_to_html_format":
456
+            // step 1:
457
+            // - prepare export file
458
+            // - get full list of objects id to export
459
+            include $SETTINGS['cpassman_dir'].'/includes/config/include.php';
460
+            include_once $SETTINGS['cpassman_dir'].'/includes/libraries/Encryption/GibberishAES/GibberishAES.php';
461
+            $idsList = array();
462
+            $objNumber = 0;
463
+
464
+            foreach (explode(';', $post_ids) as $id) {
465
+                if (in_array($id, $_SESSION['forbiden_pfs']) === false
466
+                    && in_array($id, $_SESSION['groupes_visibles']) === true
467
+                    && (in_array($id, $_SESSION['no_access_folders']) === false)
468
+                ) {
469
+                    // count elements to display
470
+                    $result = DB::query(
471
+                        "SELECT i.id AS id, i.label AS label, i.restricted_to AS restricted_to, i.perso AS perso
472 472
                     FROM ".prefix_table("items")." as i
473 473
                     INNER JOIN ".prefix_table("nested_tree")." as n ON (i.id_tree = n.id)
474 474
                     INNER JOIN ".prefix_table("log_items")." as l ON (i.id = l.id_item)
@@ -476,41 +476,41 @@  discard block
 block discarded – undo
476 476
                     AND i.id_tree= %i
477 477
                     AND (l.action = %s OR (l.action = %s AND l.raison LIKE %s))
478 478
                     ORDER BY i.label ASC, l.date DESC",
479
-                    "0",
480
-                    $id,
481
-                    "at_creation",
482
-                    "at_modification",
483
-                    "at_pw :%"
484
-                );
485
-                foreach ($result as $record) {
486
-                    $restricted_users_array = explode(';', $record['restricted_to']);
487
-                    if (((in_array($id, $_SESSION['personal_visible_groups']) === true
488
-                        && !($record['perso'] == 1 && $_SESSION['user_id'] == $record['restricted_to'])
489
-                        && empty($record['restricted_to']) === false)
490
-                        ||
491
-                        (empty($record['restricted_to']) === false 
492
-                        && in_array($_SESSION['user_id'], $restricted_users_array) === false)
493
-                        ||
494
-                        (in_array($id, $_SESSION['groupes_visibles']))
495
-                        ) && (
496
-                        in_array($record['id'], $idsList) === false
497
-                        )
498
-                    ) {
499
-                        array_push($idsList, $record['id']);
500
-                        $objNumber++;
479
+                        "0",
480
+                        $id,
481
+                        "at_creation",
482
+                        "at_modification",
483
+                        "at_pw :%"
484
+                    );
485
+                    foreach ($result as $record) {
486
+                        $restricted_users_array = explode(';', $record['restricted_to']);
487
+                        if (((in_array($id, $_SESSION['personal_visible_groups']) === true
488
+                            && !($record['perso'] == 1 && $_SESSION['user_id'] == $record['restricted_to'])
489
+                            && empty($record['restricted_to']) === false)
490
+                            ||
491
+                            (empty($record['restricted_to']) === false 
492
+                            && in_array($_SESSION['user_id'], $restricted_users_array) === false)
493
+                            ||
494
+                            (in_array($id, $_SESSION['groupes_visibles']))
495
+                            ) && (
496
+                            in_array($record['id'], $idsList) === false
497
+                            )
498
+                        ) {
499
+                            array_push($idsList, $record['id']);
500
+                            $objNumber++;
501
+                        }
501 502
                     }
502 503
                 }
503 504
             }
504
-        }
505 505
 
506
-            // prepare export file
507
-            //save the file
508
-            $html_file = '/teampass_export_'.time().'_'.generateKey().'.html';
509
-            //print_r($full_listing);
510
-            $outstream = fopen($SETTINGS['path_to_files_folder'].$html_file, "w");
511
-            fwrite(
512
-                $outstream,
513
-                '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
506
+                // prepare export file
507
+                //save the file
508
+                $html_file = '/teampass_export_'.time().'_'.generateKey().'.html';
509
+                //print_r($full_listing);
510
+                $outstream = fopen($SETTINGS['path_to_files_folder'].$html_file, "w");
511
+                fwrite(
512
+                    $outstream,
513
+                    '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
514 514
     <head>
515 515
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
516 516
     <title>TeamPass Off-line mode</title>
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
             <th style="width:20%;">'.$LANG['url'].'</th>
551 551
         </tr></thead>
552 552
         <tbody id="itemsTable_tbody">'
553
-            );
554
-
555
-        fclose($outstream);
553
+                );
556 554
 
557
-        // send back and continue
558
-        echo '[{"loop":"true", "number":"'.$objNumber.'", "file":"'.$SETTINGS['path_to_files_folder'].$html_file.'" , "file_link":"'.$SETTINGS['url_to_files_folder'].$html_file.'"}]';
559
-        break;
555
+            fclose($outstream);
560 556
 
561
-    //CASE export in HTML format - Iteration loop
562
-    case "export_to_html_format_loop":
563
-        // do checks ... if fails, return an error
564
-        if (null === $post_idTree || null === $post_idsList) {
565
-            echo '[{"error":"true"}]';
557
+            // send back and continue
558
+            echo '[{"loop":"true", "number":"'.$objNumber.'", "file":"'.$SETTINGS['path_to_files_folder'].$html_file.'" , "file_link":"'.$SETTINGS['url_to_files_folder'].$html_file.'"}]';
566 559
             break;
567
-        }
568 560
 
569
-        // exclude this folder if not allowed
570
-        if (in_array($post_idTree, $_SESSION['forbiden_pfs']) === true
571
-            || in_array($post_idTree, $_SESSION['groupes_visibles']) === false
572
-            || (in_array($post_idTree, $_SESSION['no_access_folders']) === true)
573
-        ) {
574
-            echo '[{"loop":"true", "number":"'.$post_number.'", "cpt":"'.$post_cpt.'", "file":"'.$post_file.'", "idsList":"'.$post_idsList.'" , "file_link":"'.$post_file_link.'"}]';
575
-            break;
576
-        }
561
+        //CASE export in HTML format - Iteration loop
562
+        case "export_to_html_format_loop":
563
+            // do checks ... if fails, return an error
564
+            if (null === $post_idTree || null === $post_idsList) {
565
+                echo '[{"error":"true"}]';
566
+                break;
567
+            }
577 568
 
578
-        $full_listing = array();
579
-        $items_id_list = array();
580
-        include $SETTINGS['cpassman_dir'].'/includes/config/include.php';
581
-        include_once $SETTINGS['cpassman_dir'].'/includes/libraries/Encryption/GibberishAES/GibberishAES.php';
569
+            // exclude this folder if not allowed
570
+            if (in_array($post_idTree, $_SESSION['forbiden_pfs']) === true
571
+                || in_array($post_idTree, $_SESSION['groupes_visibles']) === false
572
+                || (in_array($post_idTree, $_SESSION['no_access_folders']) === true)
573
+            ) {
574
+                echo '[{"loop":"true", "number":"'.$post_number.'", "cpt":"'.$post_cpt.'", "file":"'.$post_file.'", "idsList":"'.$post_idsList.'" , "file_link":"'.$post_file_link.'"}]';
575
+                break;
576
+            }
577
+
578
+            $full_listing = array();
579
+            $items_id_list = array();
580
+            include $SETTINGS['cpassman_dir'].'/includes/config/include.php';
581
+            include_once $SETTINGS['cpassman_dir'].'/includes/libraries/Encryption/GibberishAES/GibberishAES.php';
582 582
 
583
-        $rows = DB::query(
584
-            "SELECT i.id as id, i.url as url, i.perso as perso, i.label as label, i.description as description, i.pw as pw, i.login as login, i.id_tree as id_tree,
583
+            $rows = DB::query(
584
+                "SELECT i.id as id, i.url as url, i.perso as perso, i.label as label, i.description as description, i.pw as pw, i.login as login, i.id_tree as id_tree,
585 585
                 l.date as date, i.pw_iv as pw_iv,
586 586
                 n.renewal_period as renewal_period
587 587
             FROM ".prefix_table("items")." as i
@@ -591,108 +591,108 @@  discard block
 block discarded – undo
591 591
             AND i.id_tree= %i
592 592
             AND (l.action = %s OR (l.action = %s AND l.raison LIKE %s))
593 593
             ORDER BY i.label ASC, l.date DESC",
594
-            "0",
595
-            $post_idTree,
596
-            "at_creation",
597
-            "at_modification",
598
-            "at_pw :%"
599
-        );
600
-
601
-        foreach ($rows as $record) {
602
-            //exclude all results except the first one returned by query
603
-            if (empty($id_managed) || $id_managed != $record['id']) {
604
-                // decrypt PW
605
-                if (empty($post_salt_key) === false && null !== $post_salt_key) {
606
-                    $pw = cryption(
607
-                        $record['pw'],
608
-                        mysqli_escape_string($link, stripslashes($post_salt_key)),
609
-                        "decrypt"
594
+                "0",
595
+                $post_idTree,
596
+                "at_creation",
597
+                "at_modification",
598
+                "at_pw :%"
599
+            );
600
+
601
+            foreach ($rows as $record) {
602
+                //exclude all results except the first one returned by query
603
+                if (empty($id_managed) || $id_managed != $record['id']) {
604
+                    // decrypt PW
605
+                    if (empty($post_salt_key) === false && null !== $post_salt_key) {
606
+                        $pw = cryption(
607
+                            $record['pw'],
608
+                            mysqli_escape_string($link, stripslashes($post_salt_key)),
609
+                            "decrypt"
610
+                        );
611
+                    } else {
612
+                        $pw = cryption(
613
+                            $record['pw'],
614
+                            "",
615
+                            "decrypt"
616
+                        );
617
+                    }
618
+                    array_push(
619
+                        $full_listing, array(
620
+                            'id_tree' => $record['id_tree'],
621
+                            'id' => $record['id'],
622
+                            'label' => $record['label'],
623
+                            'description' => addslashes(str_replace(array(";", "<br />"), array("|", "\n\r"), mysqli_escape_string($link, stripslashes(utf8_decode($record['description']))))),
624
+                            'pw' => $pw['string'],
625
+                            'login' => $record['login'],
626
+                            'url' => $record['url'],
627
+                            'perso' => $record['perso']
628
+                        )
610 629
                     );
611
-                } else {
612
-                    $pw = cryption(
613
-                        $record['pw'],
614
-                        "",
615
-                        "decrypt"
630
+                    $i++;
631
+                    array_push($items_id_list, $record['id']);
632
+
633
+                    // log
634
+                    logItems(
635
+                        $record['id'],
636
+                        $record['l SeekableIteratorabel'],
637
+                        $_SESSION['user_id'],
638
+                        'at_export',
639
+                        $_SESSION['login'],
640
+                        'html'
616 641
                     );
617 642
                 }
618
-                array_push(
619
-                    $full_listing, array(
620
-                        'id_tree' => $record['id_tree'],
621
-                        'id' => $record['id'],
622
-                        'label' => $record['label'],
623
-                        'description' => addslashes(str_replace(array(";", "<br />"), array("|", "\n\r"), mysqli_escape_string($link, stripslashes(utf8_decode($record['description']))))),
624
-                        'pw' => $pw['string'],
625
-                        'login' => $record['login'],
626
-                        'url' => $record['url'],
627
-                        'perso' => $record['perso']
628
-                    )
629
-                );
630
-                $i++;
631
-                array_push($items_id_list, $record['id']);
632
-
633
-                // log
634
-                logItems(
635
-                    $record['id'],
636
-                    $record['l SeekableIteratorabel'],
637
-                    $_SESSION['user_id'],
638
-                    'at_export',
639
-                    $_SESSION['login'],
640
-                    'html'
641
-                );
643
+                $id_managed = $record['id'];
642 644
             }
643
-            $id_managed = $record['id'];
644
-        }
645 645
 
646
-        //save in export file
647
-        $outstream = fopen($post_file.'.txt', "a");
646
+            //save in export file
647
+            $outstream = fopen($post_file.'.txt', "a");
648 648
 
649
-        $lineType = "line1";
650
-        $idTree = "";
651
-        foreach ($full_listing as $elem) {
652
-            if ($lineType == "line0") {
653
-                $lineType = "line1";
654
-            } else {
655
-                $lineType = "line0";
656
-            }
657
-            if (empty($elem['description'])) {
658
-                $desc = '&nbsp;';
659
-            } else {
660
-                $desc = addslashes($elem['description']);
661
-            }
662
-            if (empty($elem['login'])) {
663
-                $login = '&nbsp;';
664
-            } else {
665
-                $login = addslashes($elem['login']);
666
-            }
667
-            if (empty($elem['url'])) {
668
-                $url = '&nbsp;';
669
-            } else {
670
-                $url = addslashes($elem['url']);
671
-            }
649
+            $lineType = "line1";
650
+            $idTree = "";
651
+            foreach ($full_listing as $elem) {
652
+                if ($lineType == "line0") {
653
+                    $lineType = "line1";
654
+                } else {
655
+                    $lineType = "line0";
656
+                }
657
+                if (empty($elem['description'])) {
658
+                    $desc = '&nbsp;';
659
+                } else {
660
+                    $desc = addslashes($elem['description']);
661
+                }
662
+                if (empty($elem['login'])) {
663
+                    $login = '&nbsp;';
664
+                } else {
665
+                    $login = addslashes($elem['login']);
666
+                }
667
+                if (empty($elem['url'])) {
668
+                    $url = '&nbsp;';
669
+                } else {
670
+                    $url = addslashes($elem['url']);
671
+                }
672 672
 
673
-            // Prepare tree
674
-            if ($idTree != $elem['id_tree']) {
675
-                $arbo = $tree->getPath($elem['id_tree'], true);
676
-                foreach ($arbo as $folder) {
677
-                    $arboHtml_tmp = htmlspecialchars(stripslashes($folder->title), ENT_QUOTES);
678
-                    if (empty($arboHtml)) {
679
-                        $arboHtml = $arboHtml_tmp;
680
-                    } else {
681
-                        $arboHtml .= ' » '.$arboHtml_tmp;
673
+                // Prepare tree
674
+                if ($idTree != $elem['id_tree']) {
675
+                    $arbo = $tree->getPath($elem['id_tree'], true);
676
+                    foreach ($arbo as $folder) {
677
+                        $arboHtml_tmp = htmlspecialchars(stripslashes($folder->title), ENT_QUOTES);
678
+                        if (empty($arboHtml)) {
679
+                            $arboHtml = $arboHtml_tmp;
680
+                        } else {
681
+                            $arboHtml .= ' » '.$arboHtml_tmp;
682
+                        }
682 683
                     }
684
+                    fputs(
685
+                        $outstream,
686
+                        '
687
+        <tr class="path"><td colspan="5">'.$arboHtml.'</td></tr>'
688
+                    );
689
+                    $idTree = $elem['id_tree'];
683 690
                 }
691
+
692
+                $encPw = GibberishAES::enc($elem['pw'], $post_pdf_password);
684 693
                 fputs(
685 694
                     $outstream,
686 695
                     '
687
-        <tr class="path"><td colspan="5">'.$arboHtml.'</td></tr>'
688
-                );
689
-                $idTree = $elem['id_tree'];
690
-            }
691
-
692
-            $encPw = GibberishAES::enc($elem['pw'], $post_pdf_password);
693
-            fputs(
694
-                $outstream,
695
-                '
696 696
         <tr class="'.$lineType.'">
697 697
             <td>'.addslashes($elem['label']).'</td>
698 698
             <td align="center"><span class="span_pw" id="span_'.$elem['id'].'"><a href="#" onclick="decryptme('.$elem['id'].', \''.$encPw.'\');return false;">Decrypt </a></span><input type="hidden" id="hide_'.$elem['id'].'" value="'.$encPw.'" /></td>
@@ -700,16 +700,16 @@  discard block
 block discarded – undo
700 700
             <td align="center">'.$login.'</td>
701 701
             <td align="center">'.$url.'</td>
702 702
             </tr>'
703
-            );
704
-        }
703
+                );
704
+            }
705 705
 
706
-        fclose($outstream);
706
+            fclose($outstream);
707 707
 
708
-        // send back and continue
709
-        echo '[{"loop":"true", "number":"'.$post_number.'", "cpt":"'.$post_cpt.'", "file":"'.$post_file.'", "idsList":"'.$post_idsList.'" , "file_link":"'.$post_file_link.'"}]';
710
-        break;
708
+            // send back and continue
709
+            echo '[{"loop":"true", "number":"'.$post_number.'", "cpt":"'.$post_cpt.'", "file":"'.$post_file.'", "idsList":"'.$post_idsList.'" , "file_link":"'.$post_file_link.'"}]';
710
+            break;
711 711
 
712
-            //CASE export in HTML format - Iteration loop
712
+                //CASE export in HTML format - Iteration loop
713 713
         case "export_to_html_format_finalize":
714 714
             // Load includes
715 715
             include $SETTINGS['cpassman_dir'].'/includes/config/include.php';
Please login to merge, or discard this patch.