FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
device/device_controller.php at master · emoncms/device · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
emoncms
/
device
Public
Notifications
You must be signed in to change notification settings
Fork
18
Star
2
Code
Issues
9
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
device
/
device_controller.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
99 lines (90 loc) · 5.04 KB
Breadcrumbs
device
/
device_controller.php
Copy path
File metadata and controls
99 lines (90 loc) · 5.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
// no direct access
defined
(
'
EMONCMS_EXEC
'
)
or
die
(
'
Restricted access
'
);
function
device_controller
()
{
global
$
mysqli
,
$
redis
,
$
session
,
$
route
,
$
device
,
$
settings
;
$
result
=
false
;
require_once
"
Modules/device/device_model.php
"
;
$
device
=
new
Device
(
$
mysqli
,
$
redis
);
if
(
$
route
->
format
==
'
html
'
)
{
if
(
$
route
->
action
==
"
view
"
&&
$
session
[
'
write
'
]) {
$
templates
=
$
device
->
get_template_list_meta
(
$
session
[
'
userid
'
]);
$
result
=
view
(
"
Modules/device/Views/device_view.php
"
,
array
(
'
templates
'
=>
$
templates
));
}
else
if
(
$
route
->
action
==
'
api
'
) {
require_once
"
Modules/device/device_api_obj.php
"
;
$
api
=
array
();
foreach
(
device_api_obj
()
as
$
endpoint
) {
$
endpoint
[
'
module
'
] =
"
device
"
;
$
api
[] =
$
endpoint
; }
$
result
=
view
(
"
Lib/api_explorer_view.php
"
,
array
(
"
title
"
=>
tr
(
"
Device API
"
),
"
sub
"
=>
tr
(
"
Use the device API to register devices and set up their inputs and feeds from a template
"
),
"
api
"
=>
$
api
,
"
show_docs_link
"
=>
true
,
"
standalone
"
=>
true
,
"
extra
"
=>
"
Modules/device/Views/device_api_extra.php
"
,
"
apikeys
"
=>
session_apikeys
()
));
}
}
if
(
$
route
->
format
==
'
json
'
)
{
if
(
$
route
->
action
==
'
list
'
) {
if
(
$
session
[
'
userid
'
]>
0
&&
$
session
[
'
read
'
])
$
result
=
$
device
->
get_list
(
$
session
[
'
userid
'
]);
}
else
if
(
$
route
->
action
==
"
create
"
) {
if
(
$
session
[
'
userid
'
]>
0
&&
$
session
[
'
write
'
])
$
result
=
$
device
->
create
(
$
session
[
'
userid
'
],
get
(
"
nodeid
"
),
get
(
"
name
"
),
get
(
"
description
"
),
get
(
"
type
"
),
get
(
"
dkey
"
));
}
// Used in conjunction with input name describe to auto create device
else
if
(
$
route
->
action
==
"
autocreate
"
) {
if
(
$
session
[
'
userid
'
]>
0
&&
$
session
[
'
write
'
])
$
result
=
$
device
->
autocreate
(
$
session
[
'
userid
'
],
get
(
'
nodeid
'
),
get
(
'
type
'
));
}
else
if
(
$
route
->
action
==
"
generatekey
"
) {
if
(
$
session
[
'
userid
'
]>
0
&&
$
session
[
'
write
'
])
$
result
=
$
device
->
generate_devicekey
();
}
else
if
(
$
route
->
action
==
"
template
"
&&
$
route
->
subaction
!=
"
prepare
"
&&
$
route
->
subaction
!=
"
prepare_custom
"
&&
$
route
->
subaction
!=
"
init
"
&&
$
route
->
subaction
!=
"
init_custom
"
&&
$
route
->
subaction
!=
"
generate
"
) {
if
(
$
route
->
subaction
==
"
listshort
"
) {
if
(
$
session
[
'
userid
'
]>
0
&&
$
session
[
'
write
'
])
$
result
=
$
device
->
get_template_list_meta
();
}
else
if
(
$
route
->
subaction
==
"
list
"
) {
if
(
$
session
[
'
userid
'
]>
0
&&
$
session
[
'
write
'
])
$
result
=
$
device
->
get_template_list
();
}
else
if
(
$
route
->
subaction
==
"
get
"
) {
if
(
$
session
[
'
userid
'
]>
0
&&
$
session
[
'
write
'
])
$
result
=
$
device
->
get_template
(
get
(
'
type
'
));
}
}
else
{
$
deviceid
= (
int
)
get
(
'
id
'
);
if
(
$
device
->
exist
(
$
deviceid
))
// if the feed exists
{
$
deviceget
=
$
device
->
get
(
$
deviceid
);
if
(
isset
(
$
session
[
'
write
'
]) &&
$
session
[
'
write
'
] &&
$
session
[
'
userid
'
]>
0
&&
$
deviceget
[
'
userid
'
]==
$
session
[
'
userid
'
]) {
if
(
$
route
->
action
==
"
get
"
)
$
result
=
$
deviceget
;
else
if
(
$
route
->
action
==
'
set
'
)
$
result
=
$
device
->
set_fields
(
$
deviceid
,
get
(
'
fields
'
));
else
if
(
$
route
->
action
==
'
init
'
)
$
result
=
$
device
->
init
(
$
deviceid
,
prop
(
'
template
'
));
else
if
(
$
route
->
action
==
"
delete
"
)
$
result
=
$
device
->
delete
(
$
deviceid
);
else
if
(
$
route
->
action
==
"
setnewdevicekey
"
)
$
result
=
$
device
->
set_new_devicekey
(
$
deviceid
);
else
if
(
$
route
->
action
==
'
template
'
) {
if
(
isset
(
$
_GET
[
'
type
'
])) {
$
device
->
set_fields
(
$
deviceid
,
json_encode
(
array
(
"
type
"
=>
$
_GET
[
'
type
'
])));
}
if
(
$
route
->
subaction
==
'
prepare
'
)
$
result
=
$
device
->
prepare_template
(
$
deviceid
);
else
if
(
$
route
->
subaction
==
'
prepare_custom
'
)
$
result
=
$
device
->
prepare_custom_template
(
$
deviceid
,
$
_POST
[
'
template
'
]);
else
if
(
$
route
->
subaction
==
'
init
'
)
$
result
=
$
device
->
init_template
(
$
deviceget
,
$
_POST
[
'
template
'
]);
else
if
(
$
route
->
subaction
==
'
init_custom
'
)
$
result
=
$
device
->
init_custom_template
(
$
deviceget
,
$
_POST
[
'
template
'
]);
else
if
(
$
route
->
subaction
==
'
generate
'
)
$
result
=
$
device
->
generate_template
(
$
deviceid
);
}
}
}
else
{
$
result
=
array
(
'
success
'
=>
false
,
'
message
'
=>
'
Device does not exist
'
);
}
}
}
if
(
$
route
->
action
==
"
clean
"
&&
$
session
[
'
write
'
]) {
$
route
->
format
=
'
text
'
;
$
active
=
0
;
if
(
isset
(
$
_GET
[
'
active
'
]))
$
active
= (
int
)
$
_GET
[
'
active
'
];
$
dryrun
=
0
;
if
(
isset
(
$
_GET
[
'
dryrun
'
]) &&
$
_GET
[
'
dryrun
'
]==
1
)
$
dryrun
=
1
;
return
$
device
->
clean
(
$
session
[
'
userid
'
],
$
active
,
$
dryrun
);
}
return
array
(
'
content
'
=>
$
result
);
}
Back
|
FazBrowse Home
|
New Git URL