index.php 19 KB
Newer Older
jlopez's avatar
jlopez committed
1
2
3
4
5
6
7
8
9
10
11
12
<?php
/**
 * Created by PhpStorm.
 * User: jimmy
 * Date: 11/12/18
 * Time: 14:30
 */

//$content = file_get_contents("container.json", FILE_USE_INCLUDE_PATH);

//$tools = json_decode($content)->containers;

jlopez's avatar
jlopez committed
13
14
session_start ();

jlopez's avatar
jlopez committed
15
16
17
18
19
20
require_once "./dao/DBquery.php";

$db = new DBquery();

$distribs = [];

jlopez's avatar
jlopez committed
21
$data_distribs = $db->getActiveDistributions();
jlopez's avatar
jlopez committed
22
23

foreach($data_distribs as $value){
jlopez's avatar
jlopez committed
24
    array_push($distribs,$value->name.":".$value->version);
jlopez's avatar
jlopez committed
25
26
}

jlopez's avatar
jlopez committed
27
$managers = $db->getManagers();
jlopez's avatar
jlopez committed
28

jlopez's avatar
jlopez committed
29
$data_section = $db->getActiveSection();
jlopez's avatar
jlopez committed
30
31

$section = array();
jlopez's avatar
jlopez committed
32
$section_visual = array();
jlopez's avatar
jlopez committed
33

jlopez's avatar
jlopez committed
34
foreach ($db->getAllActiveSectionParent() as $s){
jlopez's avatar
jlopez committed
35
36
    if($s->active == 1) {
        array_push($section, $s->name);
jlopez's avatar
jlopez committed
37
        array_push($section_visual, $s->visual);
jlopez's avatar
jlopez committed
38
39
40
    }
}

jlopez's avatar
jlopez committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

function printPanel($name) {
    echo '
    
    <br/>
    <label for="find'.$name.'Packages">Find packages with pattern :</label>
<input type="email" class="form-control" id="find'.$name.'Packages">

<div class="form-check">
    <input type="checkbox" class="form-check-input" id="pattern'.$name.'Name" checked>
    <label class="form-check-label" for="pattern'.$name.'Name">Pattern on name</label>
  </div>
  
   <div class="form-check">
    <input type="checkbox" class="form-check-input" id="pattern'.$name.'Description" checked>
    <label class="form-check-label" for="pattern'.$name.'Description">Pattern on description</label>
  </div>
  <br/>
  
    <div class="form-group">
        <label for="limit'.$name.'" class="font-check-label">Max found :</label>
        <select class="custom-select" id="limit'.$name.'">
                <option value="5">5</option>
                <option value="10" selected="selected">10</option>
                <option value="25">25</option>
                <option value="50">50</option>
                <option value="100">100</option>
                <option value="100">200</option>
                <option value="1000000000">all</option>              
        </select>
    </div>
    <br/>
  <button type="button" class="btn btn-primary" onclick="showPackage(\''.$name.'\')">Search</button>
  <br/><br/>
  <div id="containPackages'.$name.'">

    </div>
    
    ';
}

jlopez's avatar
jlopez committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
?>

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" crossorigin="anonymous">
    <link rel="stylesheet" href="./css/style.css">

    <title>wicopa</title>

  </head>
  <body>


jlopez's avatar
jlopez committed
102
    <nav class="navbar navbar-expand-md navbar-dark navbar-custom p-1">
jlopez's avatar
jlopez committed
103
        <a class="navbar-brand" href="#">WICOPA</a>
jlopez's avatar
jlopez committed
104
105
106
107
        <div class="collapse navbar-collapse justify-content-between" id="navbar">
            <div class="navbar-nav">

                <?php
108
109
110

                echo ' <a class="nav-item nav-link active" href="./index.php"> Home </a>';

jlopez's avatar
jlopez committed
111
112
                if(isset($_SESSION['username']) && !empty($_SESSION['username']))
                {
jlopez's avatar
Fix #12    
jlopez committed
113
                    if(isset($_SESSION['manage']) && !empty($_SESSION['manage']))
jlopez's avatar
jlopez committed
114
                    {
jlopez's avatar
Fix #12    
jlopez committed
115
                        echo ' <a class="nav-item nav-link" href="./manage.php"> Manage </a>';
jlopez's avatar
jlopez committed
116
                    }
jlopez's avatar
jlopez committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
                }
                ?>

            </div>
        <div class="navbar-nav">
      <?php
                if(isset($_SESSION['username']) && !empty($_SESSION['username']))
                {
                echo '<a class="nav-item btn btn-primary " href="./action/action_logout.php"> Logout ('.$_SESSION['username'].') </a>';
                }
                else
                {
                echo '<a class="nav-item btn btn-primary" href="./login.php"> Login </a>';
                }
                ?>
        </div>

