ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP181.cpp
Go to the documentation of this file.
1 /*
2  ESP181.cpp - ESP3D command class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include "../../include/esp3d_config.h"
21 #if defined (FTP_FEATURE)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/authentication/authentication_service.h"
26 //Set/Get Ftp ports
27 //[ESP181]ctrl=<port> active=<port> passive=<port> pwd=<admin password>
28 bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
29 {
30  bool response = true;
31  String parameter;
32 #ifdef AUTHENTICATION_FEATURE
33  if (auth_type == LEVEL_GUEST) {
34  output->printERROR("Wrong authentication!", 401);
35  return false;
36  }
37 #else
38  (void)auth_type;
39 #endif //AUTHENTICATION_FEATURE
40  parameter = get_param (cmd_params, "");
41  //get
42  if (parameter.length() == 0) {
44  output->printMSG(s.c_str());
45  } else { //set
46 #ifdef AUTHENTICATION_FEATURE
47  if (auth_type != LEVEL_ADMIN) {
48  output->printERROR("Wrong authentication!", 401);
49  return false;
50  }
51 #endif //AUTHENTICATION_FEATURE
52  parameter = get_param (cmd_params, "ctrl=");
53  uint ibuf;
54  bool done = false;
55  if (parameter.length() > 0) {
56  ibuf = parameter.toInt();
58  output->printERROR ("Incorrect port!");
59  return false;
60  }
62  output->printERROR ("Set failed!");
63  response = false;
64  } else {
65  done = true;
66  }
67  }
68  parameter = get_param (cmd_params, "active=");
69  if (parameter.length() > 0) {
70  ibuf = parameter.toInt();
72  output->printERROR ("Incorrect port!");
73  return false;
74  }
76  output->printERROR ("Set failed!");
77  response = false;
78  } else {
79  done = true;
80  }
81  }
82  parameter = get_param (cmd_params, "passive=");
83  if (parameter.length() > 0) {
84  ibuf = parameter.toInt();
86  output->printERROR ("Incorrect port!");
87  return false;
88  }
90  output->printERROR ("Set failed!");
91  response = false;
92  } else {
93  done = true;
94  }
95  }
96  if (response && done) {
97  output->printMSG("ok");
98  } else {
99  if (response && !done) {
100  output->printERROR ("Only ctrl, active and passive settings are supported!");
101  response = false;
102  }
103  }
104 
105  }
106  return response;
107 }
108 
109 #endif //TELNET_FEATURE
ESP_FTP_DATA_ACTIVE_PORT
#define ESP_FTP_DATA_ACTIVE_PORT
Definition: settings_esp3d.h:92
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
Settings_ESP3D::get_max_int32_value
static uint32_t get_max_int32_value(int pos)
Definition: settings_esp3d.cpp:416
Settings_ESP3D::write_uint32
static bool write_uint32(int pos, const uint32_t value)
Definition: settings_esp3d.cpp:970
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
ESP_FTP_CTRL_PORT
#define ESP_FTP_CTRL_PORT
Definition: settings_esp3d.h:91
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP3DOutput::printMSG
size_t printMSG(const char *s, bool withNL=true)
Definition: esp3doutput.cpp:190
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
Settings_ESP3D::get_min_int32_value
static uint32_t get_min_int32_value(int pos)
Definition: settings_esp3d.cpp:462
Settings_ESP3D::read_uint32
static uint32_t read_uint32(int pos, bool *haserror=NULL)
Definition: settings_esp3d.cpp:919
Commands::ESP181
bool ESP181(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP181.cpp:28
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
ESP_FTP_DATA_PASSIVE_PORT
#define ESP_FTP_DATA_PASSIVE_PORT
Definition: settings_esp3d.h:93
ESP3DOutput
Definition: esp3doutput.h:48