File: manage_apps.php

package info (click to toggle)
boinc 7.14.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,132 kB
  • sloc: cpp: 163,589; php: 113,173; ansic: 49,284; pascal: 35,620; xml: 17,864; java: 13,521; python: 6,551; sh: 4,082; perl: 1,843; makefile: 1,796; objc: 1,543; sql: 959; csh: 126; lisp: 47
file content (235 lines) | stat: -rw-r--r-- 7,383 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2017 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

// web interface for managing apps

require_once('../inc/util_ops.inc');

function do_updates() {
    $id = post_int("id");
    $app = BoincApp::lookup_id($id);
    if (!$app) admin_error_page("no such app");

    $n = post_str("deprecated", true)?1:0;
    $app->update("deprecated=$n");

    $n = post_num("weight");
    $app->update("weight=$n");

    $n = post_int("homogeneous_redundancy");
    $app->update("homogeneous_redundancy=$n");

    $n = post_int("target_nresults");
    $app->update("target_nresults=$n");

    $n = post_str("homogeneous_app_version", true)?1:0;
    $app->update("homogeneous_app_version=$n");

    $n = post_str("non_cpu_intensive", true)?1:0;
    $app->update("non_cpu_intensive=$n");

    $n = post_str("beta", true)?1:0;
    $app->update("beta=$n");

    $n = post_str("fraction_done_exact", true)?1:0;
    $app->update("fraction_done_exact=$n");

    echo "Application $id updated.
        <p>
        You must restart the project for this to take effect.
    ";
}

function add_app() {
    $name = BoincDb::escape_string(post_str('add_name'));
    $user_friendly_name = BoincDb::escape_string(post_str('add_user_friendly_name'));
    if (empty($name) || empty($user_friendly_name) ) {
        admin_error_page(
            "To add a new application please supply both a brief name and a longer 'user-friendly' name.</font></p>"
        );
    }
    $now = time();
    $id = BoincApp::insert(
        "(name,user_friendly_name,create_time) VALUES ('$name', '$user_friendly_name', $now)"
    );
    if (!$id) {
        admin_error_page("insert failed");
    }
    echo "Application added.
        <p>
        You must restart the project for this to take effect.
    ";
}

function show_form($all) {
    echo "
        <h2>Edit applications</h2>
    ";

    $app_clause="deprecated=0";
    $action_url="manage_apps.php";
    if($all) {
        $app_clause = "";
        $action_url="manage_apps.php?all=1";
        echo "<a href=\"manage_apps.php\">Don't show deprecated applications</a>";
    } else {
        echo "<a href=\"manage_apps.php?all=1\">Show deprecated applications</a>";
    }

    start_table('table-striped');
    table_header(
        "ID",
        "Name and description<br><small>Click for details</small>",
        "Created",
        "weight<br><a href=https://boinc.berkeley.edu/trac/wiki/BackendPrograms#feeder><small>details</small></a>",
        "shmem items",
        "HR type<br><a href=https://boinc.berkeley.edu/trac/wiki/HomogeneousRedundancy><small>details</small></a>",
        "Adaptive replication<br><a href=http://boinc.berkeley.edu/trac/wiki/AdaptiveReplication><small>details</small></a>",
        "homogeneous app version?<br><a href=https://boinc.berkeley.edu/trac/wiki/HomogeneousAppVersion><small>details</small></a>",
        "deprecated?",
        "Non-CPU-intensive?",
        "Beta?",
        "Exact fraction done?",
        ""
    );

    $total_weight = BoincApp::sum("weight", "where deprecated=0");
    $swi = parse_config(get_config(), "<shmem_work_items>");
    if (!$swi) {
        $swi = 100;
    }

    $apps = BoincApp::enum($app_clause);
    foreach ($apps as $app) {
        // grey-out deprecated versions
        $f1=$f2='';
        if ($app->deprecated==1) {
            $f1 = "<font color='GREY'>";
            $f2 = "</font>";
        }
        echo "<tr><form action=$action_url method=POST>";
        echo "<input type=hidden name=id value=$app->id>";
        echo "  <TD align='center'>$f1 $app->id $f2</TD>\n";

        echo "  <TD align='left'>$f1<a href=app_details.php?appid=$app->id>$app->name</a><br> $app->user_friendly_name $f2</TD>\n";

        echo "  <TD align='center'>$f1 " .date_str($app->create_time)."$f2</TD>\n";

        $v = $app->weight;
        echo "  <TD align='center'>
        <input type='text' size='4' name='weight' value='$v'></TD>\n";
        
        if ($app->deprecated || ($total_weight == 0)) {
            echo '<td></td>';
        } else {
            echo '<td align="right">'.round($app->weight/$total_weight*$swi).'</td>';
        }

        $v = $app->homogeneous_redundancy;
        echo "  <TD align='center'>
            <input size=4 name='homogeneous_redundancy' value='$v'></TD>
        ";

        $v = $app->target_nresults;
        echo "  <TD align='center'>
            <input size=4 name='target_nresults' value='$v'></TD>
        ";

        $v = '';
        if ($app->homogeneous_app_version) $v=' CHECKED ';
        echo "  <TD align='center'>
            <input name='homogeneous_app_version' type='checkbox' $v></TD>
        ";

        $v = '';
        if ($app->deprecated) $v = ' CHECKED ';
        echo "  <TD align='center'>
            <input name='deprecated' type='checkbox' $v></TD>
        ";

        $v = '';
        if ($app->non_cpu_intensive) $v = ' CHECKED ';
        echo "  <TD align='center'>
            <input name='non_cpu_intensive' type='checkbox' $v></TD>
        ";

        $v = '';
        if ($app->beta) $v = ' CHECKED ';
        echo "  <TD align='center'>
            <input name='beta' type='checkbox' $v></TD>
        ";

        $v = '';
        if ($app->fraction_done_exact) $v = ' CHECKED ';
        echo "  <TD align='center'>
            <input name='fraction_done_exact' type='checkbox' $v></TD>
        ";
        if (!in_rops()) {
            echo "<td><input class=\"btn btn-default\" type=submit name=submit value=Update></td>";
        } else {
            echo "<td>&nbsp;</td>";
        }
        echo "</tr></form>";
    }

    end_table();


    // Entry form to create a new application
    //
    if (in_rops()) {
        return;
    }

    echo"<P>
        <h2>Add an application</h2>
        To add an application enter the short name and description
        ('user friendly name') below.  You can then edit the
        application when it appears in the table above.
        <p>
        <form action=$action_url method=POST>
    ";

    start_table("align='center' ");

    table_header("Name", "Description", "&nbsp;");

    echo "<TR>
            <TD> <input type='text' size='12' name='add_name' value=''></TD>
            <TD> <input type='text' size='35' name='add_user_friendly_name' value=''></TD>
            <TD align='center' >
                 <input type='submit' name='add_app' value='Add Application'></TD>
            </TR>\n";

    end_table();
    echo "</form><p>\n";
}

admin_page_head("Manage applications");

$all = get_int('all', true);

if (post_str('add_app', true)) {
    add_app();
} else if (post_str('submit', true)) {
    do_updates();
}
show_form($all);
admin_page_tail();

?>