jlopez's avatar
jlopez committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    </nav>


    <div class="container-fluid">

        <br/>

        <div class="row">
            <div class="col-4">

                <div class="col-12">
                <div class="card border border-dark">
                    <div class="card-header bg-dark text-light">
                        Parameters :
                    </div>
                    <div class="card-body">
                        <div class="form-group">
remy's avatar
remy committed
151
                            <label for="imageNameInput" class="font-weight-bold">Image Name <span style="font-size:20px;" class="status text-danger">*</span>:</label>
jlopez's avatar
jlopez committed
152
153
154
155
                            <input type="text" class="form-control" id="imageNameInput">
                        </div>

                        <div class="form-group">
jlopez's avatar
jlopez committed
156
                            <label for="baseNameInput" class="font-weight-bold">From :</label>
jlopez's avatar
jlopez committed
157
                            <input type="text" class="form-control" id="baseNameInput">
jlopez's avatar
jlopez committed
158
                            <small id="help0" class="form-text text-muted">You can find images name on <a href="https://hub.docker.com/search?q=&type=image" >docker hub </a>.</small>
remy's avatar
remy committed
159
                            <small id="help1" class="form-text text-muted">If the above "From" field is empty, then <a href="https://docs.docker.com/engine/reference/builder/#from">"From"</a> is chosen from distribution bellow. </small>
jlopez's avatar
jlopez committed
160
161
162
163
                            <small id="help2" class="form-text text-muted">You must make sure that the OS of your base container is compatible with the chosen distribution. </small>
                        </div>

                        <div class="form-group">
remy's avatar
remy committed
164
                            <label for="selectedOS" class="font-weight-bold">Distribution <span style="font-size:20px;" class="status text-danger">*</span>:</label>
jlopez's avatar
jlopez committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
                            <select class="custom-select" id="selectedOS" onchange="hide_os_rows()">

                                <?php
                                    foreach ($distribs as $d){
                                        echo ' <option value="'.$d.'">'.$d.'</option>';
                                    }
                                ?>

                            </select>
                        </div>

                        <div class="form-group">
                            <label for="selectedOS" class="font-weight-bold">Package manager :</label>
                            <select class="custom-select" id="selectedInstaller">

                            <?php
jlopez's avatar
jlopez committed
181
182
                                    foreach ($managers as $manager){
                                        echo '<option value="'.$manager->value.'">'.$manager->value.'</option>';
jlopez's avatar
jlopez committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
                                    }
                            ?>

                            </select>
                        </div>

                        <div class="form-group">
                            <label for="containerType" class="font-weight-bold">Container type :</label>
                            <div class="custom-control custom-radio">
                                <input type="radio" id="singularityRadio" name="customRadio" class="custom-control-input" checked>
                                <label class="custom-control-label" for="singularityRadio">Singularity</label>
                            </div>
                            <div class="custom-control custom-radio">
                                <input type="radio" id="dockerRadio" name="customRadio" class="custom-control-input">
                                <label class="custom-control-label" for="dockerRadio">Docker</label>
                            </div>
                        </div>
                        <div class="form-group">
jlopez's avatar
jlopez committed
201
202
203
204
                            <button type="button" id="generateButton" class="btn btn-primary">Generate recipe</button>
                            <button type="button" id="downloadButton" class="btn btn-primary" onclick="downloadFile()">Download recipe</button>
                            <button type="button" id="generateButton" class="btn btn-primary" onclick="buildRecipe()">Build recipe</button>
                            <button type="button" id="generateButton" class="btn btn-primary">Push recipe</button>
jlopez's avatar
jlopez committed
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
                        </div>
                    </div>
                </div>

                </div>
                <br/>
                <div class="col-12">
                <div class="card border border-dark">
                    <div class="card-header bg-dark text-light">
                        Selected packages  :
                    </div>
                    <div class="card-body">
                        <table id="Table_SelectedPackages" class="table table-striped table-bordered">
                            <thead>
                            <tr>
jlopez's avatar
jlopez committed
220
                                <th></th>
jlopez's avatar
jlopez committed
221
                                <th>From</th>
jlopez's avatar
jlopez committed
222
223
                                <th>Name</th>
                     
jlopez's avatar
jlopez committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
                            </tr>
                            </thead>
                            <tbody id="TableSelectedPackages">

                            </tbody>
                        </table>
                    </div>
                </div>
                </div>
            </div>

            <div class="col-8">
                <div class="card border border-dark">
                    <div class="card-header bg-dark text-light">
                        Tools :
                    </div>
                    <div class="card-body">
                        <nav>
                            <div class="nav nav-tabs" id="nav-tab" role="tablist">

                                <?php
                                $index = 0;
                                foreach ($section as $s) {
                                    if($index == 0) {
jlopez's avatar
jlopez committed
248
                                        echo '<a class="nav-item nav-link active" id="nav-'.$s.'-tab" data-toggle="tab" href="#nav-'.$s.'" role="tab" aria-controls="nav-'.$s.'" aria-selected="false">'.$section_visual[$index].'</a>';
jlopez's avatar
jlopez committed
249
                                    } else {
jlopez's avatar
jlopez committed
250
                                        echo '<a class="nav-item nav-link" id="nav-'.$s.'-tab" data-toggle="tab" href="#nav-'.$s.'" role="tab" aria-controls="nav-'.$s.'" aria-selected="false">'.$section_visual[$index].'</a>';
jlopez's avatar
jlopez committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
                                    }
                                    $index++;
                                }
                                ?>
                            </div>
                        </nav>
                        <div class="tab-content" id="nav-tabContent">
                            <?php
                            $index = 0;
                            foreach ($section as $s) {
                                if($index == 0) {
                                    echo '<div class="tab-pane fade show active" id="nav-'.$s.'" role="tabpanel" aria-labelledby="nav-'.$s.'-tab">';
                                }else {
                                    echo '<div class="tab-pane fade" id="nav-'.$s.'" role="tabpanel" aria-labelledby="nav-'.$s.'-tab">';
                                }

                                if($s == "R") {

                                    $subsection = array();

                                    foreach ($db->getSectionWhithParent("R") as $value){
                                        if($value[1]) {
                                            array_push($subsection, $value[0]);
                                        }
                                    }

                                    echo '
                                        <div class="form-group">
                                            <label for="selectedR" class="font-weight-bold">R version :</label>
                                            <select class="custom-select" id="selectedR">
                
                                                <option value="0" selected="selected">None</option>
                                                <option value="3.5" >3.5</option>
                
                                            </select>
                                        </div>
                                        
                                        <nav>
                                            <div class="nav nav-tabs" id="nav-tab-R" role="tablist">
                                        
                                    ';


                                $indexSub = 0;
                                foreach ($subsection as $sub) {
                                    if($indexSub == 0) {
                                        echo '<a class="nav-item nav-link active" id="nav-'.$sub.'-tab-R" data-toggle="tab" href="#nav-'.$sub.'-R" role="tab" aria-controls="nav-'.$sub.'-R" aria-selected="false">'.$sub.'</a>';
                                    } else {
                                        echo '<a class="nav-item nav-link" id="nav-'.$sub.'-tab-R" data-toggle="tab" href="#nav-'.$sub.'-R" role="tab" aria-controls="nav-'.$sub.'-R" aria-selected="false">'.$sub.'</a>';
                                    }
                                    $indexSub++;
                                }


                                    echo '
                                            </div>
                                        </nav>
                                        <div class="tab-content" id="nav-tabContent-R">
                                    ';


                                    $indexSub = 0;
                                    foreach ($subsection as $sub) {
                                        if ($indexSub == 0) {
                                            echo '<div class="tab-pane fade show active" id="nav-' . $sub . '-R" role="tabpanel" aria-labelledby="nav-' . $s . '-tab-R">';
                                        } else {
                                            echo '<div class="tab-pane fade" id="nav-' . $sub . '-R" role="tabpanel" aria-labelledby="nav-' . $s . '-tab-R">';
                                        }

jlopez's avatar
jlopez committed
320
321
322
                                        
                                        printPanel($sub);
                                       
jlopez's avatar
jlopez committed
323
324
325
326
327
328
329

                                        echo '</div>';
                                        $indexSub++;
                                    }

                                    echo '</div>';
                                }
jlopez's avatar
jlopez committed
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
                                else if($s == "Python") {
                                    echo '

                                        <div class="form-group">
                                            <label for="selectedPython" class="font-weight-bold">Python version :</label>
                                            <select class="custom-select" id="selectedPython">
                
                                                <option value="0" selected="selected">None</option>
                                                <option value="3.7" >3.7</option>
                                                <option value="3.6" >3.6</option>
                                                <option value="3.5" >3.5</option>
                                                <option value="2.7" >2.7</option>
                                            </select>
                                        </div>
                                    ';
jlopez's avatar
jlopez committed
345

jlopez's avatar
jlopez committed
346
                                    printPanel($s);
jlopez's avatar
jlopez committed
347
348

                                }
jlopez's avatar
jlopez committed
349
350
                                else {
                                    printPanel($s);
jlopez's avatar
jlopez committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
                                }

                                echo '</div>';
                                $index++;
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <br/>

jlopez's avatar
jlopez committed
366

jlopez's avatar
jlopez committed
367
368
369
370
371
372
373
374
375
376
377
378
            <div class="col-12">
                <div class="card border border-dark" id = "containerPreviewHead">
                    <div class="card-header bg-dark text-light">
                        Preview File :
                    </div>
                    <div class="card-body">
                        <div class="form-group">
                            <textarea id="containerPreview"  class="form-control" rows="3"></textarea>
                        </div>
                    </div>
                </div>
            </div>
jlopez's avatar
jlopez committed
379
380


jlopez's avatar
jlopez committed
381
382
383
384
385
386
387
388
389

    </div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"  crossorigin="anonymous"></script>
jlopez's avatar
jlopez committed
390
    <script src="./js/wicopa.js"></script>
jlopez's avatar
jlopez committed
391
392
    <script>

jlopez's avatar
jlopez committed
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
        $(function()
        {

            <?php
                foreach ($data_section as $s) {
                    echo 'SELECTED_PACKAGES["'.$s->name.'"] = [];';
                    echo '';
                }

                foreach ($data_section as $s) {
                    echo 'SELECTED_PACKAGES_COLOR["'.$s->name.'"] = "' . $s->color . '";' ;
                    echo '';
                }


            ?>

            hide_os_rows();


        });

jlopez's avatar
jlopez committed
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
        function hide_os_rows() {
            var e = document.getElementById("selectedOS");
            var selectedOSRelease = e.options[e.selectedIndex].value;

            var res = "tr.table_container_" + selectedOSRelease.replace(":", "_").replace(".", "_");

            for (var i = 0; i < e.length; i++) {

                res = "tr.table_container_" + e[i].value.replace(":", "_").replace(".", "_");
                if (e[i].value !== selectedOSRelease) {
                    $(res).hide();
                } else {
                    $(res).show();
                }

            }

            var options = document.getElementById('selectedInstaller').getElementsByTagName('option');

            <?php

jlopez's avatar
jlopez committed
436
437


jlopez's avatar
jlopez committed
438
439
                foreach($data_distribs as $value){

jlopez's avatar
jlopez committed
440
                    echo "if(selectedOSRelease.includes(\"$value->name\")) {\n";
jlopez's avatar
jlopez committed
441

jlopez's avatar
jlopez committed
442
443
444
445
446
                    echo "for(var i = 0; i < options.length; i++)  {\n";
                            echo "if(options[i].value == \"$value->manager\") {\n";
                                echo "document.getElementById('selectedInstaller').getElementsByTagName('option')[i].selected = 'selected'\n";
                            echo "}\n";
                    echo "}\n";
jlopez's avatar
jlopez committed
447

jlopez's avatar
jlopez committed
448
                    echo "}\n";
jlopez's avatar
jlopez committed
449
450
451
452
453
454
455
456
                }

            ?>

            document.getElementById("selectedInstaller").disabled = true;

            SELECTED_PACKAGES["Distribution"] = [];

jlopez's avatar
jlopez committed
457
            document.getElementById("containDistributionPackages").innerHTML = '';
jlopez's avatar
jlopez committed
458
459
460
461
462
463

            gestionPackageSelected();
        }

    </script>
  </body>
remy's avatar
remy committed
464
</html>